blob: 2bb2d396e8e19402e5ac4ffda19c1c71c1c9c4d9 [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
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00009#include "common/version.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040010#include "common/utilities.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000013#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000014#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000015#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000016#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000017#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000018#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000019#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000020#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000021#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000022#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040023#include "libGLESv2/VertexArray.h"
Brandon Jones5bf98292014-06-06 17:19:38 -070024#include "libGLESv2/VertexAttribute.h"
Geoff Langc8058452014-02-03 12:04:11 -050025#include "libGLESv2/TransformFeedback.h"
Jamie Madille261b442014-06-25 12:42:21 -040026#include "libGLESv2/FramebufferAttachment.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027
Geoff Lange8ebe7f2013-08-05 15:03:13 -040028#include "libGLESv2/validationES.h"
29#include "libGLESv2/validationES2.h"
30#include "libGLESv2/validationES3.h"
Jamie Madill55856b12014-01-02 13:59:50 -050031#include "libGLESv2/queryconversions.h"
Jamie Madill478fdb22013-07-19 16:36:59 -040032
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033extern "C"
34{
35
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000036// OpenGL ES 2.0 functions
37
Kenneth Russell67ea1902014-10-06 16:44:50 -070038void GL_APIENTRY glActiveTexture(GLenum texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000040 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000041
Geoff Langbfdea662014-07-23 14:16:32 -040042 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -040043 if (context)
44 {
Geoff Lang3a61c322014-07-10 13:01:54 -040045 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000046 {
Geoff Langb1196682014-07-23 13:47:29 -040047 context->recordError(gl::Error(GL_INVALID_ENUM));
48 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049 }
Geoff Langbfdea662014-07-23 14:16:32 -040050
51 context->getState().setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052 }
53}
54
Kenneth Russell67ea1902014-10-06 16:44:50 -070055void GL_APIENTRY glAttachShader(GLuint program, GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000056{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000057 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000058
Geoff Langbfdea662014-07-23 14:16:32 -040059 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -040060 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000061 {
Geoff Langbfdea662014-07-23 14:16:32 -040062 gl::Program *programObject = context->getProgram(program);
63 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064
Geoff Langbfdea662014-07-23 14:16:32 -040065 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066 {
Geoff Langbfdea662014-07-23 14:16:32 -040067 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000068 {
Geoff Langb1196682014-07-23 13:47:29 -040069 context->recordError(gl::Error(GL_INVALID_OPERATION));
70 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000071 }
Geoff Langbfdea662014-07-23 14:16:32 -040072 else
73 {
Geoff Langb1196682014-07-23 13:47:29 -040074 context->recordError(gl::Error(GL_INVALID_VALUE));
75 return;
Geoff Langbfdea662014-07-23 14:16:32 -040076 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000077 }
Geoff Langbfdea662014-07-23 14:16:32 -040078
79 if (!shaderObject)
80 {
81 if (context->getProgram(shader))
82 {
Geoff Langb1196682014-07-23 13:47:29 -040083 context->recordError(gl::Error(GL_INVALID_OPERATION));
84 return;
Geoff Langbfdea662014-07-23 14:16:32 -040085 }
86 else
87 {
Geoff Langb1196682014-07-23 13:47:29 -040088 context->recordError(gl::Error(GL_INVALID_VALUE));
89 return;
Geoff Langbfdea662014-07-23 14:16:32 -040090 }
91 }
92
93 if (!programObject->attachShader(shaderObject))
94 {
Geoff Langb1196682014-07-23 13:47:29 -040095 context->recordError(gl::Error(GL_INVALID_OPERATION));
96 return;
Geoff Langbfdea662014-07-23 14:16:32 -040097 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098 }
99}
100
Kenneth Russell67ea1902014-10-06 16:44:50 -0700101void GL_APIENTRY glBeginQueryEXT(GLenum target, GLuint id)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000102{
103 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
104
Geoff Langbfdea662014-07-23 14:16:32 -0400105 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400106 if (context)
107 {
108 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000109 {
Geoff Langbfdea662014-07-23 14:16:32 -0400110 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000111 }
Geoff Langbfdea662014-07-23 14:16:32 -0400112
Geoff Lang5aad9672014-09-08 11:10:42 -0400113 gl::Error error = context->beginQuery(target, id);
114 if (error.isError())
115 {
116 context->recordError(error);
117 return;
118 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000119 }
120}
121
Kenneth Russell67ea1902014-10-06 16:44:50 -0700122void GL_APIENTRY glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000124 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
Geoff Langbfdea662014-07-23 14:16:32 -0400126 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400127 if (context)
128 {
Geoff Langb1196682014-07-23 13:47:29 -0400129 if (index >= gl::MAX_VERTEX_ATTRIBS)
130 {
131 context->recordError(gl::Error(GL_INVALID_VALUE));
132 return;
133 }
134
Geoff Langbfdea662014-07-23 14:16:32 -0400135 gl::Program *programObject = context->getProgram(program);
136
137 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000138 {
Geoff Langbfdea662014-07-23 14:16:32 -0400139 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000140 {
Geoff Langb1196682014-07-23 13:47:29 -0400141 context->recordError(gl::Error(GL_INVALID_OPERATION));
142 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000143 }
Geoff Langbfdea662014-07-23 14:16:32 -0400144 else
145 {
Geoff Langb1196682014-07-23 13:47:29 -0400146 context->recordError(gl::Error(GL_INVALID_VALUE));
147 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400148 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000149 }
Geoff Langbfdea662014-07-23 14:16:32 -0400150
151 if (strncmp(name, "gl_", 3) == 0)
152 {
Geoff Langb1196682014-07-23 13:47:29 -0400153 context->recordError(gl::Error(GL_INVALID_OPERATION));
154 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400155 }
156
157 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000158 }
159}
160
Kenneth Russell67ea1902014-10-06 16:44:50 -0700161void GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000162{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000163 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000164
Geoff Langbfdea662014-07-23 14:16:32 -0400165 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400166 if (context)
167 {
168 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000169 {
Geoff Langb1196682014-07-23 13:47:29 -0400170 context->recordError(gl::Error(GL_INVALID_ENUM));
171 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000172 }
Geoff Langbfdea662014-07-23 14:16:32 -0400173
174 switch (target)
175 {
176 case GL_ARRAY_BUFFER:
177 context->bindArrayBuffer(buffer);
178 return;
179 case GL_ELEMENT_ARRAY_BUFFER:
180 context->bindElementArrayBuffer(buffer);
181 return;
182 case GL_COPY_READ_BUFFER:
183 context->bindCopyReadBuffer(buffer);
184 return;
185 case GL_COPY_WRITE_BUFFER:
186 context->bindCopyWriteBuffer(buffer);
187 return;
188 case GL_PIXEL_PACK_BUFFER:
189 context->bindPixelPackBuffer(buffer);
190 return;
191 case GL_PIXEL_UNPACK_BUFFER:
192 context->bindPixelUnpackBuffer(buffer);
193 return;
194 case GL_UNIFORM_BUFFER:
195 context->bindGenericUniformBuffer(buffer);
196 return;
197 case GL_TRANSFORM_FEEDBACK_BUFFER:
198 context->bindGenericTransformFeedbackBuffer(buffer);
199 return;
Geoff Langb1196682014-07-23 13:47:29 -0400200
Geoff Langbfdea662014-07-23 14:16:32 -0400201 default:
Geoff Langb1196682014-07-23 13:47:29 -0400202 context->recordError(gl::Error(GL_INVALID_ENUM));
203 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400204 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000205 }
206}
207
Kenneth Russell67ea1902014-10-06 16:44:50 -0700208void GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000210 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000211
Geoff Langbfdea662014-07-23 14:16:32 -0400212 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400213 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000214 {
Geoff Langb1196682014-07-23 13:47:29 -0400215 if (!gl::ValidFramebufferTarget(target))
216 {
217 context->recordError(gl::Error(GL_INVALID_ENUM));
218 return;
219 }
220
Geoff Langbfdea662014-07-23 14:16:32 -0400221 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
222 {
223 context->bindReadFramebuffer(framebuffer);
224 }
225
226 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
227 {
228 context->bindDrawFramebuffer(framebuffer);
229 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000230 }
231}
232
Kenneth Russell67ea1902014-10-06 16:44:50 -0700233void GL_APIENTRY glBindRenderbuffer(GLenum target, GLuint renderbuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000234{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000235 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000236
Geoff Langbfdea662014-07-23 14:16:32 -0400237 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400238 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000239 {
Geoff Langb1196682014-07-23 13:47:29 -0400240 if (target != GL_RENDERBUFFER)
241 {
242 context->recordError(gl::Error(GL_INVALID_ENUM));
243 return;
244 }
245
Geoff Langbfdea662014-07-23 14:16:32 -0400246 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000247 }
248}
249
Kenneth Russell67ea1902014-10-06 16:44:50 -0700250void GL_APIENTRY glBindTexture(GLenum target, GLuint texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000251{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000252 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000253
Geoff Langbfdea662014-07-23 14:16:32 -0400254 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400255 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000256 {
Geoff Langbfdea662014-07-23 14:16:32 -0400257 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000258
Geoff Langbfdea662014-07-23 14:16:32 -0400259 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000260 {
Geoff Langb1196682014-07-23 13:47:29 -0400261 context->recordError(gl::Error(GL_INVALID_OPERATION));
262 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400263 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000264
Geoff Langbfdea662014-07-23 14:16:32 -0400265 switch (target)
266 {
267 case GL_TEXTURE_2D:
Geoff Langbfdea662014-07-23 14:16:32 -0400268 case GL_TEXTURE_CUBE_MAP:
Geoff Lang76b10c92014-09-05 16:28:14 -0400269 break;
Geoff Langb1196682014-07-23 13:47:29 -0400270
Geoff Langbfdea662014-07-23 14:16:32 -0400271 case GL_TEXTURE_3D:
Geoff Langbfdea662014-07-23 14:16:32 -0400272 case GL_TEXTURE_2D_ARRAY:
273 if (context->getClientVersion() < 3)
274 {
Geoff Langb1196682014-07-23 13:47:29 -0400275 context->recordError(gl::Error(GL_INVALID_ENUM));
276 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400277 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400278 break;
Geoff Langb1196682014-07-23 13:47:29 -0400279
Geoff Langbfdea662014-07-23 14:16:32 -0400280 default:
Geoff Langb1196682014-07-23 13:47:29 -0400281 context->recordError(gl::Error(GL_INVALID_ENUM));
282 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000283 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400284
285 context->bindTexture(target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000286 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287}
288
Kenneth Russell67ea1902014-10-06 16:44:50 -0700289void GL_APIENTRY glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000291 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000292 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000293
Geoff Langbfdea662014-07-23 14:16:32 -0400294 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000295
Geoff Langbfdea662014-07-23 14:16:32 -0400296 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000297 {
Geoff Langbfdea662014-07-23 14:16:32 -0400298 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000299 }
300}
301
Kenneth Russell67ea1902014-10-06 16:44:50 -0700302void GL_APIENTRY glBlendEquation(GLenum mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000303{
304 glBlendEquationSeparate(mode, mode);
305}
306
Kenneth Russell67ea1902014-10-06 16:44:50 -0700307void GL_APIENTRY glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000308{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000309 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000310
Geoff Langbfdea662014-07-23 14:16:32 -0400311 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400312 if (context)
313 {
Geoff Langb1196682014-07-23 13:47:29 -0400314 switch (modeRGB)
315 {
316 case GL_FUNC_ADD:
317 case GL_FUNC_SUBTRACT:
318 case GL_FUNC_REVERSE_SUBTRACT:
319 case GL_MIN:
320 case GL_MAX:
321 break;
322
323 default:
324 context->recordError(gl::Error(GL_INVALID_ENUM));
325 return;
326 }
327
328 switch (modeAlpha)
329 {
330 case GL_FUNC_ADD:
331 case GL_FUNC_SUBTRACT:
332 case GL_FUNC_REVERSE_SUBTRACT:
333 case GL_MIN:
334 case GL_MAX:
335 break;
336
337 default:
338 context->recordError(gl::Error(GL_INVALID_ENUM));
339 return;
340 }
341
Geoff Langbfdea662014-07-23 14:16:32 -0400342 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000343 }
344}
345
Kenneth Russell67ea1902014-10-06 16:44:50 -0700346void GL_APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000347{
348 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
349}
350
Kenneth Russell67ea1902014-10-06 16:44:50 -0700351void GL_APIENTRY glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000352{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000353 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 +0000354 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000355
Geoff Langbfdea662014-07-23 14:16:32 -0400356 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400357 if (context)
358 {
Geoff Langb1196682014-07-23 13:47:29 -0400359 switch (srcRGB)
360 {
361 case GL_ZERO:
362 case GL_ONE:
363 case GL_SRC_COLOR:
364 case GL_ONE_MINUS_SRC_COLOR:
365 case GL_DST_COLOR:
366 case GL_ONE_MINUS_DST_COLOR:
367 case GL_SRC_ALPHA:
368 case GL_ONE_MINUS_SRC_ALPHA:
369 case GL_DST_ALPHA:
370 case GL_ONE_MINUS_DST_ALPHA:
371 case GL_CONSTANT_COLOR:
372 case GL_ONE_MINUS_CONSTANT_COLOR:
373 case GL_CONSTANT_ALPHA:
374 case GL_ONE_MINUS_CONSTANT_ALPHA:
375 case GL_SRC_ALPHA_SATURATE:
376 break;
377
378 default:
379 context->recordError(gl::Error(GL_INVALID_ENUM));
380 return;
381 }
382
383 switch (dstRGB)
384 {
385 case GL_ZERO:
386 case GL_ONE:
387 case GL_SRC_COLOR:
388 case GL_ONE_MINUS_SRC_COLOR:
389 case GL_DST_COLOR:
390 case GL_ONE_MINUS_DST_COLOR:
391 case GL_SRC_ALPHA:
392 case GL_ONE_MINUS_SRC_ALPHA:
393 case GL_DST_ALPHA:
394 case GL_ONE_MINUS_DST_ALPHA:
395 case GL_CONSTANT_COLOR:
396 case GL_ONE_MINUS_CONSTANT_COLOR:
397 case GL_CONSTANT_ALPHA:
398 case GL_ONE_MINUS_CONSTANT_ALPHA:
399 break;
400
401 case GL_SRC_ALPHA_SATURATE:
402 if (context->getClientVersion() < 3)
403 {
404 context->recordError(gl::Error(GL_INVALID_ENUM));
405 return;
406 }
407 break;
408
409 default:
410 context->recordError(gl::Error(GL_INVALID_ENUM));
411 return;
412 }
413
414 switch (srcAlpha)
415 {
416 case GL_ZERO:
417 case GL_ONE:
418 case GL_SRC_COLOR:
419 case GL_ONE_MINUS_SRC_COLOR:
420 case GL_DST_COLOR:
421 case GL_ONE_MINUS_DST_COLOR:
422 case GL_SRC_ALPHA:
423 case GL_ONE_MINUS_SRC_ALPHA:
424 case GL_DST_ALPHA:
425 case GL_ONE_MINUS_DST_ALPHA:
426 case GL_CONSTANT_COLOR:
427 case GL_ONE_MINUS_CONSTANT_COLOR:
428 case GL_CONSTANT_ALPHA:
429 case GL_ONE_MINUS_CONSTANT_ALPHA:
430 case GL_SRC_ALPHA_SATURATE:
431 break;
432
433 default:
434 context->recordError(gl::Error(GL_INVALID_ENUM));
435 return;
436 }
437
438 switch (dstAlpha)
439 {
440 case GL_ZERO:
441 case GL_ONE:
442 case GL_SRC_COLOR:
443 case GL_ONE_MINUS_SRC_COLOR:
444 case GL_DST_COLOR:
445 case GL_ONE_MINUS_DST_COLOR:
446 case GL_SRC_ALPHA:
447 case GL_ONE_MINUS_SRC_ALPHA:
448 case GL_DST_ALPHA:
449 case GL_ONE_MINUS_DST_ALPHA:
450 case GL_CONSTANT_COLOR:
451 case GL_ONE_MINUS_CONSTANT_COLOR:
452 case GL_CONSTANT_ALPHA:
453 case GL_ONE_MINUS_CONSTANT_ALPHA:
454 break;
455
456 case GL_SRC_ALPHA_SATURATE:
457 if (context->getClientVersion() < 3)
458 {
459 context->recordError(gl::Error(GL_INVALID_ENUM));
460 return;
461 }
462 break;
463
464 default:
465 context->recordError(gl::Error(GL_INVALID_ENUM));
466 return;
467 }
468
469 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
470 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
471
472 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
473 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
474
475 if (constantColorUsed && constantAlphaUsed)
476 {
477 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
478 context->recordError(gl::Error(GL_INVALID_OPERATION));
479 return;
480 }
481
Geoff Langbfdea662014-07-23 14:16:32 -0400482 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000483 }
484}
485
Kenneth Russell67ea1902014-10-06 16:44:50 -0700486void GL_APIENTRY glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000487{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000488 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 +0000489 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000490
Geoff Langbfdea662014-07-23 14:16:32 -0400491 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400492 if (context)
493 {
Geoff Langb1196682014-07-23 13:47:29 -0400494 if (size < 0)
495 {
496 context->recordError(gl::Error(GL_INVALID_VALUE));
497 return;
498 }
499
500 switch (usage)
501 {
502 case GL_STREAM_DRAW:
503 case GL_STATIC_DRAW:
504 case GL_DYNAMIC_DRAW:
505 break;
506
507 case GL_STREAM_READ:
508 case GL_STREAM_COPY:
509 case GL_STATIC_READ:
510 case GL_STATIC_COPY:
511 case GL_DYNAMIC_READ:
512 case GL_DYNAMIC_COPY:
513 if (context->getClientVersion() < 3)
514 {
515 context->recordError(gl::Error(GL_INVALID_ENUM));
516 return;
517 }
518 break;
519
520 default:
521 context->recordError(gl::Error(GL_INVALID_ENUM));
522 return;
523 }
524
Geoff Langbfdea662014-07-23 14:16:32 -0400525 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000526 {
Geoff Langb1196682014-07-23 13:47:29 -0400527 context->recordError(gl::Error(GL_INVALID_ENUM));
528 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000529 }
530
Geoff Langbfdea662014-07-23 14:16:32 -0400531 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
532
533 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000534 {
Geoff Langb1196682014-07-23 13:47:29 -0400535 context->recordError(gl::Error(GL_INVALID_OPERATION));
536 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000537 }
Geoff Langbfdea662014-07-23 14:16:32 -0400538
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400539 gl::Error error = buffer->bufferData(data, size, usage);
540 if (error.isError())
541 {
542 context->recordError(error);
543 return;
544 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000545 }
546}
547
Kenneth Russell67ea1902014-10-06 16:44:50 -0700548void GL_APIENTRY glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000549{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000550 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 +0000551 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000552
Geoff Langbfdea662014-07-23 14:16:32 -0400553 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400554 if (context)
555 {
Geoff Langb1196682014-07-23 13:47:29 -0400556 if (size < 0 || offset < 0)
557 {
558 context->recordError(gl::Error(GL_INVALID_VALUE));
559 return;
560 }
561
562 if (data == NULL)
563 {
564 return;
565 }
566
Geoff Langbfdea662014-07-23 14:16:32 -0400567 if (!gl::ValidBufferTarget(context, target))
568 {
Geoff Langb1196682014-07-23 13:47:29 -0400569 context->recordError(gl::Error(GL_INVALID_ENUM));
570 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400571 }
572
573 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
574
575 if (!buffer)
576 {
Geoff Langb1196682014-07-23 13:47:29 -0400577 context->recordError(gl::Error(GL_INVALID_OPERATION));
578 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400579 }
580
581 if (buffer->isMapped())
582 {
Geoff Langb1196682014-07-23 13:47:29 -0400583 context->recordError(gl::Error(GL_INVALID_OPERATION));
584 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400585 }
586
587 // Check for possible overflow of size + offset
588 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
589 {
Geoff Langb1196682014-07-23 13:47:29 -0400590 context->recordError(gl::Error(GL_OUT_OF_MEMORY));
591 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400592 }
593
594 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000595 {
Geoff Langb1196682014-07-23 13:47:29 -0400596 context->recordError(gl::Error(GL_INVALID_VALUE));
597 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000598 }
599
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400600 gl::Error error = buffer->bufferSubData(data, size, offset);
601 if (error.isError())
602 {
603 context->recordError(error);
604 return;
605 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000606 }
607}
608
Kenneth Russell67ea1902014-10-06 16:44:50 -0700609GLenum GL_APIENTRY glCheckFramebufferStatus(GLenum target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000611 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000612
Geoff Langbfdea662014-07-23 14:16:32 -0400613 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400614 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000615 {
Geoff Langb1196682014-07-23 13:47:29 -0400616 if (!gl::ValidFramebufferTarget(target))
617 {
618 context->recordError(gl::Error(GL_INVALID_ENUM));
619 return 0;
620 }
621
Geoff Langbfdea662014-07-23 14:16:32 -0400622 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
623 ASSERT(framebuffer);
624 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625 }
626
627 return 0;
628}
629
Kenneth Russell67ea1902014-10-06 16:44:50 -0700630void GL_APIENTRY glClear(GLbitfield mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000631{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000632 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000633
Geoff Langbfdea662014-07-23 14:16:32 -0400634 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400635 if (context)
636 {
637 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
638
639 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000640 {
Geoff Langb1196682014-07-23 13:47:29 -0400641 context->recordError(gl::Error(GL_INVALID_FRAMEBUFFER_OPERATION));
642 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000643 }
Geoff Langbfdea662014-07-23 14:16:32 -0400644
645 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
646 {
Geoff Langb1196682014-07-23 13:47:29 -0400647 context->recordError(gl::Error(GL_INVALID_VALUE));
648 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400649 }
650
Geoff Langcc79b8c2014-07-25 13:48:02 -0400651 gl::Error error = context->clear(mask);
652 if (error.isError())
653 {
654 context->recordError(error);
655 return;
656 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000657 }
658}
659
Kenneth Russell67ea1902014-10-06 16:44:50 -0700660void GL_APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000662 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000663 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000664
Geoff Langbfdea662014-07-23 14:16:32 -0400665 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400666 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000667 {
Geoff Langbfdea662014-07-23 14:16:32 -0400668 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000669 }
670}
671
Kenneth Russell67ea1902014-10-06 16:44:50 -0700672void GL_APIENTRY glClearDepthf(GLclampf depth)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000673{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000674 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000675
Geoff Langbfdea662014-07-23 14:16:32 -0400676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400677 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000678 {
Geoff Langbfdea662014-07-23 14:16:32 -0400679 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000680 }
681}
682
Kenneth Russell67ea1902014-10-06 16:44:50 -0700683void GL_APIENTRY glClearStencil(GLint s)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000685 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000686
Geoff Langbfdea662014-07-23 14:16:32 -0400687 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400688 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000689 {
Geoff Langbfdea662014-07-23 14:16:32 -0400690 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000691 }
692}
693
Kenneth Russell67ea1902014-10-06 16:44:50 -0700694void GL_APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000695{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000696 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000697 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000698
Geoff Langbfdea662014-07-23 14:16:32 -0400699 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400700 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000701 {
Geoff Langbfdea662014-07-23 14:16:32 -0400702 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000703 }
704}
705
Kenneth Russell67ea1902014-10-06 16:44:50 -0700706void GL_APIENTRY glCompileShader(GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000707{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000708 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000709
Geoff Langbfdea662014-07-23 14:16:32 -0400710 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400711 if (context)
712 {
713 gl::Shader *shaderObject = context->getShader(shader);
714
715 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000716 {
Geoff Langbfdea662014-07-23 14:16:32 -0400717 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000718 {
Geoff Langb1196682014-07-23 13:47:29 -0400719 context->recordError(gl::Error(GL_INVALID_OPERATION));
720 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000721 }
Geoff Langbfdea662014-07-23 14:16:32 -0400722 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000723 {
Geoff Langb1196682014-07-23 13:47:29 -0400724 context->recordError(gl::Error(GL_INVALID_VALUE));
725 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000726 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000727 }
Geoff Langbfdea662014-07-23 14:16:32 -0400728
729 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000730 }
Geoff Langbfdea662014-07-23 14:16:32 -0400731}
732
Kenneth Russell67ea1902014-10-06 16:44:50 -0700733void GL_APIENTRY glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
Geoff Langbfdea662014-07-23 14:16:32 -0400734 GLint border, GLsizei imageSize, const GLvoid* data)
735{
736 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
737 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
738 target, level, internalformat, width, height, border, imageSize, data);
739
740 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400741 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000742 {
Geoff Langbfdea662014-07-23 14:16:32 -0400743 if (context->getClientVersion() < 3 &&
744 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
745 0, 0, width, height, border, GL_NONE, GL_NONE, data))
746 {
747 return;
748 }
749
750 if (context->getClientVersion() >= 3 &&
751 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
752 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
753 {
754 return;
755 }
756
Geoff Lang5d601382014-07-22 15:14:06 -0400757 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
758 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400759 {
Geoff Langb1196682014-07-23 13:47:29 -0400760 context->recordError(gl::Error(GL_INVALID_VALUE));
761 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400762 }
763
764 switch (target)
765 {
766 case GL_TEXTURE_2D:
767 {
768 gl::Texture2D *texture = context->getTexture2D();
Geoff Langb5348332014-09-02 13:16:34 -0400769 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
770 if (error.isError())
771 {
772 context->recordError(error);
773 return;
774 }
Geoff Langbfdea662014-07-23 14:16:32 -0400775 }
776 break;
777
778 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
779 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
780 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
781 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
782 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
783 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
784 {
785 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Langb5348332014-09-02 13:16:34 -0400786 gl::Error error = texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
787 if (error.isError())
788 {
789 context->recordError(error);
790 return;
791 }
Geoff Langbfdea662014-07-23 14:16:32 -0400792 }
793 break;
794
795 default:
Geoff Langb1196682014-07-23 13:47:29 -0400796 context->recordError(gl::Error(GL_INVALID_ENUM));
797 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400798 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000799 }
800}
801
Kenneth Russell67ea1902014-10-06 16:44:50 -0700802void GL_APIENTRY glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000803 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000804{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000805 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000806 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000807 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000808 target, level, xoffset, yoffset, width, height, format, imageSize, data);
809
Geoff Langbfdea662014-07-23 14:16:32 -0400810 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400811 if (context)
812 {
813 if (context->getClientVersion() < 3 &&
814 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
815 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000816 {
Geoff Langbfdea662014-07-23 14:16:32 -0400817 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000818 }
Geoff Langbfdea662014-07-23 14:16:32 -0400819
820 if (context->getClientVersion() >= 3 &&
821 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
822 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
823 {
824 return;
825 }
826
Geoff Lang5d601382014-07-22 15:14:06 -0400827 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
828 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400829 {
Geoff Langb1196682014-07-23 13:47:29 -0400830 context->recordError(gl::Error(GL_INVALID_VALUE));
831 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400832 }
833
834 switch (target)
835 {
836 case GL_TEXTURE_2D:
837 {
838 gl::Texture2D *texture = context->getTexture2D();
Geoff Langb5348332014-09-02 13:16:34 -0400839 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
840 if (error.isError())
841 {
842 context->recordError(error);
843 return;
844 }
Geoff Langbfdea662014-07-23 14:16:32 -0400845 }
846 break;
847
848 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
852 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
853 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
854 {
855 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Langb5348332014-09-02 13:16:34 -0400856 gl::Error error = texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
857 if (error.isError())
858 {
859 context->recordError(error);
860 return;
861 }
Geoff Langbfdea662014-07-23 14:16:32 -0400862 }
863 break;
864
865 default:
Geoff Langb1196682014-07-23 13:47:29 -0400866 context->recordError(gl::Error(GL_INVALID_ENUM));
867 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400868 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000869 }
870}
871
Kenneth Russell67ea1902014-10-06 16:44:50 -0700872void 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 +0000873{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000874 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000875 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000876 target, level, internalformat, x, y, width, height, border);
877
Geoff Langbfdea662014-07-23 14:16:32 -0400878 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400879 if (context)
880 {
881 if (context->getClientVersion() < 3 &&
882 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
883 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000884 {
Geoff Langbfdea662014-07-23 14:16:32 -0400885 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000886 }
Geoff Langbfdea662014-07-23 14:16:32 -0400887
888 if (context->getClientVersion() >= 3 &&
889 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
890 0, 0, 0, x, y, width, height, border))
891 {
892 return;
893 }
894
895 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
896
897 switch (target)
898 {
899 case GL_TEXTURE_2D:
900 {
901 gl::Texture2D *texture = context->getTexture2D();
902 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
903 }
904 break;
905
906 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
907 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
908 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
909 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
910 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
911 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
912 {
913 gl::TextureCubeMap *texture = context->getTextureCubeMap();
914 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
915 }
916 break;
917
Geoff Langb1196682014-07-23 13:47:29 -0400918 default:
919 context->recordError(gl::Error(GL_INVALID_ENUM));
920 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400921 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000922 }
923}
924
Kenneth Russell67ea1902014-10-06 16:44:50 -0700925void 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 +0000926{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000927 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000928 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000929 target, level, xoffset, yoffset, x, y, width, height);
930
Geoff Langbfdea662014-07-23 14:16:32 -0400931 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400932 if (context)
933 {
934 if (context->getClientVersion() < 3 &&
935 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
936 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000937 {
Geoff Langbfdea662014-07-23 14:16:32 -0400938 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000939 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000940
Geoff Langbfdea662014-07-23 14:16:32 -0400941 if (context->getClientVersion() >= 3 &&
942 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
943 xoffset, yoffset, 0, x, y, width, height, 0))
944 {
945 return;
946 }
947
948 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
949
950 switch (target)
951 {
952 case GL_TEXTURE_2D:
953 {
954 gl::Texture2D *texture = context->getTexture2D();
955 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
956 }
957 break;
958
959 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
961 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
962 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
963 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
964 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
965 {
966 gl::TextureCubeMap *texture = context->getTextureCubeMap();
967 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
968 }
969 break;
970
971 default:
Geoff Langb1196682014-07-23 13:47:29 -0400972 context->recordError(gl::Error(GL_INVALID_ENUM));
973 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400974 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000975 }
976}
977
Kenneth Russell67ea1902014-10-06 16:44:50 -0700978GLuint GL_APIENTRY glCreateProgram(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000979{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000980 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000981
Geoff Langbfdea662014-07-23 14:16:32 -0400982 gl::Context *context = gl::getNonLostContext();
983 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000984 {
Geoff Langbfdea662014-07-23 14:16:32 -0400985 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000986 }
987
988 return 0;
989}
990
Kenneth Russell67ea1902014-10-06 16:44:50 -0700991GLuint GL_APIENTRY glCreateShader(GLenum type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000992{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000993 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000994
Geoff Langbfdea662014-07-23 14:16:32 -0400995 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400996 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000997 {
Geoff Langbfdea662014-07-23 14:16:32 -0400998 switch (type)
999 {
1000 case GL_FRAGMENT_SHADER:
1001 case GL_VERTEX_SHADER:
1002 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -04001003
Geoff Langbfdea662014-07-23 14:16:32 -04001004 default:
Geoff Langb1196682014-07-23 13:47:29 -04001005 context->recordError(gl::Error(GL_INVALID_ENUM));
1006 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04001007 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001008 }
1009
1010 return 0;
1011}
1012
Kenneth Russell67ea1902014-10-06 16:44:50 -07001013void GL_APIENTRY glCullFace(GLenum mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001014{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001015 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001016
Geoff Langb1196682014-07-23 13:47:29 -04001017 gl::Context *context = gl::getNonLostContext();
1018 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001019 {
Geoff Langb1196682014-07-23 13:47:29 -04001020 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001021 {
Geoff Langb1196682014-07-23 13:47:29 -04001022 case GL_FRONT:
1023 case GL_BACK:
1024 case GL_FRONT_AND_BACK:
1025 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001026
Geoff Langb1196682014-07-23 13:47:29 -04001027 default:
1028 context->recordError(gl::Error(GL_INVALID_ENUM));
1029 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001030 }
Geoff Langb1196682014-07-23 13:47:29 -04001031
1032 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001033 }
1034}
1035
Kenneth Russell67ea1902014-10-06 16:44:50 -07001036void GL_APIENTRY glDeleteBuffers(GLsizei n, const GLuint* buffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001038 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001039
Geoff Langbfdea662014-07-23 14:16:32 -04001040 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001041 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001042 {
Geoff Langb1196682014-07-23 13:47:29 -04001043 if (n < 0)
1044 {
1045 context->recordError(gl::Error(GL_INVALID_VALUE));
1046 return;
1047 }
1048
Geoff Langbfdea662014-07-23 14:16:32 -04001049 for (int i = 0; i < n; i++)
1050 {
1051 context->deleteBuffer(buffers[i]);
1052 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001053 }
1054}
1055
Kenneth Russell67ea1902014-10-06 16:44:50 -07001056void GL_APIENTRY glDeleteFencesNV(GLsizei n, const GLuint* fences)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001057{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001058 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001059
Geoff Langbfdea662014-07-23 14:16:32 -04001060 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001061 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001062 {
Geoff Langb1196682014-07-23 13:47:29 -04001063 if (n < 0)
1064 {
1065 context->recordError(gl::Error(GL_INVALID_VALUE));
1066 return;
1067 }
1068
Geoff Langbfdea662014-07-23 14:16:32 -04001069 for (int i = 0; i < n; i++)
1070 {
1071 context->deleteFenceNV(fences[i]);
1072 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001073 }
1074}
1075
Kenneth Russell67ea1902014-10-06 16:44:50 -07001076void GL_APIENTRY glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001077{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001078 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001079
Geoff Langbfdea662014-07-23 14:16:32 -04001080 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001081 if (context)
1082 {
Geoff Langb1196682014-07-23 13:47:29 -04001083 if (n < 0)
1084 {
1085 context->recordError(gl::Error(GL_INVALID_VALUE));
1086 return;
1087 }
1088
Geoff Langbfdea662014-07-23 14:16:32 -04001089 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001090 {
Geoff Langbfdea662014-07-23 14:16:32 -04001091 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001092 {
Geoff Langbfdea662014-07-23 14:16:32 -04001093 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001094 }
1095 }
1096 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001097}
1098
Kenneth Russell67ea1902014-10-06 16:44:50 -07001099void GL_APIENTRY glDeleteProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001101 EVENT("(GLuint program = %d)", program);
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)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001105 {
Geoff Langb1196682014-07-23 13:47:29 -04001106 if (program == 0)
1107 {
1108 return;
1109 }
1110
Geoff Langbfdea662014-07-23 14:16:32 -04001111 if (!context->getProgram(program))
1112 {
1113 if(context->getShader(program))
1114 {
Geoff Langb1196682014-07-23 13:47:29 -04001115 context->recordError(gl::Error(GL_INVALID_OPERATION));
1116 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001117 }
1118 else
1119 {
Geoff Langb1196682014-07-23 13:47:29 -04001120 context->recordError(gl::Error(GL_INVALID_VALUE));
1121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001122 }
1123 }
1124
1125 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001126 }
1127}
1128
Kenneth Russell67ea1902014-10-06 16:44:50 -07001129void GL_APIENTRY glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001130{
1131 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1132
Geoff Langbfdea662014-07-23 14:16:32 -04001133 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001134 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001135 {
Geoff Langb1196682014-07-23 13:47:29 -04001136 if (n < 0)
1137 {
1138 context->recordError(gl::Error(GL_INVALID_VALUE));
1139 return;
1140 }
1141
Geoff Langbfdea662014-07-23 14:16:32 -04001142 for (int i = 0; i < n; i++)
1143 {
1144 context->deleteQuery(ids[i]);
1145 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001146 }
1147}
1148
Kenneth Russell67ea1902014-10-06 16:44:50 -07001149void GL_APIENTRY glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001150{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001151 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001152
Geoff Langbfdea662014-07-23 14:16:32 -04001153 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001154 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001155 {
Geoff Langb1196682014-07-23 13:47:29 -04001156 if (n < 0)
1157 {
1158 context->recordError(gl::Error(GL_INVALID_VALUE));
1159 return;
1160 }
1161
Geoff Langbfdea662014-07-23 14:16:32 -04001162 for (int i = 0; i < n; i++)
1163 {
1164 context->deleteRenderbuffer(renderbuffers[i]);
1165 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001166 }
1167}
1168
Kenneth Russell67ea1902014-10-06 16:44:50 -07001169void GL_APIENTRY glDeleteShader(GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001171 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001172
Geoff Langbfdea662014-07-23 14:16:32 -04001173 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001174 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001175 {
Geoff Langb1196682014-07-23 13:47:29 -04001176 if (shader == 0)
1177 {
1178 return;
1179 }
1180
Geoff Langbfdea662014-07-23 14:16:32 -04001181 if (!context->getShader(shader))
1182 {
1183 if(context->getProgram(shader))
1184 {
Geoff Langb1196682014-07-23 13:47:29 -04001185 context->recordError(gl::Error(GL_INVALID_OPERATION));
1186 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001187 }
1188 else
1189 {
Geoff Langb1196682014-07-23 13:47:29 -04001190 context->recordError(gl::Error(GL_INVALID_VALUE));
1191 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001192 }
1193 }
1194
1195 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001196 }
1197}
1198
Kenneth Russell67ea1902014-10-06 16:44:50 -07001199void GL_APIENTRY glDeleteTextures(GLsizei n, const GLuint* textures)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001200{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001201 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001202
Geoff Langbfdea662014-07-23 14:16:32 -04001203 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001204 if (context)
1205 {
Geoff Langb1196682014-07-23 13:47:29 -04001206 if (n < 0)
1207 {
1208 context->recordError(gl::Error(GL_INVALID_VALUE));
1209 return;
1210 }
1211
Geoff Langbfdea662014-07-23 14:16:32 -04001212 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001213 {
Geoff Langbfdea662014-07-23 14:16:32 -04001214 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001215 {
Geoff Langbfdea662014-07-23 14:16:32 -04001216 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001217 }
1218 }
1219 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001220}
1221
Kenneth Russell67ea1902014-10-06 16:44:50 -07001222void GL_APIENTRY glDepthFunc(GLenum func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001223{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001224 EVENT("(GLenum func = 0x%X)", func);
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)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001228 {
Geoff Langb1196682014-07-23 13:47:29 -04001229 switch (func)
1230 {
1231 case GL_NEVER:
1232 case GL_ALWAYS:
1233 case GL_LESS:
1234 case GL_LEQUAL:
1235 case GL_EQUAL:
1236 case GL_GREATER:
1237 case GL_GEQUAL:
1238 case GL_NOTEQUAL:
1239 context->getState().setDepthFunc(func);
1240 break;
1241
1242 default:
1243 context->recordError(gl::Error(GL_INVALID_ENUM));
1244 return;
1245 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001246 }
1247}
1248
Kenneth Russell67ea1902014-10-06 16:44:50 -07001249void GL_APIENTRY glDepthMask(GLboolean flag)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001250{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001251 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001252
Geoff Langbfdea662014-07-23 14:16:32 -04001253 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001254 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001255 {
Geoff Langbfdea662014-07-23 14:16:32 -04001256 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001257 }
1258}
1259
Kenneth Russell67ea1902014-10-06 16:44:50 -07001260void GL_APIENTRY glDepthRangef(GLclampf zNear, GLclampf zFar)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001261{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001262 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001263
Geoff Langbfdea662014-07-23 14:16:32 -04001264 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001265 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266 {
Geoff Langbfdea662014-07-23 14:16:32 -04001267 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001268 }
1269}
1270
Kenneth Russell67ea1902014-10-06 16:44:50 -07001271void GL_APIENTRY glDetachShader(GLuint program, GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001272{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001273 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001274
Geoff Langbfdea662014-07-23 14:16:32 -04001275 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001276 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277 {
Geoff Langbfdea662014-07-23 14:16:32 -04001278 gl::Program *programObject = context->getProgram(program);
1279 gl::Shader *shaderObject = context->getShader(shader);
1280
1281 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001282 {
Geoff Langbfdea662014-07-23 14:16:32 -04001283 gl::Shader *shaderByProgramHandle;
1284 shaderByProgramHandle = context->getShader(program);
1285 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001286 {
Geoff Langb1196682014-07-23 13:47:29 -04001287 context->recordError(gl::Error(GL_INVALID_VALUE));
1288 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001289 }
Geoff Langbfdea662014-07-23 14:16:32 -04001290 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001291 {
Geoff Langb1196682014-07-23 13:47:29 -04001292 context->recordError(gl::Error(GL_INVALID_OPERATION));
1293 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001294 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001295 }
Geoff Langbfdea662014-07-23 14:16:32 -04001296
1297 if (!shaderObject)
1298 {
1299 gl::Program *programByShaderHandle = context->getProgram(shader);
1300 if (!programByShaderHandle)
1301 {
Geoff Langb1196682014-07-23 13:47:29 -04001302 context->recordError(gl::Error(GL_INVALID_VALUE));
1303 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001304 }
1305 else
1306 {
Geoff Langb1196682014-07-23 13:47:29 -04001307 context->recordError(gl::Error(GL_INVALID_OPERATION));
1308 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001309 }
1310 }
1311
1312 if (!programObject->detachShader(shaderObject))
1313 {
Geoff Langb1196682014-07-23 13:47:29 -04001314 context->recordError(gl::Error(GL_INVALID_OPERATION));
1315 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001317 }
1318}
1319
Kenneth Russell67ea1902014-10-06 16:44:50 -07001320void GL_APIENTRY glDisable(GLenum cap)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001321{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001322 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001323
Geoff Langbfdea662014-07-23 14:16:32 -04001324 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001325 if (context)
1326 {
1327 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001328 {
Geoff Langb1196682014-07-23 13:47:29 -04001329 context->recordError(gl::Error(GL_INVALID_ENUM));
1330 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001331 }
Geoff Langbfdea662014-07-23 14:16:32 -04001332
1333 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001334 }
1335}
1336
Kenneth Russell67ea1902014-10-06 16:44:50 -07001337void GL_APIENTRY glDisableVertexAttribArray(GLuint index)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001338{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001339 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001340
Geoff Langbfdea662014-07-23 14:16:32 -04001341 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001342 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001343 {
Geoff Langb1196682014-07-23 13:47:29 -04001344 if (index >= gl::MAX_VERTEX_ATTRIBS)
1345 {
1346 context->recordError(gl::Error(GL_INVALID_VALUE));
1347 return;
1348 }
1349
Geoff Langbfdea662014-07-23 14:16:32 -04001350 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001351 }
1352}
1353
Kenneth Russell67ea1902014-10-06 16:44:50 -07001354void GL_APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001355{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001356 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001357
Geoff Langbfdea662014-07-23 14:16:32 -04001358 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001359 if (context)
1360 {
Jamie Madill2b976812014-08-25 15:47:49 -04001361 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001362 {
Geoff Langbfdea662014-07-23 14:16:32 -04001363 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001364 }
Geoff Langbfdea662014-07-23 14:16:32 -04001365
Geoff Langc77e8c32014-09-08 16:28:24 -04001366 gl::Error error = context->drawArrays(mode, first, count, 0);
1367 if (error.isError())
1368 {
1369 context->recordError(error);
1370 return;
1371 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001372 }
1373}
1374
Kenneth Russell67ea1902014-10-06 16:44:50 -07001375void GL_APIENTRY glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001376{
1377 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1378
Geoff Langbfdea662014-07-23 14:16:32 -04001379 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001380 if (context)
1381 {
Geoff Lang87a93302014-09-16 13:29:43 -04001382 if (!ValidateDrawArraysInstancedANGLE(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001383 {
Geoff Langbfdea662014-07-23 14:16:32 -04001384 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001385 }
Geoff Langbfdea662014-07-23 14:16:32 -04001386
Geoff Langc77e8c32014-09-08 16:28:24 -04001387 gl::Error error = context->drawArrays(mode, first, count, primcount);
1388 if (error.isError())
1389 {
1390 context->recordError(error);
1391 return;
1392 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001393 }
1394}
1395
Kenneth Russell67ea1902014-10-06 16:44:50 -07001396void GL_APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001397{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001398 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 +00001399 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001400
Geoff Langbfdea662014-07-23 14:16:32 -04001401 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001402 if (context)
1403 {
Jamie Madill2b976812014-08-25 15:47:49 -04001404 rx::RangeUI indexRange;
1405 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001406 {
Geoff Langbfdea662014-07-23 14:16:32 -04001407 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001408 }
Geoff Langbfdea662014-07-23 14:16:32 -04001409
Geoff Langc77e8c32014-09-08 16:28:24 -04001410 gl::Error error = context->drawElements(mode, count, type, indices, 0, indexRange);
1411 if (error.isError())
1412 {
1413 context->recordError(error);
1414 return;
1415 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001416 }
1417}
1418
Kenneth Russell67ea1902014-10-06 16:44:50 -07001419void GL_APIENTRY glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001420{
1421 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1422 mode, count, type, indices, primcount);
1423
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;
Geoff Lang87a93302014-09-16 13:29:43 -04001428 if (!ValidateDrawElementsInstancedANGLE(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001429 {
Geoff Langbfdea662014-07-23 14:16:32 -04001430 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +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, primcount, indexRange);
1434 if (error.isError())
1435 {
1436 context->recordError(error);
1437 return;
1438 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001439 }
1440}
1441
Kenneth Russell67ea1902014-10-06 16:44:50 -07001442void GL_APIENTRY glEnable(GLenum cap)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001443{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001444 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001445
Geoff Langbfdea662014-07-23 14:16:32 -04001446 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001447 if (context)
1448 {
1449 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001450 {
Geoff Langb1196682014-07-23 13:47:29 -04001451 context->recordError(gl::Error(GL_INVALID_ENUM));
1452 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453 }
Geoff Langbfdea662014-07-23 14:16:32 -04001454
1455 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001456 }
1457}
1458
Kenneth Russell67ea1902014-10-06 16:44:50 -07001459void GL_APIENTRY glEnableVertexAttribArray(GLuint index)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001461 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001462
Geoff Langbfdea662014-07-23 14:16:32 -04001463 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001464 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001465 {
Geoff Langb1196682014-07-23 13:47:29 -04001466 if (index >= gl::MAX_VERTEX_ATTRIBS)
1467 {
1468 context->recordError(gl::Error(GL_INVALID_VALUE));
1469 return;
1470 }
1471
Geoff Langbfdea662014-07-23 14:16:32 -04001472 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001473 }
1474}
1475
Kenneth Russell67ea1902014-10-06 16:44:50 -07001476void GL_APIENTRY glEndQueryEXT(GLenum target)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001477{
1478 EVENT("GLenum target = 0x%X)", target);
1479
Geoff Langbfdea662014-07-23 14:16:32 -04001480 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001481 if (context)
1482 {
1483 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001484 {
Geoff Langbfdea662014-07-23 14:16:32 -04001485 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001486 }
Geoff Langbfdea662014-07-23 14:16:32 -04001487
Geoff Lang5aad9672014-09-08 11:10:42 -04001488 gl::Error error = context->endQuery(target);
1489 if (error.isError())
1490 {
1491 context->recordError(error);
1492 return;
1493 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001494 }
1495}
1496
Kenneth Russell67ea1902014-10-06 16:44:50 -07001497void GL_APIENTRY glFinishFenceNV(GLuint fence)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001498{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001499 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001500
Geoff Langbfdea662014-07-23 14:16:32 -04001501 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001502 if (context)
1503 {
1504 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1505
1506 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001507 {
Geoff Langb1196682014-07-23 13:47:29 -04001508 context->recordError(gl::Error(GL_INVALID_OPERATION));
1509 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001510 }
Geoff Langbfdea662014-07-23 14:16:32 -04001511
1512 if (fenceObject->isFence() != GL_TRUE)
1513 {
Geoff Langb1196682014-07-23 13:47:29 -04001514 context->recordError(gl::Error(GL_INVALID_OPERATION));
1515 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001516 }
1517
1518 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001519 }
1520}
1521
Kenneth Russell67ea1902014-10-06 16:44:50 -07001522void GL_APIENTRY glFinish(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001524 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001525
Geoff Langbfdea662014-07-23 14:16:32 -04001526 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001527 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001528 {
Geoff Lang26298562014-10-01 10:49:03 -04001529 gl::Error error = context->sync(true);
1530 if (error.isError())
1531 {
1532 context->recordError(error);
1533 return;
1534 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001535 }
1536}
1537
Kenneth Russell67ea1902014-10-06 16:44:50 -07001538void GL_APIENTRY glFlush(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001539{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001540 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001541
Geoff Langbfdea662014-07-23 14:16:32 -04001542 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001543 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001544 {
Geoff Lang26298562014-10-01 10:49:03 -04001545 gl::Error error = context->sync(false);
1546 if (error.isError())
1547 {
1548 context->recordError(error);
1549 return;
1550 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001551 }
1552}
1553
Kenneth Russell67ea1902014-10-06 16:44:50 -07001554void GL_APIENTRY glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001555{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001556 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001557 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001558
Geoff Langbfdea662014-07-23 14:16:32 -04001559 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001560 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001561 {
Geoff Langb1196682014-07-23 13:47:29 -04001562 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1563 {
1564 context->recordError(gl::Error(GL_INVALID_ENUM));
1565 return;
1566 }
1567
Geoff Langbfdea662014-07-23 14:16:32 -04001568 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1569 {
1570 return;
1571 }
1572
1573 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1574 ASSERT(framebuffer);
1575
1576 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1577 {
1578 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1579 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1580 }
1581 else
1582 {
1583 switch (attachment)
1584 {
1585 case GL_DEPTH_ATTACHMENT:
1586 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1587 break;
1588 case GL_STENCIL_ATTACHMENT:
1589 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1590 break;
1591 case GL_DEPTH_STENCIL_ATTACHMENT:
1592 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1593 break;
1594 default:
1595 UNREACHABLE();
1596 break;
1597 }
1598 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001599 }
1600}
1601
Kenneth Russell67ea1902014-10-06 16:44:50 -07001602void GL_APIENTRY glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001603{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001604 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001605 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001606
Geoff Langbfdea662014-07-23 14:16:32 -04001607 gl::Context *context = gl::getNonLostContext();
1608 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001609 {
Geoff Langbfdea662014-07-23 14:16:32 -04001610 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001611 {
Geoff Langbfdea662014-07-23 14:16:32 -04001612 return;
1613 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001614
Geoff Langbfdea662014-07-23 14:16:32 -04001615 if (texture == 0)
1616 {
1617 textarget = GL_NONE;
1618 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001619
Geoff Langbfdea662014-07-23 14:16:32 -04001620 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001621
Geoff Langbfdea662014-07-23 14:16:32 -04001622 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1623 {
1624 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1625 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1626 }
1627 else
1628 {
1629 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001630 {
Geoff Langbfdea662014-07-23 14:16:32 -04001631 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1632 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1633 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001634 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001635 }
1636 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001637}
1638
Kenneth Russell67ea1902014-10-06 16:44:50 -07001639void GL_APIENTRY glFrontFace(GLenum mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001640{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001641 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001642
Geoff Langb1196682014-07-23 13:47:29 -04001643 gl::Context *context = gl::getNonLostContext();
1644 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001645 {
Geoff Langb1196682014-07-23 13:47:29 -04001646 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001647 {
Geoff Langb1196682014-07-23 13:47:29 -04001648 case GL_CW:
1649 case GL_CCW:
1650 context->getState().setFrontFace(mode);
1651 break;
1652 default:
1653 context->recordError(gl::Error(GL_INVALID_ENUM));
1654 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001655 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001656 }
1657}
1658
Kenneth Russell67ea1902014-10-06 16:44:50 -07001659void GL_APIENTRY glGenBuffers(GLsizei n, GLuint* buffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001660{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001661 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001662
Geoff Langbfdea662014-07-23 14:16:32 -04001663 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001664 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001665 {
Geoff Langb1196682014-07-23 13:47:29 -04001666 if (n < 0)
1667 {
1668 context->recordError(gl::Error(GL_INVALID_VALUE));
1669 return;
1670 }
1671
Geoff Langbfdea662014-07-23 14:16:32 -04001672 for (int i = 0; i < n; i++)
1673 {
1674 buffers[i] = context->createBuffer();
1675 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001676 }
1677}
1678
Kenneth Russell67ea1902014-10-06 16:44:50 -07001679void GL_APIENTRY glGenerateMipmap(GLenum target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001680{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001681 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001682
Geoff Langbfdea662014-07-23 14:16:32 -04001683 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001684 if (context)
1685 {
1686 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001687 {
Geoff Langb1196682014-07-23 13:47:29 -04001688 context->recordError(gl::Error(GL_INVALID_ENUM));
1689 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001690 }
Geoff Langbfdea662014-07-23 14:16:32 -04001691
1692 gl::Texture *texture = context->getTargetTexture(target);
1693
1694 if (texture == NULL)
1695 {
Geoff Langb1196682014-07-23 13:47:29 -04001696 context->recordError(gl::Error(GL_INVALID_OPERATION));
1697 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001698 }
1699
1700 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1701 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001702 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001703
1704 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1705 // unsized formats or that are color renderable and filterable. Since we do not track if
1706 // the texture was created with sized or unsized format (only sized formats are stored),
1707 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1708 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1709 // textures since they're the only texture format that can be created with unsized formats
1710 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1711 // was the last version to use add them.
1712 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1713 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1714 internalFormat == GL_ALPHA8_EXT;
1715
Geoff Lang5d601382014-07-22 15:14:06 -04001716 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1717 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001718 {
Geoff Langb1196682014-07-23 13:47:29 -04001719 context->recordError(gl::Error(GL_INVALID_OPERATION));
1720 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001721 }
1722
1723 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001724 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001725 {
Geoff Langb1196682014-07-23 13:47:29 -04001726 context->recordError(gl::Error(GL_INVALID_OPERATION));
1727 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001728 }
1729
1730 // Non-power of 2 ES2 check
1731 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1732 {
1733 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001734 context->recordError(gl::Error(GL_INVALID_OPERATION));
1735 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001736 }
1737
1738 // Cube completeness check
1739 if (target == GL_TEXTURE_CUBE_MAP)
1740 {
1741 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1742 if (!textureCube->isCubeComplete())
1743 {
Geoff Langb1196682014-07-23 13:47:29 -04001744 context->recordError(gl::Error(GL_INVALID_OPERATION));
1745 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001746 }
1747 }
1748
1749 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001750 }
1751}
1752
Kenneth Russell67ea1902014-10-06 16:44:50 -07001753void GL_APIENTRY glGenFencesNV(GLsizei n, GLuint* fences)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001754{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001755 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001756
Geoff Langbfdea662014-07-23 14:16:32 -04001757 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001758 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001759 {
Geoff Langb1196682014-07-23 13:47:29 -04001760 if (n < 0)
1761 {
1762 context->recordError(gl::Error(GL_INVALID_VALUE));
1763 return;
1764 }
1765
Geoff Langbfdea662014-07-23 14:16:32 -04001766 for (int i = 0; i < n; i++)
1767 {
1768 fences[i] = context->createFenceNV();
1769 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001770 }
1771}
1772
Kenneth Russell67ea1902014-10-06 16:44:50 -07001773void GL_APIENTRY glGenFramebuffers(GLsizei n, GLuint* framebuffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001774{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001775 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001776
Geoff Langbfdea662014-07-23 14:16:32 -04001777 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001778 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001779 {
Geoff Langb1196682014-07-23 13:47:29 -04001780 if (n < 0)
1781 {
1782 context->recordError(gl::Error(GL_INVALID_VALUE));
1783 return;
1784 }
1785
Geoff Langbfdea662014-07-23 14:16:32 -04001786 for (int i = 0; i < n; i++)
1787 {
1788 framebuffers[i] = context->createFramebuffer();
1789 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001790 }
1791}
1792
Kenneth Russell67ea1902014-10-06 16:44:50 -07001793void GL_APIENTRY glGenQueriesEXT(GLsizei n, GLuint* ids)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001794{
1795 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1796
Geoff Langbfdea662014-07-23 14:16:32 -04001797 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001798 if (context)
1799 {
1800 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001801 {
Geoff Langb1196682014-07-23 13:47:29 -04001802 context->recordError(gl::Error(GL_INVALID_VALUE));
1803 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001804 }
Geoff Langbfdea662014-07-23 14:16:32 -04001805
1806 for (GLsizei i = 0; i < n; i++)
1807 {
1808 ids[i] = context->createQuery();
1809 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001810 }
1811}
1812
Kenneth Russell67ea1902014-10-06 16:44:50 -07001813void GL_APIENTRY glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001814{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001815 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001816
Geoff Langbfdea662014-07-23 14:16:32 -04001817 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001818 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001819 {
Geoff Langb1196682014-07-23 13:47:29 -04001820 if (n < 0)
1821 {
1822 context->recordError(gl::Error(GL_INVALID_VALUE));
1823 return;
1824 }
1825
Geoff Langbfdea662014-07-23 14:16:32 -04001826 for (int i = 0; i < n; i++)
1827 {
1828 renderbuffers[i] = context->createRenderbuffer();
1829 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001830 }
1831}
1832
Kenneth Russell67ea1902014-10-06 16:44:50 -07001833void GL_APIENTRY glGenTextures(GLsizei n, GLuint* textures)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001834{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001835 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001836
Geoff Langbfdea662014-07-23 14:16:32 -04001837 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001838 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001839 {
Geoff Langb1196682014-07-23 13:47:29 -04001840 if (n < 0)
1841 {
1842 context->recordError(gl::Error(GL_INVALID_VALUE));
1843 return;
1844 }
1845
Geoff Langbfdea662014-07-23 14:16:32 -04001846 for (int i = 0; i < n; i++)
1847 {
1848 textures[i] = context->createTexture();
1849 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001850 }
1851}
1852
Kenneth Russell67ea1902014-10-06 16:44:50 -07001853void 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 +00001854{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001855 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001856 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001857 program, index, bufsize, length, size, type, name);
1858
Geoff Langbfdea662014-07-23 14:16:32 -04001859 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001860 if (context)
1861 {
Geoff Langb1196682014-07-23 13:47:29 -04001862 if (bufsize < 0)
1863 {
1864 context->recordError(gl::Error(GL_INVALID_VALUE));
1865 return;
1866 }
1867
Geoff Langbfdea662014-07-23 14:16:32 -04001868 gl::Program *programObject = context->getProgram(program);
1869
1870 if (!programObject)
1871 {
1872 if (context->getShader(program))
1873 {
Geoff Langb1196682014-07-23 13:47:29 -04001874 context->recordError(gl::Error(GL_INVALID_OPERATION));
1875 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001876 }
1877 else
1878 {
Geoff Langb1196682014-07-23 13:47:29 -04001879 context->recordError(gl::Error(GL_INVALID_VALUE));
1880 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001881 }
1882 }
1883
1884 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001885 {
Geoff Langb1196682014-07-23 13:47:29 -04001886 context->recordError(gl::Error(GL_INVALID_VALUE));
1887 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001888 }
1889
Geoff Langbfdea662014-07-23 14:16:32 -04001890 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001891 }
1892}
1893
Kenneth Russell67ea1902014-10-06 16:44:50 -07001894void 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 +00001895{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001896 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001897 "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 +00001898 program, index, bufsize, length, size, type, name);
1899
Geoff Langbfdea662014-07-23 14:16:32 -04001900
1901 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001902 if (context)
1903 {
Geoff Langb1196682014-07-23 13:47:29 -04001904 if (bufsize < 0)
1905 {
1906 context->recordError(gl::Error(GL_INVALID_VALUE));
1907 return;
1908 }
1909
Geoff Langbfdea662014-07-23 14:16:32 -04001910 gl::Program *programObject = context->getProgram(program);
1911
1912 if (!programObject)
1913 {
1914 if (context->getShader(program))
1915 {
Geoff Langb1196682014-07-23 13:47:29 -04001916 context->recordError(gl::Error(GL_INVALID_OPERATION));
1917 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001918 }
1919 else
1920 {
Geoff Langb1196682014-07-23 13:47:29 -04001921 context->recordError(gl::Error(GL_INVALID_VALUE));
1922 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001923 }
1924 }
1925
1926 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001927 {
Geoff Langb1196682014-07-23 13:47:29 -04001928 context->recordError(gl::Error(GL_INVALID_VALUE));
1929 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001930 }
1931
Geoff Langbfdea662014-07-23 14:16:32 -04001932 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001933 }
1934}
1935
Kenneth Russell67ea1902014-10-06 16:44:50 -07001936void GL_APIENTRY glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001937{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001938 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 +00001939 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001940
Geoff Langbfdea662014-07-23 14:16:32 -04001941 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001942 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001943 {
Geoff Langb1196682014-07-23 13:47:29 -04001944 if (maxcount < 0)
1945 {
1946 context->recordError(gl::Error(GL_INVALID_VALUE));
1947 return;
1948 }
1949
Geoff Langbfdea662014-07-23 14:16:32 -04001950 gl::Program *programObject = context->getProgram(program);
1951
1952 if (!programObject)
1953 {
1954 if (context->getShader(program))
1955 {
Geoff Langb1196682014-07-23 13:47:29 -04001956 context->recordError(gl::Error(GL_INVALID_OPERATION));
1957 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001958 }
1959 else
1960 {
Geoff Langb1196682014-07-23 13:47:29 -04001961 context->recordError(gl::Error(GL_INVALID_VALUE));
1962 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001963 }
1964 }
1965
1966 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001967 }
1968}
1969
Kenneth Russell67ea1902014-10-06 16:44:50 -07001970GLint GL_APIENTRY glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001971{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001972 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001973
Geoff Langbfdea662014-07-23 14:16:32 -04001974 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001975 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001976 {
Geoff Langbfdea662014-07-23 14:16:32 -04001977 gl::Program *programObject = context->getProgram(program);
1978
1979 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001980 {
Geoff Langbfdea662014-07-23 14:16:32 -04001981 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001982 {
Geoff Langb1196682014-07-23 13:47:29 -04001983 context->recordError(gl::Error(GL_INVALID_OPERATION));
1984 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001985 }
Geoff Langbfdea662014-07-23 14:16:32 -04001986 else
1987 {
Geoff Langb1196682014-07-23 13:47:29 -04001988 context->recordError(gl::Error(GL_INVALID_VALUE));
1989 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001990 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001991 }
Geoff Langbfdea662014-07-23 14:16:32 -04001992
1993 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1994 if (!programObject->isLinked() || !programBinary)
1995 {
Geoff Langb1196682014-07-23 13:47:29 -04001996 context->recordError(gl::Error(GL_INVALID_OPERATION));
1997 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001998 }
1999
2000 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002001 }
2002
2003 return -1;
2004}
2005
Kenneth Russell67ea1902014-10-06 16:44:50 -07002006void GL_APIENTRY glGetBooleanv(GLenum pname, GLboolean* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002007{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002008 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002009
Geoff Langbfdea662014-07-23 14:16:32 -04002010 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002011 if (context)
2012 {
2013 GLenum nativeType;
2014 unsigned int numParams = 0;
2015 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002016 {
Geoff Langbfdea662014-07-23 14:16:32 -04002017 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002018 }
Geoff Langbfdea662014-07-23 14:16:32 -04002019
2020 if (nativeType == GL_BOOL)
2021 {
2022 context->getBooleanv(pname, params);
2023 }
2024 else
2025 {
2026 CastStateValues(context, nativeType, pname, numParams, params);
2027 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002028 }
2029}
2030
Kenneth Russell67ea1902014-10-06 16:44:50 -07002031void GL_APIENTRY glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002032{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002033 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 +00002034
Geoff Langbfdea662014-07-23 14:16:32 -04002035 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002036 if (context)
2037 {
2038 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002039 {
Geoff Langb1196682014-07-23 13:47:29 -04002040 context->recordError(gl::Error(GL_INVALID_ENUM));
2041 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002042 }
Geoff Langbfdea662014-07-23 14:16:32 -04002043
2044 if (!gl::ValidBufferParameter(context, pname))
2045 {
Geoff Langb1196682014-07-23 13:47:29 -04002046 context->recordError(gl::Error(GL_INVALID_ENUM));
2047 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002048 }
2049
2050 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
2051
2052 if (!buffer)
2053 {
2054 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04002055 context->recordError(gl::Error(GL_INVALID_OPERATION));
2056 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002057 }
2058
2059 switch (pname)
2060 {
2061 case GL_BUFFER_USAGE:
2062 *params = static_cast<GLint>(buffer->getUsage());
2063 break;
2064 case GL_BUFFER_SIZE:
2065 *params = gl::clampCast<GLint>(buffer->getSize());
2066 break;
2067 case GL_BUFFER_ACCESS_FLAGS:
2068 *params = buffer->getAccessFlags();
2069 break;
2070 case GL_BUFFER_MAPPED:
2071 *params = static_cast<GLint>(buffer->isMapped());
2072 break;
2073 case GL_BUFFER_MAP_OFFSET:
2074 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2075 break;
2076 case GL_BUFFER_MAP_LENGTH:
2077 *params = gl::clampCast<GLint>(buffer->getMapLength());
2078 break;
2079 default: UNREACHABLE(); break;
2080 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002081 }
2082}
2083
Kenneth Russell67ea1902014-10-06 16:44:50 -07002084GLenum GL_APIENTRY glGetError(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002085{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002086 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002087
2088 gl::Context *context = gl::getContext();
2089
2090 if (context)
2091 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002092 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002093 }
2094
2095 return GL_NO_ERROR;
2096}
2097
Kenneth Russell67ea1902014-10-06 16:44:50 -07002098void GL_APIENTRY glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002099{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002100 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002101
Geoff Langbfdea662014-07-23 14:16:32 -04002102 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002103 if (context)
2104 {
2105 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2106
2107 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002108 {
Geoff Langb1196682014-07-23 13:47:29 -04002109 context->recordError(gl::Error(GL_INVALID_OPERATION));
2110 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002111 }
Geoff Langbfdea662014-07-23 14:16:32 -04002112
2113 if (fenceObject->isFence() != GL_TRUE)
2114 {
Geoff Langb1196682014-07-23 13:47:29 -04002115 context->recordError(gl::Error(GL_INVALID_OPERATION));
2116 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002117 }
2118
2119 switch (pname)
2120 {
2121 case GL_FENCE_STATUS_NV:
2122 case GL_FENCE_CONDITION_NV:
2123 break;
2124
Geoff Langb1196682014-07-23 13:47:29 -04002125 default:
2126 context->recordError(gl::Error(GL_INVALID_ENUM));
2127 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002128 }
2129
Geoff Lang882033e2014-09-30 11:26:07 -04002130 gl::Error error = fenceObject->getFencei(pname, params);
2131 if (error.isError())
2132 {
2133 context->recordError(error);
2134 return;
2135 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002136 }
2137}
2138
Kenneth Russell67ea1902014-10-06 16:44:50 -07002139void GL_APIENTRY glGetFloatv(GLenum pname, GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002140{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002141 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002142
Geoff Langbfdea662014-07-23 14:16:32 -04002143 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002144 if (context)
2145 {
2146 GLenum nativeType;
2147 unsigned int numParams = 0;
2148 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002149 {
Geoff Langbfdea662014-07-23 14:16:32 -04002150 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002151 }
Geoff Langbfdea662014-07-23 14:16:32 -04002152
2153 if (nativeType == GL_FLOAT)
2154 {
2155 context->getFloatv(pname, params);
2156 }
2157 else
2158 {
2159 CastStateValues(context, nativeType, pname, numParams, params);
2160 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002161 }
2162}
2163
Kenneth Russell67ea1902014-10-06 16:44:50 -07002164void GL_APIENTRY glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002165{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002166 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 +00002167 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002168
Geoff Langbfdea662014-07-23 14:16:32 -04002169 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002170 if (context)
2171 {
2172 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002173 {
Geoff Langb1196682014-07-23 13:47:29 -04002174 context->recordError(gl::Error(GL_INVALID_ENUM));
2175 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002176 }
2177
2178 int clientVersion = context->getClientVersion();
2179
2180 switch (pname)
2181 {
2182 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2183 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2184 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2185 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2186 break;
Geoff Langb1196682014-07-23 13:47:29 -04002187
Geoff Langbfdea662014-07-23 14:16:32 -04002188 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2189 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002190 {
Geoff Langb1196682014-07-23 13:47:29 -04002191 context->recordError(gl::Error(GL_INVALID_ENUM));
2192 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002193 }
Geoff Langbfdea662014-07-23 14:16:32 -04002194 break;
Geoff Langb1196682014-07-23 13:47:29 -04002195
Geoff Langbfdea662014-07-23 14:16:32 -04002196 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2197 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2198 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2199 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2200 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2201 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2202 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2203 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2204 if (clientVersion < 3)
2205 {
Geoff Langb1196682014-07-23 13:47:29 -04002206 context->recordError(gl::Error(GL_INVALID_ENUM));
2207 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002208 }
2209 break;
Geoff Langb1196682014-07-23 13:47:29 -04002210
Geoff Langbfdea662014-07-23 14:16:32 -04002211 default:
Geoff Langb1196682014-07-23 13:47:29 -04002212 context->recordError(gl::Error(GL_INVALID_ENUM));
2213 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002214 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002215
Geoff Langbfdea662014-07-23 14:16:32 -04002216 // Determine if the attachment is a valid enum
2217 switch (attachment)
2218 {
2219 case GL_BACK:
2220 case GL_FRONT:
2221 case GL_DEPTH:
2222 case GL_STENCIL:
2223 case GL_DEPTH_STENCIL_ATTACHMENT:
2224 if (clientVersion < 3)
2225 {
Geoff Langb1196682014-07-23 13:47:29 -04002226 context->recordError(gl::Error(GL_INVALID_ENUM));
2227 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002228 }
2229 break;
2230
2231 case GL_DEPTH_ATTACHMENT:
2232 case GL_STENCIL_ATTACHMENT:
2233 break;
2234
2235 default:
2236 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2237 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2238 {
Geoff Langb1196682014-07-23 13:47:29 -04002239 context->recordError(gl::Error(GL_INVALID_ENUM));
2240 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002241 }
2242 break;
2243 }
2244
2245 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2246 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2247
2248 if (framebufferHandle == 0)
2249 {
2250 if (clientVersion < 3)
2251 {
Geoff Langb1196682014-07-23 13:47:29 -04002252 context->recordError(gl::Error(GL_INVALID_OPERATION));
2253 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002254 }
2255
2256 switch (attachment)
2257 {
2258 case GL_BACK:
2259 case GL_DEPTH:
2260 case GL_STENCIL:
2261 break;
Geoff Langb1196682014-07-23 13:47:29 -04002262
Geoff Langbfdea662014-07-23 14:16:32 -04002263 default:
Geoff Langb1196682014-07-23 13:47:29 -04002264 context->recordError(gl::Error(GL_INVALID_OPERATION));
2265 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002266 }
2267 }
2268 else
2269 {
2270 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2271 {
2272 // Valid attachment query
2273 }
2274 else
2275 {
2276 switch (attachment)
2277 {
2278 case GL_DEPTH_ATTACHMENT:
2279 case GL_STENCIL_ATTACHMENT:
2280 break;
Geoff Langb1196682014-07-23 13:47:29 -04002281
Geoff Langbfdea662014-07-23 14:16:32 -04002282 case GL_DEPTH_STENCIL_ATTACHMENT:
2283 if (framebuffer->hasValidDepthStencil())
2284 {
Geoff Langb1196682014-07-23 13:47:29 -04002285 context->recordError(gl::Error(GL_INVALID_OPERATION));
2286 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002287 }
2288 break;
Geoff Langb1196682014-07-23 13:47:29 -04002289
Geoff Langbfdea662014-07-23 14:16:32 -04002290 default:
Geoff Langb1196682014-07-23 13:47:29 -04002291 context->recordError(gl::Error(GL_INVALID_OPERATION));
2292 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002293 }
2294 }
2295 }
2296
2297 GLenum attachmentType = GL_NONE;
2298 GLuint attachmentHandle = 0;
2299 GLuint attachmentLevel = 0;
2300 GLuint attachmentLayer = 0;
2301
2302 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2303
2304 if (attachmentObject)
2305 {
2306 attachmentType = attachmentObject->type();
2307 attachmentHandle = attachmentObject->id();
2308 attachmentLevel = attachmentObject->mipLevel();
2309 attachmentLayer = attachmentObject->layer();
2310 }
2311
2312 GLenum attachmentObjectType; // Type category
2313 if (framebufferHandle == 0)
2314 {
2315 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2316 }
2317 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2318 {
2319 attachmentObjectType = attachmentType;
2320 }
2321 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2322 {
2323 attachmentObjectType = GL_TEXTURE;
2324 }
2325 else
2326 {
2327 UNREACHABLE();
2328 return;
2329 }
2330
2331 if (attachmentObjectType == GL_NONE)
2332 {
2333 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2334 // is NONE, then querying any other pname will generate INVALID_ENUM.
2335
2336 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2337 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2338 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002339
Geoff Lang646559f2013-08-15 11:08:15 -04002340 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002341 {
Geoff Lang646559f2013-08-15 11:08:15 -04002342 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002343 *params = attachmentObjectType;
2344 break;
2345
Geoff Lang646559f2013-08-15 11:08:15 -04002346 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002347 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002348 {
Geoff Langb1196682014-07-23 13:47:29 -04002349 context->recordError(gl::Error(GL_INVALID_ENUM));
2350 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002351 }
Geoff Langbfdea662014-07-23 14:16:32 -04002352 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002353 break;
2354
2355 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002356 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002357 {
Geoff Langb1196682014-07-23 13:47:29 -04002358 context->recordError(gl::Error(GL_INVALID_ENUM));
2359 return;
Geoff Lang646559f2013-08-15 11:08:15 -04002360 }
2361 else
2362 {
Geoff Langb1196682014-07-23 13:47:29 -04002363 context->recordError(gl::Error(GL_INVALID_OPERATION));
2364 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002365 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002366 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002367 }
Geoff Langbfdea662014-07-23 14:16:32 -04002368 else
2369 {
2370 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2371 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2372 ASSERT(attachmentObject != NULL);
2373
2374 switch (pname)
2375 {
2376 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2377 *params = attachmentObjectType;
2378 break;
2379
2380 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2381 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2382 {
Geoff Langb1196682014-07-23 13:47:29 -04002383 context->recordError(gl::Error(GL_INVALID_ENUM));
2384 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002385 }
2386 *params = attachmentHandle;
2387 break;
2388
2389 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2390 if (attachmentObjectType != GL_TEXTURE)
2391 {
Geoff Langb1196682014-07-23 13:47:29 -04002392 context->recordError(gl::Error(GL_INVALID_ENUM));
2393 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002394 }
2395 *params = attachmentLevel;
2396 break;
2397
2398 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2399 if (attachmentObjectType != GL_TEXTURE)
2400 {
Geoff Langb1196682014-07-23 13:47:29 -04002401 context->recordError(gl::Error(GL_INVALID_ENUM));
2402 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002403 }
2404 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2405 break;
2406
2407 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2408 *params = attachmentObject->getRedSize();
2409 break;
2410
2411 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2412 *params = attachmentObject->getGreenSize();
2413 break;
2414
2415 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2416 *params = attachmentObject->getBlueSize();
2417 break;
2418
2419 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2420 *params = attachmentObject->getAlphaSize();
2421 break;
2422
2423 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2424 *params = attachmentObject->getDepthSize();
2425 break;
2426
2427 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2428 *params = attachmentObject->getStencilSize();
2429 break;
2430
2431 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
Jamie Madillee85d1b2014-09-17 10:35:23 -04002432 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT)
Geoff Langbfdea662014-07-23 14:16:32 -04002433 {
Geoff Langb1196682014-07-23 13:47:29 -04002434 context->recordError(gl::Error(GL_INVALID_OPERATION));
2435 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002436 }
2437 *params = attachmentObject->getComponentType();
2438 break;
2439
2440 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2441 *params = attachmentObject->getColorEncoding();
2442 break;
2443
2444 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2445 if (attachmentObjectType != GL_TEXTURE)
2446 {
Geoff Langb1196682014-07-23 13:47:29 -04002447 context->recordError(gl::Error(GL_INVALID_ENUM));
2448 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002449 }
2450 *params = attachmentLayer;
2451 break;
2452
2453 default:
2454 UNREACHABLE();
2455 break;
2456 }
2457 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002458 }
2459}
2460
Kenneth Russell67ea1902014-10-06 16:44:50 -07002461GLenum GL_APIENTRY glGetGraphicsResetStatusEXT(void)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002462{
2463 EVENT("()");
2464
Geoff Langbfdea662014-07-23 14:16:32 -04002465 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002466
Geoff Langbfdea662014-07-23 14:16:32 -04002467 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002468 {
Geoff Langbfdea662014-07-23 14:16:32 -04002469 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002470 }
Geoff Langbfdea662014-07-23 14:16:32 -04002471
2472 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002473}
2474
Kenneth Russell67ea1902014-10-06 16:44:50 -07002475void GL_APIENTRY glGetIntegerv(GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002476{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002477 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002478
Geoff Langbfdea662014-07-23 14:16:32 -04002479 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002480 if (context)
2481 {
2482 GLenum nativeType;
2483 unsigned int numParams = 0;
2484
2485 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002486 {
Geoff Langbfdea662014-07-23 14:16:32 -04002487 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002488 }
Geoff Langbfdea662014-07-23 14:16:32 -04002489
2490 if (nativeType == GL_INT)
2491 {
2492 context->getIntegerv(pname, params);
2493 }
2494 else
2495 {
2496 CastStateValues(context, nativeType, pname, numParams, params);
2497 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002498 }
2499}
2500
Kenneth Russell67ea1902014-10-06 16:44:50 -07002501void GL_APIENTRY glGetProgramiv(GLuint program, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002502{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002503 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002504
Geoff Langbfdea662014-07-23 14:16:32 -04002505 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002506 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002507 {
Geoff Langbfdea662014-07-23 14:16:32 -04002508 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002509
Geoff Langbfdea662014-07-23 14:16:32 -04002510 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002511 {
Geoff Langb1196682014-07-23 13:47:29 -04002512 context->recordError(gl::Error(GL_INVALID_VALUE));
2513 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002514 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002515
Geoff Langbfdea662014-07-23 14:16:32 -04002516 if (context->getClientVersion() < 3)
2517 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002518 switch (pname)
2519 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002520 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002521 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002522 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002523 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002524 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002525 context->recordError(gl::Error(GL_INVALID_ENUM));
2526 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002527 }
2528 }
Geoff Langbfdea662014-07-23 14:16:32 -04002529
2530 switch (pname)
2531 {
2532 case GL_DELETE_STATUS:
2533 *params = programObject->isFlaggedForDeletion();
2534 return;
2535 case GL_LINK_STATUS:
2536 *params = programObject->isLinked();
2537 return;
2538 case GL_VALIDATE_STATUS:
2539 *params = programObject->isValidated();
2540 return;
2541 case GL_INFO_LOG_LENGTH:
2542 *params = programObject->getInfoLogLength();
2543 return;
2544 case GL_ATTACHED_SHADERS:
2545 *params = programObject->getAttachedShadersCount();
2546 return;
2547 case GL_ACTIVE_ATTRIBUTES:
2548 *params = programObject->getActiveAttributeCount();
2549 return;
2550 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2551 *params = programObject->getActiveAttributeMaxLength();
2552 return;
2553 case GL_ACTIVE_UNIFORMS:
2554 *params = programObject->getActiveUniformCount();
2555 return;
2556 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2557 *params = programObject->getActiveUniformMaxLength();
2558 return;
2559 case GL_PROGRAM_BINARY_LENGTH_OES:
2560 *params = programObject->getProgramBinaryLength();
2561 return;
2562 case GL_ACTIVE_UNIFORM_BLOCKS:
2563 *params = programObject->getActiveUniformBlockCount();
2564 return;
2565 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2566 *params = programObject->getActiveUniformBlockMaxLength();
2567 break;
2568 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2569 *params = programObject->getTransformFeedbackBufferMode();
2570 break;
2571 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2572 *params = programObject->getTransformFeedbackVaryingCount();
2573 break;
2574 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2575 *params = programObject->getTransformFeedbackVaryingMaxLength();
2576 break;
Geoff Langb1196682014-07-23 13:47:29 -04002577
Geoff Langbfdea662014-07-23 14:16:32 -04002578 default:
Geoff Langb1196682014-07-23 13:47:29 -04002579 context->recordError(gl::Error(GL_INVALID_ENUM));
2580 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002581 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002582 }
2583}
2584
Kenneth Russell67ea1902014-10-06 16:44:50 -07002585void GL_APIENTRY glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002587 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 +00002588 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002589
Geoff Langbfdea662014-07-23 14:16:32 -04002590 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002591 if (context)
2592 {
Geoff Langb1196682014-07-23 13:47:29 -04002593 if (bufsize < 0)
2594 {
2595 context->recordError(gl::Error(GL_INVALID_VALUE));
2596 return;
2597 }
2598
Geoff Langbfdea662014-07-23 14:16:32 -04002599 gl::Program *programObject = context->getProgram(program);
2600
2601 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002602 {
Geoff Langb1196682014-07-23 13:47:29 -04002603 context->recordError(gl::Error(GL_INVALID_VALUE));
2604 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002605 }
2606
Geoff Langbfdea662014-07-23 14:16:32 -04002607 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002608 }
2609}
2610
Kenneth Russell67ea1902014-10-06 16:44:50 -07002611void GL_APIENTRY glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002612{
2613 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2614
Geoff Langbfdea662014-07-23 14:16:32 -04002615 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002616 if (context)
2617 {
2618 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002619 {
Geoff Langb1196682014-07-23 13:47:29 -04002620 context->recordError(gl::Error(GL_INVALID_ENUM));
2621 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002622 }
Geoff Langbfdea662014-07-23 14:16:32 -04002623
2624 switch (pname)
2625 {
2626 case GL_CURRENT_QUERY_EXT:
2627 params[0] = context->getState().getActiveQueryId(target);
2628 break;
2629
2630 default:
Geoff Langb1196682014-07-23 13:47:29 -04002631 context->recordError(gl::Error(GL_INVALID_ENUM));
2632 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002633 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002634 }
2635}
2636
Kenneth Russell67ea1902014-10-06 16:44:50 -07002637void GL_APIENTRY glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002638{
2639 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2640
Geoff Langbfdea662014-07-23 14:16:32 -04002641 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002642 if (context)
2643 {
2644 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2645
2646 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002647 {
Geoff Langb1196682014-07-23 13:47:29 -04002648 context->recordError(gl::Error(GL_INVALID_OPERATION));
2649 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002650 }
Geoff Langbfdea662014-07-23 14:16:32 -04002651
2652 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2653 {
Geoff Langb1196682014-07-23 13:47:29 -04002654 context->recordError(gl::Error(GL_INVALID_OPERATION));
2655 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002656 }
2657
2658 switch(pname)
2659 {
2660 case GL_QUERY_RESULT_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002661 {
2662 gl::Error error = queryObject->getResult(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 case GL_QUERY_RESULT_AVAILABLE_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002672 {
2673 gl::Error error = queryObject->isResultAvailable(params);
2674 if (error.isError())
2675 {
2676 context->recordError(error);
2677 return;
2678 }
2679 }
Geoff Langbfdea662014-07-23 14:16:32 -04002680 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002681
Geoff Langbfdea662014-07-23 14:16:32 -04002682 default:
Geoff Langb1196682014-07-23 13:47:29 -04002683 context->recordError(gl::Error(GL_INVALID_ENUM));
2684 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002685 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002686 }
2687}
2688
Kenneth Russell67ea1902014-10-06 16:44:50 -07002689void GL_APIENTRY glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002690{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002691 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 +00002692
Geoff Langbfdea662014-07-23 14:16:32 -04002693 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002694 if (context)
2695 {
2696 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002697 {
Geoff Langb1196682014-07-23 13:47:29 -04002698 context->recordError(gl::Error(GL_INVALID_ENUM));
2699 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002700 }
Geoff Langbfdea662014-07-23 14:16:32 -04002701
2702 if (context->getState().getRenderbufferId() == 0)
2703 {
Geoff Langb1196682014-07-23 13:47:29 -04002704 context->recordError(gl::Error(GL_INVALID_OPERATION));
2705 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002706 }
2707
2708 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2709
2710 switch (pname)
2711 {
2712 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2713 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2714 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2715 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2716 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2717 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2718 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2719 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2720 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002721
Geoff Langbfdea662014-07-23 14:16:32 -04002722 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2723 if (!context->getExtensions().framebufferMultisample)
2724 {
Geoff Langb1196682014-07-23 13:47:29 -04002725 context->recordError(gl::Error(GL_INVALID_ENUM));
2726 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002727 }
2728 *params = renderbuffer->getSamples();
2729 break;
Geoff Langb1196682014-07-23 13:47:29 -04002730
Geoff Langbfdea662014-07-23 14:16:32 -04002731 default:
Geoff Langb1196682014-07-23 13:47:29 -04002732 context->recordError(gl::Error(GL_INVALID_ENUM));
2733 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002734 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735 }
2736}
2737
Kenneth Russell67ea1902014-10-06 16:44:50 -07002738void GL_APIENTRY glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002739{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002740 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002741
Geoff Langbfdea662014-07-23 14:16:32 -04002742 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002743 if (context)
2744 {
2745 gl::Shader *shaderObject = context->getShader(shader);
2746
2747 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002748 {
Geoff Langb1196682014-07-23 13:47:29 -04002749 context->recordError(gl::Error(GL_INVALID_VALUE));
2750 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002751 }
Geoff Langbfdea662014-07-23 14:16:32 -04002752
2753 switch (pname)
2754 {
2755 case GL_SHADER_TYPE:
2756 *params = shaderObject->getType();
2757 return;
2758 case GL_DELETE_STATUS:
2759 *params = shaderObject->isFlaggedForDeletion();
2760 return;
2761 case GL_COMPILE_STATUS:
2762 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2763 return;
2764 case GL_INFO_LOG_LENGTH:
2765 *params = shaderObject->getInfoLogLength();
2766 return;
2767 case GL_SHADER_SOURCE_LENGTH:
2768 *params = shaderObject->getSourceLength();
2769 return;
2770 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2771 *params = shaderObject->getTranslatedSourceLength();
2772 return;
Geoff Langb1196682014-07-23 13:47:29 -04002773
Geoff Langbfdea662014-07-23 14:16:32 -04002774 default:
Geoff Langb1196682014-07-23 13:47:29 -04002775 context->recordError(gl::Error(GL_INVALID_ENUM));
2776 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002777 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002778 }
2779}
2780
Kenneth Russell67ea1902014-10-06 16:44:50 -07002781void GL_APIENTRY glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002782{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002783 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 +00002784 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002785
Geoff Langbfdea662014-07-23 14:16:32 -04002786 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002787 if (context)
2788 {
Geoff Langb1196682014-07-23 13:47:29 -04002789 if (bufsize < 0)
2790 {
2791 context->recordError(gl::Error(GL_INVALID_VALUE));
2792 return;
2793 }
2794
Geoff Langbfdea662014-07-23 14:16:32 -04002795 gl::Shader *shaderObject = context->getShader(shader);
2796
2797 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002798 {
Geoff Langb1196682014-07-23 13:47:29 -04002799 context->recordError(gl::Error(GL_INVALID_VALUE));
2800 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002801 }
2802
Geoff Langbfdea662014-07-23 14:16:32 -04002803 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002804 }
2805}
2806
Kenneth Russell67ea1902014-10-06 16:44:50 -07002807void GL_APIENTRY glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002808{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002809 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 +00002810 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002811
Geoff Langb1196682014-07-23 13:47:29 -04002812 gl::Context *context = gl::getNonLostContext();
2813 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002814 {
Geoff Langb1196682014-07-23 13:47:29 -04002815 switch (shadertype)
2816 {
2817 case GL_VERTEX_SHADER:
2818 case GL_FRAGMENT_SHADER:
2819 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002820
Geoff Langb1196682014-07-23 13:47:29 -04002821 default:
2822 context->recordError(gl::Error(GL_INVALID_ENUM));
2823 return;
2824 }
2825
2826 switch (precisiontype)
2827 {
2828 case GL_LOW_FLOAT:
2829 case GL_MEDIUM_FLOAT:
2830 case GL_HIGH_FLOAT:
2831 // Assume IEEE 754 precision
2832 range[0] = 127;
2833 range[1] = 127;
2834 *precision = 23;
2835 break;
2836
2837 case GL_LOW_INT:
2838 case GL_MEDIUM_INT:
2839 case GL_HIGH_INT:
2840 // Some (most) hardware only supports single-precision floating-point numbers,
2841 // which can accurately represent integers up to +/-16777216
2842 range[0] = 24;
2843 range[1] = 24;
2844 *precision = 0;
2845 break;
2846
2847 default:
2848 context->recordError(gl::Error(GL_INVALID_ENUM));
2849 return;
2850 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002851 }
2852}
2853
Kenneth Russell67ea1902014-10-06 16:44:50 -07002854void GL_APIENTRY glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002855{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002856 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 +00002857 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002858
Geoff Langbfdea662014-07-23 14:16:32 -04002859 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002860 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002861 {
Geoff Langb1196682014-07-23 13:47:29 -04002862 if (bufsize < 0)
2863 {
2864 context->recordError(gl::Error(GL_INVALID_VALUE));
2865 return;
2866 }
2867
Geoff Langbfdea662014-07-23 14:16:32 -04002868 gl::Shader *shaderObject = context->getShader(shader);
2869
2870 if (!shaderObject)
2871 {
Geoff Langb1196682014-07-23 13:47:29 -04002872 context->recordError(gl::Error(GL_INVALID_OPERATION));
2873 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002874 }
2875
2876 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002877 }
2878}
2879
Kenneth Russell67ea1902014-10-06 16:44:50 -07002880void GL_APIENTRY glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
zmo@google.coma574f782011-10-03 21:45:23 +00002881{
2882 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2883 shader, bufsize, length, source);
2884
Geoff Langbfdea662014-07-23 14:16:32 -04002885 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002886 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002887 {
Geoff Langb1196682014-07-23 13:47:29 -04002888 if (bufsize < 0)
2889 {
2890 context->recordError(gl::Error(GL_INVALID_VALUE));
2891 return;
2892 }
2893
Geoff Langbfdea662014-07-23 14:16:32 -04002894 gl::Shader *shaderObject = context->getShader(shader);
2895
2896 if (!shaderObject)
2897 {
Geoff Langb1196682014-07-23 13:47:29 -04002898 context->recordError(gl::Error(GL_INVALID_OPERATION));
2899 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002900 }
2901
2902 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002903 }
2904}
2905
Kenneth Russell67ea1902014-10-06 16:44:50 -07002906const GLubyte* GL_APIENTRY glGetString(GLenum name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002907{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002908 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002909
Geoff Langbfdea662014-07-23 14:16:32 -04002910 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002911
Geoff Langbfdea662014-07-23 14:16:32 -04002912 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002913 {
Geoff Langbfdea662014-07-23 14:16:32 -04002914 case GL_VENDOR:
2915 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002916
Geoff Langbfdea662014-07-23 14:16:32 -04002917 case GL_RENDERER:
2918 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002919
Geoff Langbfdea662014-07-23 14:16:32 -04002920 case GL_VERSION:
2921 if (context->getClientVersion() == 2)
2922 {
2923 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2924 }
2925 else
2926 {
2927 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2928 }
Geoff Langb1196682014-07-23 13:47:29 -04002929
Geoff Langbfdea662014-07-23 14:16:32 -04002930 case GL_SHADING_LANGUAGE_VERSION:
2931 if (context->getClientVersion() == 2)
2932 {
2933 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2934 }
2935 else
2936 {
2937 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2938 }
Geoff Langb1196682014-07-23 13:47:29 -04002939
Geoff Langbfdea662014-07-23 14:16:32 -04002940 case GL_EXTENSIONS:
2941 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002942
Geoff Langbfdea662014-07-23 14:16:32 -04002943 default:
Geoff Langb1196682014-07-23 13:47:29 -04002944 if (context)
2945 {
2946 context->recordError(gl::Error(GL_INVALID_ENUM));
2947 }
2948 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002949 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002950}
2951
Kenneth Russell67ea1902014-10-06 16:44:50 -07002952void GL_APIENTRY glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002953{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002954 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 +00002955
Geoff Langbfdea662014-07-23 14:16:32 -04002956 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002957 if (context)
2958 {
2959 gl::Texture *texture = context->getTargetTexture(target);
2960
2961 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002962 {
Geoff Langb1196682014-07-23 13:47:29 -04002963 context->recordError(gl::Error(GL_INVALID_ENUM));
2964 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002965 }
Geoff Langbfdea662014-07-23 14:16:32 -04002966
2967 switch (pname)
2968 {
2969 case GL_TEXTURE_MAG_FILTER:
2970 *params = (GLfloat)texture->getSamplerState().magFilter;
2971 break;
2972 case GL_TEXTURE_MIN_FILTER:
2973 *params = (GLfloat)texture->getSamplerState().minFilter;
2974 break;
2975 case GL_TEXTURE_WRAP_S:
2976 *params = (GLfloat)texture->getSamplerState().wrapS;
2977 break;
2978 case GL_TEXTURE_WRAP_T:
2979 *params = (GLfloat)texture->getSamplerState().wrapT;
2980 break;
2981 case GL_TEXTURE_WRAP_R:
2982 if (context->getClientVersion() < 3)
2983 {
Geoff Langb1196682014-07-23 13:47:29 -04002984 context->recordError(gl::Error(GL_INVALID_ENUM));
2985 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002986 }
2987 *params = (GLfloat)texture->getSamplerState().wrapR;
2988 break;
2989 case GL_TEXTURE_IMMUTABLE_FORMAT:
2990 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2991 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2992 break;
2993 case GL_TEXTURE_IMMUTABLE_LEVELS:
2994 if (context->getClientVersion() < 3)
2995 {
Geoff Langb1196682014-07-23 13:47:29 -04002996 context->recordError(gl::Error(GL_INVALID_ENUM));
2997 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002998 }
2999 *params = (GLfloat)texture->immutableLevelCount();
3000 break;
3001 case GL_TEXTURE_USAGE_ANGLE:
3002 *params = (GLfloat)texture->getUsage();
3003 break;
3004 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3005 if (!context->getExtensions().textureFilterAnisotropic)
3006 {
Geoff Langb1196682014-07-23 13:47:29 -04003007 context->recordError(gl::Error(GL_INVALID_ENUM));
3008 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003009 }
3010 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
3011 break;
3012 case GL_TEXTURE_SWIZZLE_R:
3013 if (context->getClientVersion() < 3)
3014 {
Geoff Langb1196682014-07-23 13:47:29 -04003015 context->recordError(gl::Error(GL_INVALID_ENUM));
3016 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003017 }
3018 *params = (GLfloat)texture->getSamplerState().swizzleRed;
3019 break;
3020 case GL_TEXTURE_SWIZZLE_G:
3021 if (context->getClientVersion() < 3)
3022 {
Geoff Langb1196682014-07-23 13:47:29 -04003023 context->recordError(gl::Error(GL_INVALID_ENUM));
3024 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003025 }
3026 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
3027 break;
3028 case GL_TEXTURE_SWIZZLE_B:
3029 if (context->getClientVersion() < 3)
3030 {
Geoff Langb1196682014-07-23 13:47:29 -04003031 context->recordError(gl::Error(GL_INVALID_ENUM));
3032 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003033 }
3034 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
3035 break;
3036 case GL_TEXTURE_SWIZZLE_A:
3037 if (context->getClientVersion() < 3)
3038 {
Geoff Langb1196682014-07-23 13:47:29 -04003039 context->recordError(gl::Error(GL_INVALID_ENUM));
3040 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003041 }
3042 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
3043 break;
3044 case GL_TEXTURE_BASE_LEVEL:
3045 if (context->getClientVersion() < 3)
3046 {
Geoff Langb1196682014-07-23 13:47:29 -04003047 context->recordError(gl::Error(GL_INVALID_ENUM));
3048 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003049 }
3050 *params = (GLfloat)texture->getSamplerState().baseLevel;
3051 break;
3052 case GL_TEXTURE_MAX_LEVEL:
3053 if (context->getClientVersion() < 3)
3054 {
Geoff Langb1196682014-07-23 13:47:29 -04003055 context->recordError(gl::Error(GL_INVALID_ENUM));
3056 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003057 }
3058 *params = (GLfloat)texture->getSamplerState().maxLevel;
3059 break;
3060 case GL_TEXTURE_MIN_LOD:
3061 if (context->getClientVersion() < 3)
3062 {
Geoff Langb1196682014-07-23 13:47:29 -04003063 context->recordError(gl::Error(GL_INVALID_ENUM));
3064 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003065 }
3066 *params = texture->getSamplerState().minLod;
3067 break;
3068 case GL_TEXTURE_MAX_LOD:
3069 if (context->getClientVersion() < 3)
3070 {
Geoff Langb1196682014-07-23 13:47:29 -04003071 context->recordError(gl::Error(GL_INVALID_ENUM));
3072 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003073 }
3074 *params = texture->getSamplerState().maxLod;
3075 break;
Geoff Langb1196682014-07-23 13:47:29 -04003076
Geoff Langbfdea662014-07-23 14:16:32 -04003077 default:
Geoff Langb1196682014-07-23 13:47:29 -04003078 context->recordError(gl::Error(GL_INVALID_ENUM));
3079 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003080 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003081 }
3082}
3083
Kenneth Russell67ea1902014-10-06 16:44:50 -07003084void GL_APIENTRY glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003085{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003086 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 +00003087
Geoff Langbfdea662014-07-23 14:16:32 -04003088 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003089 if (context)
3090 {
3091 gl::Texture *texture = context->getTargetTexture(target);
3092
3093 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003094 {
Geoff Langb1196682014-07-23 13:47:29 -04003095 context->recordError(gl::Error(GL_INVALID_ENUM));
3096 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003097 }
Geoff Langbfdea662014-07-23 14:16:32 -04003098
3099 switch (pname)
3100 {
3101 case GL_TEXTURE_MAG_FILTER:
3102 *params = texture->getSamplerState().magFilter;
3103 break;
3104 case GL_TEXTURE_MIN_FILTER:
3105 *params = texture->getSamplerState().minFilter;
3106 break;
3107 case GL_TEXTURE_WRAP_S:
3108 *params = texture->getSamplerState().wrapS;
3109 break;
3110 case GL_TEXTURE_WRAP_T:
3111 *params = texture->getSamplerState().wrapT;
3112 break;
3113 case GL_TEXTURE_WRAP_R:
3114 if (context->getClientVersion() < 3)
3115 {
Geoff Langb1196682014-07-23 13:47:29 -04003116 context->recordError(gl::Error(GL_INVALID_ENUM));
3117 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003118 }
3119 *params = texture->getSamplerState().wrapR;
3120 break;
3121 case GL_TEXTURE_IMMUTABLE_FORMAT:
3122 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3123 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3124 break;
3125 case GL_TEXTURE_IMMUTABLE_LEVELS:
3126 if (context->getClientVersion() < 3)
3127 {
Geoff Langb1196682014-07-23 13:47:29 -04003128 context->recordError(gl::Error(GL_INVALID_ENUM));
3129 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003130 }
3131 *params = texture->immutableLevelCount();
3132 break;
3133 case GL_TEXTURE_USAGE_ANGLE:
3134 *params = texture->getUsage();
3135 break;
3136 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3137 if (!context->getExtensions().textureFilterAnisotropic)
3138 {
Geoff Langb1196682014-07-23 13:47:29 -04003139 context->recordError(gl::Error(GL_INVALID_ENUM));
3140 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003141 }
3142 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3143 break;
3144 case GL_TEXTURE_SWIZZLE_R:
3145 if (context->getClientVersion() < 3)
3146 {
Geoff Langb1196682014-07-23 13:47:29 -04003147 context->recordError(gl::Error(GL_INVALID_ENUM));
3148 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003149 }
3150 *params = texture->getSamplerState().swizzleRed;
3151 break;
3152 case GL_TEXTURE_SWIZZLE_G:
3153 if (context->getClientVersion() < 3)
3154 {
Geoff Langb1196682014-07-23 13:47:29 -04003155 context->recordError(gl::Error(GL_INVALID_ENUM));
3156 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003157 }
3158 *params = texture->getSamplerState().swizzleGreen;
3159 break;
3160 case GL_TEXTURE_SWIZZLE_B:
3161 if (context->getClientVersion() < 3)
3162 {
Geoff Langb1196682014-07-23 13:47:29 -04003163 context->recordError(gl::Error(GL_INVALID_ENUM));
3164 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003165 }
3166 *params = texture->getSamplerState().swizzleBlue;
3167 break;
3168 case GL_TEXTURE_SWIZZLE_A:
3169 if (context->getClientVersion() < 3)
3170 {
Geoff Langb1196682014-07-23 13:47:29 -04003171 context->recordError(gl::Error(GL_INVALID_ENUM));
3172 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003173 }
3174 *params = texture->getSamplerState().swizzleAlpha;
3175 break;
3176 case GL_TEXTURE_BASE_LEVEL:
3177 if (context->getClientVersion() < 3)
3178 {
Geoff Langb1196682014-07-23 13:47:29 -04003179 context->recordError(gl::Error(GL_INVALID_ENUM));
3180 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003181 }
3182 *params = texture->getSamplerState().baseLevel;
3183 break;
3184 case GL_TEXTURE_MAX_LEVEL:
3185 if (context->getClientVersion() < 3)
3186 {
Geoff Langb1196682014-07-23 13:47:29 -04003187 context->recordError(gl::Error(GL_INVALID_ENUM));
3188 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003189 }
3190 *params = texture->getSamplerState().maxLevel;
3191 break;
3192 case GL_TEXTURE_MIN_LOD:
3193 if (context->getClientVersion() < 3)
3194 {
Geoff Langb1196682014-07-23 13:47:29 -04003195 context->recordError(gl::Error(GL_INVALID_ENUM));
3196 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003197 }
3198 *params = (GLint)texture->getSamplerState().minLod;
3199 break;
3200 case GL_TEXTURE_MAX_LOD:
3201 if (context->getClientVersion() < 3)
3202 {
Geoff Langb1196682014-07-23 13:47:29 -04003203 context->recordError(gl::Error(GL_INVALID_ENUM));
3204 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003205 }
3206 *params = (GLint)texture->getSamplerState().maxLod;
3207 break;
Geoff Langb1196682014-07-23 13:47:29 -04003208
Geoff Langbfdea662014-07-23 14:16:32 -04003209 default:
Geoff Langb1196682014-07-23 13:47:29 -04003210 context->recordError(gl::Error(GL_INVALID_ENUM));
3211 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003212 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003213 }
3214}
3215
Kenneth Russell67ea1902014-10-06 16:44:50 -07003216void GL_APIENTRY glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003217{
3218 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3219 program, location, bufSize, params);
3220
Geoff Langbfdea662014-07-23 14:16:32 -04003221 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003222 if (context)
3223 {
Jamie Madill0063c512014-08-25 15:47:53 -04003224 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003225 {
Jamie Madill0063c512014-08-25 15:47:53 -04003226 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003227 }
3228
Jamie Madilla502c742014-08-28 17:19:13 -04003229 gl::Program *programObject = context->getProgram(program);
3230 ASSERT(programObject);
3231 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003232 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003233
Jamie Madill99a1e982014-08-25 15:47:54 -04003234 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003235 }
3236}
3237
Kenneth Russell67ea1902014-10-06 16:44:50 -07003238void GL_APIENTRY glGetUniformfv(GLuint program, GLint location, GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003239{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003240 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003241
Geoff Langbfdea662014-07-23 14:16:32 -04003242 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003243 if (context)
3244 {
Jamie Madill0063c512014-08-25 15:47:53 -04003245 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003246 {
Jamie Madill0063c512014-08-25 15:47:53 -04003247 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003248 }
Geoff Langbfdea662014-07-23 14:16:32 -04003249
Jamie Madilla502c742014-08-28 17:19:13 -04003250 gl::Program *programObject = context->getProgram(program);
3251 ASSERT(programObject);
3252 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003253 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003254
Jamie Madill99a1e982014-08-25 15:47:54 -04003255 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003256 }
3257}
3258
Kenneth Russell67ea1902014-10-06 16:44:50 -07003259void GL_APIENTRY glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003260{
Geoff Langbfdea662014-07-23 14:16:32 -04003261 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003262 program, location, bufSize, params);
3263
Geoff Langbfdea662014-07-23 14:16:32 -04003264 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003265 if (context)
3266 {
Jamie Madill0063c512014-08-25 15:47:53 -04003267 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003268 {
Jamie Madill0063c512014-08-25 15:47:53 -04003269 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003270 }
3271
Jamie Madilla502c742014-08-28 17:19:13 -04003272 gl::Program *programObject = context->getProgram(program);
3273 ASSERT(programObject);
3274 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003275 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003276
Jamie Madill99a1e982014-08-25 15:47:54 -04003277 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003278 }
3279}
3280
Kenneth Russell67ea1902014-10-06 16:44:50 -07003281void GL_APIENTRY glGetUniformiv(GLuint program, GLint location, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003282{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003283 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003284
Geoff Langbfdea662014-07-23 14:16:32 -04003285 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003286 if (context)
3287 {
Jamie Madill0063c512014-08-25 15:47:53 -04003288 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003289 {
Jamie Madill0063c512014-08-25 15:47:53 -04003290 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003291 }
Geoff Langbfdea662014-07-23 14:16:32 -04003292
Jamie Madilla502c742014-08-28 17:19:13 -04003293 gl::Program *programObject = context->getProgram(program);
3294 ASSERT(programObject);
3295 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003296 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003297
Jamie Madill99a1e982014-08-25 15:47:54 -04003298 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003299 }
3300}
3301
Kenneth Russell67ea1902014-10-06 16:44:50 -07003302GLint GL_APIENTRY glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003303{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003304 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003305
Geoff Langbfdea662014-07-23 14:16:32 -04003306 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003307 if (context)
3308 {
Geoff Langb1196682014-07-23 13:47:29 -04003309 if (strstr(name, "gl_") == name)
3310 {
3311 return -1;
3312 }
3313
Geoff Langbfdea662014-07-23 14:16:32 -04003314 gl::Program *programObject = context->getProgram(program);
3315
3316 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003317 {
Geoff Langbfdea662014-07-23 14:16:32 -04003318 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003319 {
Geoff Langb1196682014-07-23 13:47:29 -04003320 context->recordError(gl::Error(GL_INVALID_OPERATION));
3321 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003322 }
Geoff Langbfdea662014-07-23 14:16:32 -04003323 else
3324 {
Geoff Langb1196682014-07-23 13:47:29 -04003325 context->recordError(gl::Error(GL_INVALID_VALUE));
3326 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003327 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328 }
Geoff Langbfdea662014-07-23 14:16:32 -04003329
3330 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3331 if (!programObject->isLinked() || !programBinary)
3332 {
Geoff Langb1196682014-07-23 13:47:29 -04003333 context->recordError(gl::Error(GL_INVALID_OPERATION));
3334 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003335 }
3336
3337 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003338 }
3339
3340 return -1;
3341}
3342
Kenneth Russell67ea1902014-10-06 16:44:50 -07003343void GL_APIENTRY glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003344{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003345 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003346
Geoff Langbfdea662014-07-23 14:16:32 -04003347 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003348 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003349 {
Geoff Langbfdea662014-07-23 14:16:32 -04003350 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003351 {
Geoff Langb1196682014-07-23 13:47:29 -04003352 context->recordError(gl::Error(GL_INVALID_VALUE));
3353 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003354 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003355
Geoff Langbfdea662014-07-23 14:16:32 -04003356 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003357 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003358 {
3359 return;
3360 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003361
Geoff Langbfdea662014-07-23 14:16:32 -04003362 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3363 {
3364 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3365 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003366 {
Geoff Langbfdea662014-07-23 14:16:32 -04003367 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003368 }
3369 }
Geoff Langbfdea662014-07-23 14:16:32 -04003370 else
3371 {
3372 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3373 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003374 }
3375}
3376
Kenneth Russell67ea1902014-10-06 16:44:50 -07003377void GL_APIENTRY glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003378{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003379 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003380
Geoff Langbfdea662014-07-23 14:16:32 -04003381 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003382 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003383 {
Geoff Langbfdea662014-07-23 14:16:32 -04003384 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003385 {
Geoff Langb1196682014-07-23 13:47:29 -04003386 context->recordError(gl::Error(GL_INVALID_VALUE));
3387 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003388 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003389
Geoff Langbfdea662014-07-23 14:16:32 -04003390 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003391
Geoff Langb1196682014-07-23 13:47:29 -04003392 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003393 {
3394 return;
3395 }
Jamie Madillaff71502013-07-02 11:57:05 -04003396
Geoff Langbfdea662014-07-23 14:16:32 -04003397 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3398 {
3399 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3400 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003401 {
Geoff Langbfdea662014-07-23 14:16:32 -04003402 float currentValue = currentValueData.FloatValues[i];
3403 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003404 }
3405 }
Geoff Langbfdea662014-07-23 14:16:32 -04003406 else
3407 {
3408 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3409 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003410 }
3411}
3412
Kenneth Russell67ea1902014-10-06 16:44:50 -07003413void GL_APIENTRY glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003414{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003415 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003416
Geoff Langbfdea662014-07-23 14:16:32 -04003417 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003418 if (context)
3419 {
3420 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003421 {
Geoff Langb1196682014-07-23 13:47:29 -04003422 context->recordError(gl::Error(GL_INVALID_VALUE));
3423 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003424 }
Geoff Langbfdea662014-07-23 14:16:32 -04003425
3426 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3427 {
Geoff Langb1196682014-07-23 13:47:29 -04003428 context->recordError(gl::Error(GL_INVALID_ENUM));
3429 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003430 }
3431
3432 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003433 }
3434}
3435
Kenneth Russell67ea1902014-10-06 16:44:50 -07003436void GL_APIENTRY glHint(GLenum target, GLenum mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003437{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003438 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003439
Geoff Langbfdea662014-07-23 14:16:32 -04003440 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003441 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003442 {
Geoff Langb1196682014-07-23 13:47:29 -04003443 switch (mode)
3444 {
3445 case GL_FASTEST:
3446 case GL_NICEST:
3447 case GL_DONT_CARE:
3448 break;
3449
3450 default:
3451 context->recordError(gl::Error(GL_INVALID_ENUM));
3452 return;
3453 }
3454
3455 switch (target)
3456 {
3457 case GL_GENERATE_MIPMAP_HINT:
3458 context->getState().setGenerateMipmapHint(mode);
3459 break;
3460
3461 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3462 context->getState().setFragmentShaderDerivativeHint(mode);
3463 break;
3464
3465 default:
3466 context->recordError(gl::Error(GL_INVALID_ENUM));
3467 return;
3468 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003469 }
3470}
3471
Kenneth Russell67ea1902014-10-06 16:44:50 -07003472GLboolean GL_APIENTRY glIsBuffer(GLuint buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003473{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003474 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003475
Geoff Langbfdea662014-07-23 14:16:32 -04003476 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003477 if (context && buffer)
3478 {
3479 gl::Buffer *bufferObject = context->getBuffer(buffer);
3480
3481 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003482 {
Geoff Langbfdea662014-07-23 14:16:32 -04003483 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003484 }
3485 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003486
3487 return GL_FALSE;
3488}
3489
Kenneth Russell67ea1902014-10-06 16:44:50 -07003490GLboolean GL_APIENTRY glIsEnabled(GLenum cap)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003492 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003493
Geoff Langbfdea662014-07-23 14:16:32 -04003494 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003495 if (context)
3496 {
3497 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003498 {
Geoff Langb1196682014-07-23 13:47:29 -04003499 context->recordError(gl::Error(GL_INVALID_ENUM));
3500 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003501 }
Geoff Langbfdea662014-07-23 14:16:32 -04003502
3503 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003504 }
3505
3506 return false;
3507}
3508
Kenneth Russell67ea1902014-10-06 16:44:50 -07003509GLboolean GL_APIENTRY glIsFenceNV(GLuint fence)
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003510{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003511 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003512
Geoff Langbfdea662014-07-23 14:16:32 -04003513 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003514 if (context)
3515 {
3516 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3517
3518 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003519 {
Geoff Langbfdea662014-07-23 14:16:32 -04003520 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003521 }
Geoff Langbfdea662014-07-23 14:16:32 -04003522
3523 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003524 }
3525
3526 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003527}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003528
Kenneth Russell67ea1902014-10-06 16:44:50 -07003529GLboolean GL_APIENTRY glIsFramebuffer(GLuint framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003530{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003531 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003532
Geoff Langbfdea662014-07-23 14:16:32 -04003533 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003534 if (context && framebuffer)
3535 {
3536 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3537
3538 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003539 {
Geoff Langbfdea662014-07-23 14:16:32 -04003540 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003541 }
3542 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003543
3544 return GL_FALSE;
3545}
3546
Kenneth Russell67ea1902014-10-06 16:44:50 -07003547GLboolean GL_APIENTRY glIsProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003548{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003549 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003550
Geoff Langbfdea662014-07-23 14:16:32 -04003551 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003552 if (context && program)
3553 {
3554 gl::Program *programObject = context->getProgram(program);
3555
3556 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003557 {
Geoff Langbfdea662014-07-23 14:16:32 -04003558 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003559 }
3560 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003561
3562 return GL_FALSE;
3563}
3564
Kenneth Russell67ea1902014-10-06 16:44:50 -07003565GLboolean GL_APIENTRY glIsQueryEXT(GLuint id)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003566{
3567 EVENT("(GLuint id = %d)", id);
3568
Geoff Langbfdea662014-07-23 14:16:32 -04003569 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003570 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003571 {
Geoff Langbfdea662014-07-23 14:16:32 -04003572 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003573 }
3574
3575 return GL_FALSE;
3576}
3577
Kenneth Russell67ea1902014-10-06 16:44:50 -07003578GLboolean GL_APIENTRY glIsRenderbuffer(GLuint renderbuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003579{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003580 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003581
Geoff Langbfdea662014-07-23 14:16:32 -04003582 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003583 if (context && renderbuffer)
3584 {
3585 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3586
3587 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003588 {
Geoff Langbfdea662014-07-23 14:16:32 -04003589 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003590 }
3591 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003592
3593 return GL_FALSE;
3594}
3595
Kenneth Russell67ea1902014-10-06 16:44:50 -07003596GLboolean GL_APIENTRY glIsShader(GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003597{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003598 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003599
Geoff Langbfdea662014-07-23 14:16:32 -04003600 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003601 if (context && shader)
3602 {
3603 gl::Shader *shaderObject = context->getShader(shader);
3604
3605 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606 {
Geoff Langbfdea662014-07-23 14:16:32 -04003607 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003608 }
3609 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003610
3611 return GL_FALSE;
3612}
3613
Kenneth Russell67ea1902014-10-06 16:44:50 -07003614GLboolean GL_APIENTRY glIsTexture(GLuint texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003615{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003616 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617
Geoff Langbfdea662014-07-23 14:16:32 -04003618 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003619 if (context && texture)
3620 {
3621 gl::Texture *textureObject = context->getTexture(texture);
3622
3623 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003624 {
Geoff Langbfdea662014-07-23 14:16:32 -04003625 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003626 }
3627 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003628
3629 return GL_FALSE;
3630}
3631
Kenneth Russell67ea1902014-10-06 16:44:50 -07003632void GL_APIENTRY glLineWidth(GLfloat width)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003633{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003634 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003635
Geoff Langbfdea662014-07-23 14:16:32 -04003636 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003637 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003638 {
Geoff Langb1196682014-07-23 13:47:29 -04003639 if (width <= 0.0f)
3640 {
3641 context->recordError(gl::Error(GL_INVALID_VALUE));
3642 return;
3643 }
3644
Geoff Langbfdea662014-07-23 14:16:32 -04003645 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003646 }
3647}
3648
Kenneth Russell67ea1902014-10-06 16:44:50 -07003649void GL_APIENTRY glLinkProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003650{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003651 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003652
Geoff Langbfdea662014-07-23 14:16:32 -04003653 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003654 if (context)
3655 {
3656 gl::Program *programObject = context->getProgram(program);
3657
3658 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003659 {
Geoff Langbfdea662014-07-23 14:16:32 -04003660 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661 {
Geoff Langb1196682014-07-23 13:47:29 -04003662 context->recordError(gl::Error(GL_INVALID_OPERATION));
3663 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664 }
Geoff Langbfdea662014-07-23 14:16:32 -04003665 else
3666 {
Geoff Langb1196682014-07-23 13:47:29 -04003667 context->recordError(gl::Error(GL_INVALID_VALUE));
3668 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003669 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670 }
Geoff Langbfdea662014-07-23 14:16:32 -04003671
Geoff Langb543aff2014-09-30 14:52:54 -04003672 gl::Error error = context->linkProgram(program);
3673 if (error.isError())
3674 {
3675 context->recordError(error);
3676 return;
3677 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003678 }
3679}
3680
Kenneth Russell67ea1902014-10-06 16:44:50 -07003681void GL_APIENTRY glPixelStorei(GLenum pname, GLint param)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003682{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003683 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003684
Geoff Langbfdea662014-07-23 14:16:32 -04003685 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003686 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003687 {
Geoff Langbfdea662014-07-23 14:16:32 -04003688 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003689 {
Geoff Langbfdea662014-07-23 14:16:32 -04003690 case GL_UNPACK_ALIGNMENT:
3691 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003692 {
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().setUnpackAlignment(param);
3698 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003699
Geoff Langbfdea662014-07-23 14:16:32 -04003700 case GL_PACK_ALIGNMENT:
3701 if (param != 1 && param != 2 && param != 4 && param != 8)
3702 {
Geoff Langb1196682014-07-23 13:47:29 -04003703 context->recordError(gl::Error(GL_INVALID_VALUE));
3704 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003705 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003706
Geoff Langbfdea662014-07-23 14:16:32 -04003707 context->getState().setPackAlignment(param);
3708 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003709
Geoff Langbfdea662014-07-23 14:16:32 -04003710 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3711 context->getState().setPackReverseRowOrder(param != 0);
3712 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003713
Geoff Langbfdea662014-07-23 14:16:32 -04003714 case GL_UNPACK_IMAGE_HEIGHT:
3715 case GL_UNPACK_SKIP_IMAGES:
3716 case GL_UNPACK_ROW_LENGTH:
3717 case GL_UNPACK_SKIP_ROWS:
3718 case GL_UNPACK_SKIP_PIXELS:
3719 case GL_PACK_ROW_LENGTH:
3720 case GL_PACK_SKIP_ROWS:
3721 case GL_PACK_SKIP_PIXELS:
3722 if (context->getClientVersion() < 3)
3723 {
Geoff Langb1196682014-07-23 13:47:29 -04003724 context->recordError(gl::Error(GL_INVALID_ENUM));
3725 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003726 }
Geoff Langbfdea662014-07-23 14:16:32 -04003727 UNIMPLEMENTED();
3728 break;
3729
3730 default:
Geoff Langb1196682014-07-23 13:47:29 -04003731 context->recordError(gl::Error(GL_INVALID_ENUM));
3732 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733 }
3734 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003735}
3736
Kenneth Russell67ea1902014-10-06 16:44:50 -07003737void GL_APIENTRY glPolygonOffset(GLfloat factor, GLfloat units)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003738{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003739 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003740
Geoff Langbfdea662014-07-23 14:16:32 -04003741 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003742 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743 {
Geoff Langbfdea662014-07-23 14:16:32 -04003744 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003745 }
3746}
3747
Kenneth Russell67ea1902014-10-06 16:44:50 -07003748void GL_APIENTRY glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003749 GLenum format, GLenum type, GLsizei bufSize,
3750 GLvoid *data)
3751{
3752 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3753 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3754 x, y, width, height, format, type, bufSize, data);
3755
Geoff Langbfdea662014-07-23 14:16:32 -04003756 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003757 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003758 {
Geoff Langb1196682014-07-23 13:47:29 -04003759 if (width < 0 || height < 0 || bufSize < 0)
3760 {
3761 context->recordError(gl::Error(GL_INVALID_VALUE));
3762 return;
3763 }
3764
Geoff Langbfdea662014-07-23 14:16:32 -04003765 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3766 format, type, &bufSize, data))
3767 {
3768 return;
3769 }
3770
Geoff Lang63d2fc72014-07-25 14:51:41 -04003771 gl::Error error = context->readPixels(x, y, width, height, format, type, &bufSize, data);
3772 if (error.isError())
3773 {
3774 context->recordError(error);
3775 return;
3776 }
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003777 }
3778}
3779
Kenneth Russell67ea1902014-10-06 16:44:50 -07003780void GL_APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003781 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003782{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003783 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003784 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003785 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003786
Geoff Langbfdea662014-07-23 14:16:32 -04003787 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003788 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789 {
Geoff Langb1196682014-07-23 13:47:29 -04003790 if (width < 0 || height < 0)
3791 {
3792 context->recordError(gl::Error(GL_INVALID_VALUE));
3793 return;
3794 }
3795
Geoff Langbfdea662014-07-23 14:16:32 -04003796 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3797 format, type, NULL, pixels))
3798 {
3799 return;
3800 }
3801
Geoff Lang63d2fc72014-07-25 14:51:41 -04003802 gl::Error error = context->readPixels(x, y, width, height, format, type, NULL, pixels);
3803 if (error.isError())
3804 {
3805 context->recordError(error);
3806 return;
3807 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003808 }
3809}
3810
Kenneth Russell67ea1902014-10-06 16:44:50 -07003811void GL_APIENTRY glReleaseShaderCompiler(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003812{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003813 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003814
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003815 gl::Context *context = gl::getNonLostContext();
3816
3817 if (context)
3818 {
3819 context->releaseShaderCompiler();
3820 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003821}
3822
Kenneth Russell67ea1902014-10-06 16:44:50 -07003823void GL_APIENTRY glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003824{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003825 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 +00003826 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003827
Geoff Langbfdea662014-07-23 14:16:32 -04003828 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003829 if (context)
3830 {
3831 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3832 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003833 {
Geoff Langbfdea662014-07-23 14:16:32 -04003834 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003835 }
Geoff Langbfdea662014-07-23 14:16:32 -04003836
3837 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838 }
3839}
3840
Kenneth Russell67ea1902014-10-06 16:44:50 -07003841void GL_APIENTRY glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003842{
3843 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3844}
3845
Kenneth Russell67ea1902014-10-06 16:44:50 -07003846void GL_APIENTRY glSampleCoverage(GLclampf value, GLboolean invert)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003847{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003848 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003849
Geoff Langbfdea662014-07-23 14:16:32 -04003850 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003851
Geoff Langbfdea662014-07-23 14:16:32 -04003852 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003853 {
Geoff Langbfdea662014-07-23 14:16:32 -04003854 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003855 }
3856}
3857
Kenneth Russell67ea1902014-10-06 16:44:50 -07003858void GL_APIENTRY glSetFenceNV(GLuint fence, GLenum condition)
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003859{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003860 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003861
Geoff Langbfdea662014-07-23 14:16:32 -04003862 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003863 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003864 {
Geoff Langb1196682014-07-23 13:47:29 -04003865 if (condition != GL_ALL_COMPLETED_NV)
3866 {
3867 context->recordError(gl::Error(GL_INVALID_ENUM));
3868 return;
3869 }
3870
Geoff Langbfdea662014-07-23 14:16:32 -04003871 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3872
3873 if (fenceObject == NULL)
3874 {
Geoff Langb1196682014-07-23 13:47:29 -04003875 context->recordError(gl::Error(GL_INVALID_OPERATION));
3876 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003877 }
3878
Geoff Lang882033e2014-09-30 11:26:07 -04003879 gl::Error error = fenceObject->setFence(condition);
3880 if (error.isError())
3881 {
3882 context->recordError(error);
3883 return;
3884 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003885 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003886}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003887
Kenneth Russell67ea1902014-10-06 16:44:50 -07003888void GL_APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003889{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003890 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 +00003891
Geoff Langbfdea662014-07-23 14:16:32 -04003892 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003893 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003894 {
Geoff Langb1196682014-07-23 13:47:29 -04003895 if (width < 0 || height < 0)
3896 {
3897 context->recordError(gl::Error(GL_INVALID_VALUE));
3898 return;
3899 }
3900
Geoff Langbfdea662014-07-23 14:16:32 -04003901 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003902 }
3903}
3904
Kenneth Russell67ea1902014-10-06 16:44:50 -07003905void GL_APIENTRY glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003906{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003907 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003908 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003909 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003910
Geoff Lang900013c2014-07-07 11:32:19 -04003911 gl::Context* context = gl::getNonLostContext();
3912 if (context)
3913 {
3914 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3915 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3916 {
Geoff Langb1196682014-07-23 13:47:29 -04003917 context->recordError(gl::Error(GL_INVALID_ENUM));
3918 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003919 }
3920
3921 // No binary shader formats are supported.
3922 UNIMPLEMENTED();
3923 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003924}
3925
Kenneth Russell67ea1902014-10-06 16:44:50 -07003926void GL_APIENTRY glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003927{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003928 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 +00003929 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003930
Geoff Langbfdea662014-07-23 14:16:32 -04003931 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003932 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003933 {
Geoff Langb1196682014-07-23 13:47:29 -04003934 if (count < 0)
3935 {
3936 context->recordError(gl::Error(GL_INVALID_VALUE));
3937 return;
3938 }
3939
Geoff Langbfdea662014-07-23 14:16:32 -04003940 gl::Shader *shaderObject = context->getShader(shader);
3941
3942 if (!shaderObject)
3943 {
3944 if (context->getProgram(shader))
3945 {
Geoff Langb1196682014-07-23 13:47:29 -04003946 context->recordError(gl::Error(GL_INVALID_OPERATION));
3947 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003948 }
3949 else
3950 {
Geoff Langb1196682014-07-23 13:47:29 -04003951 context->recordError(gl::Error(GL_INVALID_VALUE));
3952 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003953 }
3954 }
3955
3956 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003957 }
3958}
3959
Kenneth Russell67ea1902014-10-06 16:44:50 -07003960void GL_APIENTRY glStencilFunc(GLenum func, GLint ref, GLuint mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003961{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003962 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003963}
3964
Kenneth Russell67ea1902014-10-06 16:44:50 -07003965void GL_APIENTRY glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003966{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003967 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 +00003968
Geoff Langbfdea662014-07-23 14:16:32 -04003969 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003970 if (context)
3971 {
Geoff Langb1196682014-07-23 13:47:29 -04003972 switch (face)
3973 {
3974 case GL_FRONT:
3975 case GL_BACK:
3976 case GL_FRONT_AND_BACK:
3977 break;
3978
3979 default:
3980 context->recordError(gl::Error(GL_INVALID_ENUM));
3981 return;
3982 }
3983
3984 switch (func)
3985 {
3986 case GL_NEVER:
3987 case GL_ALWAYS:
3988 case GL_LESS:
3989 case GL_LEQUAL:
3990 case GL_EQUAL:
3991 case GL_GEQUAL:
3992 case GL_GREATER:
3993 case GL_NOTEQUAL:
3994 break;
3995
3996 default:
3997 context->recordError(gl::Error(GL_INVALID_ENUM));
3998 return;
3999 }
4000
Geoff Langbfdea662014-07-23 14:16:32 -04004001 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4002 {
4003 context->getState().setStencilParams(func, ref, mask);
4004 }
4005
4006 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4007 {
4008 context->getState().setStencilBackParams(func, ref, mask);
4009 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004010 }
4011}
4012
Kenneth Russell67ea1902014-10-06 16:44:50 -07004013void GL_APIENTRY glStencilMask(GLuint mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004014{
4015 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4016}
4017
Kenneth Russell67ea1902014-10-06 16:44:50 -07004018void GL_APIENTRY glStencilMaskSeparate(GLenum face, GLuint mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004019{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004020 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004021
Geoff Langbfdea662014-07-23 14:16:32 -04004022 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004023 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004024 {
Geoff Langb1196682014-07-23 13:47:29 -04004025 switch (face)
4026 {
4027 case GL_FRONT:
4028 case GL_BACK:
4029 case GL_FRONT_AND_BACK:
4030 break;
4031
4032 default:
4033 context->recordError(gl::Error(GL_INVALID_ENUM));
4034 return;
4035 }
4036
Geoff Langbfdea662014-07-23 14:16:32 -04004037 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4038 {
4039 context->getState().setStencilWritemask(mask);
4040 }
4041
4042 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4043 {
4044 context->getState().setStencilBackWritemask(mask);
4045 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047}
4048
Kenneth Russell67ea1902014-10-06 16:44:50 -07004049void GL_APIENTRY glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004050{
4051 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4052}
4053
Kenneth Russell67ea1902014-10-06 16:44:50 -07004054void GL_APIENTRY glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004055{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004056 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 +00004057 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004058
Geoff Langbfdea662014-07-23 14:16:32 -04004059 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004060 if (context)
4061 {
Geoff Langb1196682014-07-23 13:47:29 -04004062 switch (face)
4063 {
4064 case GL_FRONT:
4065 case GL_BACK:
4066 case GL_FRONT_AND_BACK:
4067 break;
4068
4069 default:
4070 context->recordError(gl::Error(GL_INVALID_ENUM));
4071 return;
4072 }
4073
4074 switch (fail)
4075 {
4076 case GL_ZERO:
4077 case GL_KEEP:
4078 case GL_REPLACE:
4079 case GL_INCR:
4080 case GL_DECR:
4081 case GL_INVERT:
4082 case GL_INCR_WRAP:
4083 case GL_DECR_WRAP:
4084 break;
4085
4086 default:
4087 context->recordError(gl::Error(GL_INVALID_ENUM));
4088 return;
4089 }
4090
4091 switch (zfail)
4092 {
4093 case GL_ZERO:
4094 case GL_KEEP:
4095 case GL_REPLACE:
4096 case GL_INCR:
4097 case GL_DECR:
4098 case GL_INVERT:
4099 case GL_INCR_WRAP:
4100 case GL_DECR_WRAP:
4101 break;
4102
4103 default:
4104 context->recordError(gl::Error(GL_INVALID_ENUM));
4105 return;
4106 }
4107
4108 switch (zpass)
4109 {
4110 case GL_ZERO:
4111 case GL_KEEP:
4112 case GL_REPLACE:
4113 case GL_INCR:
4114 case GL_DECR:
4115 case GL_INVERT:
4116 case GL_INCR_WRAP:
4117 case GL_DECR_WRAP:
4118 break;
4119
4120 default:
4121 context->recordError(gl::Error(GL_INVALID_ENUM));
4122 return;
4123 }
4124
Geoff Langbfdea662014-07-23 14:16:32 -04004125 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4126 {
4127 context->getState().setStencilOperations(fail, zfail, zpass);
4128 }
4129
4130 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4131 {
4132 context->getState().setStencilBackOperations(fail, zfail, zpass);
4133 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004134 }
4135}
4136
Kenneth Russell67ea1902014-10-06 16:44:50 -07004137GLboolean GL_APIENTRY glTestFenceNV(GLuint fence)
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004138{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004139 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004140
Geoff Langbfdea662014-07-23 14:16:32 -04004141 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004142 if (context)
4143 {
4144 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4145
4146 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004147 {
Geoff Langb1196682014-07-23 13:47:29 -04004148 context->recordError(gl::Error(GL_INVALID_OPERATION));
4149 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004150 }
Geoff Langbfdea662014-07-23 14:16:32 -04004151
4152 if (fenceObject->isFence() != GL_TRUE)
4153 {
Geoff Langb1196682014-07-23 13:47:29 -04004154 context->recordError(gl::Error(GL_INVALID_OPERATION));
4155 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004156 }
4157
Geoff Lang882033e2014-09-30 11:26:07 -04004158 GLboolean result;
4159 gl::Error error = fenceObject->testFence(&result);
4160 if (error.isError())
4161 {
4162 context->recordError(error);
4163 return GL_TRUE;
4164 }
4165
4166 return result;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004167 }
Geoff Langbfdea662014-07-23 14:16:32 -04004168
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004169 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004170}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004171
Kenneth Russell67ea1902014-10-06 16:44:50 -07004172void GL_APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004173 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004174{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004175 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004176 "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 +00004177 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004178
Geoff Langbfdea662014-07-23 14:16:32 -04004179 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004180 if (context)
4181 {
4182 if (context->getClientVersion() < 3 &&
4183 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4184 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004185 {
Geoff Langbfdea662014-07-23 14:16:32 -04004186 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004187 }
Geoff Langbfdea662014-07-23 14:16:32 -04004188
4189 if (context->getClientVersion() >= 3 &&
4190 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4191 0, 0, 0, width, height, 1, border, format, type, pixels))
4192 {
4193 return;
4194 }
4195
4196 switch (target)
4197 {
4198 case GL_TEXTURE_2D:
4199 {
4200 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004201 gl::Error error = texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4202 if (error.isError())
4203 {
4204 context->recordError(error);
4205 return;
4206 }
Geoff Langbfdea662014-07-23 14:16:32 -04004207 }
4208 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004209
Geoff Langbfdea662014-07-23 14:16:32 -04004210 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004211 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004212 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004213 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004214 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
Geoff Langbfdea662014-07-23 14:16:32 -04004215 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4216 {
4217 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang8376cea2014-09-02 11:47:07 -04004218 gl::Error error = texture->setImage(target, level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004219 if (error.isError())
4220 {
4221 context->recordError(error);
4222 return;
4223 }
Geoff Langbfdea662014-07-23 14:16:32 -04004224 }
4225 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004226
Geoff Langbfdea662014-07-23 14:16:32 -04004227 default: UNREACHABLE();
4228 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004229 }
4230}
4231
Kenneth Russell67ea1902014-10-06 16:44:50 -07004232void GL_APIENTRY glTexParameterf(GLenum target, GLenum pname, GLfloat param)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004233{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004234 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4235
Geoff Langbfdea662014-07-23 14:16:32 -04004236 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004237 if (context)
4238 {
4239 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004240 {
Geoff Langbfdea662014-07-23 14:16:32 -04004241 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004242 }
Geoff Langbfdea662014-07-23 14:16:32 -04004243
4244 gl::Texture *texture = context->getTargetTexture(target);
4245
4246 if (!texture)
4247 {
Geoff Langb1196682014-07-23 13:47:29 -04004248 context->recordError(gl::Error(GL_INVALID_ENUM));
4249 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004250 }
4251
4252 switch (pname)
4253 {
4254 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4255 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4256 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4257 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4258 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4259 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4260 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4261 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4262 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4263 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4264 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4265 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4266 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4267 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4268 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4269 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4270 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4271 default: UNREACHABLE(); break;
4272 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004273 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004274}
4275
Kenneth Russell67ea1902014-10-06 16:44:50 -07004276void GL_APIENTRY glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004277{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004278 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004279}
4280
Kenneth Russell67ea1902014-10-06 16:44:50 -07004281void GL_APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004282{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004283 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004284
Geoff Langbfdea662014-07-23 14:16:32 -04004285 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004286 if (context)
4287 {
4288 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004289 {
Geoff Langbfdea662014-07-23 14:16:32 -04004290 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291 }
Geoff Langbfdea662014-07-23 14:16:32 -04004292
4293 gl::Texture *texture = context->getTargetTexture(target);
4294
4295 if (!texture)
4296 {
Geoff Langb1196682014-07-23 13:47:29 -04004297 context->recordError(gl::Error(GL_INVALID_ENUM));
4298 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004299 }
4300
4301 switch (pname)
4302 {
4303 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4304 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4305 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4306 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4307 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4308 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4309 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4310 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4311 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4312 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4313 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4314 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4315 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4316 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4317 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4318 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4319 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4320 default: UNREACHABLE(); break;
4321 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004322 }
4323}
4324
Kenneth Russell67ea1902014-10-06 16:44:50 -07004325void GL_APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004326{
4327 glTexParameteri(target, pname, *params);
4328}
4329
Kenneth Russell67ea1902014-10-06 16:44:50 -07004330void GL_APIENTRY glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004331{
4332 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4333 target, levels, internalformat, width, height);
4334
Geoff Langbfdea662014-07-23 14:16:32 -04004335 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004336 if (context)
4337 {
4338 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004339 {
Geoff Langb1196682014-07-23 13:47:29 -04004340 context->recordError(gl::Error(GL_INVALID_OPERATION));
4341 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004342 }
Geoff Langbfdea662014-07-23 14:16:32 -04004343
4344 if (context->getClientVersion() < 3 &&
4345 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4346 {
4347 return;
4348 }
4349
4350 if (context->getClientVersion() >= 3 &&
4351 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4352 {
4353 return;
4354 }
4355
4356 switch (target)
4357 {
4358 case GL_TEXTURE_2D:
4359 {
4360 gl::Texture2D *texture2d = context->getTexture2D();
4361 texture2d->storage(levels, internalformat, width, height);
4362 }
4363 break;
4364
4365 case GL_TEXTURE_CUBE_MAP:
4366 {
4367 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4368 textureCube->storage(levels, internalformat, width);
4369 }
4370 break;
4371
4372 default:
Geoff Langb1196682014-07-23 13:47:29 -04004373 context->recordError(gl::Error(GL_INVALID_ENUM));
4374 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004375 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004376 }
4377}
4378
Kenneth Russell67ea1902014-10-06 16:44:50 -07004379void GL_APIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004380 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004381{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004382 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004383 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004384 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004385 target, level, xoffset, yoffset, width, height, format, type, pixels);
4386
Geoff Langbfdea662014-07-23 14:16:32 -04004387 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004388 if (context)
4389 {
4390 if (context->getClientVersion() < 3 &&
4391 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4392 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004393 {
Geoff Langbfdea662014-07-23 14:16:32 -04004394 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004395 }
Geoff Langbfdea662014-07-23 14:16:32 -04004396
4397 if (context->getClientVersion() >= 3 &&
4398 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4399 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4400 {
4401 return;
4402 }
4403
4404 // Zero sized uploads are valid but no-ops
4405 if (width == 0 || height == 0)
4406 {
4407 return;
4408 }
4409
4410 switch (target)
4411 {
4412 case GL_TEXTURE_2D:
4413 {
4414 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004415 gl::Error error = texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4416 if (error.isError())
4417 {
4418 context->recordError(error);
4419 return;
4420 }
Geoff Langbfdea662014-07-23 14:16:32 -04004421 }
4422 break;
4423
4424 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4425 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4426 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4427 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4428 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4429 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4430 {
4431 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004432 gl::Error error = texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4433 if (error.isError())
4434 {
4435 context->recordError(error);
4436 return;
4437 }
Geoff Langbfdea662014-07-23 14:16:32 -04004438 }
4439 break;
4440
4441 default:
4442 UNREACHABLE();
4443 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004444 }
4445}
4446
Kenneth Russell67ea1902014-10-06 16:44:50 -07004447void GL_APIENTRY glUniform1f(GLint location, GLfloat x)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004448{
4449 glUniform1fv(location, 1, &x);
4450}
4451
Kenneth Russell67ea1902014-10-06 16:44:50 -07004452void GL_APIENTRY glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004453{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004454 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004455
Geoff Langbfdea662014-07-23 14:16:32 -04004456 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004457 if (context)
4458 {
4459 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004460 {
Geoff Langbfdea662014-07-23 14:16:32 -04004461 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004462 }
Geoff Langbfdea662014-07-23 14:16:32 -04004463
4464 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4465 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004466 }
4467}
4468
Kenneth Russell67ea1902014-10-06 16:44:50 -07004469void GL_APIENTRY glUniform1i(GLint location, GLint x)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004470{
4471 glUniform1iv(location, 1, &x);
4472}
4473
Kenneth Russell67ea1902014-10-06 16:44:50 -07004474void GL_APIENTRY glUniform1iv(GLint location, GLsizei count, const GLint* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004475{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004476 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004477
Geoff Langbfdea662014-07-23 14:16:32 -04004478 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004479 if (context)
4480 {
4481 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004482 {
Geoff Langbfdea662014-07-23 14:16:32 -04004483 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004484 }
Geoff Langbfdea662014-07-23 14:16:32 -04004485
4486 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4487 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004488 }
4489}
4490
Kenneth Russell67ea1902014-10-06 16:44:50 -07004491void GL_APIENTRY glUniform2f(GLint location, GLfloat x, GLfloat y)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004492{
4493 GLfloat xy[2] = {x, y};
4494
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004495 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004496}
4497
Kenneth Russell67ea1902014-10-06 16:44:50 -07004498void GL_APIENTRY glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004499{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004500 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004501
Geoff Langbfdea662014-07-23 14:16:32 -04004502 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004503 if (context)
4504 {
4505 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004506 {
Geoff Langbfdea662014-07-23 14:16:32 -04004507 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508 }
Geoff Langbfdea662014-07-23 14:16:32 -04004509
4510 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4511 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004512 }
4513}
4514
Kenneth Russell67ea1902014-10-06 16:44:50 -07004515void GL_APIENTRY glUniform2i(GLint location, GLint x, GLint y)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004516{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004517 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004518
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004519 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004520}
4521
Kenneth Russell67ea1902014-10-06 16:44:50 -07004522void GL_APIENTRY glUniform2iv(GLint location, GLsizei count, const GLint* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004524 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004525
Geoff Langbfdea662014-07-23 14:16:32 -04004526 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004527 if (context)
4528 {
4529 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004530 {
Geoff Langbfdea662014-07-23 14:16:32 -04004531 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004532 }
Geoff Langbfdea662014-07-23 14:16:32 -04004533
4534 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4535 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004536 }
4537}
4538
Kenneth Russell67ea1902014-10-06 16:44:50 -07004539void GL_APIENTRY glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004540{
4541 GLfloat xyz[3] = {x, y, z};
4542
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004543 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004544}
4545
Kenneth Russell67ea1902014-10-06 16:44:50 -07004546void GL_APIENTRY glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004547{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004548 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004549
Geoff Langbfdea662014-07-23 14:16:32 -04004550 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004551 if (context)
4552 {
4553 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004554 {
Geoff Langbfdea662014-07-23 14:16:32 -04004555 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004556 }
Geoff Langbfdea662014-07-23 14:16:32 -04004557
4558 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4559 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004560 }
4561}
4562
Kenneth Russell67ea1902014-10-06 16:44:50 -07004563void GL_APIENTRY glUniform3i(GLint location, GLint x, GLint y, GLint z)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004564{
4565 GLint xyz[3] = {x, y, z};
4566
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004567 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004568}
4569
Kenneth Russell67ea1902014-10-06 16:44:50 -07004570void GL_APIENTRY glUniform3iv(GLint location, GLsizei count, const GLint* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004572 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573
Geoff Langbfdea662014-07-23 14:16:32 -04004574 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004575 if (context)
4576 {
4577 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004578 {
Geoff Langbfdea662014-07-23 14:16:32 -04004579 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004580 }
Geoff Langbfdea662014-07-23 14:16:32 -04004581
4582 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4583 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004584 }
4585}
4586
Kenneth Russell67ea1902014-10-06 16:44:50 -07004587void GL_APIENTRY glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004588{
4589 GLfloat xyzw[4] = {x, y, z, w};
4590
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004591 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004592}
4593
Kenneth Russell67ea1902014-10-06 16:44:50 -07004594void GL_APIENTRY glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004596 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004597
Geoff Langbfdea662014-07-23 14:16:32 -04004598 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004599 if (context)
4600 {
4601 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004602 {
Geoff Langbfdea662014-07-23 14:16:32 -04004603 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004604 }
Geoff Langbfdea662014-07-23 14:16:32 -04004605
4606 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4607 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004608 }
4609}
4610
Kenneth Russell67ea1902014-10-06 16:44:50 -07004611void GL_APIENTRY glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004612{
4613 GLint xyzw[4] = {x, y, z, w};
4614
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004615 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004616}
4617
Kenneth Russell67ea1902014-10-06 16:44:50 -07004618void GL_APIENTRY glUniform4iv(GLint location, GLsizei count, const GLint* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004620 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004621
Geoff Langbfdea662014-07-23 14:16:32 -04004622 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004623 if (context)
4624 {
4625 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004626 {
Geoff Langbfdea662014-07-23 14:16:32 -04004627 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004628 }
Geoff Langbfdea662014-07-23 14:16:32 -04004629
4630 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4631 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004632 }
4633}
4634
Kenneth Russell67ea1902014-10-06 16:44:50 -07004635void GL_APIENTRY glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004636{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004637 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004638 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004639
Geoff Langbfdea662014-07-23 14:16:32 -04004640 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004641 if (context)
4642 {
4643 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004644 {
Geoff Langbfdea662014-07-23 14:16:32 -04004645 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004646 }
Geoff Langbfdea662014-07-23 14:16:32 -04004647
4648 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4649 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004650 }
4651}
4652
Kenneth Russell67ea1902014-10-06 16:44:50 -07004653void GL_APIENTRY glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004654{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004655 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004656 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004657
Geoff Langbfdea662014-07-23 14:16:32 -04004658 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004659 if (context)
4660 {
4661 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004662 {
Geoff Langbfdea662014-07-23 14:16:32 -04004663 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004664 }
Geoff Langbfdea662014-07-23 14:16:32 -04004665
4666 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4667 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004668 }
4669}
4670
Kenneth Russell67ea1902014-10-06 16:44:50 -07004671void GL_APIENTRY glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004672{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004673 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004674 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004675
Geoff Langbfdea662014-07-23 14:16:32 -04004676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004677 if (context)
4678 {
4679 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004680 {
Geoff Langbfdea662014-07-23 14:16:32 -04004681 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004682 }
Geoff Langbfdea662014-07-23 14:16:32 -04004683
4684 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4685 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004686 }
4687}
4688
Kenneth Russell67ea1902014-10-06 16:44:50 -07004689void GL_APIENTRY glUseProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004690{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004691 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004692
Geoff Langbfdea662014-07-23 14:16:32 -04004693 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004694 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004695 {
Geoff Langbfdea662014-07-23 14:16:32 -04004696 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004697
Geoff Langbfdea662014-07-23 14:16:32 -04004698 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004699 {
Geoff Langbfdea662014-07-23 14:16:32 -04004700 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004701 {
Geoff Langb1196682014-07-23 13:47:29 -04004702 context->recordError(gl::Error(GL_INVALID_OPERATION));
4703 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004704 }
Geoff Langbfdea662014-07-23 14:16:32 -04004705 else
4706 {
Geoff Langb1196682014-07-23 13:47:29 -04004707 context->recordError(gl::Error(GL_INVALID_VALUE));
4708 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004709 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004710 }
Geoff Langbfdea662014-07-23 14:16:32 -04004711
4712 if (program != 0 && !programObject->isLinked())
4713 {
Geoff Langb1196682014-07-23 13:47:29 -04004714 context->recordError(gl::Error(GL_INVALID_OPERATION));
4715 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004716 }
4717
4718 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004719 }
4720}
4721
Kenneth Russell67ea1902014-10-06 16:44:50 -07004722void GL_APIENTRY glValidateProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004723{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004724 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004725
Geoff Langbfdea662014-07-23 14:16:32 -04004726 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004727 if (context)
4728 {
4729 gl::Program *programObject = context->getProgram(program);
4730
4731 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004732 {
Geoff Langbfdea662014-07-23 14:16:32 -04004733 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004734 {
Geoff Langb1196682014-07-23 13:47:29 -04004735 context->recordError(gl::Error(GL_INVALID_OPERATION));
4736 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004737 }
Geoff Langbfdea662014-07-23 14:16:32 -04004738 else
4739 {
Geoff Langb1196682014-07-23 13:47:29 -04004740 context->recordError(gl::Error(GL_INVALID_VALUE));
4741 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004742 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004743 }
Geoff Langbfdea662014-07-23 14:16:32 -04004744
Brandon Jones43a53e22014-08-28 16:23:22 -07004745 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004746 }
4747}
4748
Kenneth Russell67ea1902014-10-06 16:44:50 -07004749void GL_APIENTRY glVertexAttrib1f(GLuint index, GLfloat x)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004750{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004751 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004752
Geoff Langbfdea662014-07-23 14:16:32 -04004753 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004754 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004755 {
Geoff Langb1196682014-07-23 13:47:29 -04004756 if (index >= gl::MAX_VERTEX_ATTRIBS)
4757 {
4758 context->recordError(gl::Error(GL_INVALID_VALUE));
4759 return;
4760 }
4761
Geoff Langbfdea662014-07-23 14:16:32 -04004762 GLfloat vals[4] = { x, 0, 0, 1 };
4763 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004764 }
4765}
4766
Kenneth Russell67ea1902014-10-06 16:44:50 -07004767void GL_APIENTRY glVertexAttrib1fv(GLuint index, const GLfloat* values)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004768{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004769 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004770
Geoff Langbfdea662014-07-23 14:16:32 -04004771 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004772 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004773 {
Geoff Langb1196682014-07-23 13:47:29 -04004774 if (index >= gl::MAX_VERTEX_ATTRIBS)
4775 {
4776 context->recordError(gl::Error(GL_INVALID_VALUE));
4777 return;
4778 }
4779
Geoff Langbfdea662014-07-23 14:16:32 -04004780 GLfloat vals[4] = { values[0], 0, 0, 1 };
4781 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004782 }
4783}
4784
Kenneth Russell67ea1902014-10-06 16:44:50 -07004785void GL_APIENTRY glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004786{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004787 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004788
Geoff Langbfdea662014-07-23 14:16:32 -04004789 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004790 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004791 {
Geoff Langb1196682014-07-23 13:47:29 -04004792 if (index >= gl::MAX_VERTEX_ATTRIBS)
4793 {
4794 context->recordError(gl::Error(GL_INVALID_VALUE));
4795 return;
4796 }
4797
Geoff Langbfdea662014-07-23 14:16:32 -04004798 GLfloat vals[4] = { x, y, 0, 1 };
4799 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004800 }
4801}
4802
Kenneth Russell67ea1902014-10-06 16:44:50 -07004803void GL_APIENTRY glVertexAttrib2fv(GLuint index, const GLfloat* values)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004804{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004805 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004806
Geoff Langbfdea662014-07-23 14:16:32 -04004807 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004808 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004809 {
Geoff Langb1196682014-07-23 13:47:29 -04004810 if (index >= gl::MAX_VERTEX_ATTRIBS)
4811 {
4812 context->recordError(gl::Error(GL_INVALID_VALUE));
4813 return;
4814 }
4815
Geoff Langbfdea662014-07-23 14:16:32 -04004816 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4817 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004818 }
4819}
4820
Kenneth Russell67ea1902014-10-06 16:44:50 -07004821void GL_APIENTRY glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004822{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004823 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 +00004824
Geoff Langbfdea662014-07-23 14:16:32 -04004825 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004826 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004827 {
Geoff Langb1196682014-07-23 13:47:29 -04004828 if (index >= gl::MAX_VERTEX_ATTRIBS)
4829 {
4830 context->recordError(gl::Error(GL_INVALID_VALUE));
4831 return;
4832 }
4833
Geoff Langbfdea662014-07-23 14:16:32 -04004834 GLfloat vals[4] = { x, y, z, 1 };
4835 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004836 }
4837}
4838
Kenneth Russell67ea1902014-10-06 16:44:50 -07004839void GL_APIENTRY glVertexAttrib3fv(GLuint index, const GLfloat* values)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004840{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004841 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004842
Geoff Langbfdea662014-07-23 14:16:32 -04004843 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004844 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004845 {
Geoff Langb1196682014-07-23 13:47:29 -04004846 if (index >= gl::MAX_VERTEX_ATTRIBS)
4847 {
4848 context->recordError(gl::Error(GL_INVALID_VALUE));
4849 return;
4850 }
4851
Geoff Langbfdea662014-07-23 14:16:32 -04004852 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4853 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004854 }
4855}
4856
Kenneth Russell67ea1902014-10-06 16:44:50 -07004857void GL_APIENTRY glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004858{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004859 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 +00004860
Geoff Langbfdea662014-07-23 14:16:32 -04004861 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004862 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004863 {
Geoff Langb1196682014-07-23 13:47:29 -04004864 if (index >= gl::MAX_VERTEX_ATTRIBS)
4865 {
4866 context->recordError(gl::Error(GL_INVALID_VALUE));
4867 return;
4868 }
4869
Geoff Langbfdea662014-07-23 14:16:32 -04004870 GLfloat vals[4] = { x, y, z, w };
4871 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004872 }
4873}
4874
Kenneth Russell67ea1902014-10-06 16:44:50 -07004875void GL_APIENTRY glVertexAttrib4fv(GLuint index, const GLfloat* values)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004876{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004877 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004878
Geoff Langbfdea662014-07-23 14:16:32 -04004879 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004880 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004881 {
Geoff Langb1196682014-07-23 13:47:29 -04004882 if (index >= gl::MAX_VERTEX_ATTRIBS)
4883 {
4884 context->recordError(gl::Error(GL_INVALID_VALUE));
4885 return;
4886 }
4887
Geoff Langbfdea662014-07-23 14:16:32 -04004888 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004889 }
4890}
4891
Kenneth Russell67ea1902014-10-06 16:44:50 -07004892void GL_APIENTRY glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004893{
4894 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4895
Geoff Langbfdea662014-07-23 14:16:32 -04004896 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004897 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004898 {
Geoff Langb1196682014-07-23 13:47:29 -04004899 if (index >= gl::MAX_VERTEX_ATTRIBS)
4900 {
4901 context->recordError(gl::Error(GL_INVALID_VALUE));
4902 return;
4903 }
4904
Geoff Langbfdea662014-07-23 14:16:32 -04004905 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004906 }
4907}
4908
Kenneth Russell67ea1902014-10-06 16:44:50 -07004909void GL_APIENTRY glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004910{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004911 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004912 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004913 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004914
Geoff Langbfdea662014-07-23 14:16:32 -04004915 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004916 if (context)
4917 {
Geoff Langb1196682014-07-23 13:47:29 -04004918 if (index >= gl::MAX_VERTEX_ATTRIBS)
4919 {
4920 context->recordError(gl::Error(GL_INVALID_VALUE));
4921 return;
4922 }
4923
4924 if (size < 1 || size > 4)
4925 {
4926 context->recordError(gl::Error(GL_INVALID_VALUE));
4927 return;
4928 }
4929
4930 switch (type)
4931 {
4932 case GL_BYTE:
4933 case GL_UNSIGNED_BYTE:
4934 case GL_SHORT:
4935 case GL_UNSIGNED_SHORT:
4936 case GL_FIXED:
4937 case GL_FLOAT:
4938 break;
4939
4940 case GL_HALF_FLOAT:
4941 case GL_INT:
4942 case GL_UNSIGNED_INT:
4943 case GL_INT_2_10_10_10_REV:
4944 case GL_UNSIGNED_INT_2_10_10_10_REV:
4945 if (context->getClientVersion() < 3)
4946 {
4947 context->recordError(gl::Error(GL_INVALID_ENUM));
4948 return;
4949 }
4950 break;
4951
4952 default:
4953 context->recordError(gl::Error(GL_INVALID_ENUM));
4954 return;
4955 }
4956
4957 if (stride < 0)
4958 {
4959 context->recordError(gl::Error(GL_INVALID_VALUE));
4960 return;
4961 }
4962
4963 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4964 {
4965 context->recordError(gl::Error(GL_INVALID_OPERATION));
4966 return;
4967 }
4968
Geoff Langbfdea662014-07-23 14:16:32 -04004969 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4970 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4971 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4972 // and the pointer argument is not NULL.
4973 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004974 {
Geoff Langb1196682014-07-23 13:47:29 -04004975 context->recordError(gl::Error(GL_INVALID_OPERATION));
4976 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004977 }
4978
Geoff Langbfdea662014-07-23 14:16:32 -04004979 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4980 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004981 }
4982}
4983
Kenneth Russell67ea1902014-10-06 16:44:50 -07004984void GL_APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004985{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004986 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 +00004987
Geoff Langbfdea662014-07-23 14:16:32 -04004988 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004989 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004990 {
Geoff Langb1196682014-07-23 13:47:29 -04004991 if (width < 0 || height < 0)
4992 {
4993 context->recordError(gl::Error(GL_INVALID_VALUE));
4994 return;
4995 }
4996
Geoff Langbfdea662014-07-23 14:16:32 -04004997 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004998 }
4999}
5000
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005001// OpenGL ES 3.0 functions
5002
Kenneth Russell67ea1902014-10-06 16:44:50 -07005003void GL_APIENTRY glReadBuffer(GLenum mode)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005004{
5005 EVENT("(GLenum mode = 0x%X)", mode);
5006
Geoff Langbfdea662014-07-23 14:16:32 -04005007 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005008 if (context)
5009 {
5010 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005011 {
Geoff Langb1196682014-07-23 13:47:29 -04005012 context->recordError(gl::Error(GL_INVALID_OPERATION));
5013 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005014 }
Geoff Langbfdea662014-07-23 14:16:32 -04005015
5016 // glReadBuffer
5017 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005018 }
5019}
5020
Kenneth Russell67ea1902014-10-06 16:44:50 -07005021void 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 +00005022{
5023 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
5024 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
5025
Geoff Langbfdea662014-07-23 14:16:32 -04005026 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005027 if (context)
5028 {
5029 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005030 {
Geoff Langb1196682014-07-23 13:47:29 -04005031 context->recordError(gl::Error(GL_INVALID_OPERATION));
5032 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005033 }
Geoff Langbfdea662014-07-23 14:16:32 -04005034
5035 // glDrawRangeElements
5036 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005037 }
5038}
5039
Kenneth Russell67ea1902014-10-06 16:44:50 -07005040void 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 +00005041{
5042 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
5043 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
5044 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5045 target, level, internalformat, width, height, depth, border, format, type, pixels);
5046
Geoff Langbfdea662014-07-23 14:16:32 -04005047 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005048 if (context)
5049 {
5050 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005051 {
Geoff Langb1196682014-07-23 13:47:29 -04005052 context->recordError(gl::Error(GL_INVALID_OPERATION));
5053 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005054 }
Geoff Langbfdea662014-07-23 14:16:32 -04005055
5056 // validateES3TexImageFormat sets the error code if there is an error
5057 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
5058 0, 0, 0, width, height, depth, border, format, type, pixels))
5059 {
5060 return;
5061 }
5062
5063 switch(target)
5064 {
5065 case GL_TEXTURE_3D:
5066 {
5067 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005068 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5069 if (error.isError())
5070 {
5071 context->recordError(error);
5072 return;
5073 }
Geoff Langbfdea662014-07-23 14:16:32 -04005074 }
5075 break;
5076
5077 case GL_TEXTURE_2D_ARRAY:
5078 {
5079 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005080 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5081 if (error.isError())
5082 {
5083 context->recordError(error);
5084 return;
5085 }
Geoff Langbfdea662014-07-23 14:16:32 -04005086 }
5087 break;
5088
5089 default:
Geoff Langb1196682014-07-23 13:47:29 -04005090 context->recordError(gl::Error(GL_INVALID_ENUM));
5091 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005092 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005093 }
5094}
5095
Kenneth Russell67ea1902014-10-06 16:44:50 -07005096void 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 +00005097{
5098 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5099 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5100 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5101 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
5102
Geoff Langbfdea662014-07-23 14:16:32 -04005103 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005104 if (context)
5105 {
5106 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005107 {
Geoff Langb1196682014-07-23 13:47:29 -04005108 context->recordError(gl::Error(GL_INVALID_OPERATION));
5109 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005110 }
Geoff Langbfdea662014-07-23 14:16:32 -04005111
5112 // validateES3TexImageFormat sets the error code if there is an error
5113 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5114 xoffset, yoffset, zoffset, width, height, depth, 0,
5115 format, type, pixels))
5116 {
5117 return;
5118 }
5119
5120 // Zero sized uploads are valid but no-ops
5121 if (width == 0 || height == 0 || depth == 0)
5122 {
5123 return;
5124 }
5125
5126 switch(target)
5127 {
5128 case GL_TEXTURE_3D:
5129 {
5130 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005131 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5132 if (error.isError())
5133 {
5134 context->recordError(error);
5135 return;
5136 }
Geoff Langbfdea662014-07-23 14:16:32 -04005137 }
5138 break;
5139
5140 case GL_TEXTURE_2D_ARRAY:
5141 {
5142 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005143 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5144 if (error.isError())
5145 {
5146 context->recordError(error);
5147 return;
5148 }
Geoff Langbfdea662014-07-23 14:16:32 -04005149 }
5150 break;
5151
5152 default:
Geoff Langb1196682014-07-23 13:47:29 -04005153 context->recordError(gl::Error(GL_INVALID_ENUM));
5154 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005155 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005156 }
5157}
5158
Kenneth Russell67ea1902014-10-06 16:44:50 -07005159void 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 +00005160{
5161 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5162 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5163 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5164
Geoff Langbfdea662014-07-23 14:16:32 -04005165 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005166 if (context)
5167 {
5168 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005169 {
Geoff Langb1196682014-07-23 13:47:29 -04005170 context->recordError(gl::Error(GL_INVALID_OPERATION));
5171 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005172 }
Geoff Langbfdea662014-07-23 14:16:32 -04005173
5174 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5175 x, y, width, height, 0))
5176 {
5177 return;
5178 }
5179
5180 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5181 gl::Texture *texture = NULL;
5182 switch (target)
5183 {
5184 case GL_TEXTURE_3D:
5185 texture = context->getTexture3D();
5186 break;
5187
5188 case GL_TEXTURE_2D_ARRAY:
5189 texture = context->getTexture2DArray();
5190 break;
5191
5192 default:
Geoff Langb1196682014-07-23 13:47:29 -04005193 context->recordError(gl::Error(GL_INVALID_ENUM));
5194 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005195 }
5196
5197 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005198 }
5199}
5200
Kenneth Russell67ea1902014-10-06 16:44:50 -07005201void 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 +00005202{
Geoff Langeef52cc2013-10-16 15:07:39 -04005203 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 +00005204 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5205 "const GLvoid* data = 0x%0.8p)",
5206 target, level, internalformat, width, height, depth, border, imageSize, data);
5207
Geoff Langbfdea662014-07-23 14:16:32 -04005208 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005209 if (context)
5210 {
5211 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005212 {
Geoff Langb1196682014-07-23 13:47:29 -04005213 context->recordError(gl::Error(GL_INVALID_OPERATION));
5214 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005215 }
Geoff Langbfdea662014-07-23 14:16:32 -04005216
Geoff Lang5d601382014-07-22 15:14:06 -04005217 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5218 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005219 {
Geoff Langb1196682014-07-23 13:47:29 -04005220 context->recordError(gl::Error(GL_INVALID_VALUE));
5221 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005222 }
5223
5224 // validateES3TexImageFormat sets the error code if there is an error
5225 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5226 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5227 {
5228 return;
5229 }
5230
5231 switch(target)
5232 {
5233 case GL_TEXTURE_3D:
5234 {
5235 gl::Texture3D *texture = context->getTexture3D();
Geoff Langb5348332014-09-02 13:16:34 -04005236 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5237 if (error.isError())
5238 {
5239 context->recordError(error);
5240 return;
5241 }
Geoff Langbfdea662014-07-23 14:16:32 -04005242 }
5243 break;
5244
5245 case GL_TEXTURE_2D_ARRAY:
5246 {
5247 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Langb5348332014-09-02 13:16:34 -04005248 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5249 if (error.isError())
5250 {
5251 context->recordError(error);
5252 return;
5253 }
Geoff Langbfdea662014-07-23 14:16:32 -04005254 }
5255 break;
5256
5257 default:
Geoff Langb1196682014-07-23 13:47:29 -04005258 context->recordError(gl::Error(GL_INVALID_ENUM));
5259 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005260 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005261 }
5262}
5263
Kenneth Russell67ea1902014-10-06 16:44:50 -07005264void 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 +00005265{
5266 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5267 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5268 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5269 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5270
Geoff Langbfdea662014-07-23 14:16:32 -04005271 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005272 if (context)
5273 {
5274 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005275 {
Geoff Langb1196682014-07-23 13:47:29 -04005276 context->recordError(gl::Error(GL_INVALID_OPERATION));
5277 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005278 }
Geoff Langbfdea662014-07-23 14:16:32 -04005279
Geoff Lang5d601382014-07-22 15:14:06 -04005280 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5281 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005282 {
Geoff Langb1196682014-07-23 13:47:29 -04005283 context->recordError(gl::Error(GL_INVALID_VALUE));
5284 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005285 }
5286
5287 if (!data)
5288 {
Geoff Langb1196682014-07-23 13:47:29 -04005289 context->recordError(gl::Error(GL_INVALID_VALUE));
5290 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005291 }
5292
5293 // validateES3TexImageFormat sets the error code if there is an error
5294 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5295 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5296 {
5297 return;
5298 }
5299
5300 // Zero sized uploads are valid but no-ops
5301 if (width == 0 || height == 0)
5302 {
5303 return;
5304 }
5305
5306 switch(target)
5307 {
5308 case GL_TEXTURE_3D:
5309 {
5310 gl::Texture3D *texture = context->getTexture3D();
Geoff Langb5348332014-09-02 13:16:34 -04005311 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5312 format, imageSize, data);
5313 if (error.isError())
5314 {
5315 context->recordError(error);
5316 return;
5317 }
Geoff Langbfdea662014-07-23 14:16:32 -04005318 }
5319 break;
5320
5321 case GL_TEXTURE_2D_ARRAY:
5322 {
5323 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Langb5348332014-09-02 13:16:34 -04005324 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5325 format, imageSize, data);
5326 if (error.isError())
5327 {
5328 context->recordError(error);
5329 return;
5330 }
Geoff Langbfdea662014-07-23 14:16:32 -04005331 }
5332 break;
5333
Geoff Langb1196682014-07-23 13:47:29 -04005334 default:
5335 context->recordError(gl::Error(GL_INVALID_ENUM));
5336 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005337 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005338 }
5339}
5340
Kenneth Russell67ea1902014-10-06 16:44:50 -07005341void GL_APIENTRY glGenQueries(GLsizei n, GLuint* ids)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005342{
5343 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5344
Geoff Langbfdea662014-07-23 14:16:32 -04005345 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005346 if (context)
5347 {
5348 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005349 {
Geoff Langb1196682014-07-23 13:47:29 -04005350 context->recordError(gl::Error(GL_INVALID_OPERATION));
5351 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005352 }
Geoff Langbfdea662014-07-23 14:16:32 -04005353
5354 if (n < 0)
5355 {
Geoff Langb1196682014-07-23 13:47:29 -04005356 context->recordError(gl::Error(GL_INVALID_VALUE));
5357 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005358 }
5359
5360 for (GLsizei i = 0; i < n; i++)
5361 {
5362 ids[i] = context->createQuery();
5363 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005364 }
5365}
5366
Kenneth Russell67ea1902014-10-06 16:44:50 -07005367void GL_APIENTRY glDeleteQueries(GLsizei n, const GLuint* ids)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005368{
5369 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5370
Geoff Langbfdea662014-07-23 14:16:32 -04005371 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005372 if (context)
5373 {
5374 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005375 {
Geoff Langb1196682014-07-23 13:47:29 -04005376 context->recordError(gl::Error(GL_INVALID_OPERATION));
5377 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005378 }
Geoff Langbfdea662014-07-23 14:16:32 -04005379
5380 if (n < 0)
5381 {
Geoff Langb1196682014-07-23 13:47:29 -04005382 context->recordError(gl::Error(GL_INVALID_VALUE));
5383 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005384 }
5385
5386 for (GLsizei i = 0; i < n; i++)
5387 {
5388 context->deleteQuery(ids[i]);
5389 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005390 }
5391}
5392
Kenneth Russell67ea1902014-10-06 16:44:50 -07005393GLboolean GL_APIENTRY glIsQuery(GLuint id)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005394{
5395 EVENT("(GLuint id = %u)", id);
5396
Geoff Langbfdea662014-07-23 14:16:32 -04005397 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005398 if (context)
5399 {
5400 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005401 {
Geoff Langb1196682014-07-23 13:47:29 -04005402 context->recordError(gl::Error(GL_INVALID_OPERATION));
5403 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005404 }
Geoff Langbfdea662014-07-23 14:16:32 -04005405
5406 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005407 }
5408
5409 return GL_FALSE;
5410}
5411
Kenneth Russell67ea1902014-10-06 16:44:50 -07005412void GL_APIENTRY glBeginQuery(GLenum target, GLuint id)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005413{
5414 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5415
Geoff Langbfdea662014-07-23 14:16:32 -04005416 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005417 if (context)
5418 {
5419 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005420 {
Geoff Langb1196682014-07-23 13:47:29 -04005421 context->recordError(gl::Error(GL_INVALID_OPERATION));
5422 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005423 }
Geoff Langbfdea662014-07-23 14:16:32 -04005424
5425 if (!ValidateBeginQuery(context, target, id))
5426 {
5427 return;
5428 }
Geoff Lang5aad9672014-09-08 11:10:42 -04005429
5430 gl::Error error = context->beginQuery(target, id);
5431 if (error.isError())
5432 {
5433 context->recordError(error);
5434 return;
5435 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005436 }
5437}
5438
Kenneth Russell67ea1902014-10-06 16:44:50 -07005439void GL_APIENTRY glEndQuery(GLenum target)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005440{
5441 EVENT("(GLenum target = 0x%X)", target);
5442
Geoff Langbfdea662014-07-23 14:16:32 -04005443 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005444 if (context)
5445 {
5446 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005447 {
Geoff Langb1196682014-07-23 13:47:29 -04005448 context->recordError(gl::Error(GL_INVALID_OPERATION));
5449 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005450 }
Geoff Langbfdea662014-07-23 14:16:32 -04005451
5452 if (!ValidateEndQuery(context, target))
5453 {
5454 return;
5455 }
5456
Geoff Lang5aad9672014-09-08 11:10:42 -04005457 gl::Error error = context->endQuery(target);
5458 if (error.isError())
5459 {
5460 context->recordError(error);
5461 return;
5462 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005463 }
5464}
5465
Kenneth Russell67ea1902014-10-06 16:44:50 -07005466void GL_APIENTRY glGetQueryiv(GLenum target, GLenum pname, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005467{
5468 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5469
Geoff Langbfdea662014-07-23 14:16:32 -04005470 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005471 if (context)
5472 {
5473 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005474 {
Geoff Langb1196682014-07-23 13:47:29 -04005475 context->recordError(gl::Error(GL_INVALID_OPERATION));
5476 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005477 }
Geoff Langbfdea662014-07-23 14:16:32 -04005478
5479 if (!ValidQueryType(context, target))
5480 {
Geoff Langb1196682014-07-23 13:47:29 -04005481 context->recordError(gl::Error(GL_INVALID_ENUM));
5482 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005483 }
5484
5485 switch (pname)
5486 {
5487 case GL_CURRENT_QUERY:
5488 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5489 break;
5490
5491 default:
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 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005495 }
5496}
5497
Kenneth Russell67ea1902014-10-06 16:44:50 -07005498void GL_APIENTRY glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005499{
5500 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5501
Geoff Langbfdea662014-07-23 14:16:32 -04005502 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005503 if (context)
5504 {
5505 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005506 {
Geoff Langb1196682014-07-23 13:47:29 -04005507 context->recordError(gl::Error(GL_INVALID_OPERATION));
5508 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005509 }
Geoff Langbfdea662014-07-23 14:16:32 -04005510
5511 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5512
5513 if (!queryObject)
5514 {
Geoff Langb1196682014-07-23 13:47:29 -04005515 context->recordError(gl::Error(GL_INVALID_OPERATION));
5516 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005517 }
5518
5519 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5520 {
Geoff Langb1196682014-07-23 13:47:29 -04005521 context->recordError(gl::Error(GL_INVALID_OPERATION));
5522 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005523 }
5524
5525 switch(pname)
5526 {
Geoff Lang5aad9672014-09-08 11:10:42 -04005527 case GL_QUERY_RESULT_EXT:
5528 {
5529 gl::Error error = queryObject->getResult(params);
5530 if (error.isError())
5531 {
5532 context->recordError(error);
5533 return;
5534 }
5535 }
Geoff Langbfdea662014-07-23 14:16:32 -04005536 break;
Geoff Langb1196682014-07-23 13:47:29 -04005537
Geoff Lang5aad9672014-09-08 11:10:42 -04005538 case GL_QUERY_RESULT_AVAILABLE_EXT:
5539 {
5540 gl::Error error = queryObject->isResultAvailable(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 Langbfdea662014-07-23 14:16:32 -04005549 default:
Geoff Langb1196682014-07-23 13:47:29 -04005550 context->recordError(gl::Error(GL_INVALID_ENUM));
5551 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005552 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005553 }
5554}
5555
Kenneth Russell67ea1902014-10-06 16:44:50 -07005556GLboolean GL_APIENTRY glUnmapBuffer(GLenum target)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005557{
5558 EVENT("(GLenum target = 0x%X)", target);
5559
Geoff Langbfdea662014-07-23 14:16:32 -04005560 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005561 if (context)
5562 {
5563 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005564 {
Geoff Langb1196682014-07-23 13:47:29 -04005565 context->recordError(gl::Error(GL_INVALID_OPERATION));
5566 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005567 }
Geoff Langbfdea662014-07-23 14:16:32 -04005568
5569 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005570 }
5571
5572 return GL_FALSE;
5573}
5574
Kenneth Russell67ea1902014-10-06 16:44:50 -07005575void GL_APIENTRY glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005576{
5577 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5578
Geoff Langbfdea662014-07-23 14:16:32 -04005579 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005580 if (context)
5581 {
5582 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005583 {
Geoff Langb1196682014-07-23 13:47:29 -04005584 context->recordError(gl::Error(GL_INVALID_OPERATION));
5585 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005586 }
Geoff Langbfdea662014-07-23 14:16:32 -04005587
5588 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005589 }
5590}
5591
Kenneth Russell67ea1902014-10-06 16:44:50 -07005592void GL_APIENTRY glDrawBuffers(GLsizei n, const GLenum* bufs)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005593{
Geoff Langbfdea662014-07-23 14:16:32 -04005594 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005595 if (context)
5596 {
5597 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005598 {
Geoff Langb1196682014-07-23 13:47:29 -04005599 context->recordError(gl::Error(GL_INVALID_OPERATION));
5600 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005601 }
Geoff Langbfdea662014-07-23 14:16:32 -04005602
5603 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005604 }
5605}
5606
Kenneth Russell67ea1902014-10-06 16:44:50 -07005607void GL_APIENTRY glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005608{
5609 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5610 location, count, transpose, value);
5611
Geoff Langbfdea662014-07-23 14:16:32 -04005612 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005613 if (context)
5614 {
5615 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005616 {
Geoff Langbfdea662014-07-23 14:16:32 -04005617 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005618 }
Geoff Langbfdea662014-07-23 14:16:32 -04005619
5620 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5621 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005622 }
5623}
5624
Kenneth Russell67ea1902014-10-06 16:44:50 -07005625void GL_APIENTRY glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005626{
5627 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5628 location, count, transpose, value);
5629
Geoff Langbfdea662014-07-23 14:16:32 -04005630 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005631 if (context)
5632 {
5633 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005634 {
Geoff Langbfdea662014-07-23 14:16:32 -04005635 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005636 }
Geoff Langbfdea662014-07-23 14:16:32 -04005637
5638 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5639 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005640 }
5641}
5642
Kenneth Russell67ea1902014-10-06 16:44:50 -07005643void GL_APIENTRY glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005644{
5645 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5646 location, count, transpose, value);
5647
Geoff Langbfdea662014-07-23 14:16:32 -04005648 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005649 if (context)
5650 {
5651 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005652 {
Geoff Langbfdea662014-07-23 14:16:32 -04005653 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005654 }
Geoff Langbfdea662014-07-23 14:16:32 -04005655
5656 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5657 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005658 }
5659}
5660
Kenneth Russell67ea1902014-10-06 16:44:50 -07005661void GL_APIENTRY glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005662{
5663 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5664 location, count, transpose, value);
5665
Geoff Langbfdea662014-07-23 14:16:32 -04005666 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005667 if (context)
5668 {
5669 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005670 {
Geoff Langbfdea662014-07-23 14:16:32 -04005671 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005672 }
Geoff Langbfdea662014-07-23 14:16:32 -04005673
5674 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5675 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005676 }
5677}
5678
Kenneth Russell67ea1902014-10-06 16:44:50 -07005679void GL_APIENTRY glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005680{
5681 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5682 location, count, transpose, value);
5683
Geoff Langbfdea662014-07-23 14:16:32 -04005684 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005685 if (context)
5686 {
5687 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005688 {
Geoff Langbfdea662014-07-23 14:16:32 -04005689 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005690 }
Geoff Langbfdea662014-07-23 14:16:32 -04005691
5692 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5693 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005694 }
5695}
5696
Kenneth Russell67ea1902014-10-06 16:44:50 -07005697void GL_APIENTRY glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005698{
5699 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5700 location, count, transpose, value);
5701
Geoff Langbfdea662014-07-23 14:16:32 -04005702 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005703 if (context)
5704 {
5705 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005706 {
Geoff Langbfdea662014-07-23 14:16:32 -04005707 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005708 }
Geoff Langbfdea662014-07-23 14:16:32 -04005709
5710 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5711 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005712 }
5713}
5714
Kenneth Russell67ea1902014-10-06 16:44:50 -07005715void 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 +00005716{
5717 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5718 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5719 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5720
Geoff Langbfdea662014-07-23 14:16:32 -04005721 gl::Context *context = gl::getNonLostContext();
5722 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005723 {
Geoff Langbfdea662014-07-23 14:16:32 -04005724 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005725 {
Geoff Langb1196682014-07-23 13:47:29 -04005726 context->recordError(gl::Error(GL_INVALID_OPERATION));
5727 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005728 }
Geoff Langbfdea662014-07-23 14:16:32 -04005729
5730 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5731 dstX0, dstY0, dstX1, dstY1, mask, filter,
5732 false))
5733 {
5734 return;
5735 }
5736
Geoff Lang64839152014-08-26 16:23:25 -04005737 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5738 mask, filter);
5739 if (error.isError())
5740 {
5741 context->recordError(error);
5742 return;
5743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005744 }
5745}
5746
Kenneth Russell67ea1902014-10-06 16:44:50 -07005747void GL_APIENTRY glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005748{
5749 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5750 target, samples, internalformat, width, height);
5751
Geoff Langbfdea662014-07-23 14:16:32 -04005752 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005753 if (context)
5754 {
5755 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005756 {
Geoff Langb1196682014-07-23 13:47:29 -04005757 context->recordError(gl::Error(GL_INVALID_OPERATION));
5758 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005759 }
Geoff Langbfdea662014-07-23 14:16:32 -04005760
5761 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5762 width, height, false))
5763 {
5764 return;
5765 }
5766
5767 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005768 }
5769}
5770
Kenneth Russell67ea1902014-10-06 16:44:50 -07005771void GL_APIENTRY glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005772{
5773 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5774 target, attachment, texture, level, layer);
5775
Geoff Langbfdea662014-07-23 14:16:32 -04005776 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005777 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005778 {
Geoff Langbfdea662014-07-23 14:16:32 -04005779 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5780 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005781 {
Geoff Langbfdea662014-07-23 14:16:32 -04005782 return;
5783 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005784
Geoff Langbfdea662014-07-23 14:16:32 -04005785 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5786 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005787
Geoff Langbfdea662014-07-23 14:16:32 -04005788 gl::Texture *textureObject = context->getTexture(texture);
5789 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005790
Geoff Langbfdea662014-07-23 14:16:32 -04005791 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5792 {
5793 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5794 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5795 }
5796 else
5797 {
5798 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005799 {
Geoff Langbfdea662014-07-23 14:16:32 -04005800 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5801 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5802 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005803 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005804 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005805 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005806}
5807
Kenneth Russell67ea1902014-10-06 16:44:50 -07005808GLvoid* GL_APIENTRY glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005809{
5810 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5811 target, offset, length, access);
5812
Geoff Langbfdea662014-07-23 14:16:32 -04005813 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005814 if (context)
5815 {
5816 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005817 {
Geoff Langb1196682014-07-23 13:47:29 -04005818 context->recordError(gl::Error(GL_INVALID_OPERATION));
5819 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005820 }
Geoff Langbfdea662014-07-23 14:16:32 -04005821
5822 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005823 }
5824
5825 return NULL;
5826}
5827
Kenneth Russell67ea1902014-10-06 16:44:50 -07005828void GL_APIENTRY glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005829{
5830 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5831
Geoff Langbfdea662014-07-23 14:16:32 -04005832 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005833 if (context)
5834 {
5835 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005836 {
Geoff Langb1196682014-07-23 13:47:29 -04005837 context->recordError(gl::Error(GL_INVALID_OPERATION));
5838 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005839 }
Geoff Langbfdea662014-07-23 14:16:32 -04005840
5841 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005842 }
5843}
5844
Kenneth Russell67ea1902014-10-06 16:44:50 -07005845void GL_APIENTRY glBindVertexArray(GLuint array)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005846{
5847 EVENT("(GLuint array = %u)", array);
5848
Geoff Langbfdea662014-07-23 14:16:32 -04005849 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005850 if (context)
5851 {
5852 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005853 {
Geoff Langb1196682014-07-23 13:47:29 -04005854 context->recordError(gl::Error(GL_INVALID_OPERATION));
5855 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005856 }
Geoff Langbfdea662014-07-23 14:16:32 -04005857
5858 gl::VertexArray *vao = context->getVertexArray(array);
5859
5860 if (!vao)
5861 {
5862 // The default VAO should always exist
5863 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005864 context->recordError(gl::Error(GL_INVALID_OPERATION));
5865 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005866 }
5867
5868 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005869 }
5870}
5871
Kenneth Russell67ea1902014-10-06 16:44:50 -07005872void GL_APIENTRY glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005873{
5874 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5875
Geoff Langbfdea662014-07-23 14:16:32 -04005876 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005877 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005878 {
Geoff Langbfdea662014-07-23 14:16:32 -04005879 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005880 {
Geoff Langb1196682014-07-23 13:47:29 -04005881 context->recordError(gl::Error(GL_INVALID_OPERATION));
5882 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005883 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005884
Geoff Langbfdea662014-07-23 14:16:32 -04005885 if (n < 0)
5886 {
Geoff Langb1196682014-07-23 13:47:29 -04005887 context->recordError(gl::Error(GL_INVALID_VALUE));
5888 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005889 }
Jamie Madilld1028542013-07-02 11:57:04 -04005890
Geoff Langbfdea662014-07-23 14:16:32 -04005891 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5892 {
5893 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005894 {
Geoff Langbfdea662014-07-23 14:16:32 -04005895 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005896 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005897 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005898 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005899}
5900
Kenneth Russell67ea1902014-10-06 16:44:50 -07005901void GL_APIENTRY glGenVertexArrays(GLsizei n, GLuint* arrays)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005902{
5903 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5904
Geoff Langbfdea662014-07-23 14:16:32 -04005905 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005906 if (context)
5907 {
5908 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005909 {
Geoff Langb1196682014-07-23 13:47:29 -04005910 context->recordError(gl::Error(GL_INVALID_OPERATION));
5911 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005912 }
Geoff Langbfdea662014-07-23 14:16:32 -04005913
5914 if (n < 0)
5915 {
Geoff Langb1196682014-07-23 13:47:29 -04005916 context->recordError(gl::Error(GL_INVALID_VALUE));
5917 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005918 }
5919
5920 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5921 {
5922 arrays[arrayIndex] = context->createVertexArray();
5923 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005924 }
5925}
5926
Kenneth Russell67ea1902014-10-06 16:44:50 -07005927GLboolean GL_APIENTRY glIsVertexArray(GLuint array)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005928{
5929 EVENT("(GLuint array = %u)", array);
5930
Geoff Langbfdea662014-07-23 14:16:32 -04005931 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005932 if (context)
5933 {
5934 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005935 {
Geoff Langb1196682014-07-23 13:47:29 -04005936 context->recordError(gl::Error(GL_INVALID_OPERATION));
5937 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005938 }
Geoff Langbfdea662014-07-23 14:16:32 -04005939
5940 if (array == 0)
5941 {
5942 return GL_FALSE;
5943 }
5944
5945 gl::VertexArray *vao = context->getVertexArray(array);
5946
5947 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005948 }
5949
5950 return GL_FALSE;
5951}
5952
Kenneth Russell67ea1902014-10-06 16:44:50 -07005953void GL_APIENTRY glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005954{
5955 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5956 target, index, data);
5957
Geoff Langbfdea662014-07-23 14:16:32 -04005958 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005959 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005960 {
Geoff Langbfdea662014-07-23 14:16:32 -04005961 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005962 {
Geoff Langb1196682014-07-23 13:47:29 -04005963 context->recordError(gl::Error(GL_INVALID_OPERATION));
5964 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005965 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005966
Geoff Lang3a61c322014-07-10 13:01:54 -04005967 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005968 switch (target)
5969 {
5970 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5971 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5972 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005973 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5974 {
Geoff Langb1196682014-07-23 13:47:29 -04005975 context->recordError(gl::Error(GL_INVALID_VALUE));
5976 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005977 }
Geoff Langbfdea662014-07-23 14:16:32 -04005978 break;
Geoff Langb1196682014-07-23 13:47:29 -04005979
Geoff Langbfdea662014-07-23 14:16:32 -04005980 case GL_UNIFORM_BUFFER_START:
5981 case GL_UNIFORM_BUFFER_SIZE:
5982 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005983 if (index >= caps.maxCombinedUniformBlocks)
5984 {
Geoff Langb1196682014-07-23 13:47:29 -04005985 context->recordError(gl::Error(GL_INVALID_VALUE));
5986 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005987 }
Geoff Langbfdea662014-07-23 14:16:32 -04005988 break;
Geoff Langb1196682014-07-23 13:47:29 -04005989
Geoff Langbfdea662014-07-23 14:16:32 -04005990 default:
Geoff Langb1196682014-07-23 13:47:29 -04005991 context->recordError(gl::Error(GL_INVALID_ENUM));
5992 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005993 }
5994
5995 if (!(context->getIndexedIntegerv(target, index, data)))
5996 {
5997 GLenum nativeType;
5998 unsigned int numParams = 0;
5999 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04006000 {
6001 context->recordError(gl::Error(GL_INVALID_ENUM));
6002 return;
6003 }
Shannon Woods15934d52013-08-19 14:28:49 -04006004
Geoff Langbfdea662014-07-23 14:16:32 -04006005 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04006006 {
Geoff Langbfdea662014-07-23 14:16:32 -04006007 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04006008 }
Geoff Langbfdea662014-07-23 14:16:32 -04006009
6010 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04006011 {
Geoff Langbfdea662014-07-23 14:16:32 -04006012 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
6013 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
6014 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04006015
Geoff Langbfdea662014-07-23 14:16:32 -04006016 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04006017
Geoff Langbfdea662014-07-23 14:16:32 -04006018 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04006019 {
Geoff Langbfdea662014-07-23 14:16:32 -04006020 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
6021 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04006022 }
Geoff Langbfdea662014-07-23 14:16:32 -04006023
6024 delete [] int64Params;
6025 }
6026 else
6027 {
6028 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04006029 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006030 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006031 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006032}
6033
Kenneth Russell67ea1902014-10-06 16:44:50 -07006034void GL_APIENTRY glBeginTransformFeedback(GLenum primitiveMode)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006035{
6036 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
6037
Geoff Langbfdea662014-07-23 14:16:32 -04006038 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006039 if (context)
6040 {
6041 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006042 {
Geoff Langb1196682014-07-23 13:47:29 -04006043 context->recordError(gl::Error(GL_INVALID_OPERATION));
6044 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006045 }
Geoff Langbfdea662014-07-23 14:16:32 -04006046
6047 switch (primitiveMode)
6048 {
6049 case GL_TRIANGLES:
6050 case GL_LINES:
6051 case GL_POINTS:
6052 break;
Geoff Langb1196682014-07-23 13:47:29 -04006053
Geoff Langbfdea662014-07-23 14:16:32 -04006054 default:
Geoff Langb1196682014-07-23 13:47:29 -04006055 context->recordError(gl::Error(GL_INVALID_ENUM));
6056 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006057 }
6058
6059 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6060 ASSERT(transformFeedback != NULL);
6061
6062 if (transformFeedback->isStarted())
6063 {
Geoff Langb1196682014-07-23 13:47:29 -04006064 context->recordError(gl::Error(GL_INVALID_OPERATION));
6065 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006066 }
6067
6068 if (transformFeedback->isPaused())
6069 {
6070 transformFeedback->resume();
6071 }
6072 else
6073 {
6074 transformFeedback->start(primitiveMode);
6075 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006076 }
6077}
6078
Kenneth Russell67ea1902014-10-06 16:44:50 -07006079void GL_APIENTRY glEndTransformFeedback(void)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006080{
6081 EVENT("(void)");
6082
Geoff Langbfdea662014-07-23 14:16:32 -04006083 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006084 if (context)
6085 {
6086 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006087 {
Geoff Langb1196682014-07-23 13:47:29 -04006088 context->recordError(gl::Error(GL_INVALID_OPERATION));
6089 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006090 }
Geoff Langbfdea662014-07-23 14:16:32 -04006091
6092 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6093 ASSERT(transformFeedback != NULL);
6094
6095 if (!transformFeedback->isStarted())
6096 {
Geoff Langb1196682014-07-23 13:47:29 -04006097 context->recordError(gl::Error(GL_INVALID_OPERATION));
6098 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006099 }
6100
6101 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006102 }
6103}
6104
Kenneth Russell67ea1902014-10-06 16:44:50 -07006105void GL_APIENTRY glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006106{
6107 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
6108 target, index, buffer, offset, size);
6109
Geoff Langbfdea662014-07-23 14:16:32 -04006110 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006111 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006112 {
Geoff Langbfdea662014-07-23 14:16:32 -04006113 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006114 {
Geoff Langb1196682014-07-23 13:47:29 -04006115 context->recordError(gl::Error(GL_INVALID_OPERATION));
6116 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006117 }
6118
Geoff Lang3a61c322014-07-10 13:01:54 -04006119 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006120 switch (target)
6121 {
6122 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006123 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006124 {
Geoff Langb1196682014-07-23 13:47:29 -04006125 context->recordError(gl::Error(GL_INVALID_VALUE));
6126 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006127 }
Geoff Langbfdea662014-07-23 14:16:32 -04006128 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006129
Geoff Langbfdea662014-07-23 14:16:32 -04006130 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006131 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006132 {
Geoff Langb1196682014-07-23 13:47:29 -04006133 context->recordError(gl::Error(GL_INVALID_VALUE));
6134 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006135 }
Geoff Langbfdea662014-07-23 14:16:32 -04006136 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006137
Geoff Langbfdea662014-07-23 14:16:32 -04006138 default:
Geoff Langb1196682014-07-23 13:47:29 -04006139 context->recordError(gl::Error(GL_INVALID_ENUM));
6140 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006141 }
6142
6143 if (buffer != 0 && size <= 0)
6144 {
Geoff Langb1196682014-07-23 13:47:29 -04006145 context->recordError(gl::Error(GL_INVALID_VALUE));
6146 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006147 }
6148
6149 switch (target)
6150 {
6151 case GL_TRANSFORM_FEEDBACK_BUFFER:
6152
6153 // size and offset must be a multiple of 4
6154 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006155 {
Geoff Langb1196682014-07-23 13:47:29 -04006156 context->recordError(gl::Error(GL_INVALID_VALUE));
6157 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006158 }
6159
Geoff Langbfdea662014-07-23 14:16:32 -04006160 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
6161 context->bindGenericTransformFeedbackBuffer(buffer);
6162 break;
6163
6164 case GL_UNIFORM_BUFFER:
6165
6166 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006167 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006168 {
Geoff Langb1196682014-07-23 13:47:29 -04006169 context->recordError(gl::Error(GL_INVALID_VALUE));
6170 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006171 }
Geoff Langbfdea662014-07-23 14:16:32 -04006172
6173 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6174 context->bindGenericUniformBuffer(buffer);
6175 break;
6176
6177 default:
6178 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006179 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006180 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006181}
6182
Kenneth Russell67ea1902014-10-06 16:44:50 -07006183void GL_APIENTRY glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006184{
6185 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6186 target, index, buffer);
6187
Geoff Langbfdea662014-07-23 14:16:32 -04006188 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006189 if (context)
6190 {
6191 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006192 {
Geoff Langb1196682014-07-23 13:47:29 -04006193 context->recordError(gl::Error(GL_INVALID_OPERATION));
6194 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006195 }
Geoff Langbfdea662014-07-23 14:16:32 -04006196
Geoff Lang3a61c322014-07-10 13:01:54 -04006197 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006198 switch (target)
6199 {
6200 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006201 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006202 {
Geoff Langb1196682014-07-23 13:47:29 -04006203 context->recordError(gl::Error(GL_INVALID_VALUE));
6204 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006205 }
6206 break;
6207
6208 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006209 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006210 {
Geoff Langb1196682014-07-23 13:47:29 -04006211 context->recordError(gl::Error(GL_INVALID_VALUE));
6212 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006213 }
6214 break;
6215
6216 default:
Geoff Langb1196682014-07-23 13:47:29 -04006217 context->recordError(gl::Error(GL_INVALID_ENUM));
6218 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006219 }
6220
6221 switch (target)
6222 {
6223 case GL_TRANSFORM_FEEDBACK_BUFFER:
6224 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6225 context->bindGenericTransformFeedbackBuffer(buffer);
6226 break;
6227
6228 case GL_UNIFORM_BUFFER:
6229 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6230 context->bindGenericUniformBuffer(buffer);
6231 break;
6232
6233 default:
6234 UNREACHABLE();
6235 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006236 }
6237}
6238
Kenneth Russell67ea1902014-10-06 16:44:50 -07006239void GL_APIENTRY glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006240{
6241 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6242 program, count, varyings, bufferMode);
6243
Geoff Langbfdea662014-07-23 14:16:32 -04006244 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006245 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006246 {
Geoff Langbfdea662014-07-23 14:16:32 -04006247 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006248 {
Geoff Langb1196682014-07-23 13:47:29 -04006249 context->recordError(gl::Error(GL_INVALID_OPERATION));
6250 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006251 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006252
Geoff Langbfdea662014-07-23 14:16:32 -04006253 if (count < 0)
6254 {
Geoff Langb1196682014-07-23 13:47:29 -04006255 context->recordError(gl::Error(GL_INVALID_VALUE));
6256 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006257 }
6258
Geoff Lang05881a02014-07-10 14:05:30 -04006259 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006260 switch (bufferMode)
6261 {
6262 case GL_INTERLEAVED_ATTRIBS:
6263 break;
6264 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006265 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006266 {
Geoff Langb1196682014-07-23 13:47:29 -04006267 context->recordError(gl::Error(GL_INVALID_VALUE));
6268 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006269 }
Geoff Langbfdea662014-07-23 14:16:32 -04006270 break;
6271 default:
Geoff Langb1196682014-07-23 13:47:29 -04006272 context->recordError(gl::Error(GL_INVALID_ENUM));
6273 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006274 }
Geoff Langbfdea662014-07-23 14:16:32 -04006275
6276 if (!gl::ValidProgram(context, program))
6277 {
6278 return;
6279 }
6280
6281 gl::Program *programObject = context->getProgram(program);
6282 ASSERT(programObject);
6283
6284 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006285 }
6286}
6287
Kenneth Russell67ea1902014-10-06 16:44:50 -07006288void 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 +00006289{
6290 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6291 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6292 program, index, bufSize, length, size, type, name);
6293
Geoff Langbfdea662014-07-23 14:16:32 -04006294 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006295 if (context)
6296 {
6297 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006298 {
Geoff Langb1196682014-07-23 13:47:29 -04006299 context->recordError(gl::Error(GL_INVALID_OPERATION));
6300 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006301 }
Geoff Langbfdea662014-07-23 14:16:32 -04006302
6303 if (bufSize < 0)
6304 {
Geoff Langb1196682014-07-23 13:47:29 -04006305 context->recordError(gl::Error(GL_INVALID_VALUE));
6306 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006307 }
6308
6309 if (!gl::ValidProgram(context, program))
6310 {
6311 return;
6312 }
6313
6314 gl::Program *programObject = context->getProgram(program);
6315 ASSERT(programObject);
6316
6317 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6318 {
Geoff Langb1196682014-07-23 13:47:29 -04006319 context->recordError(gl::Error(GL_INVALID_VALUE));
6320 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006321 }
6322
6323 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006324 }
6325}
6326
Kenneth Russell67ea1902014-10-06 16:44:50 -07006327void 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 +00006328{
6329 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6330 index, size, type, stride, pointer);
6331
Geoff Langbfdea662014-07-23 14:16:32 -04006332 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006333 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006334 {
Geoff Langbfdea662014-07-23 14:16:32 -04006335 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006336 {
Geoff Langb1196682014-07-23 13:47:29 -04006337 context->recordError(gl::Error(GL_INVALID_OPERATION));
6338 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006339 }
6340
Geoff Langb1196682014-07-23 13:47:29 -04006341 if (index >= gl::MAX_VERTEX_ATTRIBS)
6342 {
6343 context->recordError(gl::Error(GL_INVALID_VALUE));
6344 return;
6345 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006346
Geoff Langb1196682014-07-23 13:47:29 -04006347 if (size < 1 || size > 4)
6348 {
6349 context->recordError(gl::Error(GL_INVALID_VALUE));
6350 return;
6351 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006352
Geoff Langb1196682014-07-23 13:47:29 -04006353 switch (type)
6354 {
6355 case GL_BYTE:
6356 case GL_UNSIGNED_BYTE:
6357 case GL_SHORT:
6358 case GL_UNSIGNED_SHORT:
6359 case GL_INT:
6360 case GL_UNSIGNED_INT:
6361 case GL_INT_2_10_10_10_REV:
6362 case GL_UNSIGNED_INT_2_10_10_10_REV:
6363 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006364
Geoff Langb1196682014-07-23 13:47:29 -04006365 default:
6366 context->recordError(gl::Error(GL_INVALID_ENUM));
6367 return;
6368 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006369
Geoff Langb1196682014-07-23 13:47:29 -04006370 if (stride < 0)
6371 {
6372 context->recordError(gl::Error(GL_INVALID_VALUE));
6373 return;
6374 }
Geoff Langbfdea662014-07-23 14:16:32 -04006375
Geoff Langb1196682014-07-23 13:47:29 -04006376 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6377 {
6378 context->recordError(gl::Error(GL_INVALID_OPERATION));
6379 return;
6380 }
6381
Geoff Langbfdea662014-07-23 14:16:32 -04006382 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6383 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6384 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6385 // and the pointer argument is not NULL.
6386 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006387 {
Geoff Langb1196682014-07-23 13:47:29 -04006388 context->recordError(gl::Error(GL_INVALID_OPERATION));
6389 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006390 }
6391
Geoff Langbfdea662014-07-23 14:16:32 -04006392 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6393 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006394 }
6395}
6396
Kenneth Russell67ea1902014-10-06 16:44:50 -07006397void GL_APIENTRY glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006398{
6399 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6400 index, pname, params);
6401
Geoff Langbfdea662014-07-23 14:16:32 -04006402 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006403 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006404 {
Geoff Langbfdea662014-07-23 14:16:32 -04006405 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006406 {
Geoff Langb1196682014-07-23 13:47:29 -04006407 context->recordError(gl::Error(GL_INVALID_OPERATION));
6408 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006409 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006410
Geoff Langbfdea662014-07-23 14:16:32 -04006411 if (index >= gl::MAX_VERTEX_ATTRIBS)
6412 {
Geoff Langb1196682014-07-23 13:47:29 -04006413 context->recordError(gl::Error(GL_INVALID_VALUE));
6414 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006415 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006416
Geoff Langbfdea662014-07-23 14:16:32 -04006417 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006418
Geoff Langb1196682014-07-23 13:47:29 -04006419 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006420 {
6421 return;
6422 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006423
Geoff Langbfdea662014-07-23 14:16:32 -04006424 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6425 {
6426 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6427 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006428 {
Geoff Langbfdea662014-07-23 14:16:32 -04006429 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006430 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006431 }
Geoff Langbfdea662014-07-23 14:16:32 -04006432 else
6433 {
6434 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6435 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006436 }
6437}
6438
Kenneth Russell67ea1902014-10-06 16:44:50 -07006439void GL_APIENTRY glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006440{
6441 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6442 index, pname, params);
6443
Geoff Langbfdea662014-07-23 14:16:32 -04006444 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006445 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006446 {
Geoff Langbfdea662014-07-23 14:16:32 -04006447 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006448 {
Geoff Langb1196682014-07-23 13:47:29 -04006449 context->recordError(gl::Error(GL_INVALID_OPERATION));
6450 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006451 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006452
Geoff Langbfdea662014-07-23 14:16:32 -04006453 if (index >= gl::MAX_VERTEX_ATTRIBS)
6454 {
Geoff Langb1196682014-07-23 13:47:29 -04006455 context->recordError(gl::Error(GL_INVALID_VALUE));
6456 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006457 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006458
Geoff Langbfdea662014-07-23 14:16:32 -04006459 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006460
Geoff Langb1196682014-07-23 13:47:29 -04006461 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006462 {
6463 return;
6464 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006465
Geoff Langbfdea662014-07-23 14:16:32 -04006466 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6467 {
6468 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6469 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006470 {
Geoff Langbfdea662014-07-23 14:16:32 -04006471 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006472 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006473 }
Geoff Langbfdea662014-07-23 14:16:32 -04006474 else
6475 {
6476 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6477 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006478 }
6479}
6480
Kenneth Russell67ea1902014-10-06 16:44:50 -07006481void GL_APIENTRY glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006482{
6483 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6484 index, x, y, z, w);
6485
Geoff Langbfdea662014-07-23 14:16:32 -04006486 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006487 if (context)
6488 {
6489 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006490 {
Geoff Langb1196682014-07-23 13:47:29 -04006491 context->recordError(gl::Error(GL_INVALID_OPERATION));
6492 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006493 }
Geoff Langbfdea662014-07-23 14:16:32 -04006494
6495 if (index >= gl::MAX_VERTEX_ATTRIBS)
6496 {
Geoff Langb1196682014-07-23 13:47:29 -04006497 context->recordError(gl::Error(GL_INVALID_VALUE));
6498 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006499 }
6500
6501 GLint vals[4] = { x, y, z, w };
6502 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006503 }
6504}
6505
Kenneth Russell67ea1902014-10-06 16:44:50 -07006506void GL_APIENTRY glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006507{
6508 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6509 index, x, y, z, w);
6510
Geoff Langbfdea662014-07-23 14:16:32 -04006511 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006512 if (context)
6513 {
6514 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006515 {
Geoff Langb1196682014-07-23 13:47:29 -04006516 context->recordError(gl::Error(GL_INVALID_OPERATION));
6517 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006518 }
Geoff Langbfdea662014-07-23 14:16:32 -04006519
6520 if (index >= gl::MAX_VERTEX_ATTRIBS)
6521 {
Geoff Langb1196682014-07-23 13:47:29 -04006522 context->recordError(gl::Error(GL_INVALID_VALUE));
6523 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006524 }
6525
6526 GLuint vals[4] = { x, y, z, w };
6527 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006528 }
6529}
6530
Kenneth Russell67ea1902014-10-06 16:44:50 -07006531void GL_APIENTRY glVertexAttribI4iv(GLuint index, const GLint* v)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006532{
6533 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6534
Geoff Langbfdea662014-07-23 14:16:32 -04006535 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006536 if (context)
6537 {
6538 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006539 {
Geoff Langb1196682014-07-23 13:47:29 -04006540 context->recordError(gl::Error(GL_INVALID_OPERATION));
6541 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006542 }
Geoff Langbfdea662014-07-23 14:16:32 -04006543
6544 if (index >= gl::MAX_VERTEX_ATTRIBS)
6545 {
Geoff Langb1196682014-07-23 13:47:29 -04006546 context->recordError(gl::Error(GL_INVALID_VALUE));
6547 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006548 }
6549
6550 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006551 }
6552}
6553
Kenneth Russell67ea1902014-10-06 16:44:50 -07006554void GL_APIENTRY glVertexAttribI4uiv(GLuint index, const GLuint* v)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006555{
6556 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6557
Geoff Langbfdea662014-07-23 14:16:32 -04006558 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006559 if (context)
6560 {
6561 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006562 {
Geoff Langb1196682014-07-23 13:47:29 -04006563 context->recordError(gl::Error(GL_INVALID_OPERATION));
6564 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006565 }
Geoff Langbfdea662014-07-23 14:16:32 -04006566
6567 if (index >= gl::MAX_VERTEX_ATTRIBS)
6568 {
Geoff Langb1196682014-07-23 13:47:29 -04006569 context->recordError(gl::Error(GL_INVALID_VALUE));
6570 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006571 }
6572
6573 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006574 }
6575}
6576
Kenneth Russell67ea1902014-10-06 16:44:50 -07006577void GL_APIENTRY glGetUniformuiv(GLuint program, GLint location, GLuint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006578{
6579 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6580 program, location, params);
6581
Geoff Langbfdea662014-07-23 14:16:32 -04006582 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006583 if (context)
6584 {
Jamie Madill0063c512014-08-25 15:47:53 -04006585 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006586 {
Jamie Madill0063c512014-08-25 15:47:53 -04006587 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006588 }
Geoff Langbfdea662014-07-23 14:16:32 -04006589
Jamie Madilla502c742014-08-28 17:19:13 -04006590 gl::Program *programObject = context->getProgram(program);
6591 ASSERT(programObject);
6592 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006593 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006594
Jamie Madill99a1e982014-08-25 15:47:54 -04006595 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006596 }
6597}
6598
Kenneth Russell67ea1902014-10-06 16:44:50 -07006599GLint GL_APIENTRY glGetFragDataLocation(GLuint program, const GLchar *name)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006600{
6601 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6602 program, name);
6603
Geoff Langbfdea662014-07-23 14:16:32 -04006604 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006605 if (context)
6606 {
6607 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006608 {
Geoff Langb1196682014-07-23 13:47:29 -04006609 context->recordError(gl::Error(GL_INVALID_OPERATION));
6610 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006611 }
Geoff Langbfdea662014-07-23 14:16:32 -04006612
6613 if (program == 0)
6614 {
Geoff Langb1196682014-07-23 13:47:29 -04006615 context->recordError(gl::Error(GL_INVALID_VALUE));
6616 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006617 }
6618
6619 gl::Program *programObject = context->getProgram(program);
6620
6621 if (!programObject || !programObject->isLinked())
6622 {
Geoff Langb1196682014-07-23 13:47:29 -04006623 context->recordError(gl::Error(GL_INVALID_OPERATION));
6624 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006625 }
6626
6627 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6628 if (!programBinary)
6629 {
Geoff Langb1196682014-07-23 13:47:29 -04006630 context->recordError(gl::Error(GL_INVALID_OPERATION));
6631 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006632 }
6633
6634 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006635 }
6636
6637 return 0;
6638}
6639
Kenneth Russell67ea1902014-10-06 16:44:50 -07006640void GL_APIENTRY glUniform1ui(GLint location, GLuint v0)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006641{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006642 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006643}
6644
Kenneth Russell67ea1902014-10-06 16:44:50 -07006645void GL_APIENTRY glUniform2ui(GLint location, GLuint v0, GLuint v1)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006646{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006647 const GLuint xy[] = { v0, v1 };
6648 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006649}
6650
Kenneth Russell67ea1902014-10-06 16:44:50 -07006651void GL_APIENTRY glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006652{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006653 const GLuint xyz[] = { v0, v1, v2 };
6654 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006655}
6656
Kenneth Russell67ea1902014-10-06 16:44:50 -07006657void GL_APIENTRY glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006658{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006659 const GLuint xyzw[] = { v0, v1, v2, v3 };
6660 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006661}
6662
Kenneth Russell67ea1902014-10-06 16:44:50 -07006663void GL_APIENTRY glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006664{
6665 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6666 location, count, value);
6667
Geoff Langbfdea662014-07-23 14:16:32 -04006668 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006669 if (context)
6670 {
6671 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006672 {
Geoff Langbfdea662014-07-23 14:16:32 -04006673 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006674 }
Geoff Langbfdea662014-07-23 14:16:32 -04006675
6676 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6677 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006678 }
6679}
6680
Kenneth Russell67ea1902014-10-06 16:44:50 -07006681void GL_APIENTRY glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006682{
6683 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6684 location, count, value);
6685
Geoff Langbfdea662014-07-23 14:16:32 -04006686 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006687 if (context)
6688 {
6689 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006690 {
Geoff Langbfdea662014-07-23 14:16:32 -04006691 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006692 }
Geoff Langbfdea662014-07-23 14:16:32 -04006693
6694 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6695 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006696 }
6697}
6698
Kenneth Russell67ea1902014-10-06 16:44:50 -07006699void GL_APIENTRY glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006700{
6701 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6702 location, count, value);
6703
Geoff Langbfdea662014-07-23 14:16:32 -04006704 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006705 if (context)
6706 {
6707 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006708 {
Geoff Langbfdea662014-07-23 14:16:32 -04006709 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006710 }
Geoff Langbfdea662014-07-23 14:16:32 -04006711
6712 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6713 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006714 }
6715}
6716
Kenneth Russell67ea1902014-10-06 16:44:50 -07006717void GL_APIENTRY glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006718{
6719 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6720 location, count, value);
6721
Geoff Langbfdea662014-07-23 14:16:32 -04006722 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006723 if (context)
6724 {
6725 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006726 {
Geoff Langbfdea662014-07-23 14:16:32 -04006727 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006728 }
Geoff Langbfdea662014-07-23 14:16:32 -04006729
6730 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6731 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006732 }
6733}
6734
Kenneth Russell67ea1902014-10-06 16:44:50 -07006735void GL_APIENTRY glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006736{
6737 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6738 buffer, drawbuffer, value);
6739
Geoff Langbfdea662014-07-23 14:16:32 -04006740 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006741 if (context)
6742 {
6743 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006744 {
Geoff Langbfdea662014-07-23 14:16:32 -04006745 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006746 }
Geoff Langbfdea662014-07-23 14:16:32 -04006747
6748 switch (buffer)
6749 {
6750 case GL_COLOR:
6751 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6752 {
Geoff Langb1196682014-07-23 13:47:29 -04006753 context->recordError(gl::Error(GL_INVALID_VALUE));
6754 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006755 }
6756 break;
Geoff Langb1196682014-07-23 13:47:29 -04006757
Geoff Langbfdea662014-07-23 14:16:32 -04006758 case GL_STENCIL:
6759 if (drawbuffer != 0)
6760 {
Geoff Langb1196682014-07-23 13:47:29 -04006761 context->recordError(gl::Error(GL_INVALID_VALUE));
6762 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006763 }
6764 break;
Geoff Langb1196682014-07-23 13:47:29 -04006765
Geoff Langbfdea662014-07-23 14:16:32 -04006766 default:
Geoff Langb1196682014-07-23 13:47:29 -04006767 context->recordError(gl::Error(GL_INVALID_ENUM));
6768 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006769 }
6770
Geoff Langcc79b8c2014-07-25 13:48:02 -04006771 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6772 if (error.isError())
6773 {
6774 context->recordError(error);
6775 return;
6776 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006777 }
6778}
6779
Kenneth Russell67ea1902014-10-06 16:44:50 -07006780void GL_APIENTRY glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006781{
6782 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6783 buffer, drawbuffer, value);
6784
Geoff Langbfdea662014-07-23 14:16:32 -04006785 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006786 if (context)
6787 {
6788 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006789 {
Geoff Langbfdea662014-07-23 14:16:32 -04006790 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006791 }
Geoff Langbfdea662014-07-23 14:16:32 -04006792
6793 switch (buffer)
6794 {
6795 case GL_COLOR:
6796 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6797 {
Geoff Langb1196682014-07-23 13:47:29 -04006798 context->recordError(gl::Error(GL_INVALID_VALUE));
6799 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006800 }
6801 break;
Geoff Langb1196682014-07-23 13:47:29 -04006802
Geoff Langbfdea662014-07-23 14:16:32 -04006803 default:
Geoff Langb1196682014-07-23 13:47:29 -04006804 context->recordError(gl::Error(GL_INVALID_ENUM));
6805 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006806 }
6807
Geoff Langcc79b8c2014-07-25 13:48:02 -04006808 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6809 if (error.isError())
6810 {
6811 context->recordError(error);
6812 return;
6813 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006814 }
6815}
6816
Kenneth Russell67ea1902014-10-06 16:44:50 -07006817void GL_APIENTRY glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006818{
6819 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6820 buffer, drawbuffer, value);
6821
Geoff Langbfdea662014-07-23 14:16:32 -04006822 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006823 if (context)
6824 {
6825 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006826 {
Geoff Langbfdea662014-07-23 14:16:32 -04006827 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006828 }
Geoff Langbfdea662014-07-23 14:16:32 -04006829
6830 switch (buffer)
6831 {
6832 case GL_COLOR:
6833 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6834 {
Geoff Langb1196682014-07-23 13:47:29 -04006835 context->recordError(gl::Error(GL_INVALID_VALUE));
6836 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006837 }
6838 break;
Geoff Langb1196682014-07-23 13:47:29 -04006839
Geoff Langbfdea662014-07-23 14:16:32 -04006840 case GL_DEPTH:
6841 if (drawbuffer != 0)
6842 {
Geoff Langb1196682014-07-23 13:47:29 -04006843 context->recordError(gl::Error(GL_INVALID_VALUE));
6844 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006845 }
6846 break;
Geoff Langb1196682014-07-23 13:47:29 -04006847
Geoff Langbfdea662014-07-23 14:16:32 -04006848 default:
Geoff Langb1196682014-07-23 13:47:29 -04006849 context->recordError(gl::Error(GL_INVALID_ENUM));
6850 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006851 }
6852
Geoff Langcc79b8c2014-07-25 13:48:02 -04006853 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6854 if (error.isError())
6855 {
6856 context->recordError(error);
6857 return;
6858 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006859 }
6860}
6861
Kenneth Russell67ea1902014-10-06 16:44:50 -07006862void GL_APIENTRY glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006863{
6864 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6865 buffer, drawbuffer, depth, stencil);
6866
Geoff Langbfdea662014-07-23 14:16:32 -04006867 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006868 if (context)
6869 {
6870 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006871 {
Geoff Langbfdea662014-07-23 14:16:32 -04006872 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006873 }
Geoff Langbfdea662014-07-23 14:16:32 -04006874
6875 switch (buffer)
6876 {
6877 case GL_DEPTH_STENCIL:
6878 if (drawbuffer != 0)
6879 {
Geoff Langb1196682014-07-23 13:47:29 -04006880 context->recordError(gl::Error(GL_INVALID_VALUE));
6881 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006882 }
6883 break;
Geoff Langb1196682014-07-23 13:47:29 -04006884
Geoff Langbfdea662014-07-23 14:16:32 -04006885 default:
Geoff Langb1196682014-07-23 13:47:29 -04006886 context->recordError(gl::Error(GL_INVALID_ENUM));
6887 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006888 }
6889
Geoff Langcc79b8c2014-07-25 13:48:02 -04006890 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6891 if (error.isError())
6892 {
6893 context->recordError(error);
6894 return;
6895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006896 }
6897}
6898
Kenneth Russell67ea1902014-10-06 16:44:50 -07006899const GLubyte* GL_APIENTRY glGetStringi(GLenum name, GLuint index)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006900{
6901 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6902
Geoff Langbfdea662014-07-23 14:16:32 -04006903 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006904 if (context)
6905 {
6906 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006907 {
Geoff Langb1196682014-07-23 13:47:29 -04006908 context->recordError(gl::Error(GL_INVALID_OPERATION));
6909 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006910 }
Geoff Langbfdea662014-07-23 14:16:32 -04006911
6912 if (name != GL_EXTENSIONS)
6913 {
Geoff Langb1196682014-07-23 13:47:29 -04006914 context->recordError(gl::Error(GL_INVALID_ENUM));
6915 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006916 }
6917
6918 if (index >= context->getExtensionStringCount())
6919 {
Geoff Langb1196682014-07-23 13:47:29 -04006920 context->recordError(gl::Error(GL_INVALID_VALUE));
6921 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006922 }
6923
6924 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006925 }
6926
6927 return NULL;
6928}
6929
Kenneth Russell67ea1902014-10-06 16:44:50 -07006930void GL_APIENTRY glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006931{
6932 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6933 readTarget, writeTarget, readOffset, writeOffset, size);
6934
Geoff Langbfdea662014-07-23 14:16:32 -04006935 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006936 if (context)
6937 {
6938 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006939 {
Geoff Langb1196682014-07-23 13:47:29 -04006940 context->recordError(gl::Error(GL_INVALID_OPERATION));
6941 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006942 }
Geoff Langbfdea662014-07-23 14:16:32 -04006943
6944 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6945 {
Geoff Langb1196682014-07-23 13:47:29 -04006946 context->recordError(gl::Error(GL_INVALID_ENUM));
6947 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006948 }
6949
6950 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6951 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6952
6953 if (!readBuffer || !writeBuffer)
6954 {
Geoff Langb1196682014-07-23 13:47:29 -04006955 context->recordError(gl::Error(GL_INVALID_OPERATION));
6956 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006957 }
6958
Jamie Madillcfaaf722014-07-31 10:47:54 -04006959 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006960 if (readBuffer->isMapped() || writeBuffer->isMapped())
6961 {
Geoff Langb1196682014-07-23 13:47:29 -04006962 context->recordError(gl::Error(GL_INVALID_OPERATION));
6963 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006964 }
6965
6966 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6967 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6968 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6969 {
Geoff Langb1196682014-07-23 13:47:29 -04006970 context->recordError(gl::Error(GL_INVALID_VALUE));
6971 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006972 }
6973
Kenneth Russell67ea1902014-10-06 16:44:50 -07006974 if (readBuffer == writeBuffer && std::abs(readOffset - writeOffset) < size)
Geoff Langbfdea662014-07-23 14:16:32 -04006975 {
Geoff Langb1196682014-07-23 13:47:29 -04006976 context->recordError(gl::Error(GL_INVALID_VALUE));
6977 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006978 }
6979
Geoff Langbfdea662014-07-23 14:16:32 -04006980 // if size is zero, the copy is a successful no-op
6981 if (size > 0)
6982 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006983 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6984 if (error.isError())
6985 {
6986 context->recordError(error);
6987 return;
6988 }
Geoff Langbfdea662014-07-23 14:16:32 -04006989 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006990 }
6991}
6992
Kenneth Russell67ea1902014-10-06 16:44:50 -07006993void GL_APIENTRY glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006994{
6995 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6996 program, uniformCount, uniformNames, uniformIndices);
6997
Geoff Langbfdea662014-07-23 14:16:32 -04006998 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006999 if (context)
7000 {
7001 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007002 {
Geoff Langb1196682014-07-23 13:47:29 -04007003 context->recordError(gl::Error(GL_INVALID_OPERATION));
7004 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007005 }
7006
7007 if (uniformCount < 0)
7008 {
Geoff Langb1196682014-07-23 13:47:29 -04007009 context->recordError(gl::Error(GL_INVALID_VALUE));
7010 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007011 }
7012
7013 gl::Program *programObject = context->getProgram(program);
7014
7015 if (!programObject)
7016 {
7017 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007018 {
Geoff Langb1196682014-07-23 13:47:29 -04007019 context->recordError(gl::Error(GL_INVALID_OPERATION));
7020 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007021 }
Geoff Langbfdea662014-07-23 14:16:32 -04007022 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007023 {
Geoff Langb1196682014-07-23 13:47:29 -04007024 context->recordError(gl::Error(GL_INVALID_VALUE));
7025 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007026 }
Geoff Langbfdea662014-07-23 14:16:32 -04007027 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007028
Geoff Langbfdea662014-07-23 14:16:32 -04007029 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7030 if (!programObject->isLinked() || !programBinary)
7031 {
7032 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007033 {
Geoff Langbfdea662014-07-23 14:16:32 -04007034 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007035 }
7036 }
Geoff Langbfdea662014-07-23 14:16:32 -04007037 else
7038 {
7039 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7040 {
7041 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
7042 }
7043 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007044 }
7045}
7046
Kenneth Russell67ea1902014-10-06 16:44:50 -07007047void 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 +00007048{
7049 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7050 program, uniformCount, uniformIndices, pname, params);
7051
Geoff Langbfdea662014-07-23 14:16:32 -04007052 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007053 if (context)
7054 {
7055 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007056 {
Geoff Langb1196682014-07-23 13:47:29 -04007057 context->recordError(gl::Error(GL_INVALID_OPERATION));
7058 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007059 }
7060
7061 if (uniformCount < 0)
7062 {
Geoff Langb1196682014-07-23 13:47:29 -04007063 context->recordError(gl::Error(GL_INVALID_VALUE));
7064 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007065 }
7066
7067 gl::Program *programObject = context->getProgram(program);
7068
7069 if (!programObject)
7070 {
7071 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007072 {
Geoff Langb1196682014-07-23 13:47:29 -04007073 context->recordError(gl::Error(GL_INVALID_OPERATION));
7074 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007075 }
Geoff Langbfdea662014-07-23 14:16:32 -04007076 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007077 {
Geoff Langb1196682014-07-23 13:47:29 -04007078 context->recordError(gl::Error(GL_INVALID_VALUE));
7079 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007080 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007081 }
Geoff Langbfdea662014-07-23 14:16:32 -04007082
7083 switch (pname)
7084 {
7085 case GL_UNIFORM_TYPE:
7086 case GL_UNIFORM_SIZE:
7087 case GL_UNIFORM_NAME_LENGTH:
7088 case GL_UNIFORM_BLOCK_INDEX:
7089 case GL_UNIFORM_OFFSET:
7090 case GL_UNIFORM_ARRAY_STRIDE:
7091 case GL_UNIFORM_MATRIX_STRIDE:
7092 case GL_UNIFORM_IS_ROW_MAJOR:
7093 break;
Geoff Langb1196682014-07-23 13:47:29 -04007094
Geoff Langbfdea662014-07-23 14:16:32 -04007095 default:
Geoff Langb1196682014-07-23 13:47:29 -04007096 context->recordError(gl::Error(GL_INVALID_ENUM));
7097 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007098 }
7099
7100 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7101
7102 if (!programBinary && uniformCount > 0)
7103 {
Geoff Langb1196682014-07-23 13:47:29 -04007104 context->recordError(gl::Error(GL_INVALID_VALUE));
7105 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007106 }
7107
7108 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7109 {
7110 const GLuint index = uniformIndices[uniformId];
7111
7112 if (index >= (GLuint)programBinary->getActiveUniformCount())
7113 {
Geoff Langb1196682014-07-23 13:47:29 -04007114 context->recordError(gl::Error(GL_INVALID_VALUE));
7115 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007116 }
7117 }
7118
7119 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7120 {
7121 const GLuint index = uniformIndices[uniformId];
7122 params[uniformId] = programBinary->getActiveUniformi(index, pname);
7123 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007124 }
7125}
7126
Kenneth Russell67ea1902014-10-06 16:44:50 -07007127GLuint GL_APIENTRY glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007128{
7129 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
7130
Geoff Langbfdea662014-07-23 14:16:32 -04007131 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007132 if (context)
7133 {
7134 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007135 {
Geoff Langb1196682014-07-23 13:47:29 -04007136 context->recordError(gl::Error(GL_INVALID_OPERATION));
7137 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04007138 }
7139
7140 gl::Program *programObject = context->getProgram(program);
7141
7142 if (!programObject)
7143 {
7144 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007145 {
Geoff Langb1196682014-07-23 13:47:29 -04007146 context->recordError(gl::Error(GL_INVALID_OPERATION));
7147 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007148 }
Geoff Langbfdea662014-07-23 14:16:32 -04007149 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007150 {
Geoff Langb1196682014-07-23 13:47:29 -04007151 context->recordError(gl::Error(GL_INVALID_VALUE));
7152 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007153 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007154 }
Geoff Langbfdea662014-07-23 14:16:32 -04007155
7156 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7157 if (!programBinary)
7158 {
7159 return GL_INVALID_INDEX;
7160 }
7161
7162 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007163 }
7164
7165 return 0;
7166}
7167
Kenneth Russell67ea1902014-10-06 16:44:50 -07007168void GL_APIENTRY glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007169{
7170 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7171 program, uniformBlockIndex, pname, params);
7172
Geoff Langbfdea662014-07-23 14:16:32 -04007173 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007174 if (context)
7175 {
7176 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007177 {
Geoff Langb1196682014-07-23 13:47:29 -04007178 context->recordError(gl::Error(GL_INVALID_OPERATION));
7179 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007180 }
7181 gl::Program *programObject = context->getProgram(program);
7182
7183 if (!programObject)
7184 {
7185 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007186 {
Geoff Langb1196682014-07-23 13:47:29 -04007187 context->recordError(gl::Error(GL_INVALID_OPERATION));
7188 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007189 }
Geoff Langbfdea662014-07-23 14:16:32 -04007190 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007191 {
Geoff Langb1196682014-07-23 13:47:29 -04007192 context->recordError(gl::Error(GL_INVALID_VALUE));
7193 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007194 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007195 }
Geoff Langbfdea662014-07-23 14:16:32 -04007196
7197 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7198
7199 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7200 {
Geoff Langb1196682014-07-23 13:47:29 -04007201 context->recordError(gl::Error(GL_INVALID_VALUE));
7202 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007203 }
7204
7205 switch (pname)
7206 {
7207 case GL_UNIFORM_BLOCK_BINDING:
7208 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7209 break;
7210
7211 case GL_UNIFORM_BLOCK_DATA_SIZE:
7212 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7213 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7214 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7215 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7216 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7217 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7218 break;
7219
7220 default:
Geoff Langb1196682014-07-23 13:47:29 -04007221 context->recordError(gl::Error(GL_INVALID_ENUM));
7222 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007223 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007224 }
7225}
7226
Kenneth Russell67ea1902014-10-06 16:44:50 -07007227void GL_APIENTRY glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007228{
7229 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7230 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7231
Geoff Langbfdea662014-07-23 14:16:32 -04007232 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007233 if (context)
7234 {
7235 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007236 {
Geoff Langb1196682014-07-23 13:47:29 -04007237 context->recordError(gl::Error(GL_INVALID_OPERATION));
7238 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007239 }
7240
7241 gl::Program *programObject = context->getProgram(program);
7242
7243 if (!programObject)
7244 {
7245 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007246 {
Geoff Langb1196682014-07-23 13:47:29 -04007247 context->recordError(gl::Error(GL_INVALID_OPERATION));
7248 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007249 }
Geoff Langbfdea662014-07-23 14:16:32 -04007250 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007251 {
Geoff Langb1196682014-07-23 13:47:29 -04007252 context->recordError(gl::Error(GL_INVALID_VALUE));
7253 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007254 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007255 }
Geoff Langbfdea662014-07-23 14:16:32 -04007256
7257 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7258
7259 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7260 {
Geoff Langb1196682014-07-23 13:47:29 -04007261 context->recordError(gl::Error(GL_INVALID_VALUE));
7262 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007263 }
7264
7265 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007266 }
7267}
7268
Kenneth Russell67ea1902014-10-06 16:44:50 -07007269void GL_APIENTRY glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007270{
7271 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7272 program, uniformBlockIndex, uniformBlockBinding);
7273
Geoff Langbfdea662014-07-23 14:16:32 -04007274 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007275 if (context)
7276 {
7277 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007278 {
Geoff Langb1196682014-07-23 13:47:29 -04007279 context->recordError(gl::Error(GL_INVALID_OPERATION));
7280 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007281 }
7282
Geoff Lang3a61c322014-07-10 13:01:54 -04007283 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007284 {
Geoff Langb1196682014-07-23 13:47:29 -04007285 context->recordError(gl::Error(GL_INVALID_VALUE));
7286 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007287 }
7288
7289 gl::Program *programObject = context->getProgram(program);
7290
7291 if (!programObject)
7292 {
7293 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007294 {
Geoff Langb1196682014-07-23 13:47:29 -04007295 context->recordError(gl::Error(GL_INVALID_OPERATION));
7296 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007297 }
Geoff Langbfdea662014-07-23 14:16:32 -04007298 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007299 {
Geoff Langb1196682014-07-23 13:47:29 -04007300 context->recordError(gl::Error(GL_INVALID_VALUE));
7301 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007302 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007303 }
Geoff Langbfdea662014-07-23 14:16:32 -04007304
7305 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7306
7307 // if never linked, there won't be any uniform blocks
7308 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7309 {
Geoff Langb1196682014-07-23 13:47:29 -04007310 context->recordError(gl::Error(GL_INVALID_VALUE));
7311 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007312 }
7313
7314 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007315 }
7316}
7317
Kenneth Russell67ea1902014-10-06 16:44:50 -07007318void GL_APIENTRY glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007319{
7320 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7321 mode, first, count, instanceCount);
7322
Geoff Langbfdea662014-07-23 14:16:32 -04007323 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007324 if (context)
7325 {
7326 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007327 {
Geoff Langb1196682014-07-23 13:47:29 -04007328 context->recordError(gl::Error(GL_INVALID_OPERATION));
7329 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007330 }
Geoff Langbfdea662014-07-23 14:16:32 -04007331
7332 // glDrawArraysInstanced
7333 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007334 }
7335}
7336
Kenneth Russell67ea1902014-10-06 16:44:50 -07007337void 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 +00007338{
7339 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7340 mode, count, type, indices, instanceCount);
7341
Geoff Langbfdea662014-07-23 14:16:32 -04007342 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007343 if (context)
7344 {
7345 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007346 {
Geoff Langb1196682014-07-23 13:47:29 -04007347 context->recordError(gl::Error(GL_INVALID_OPERATION));
7348 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007349 }
Geoff Langbfdea662014-07-23 14:16:32 -04007350
7351 // glDrawElementsInstanced
7352 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007353 }
7354}
7355
Kenneth Russell67ea1902014-10-06 16:44:50 -07007356GLsync GL_APIENTRY glFenceSync(GLenum condition, GLbitfield flags)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007357{
7358 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7359
Geoff Langbfdea662014-07-23 14:16:32 -04007360 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007361 if (context)
7362 {
7363 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007364 {
Geoff Langb1196682014-07-23 13:47:29 -04007365 context->recordError(gl::Error(GL_INVALID_OPERATION));
7366 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007367 }
Geoff Langbfdea662014-07-23 14:16:32 -04007368
7369 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7370 {
Geoff Langb1196682014-07-23 13:47:29 -04007371 context->recordError(gl::Error(GL_INVALID_ENUM));
7372 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007373 }
7374
7375 if (flags != 0)
7376 {
Geoff Langb1196682014-07-23 13:47:29 -04007377 context->recordError(gl::Error(GL_INVALID_VALUE));
7378 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007379 }
7380
Geoff Lang882033e2014-09-30 11:26:07 -04007381 GLsync fenceSync = context->createFenceSync();
7382
7383 gl::FenceSync *fenceSyncObject = context->getFenceSync(fenceSync);
7384 gl::Error error = fenceSyncObject->set(condition);
7385 if (error.isError())
7386 {
7387 context->deleteFenceSync(fenceSync);
7388 context->recordError(error);
7389 return NULL;
7390 }
7391
7392 return fenceSync;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007393 }
7394
7395 return NULL;
7396}
7397
Kenneth Russell67ea1902014-10-06 16:44:50 -07007398GLboolean GL_APIENTRY glIsSync(GLsync sync)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007399{
7400 EVENT("(GLsync sync = 0x%0.8p)", sync);
7401
Geoff Langbfdea662014-07-23 14:16:32 -04007402 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007403 if (context)
7404 {
7405 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007406 {
Geoff Langb1196682014-07-23 13:47:29 -04007407 context->recordError(gl::Error(GL_INVALID_OPERATION));
7408 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007409 }
Geoff Langbfdea662014-07-23 14:16:32 -04007410
7411 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007412 }
7413
7414 return GL_FALSE;
7415}
7416
Kenneth Russell67ea1902014-10-06 16:44:50 -07007417void GL_APIENTRY glDeleteSync(GLsync sync)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007418{
7419 EVENT("(GLsync sync = 0x%0.8p)", sync);
7420
Geoff Langbfdea662014-07-23 14:16:32 -04007421 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007422 if (context)
7423 {
7424 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007425 {
Geoff Langb1196682014-07-23 13:47:29 -04007426 context->recordError(gl::Error(GL_INVALID_OPERATION));
7427 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007428 }
Geoff Langbfdea662014-07-23 14:16:32 -04007429
7430 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7431 {
Geoff Langb1196682014-07-23 13:47:29 -04007432 context->recordError(gl::Error(GL_INVALID_VALUE));
7433 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007434 }
7435
7436 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007437 }
7438}
7439
Kenneth Russell67ea1902014-10-06 16:44:50 -07007440GLenum GL_APIENTRY glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007441{
7442 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7443 sync, flags, timeout);
7444
Geoff Langbfdea662014-07-23 14:16:32 -04007445 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007446 if (context)
7447 {
7448 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007449 {
Geoff Langb1196682014-07-23 13:47:29 -04007450 context->recordError(gl::Error(GL_INVALID_OPERATION));
7451 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007452 }
Geoff Langbfdea662014-07-23 14:16:32 -04007453
7454 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7455 {
Geoff Langb1196682014-07-23 13:47:29 -04007456 context->recordError(gl::Error(GL_INVALID_VALUE));
7457 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007458 }
7459
7460 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7461
7462 if (!fenceSync)
7463 {
Geoff Langb1196682014-07-23 13:47:29 -04007464 context->recordError(gl::Error(GL_INVALID_VALUE));
7465 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007466 }
7467
Geoff Lang882033e2014-09-30 11:26:07 -04007468 GLenum result = GL_WAIT_FAILED;
7469 gl::Error error = fenceSync->clientWait(flags, timeout, &result);
7470 if (error.isError())
7471 {
7472 context->recordError(error);
7473 return GL_WAIT_FAILED;
7474 }
7475
7476 return result;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007477 }
7478
7479 return GL_FALSE;
7480}
7481
Kenneth Russell67ea1902014-10-06 16:44:50 -07007482void GL_APIENTRY glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007483{
7484 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7485 sync, flags, timeout);
7486
Geoff Langbfdea662014-07-23 14:16:32 -04007487 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007488 if (context)
7489 {
7490 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007491 {
Geoff Langb1196682014-07-23 13:47:29 -04007492 context->recordError(gl::Error(GL_INVALID_OPERATION));
7493 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007494 }
Geoff Langbfdea662014-07-23 14:16:32 -04007495
7496 if (flags != 0)
7497 {
Geoff Langb1196682014-07-23 13:47:29 -04007498 context->recordError(gl::Error(GL_INVALID_VALUE));
7499 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007500 }
7501
7502 if (timeout != GL_TIMEOUT_IGNORED)
7503 {
Geoff Langb1196682014-07-23 13:47:29 -04007504 context->recordError(gl::Error(GL_INVALID_VALUE));
7505 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007506 }
7507
7508 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7509
7510 if (!fenceSync)
7511 {
Geoff Langb1196682014-07-23 13:47:29 -04007512 context->recordError(gl::Error(GL_INVALID_VALUE));
7513 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007514 }
7515
Geoff Lang882033e2014-09-30 11:26:07 -04007516 gl::Error error = fenceSync->serverWait();
7517 if (error.isError())
7518 {
7519 context->recordError(error);
7520 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007521 }
7522}
7523
Kenneth Russell67ea1902014-10-06 16:44:50 -07007524void GL_APIENTRY glGetInteger64v(GLenum pname, GLint64* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007525{
7526 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7527 pname, params);
7528
Geoff Langbfdea662014-07-23 14:16:32 -04007529 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007530 if (context)
7531 {
7532 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007533 {
Geoff Langb1196682014-07-23 13:47:29 -04007534 context->recordError(gl::Error(GL_INVALID_OPERATION));
7535 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007536 }
Geoff Langbfdea662014-07-23 14:16:32 -04007537
7538 GLenum nativeType;
7539 unsigned int numParams = 0;
7540 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7541 {
7542 return;
7543 }
7544
7545 if (nativeType == GL_INT_64_ANGLEX)
7546 {
7547 context->getInteger64v(pname, params);
7548 }
7549 else
7550 {
7551 CastStateValues(context, nativeType, pname, numParams, params);
7552 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007553 }
7554}
7555
Kenneth Russell67ea1902014-10-06 16:44:50 -07007556void GL_APIENTRY glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007557{
7558 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7559 sync, pname, bufSize, length, values);
7560
Geoff Langbfdea662014-07-23 14:16:32 -04007561 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007562 if (context)
7563 {
7564 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007565 {
Geoff Langb1196682014-07-23 13:47:29 -04007566 context->recordError(gl::Error(GL_INVALID_OPERATION));
7567 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007568 }
Geoff Langbfdea662014-07-23 14:16:32 -04007569
7570 if (bufSize < 0)
7571 {
Geoff Langb1196682014-07-23 13:47:29 -04007572 context->recordError(gl::Error(GL_INVALID_VALUE));
7573 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007574 }
7575
7576 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7577
7578 if (!fenceSync)
7579 {
Geoff Langb1196682014-07-23 13:47:29 -04007580 context->recordError(gl::Error(GL_INVALID_VALUE));
7581 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007582 }
7583
7584 switch (pname)
7585 {
7586 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
Geoff Langbfdea662014-07-23 14:16:32 -04007587 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7588 case GL_SYNC_FLAGS: values[0] = 0; break;
7589
Geoff Lang882033e2014-09-30 11:26:07 -04007590 case GL_SYNC_STATUS:
7591 {
7592 gl::Error error = fenceSync->getStatus(values);
7593 if (error.isError())
7594 {
7595 context->recordError(error);
7596 return;
7597 }
7598 break;
7599 }
7600
Geoff Langbfdea662014-07-23 14:16:32 -04007601 default:
Geoff Langb1196682014-07-23 13:47:29 -04007602 context->recordError(gl::Error(GL_INVALID_ENUM));
7603 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007604 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007605 }
7606}
7607
Kenneth Russell67ea1902014-10-06 16:44:50 -07007608void GL_APIENTRY glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007609{
7610 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7611 target, index, data);
7612
Geoff Langbfdea662014-07-23 14:16:32 -04007613 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007614 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007615 {
Geoff Langbfdea662014-07-23 14:16:32 -04007616 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007617 {
Geoff Langb1196682014-07-23 13:47:29 -04007618 context->recordError(gl::Error(GL_INVALID_OPERATION));
7619 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007621
Geoff Lang3a61c322014-07-10 13:01:54 -04007622 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007623 switch (target)
7624 {
7625 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7626 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7627 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007628 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7629 {
Geoff Langb1196682014-07-23 13:47:29 -04007630 context->recordError(gl::Error(GL_INVALID_VALUE));
7631 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007632 }
Geoff Langbfdea662014-07-23 14:16:32 -04007633 break;
Geoff Langb1196682014-07-23 13:47:29 -04007634
Geoff Langbfdea662014-07-23 14:16:32 -04007635 case GL_UNIFORM_BUFFER_START:
7636 case GL_UNIFORM_BUFFER_SIZE:
7637 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007638 if (index >= caps.maxUniformBufferBindings)
7639 {
Geoff Langb1196682014-07-23 13:47:29 -04007640 context->recordError(gl::Error(GL_INVALID_VALUE));
7641 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007642 }
Geoff Langbfdea662014-07-23 14:16:32 -04007643 break;
Geoff Langb1196682014-07-23 13:47:29 -04007644
Geoff Langbfdea662014-07-23 14:16:32 -04007645 default:
Geoff Langb1196682014-07-23 13:47:29 -04007646 context->recordError(gl::Error(GL_INVALID_ENUM));
7647 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007648 }
7649
7650 if (!(context->getIndexedInteger64v(target, index, data)))
7651 {
7652 GLenum nativeType;
7653 unsigned int numParams = 0;
7654 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007655 {
7656 context->recordError(gl::Error(GL_INVALID_ENUM));
7657 return;
7658 }
Shannon Woods15934d52013-08-19 14:28:49 -04007659
Geoff Langbfdea662014-07-23 14:16:32 -04007660 if (numParams == 0)
7661 return; // it is known that pname is valid, but there are no parameters to return
7662
7663 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007664 {
Geoff Langbfdea662014-07-23 14:16:32 -04007665 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007666
Geoff Langbfdea662014-07-23 14:16:32 -04007667 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007668
Geoff Langbfdea662014-07-23 14:16:32 -04007669 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007670 {
Geoff Langbfdea662014-07-23 14:16:32 -04007671 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007672 }
Geoff Langbfdea662014-07-23 14:16:32 -04007673
7674 delete [] intParams;
7675 }
7676 else
7677 {
7678 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007679 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007680 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007681 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007682}
7683
Kenneth Russell67ea1902014-10-06 16:44:50 -07007684void GL_APIENTRY glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007685{
7686 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7687 target, pname, params);
7688
Geoff Langbfdea662014-07-23 14:16:32 -04007689 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007690 if (context)
7691 {
7692 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007693 {
Geoff Langb1196682014-07-23 13:47:29 -04007694 context->recordError(gl::Error(GL_INVALID_OPERATION));
7695 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007696 }
Geoff Langbfdea662014-07-23 14:16:32 -04007697
7698 if (!gl::ValidBufferTarget(context, target))
7699 {
Geoff Langb1196682014-07-23 13:47:29 -04007700 context->recordError(gl::Error(GL_INVALID_ENUM));
7701 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007702 }
7703
7704 if (!gl::ValidBufferParameter(context, pname))
7705 {
Geoff Langb1196682014-07-23 13:47:29 -04007706 context->recordError(gl::Error(GL_INVALID_ENUM));
7707 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007708 }
7709
7710 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7711
7712 if (!buffer)
7713 {
7714 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007715 context->recordError(gl::Error(GL_INVALID_OPERATION));
7716 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007717 }
7718
7719 switch (pname)
7720 {
7721 case GL_BUFFER_USAGE:
7722 *params = static_cast<GLint64>(buffer->getUsage());
7723 break;
7724 case GL_BUFFER_SIZE:
7725 *params = buffer->getSize();
7726 break;
7727 case GL_BUFFER_ACCESS_FLAGS:
7728 *params = static_cast<GLint64>(buffer->getAccessFlags());
7729 break;
7730 case GL_BUFFER_MAPPED:
7731 *params = static_cast<GLint64>(buffer->isMapped());
7732 break;
7733 case GL_BUFFER_MAP_OFFSET:
7734 *params = buffer->getMapOffset();
7735 break;
7736 case GL_BUFFER_MAP_LENGTH:
7737 *params = buffer->getMapLength();
7738 break;
7739 default: UNREACHABLE(); break;
7740 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007741 }
7742}
7743
Kenneth Russell67ea1902014-10-06 16:44:50 -07007744void GL_APIENTRY glGenSamplers(GLsizei count, GLuint* samplers)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007745{
7746 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7747
Geoff Langbfdea662014-07-23 14:16:32 -04007748 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007749 if (context)
7750 {
7751 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007752 {
Geoff Langb1196682014-07-23 13:47:29 -04007753 context->recordError(gl::Error(GL_INVALID_OPERATION));
7754 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007755 }
Geoff Langbfdea662014-07-23 14:16:32 -04007756
7757 if (count < 0)
7758 {
Geoff Langb1196682014-07-23 13:47:29 -04007759 context->recordError(gl::Error(GL_INVALID_VALUE));
7760 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007761 }
7762
7763 for (int i = 0; i < count; i++)
7764 {
7765 samplers[i] = context->createSampler();
7766 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007767 }
7768}
7769
Kenneth Russell67ea1902014-10-06 16:44:50 -07007770void GL_APIENTRY glDeleteSamplers(GLsizei count, const GLuint* samplers)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007771{
7772 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7773
Geoff Langbfdea662014-07-23 14:16:32 -04007774 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007775 if (context)
7776 {
7777 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007778 {
Geoff Langb1196682014-07-23 13:47:29 -04007779 context->recordError(gl::Error(GL_INVALID_OPERATION));
7780 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007781 }
Geoff Langbfdea662014-07-23 14:16:32 -04007782
7783 if (count < 0)
7784 {
Geoff Langb1196682014-07-23 13:47:29 -04007785 context->recordError(gl::Error(GL_INVALID_VALUE));
7786 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007787 }
7788
7789 for (int i = 0; i < count; i++)
7790 {
7791 context->deleteSampler(samplers[i]);
7792 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007793 }
7794}
7795
Kenneth Russell67ea1902014-10-06 16:44:50 -07007796GLboolean GL_APIENTRY glIsSampler(GLuint sampler)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007797{
7798 EVENT("(GLuint sampler = %u)", sampler);
7799
Geoff Langbfdea662014-07-23 14:16:32 -04007800 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007801 if (context)
7802 {
7803 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007804 {
Geoff Langb1196682014-07-23 13:47:29 -04007805 context->recordError(gl::Error(GL_INVALID_OPERATION));
7806 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007807 }
Geoff Langbfdea662014-07-23 14:16:32 -04007808
7809 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007810 }
7811
7812 return GL_FALSE;
7813}
7814
Kenneth Russell67ea1902014-10-06 16:44:50 -07007815void GL_APIENTRY glBindSampler(GLuint unit, GLuint sampler)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007816{
7817 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7818
Geoff Langbfdea662014-07-23 14:16:32 -04007819 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007820 if (context)
7821 {
7822 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007823 {
Geoff Langb1196682014-07-23 13:47:29 -04007824 context->recordError(gl::Error(GL_INVALID_OPERATION));
7825 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007826 }
Geoff Langbfdea662014-07-23 14:16:32 -04007827
7828 if (sampler != 0 && !context->isSampler(sampler))
7829 {
Geoff Langb1196682014-07-23 13:47:29 -04007830 context->recordError(gl::Error(GL_INVALID_OPERATION));
7831 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007832 }
7833
Geoff Lang3a61c322014-07-10 13:01:54 -04007834 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007835 {
Geoff Langb1196682014-07-23 13:47:29 -04007836 context->recordError(gl::Error(GL_INVALID_VALUE));
7837 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007838 }
7839
7840 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007841 }
7842}
7843
Kenneth Russell67ea1902014-10-06 16:44:50 -07007844void GL_APIENTRY glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007845{
7846 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7847
Geoff Langbfdea662014-07-23 14:16:32 -04007848 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007849 if (context)
7850 {
7851 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007852 {
Geoff Langb1196682014-07-23 13:47:29 -04007853 context->recordError(gl::Error(GL_INVALID_OPERATION));
7854 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007855 }
Geoff Langbfdea662014-07-23 14:16:32 -04007856
Geoff Langb1196682014-07-23 13:47:29 -04007857 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007858 {
7859 return;
7860 }
7861
7862 if (!gl::ValidateTexParamParameters(context, pname, param))
7863 {
7864 return;
7865 }
7866
7867 if (!context->isSampler(sampler))
7868 {
Geoff Langb1196682014-07-23 13:47:29 -04007869 context->recordError(gl::Error(GL_INVALID_OPERATION));
7870 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007871 }
7872
7873 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007874 }
7875}
7876
Kenneth Russell67ea1902014-10-06 16:44:50 -07007877void GL_APIENTRY glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007878{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007879 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007880}
7881
Kenneth Russell67ea1902014-10-06 16:44:50 -07007882void GL_APIENTRY glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007883{
7884 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7885
Geoff Langbfdea662014-07-23 14:16:32 -04007886 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007887 if (context)
7888 {
7889 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007890 {
Geoff Langb1196682014-07-23 13:47:29 -04007891 context->recordError(gl::Error(GL_INVALID_OPERATION));
7892 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007893 }
Geoff Langbfdea662014-07-23 14:16:32 -04007894
Geoff Langb1196682014-07-23 13:47:29 -04007895 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007896 {
7897 return;
7898 }
7899
7900 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7901 {
7902 return;
7903 }
7904
7905 if (!context->isSampler(sampler))
7906 {
Geoff Langb1196682014-07-23 13:47:29 -04007907 context->recordError(gl::Error(GL_INVALID_OPERATION));
7908 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007909 }
7910
7911 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007912 }
7913}
7914
Kenneth Russell67ea1902014-10-06 16:44:50 -07007915void GL_APIENTRY glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007916{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007917 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007918}
7919
Kenneth Russell67ea1902014-10-06 16:44:50 -07007920void GL_APIENTRY glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007921{
7922 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7923
Geoff Langbfdea662014-07-23 14:16:32 -04007924 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007925 if (context)
7926 {
7927 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007928 {
Geoff Langb1196682014-07-23 13:47:29 -04007929 context->recordError(gl::Error(GL_INVALID_OPERATION));
7930 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007931 }
Geoff Langbfdea662014-07-23 14:16:32 -04007932
Geoff Langb1196682014-07-23 13:47:29 -04007933 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007934 {
7935 return;
7936 }
7937
7938 if (!context->isSampler(sampler))
7939 {
Geoff Langb1196682014-07-23 13:47:29 -04007940 context->recordError(gl::Error(GL_INVALID_OPERATION));
7941 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007942 }
7943
7944 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007945 }
7946}
7947
Kenneth Russell67ea1902014-10-06 16:44:50 -07007948void GL_APIENTRY glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007949{
7950 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7951
Geoff Langbfdea662014-07-23 14:16:32 -04007952 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007953 if (context)
7954 {
7955 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007956 {
Geoff Langb1196682014-07-23 13:47:29 -04007957 context->recordError(gl::Error(GL_INVALID_OPERATION));
7958 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007959 }
Geoff Langbfdea662014-07-23 14:16:32 -04007960
Geoff Langb1196682014-07-23 13:47:29 -04007961 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007962 {
7963 return;
7964 }
7965
7966 if (!context->isSampler(sampler))
7967 {
Geoff Langb1196682014-07-23 13:47:29 -04007968 context->recordError(gl::Error(GL_INVALID_OPERATION));
7969 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007970 }
7971
7972 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007973 }
7974}
7975
Kenneth Russell67ea1902014-10-06 16:44:50 -07007976void GL_APIENTRY glVertexAttribDivisor(GLuint index, GLuint divisor)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007977{
7978 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7979
Geoff Langbfdea662014-07-23 14:16:32 -04007980 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007981 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007982 {
Geoff Langbfdea662014-07-23 14:16:32 -04007983 if (context->getClientVersion() < 3)
7984 {
Geoff Langb1196682014-07-23 13:47:29 -04007985 context->recordError(gl::Error(GL_INVALID_OPERATION));
7986 return;
7987 }
7988
7989 if (index >= gl::MAX_VERTEX_ATTRIBS)
7990 {
7991 context->recordError(gl::Error(GL_INVALID_VALUE));
7992 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007993 }
7994
7995 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007996 }
7997}
7998
Kenneth Russell67ea1902014-10-06 16:44:50 -07007999void GL_APIENTRY glBindTransformFeedback(GLenum target, GLuint id)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008000{
8001 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8002
Geoff Langbfdea662014-07-23 14:16:32 -04008003 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008004 if (context)
8005 {
8006 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008007 {
Geoff Langb1196682014-07-23 13:47:29 -04008008 context->recordError(gl::Error(GL_INVALID_OPERATION));
8009 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008010 }
Geoff Langbfdea662014-07-23 14:16:32 -04008011
8012 switch (target)
8013 {
8014 case GL_TRANSFORM_FEEDBACK:
8015 {
8016 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
8017 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
8018 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
8019 {
Geoff Langb1196682014-07-23 13:47:29 -04008020 context->recordError(gl::Error(GL_INVALID_OPERATION));
8021 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008022 }
8023
8024 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
8025 if (context->getTransformFeedback(id) == NULL)
8026 {
Geoff Langb1196682014-07-23 13:47:29 -04008027 context->recordError(gl::Error(GL_INVALID_OPERATION));
8028 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008029 }
8030
8031 context->bindTransformFeedback(id);
8032 }
8033 break;
8034
8035 default:
Geoff Langb1196682014-07-23 13:47:29 -04008036 context->recordError(gl::Error(GL_INVALID_ENUM));
8037 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008038 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008039 }
8040}
8041
Kenneth Russell67ea1902014-10-06 16:44:50 -07008042void GL_APIENTRY glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008043{
8044 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
8045
Geoff Langbfdea662014-07-23 14:16:32 -04008046 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008047 if (context)
8048 {
8049 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008050 {
Geoff Langb1196682014-07-23 13:47:29 -04008051 context->recordError(gl::Error(GL_INVALID_OPERATION));
8052 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008053 }
Geoff Langbfdea662014-07-23 14:16:32 -04008054
8055 for (int i = 0; i < n; i++)
8056 {
8057 context->deleteTransformFeedback(ids[i]);
8058 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008059 }
8060}
8061
Kenneth Russell67ea1902014-10-06 16:44:50 -07008062void GL_APIENTRY glGenTransformFeedbacks(GLsizei n, GLuint* ids)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008063{
8064 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8065
Geoff Langbfdea662014-07-23 14:16:32 -04008066 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008067 if (context)
8068 {
8069 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008070 {
Geoff Langb1196682014-07-23 13:47:29 -04008071 context->recordError(gl::Error(GL_INVALID_OPERATION));
8072 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008073 }
Geoff Langbfdea662014-07-23 14:16:32 -04008074
8075 for (int i = 0; i < n; i++)
8076 {
8077 ids[i] = context->createTransformFeedback();
8078 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008079 }
8080}
8081
Kenneth Russell67ea1902014-10-06 16:44:50 -07008082GLboolean GL_APIENTRY glIsTransformFeedback(GLuint id)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008083{
8084 EVENT("(GLuint id = %u)", id);
8085
Geoff Langbfdea662014-07-23 14:16:32 -04008086 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008087 if (context)
8088 {
8089 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008090 {
Geoff Langb1196682014-07-23 13:47:29 -04008091 context->recordError(gl::Error(GL_INVALID_OPERATION));
8092 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008093 }
Geoff Langbfdea662014-07-23 14:16:32 -04008094
8095 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008096 }
8097
8098 return GL_FALSE;
8099}
8100
Kenneth Russell67ea1902014-10-06 16:44:50 -07008101void GL_APIENTRY glPauseTransformFeedback(void)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008102{
8103 EVENT("(void)");
8104
Geoff Langbfdea662014-07-23 14:16:32 -04008105 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008106 if (context)
8107 {
8108 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008109 {
Geoff Langb1196682014-07-23 13:47:29 -04008110 context->recordError(gl::Error(GL_INVALID_OPERATION));
8111 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008112 }
Geoff Langbfdea662014-07-23 14:16:32 -04008113
8114 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8115 ASSERT(transformFeedback != NULL);
8116
8117 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
8118 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
8119 {
Geoff Langb1196682014-07-23 13:47:29 -04008120 context->recordError(gl::Error(GL_INVALID_OPERATION));
8121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008122 }
8123
8124 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008125 }
8126}
8127
Kenneth Russell67ea1902014-10-06 16:44:50 -07008128void GL_APIENTRY glResumeTransformFeedback(void)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008129{
8130 EVENT("(void)");
8131
Geoff Langbfdea662014-07-23 14:16:32 -04008132 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008133 if (context)
8134 {
8135 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008136 {
Geoff Langb1196682014-07-23 13:47:29 -04008137 context->recordError(gl::Error(GL_INVALID_OPERATION));
8138 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008139 }
Geoff Langbfdea662014-07-23 14:16:32 -04008140
8141 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8142 ASSERT(transformFeedback != NULL);
8143
8144 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
8145 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
8146 {
Geoff Langb1196682014-07-23 13:47:29 -04008147 context->recordError(gl::Error(GL_INVALID_OPERATION));
8148 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008149 }
8150
8151 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008152 }
8153}
8154
Kenneth Russell67ea1902014-10-06 16:44:50 -07008155void GL_APIENTRY glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008156{
8157 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
8158 program, bufSize, length, binaryFormat, binary);
8159
Geoff Langbfdea662014-07-23 14:16:32 -04008160 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008161 if (context)
8162 {
8163 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008164 {
Geoff Langb1196682014-07-23 13:47:29 -04008165 context->recordError(gl::Error(GL_INVALID_OPERATION));
8166 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008167 }
Geoff Langbfdea662014-07-23 14:16:32 -04008168
8169 // glGetProgramBinary
8170 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008171 }
8172}
8173
Kenneth Russell67ea1902014-10-06 16:44:50 -07008174void GL_APIENTRY glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008175{
8176 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
8177 program, binaryFormat, binary, length);
8178
Geoff Langbfdea662014-07-23 14:16:32 -04008179 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008180 if (context)
8181 {
8182 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008183 {
Geoff Langb1196682014-07-23 13:47:29 -04008184 context->recordError(gl::Error(GL_INVALID_OPERATION));
8185 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008186 }
Geoff Langbfdea662014-07-23 14:16:32 -04008187
8188 // glProgramBinary
8189 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008190 }
8191}
8192
Kenneth Russell67ea1902014-10-06 16:44:50 -07008193void GL_APIENTRY glProgramParameteri(GLuint program, GLenum pname, GLint value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008194{
8195 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
8196 program, pname, value);
8197
Geoff Langbfdea662014-07-23 14:16:32 -04008198 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008199 if (context)
8200 {
8201 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008202 {
Geoff Langb1196682014-07-23 13:47:29 -04008203 context->recordError(gl::Error(GL_INVALID_OPERATION));
8204 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008205 }
Geoff Langbfdea662014-07-23 14:16:32 -04008206
8207 // glProgramParameteri
8208 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008209 }
8210}
8211
Kenneth Russell67ea1902014-10-06 16:44:50 -07008212void GL_APIENTRY glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008213{
8214 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8215 target, numAttachments, attachments);
8216
Geoff Langbfdea662014-07-23 14:16:32 -04008217 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008218 if (context)
8219 {
8220 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008221 {
Geoff Langb1196682014-07-23 13:47:29 -04008222 context->recordError(gl::Error(GL_INVALID_OPERATION));
8223 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008224 }
Geoff Langbfdea662014-07-23 14:16:32 -04008225
8226 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8227 {
8228 return;
8229 }
8230
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008231 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8232 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8233 {
8234 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8235 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008236 }
8237}
8238
Kenneth Russell67ea1902014-10-06 16:44:50 -07008239void 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 +00008240{
8241 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8242 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8243 target, numAttachments, attachments, x, y, width, height);
8244
Geoff Langbfdea662014-07-23 14:16:32 -04008245 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008246 if (context)
8247 {
8248 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008249 {
Geoff Langb1196682014-07-23 13:47:29 -04008250 context->recordError(gl::Error(GL_INVALID_OPERATION));
8251 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008252 }
Geoff Langbfdea662014-07-23 14:16:32 -04008253
8254 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8255 {
8256 return;
8257 }
8258
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008259 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8260 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8261 {
8262 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8263 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008264 }
8265}
8266
Kenneth Russell67ea1902014-10-06 16:44:50 -07008267void GL_APIENTRY glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008268{
8269 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8270 target, levels, internalformat, width, height);
8271
Geoff Langbfdea662014-07-23 14:16:32 -04008272 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008273 if (context)
8274 {
8275 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008276 {
Geoff Langb1196682014-07-23 13:47:29 -04008277 context->recordError(gl::Error(GL_INVALID_OPERATION));
8278 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008279 }
Geoff Langbfdea662014-07-23 14:16:32 -04008280
8281 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8282 {
8283 return;
8284 }
8285
8286 switch (target)
8287 {
8288 case GL_TEXTURE_2D:
8289 {
8290 gl::Texture2D *texture2d = context->getTexture2D();
8291 texture2d->storage(levels, internalformat, width, height);
8292 }
8293 break;
8294
8295 case GL_TEXTURE_CUBE_MAP:
8296 {
8297 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8298 textureCube->storage(levels, internalformat, width);
8299 }
8300 break;
8301
8302 default:
Geoff Langb1196682014-07-23 13:47:29 -04008303 context->recordError(gl::Error(GL_INVALID_ENUM));
8304 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008305 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008306 }
8307}
8308
Kenneth Russell67ea1902014-10-06 16:44:50 -07008309void 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 +00008310{
8311 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8312 "GLsizei height = %d, GLsizei depth = %d)",
8313 target, levels, internalformat, width, height, depth);
8314
Geoff Langbfdea662014-07-23 14:16:32 -04008315 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008316 if (context)
8317 {
8318 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008319 {
Geoff Langb1196682014-07-23 13:47:29 -04008320 context->recordError(gl::Error(GL_INVALID_OPERATION));
8321 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008322 }
Geoff Langbfdea662014-07-23 14:16:32 -04008323
8324 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8325 {
8326 return;
8327 }
8328
8329 switch (target)
8330 {
8331 case GL_TEXTURE_3D:
8332 {
8333 gl::Texture3D *texture3d = context->getTexture3D();
8334 texture3d->storage(levels, internalformat, width, height, depth);
8335 }
8336 break;
8337
8338 case GL_TEXTURE_2D_ARRAY:
8339 {
8340 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8341 texture2darray->storage(levels, internalformat, width, height, depth);
8342 }
8343 break;
8344
8345 default:
8346 UNREACHABLE();
8347 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008348 }
8349}
8350
Kenneth Russell67ea1902014-10-06 16:44:50 -07008351void GL_APIENTRY glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008352{
8353 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8354 "GLint* params = 0x%0.8p)",
8355 target, internalformat, pname, bufSize, params);
8356
Geoff Langbfdea662014-07-23 14:16:32 -04008357 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008358 if (context)
8359 {
8360 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008361 {
Geoff Langb1196682014-07-23 13:47:29 -04008362 context->recordError(gl::Error(GL_INVALID_OPERATION));
8363 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008364 }
Geoff Langbfdea662014-07-23 14:16:32 -04008365
8366 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8367 if (!formatCaps.renderable)
8368 {
Geoff Langb1196682014-07-23 13:47:29 -04008369 context->recordError(gl::Error(GL_INVALID_ENUM));
8370 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008371 }
8372
8373 if (target != GL_RENDERBUFFER)
8374 {
Geoff Langb1196682014-07-23 13:47:29 -04008375 context->recordError(gl::Error(GL_INVALID_ENUM));
8376 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008377 }
8378
8379 if (bufSize < 0)
8380 {
Geoff Langb1196682014-07-23 13:47:29 -04008381 context->recordError(gl::Error(GL_INVALID_VALUE));
8382 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008383 }
8384
8385 switch (pname)
8386 {
8387 case GL_NUM_SAMPLE_COUNTS:
8388 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008389 {
8390 *params = formatCaps.sampleCounts.size();
8391 }
Geoff Langbfdea662014-07-23 14:16:32 -04008392 break;
Geoff Langb1196682014-07-23 13:47:29 -04008393
Geoff Langbfdea662014-07-23 14:16:32 -04008394 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008395 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008396 break;
Geoff Langb1196682014-07-23 13:47:29 -04008397
Geoff Langbfdea662014-07-23 14:16:32 -04008398 default:
Geoff Langb1196682014-07-23 13:47:29 -04008399 context->recordError(gl::Error(GL_INVALID_ENUM));
8400 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008401 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008402 }
8403}
8404
8405// Extension functions
8406
Kenneth Russell67ea1902014-10-06 16:44:50 -07008407void 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 +00008408 GLbitfield mask, GLenum filter)
8409{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008410 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008411 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8412 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8413 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8414
Geoff Langbfdea662014-07-23 14:16:32 -04008415 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008416 if (context)
8417 {
8418 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8419 dstX0, dstY0, dstX1, dstY1, mask, filter,
8420 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008421 {
Geoff Langbfdea662014-07-23 14:16:32 -04008422 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008423 }
Geoff Langbfdea662014-07-23 14:16:32 -04008424
Geoff Lang64839152014-08-26 16:23:25 -04008425 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8426 mask, filter);
8427 if (error.isError())
8428 {
8429 context->recordError(error);
8430 return;
8431 }
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008432 }
8433}
8434
Kenneth Russell67ea1902014-10-06 16:44:50 -07008435void GL_APIENTRY glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008436 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008437{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008438 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008439 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008440 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008441 target, level, internalformat, width, height, depth, border, format, type, pixels);
8442
Geoff Langbfdea662014-07-23 14:16:32 -04008443 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008444}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008445
Kenneth Russell67ea1902014-10-06 16:44:50 -07008446void GL_APIENTRY glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008447 GLenum *binaryFormat, void *binary)
8448{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008449 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 +00008450 program, bufSize, length, binaryFormat, binary);
8451
Geoff Langbfdea662014-07-23 14:16:32 -04008452 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008453 if (context)
8454 {
8455 gl::Program *programObject = context->getProgram(program);
8456
8457 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008458 {
Geoff Langb1196682014-07-23 13:47:29 -04008459 context->recordError(gl::Error(GL_INVALID_OPERATION));
8460 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008461 }
Geoff Langbfdea662014-07-23 14:16:32 -04008462
8463 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8464
8465 if (!programBinary)
8466 {
Geoff Langb1196682014-07-23 13:47:29 -04008467 context->recordError(gl::Error(GL_INVALID_OPERATION));
8468 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008469 }
8470
Geoff Langb543aff2014-09-30 14:52:54 -04008471 gl::Error error = programBinary->save(binaryFormat, binary, bufSize, length);
8472 if (error.isError())
Geoff Langbfdea662014-07-23 14:16:32 -04008473 {
Geoff Langb543aff2014-09-30 14:52:54 -04008474 context->recordError(error);
Geoff Langb1196682014-07-23 13:47:29 -04008475 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008476 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008477 }
8478}
8479
Kenneth Russell67ea1902014-10-06 16:44:50 -07008480void GL_APIENTRY glProgramBinaryOES(GLuint program, GLenum binaryFormat,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008481 const void *binary, GLint length)
8482{
8483 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8484 program, binaryFormat, binary, length);
8485
Geoff Langbfdea662014-07-23 14:16:32 -04008486 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008487 if (context)
8488 {
Geoff Lang900013c2014-07-07 11:32:19 -04008489 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8490 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008491 {
Geoff Langb1196682014-07-23 13:47:29 -04008492 context->recordError(gl::Error(GL_INVALID_ENUM));
8493 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008494 }
Geoff Langbfdea662014-07-23 14:16:32 -04008495
8496 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008497 if (!programObject)
8498 {
Geoff Langb1196682014-07-23 13:47:29 -04008499 context->recordError(gl::Error(GL_INVALID_OPERATION));
8500 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008501 }
8502
Geoff Langb543aff2014-09-30 14:52:54 -04008503 gl::Error error = context->setProgramBinary(program, binaryFormat, binary, length);
8504 if (error.isError())
8505 {
8506 context->recordError(error);
8507 return;
8508 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008509 }
8510}
8511
Kenneth Russell67ea1902014-10-06 16:44:50 -07008512void GL_APIENTRY glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008513{
8514 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8515
Geoff Langbfdea662014-07-23 14:16:32 -04008516 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008517 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008518 {
Geoff Langbfdea662014-07-23 14:16:32 -04008519 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008520 {
Geoff Langb1196682014-07-23 13:47:29 -04008521 context->recordError(gl::Error(GL_INVALID_VALUE));
8522 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008523 }
8524
8525 if (context->getState().getDrawFramebuffer()->id() == 0)
8526 {
8527 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008528 {
Geoff Langb1196682014-07-23 13:47:29 -04008529 context->recordError(gl::Error(GL_INVALID_OPERATION));
8530 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008531 }
8532
Geoff Langbfdea662014-07-23 14:16:32 -04008533 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008534 {
Geoff Langb1196682014-07-23 13:47:29 -04008535 context->recordError(gl::Error(GL_INVALID_OPERATION));
8536 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008537 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008538 }
Geoff Langbfdea662014-07-23 14:16:32 -04008539 else
8540 {
8541 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8542 {
8543 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8544 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8545 {
Geoff Langb1196682014-07-23 13:47:29 -04008546 context->recordError(gl::Error(GL_INVALID_OPERATION));
8547 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008548 }
8549 }
8550 }
8551
8552 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8553
8554 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8555 {
8556 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8557 }
8558
8559 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8560 {
8561 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8562 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008563 }
8564}
8565
Kenneth Russell67ea1902014-10-06 16:44:50 -07008566void GL_APIENTRY glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
Shannon Woodsb3801742014-03-27 14:59:19 -04008567{
8568 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8569
Geoff Langbfdea662014-07-23 14:16:32 -04008570 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008571 if (context)
8572 {
8573 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008574 {
Geoff Langb1196682014-07-23 13:47:29 -04008575 context->recordError(gl::Error(GL_INVALID_ENUM));
8576 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008577 }
Geoff Langbfdea662014-07-23 14:16:32 -04008578
8579 if (pname != GL_BUFFER_MAP_POINTER)
8580 {
Geoff Langb1196682014-07-23 13:47:29 -04008581 context->recordError(gl::Error(GL_INVALID_ENUM));
8582 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008583 }
8584
8585 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8586
8587 if (!buffer || !buffer->isMapped())
8588 {
8589 *params = NULL;
8590 }
8591 else
8592 {
8593 *params = buffer->getMapPointer();
8594 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008595 }
8596}
8597
Kenneth Russell67ea1902014-10-06 16:44:50 -07008598void * GL_APIENTRY glMapBufferOES(GLenum target, GLenum access)
Shannon Woodsb3801742014-03-27 14:59:19 -04008599{
8600 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8601
Geoff Langbfdea662014-07-23 14:16:32 -04008602 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008603 if (context)
8604 {
8605 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008606 {
Geoff Langb1196682014-07-23 13:47:29 -04008607 context->recordError(gl::Error(GL_INVALID_ENUM));
8608 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008609 }
Geoff Langbfdea662014-07-23 14:16:32 -04008610
8611 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8612
8613 if (buffer == NULL)
8614 {
Geoff Langb1196682014-07-23 13:47:29 -04008615 context->recordError(gl::Error(GL_INVALID_OPERATION));
8616 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008617 }
8618
8619 if (access != GL_WRITE_ONLY_OES)
8620 {
Geoff Langb1196682014-07-23 13:47:29 -04008621 context->recordError(gl::Error(GL_INVALID_ENUM));
8622 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008623 }
8624
8625 if (buffer->isMapped())
8626 {
Geoff Langb1196682014-07-23 13:47:29 -04008627 context->recordError(gl::Error(GL_INVALID_OPERATION));
8628 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008629 }
8630
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008631 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8632 if (error.isError())
8633 {
8634 context->recordError(error);
8635 return NULL;
8636 }
8637
8638 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008639 }
8640
8641 return NULL;
8642}
8643
Kenneth Russell67ea1902014-10-06 16:44:50 -07008644GLboolean GL_APIENTRY glUnmapBufferOES(GLenum target)
Shannon Woodsb3801742014-03-27 14:59:19 -04008645{
8646 EVENT("(GLenum target = 0x%X)", target);
8647
Geoff Langbfdea662014-07-23 14:16:32 -04008648 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008649 if (context)
8650 {
8651 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008652 {
Geoff Langb1196682014-07-23 13:47:29 -04008653 context->recordError(gl::Error(GL_INVALID_ENUM));
8654 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008655 }
Geoff Langbfdea662014-07-23 14:16:32 -04008656
8657 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8658
8659 if (buffer == NULL || !buffer->isMapped())
8660 {
Geoff Langb1196682014-07-23 13:47:29 -04008661 context->recordError(gl::Error(GL_INVALID_OPERATION));
8662 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008663 }
8664
8665 // TODO: detect if we had corruption. if so, throw an error and return false.
8666
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008667 gl::Error error = buffer->unmap();
8668 if (error.isError())
8669 {
8670 context->recordError(error);
8671 return GL_FALSE;
8672 }
Geoff Langbfdea662014-07-23 14:16:32 -04008673
8674 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008675 }
8676
8677 return GL_FALSE;
8678}
8679
Kenneth Russell67ea1902014-10-06 16:44:50 -07008680void* GL_APIENTRY glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Shannon Woods916e7692014-03-27 16:58:22 -04008681{
8682 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8683 target, offset, length, access);
8684
Geoff Langbfdea662014-07-23 14:16:32 -04008685 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008686 if (context)
8687 {
8688 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008689 {
Geoff Langb1196682014-07-23 13:47:29 -04008690 context->recordError(gl::Error(GL_INVALID_ENUM));
8691 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008692 }
Geoff Langbfdea662014-07-23 14:16:32 -04008693
8694 if (offset < 0 || length < 0)
8695 {
Geoff Langb1196682014-07-23 13:47:29 -04008696 context->recordError(gl::Error(GL_INVALID_VALUE));
8697 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008698 }
8699
8700 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8701
8702 if (buffer == NULL)
8703 {
Geoff Langb1196682014-07-23 13:47:29 -04008704 context->recordError(gl::Error(GL_INVALID_OPERATION));
8705 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008706 }
8707
8708 // Check for buffer overflow
8709 size_t offsetSize = static_cast<size_t>(offset);
8710 size_t lengthSize = static_cast<size_t>(length);
8711
8712 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8713 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8714 {
Geoff Langb1196682014-07-23 13:47:29 -04008715 context->recordError(gl::Error(GL_INVALID_VALUE));
8716 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008717 }
8718
8719 // Check for invalid bits in the mask
8720 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8721 GL_MAP_WRITE_BIT |
8722 GL_MAP_INVALIDATE_RANGE_BIT |
8723 GL_MAP_INVALIDATE_BUFFER_BIT |
8724 GL_MAP_FLUSH_EXPLICIT_BIT |
8725 GL_MAP_UNSYNCHRONIZED_BIT;
8726
8727 if (access & ~(allAccessBits))
8728 {
Geoff Langb1196682014-07-23 13:47:29 -04008729 context->recordError(gl::Error(GL_INVALID_VALUE));
8730 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008731 }
8732
8733 if (length == 0 || buffer->isMapped())
8734 {
Geoff Langb1196682014-07-23 13:47:29 -04008735 context->recordError(gl::Error(GL_INVALID_OPERATION));
8736 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008737 }
8738
8739 // Check for invalid bit combinations
8740 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8741 {
Geoff Langb1196682014-07-23 13:47:29 -04008742 context->recordError(gl::Error(GL_INVALID_OPERATION));
8743 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008744 }
8745
8746 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8747 GL_MAP_INVALIDATE_BUFFER_BIT |
8748 GL_MAP_UNSYNCHRONIZED_BIT;
8749
8750 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8751 {
Geoff Langb1196682014-07-23 13:47:29 -04008752 context->recordError(gl::Error(GL_INVALID_OPERATION));
8753 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008754 }
8755
8756 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8757 {
Geoff Langb1196682014-07-23 13:47:29 -04008758 context->recordError(gl::Error(GL_INVALID_OPERATION));
8759 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008760 }
8761
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008762 gl::Error error = buffer->mapRange(offset, length, access);
8763 if (error.isError())
8764 {
8765 context->recordError(error);
8766 return NULL;
8767 }
8768
8769 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008770 }
8771
8772 return NULL;
8773}
8774
Kenneth Russell67ea1902014-10-06 16:44:50 -07008775void GL_APIENTRY glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
Shannon Woods916e7692014-03-27 16:58:22 -04008776{
8777 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8778
Geoff Langbfdea662014-07-23 14:16:32 -04008779 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008780 if (context)
8781 {
8782 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008783 {
Geoff Langb1196682014-07-23 13:47:29 -04008784 context->recordError(gl::Error(GL_INVALID_VALUE));
8785 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008786 }
Geoff Langbfdea662014-07-23 14:16:32 -04008787
8788 if (!gl::ValidBufferTarget(context, target))
8789 {
Geoff Langb1196682014-07-23 13:47:29 -04008790 context->recordError(gl::Error(GL_INVALID_ENUM));
8791 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008792 }
8793
8794 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8795
8796 if (buffer == NULL)
8797 {
Geoff Langb1196682014-07-23 13:47:29 -04008798 context->recordError(gl::Error(GL_INVALID_OPERATION));
8799 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008800 }
8801
8802 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8803 {
Geoff Langb1196682014-07-23 13:47:29 -04008804 context->recordError(gl::Error(GL_INVALID_OPERATION));
8805 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008806 }
8807
8808 // Check for buffer overflow
8809 size_t offsetSize = static_cast<size_t>(offset);
8810 size_t lengthSize = static_cast<size_t>(length);
8811
8812 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8813 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8814 {
Geoff Langb1196682014-07-23 13:47:29 -04008815 context->recordError(gl::Error(GL_INVALID_VALUE));
8816 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008817 }
8818
8819 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008820 }
8821}
8822
Kenneth Russell67ea1902014-10-06 16:44:50 -07008823__eglMustCastToProperFunctionPointerType EGLAPIENTRY glGetProcAddress(const char *procname)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008824{
8825 struct Extension
8826 {
8827 const char *name;
8828 __eglMustCastToProperFunctionPointerType address;
8829 };
8830
8831 static const Extension glExtensions[] =
8832 {
8833 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008834 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008835 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008836 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8837 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8838 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8839 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8840 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8841 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8842 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008843 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008844 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008845 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8846 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8847 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8848 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008849 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8850 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8851 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8852 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8853 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8854 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8855 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008856 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008857 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8858 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8859 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008860 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008861 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8862 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8863 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008864 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8865 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8866 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008867
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008868 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008869 {
8870 if (strcmp(procname, glExtensions[ext].name) == 0)
8871 {
8872 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8873 }
8874 }
8875
8876 return NULL;
8877}
8878
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008879// Non-public functions used by EGL
8880
Kenneth Russell67ea1902014-10-06 16:44:50 -07008881bool EGLAPIENTRY glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008882{
8883 EVENT("(egl::Surface* surface = 0x%0.8p)",
8884 surface);
8885
Geoff Langbfdea662014-07-23 14:16:32 -04008886 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008887 if (context)
8888 {
8889 gl::Texture2D *textureObject = context->getTexture2D();
8890 ASSERT(textureObject != NULL);
8891
8892 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008893 {
Geoff Langbfdea662014-07-23 14:16:32 -04008894 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008895 }
Geoff Langbfdea662014-07-23 14:16:32 -04008896
8897 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008898 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008899
8900 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008901}
8902
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008903}