blob: 40bfbfa8e7dcb91414a3cae2c725e3ee0a6f9894 [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
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038void __stdcall glActiveTexture(GLenum texture)
39{
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();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000043
Geoff Langbfdea662014-07-23 14:16:32 -040044 if (context)
45 {
46 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000047 {
Geoff Langbfdea662014-07-23 14:16:32 -040048 return gl::error(GL_INVALID_ENUM);
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
55void __stdcall glAttachShader(GLuint program, GLuint shader)
56{
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();
60
61 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000062 {
Geoff Langbfdea662014-07-23 14:16:32 -040063 gl::Program *programObject = context->getProgram(program);
64 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000065
Geoff Langbfdea662014-07-23 14:16:32 -040066 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000067 {
Geoff Langbfdea662014-07-23 14:16:32 -040068 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000070 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000071 }
Geoff Langbfdea662014-07-23 14:16:32 -040072 else
73 {
74 return gl::error(GL_INVALID_VALUE);
75 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000076 }
Geoff Langbfdea662014-07-23 14:16:32 -040077
78 if (!shaderObject)
79 {
80 if (context->getProgram(shader))
81 {
82 return gl::error(GL_INVALID_OPERATION);
83 }
84 else
85 {
86 return gl::error(GL_INVALID_VALUE);
87 }
88 }
89
90 if (!programObject->attachShader(shaderObject))
91 {
92 return gl::error(GL_INVALID_OPERATION);
93 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000094 }
95}
96
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000097void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
98{
99 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
100
Geoff Langbfdea662014-07-23 14:16:32 -0400101 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000102
Geoff Langbfdea662014-07-23 14:16:32 -0400103 if (context)
104 {
105 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000106 {
Geoff Langbfdea662014-07-23 14:16:32 -0400107 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000108 }
Geoff Langbfdea662014-07-23 14:16:32 -0400109
110 context->beginQuery(target, id);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000111 }
112}
113
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000114void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000115{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000116 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000117
Geoff Langbfdea662014-07-23 14:16:32 -0400118 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000119 {
Geoff Langbfdea662014-07-23 14:16:32 -0400120 return gl::error(GL_INVALID_VALUE);
121 }
122
123 gl::Context *context = gl::getNonLostContext();
124
125 if (context)
126 {
127 gl::Program *programObject = context->getProgram(program);
128
129 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000130 {
Geoff Langbfdea662014-07-23 14:16:32 -0400131 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000133 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000134 }
Geoff Langbfdea662014-07-23 14:16:32 -0400135 else
136 {
137 return gl::error(GL_INVALID_VALUE);
138 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000139 }
Geoff Langbfdea662014-07-23 14:16:32 -0400140
141 if (strncmp(name, "gl_", 3) == 0)
142 {
143 return gl::error(GL_INVALID_OPERATION);
144 }
145
146 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000147 }
148}
149
150void __stdcall glBindBuffer(GLenum target, GLuint buffer)
151{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000152 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000153
Geoff Langbfdea662014-07-23 14:16:32 -0400154 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000155
Geoff Langbfdea662014-07-23 14:16:32 -0400156 if (context)
157 {
158 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159 {
Geoff Langbfdea662014-07-23 14:16:32 -0400160 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000161 }
Geoff Langbfdea662014-07-23 14:16:32 -0400162
163 switch (target)
164 {
165 case GL_ARRAY_BUFFER:
166 context->bindArrayBuffer(buffer);
167 return;
168 case GL_ELEMENT_ARRAY_BUFFER:
169 context->bindElementArrayBuffer(buffer);
170 return;
171 case GL_COPY_READ_BUFFER:
172 context->bindCopyReadBuffer(buffer);
173 return;
174 case GL_COPY_WRITE_BUFFER:
175 context->bindCopyWriteBuffer(buffer);
176 return;
177 case GL_PIXEL_PACK_BUFFER:
178 context->bindPixelPackBuffer(buffer);
179 return;
180 case GL_PIXEL_UNPACK_BUFFER:
181 context->bindPixelUnpackBuffer(buffer);
182 return;
183 case GL_UNIFORM_BUFFER:
184 context->bindGenericUniformBuffer(buffer);
185 return;
186 case GL_TRANSFORM_FEEDBACK_BUFFER:
187 context->bindGenericTransformFeedbackBuffer(buffer);
188 return;
189 default:
190 return gl::error(GL_INVALID_ENUM);
191 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000192 }
193}
194
195void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
196{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000197 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000198
Geoff Langbfdea662014-07-23 14:16:32 -0400199 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000200 {
Geoff Langbfdea662014-07-23 14:16:32 -0400201 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000202 }
Geoff Langbfdea662014-07-23 14:16:32 -0400203
204 gl::Context *context = gl::getNonLostContext();
205
206 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000207 {
Geoff Langbfdea662014-07-23 14:16:32 -0400208 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
209 {
210 context->bindReadFramebuffer(framebuffer);
211 }
212
213 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
214 {
215 context->bindDrawFramebuffer(framebuffer);
216 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000217 }
218}
219
220void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
221{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000222 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000223
Geoff Langbfdea662014-07-23 14:16:32 -0400224 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000225 {
Geoff Langbfdea662014-07-23 14:16:32 -0400226 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000227 }
Geoff Langbfdea662014-07-23 14:16:32 -0400228
229 gl::Context *context = gl::getNonLostContext();
230
231 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000232 {
Geoff Langbfdea662014-07-23 14:16:32 -0400233 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000234 }
235}
236
237void __stdcall glBindTexture(GLenum target, GLuint texture)
238{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000239 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000240
Geoff Langbfdea662014-07-23 14:16:32 -0400241 gl::Context *context = gl::getNonLostContext();
242
243 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000244 {
Geoff Langbfdea662014-07-23 14:16:32 -0400245 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000246
Geoff Langbfdea662014-07-23 14:16:32 -0400247 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000248 {
Geoff Langbfdea662014-07-23 14:16:32 -0400249 return gl::error(GL_INVALID_OPERATION);
250 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000251
Geoff Langbfdea662014-07-23 14:16:32 -0400252 switch (target)
253 {
254 case GL_TEXTURE_2D:
255 context->bindTexture2D(texture);
256 return;
257 case GL_TEXTURE_CUBE_MAP:
258 context->bindTextureCubeMap(texture);
259 return;
260 case GL_TEXTURE_3D:
261 if (context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000263 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000264 }
Geoff Langbfdea662014-07-23 14:16:32 -0400265 context->bindTexture3D(texture);
266 return;
267 case GL_TEXTURE_2D_ARRAY:
268 if (context->getClientVersion() < 3)
269 {
270 return gl::error(GL_INVALID_ENUM);
271 }
272 context->bindTexture2DArray(texture);
273 return;
274 default:
275 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276 }
277 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000278}
279
280void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
281{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000282 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000283 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000284
Geoff Langbfdea662014-07-23 14:16:32 -0400285 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000286
Geoff Langbfdea662014-07-23 14:16:32 -0400287 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000288 {
Geoff Langbfdea662014-07-23 14:16:32 -0400289 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000290 }
291}
292
293void __stdcall glBlendEquation(GLenum mode)
294{
295 glBlendEquationSeparate(mode, mode);
296}
297
298void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
299{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000300 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000301
Geoff Langbfdea662014-07-23 14:16:32 -0400302 gl::Context *context = gl::getNonLostContext();
303
304 switch (modeRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000305 {
Geoff Langbfdea662014-07-23 14:16:32 -0400306 case GL_FUNC_ADD:
307 case GL_FUNC_SUBTRACT:
308 case GL_FUNC_REVERSE_SUBTRACT:
309 case GL_MIN:
310 case GL_MAX:
311 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000312
Geoff Langbfdea662014-07-23 14:16:32 -0400313 default:
314 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000315 }
Geoff Langbfdea662014-07-23 14:16:32 -0400316
317 switch (modeAlpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000318 {
Geoff Langbfdea662014-07-23 14:16:32 -0400319 case GL_FUNC_ADD:
320 case GL_FUNC_SUBTRACT:
321 case GL_FUNC_REVERSE_SUBTRACT:
322 case GL_MIN:
323 case GL_MAX:
324 break;
325
326 default:
327 return gl::error(GL_INVALID_ENUM);
328 }
329
330 if (context)
331 {
332 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000333 }
334}
335
336void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
337{
338 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
339}
340
341void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
342{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000343 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 +0000344 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000345
Geoff Langbfdea662014-07-23 14:16:32 -0400346 gl::Context *context = gl::getNonLostContext();
347
348 switch (srcRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000349 {
Geoff Langbfdea662014-07-23 14:16:32 -0400350 case GL_ZERO:
351 case GL_ONE:
352 case GL_SRC_COLOR:
353 case GL_ONE_MINUS_SRC_COLOR:
354 case GL_DST_COLOR:
355 case GL_ONE_MINUS_DST_COLOR:
356 case GL_SRC_ALPHA:
357 case GL_ONE_MINUS_SRC_ALPHA:
358 case GL_DST_ALPHA:
359 case GL_ONE_MINUS_DST_ALPHA:
360 case GL_CONSTANT_COLOR:
361 case GL_ONE_MINUS_CONSTANT_COLOR:
362 case GL_CONSTANT_ALPHA:
363 case GL_ONE_MINUS_CONSTANT_ALPHA:
364 case GL_SRC_ALPHA_SATURATE:
365 break;
366 default:
367 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000368 }
Geoff Langbfdea662014-07-23 14:16:32 -0400369
370 switch (dstRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000371 {
Geoff Langbfdea662014-07-23 14:16:32 -0400372 case GL_ZERO:
373 case GL_ONE:
374 case GL_SRC_COLOR:
375 case GL_ONE_MINUS_SRC_COLOR:
376 case GL_DST_COLOR:
377 case GL_ONE_MINUS_DST_COLOR:
378 case GL_SRC_ALPHA:
379 case GL_ONE_MINUS_SRC_ALPHA:
380 case GL_DST_ALPHA:
381 case GL_ONE_MINUS_DST_ALPHA:
382 case GL_CONSTANT_COLOR:
383 case GL_ONE_MINUS_CONSTANT_COLOR:
384 case GL_CONSTANT_ALPHA:
385 case GL_ONE_MINUS_CONSTANT_ALPHA:
386 break;
387
388 case GL_SRC_ALPHA_SATURATE:
389 if (!context || context->getClientVersion() < 3)
390 {
391 return gl::error(GL_INVALID_ENUM);
392 }
393 break;
394
395 default:
396 return gl::error(GL_INVALID_ENUM);
397 }
398
399 switch (srcAlpha)
400 {
401 case GL_ZERO:
402 case GL_ONE:
403 case GL_SRC_COLOR:
404 case GL_ONE_MINUS_SRC_COLOR:
405 case GL_DST_COLOR:
406 case GL_ONE_MINUS_DST_COLOR:
407 case GL_SRC_ALPHA:
408 case GL_ONE_MINUS_SRC_ALPHA:
409 case GL_DST_ALPHA:
410 case GL_ONE_MINUS_DST_ALPHA:
411 case GL_CONSTANT_COLOR:
412 case GL_ONE_MINUS_CONSTANT_COLOR:
413 case GL_CONSTANT_ALPHA:
414 case GL_ONE_MINUS_CONSTANT_ALPHA:
415 case GL_SRC_ALPHA_SATURATE:
416 break;
417 default:
418 return gl::error(GL_INVALID_ENUM);
419 }
420
421 switch (dstAlpha)
422 {
423 case GL_ZERO:
424 case GL_ONE:
425 case GL_SRC_COLOR:
426 case GL_ONE_MINUS_SRC_COLOR:
427 case GL_DST_COLOR:
428 case GL_ONE_MINUS_DST_COLOR:
429 case GL_SRC_ALPHA:
430 case GL_ONE_MINUS_SRC_ALPHA:
431 case GL_DST_ALPHA:
432 case GL_ONE_MINUS_DST_ALPHA:
433 case GL_CONSTANT_COLOR:
434 case GL_ONE_MINUS_CONSTANT_COLOR:
435 case GL_CONSTANT_ALPHA:
436 case GL_ONE_MINUS_CONSTANT_ALPHA:
437 break;
438
439 case GL_SRC_ALPHA_SATURATE:
440 if (!context || context->getClientVersion() < 3)
441 {
442 return gl::error(GL_INVALID_ENUM);
443 }
444 break;
445
446 default:
447 return gl::error(GL_INVALID_ENUM);
448 }
449
450 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
451 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
452
453 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
454 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
455
456 if (constantColorUsed && constantAlphaUsed)
457 {
458 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
459 return gl::error(GL_INVALID_OPERATION);
460 }
461
462 if (context)
463 {
464 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000465 }
466}
467
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000468void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000469{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000470 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 +0000471 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000472
Geoff Langbfdea662014-07-23 14:16:32 -0400473 if (size < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000474 {
Geoff Langbfdea662014-07-23 14:16:32 -0400475 return gl::error(GL_INVALID_VALUE);
476 }
477
478 gl::Context *context = gl::getNonLostContext();
479
480 switch (usage)
481 {
482 case GL_STREAM_DRAW:
483 case GL_STATIC_DRAW:
484 case GL_DYNAMIC_DRAW:
485 break;
486
487 case GL_STREAM_READ:
488 case GL_STREAM_COPY:
489 case GL_STATIC_READ:
490 case GL_STATIC_COPY:
491 case GL_DYNAMIC_READ:
492 case GL_DYNAMIC_COPY:
493 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000494 {
Geoff Langbfdea662014-07-23 14:16:32 -0400495 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000496 }
Geoff Langbfdea662014-07-23 14:16:32 -0400497 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000498
Geoff Langbfdea662014-07-23 14:16:32 -0400499 default:
500 return gl::error(GL_INVALID_ENUM);
501 }
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +0000502
Geoff Langbfdea662014-07-23 14:16:32 -0400503 if (context)
504 {
505 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000507 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000508 }
509
Geoff Langbfdea662014-07-23 14:16:32 -0400510 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
511
512 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000513 {
Geoff Langbfdea662014-07-23 14:16:32 -0400514 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000515 }
Geoff Langbfdea662014-07-23 14:16:32 -0400516
517 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000518 }
519}
520
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000521void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000522{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000523 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 +0000524 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000525
Geoff Langbfdea662014-07-23 14:16:32 -0400526 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000527 {
Geoff Langbfdea662014-07-23 14:16:32 -0400528 return gl::error(GL_INVALID_VALUE);
529 }
530
531 if (data == NULL)
532 {
533 return;
534 }
535
536 gl::Context *context = gl::getNonLostContext();
537
538 if (context)
539 {
540 if (!gl::ValidBufferTarget(context, target))
541 {
542 return gl::error(GL_INVALID_ENUM);
543 }
544
545 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
546
547 if (!buffer)
548 {
549 return gl::error(GL_INVALID_OPERATION);
550 }
551
552 if (buffer->isMapped())
553 {
554 return gl::error(GL_INVALID_OPERATION);
555 }
556
557 // Check for possible overflow of size + offset
558 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
559 {
560 return gl::error(GL_OUT_OF_MEMORY);
561 }
562
563 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000564 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000565 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000566 }
567
Geoff Langbfdea662014-07-23 14:16:32 -0400568 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000569 }
570}
571
572GLenum __stdcall glCheckFramebufferStatus(GLenum target)
573{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000574 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000575
Geoff Langbfdea662014-07-23 14:16:32 -0400576 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000577 {
Geoff Langbfdea662014-07-23 14:16:32 -0400578 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000579 }
Geoff Langbfdea662014-07-23 14:16:32 -0400580
581 gl::Context *context = gl::getNonLostContext();
582
583 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000584 {
Geoff Langbfdea662014-07-23 14:16:32 -0400585 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
586 ASSERT(framebuffer);
587 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000588 }
589
590 return 0;
591}
592
593void __stdcall glClear(GLbitfield mask)
594{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000595 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000596
Geoff Langbfdea662014-07-23 14:16:32 -0400597 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000598
Geoff Langbfdea662014-07-23 14:16:32 -0400599 if (context)
600 {
601 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
602
603 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000604 {
Geoff Langbfdea662014-07-23 14:16:32 -0400605 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000606 }
Geoff Langbfdea662014-07-23 14:16:32 -0400607
608 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
609 {
610 return gl::error(GL_INVALID_VALUE);
611 }
612
613 context->clear(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000614 }
615}
616
617void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
618{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000619 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000620 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000621
Geoff Langbfdea662014-07-23 14:16:32 -0400622 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000623
Geoff Langbfdea662014-07-23 14:16:32 -0400624 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625 {
Geoff Langbfdea662014-07-23 14:16:32 -0400626 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000627 }
628}
629
630void __stdcall glClearDepthf(GLclampf depth)
631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000632 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000633
Geoff Langbfdea662014-07-23 14:16:32 -0400634 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000635
Geoff Langbfdea662014-07-23 14:16:32 -0400636 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000637 {
Geoff Langbfdea662014-07-23 14:16:32 -0400638 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000639 }
640}
641
642void __stdcall glClearStencil(GLint s)
643{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000644 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000645
Geoff Langbfdea662014-07-23 14:16:32 -0400646 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000647
Geoff Langbfdea662014-07-23 14:16:32 -0400648 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000649 {
Geoff Langbfdea662014-07-23 14:16:32 -0400650 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000651 }
652}
653
654void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
655{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000656 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000657 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000658
Geoff Langbfdea662014-07-23 14:16:32 -0400659 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000660
Geoff Langbfdea662014-07-23 14:16:32 -0400661 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000662 {
Geoff Langbfdea662014-07-23 14:16:32 -0400663 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000664 }
665}
666
667void __stdcall glCompileShader(GLuint shader)
668{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000669 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000670
Geoff Langbfdea662014-07-23 14:16:32 -0400671 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000672
Geoff Langbfdea662014-07-23 14:16:32 -0400673 if (context)
674 {
675 gl::Shader *shaderObject = context->getShader(shader);
676
677 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000678 {
Geoff Langbfdea662014-07-23 14:16:32 -0400679 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000680 {
Geoff Langbfdea662014-07-23 14:16:32 -0400681 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000682 }
Geoff Langbfdea662014-07-23 14:16:32 -0400683 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000685 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000686 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000687 }
Geoff Langbfdea662014-07-23 14:16:32 -0400688
689 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000690 }
Geoff Langbfdea662014-07-23 14:16:32 -0400691}
692
693void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
694 GLint border, GLsizei imageSize, const GLvoid* data)
695{
696 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
697 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
698 target, level, internalformat, width, height, border, imageSize, data);
699
700 gl::Context *context = gl::getNonLostContext();
701
702 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000703 {
Geoff Langbfdea662014-07-23 14:16:32 -0400704 if (context->getClientVersion() < 3 &&
705 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
706 0, 0, width, height, border, GL_NONE, GL_NONE, data))
707 {
708 return;
709 }
710
711 if (context->getClientVersion() >= 3 &&
712 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
713 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
714 {
715 return;
716 }
717
Geoff Lang5d601382014-07-22 15:14:06 -0400718 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
719 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400720 {
721 return gl::error(GL_INVALID_VALUE);
722 }
723
724 switch (target)
725 {
726 case GL_TEXTURE_2D:
727 {
728 gl::Texture2D *texture = context->getTexture2D();
729 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
730 }
731 break;
732
733 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
734 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
735 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
736 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
737 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
738 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
739 {
740 gl::TextureCubeMap *texture = context->getTextureCubeMap();
741 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
742 }
743 break;
744
745 default:
746 return gl::error(GL_INVALID_ENUM);
747 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000748 }
749}
750
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000751void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
752 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000754 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000755 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000756 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000757 target, level, xoffset, yoffset, width, height, format, imageSize, data);
758
Geoff Langbfdea662014-07-23 14:16:32 -0400759 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +0000760
Geoff Langbfdea662014-07-23 14:16:32 -0400761 if (context)
762 {
763 if (context->getClientVersion() < 3 &&
764 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
765 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000766 {
Geoff Langbfdea662014-07-23 14:16:32 -0400767 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000768 }
Geoff Langbfdea662014-07-23 14:16:32 -0400769
770 if (context->getClientVersion() >= 3 &&
771 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
772 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
773 {
774 return;
775 }
776
Geoff Lang5d601382014-07-22 15:14:06 -0400777 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
778 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400779 {
780 return gl::error(GL_INVALID_VALUE);
781 }
782
783 switch (target)
784 {
785 case GL_TEXTURE_2D:
786 {
787 gl::Texture2D *texture = context->getTexture2D();
788 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
789 }
790 break;
791
792 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
793 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
794 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
795 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
796 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
797 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
798 {
799 gl::TextureCubeMap *texture = context->getTextureCubeMap();
800 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
801 }
802 break;
803
804 default:
805 return gl::error(GL_INVALID_ENUM);
806 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000807 }
808}
809
810void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
811{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000812 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000813 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000814 target, level, internalformat, x, y, width, height, border);
815
Geoff Langbfdea662014-07-23 14:16:32 -0400816 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000817
Geoff Langbfdea662014-07-23 14:16:32 -0400818 if (context)
819 {
820 if (context->getClientVersion() < 3 &&
821 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
822 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000823 {
Geoff Langbfdea662014-07-23 14:16:32 -0400824 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000825 }
Geoff Langbfdea662014-07-23 14:16:32 -0400826
827 if (context->getClientVersion() >= 3 &&
828 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
829 0, 0, 0, x, y, width, height, border))
830 {
831 return;
832 }
833
834 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
835
836 switch (target)
837 {
838 case GL_TEXTURE_2D:
839 {
840 gl::Texture2D *texture = context->getTexture2D();
841 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
842 }
843 break;
844
845 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
846 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
847 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
848 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
849 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
850 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
851 {
852 gl::TextureCubeMap *texture = context->getTextureCubeMap();
853 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
854 }
855 break;
856
857 default:
858 return gl::error(GL_INVALID_ENUM);
859 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000860 }
861}
862
863void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000865 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000866 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000867 target, level, xoffset, yoffset, x, y, width, height);
868
Geoff Langbfdea662014-07-23 14:16:32 -0400869 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000870
Geoff Langbfdea662014-07-23 14:16:32 -0400871 if (context)
872 {
873 if (context->getClientVersion() < 3 &&
874 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
875 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000876 {
Geoff Langbfdea662014-07-23 14:16:32 -0400877 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000878 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000879
Geoff Langbfdea662014-07-23 14:16:32 -0400880 if (context->getClientVersion() >= 3 &&
881 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
882 xoffset, yoffset, 0, x, y, width, height, 0))
883 {
884 return;
885 }
886
887 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
888
889 switch (target)
890 {
891 case GL_TEXTURE_2D:
892 {
893 gl::Texture2D *texture = context->getTexture2D();
894 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
895 }
896 break;
897
898 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
899 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
900 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
901 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
902 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
903 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
904 {
905 gl::TextureCubeMap *texture = context->getTextureCubeMap();
906 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
907 }
908 break;
909
910 default:
911 return gl::error(GL_INVALID_ENUM);
912 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000913 }
914}
915
916GLuint __stdcall glCreateProgram(void)
917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000918 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000919
Geoff Langbfdea662014-07-23 14:16:32 -0400920 gl::Context *context = gl::getNonLostContext();
921 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000922 {
Geoff Langbfdea662014-07-23 14:16:32 -0400923 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000924 }
925
926 return 0;
927}
928
929GLuint __stdcall glCreateShader(GLenum type)
930{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000931 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000932
Geoff Langbfdea662014-07-23 14:16:32 -0400933 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000934
Geoff Langbfdea662014-07-23 14:16:32 -0400935 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000936 {
Geoff Langbfdea662014-07-23 14:16:32 -0400937 switch (type)
938 {
939 case GL_FRAGMENT_SHADER:
940 case GL_VERTEX_SHADER:
941 return context->createShader(type);
942 default:
943 return gl::error(GL_INVALID_ENUM, 0);
944 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000945 }
946
947 return 0;
948}
949
950void __stdcall glCullFace(GLenum mode)
951{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000952 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000953
Geoff Langbfdea662014-07-23 14:16:32 -0400954 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000955 {
Geoff Langbfdea662014-07-23 14:16:32 -0400956 case GL_FRONT:
957 case GL_BACK:
958 case GL_FRONT_AND_BACK:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000959 {
Geoff Langbfdea662014-07-23 14:16:32 -0400960 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000961
Geoff Langbfdea662014-07-23 14:16:32 -0400962 if (context)
963 {
964 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000965 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000966 }
Geoff Langbfdea662014-07-23 14:16:32 -0400967 break;
968 default:
969 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000970 }
971}
972
973void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
974{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000975 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000976
Geoff Langbfdea662014-07-23 14:16:32 -0400977 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000978 {
Geoff Langbfdea662014-07-23 14:16:32 -0400979 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000980 }
Geoff Langbfdea662014-07-23 14:16:32 -0400981
982 gl::Context *context = gl::getNonLostContext();
983
984 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000985 {
Geoff Langbfdea662014-07-23 14:16:32 -0400986 for (int i = 0; i < n; i++)
987 {
988 context->deleteBuffer(buffers[i]);
989 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000990 }
991}
992
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000993void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000995 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000996
Geoff Langbfdea662014-07-23 14:16:32 -0400997 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000998 {
Geoff Langbfdea662014-07-23 14:16:32 -0400999 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001000 }
Geoff Langbfdea662014-07-23 14:16:32 -04001001
1002 gl::Context *context = gl::getNonLostContext();
1003
1004 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001005 {
Geoff Langbfdea662014-07-23 14:16:32 -04001006 for (int i = 0; i < n; i++)
1007 {
1008 context->deleteFenceNV(fences[i]);
1009 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001010 }
1011}
1012
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001013void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1014{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001015 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001016
Geoff Langbfdea662014-07-23 14:16:32 -04001017 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001018 {
Geoff Langbfdea662014-07-23 14:16:32 -04001019 return gl::error(GL_INVALID_VALUE);
1020 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001021
Geoff Langbfdea662014-07-23 14:16:32 -04001022 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001023
Geoff Langbfdea662014-07-23 14:16:32 -04001024 if (context)
1025 {
1026 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001027 {
Geoff Langbfdea662014-07-23 14:16:32 -04001028 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001029 {
Geoff Langbfdea662014-07-23 14:16:32 -04001030 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001031 }
1032 }
1033 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001034}
1035
1036void __stdcall glDeleteProgram(GLuint program)
1037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001038 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001039
Geoff Langbfdea662014-07-23 14:16:32 -04001040 if (program == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001041 {
Geoff Langbfdea662014-07-23 14:16:32 -04001042 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001043 }
Geoff Langbfdea662014-07-23 14:16:32 -04001044
1045 gl::Context *context = gl::getNonLostContext();
1046
1047 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001048 {
Geoff Langbfdea662014-07-23 14:16:32 -04001049 if (!context->getProgram(program))
1050 {
1051 if(context->getShader(program))
1052 {
1053 return gl::error(GL_INVALID_OPERATION);
1054 }
1055 else
1056 {
1057 return gl::error(GL_INVALID_VALUE);
1058 }
1059 }
1060
1061 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001062 }
1063}
1064
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001065void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1066{
1067 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1068
Geoff Langbfdea662014-07-23 14:16:32 -04001069 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001070 {
Geoff Langbfdea662014-07-23 14:16:32 -04001071 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001072 }
Geoff Langbfdea662014-07-23 14:16:32 -04001073
1074 gl::Context *context = gl::getNonLostContext();
1075
1076 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001077 {
Geoff Langbfdea662014-07-23 14:16:32 -04001078 for (int i = 0; i < n; i++)
1079 {
1080 context->deleteQuery(ids[i]);
1081 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001082 }
1083}
1084
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001085void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1086{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001087 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001088
Geoff Langbfdea662014-07-23 14:16:32 -04001089 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001090 {
Geoff Langbfdea662014-07-23 14:16:32 -04001091 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001092 }
Geoff Langbfdea662014-07-23 14:16:32 -04001093
1094 gl::Context *context = gl::getNonLostContext();
1095
1096 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001097 {
Geoff Langbfdea662014-07-23 14:16:32 -04001098 for (int i = 0; i < n; i++)
1099 {
1100 context->deleteRenderbuffer(renderbuffers[i]);
1101 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001102 }
1103}
1104
1105void __stdcall glDeleteShader(GLuint shader)
1106{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001107 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001108
Geoff Langbfdea662014-07-23 14:16:32 -04001109 if (shader == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001110 {
Geoff Langbfdea662014-07-23 14:16:32 -04001111 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001112 }
Geoff Langbfdea662014-07-23 14:16:32 -04001113
1114 gl::Context *context = gl::getNonLostContext();
1115
1116 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001117 {
Geoff Langbfdea662014-07-23 14:16:32 -04001118 if (!context->getShader(shader))
1119 {
1120 if(context->getProgram(shader))
1121 {
1122 return gl::error(GL_INVALID_OPERATION);
1123 }
1124 else
1125 {
1126 return gl::error(GL_INVALID_VALUE);
1127 }
1128 }
1129
1130 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001131 }
1132}
1133
1134void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1135{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001136 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001137
Geoff Langbfdea662014-07-23 14:16:32 -04001138 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001139 {
Geoff Langbfdea662014-07-23 14:16:32 -04001140 return gl::error(GL_INVALID_VALUE);
1141 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001142
Geoff Langbfdea662014-07-23 14:16:32 -04001143 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001144
Geoff Langbfdea662014-07-23 14:16:32 -04001145 if (context)
1146 {
1147 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001148 {
Geoff Langbfdea662014-07-23 14:16:32 -04001149 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001150 {
Geoff Langbfdea662014-07-23 14:16:32 -04001151 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001152 }
1153 }
1154 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001155}
1156
1157void __stdcall glDepthFunc(GLenum func)
1158{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001159 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001160
Geoff Langbfdea662014-07-23 14:16:32 -04001161 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001162 {
Geoff Langbfdea662014-07-23 14:16:32 -04001163 case GL_NEVER:
1164 case GL_ALWAYS:
1165 case GL_LESS:
1166 case GL_LEQUAL:
1167 case GL_EQUAL:
1168 case GL_GREATER:
1169 case GL_GEQUAL:
1170 case GL_NOTEQUAL:
1171 break;
1172 default:
1173 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001174 }
Geoff Langbfdea662014-07-23 14:16:32 -04001175
1176 gl::Context *context = gl::getNonLostContext();
1177
1178 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001179 {
Geoff Langbfdea662014-07-23 14:16:32 -04001180 context->getState().setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001181 }
1182}
1183
1184void __stdcall glDepthMask(GLboolean flag)
1185{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001186 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001187
Geoff Langbfdea662014-07-23 14:16:32 -04001188 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001189
Geoff Langbfdea662014-07-23 14:16:32 -04001190 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001191 {
Geoff Langbfdea662014-07-23 14:16:32 -04001192 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001193 }
1194}
1195
1196void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1197{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001198 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001199
Geoff Langbfdea662014-07-23 14:16:32 -04001200 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001201
Geoff Langbfdea662014-07-23 14:16:32 -04001202 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001203 {
Geoff Langbfdea662014-07-23 14:16:32 -04001204 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001205 }
1206}
1207
1208void __stdcall glDetachShader(GLuint program, GLuint shader)
1209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001210 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001211
Geoff Langbfdea662014-07-23 14:16:32 -04001212 gl::Context *context = gl::getNonLostContext();
1213
1214 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001215 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001216
Geoff Langbfdea662014-07-23 14:16:32 -04001217 gl::Program *programObject = context->getProgram(program);
1218 gl::Shader *shaderObject = context->getShader(shader);
1219
1220 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001221 {
Geoff Langbfdea662014-07-23 14:16:32 -04001222 gl::Shader *shaderByProgramHandle;
1223 shaderByProgramHandle = context->getShader(program);
1224 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001225 {
Geoff Langbfdea662014-07-23 14:16:32 -04001226 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001227 }
Geoff Langbfdea662014-07-23 14:16:32 -04001228 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001229 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001230 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001231 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001232 }
Geoff Langbfdea662014-07-23 14:16:32 -04001233
1234 if (!shaderObject)
1235 {
1236 gl::Program *programByShaderHandle = context->getProgram(shader);
1237 if (!programByShaderHandle)
1238 {
1239 return gl::error(GL_INVALID_VALUE);
1240 }
1241 else
1242 {
1243 return gl::error(GL_INVALID_OPERATION);
1244 }
1245 }
1246
1247 if (!programObject->detachShader(shaderObject))
1248 {
1249 return gl::error(GL_INVALID_OPERATION);
1250 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001251 }
1252}
1253
1254void __stdcall glDisable(GLenum cap)
1255{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001256 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001257
Geoff Langbfdea662014-07-23 14:16:32 -04001258 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001259
Geoff Langbfdea662014-07-23 14:16:32 -04001260 if (context)
1261 {
1262 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001263 {
Geoff Langbfdea662014-07-23 14:16:32 -04001264 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001265 }
Geoff Langbfdea662014-07-23 14:16:32 -04001266
1267 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001268 }
1269}
1270
1271void __stdcall glDisableVertexAttribArray(GLuint index)
1272{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001273 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001274
Geoff Langbfdea662014-07-23 14:16:32 -04001275 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001276 {
Geoff Langbfdea662014-07-23 14:16:32 -04001277 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001278 }
Geoff Langbfdea662014-07-23 14:16:32 -04001279
1280 gl::Context *context = gl::getNonLostContext();
1281
1282 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001283 {
Geoff Langbfdea662014-07-23 14:16:32 -04001284 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001285 }
1286}
1287
1288void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001290 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001291
Geoff Langbfdea662014-07-23 14:16:32 -04001292 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001293
Geoff Langbfdea662014-07-23 14:16:32 -04001294 if (context)
1295 {
Jamie Madill2b976812014-08-25 15:47:49 -04001296 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001297 {
Geoff Langbfdea662014-07-23 14:16:32 -04001298 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001299 }
Geoff Langbfdea662014-07-23 14:16:32 -04001300
1301 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001302 }
1303}
1304
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001305void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1306{
1307 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1308
Geoff Langbfdea662014-07-23 14:16:32 -04001309 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001310
Geoff Langbfdea662014-07-23 14:16:32 -04001311 if (context)
1312 {
1313 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001314 {
Geoff Langbfdea662014-07-23 14:16:32 -04001315 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001316 }
Geoff Langbfdea662014-07-23 14:16:32 -04001317
1318 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001319 }
1320}
1321
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001322void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001323{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001324 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 +00001325 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001326
Geoff Langbfdea662014-07-23 14:16:32 -04001327 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001328
Geoff Langbfdea662014-07-23 14:16:32 -04001329 if (context)
1330 {
Jamie Madill2b976812014-08-25 15:47:49 -04001331 rx::RangeUI indexRange;
1332 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001333 {
Geoff Langbfdea662014-07-23 14:16:32 -04001334 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001335 }
Geoff Langbfdea662014-07-23 14:16:32 -04001336
Jamie Madill2b976812014-08-25 15:47:49 -04001337 context->drawElements(mode, count, type, indices, 0, indexRange);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001338 }
1339}
1340
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001341void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1342{
1343 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1344 mode, count, type, indices, primcount);
1345
Geoff Langbfdea662014-07-23 14:16:32 -04001346 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001347
Geoff Langbfdea662014-07-23 14:16:32 -04001348 if (context)
1349 {
Jamie Madill2b976812014-08-25 15:47:49 -04001350 rx::RangeUI indexRange;
1351 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001352 {
Geoff Langbfdea662014-07-23 14:16:32 -04001353 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001354 }
Geoff Langbfdea662014-07-23 14:16:32 -04001355
Jamie Madill2b976812014-08-25 15:47:49 -04001356 context->drawElements(mode, count, type, indices, primcount, indexRange);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001357 }
1358}
1359
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001360void __stdcall glEnable(GLenum cap)
1361{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001362 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001363
Geoff Langbfdea662014-07-23 14:16:32 -04001364 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001365
Geoff Langbfdea662014-07-23 14:16:32 -04001366 if (context)
1367 {
1368 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001369 {
Geoff Langbfdea662014-07-23 14:16:32 -04001370 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001371 }
Geoff Langbfdea662014-07-23 14:16:32 -04001372
1373 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001374 }
1375}
1376
1377void __stdcall glEnableVertexAttribArray(GLuint index)
1378{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001379 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001380
Geoff Langbfdea662014-07-23 14:16:32 -04001381 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001382 {
Geoff Langbfdea662014-07-23 14:16:32 -04001383 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001384 }
Geoff Langbfdea662014-07-23 14:16:32 -04001385
1386 gl::Context *context = gl::getNonLostContext();
1387
1388 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001389 {
Geoff Langbfdea662014-07-23 14:16:32 -04001390 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001391 }
1392}
1393
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001394void __stdcall glEndQueryEXT(GLenum target)
1395{
1396 EVENT("GLenum target = 0x%X)", target);
1397
Geoff Langbfdea662014-07-23 14:16:32 -04001398 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001399
Geoff Langbfdea662014-07-23 14:16:32 -04001400 if (context)
1401 {
1402 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001403 {
Geoff Langbfdea662014-07-23 14:16:32 -04001404 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001405 }
Geoff Langbfdea662014-07-23 14:16:32 -04001406
1407 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001408 }
1409}
1410
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001411void __stdcall glFinishFenceNV(GLuint fence)
1412{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001413 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001414
Geoff Langbfdea662014-07-23 14:16:32 -04001415 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001416
Geoff Langbfdea662014-07-23 14:16:32 -04001417 if (context)
1418 {
1419 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1420
1421 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001422 {
Geoff Langbfdea662014-07-23 14:16:32 -04001423 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001424 }
Geoff Langbfdea662014-07-23 14:16:32 -04001425
1426 if (fenceObject->isFence() != GL_TRUE)
1427 {
1428 return gl::error(GL_INVALID_OPERATION);
1429 }
1430
1431 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001432 }
1433}
1434
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001435void __stdcall glFinish(void)
1436{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001437 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001438
Geoff Langbfdea662014-07-23 14:16:32 -04001439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001440
Geoff Langbfdea662014-07-23 14:16:32 -04001441 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001442 {
Geoff Langbfdea662014-07-23 14:16:32 -04001443 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001444 }
1445}
1446
1447void __stdcall glFlush(void)
1448{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001449 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001450
Geoff Langbfdea662014-07-23 14:16:32 -04001451 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001452
Geoff Langbfdea662014-07-23 14:16:32 -04001453 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001454 {
Geoff Langbfdea662014-07-23 14:16:32 -04001455 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001456 }
1457}
1458
1459void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001461 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001462 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001463
Geoff Langbfdea662014-07-23 14:16:32 -04001464 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001465 {
Geoff Langbfdea662014-07-23 14:16:32 -04001466 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001467 }
Geoff Langbfdea662014-07-23 14:16:32 -04001468
1469 gl::Context *context = gl::getNonLostContext();
1470
1471 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001472 {
Geoff Langbfdea662014-07-23 14:16:32 -04001473 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1474 {
1475 return;
1476 }
1477
1478 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1479 ASSERT(framebuffer);
1480
1481 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1482 {
1483 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1484 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1485 }
1486 else
1487 {
1488 switch (attachment)
1489 {
1490 case GL_DEPTH_ATTACHMENT:
1491 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1492 break;
1493 case GL_STENCIL_ATTACHMENT:
1494 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1495 break;
1496 case GL_DEPTH_STENCIL_ATTACHMENT:
1497 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1498 break;
1499 default:
1500 UNREACHABLE();
1501 break;
1502 }
1503 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001504 }
1505}
1506
1507void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1508{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001509 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001510 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001511
Geoff Langbfdea662014-07-23 14:16:32 -04001512 gl::Context *context = gl::getNonLostContext();
1513 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001514 {
Geoff Langbfdea662014-07-23 14:16:32 -04001515 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001516 {
Geoff Langbfdea662014-07-23 14:16:32 -04001517 return;
1518 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001519
Geoff Langbfdea662014-07-23 14:16:32 -04001520 if (texture == 0)
1521 {
1522 textarget = GL_NONE;
1523 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001524
Geoff Langbfdea662014-07-23 14:16:32 -04001525 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001526
Geoff Langbfdea662014-07-23 14:16:32 -04001527 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1528 {
1529 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1530 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1531 }
1532 else
1533 {
1534 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001535 {
Geoff Langbfdea662014-07-23 14:16:32 -04001536 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1537 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1538 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001539 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001540 }
1541 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001542}
1543
1544void __stdcall glFrontFace(GLenum mode)
1545{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001546 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001547
Geoff Langbfdea662014-07-23 14:16:32 -04001548 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001549 {
Geoff Langbfdea662014-07-23 14:16:32 -04001550 case GL_CW:
1551 case GL_CCW:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001552 {
Geoff Langbfdea662014-07-23 14:16:32 -04001553 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001554
Geoff Langbfdea662014-07-23 14:16:32 -04001555 if (context)
1556 {
1557 context->getState().setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001558 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001559 }
Geoff Langbfdea662014-07-23 14:16:32 -04001560 break;
1561 default:
1562 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001563 }
1564}
1565
1566void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1567{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001568 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001569
Geoff Langbfdea662014-07-23 14:16:32 -04001570 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001571 {
Geoff Langbfdea662014-07-23 14:16:32 -04001572 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001573 }
Geoff Langbfdea662014-07-23 14:16:32 -04001574
1575 gl::Context *context = gl::getNonLostContext();
1576
1577 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001578 {
Geoff Langbfdea662014-07-23 14:16:32 -04001579 for (int i = 0; i < n; i++)
1580 {
1581 buffers[i] = context->createBuffer();
1582 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001583 }
1584}
1585
1586void __stdcall glGenerateMipmap(GLenum target)
1587{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001588 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001589
Geoff Langbfdea662014-07-23 14:16:32 -04001590 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001591
Geoff Langbfdea662014-07-23 14:16:32 -04001592 if (context)
1593 {
1594 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001595 {
Geoff Langbfdea662014-07-23 14:16:32 -04001596 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001597 }
Geoff Langbfdea662014-07-23 14:16:32 -04001598
1599 gl::Texture *texture = context->getTargetTexture(target);
1600
1601 if (texture == NULL)
1602 {
1603 return gl::error(GL_INVALID_OPERATION);
1604 }
1605
1606 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1607 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001608 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001609
1610 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1611 // unsized formats or that are color renderable and filterable. Since we do not track if
1612 // the texture was created with sized or unsized format (only sized formats are stored),
1613 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1614 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1615 // textures since they're the only texture format that can be created with unsized formats
1616 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1617 // was the last version to use add them.
1618 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1619 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1620 internalFormat == GL_ALPHA8_EXT;
1621
Geoff Lang5d601382014-07-22 15:14:06 -04001622 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1623 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001624 {
1625 return gl::error(GL_INVALID_OPERATION);
1626 }
1627
1628 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001629 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001630 {
1631 return gl::error(GL_INVALID_OPERATION);
1632 }
1633
1634 // Non-power of 2 ES2 check
1635 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1636 {
1637 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
1638 return gl::error(GL_INVALID_OPERATION);
1639 }
1640
1641 // Cube completeness check
1642 if (target == GL_TEXTURE_CUBE_MAP)
1643 {
1644 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1645 if (!textureCube->isCubeComplete())
1646 {
1647 return gl::error(GL_INVALID_OPERATION);
1648 }
1649 }
1650
1651 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001652 }
1653}
1654
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001655void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1656{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001657 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001658
Geoff Langbfdea662014-07-23 14:16:32 -04001659 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001660 {
Geoff Langbfdea662014-07-23 14:16:32 -04001661 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001662 }
Geoff Langbfdea662014-07-23 14:16:32 -04001663
1664 gl::Context *context = gl::getNonLostContext();
1665
1666 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001667 {
Geoff Langbfdea662014-07-23 14:16:32 -04001668 for (int i = 0; i < n; i++)
1669 {
1670 fences[i] = context->createFenceNV();
1671 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001672 }
1673}
1674
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001675void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1676{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001677 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001678
Geoff Langbfdea662014-07-23 14:16:32 -04001679 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001680 {
Geoff Langbfdea662014-07-23 14:16:32 -04001681 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001682 }
Geoff Langbfdea662014-07-23 14:16:32 -04001683
1684 gl::Context *context = gl::getNonLostContext();
1685
1686 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001687 {
Geoff Langbfdea662014-07-23 14:16:32 -04001688 for (int i = 0; i < n; i++)
1689 {
1690 framebuffers[i] = context->createFramebuffer();
1691 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001692 }
1693}
1694
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001695void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1696{
1697 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1698
Geoff Langbfdea662014-07-23 14:16:32 -04001699 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001700
Geoff Langbfdea662014-07-23 14:16:32 -04001701 if (context)
1702 {
1703 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001704 {
Geoff Langbfdea662014-07-23 14:16:32 -04001705 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001706 }
Geoff Langbfdea662014-07-23 14:16:32 -04001707
1708 for (GLsizei i = 0; i < n; i++)
1709 {
1710 ids[i] = context->createQuery();
1711 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001712 }
1713}
1714
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001715void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1716{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001717 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001718
Geoff Langbfdea662014-07-23 14:16:32 -04001719 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001720 {
Geoff Langbfdea662014-07-23 14:16:32 -04001721 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001722 }
Geoff Langbfdea662014-07-23 14:16:32 -04001723
1724 gl::Context *context = gl::getNonLostContext();
1725
1726 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001727 {
Geoff Langbfdea662014-07-23 14:16:32 -04001728 for (int i = 0; i < n; i++)
1729 {
1730 renderbuffers[i] = context->createRenderbuffer();
1731 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001732 }
1733}
1734
1735void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1736{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001737 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001738
Geoff Langbfdea662014-07-23 14:16:32 -04001739 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001740 {
Geoff Langbfdea662014-07-23 14:16:32 -04001741 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001742 }
Geoff Langbfdea662014-07-23 14:16:32 -04001743
1744 gl::Context *context = gl::getNonLostContext();
1745
1746 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001747 {
Geoff Langbfdea662014-07-23 14:16:32 -04001748 for (int i = 0; i < n; i++)
1749 {
1750 textures[i] = context->createTexture();
1751 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001752 }
1753}
1754
daniel@transgaming.com85423182010-04-22 13:35:27 +00001755void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001756{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001757 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001758 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001759 program, index, bufsize, length, size, type, name);
1760
Geoff Langbfdea662014-07-23 14:16:32 -04001761 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001762 {
Geoff Langbfdea662014-07-23 14:16:32 -04001763 return gl::error(GL_INVALID_VALUE);
1764 }
1765
1766 gl::Context *context = gl::getNonLostContext();
1767
1768 if (context)
1769 {
1770 gl::Program *programObject = context->getProgram(program);
1771
1772 if (!programObject)
1773 {
1774 if (context->getShader(program))
1775 {
1776 return gl::error(GL_INVALID_OPERATION);
1777 }
1778 else
1779 {
1780 return gl::error(GL_INVALID_VALUE);
1781 }
1782 }
1783
1784 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001786 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001787 }
1788
Geoff Langbfdea662014-07-23 14:16:32 -04001789 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001790 }
1791}
1792
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001793void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001794{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001795 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001796 "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 +00001797 program, index, bufsize, length, size, type, name);
1798
Geoff Langbfdea662014-07-23 14:16:32 -04001799 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001800 {
Geoff Langbfdea662014-07-23 14:16:32 -04001801 return gl::error(GL_INVALID_VALUE);
1802 }
1803
1804 gl::Context *context = gl::getNonLostContext();
1805
1806 if (context)
1807 {
1808 gl::Program *programObject = context->getProgram(program);
1809
1810 if (!programObject)
1811 {
1812 if (context->getShader(program))
1813 {
1814 return gl::error(GL_INVALID_OPERATION);
1815 }
1816 else
1817 {
1818 return gl::error(GL_INVALID_VALUE);
1819 }
1820 }
1821
1822 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001823 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001824 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001825 }
1826
Geoff Langbfdea662014-07-23 14:16:32 -04001827 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001828 }
1829}
1830
1831void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1832{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001833 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 +00001834 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001835
Geoff Langbfdea662014-07-23 14:16:32 -04001836 if (maxcount < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001837 {
Geoff Langbfdea662014-07-23 14:16:32 -04001838 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001839 }
Geoff Langbfdea662014-07-23 14:16:32 -04001840
1841 gl::Context *context = gl::getNonLostContext();
1842
1843 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001844 {
Geoff Langbfdea662014-07-23 14:16:32 -04001845 gl::Program *programObject = context->getProgram(program);
1846
1847 if (!programObject)
1848 {
1849 if (context->getShader(program))
1850 {
1851 return gl::error(GL_INVALID_OPERATION);
1852 }
1853 else
1854 {
1855 return gl::error(GL_INVALID_VALUE);
1856 }
1857 }
1858
1859 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001860 }
1861}
1862
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001863int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001865 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001866
Geoff Langbfdea662014-07-23 14:16:32 -04001867 gl::Context *context = gl::getNonLostContext();
1868
1869 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001870 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001871
Geoff Langbfdea662014-07-23 14:16:32 -04001872 gl::Program *programObject = context->getProgram(program);
1873
1874 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001875 {
Geoff Langbfdea662014-07-23 14:16:32 -04001876 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001878 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001879 }
Geoff Langbfdea662014-07-23 14:16:32 -04001880 else
1881 {
1882 return gl::error(GL_INVALID_VALUE, -1);
1883 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001884 }
Geoff Langbfdea662014-07-23 14:16:32 -04001885
1886 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1887 if (!programObject->isLinked() || !programBinary)
1888 {
1889 return gl::error(GL_INVALID_OPERATION, -1);
1890 }
1891
1892 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001893 }
1894
1895 return -1;
1896}
1897
1898void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1899{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001900 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001901
Geoff Langbfdea662014-07-23 14:16:32 -04001902 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00001903
Geoff Langbfdea662014-07-23 14:16:32 -04001904 if (context)
1905 {
1906 GLenum nativeType;
1907 unsigned int numParams = 0;
1908 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001909 {
Geoff Langbfdea662014-07-23 14:16:32 -04001910 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001911 }
Geoff Langbfdea662014-07-23 14:16:32 -04001912
1913 if (nativeType == GL_BOOL)
1914 {
1915 context->getBooleanv(pname, params);
1916 }
1917 else
1918 {
1919 CastStateValues(context, nativeType, pname, numParams, params);
1920 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001921 }
1922}
1923
1924void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1925{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001926 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 +00001927
Geoff Langbfdea662014-07-23 14:16:32 -04001928 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001929
Geoff Langbfdea662014-07-23 14:16:32 -04001930 if (context)
1931 {
1932 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001933 {
Geoff Langbfdea662014-07-23 14:16:32 -04001934 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001935 }
Geoff Langbfdea662014-07-23 14:16:32 -04001936
1937 if (!gl::ValidBufferParameter(context, pname))
1938 {
1939 return gl::error(GL_INVALID_ENUM);
1940 }
1941
1942 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
1943
1944 if (!buffer)
1945 {
1946 // A null buffer means that "0" is bound to the requested buffer target
1947 return gl::error(GL_INVALID_OPERATION);
1948 }
1949
1950 switch (pname)
1951 {
1952 case GL_BUFFER_USAGE:
1953 *params = static_cast<GLint>(buffer->getUsage());
1954 break;
1955 case GL_BUFFER_SIZE:
1956 *params = gl::clampCast<GLint>(buffer->getSize());
1957 break;
1958 case GL_BUFFER_ACCESS_FLAGS:
1959 *params = buffer->getAccessFlags();
1960 break;
1961 case GL_BUFFER_MAPPED:
1962 *params = static_cast<GLint>(buffer->isMapped());
1963 break;
1964 case GL_BUFFER_MAP_OFFSET:
1965 *params = gl::clampCast<GLint>(buffer->getMapOffset());
1966 break;
1967 case GL_BUFFER_MAP_LENGTH:
1968 *params = gl::clampCast<GLint>(buffer->getMapLength());
1969 break;
1970 default: UNREACHABLE(); break;
1971 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001972 }
1973}
1974
1975GLenum __stdcall glGetError(void)
1976{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001977 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001978
1979 gl::Context *context = gl::getContext();
1980
1981 if (context)
1982 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00001983 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001984 }
1985
1986 return GL_NO_ERROR;
1987}
1988
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001989void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
1990{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001991 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001992
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001993
Geoff Langbfdea662014-07-23 14:16:32 -04001994 gl::Context *context = gl::getNonLostContext();
1995
1996 if (context)
1997 {
1998 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1999
2000 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002001 {
Geoff Langbfdea662014-07-23 14:16:32 -04002002 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002003 }
Geoff Langbfdea662014-07-23 14:16:32 -04002004
2005 if (fenceObject->isFence() != GL_TRUE)
2006 {
2007 return gl::error(GL_INVALID_OPERATION);
2008 }
2009
2010 switch (pname)
2011 {
2012 case GL_FENCE_STATUS_NV:
2013 case GL_FENCE_CONDITION_NV:
2014 break;
2015
2016 default: return gl::error(GL_INVALID_ENUM);
2017 }
2018
2019 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002020 }
2021}
2022
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002023void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2024{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002025 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002026
Geoff Langbfdea662014-07-23 14:16:32 -04002027 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002028
Geoff Langbfdea662014-07-23 14:16:32 -04002029 if (context)
2030 {
2031 GLenum nativeType;
2032 unsigned int numParams = 0;
2033 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002034 {
Geoff Langbfdea662014-07-23 14:16:32 -04002035 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002036 }
Geoff Langbfdea662014-07-23 14:16:32 -04002037
2038 if (nativeType == GL_FLOAT)
2039 {
2040 context->getFloatv(pname, params);
2041 }
2042 else
2043 {
2044 CastStateValues(context, nativeType, pname, numParams, params);
2045 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002046 }
2047}
2048
2049void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2050{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002051 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 +00002052 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002053
Geoff Langbfdea662014-07-23 14:16:32 -04002054 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002055
Geoff Langbfdea662014-07-23 14:16:32 -04002056 if (context)
2057 {
2058 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002059 {
Geoff Langbfdea662014-07-23 14:16:32 -04002060 return gl::error(GL_INVALID_ENUM);
2061 }
2062
2063 int clientVersion = context->getClientVersion();
2064
2065 switch (pname)
2066 {
2067 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2068 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2069 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2070 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2071 break;
2072 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2073 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002075 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002076 }
Geoff Langbfdea662014-07-23 14:16:32 -04002077 break;
2078 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2079 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2080 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2081 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2082 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2083 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2084 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2085 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2086 if (clientVersion < 3)
2087 {
2088 return gl::error(GL_INVALID_ENUM);
2089 }
2090 break;
2091 default:
2092 return gl::error(GL_INVALID_ENUM);
2093 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002094
Geoff Langbfdea662014-07-23 14:16:32 -04002095 // Determine if the attachment is a valid enum
2096 switch (attachment)
2097 {
2098 case GL_BACK:
2099 case GL_FRONT:
2100 case GL_DEPTH:
2101 case GL_STENCIL:
2102 case GL_DEPTH_STENCIL_ATTACHMENT:
2103 if (clientVersion < 3)
2104 {
2105 return gl::error(GL_INVALID_ENUM);
2106 }
2107 break;
2108
2109 case GL_DEPTH_ATTACHMENT:
2110 case GL_STENCIL_ATTACHMENT:
2111 break;
2112
2113 default:
2114 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2115 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2116 {
2117 return gl::error(GL_INVALID_ENUM);
2118 }
2119 break;
2120 }
2121
2122 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2123 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2124
2125 if (framebufferHandle == 0)
2126 {
2127 if (clientVersion < 3)
2128 {
2129 return gl::error(GL_INVALID_OPERATION);
2130 }
2131
2132 switch (attachment)
2133 {
2134 case GL_BACK:
2135 case GL_DEPTH:
2136 case GL_STENCIL:
2137 break;
2138 default:
2139 return gl::error(GL_INVALID_OPERATION);
2140 }
2141 }
2142 else
2143 {
2144 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2145 {
2146 // Valid attachment query
2147 }
2148 else
2149 {
2150 switch (attachment)
2151 {
2152 case GL_DEPTH_ATTACHMENT:
2153 case GL_STENCIL_ATTACHMENT:
2154 break;
2155 case GL_DEPTH_STENCIL_ATTACHMENT:
2156 if (framebuffer->hasValidDepthStencil())
2157 {
2158 return gl::error(GL_INVALID_OPERATION);
2159 }
2160 break;
2161 default:
2162 return gl::error(GL_INVALID_OPERATION);
2163 }
2164 }
2165 }
2166
2167 GLenum attachmentType = GL_NONE;
2168 GLuint attachmentHandle = 0;
2169 GLuint attachmentLevel = 0;
2170 GLuint attachmentLayer = 0;
2171
2172 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2173
2174 if (attachmentObject)
2175 {
2176 attachmentType = attachmentObject->type();
2177 attachmentHandle = attachmentObject->id();
2178 attachmentLevel = attachmentObject->mipLevel();
2179 attachmentLayer = attachmentObject->layer();
2180 }
2181
2182 GLenum attachmentObjectType; // Type category
2183 if (framebufferHandle == 0)
2184 {
2185 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2186 }
2187 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2188 {
2189 attachmentObjectType = attachmentType;
2190 }
2191 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2192 {
2193 attachmentObjectType = GL_TEXTURE;
2194 }
2195 else
2196 {
2197 UNREACHABLE();
2198 return;
2199 }
2200
2201 if (attachmentObjectType == GL_NONE)
2202 {
2203 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2204 // is NONE, then querying any other pname will generate INVALID_ENUM.
2205
2206 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2207 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2208 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002209
Geoff Lang646559f2013-08-15 11:08:15 -04002210 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002211 {
Geoff Lang646559f2013-08-15 11:08:15 -04002212 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002213 *params = attachmentObjectType;
2214 break;
2215
Geoff Lang646559f2013-08-15 11:08:15 -04002216 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002217 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002218 {
Geoff Lang05b05022014-06-11 15:31:45 -04002219 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002220 }
Geoff Langbfdea662014-07-23 14:16:32 -04002221 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002222 break;
2223
2224 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002225 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002226 {
Geoff Langbfdea662014-07-23 14:16:32 -04002227 return gl::error(GL_INVALID_ENUM);
Geoff Lang646559f2013-08-15 11:08:15 -04002228 }
2229 else
2230 {
Geoff Langbfdea662014-07-23 14:16:32 -04002231 gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002232 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002233 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002234 }
Geoff Langbfdea662014-07-23 14:16:32 -04002235 else
2236 {
2237 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2238 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2239 ASSERT(attachmentObject != NULL);
2240
2241 switch (pname)
2242 {
2243 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2244 *params = attachmentObjectType;
2245 break;
2246
2247 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2248 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2249 {
2250 return gl::error(GL_INVALID_ENUM);
2251 }
2252 *params = attachmentHandle;
2253 break;
2254
2255 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2256 if (attachmentObjectType != GL_TEXTURE)
2257 {
2258 return gl::error(GL_INVALID_ENUM);
2259 }
2260 *params = attachmentLevel;
2261 break;
2262
2263 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2264 if (attachmentObjectType != GL_TEXTURE)
2265 {
2266 return gl::error(GL_INVALID_ENUM);
2267 }
2268 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2269 break;
2270
2271 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2272 *params = attachmentObject->getRedSize();
2273 break;
2274
2275 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2276 *params = attachmentObject->getGreenSize();
2277 break;
2278
2279 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2280 *params = attachmentObject->getBlueSize();
2281 break;
2282
2283 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2284 *params = attachmentObject->getAlphaSize();
2285 break;
2286
2287 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2288 *params = attachmentObject->getDepthSize();
2289 break;
2290
2291 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2292 *params = attachmentObject->getStencilSize();
2293 break;
2294
2295 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2296 if (attachment == GL_DEPTH_STENCIL)
2297 {
2298 gl::error(GL_INVALID_OPERATION);
2299 }
2300 *params = attachmentObject->getComponentType();
2301 break;
2302
2303 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2304 *params = attachmentObject->getColorEncoding();
2305 break;
2306
2307 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2308 if (attachmentObjectType != GL_TEXTURE)
2309 {
2310 return gl::error(GL_INVALID_ENUM);
2311 }
2312 *params = attachmentLayer;
2313 break;
2314
2315 default:
2316 UNREACHABLE();
2317 break;
2318 }
2319 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002320 }
2321}
2322
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002323GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2324{
2325 EVENT("()");
2326
Geoff Langbfdea662014-07-23 14:16:32 -04002327 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002328
Geoff Langbfdea662014-07-23 14:16:32 -04002329 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002330 {
Geoff Langbfdea662014-07-23 14:16:32 -04002331 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002332 }
Geoff Langbfdea662014-07-23 14:16:32 -04002333
2334 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002335}
2336
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002337void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2338{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002339 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002340
Geoff Langbfdea662014-07-23 14:16:32 -04002341 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002342
Geoff Langbfdea662014-07-23 14:16:32 -04002343 if (context)
2344 {
2345 GLenum nativeType;
2346 unsigned int numParams = 0;
2347
2348 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349 {
Geoff Langbfdea662014-07-23 14:16:32 -04002350 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002351 }
Geoff Langbfdea662014-07-23 14:16:32 -04002352
2353 if (nativeType == GL_INT)
2354 {
2355 context->getIntegerv(pname, params);
2356 }
2357 else
2358 {
2359 CastStateValues(context, nativeType, pname, numParams, params);
2360 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002361 }
2362}
2363
2364void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2365{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002366 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002367
Geoff Langbfdea662014-07-23 14:16:32 -04002368 gl::Context *context = gl::getNonLostContext();
2369
2370 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002371 {
Geoff Langbfdea662014-07-23 14:16:32 -04002372 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002373
Geoff Langbfdea662014-07-23 14:16:32 -04002374 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002375 {
Geoff Langbfdea662014-07-23 14:16:32 -04002376 return gl::error(GL_INVALID_VALUE);
2377 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002378
Geoff Langbfdea662014-07-23 14:16:32 -04002379 if (context->getClientVersion() < 3)
2380 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002381 switch (pname)
2382 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002383 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002384 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002385 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002386 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002387 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002388 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002389 }
2390 }
Geoff Langbfdea662014-07-23 14:16:32 -04002391
2392 switch (pname)
2393 {
2394 case GL_DELETE_STATUS:
2395 *params = programObject->isFlaggedForDeletion();
2396 return;
2397 case GL_LINK_STATUS:
2398 *params = programObject->isLinked();
2399 return;
2400 case GL_VALIDATE_STATUS:
2401 *params = programObject->isValidated();
2402 return;
2403 case GL_INFO_LOG_LENGTH:
2404 *params = programObject->getInfoLogLength();
2405 return;
2406 case GL_ATTACHED_SHADERS:
2407 *params = programObject->getAttachedShadersCount();
2408 return;
2409 case GL_ACTIVE_ATTRIBUTES:
2410 *params = programObject->getActiveAttributeCount();
2411 return;
2412 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2413 *params = programObject->getActiveAttributeMaxLength();
2414 return;
2415 case GL_ACTIVE_UNIFORMS:
2416 *params = programObject->getActiveUniformCount();
2417 return;
2418 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2419 *params = programObject->getActiveUniformMaxLength();
2420 return;
2421 case GL_PROGRAM_BINARY_LENGTH_OES:
2422 *params = programObject->getProgramBinaryLength();
2423 return;
2424 case GL_ACTIVE_UNIFORM_BLOCKS:
2425 *params = programObject->getActiveUniformBlockCount();
2426 return;
2427 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2428 *params = programObject->getActiveUniformBlockMaxLength();
2429 break;
2430 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2431 *params = programObject->getTransformFeedbackBufferMode();
2432 break;
2433 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2434 *params = programObject->getTransformFeedbackVaryingCount();
2435 break;
2436 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2437 *params = programObject->getTransformFeedbackVaryingMaxLength();
2438 break;
2439 default:
2440 return gl::error(GL_INVALID_ENUM);
2441 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442 }
2443}
2444
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002445void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002446{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002447 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 +00002448 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449
Geoff Langbfdea662014-07-23 14:16:32 -04002450 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002451 {
Geoff Langbfdea662014-07-23 14:16:32 -04002452 return gl::error(GL_INVALID_VALUE);
2453 }
2454
2455 gl::Context *context = gl::getNonLostContext();
2456
2457 if (context)
2458 {
2459 gl::Program *programObject = context->getProgram(program);
2460
2461 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002463 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002464 }
2465
Geoff Langbfdea662014-07-23 14:16:32 -04002466 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002467 }
2468}
2469
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002470void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2471{
2472 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2473
Geoff Langbfdea662014-07-23 14:16:32 -04002474 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002475
Geoff Langbfdea662014-07-23 14:16:32 -04002476 if (context)
2477 {
2478 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002479 {
Geoff Langbfdea662014-07-23 14:16:32 -04002480 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002481 }
Geoff Langbfdea662014-07-23 14:16:32 -04002482
2483 switch (pname)
2484 {
2485 case GL_CURRENT_QUERY_EXT:
2486 params[0] = context->getState().getActiveQueryId(target);
2487 break;
2488
2489 default:
2490 return gl::error(GL_INVALID_ENUM);
2491 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002492 }
2493}
2494
2495void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2496{
2497 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2498
Geoff Langbfdea662014-07-23 14:16:32 -04002499 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002500
Geoff Langbfdea662014-07-23 14:16:32 -04002501 if (context)
2502 {
2503 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2504
2505 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002506 {
Geoff Langbfdea662014-07-23 14:16:32 -04002507 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002508 }
Geoff Langbfdea662014-07-23 14:16:32 -04002509
2510 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2511 {
2512 return gl::error(GL_INVALID_OPERATION);
2513 }
2514
2515 switch(pname)
2516 {
2517 case GL_QUERY_RESULT_EXT:
2518 params[0] = queryObject->getResult();
2519 break;
2520 case GL_QUERY_RESULT_AVAILABLE_EXT:
2521 params[0] = queryObject->isResultAvailable();
2522 break;
2523 default:
2524 return gl::error(GL_INVALID_ENUM);
2525 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002526 }
2527}
2528
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002529void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2530{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002531 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 +00002532
Geoff Langbfdea662014-07-23 14:16:32 -04002533 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002534
Geoff Langbfdea662014-07-23 14:16:32 -04002535 if (context)
2536 {
2537 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002538 {
Geoff Langbfdea662014-07-23 14:16:32 -04002539 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002540 }
Geoff Langbfdea662014-07-23 14:16:32 -04002541
2542 if (context->getState().getRenderbufferId() == 0)
2543 {
2544 return gl::error(GL_INVALID_OPERATION);
2545 }
2546
2547 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2548
2549 switch (pname)
2550 {
2551 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2552 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2553 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2554 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2555 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2556 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2557 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2558 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2559 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
2560 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2561 if (!context->getExtensions().framebufferMultisample)
2562 {
2563 return gl::error(GL_INVALID_ENUM);
2564 }
2565 *params = renderbuffer->getSamples();
2566 break;
2567 default:
2568 return gl::error(GL_INVALID_ENUM);
2569 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002570 }
2571}
2572
2573void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2574{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002575 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002576
Geoff Langbfdea662014-07-23 14:16:32 -04002577 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002578
Geoff Langbfdea662014-07-23 14:16:32 -04002579 if (context)
2580 {
2581 gl::Shader *shaderObject = context->getShader(shader);
2582
2583 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002584 {
Geoff Langbfdea662014-07-23 14:16:32 -04002585 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002586 }
Geoff Langbfdea662014-07-23 14:16:32 -04002587
2588 switch (pname)
2589 {
2590 case GL_SHADER_TYPE:
2591 *params = shaderObject->getType();
2592 return;
2593 case GL_DELETE_STATUS:
2594 *params = shaderObject->isFlaggedForDeletion();
2595 return;
2596 case GL_COMPILE_STATUS:
2597 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2598 return;
2599 case GL_INFO_LOG_LENGTH:
2600 *params = shaderObject->getInfoLogLength();
2601 return;
2602 case GL_SHADER_SOURCE_LENGTH:
2603 *params = shaderObject->getSourceLength();
2604 return;
2605 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2606 *params = shaderObject->getTranslatedSourceLength();
2607 return;
2608 default:
2609 return gl::error(GL_INVALID_ENUM);
2610 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002611 }
2612}
2613
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002614void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002615{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002616 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 +00002617 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002618
Geoff Langbfdea662014-07-23 14:16:32 -04002619 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002620 {
Geoff Langbfdea662014-07-23 14:16:32 -04002621 return gl::error(GL_INVALID_VALUE);
2622 }
2623
2624 gl::Context *context = gl::getNonLostContext();
2625
2626 if (context)
2627 {
2628 gl::Shader *shaderObject = context->getShader(shader);
2629
2630 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002631 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002632 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002633 }
2634
Geoff Langbfdea662014-07-23 14:16:32 -04002635 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002636 }
2637}
2638
2639void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2640{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002641 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 +00002642 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002643
Geoff Langbfdea662014-07-23 14:16:32 -04002644 switch (shadertype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002645 {
Geoff Langbfdea662014-07-23 14:16:32 -04002646 case GL_VERTEX_SHADER:
2647 case GL_FRAGMENT_SHADER:
2648 break;
2649 default:
2650 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002651 }
Geoff Langbfdea662014-07-23 14:16:32 -04002652
2653 switch (precisiontype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002654 {
Geoff Langbfdea662014-07-23 14:16:32 -04002655 case GL_LOW_FLOAT:
2656 case GL_MEDIUM_FLOAT:
2657 case GL_HIGH_FLOAT:
2658 // Assume IEEE 754 precision
2659 range[0] = 127;
2660 range[1] = 127;
2661 *precision = 23;
2662 break;
2663 case GL_LOW_INT:
2664 case GL_MEDIUM_INT:
2665 case GL_HIGH_INT:
2666 // Some (most) hardware only supports single-precision floating-point numbers,
2667 // which can accurately represent integers up to +/-16777216
2668 range[0] = 24;
2669 range[1] = 24;
2670 *precision = 0;
2671 break;
2672 default:
2673 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002674 }
2675}
2676
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002677void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002679 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 +00002680 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002681
Geoff Langbfdea662014-07-23 14:16:32 -04002682 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002683 {
Geoff Langbfdea662014-07-23 14:16:32 -04002684 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002685 }
Geoff Langbfdea662014-07-23 14:16:32 -04002686
2687 gl::Context *context = gl::getNonLostContext();
2688
2689 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002690 {
Geoff Langbfdea662014-07-23 14:16:32 -04002691 gl::Shader *shaderObject = context->getShader(shader);
2692
2693 if (!shaderObject)
2694 {
2695 return gl::error(GL_INVALID_OPERATION);
2696 }
2697
2698 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002699 }
2700}
2701
zmo@google.coma574f782011-10-03 21:45:23 +00002702void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2703{
2704 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2705 shader, bufsize, length, source);
2706
Geoff Langbfdea662014-07-23 14:16:32 -04002707 if (bufsize < 0)
zmo@google.coma574f782011-10-03 21:45:23 +00002708 {
Geoff Langbfdea662014-07-23 14:16:32 -04002709 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00002710 }
Geoff Langbfdea662014-07-23 14:16:32 -04002711
2712 gl::Context *context = gl::getNonLostContext();
2713
2714 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002715 {
Geoff Langbfdea662014-07-23 14:16:32 -04002716 gl::Shader *shaderObject = context->getShader(shader);
2717
2718 if (!shaderObject)
2719 {
2720 return gl::error(GL_INVALID_OPERATION);
2721 }
2722
2723 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002724 }
2725}
2726
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002727const GLubyte* __stdcall glGetString(GLenum name)
2728{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002729 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002730
Geoff Langbfdea662014-07-23 14:16:32 -04002731 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002732
Geoff Langbfdea662014-07-23 14:16:32 -04002733 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002734 {
Geoff Langbfdea662014-07-23 14:16:32 -04002735 case GL_VENDOR:
2736 return (GLubyte*)"Google Inc.";
2737 case GL_RENDERER:
2738 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
2739 case GL_VERSION:
2740 if (context->getClientVersion() == 2)
2741 {
2742 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2743 }
2744 else
2745 {
2746 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2747 }
2748 case GL_SHADING_LANGUAGE_VERSION:
2749 if (context->getClientVersion() == 2)
2750 {
2751 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2752 }
2753 else
2754 {
2755 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2756 }
2757 case GL_EXTENSIONS:
2758 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
2759 default:
2760 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002761 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762}
2763
2764void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2765{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002766 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 +00002767
Geoff Langbfdea662014-07-23 14:16:32 -04002768 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002769
Geoff Langbfdea662014-07-23 14:16:32 -04002770 if (context)
2771 {
2772 gl::Texture *texture = context->getTargetTexture(target);
2773
2774 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002775 {
Geoff Langbfdea662014-07-23 14:16:32 -04002776 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002777 }
Geoff Langbfdea662014-07-23 14:16:32 -04002778
2779 switch (pname)
2780 {
2781 case GL_TEXTURE_MAG_FILTER:
2782 *params = (GLfloat)texture->getSamplerState().magFilter;
2783 break;
2784 case GL_TEXTURE_MIN_FILTER:
2785 *params = (GLfloat)texture->getSamplerState().minFilter;
2786 break;
2787 case GL_TEXTURE_WRAP_S:
2788 *params = (GLfloat)texture->getSamplerState().wrapS;
2789 break;
2790 case GL_TEXTURE_WRAP_T:
2791 *params = (GLfloat)texture->getSamplerState().wrapT;
2792 break;
2793 case GL_TEXTURE_WRAP_R:
2794 if (context->getClientVersion() < 3)
2795 {
2796 return gl::error(GL_INVALID_ENUM);
2797 }
2798 *params = (GLfloat)texture->getSamplerState().wrapR;
2799 break;
2800 case GL_TEXTURE_IMMUTABLE_FORMAT:
2801 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2802 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2803 break;
2804 case GL_TEXTURE_IMMUTABLE_LEVELS:
2805 if (context->getClientVersion() < 3)
2806 {
2807 return gl::error(GL_INVALID_ENUM);
2808 }
2809 *params = (GLfloat)texture->immutableLevelCount();
2810 break;
2811 case GL_TEXTURE_USAGE_ANGLE:
2812 *params = (GLfloat)texture->getUsage();
2813 break;
2814 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2815 if (!context->getExtensions().textureFilterAnisotropic)
2816 {
2817 return gl::error(GL_INVALID_ENUM);
2818 }
2819 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2820 break;
2821 case GL_TEXTURE_SWIZZLE_R:
2822 if (context->getClientVersion() < 3)
2823 {
2824 return gl::error(GL_INVALID_ENUM);
2825 }
2826 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2827 break;
2828 case GL_TEXTURE_SWIZZLE_G:
2829 if (context->getClientVersion() < 3)
2830 {
2831 return gl::error(GL_INVALID_ENUM);
2832 }
2833 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2834 break;
2835 case GL_TEXTURE_SWIZZLE_B:
2836 if (context->getClientVersion() < 3)
2837 {
2838 return gl::error(GL_INVALID_ENUM);
2839 }
2840 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2841 break;
2842 case GL_TEXTURE_SWIZZLE_A:
2843 if (context->getClientVersion() < 3)
2844 {
2845 return gl::error(GL_INVALID_ENUM);
2846 }
2847 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2848 break;
2849 case GL_TEXTURE_BASE_LEVEL:
2850 if (context->getClientVersion() < 3)
2851 {
2852 return gl::error(GL_INVALID_ENUM);
2853 }
2854 *params = (GLfloat)texture->getSamplerState().baseLevel;
2855 break;
2856 case GL_TEXTURE_MAX_LEVEL:
2857 if (context->getClientVersion() < 3)
2858 {
2859 return gl::error(GL_INVALID_ENUM);
2860 }
2861 *params = (GLfloat)texture->getSamplerState().maxLevel;
2862 break;
2863 case GL_TEXTURE_MIN_LOD:
2864 if (context->getClientVersion() < 3)
2865 {
2866 return gl::error(GL_INVALID_ENUM);
2867 }
2868 *params = texture->getSamplerState().minLod;
2869 break;
2870 case GL_TEXTURE_MAX_LOD:
2871 if (context->getClientVersion() < 3)
2872 {
2873 return gl::error(GL_INVALID_ENUM);
2874 }
2875 *params = texture->getSamplerState().maxLod;
2876 break;
2877 default:
2878 return gl::error(GL_INVALID_ENUM);
2879 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002880 }
2881}
2882
2883void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
2884{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002885 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 +00002886
Geoff Langbfdea662014-07-23 14:16:32 -04002887 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002888
Geoff Langbfdea662014-07-23 14:16:32 -04002889 if (context)
2890 {
2891 gl::Texture *texture = context->getTargetTexture(target);
2892
2893 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002894 {
Geoff Langbfdea662014-07-23 14:16:32 -04002895 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002896 }
Geoff Langbfdea662014-07-23 14:16:32 -04002897
2898 switch (pname)
2899 {
2900 case GL_TEXTURE_MAG_FILTER:
2901 *params = texture->getSamplerState().magFilter;
2902 break;
2903 case GL_TEXTURE_MIN_FILTER:
2904 *params = texture->getSamplerState().minFilter;
2905 break;
2906 case GL_TEXTURE_WRAP_S:
2907 *params = texture->getSamplerState().wrapS;
2908 break;
2909 case GL_TEXTURE_WRAP_T:
2910 *params = texture->getSamplerState().wrapT;
2911 break;
2912 case GL_TEXTURE_WRAP_R:
2913 if (context->getClientVersion() < 3)
2914 {
2915 return gl::error(GL_INVALID_ENUM);
2916 }
2917 *params = texture->getSamplerState().wrapR;
2918 break;
2919 case GL_TEXTURE_IMMUTABLE_FORMAT:
2920 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2921 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
2922 break;
2923 case GL_TEXTURE_IMMUTABLE_LEVELS:
2924 if (context->getClientVersion() < 3)
2925 {
2926 return gl::error(GL_INVALID_ENUM);
2927 }
2928 *params = texture->immutableLevelCount();
2929 break;
2930 case GL_TEXTURE_USAGE_ANGLE:
2931 *params = texture->getUsage();
2932 break;
2933 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2934 if (!context->getExtensions().textureFilterAnisotropic)
2935 {
2936 return gl::error(GL_INVALID_ENUM);
2937 }
2938 *params = (GLint)texture->getSamplerState().maxAnisotropy;
2939 break;
2940 case GL_TEXTURE_SWIZZLE_R:
2941 if (context->getClientVersion() < 3)
2942 {
2943 return gl::error(GL_INVALID_ENUM);
2944 }
2945 *params = texture->getSamplerState().swizzleRed;
2946 break;
2947 case GL_TEXTURE_SWIZZLE_G:
2948 if (context->getClientVersion() < 3)
2949 {
2950 return gl::error(GL_INVALID_ENUM);
2951 }
2952 *params = texture->getSamplerState().swizzleGreen;
2953 break;
2954 case GL_TEXTURE_SWIZZLE_B:
2955 if (context->getClientVersion() < 3)
2956 {
2957 return gl::error(GL_INVALID_ENUM);
2958 }
2959 *params = texture->getSamplerState().swizzleBlue;
2960 break;
2961 case GL_TEXTURE_SWIZZLE_A:
2962 if (context->getClientVersion() < 3)
2963 {
2964 return gl::error(GL_INVALID_ENUM);
2965 }
2966 *params = texture->getSamplerState().swizzleAlpha;
2967 break;
2968 case GL_TEXTURE_BASE_LEVEL:
2969 if (context->getClientVersion() < 3)
2970 {
2971 return gl::error(GL_INVALID_ENUM);
2972 }
2973 *params = texture->getSamplerState().baseLevel;
2974 break;
2975 case GL_TEXTURE_MAX_LEVEL:
2976 if (context->getClientVersion() < 3)
2977 {
2978 return gl::error(GL_INVALID_ENUM);
2979 }
2980 *params = texture->getSamplerState().maxLevel;
2981 break;
2982 case GL_TEXTURE_MIN_LOD:
2983 if (context->getClientVersion() < 3)
2984 {
2985 return gl::error(GL_INVALID_ENUM);
2986 }
2987 *params = (GLint)texture->getSamplerState().minLod;
2988 break;
2989 case GL_TEXTURE_MAX_LOD:
2990 if (context->getClientVersion() < 3)
2991 {
2992 return gl::error(GL_INVALID_ENUM);
2993 }
2994 *params = (GLint)texture->getSamplerState().maxLod;
2995 break;
2996 default:
2997 return gl::error(GL_INVALID_ENUM);
2998 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002999 }
3000}
3001
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003002void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3003{
3004 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3005 program, location, bufSize, params);
3006
Geoff Langbfdea662014-07-23 14:16:32 -04003007 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003008 {
Geoff Langbfdea662014-07-23 14:16:32 -04003009 return gl::error(GL_INVALID_VALUE);
3010 }
3011
3012 gl::Context *context = gl::getNonLostContext();
3013
3014 if (context)
3015 {
Jamie Madill0063c512014-08-25 15:47:53 -04003016 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003017 {
Jamie Madill0063c512014-08-25 15:47:53 -04003018 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003019 }
3020
Jamie Madill0063c512014-08-25 15:47:53 -04003021 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3022 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003023
Jamie Madill99a1e982014-08-25 15:47:54 -04003024 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003025 }
3026}
3027
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003028void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3029{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003030 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003031
Geoff Langbfdea662014-07-23 14:16:32 -04003032 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003033
Geoff Langbfdea662014-07-23 14:16:32 -04003034 if (context)
3035 {
Jamie Madill0063c512014-08-25 15:47:53 -04003036 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003037 {
Jamie Madill0063c512014-08-25 15:47:53 -04003038 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003039 }
Geoff Langbfdea662014-07-23 14:16:32 -04003040
Jamie Madill0063c512014-08-25 15:47:53 -04003041 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3042 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003043
Jamie Madill99a1e982014-08-25 15:47:54 -04003044 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003045 }
3046}
3047
3048void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3049{
Geoff Langbfdea662014-07-23 14:16:32 -04003050 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003051 program, location, bufSize, params);
3052
Geoff Langbfdea662014-07-23 14:16:32 -04003053 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003054 {
Geoff Langbfdea662014-07-23 14:16:32 -04003055 return gl::error(GL_INVALID_VALUE);
3056 }
3057
3058 gl::Context *context = gl::getNonLostContext();
3059
3060 if (context)
3061 {
Jamie Madill0063c512014-08-25 15:47:53 -04003062 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003063 {
Jamie Madill0063c512014-08-25 15:47:53 -04003064 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003065 }
3066
Jamie Madill0063c512014-08-25 15:47:53 -04003067 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3068 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003069
Jamie Madill99a1e982014-08-25 15:47:54 -04003070 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003071 }
3072}
3073
3074void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3075{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003076 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003077
Geoff Langbfdea662014-07-23 14:16:32 -04003078 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003079
Geoff Langbfdea662014-07-23 14:16:32 -04003080 if (context)
3081 {
Jamie Madill0063c512014-08-25 15:47:53 -04003082 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003083 {
Jamie Madill0063c512014-08-25 15:47:53 -04003084 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003085 }
Geoff Langbfdea662014-07-23 14:16:32 -04003086
Jamie Madill0063c512014-08-25 15:47:53 -04003087 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3088 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003089
Jamie Madill99a1e982014-08-25 15:47:54 -04003090 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003091 }
3092}
3093
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003094int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003095{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003096 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003097
Geoff Langbfdea662014-07-23 14:16:32 -04003098 gl::Context *context = gl::getNonLostContext();
3099
3100 if (strstr(name, "gl_") == name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003101 {
Geoff Langbfdea662014-07-23 14:16:32 -04003102 return -1;
3103 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003104
Geoff Langbfdea662014-07-23 14:16:32 -04003105 if (context)
3106 {
3107 gl::Program *programObject = context->getProgram(program);
3108
3109 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003110 {
Geoff Langbfdea662014-07-23 14:16:32 -04003111 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003112 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003113 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003114 }
Geoff Langbfdea662014-07-23 14:16:32 -04003115 else
3116 {
3117 return gl::error(GL_INVALID_VALUE, -1);
3118 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003119 }
Geoff Langbfdea662014-07-23 14:16:32 -04003120
3121 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3122 if (!programObject->isLinked() || !programBinary)
3123 {
3124 return gl::error(GL_INVALID_OPERATION, -1);
3125 }
3126
3127 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003128 }
3129
3130 return -1;
3131}
3132
3133void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3134{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003135 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003136
Geoff Langbfdea662014-07-23 14:16:32 -04003137 gl::Context *context = gl::getNonLostContext();
3138
3139 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003140 {
Geoff Langbfdea662014-07-23 14:16:32 -04003141 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003142 {
Geoff Langbfdea662014-07-23 14:16:32 -04003143 return gl::error(GL_INVALID_VALUE);
3144 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003145
Geoff Langbfdea662014-07-23 14:16:32 -04003146 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
3147 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3148 {
3149 return;
3150 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003151
Geoff Langbfdea662014-07-23 14:16:32 -04003152 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3153 {
3154 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3155 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003156 {
Geoff Langbfdea662014-07-23 14:16:32 -04003157 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003158 }
3159 }
Geoff Langbfdea662014-07-23 14:16:32 -04003160 else
3161 {
3162 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3163 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003164 }
3165}
3166
3167void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3168{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003169 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003170
Geoff Langbfdea662014-07-23 14:16:32 -04003171 gl::Context *context = gl::getNonLostContext();
3172
3173 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003174 {
Geoff Langbfdea662014-07-23 14:16:32 -04003175 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003176 {
Geoff Langbfdea662014-07-23 14:16:32 -04003177 return gl::error(GL_INVALID_VALUE);
3178 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003179
Geoff Langbfdea662014-07-23 14:16:32 -04003180 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003181
Geoff Langbfdea662014-07-23 14:16:32 -04003182 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3183 {
3184 return;
3185 }
Jamie Madillaff71502013-07-02 11:57:05 -04003186
Geoff Langbfdea662014-07-23 14:16:32 -04003187 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3188 {
3189 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3190 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003191 {
Geoff Langbfdea662014-07-23 14:16:32 -04003192 float currentValue = currentValueData.FloatValues[i];
3193 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003194 }
3195 }
Geoff Langbfdea662014-07-23 14:16:32 -04003196 else
3197 {
3198 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3199 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003200 }
3201}
3202
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003203void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003204{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003205 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003206
Geoff Langbfdea662014-07-23 14:16:32 -04003207 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208
Geoff Langbfdea662014-07-23 14:16:32 -04003209 if (context)
3210 {
3211 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003212 {
Geoff Langbfdea662014-07-23 14:16:32 -04003213 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003214 }
Geoff Langbfdea662014-07-23 14:16:32 -04003215
3216 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3217 {
3218 return gl::error(GL_INVALID_ENUM);
3219 }
3220
3221 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003222 }
3223}
3224
3225void __stdcall glHint(GLenum target, GLenum mode)
3226{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003227 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003228
Geoff Langbfdea662014-07-23 14:16:32 -04003229 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003230 {
Geoff Langbfdea662014-07-23 14:16:32 -04003231 case GL_FASTEST:
3232 case GL_NICEST:
3233 case GL_DONT_CARE:
3234 break;
3235 default:
3236 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003237 }
Geoff Langbfdea662014-07-23 14:16:32 -04003238
3239 gl::Context *context = gl::getNonLostContext();
3240 switch (target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003241 {
Geoff Langbfdea662014-07-23 14:16:32 -04003242 case GL_GENERATE_MIPMAP_HINT:
3243 if (context) context->getState().setGenerateMipmapHint(mode);
3244 break;
3245 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3246 if (context) context->getState().setFragmentShaderDerivativeHint(mode);
3247 break;
3248 default:
3249 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003250 }
3251}
3252
3253GLboolean __stdcall glIsBuffer(GLuint buffer)
3254{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003255 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003256
Geoff Langbfdea662014-07-23 14:16:32 -04003257 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003258
Geoff Langbfdea662014-07-23 14:16:32 -04003259 if (context && buffer)
3260 {
3261 gl::Buffer *bufferObject = context->getBuffer(buffer);
3262
3263 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003264 {
Geoff Langbfdea662014-07-23 14:16:32 -04003265 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003266 }
3267 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268
3269 return GL_FALSE;
3270}
3271
3272GLboolean __stdcall glIsEnabled(GLenum cap)
3273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003274 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003275
Geoff Langbfdea662014-07-23 14:16:32 -04003276 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003277
Geoff Langbfdea662014-07-23 14:16:32 -04003278 if (context)
3279 {
3280 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003281 {
Geoff Langbfdea662014-07-23 14:16:32 -04003282 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003283 }
Geoff Langbfdea662014-07-23 14:16:32 -04003284
3285 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003286 }
3287
3288 return false;
3289}
3290
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003291GLboolean __stdcall glIsFenceNV(GLuint fence)
3292{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003293 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003294
Geoff Langbfdea662014-07-23 14:16:32 -04003295 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003296
Geoff Langbfdea662014-07-23 14:16:32 -04003297 if (context)
3298 {
3299 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3300
3301 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003302 {
Geoff Langbfdea662014-07-23 14:16:32 -04003303 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003304 }
Geoff Langbfdea662014-07-23 14:16:32 -04003305
3306 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003307 }
3308
3309 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003310}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003311
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003312GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3313{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003314 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003315
Geoff Langbfdea662014-07-23 14:16:32 -04003316 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003317
Geoff Langbfdea662014-07-23 14:16:32 -04003318 if (context && framebuffer)
3319 {
3320 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3321
3322 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003323 {
Geoff Langbfdea662014-07-23 14:16:32 -04003324 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325 }
3326 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003327
3328 return GL_FALSE;
3329}
3330
3331GLboolean __stdcall glIsProgram(GLuint program)
3332{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003333 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334
Geoff Langbfdea662014-07-23 14:16:32 -04003335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003336
Geoff Langbfdea662014-07-23 14:16:32 -04003337 if (context && program)
3338 {
3339 gl::Program *programObject = context->getProgram(program);
3340
3341 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003342 {
Geoff Langbfdea662014-07-23 14:16:32 -04003343 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003344 }
3345 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003346
3347 return GL_FALSE;
3348}
3349
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003350GLboolean __stdcall glIsQueryEXT(GLuint id)
3351{
3352 EVENT("(GLuint id = %d)", id);
3353
Geoff Langbfdea662014-07-23 14:16:32 -04003354 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003355
Geoff Langbfdea662014-07-23 14:16:32 -04003356 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003357 {
Geoff Langbfdea662014-07-23 14:16:32 -04003358 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003359 }
3360
3361 return GL_FALSE;
3362}
3363
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3365{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003366 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003367
Geoff Langbfdea662014-07-23 14:16:32 -04003368 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003369
Geoff Langbfdea662014-07-23 14:16:32 -04003370 if (context && renderbuffer)
3371 {
3372 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3373
3374 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003375 {
Geoff Langbfdea662014-07-23 14:16:32 -04003376 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003377 }
3378 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379
3380 return GL_FALSE;
3381}
3382
3383GLboolean __stdcall glIsShader(GLuint shader)
3384{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003385 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003386
Geoff Langbfdea662014-07-23 14:16:32 -04003387 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003388
Geoff Langbfdea662014-07-23 14:16:32 -04003389 if (context && shader)
3390 {
3391 gl::Shader *shaderObject = context->getShader(shader);
3392
3393 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003394 {
Geoff Langbfdea662014-07-23 14:16:32 -04003395 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003396 }
3397 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003398
3399 return GL_FALSE;
3400}
3401
3402GLboolean __stdcall glIsTexture(GLuint texture)
3403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003404 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003405
Geoff Langbfdea662014-07-23 14:16:32 -04003406 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003407
Geoff Langbfdea662014-07-23 14:16:32 -04003408 if (context && texture)
3409 {
3410 gl::Texture *textureObject = context->getTexture(texture);
3411
3412 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003413 {
Geoff Langbfdea662014-07-23 14:16:32 -04003414 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415 }
3416 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003417
3418 return GL_FALSE;
3419}
3420
3421void __stdcall glLineWidth(GLfloat width)
3422{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003423 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003424
Geoff Langbfdea662014-07-23 14:16:32 -04003425 if (width <= 0.0f)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003426 {
Geoff Langbfdea662014-07-23 14:16:32 -04003427 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428 }
Geoff Langbfdea662014-07-23 14:16:32 -04003429
3430 gl::Context *context = gl::getNonLostContext();
3431
3432 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003433 {
Geoff Langbfdea662014-07-23 14:16:32 -04003434 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003435 }
3436}
3437
3438void __stdcall glLinkProgram(GLuint program)
3439{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003440 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003441
Geoff Langbfdea662014-07-23 14:16:32 -04003442 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003443
Geoff Langbfdea662014-07-23 14:16:32 -04003444 if (context)
3445 {
3446 gl::Program *programObject = context->getProgram(program);
3447
3448 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449 {
Geoff Langbfdea662014-07-23 14:16:32 -04003450 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003451 {
Geoff Langbfdea662014-07-23 14:16:32 -04003452 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003453 }
Geoff Langbfdea662014-07-23 14:16:32 -04003454 else
3455 {
3456 return gl::error(GL_INVALID_VALUE);
3457 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003458 }
Geoff Langbfdea662014-07-23 14:16:32 -04003459
3460 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003461 }
3462}
3463
3464void __stdcall glPixelStorei(GLenum pname, GLint param)
3465{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003466 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003467
Geoff Langbfdea662014-07-23 14:16:32 -04003468 gl::Context *context = gl::getNonLostContext();
3469
3470 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003471 {
Geoff Langbfdea662014-07-23 14:16:32 -04003472 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003473 {
Geoff Langbfdea662014-07-23 14:16:32 -04003474 case GL_UNPACK_ALIGNMENT:
3475 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003476 {
Geoff Langbfdea662014-07-23 14:16:32 -04003477 return gl::error(GL_INVALID_VALUE);
3478 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003479
Geoff Langbfdea662014-07-23 14:16:32 -04003480 context->getState().setUnpackAlignment(param);
3481 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003482
Geoff Langbfdea662014-07-23 14:16:32 -04003483 case GL_PACK_ALIGNMENT:
3484 if (param != 1 && param != 2 && param != 4 && param != 8)
3485 {
3486 return gl::error(GL_INVALID_VALUE);
3487 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003488
Geoff Langbfdea662014-07-23 14:16:32 -04003489 context->getState().setPackAlignment(param);
3490 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003491
Geoff Langbfdea662014-07-23 14:16:32 -04003492 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3493 context->getState().setPackReverseRowOrder(param != 0);
3494 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003495
Geoff Langbfdea662014-07-23 14:16:32 -04003496 case GL_UNPACK_IMAGE_HEIGHT:
3497 case GL_UNPACK_SKIP_IMAGES:
3498 case GL_UNPACK_ROW_LENGTH:
3499 case GL_UNPACK_SKIP_ROWS:
3500 case GL_UNPACK_SKIP_PIXELS:
3501 case GL_PACK_ROW_LENGTH:
3502 case GL_PACK_SKIP_ROWS:
3503 case GL_PACK_SKIP_PIXELS:
3504 if (context->getClientVersion() < 3)
3505 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003506 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003507 }
Geoff Langbfdea662014-07-23 14:16:32 -04003508 UNIMPLEMENTED();
3509 break;
3510
3511 default:
3512 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003513 }
3514 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003515}
3516
3517void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3518{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003519 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003520
Geoff Langbfdea662014-07-23 14:16:32 -04003521 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00003522
Geoff Langbfdea662014-07-23 14:16:32 -04003523 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003524 {
Geoff Langbfdea662014-07-23 14:16:32 -04003525 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526 }
3527}
3528
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003529void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3530 GLenum format, GLenum type, GLsizei bufSize,
3531 GLvoid *data)
3532{
3533 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3534 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3535 x, y, width, height, format, type, bufSize, data);
3536
Geoff Langbfdea662014-07-23 14:16:32 -04003537 if (width < 0 || height < 0 || bufSize < 0)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003538 {
Geoff Langbfdea662014-07-23 14:16:32 -04003539 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003540 }
Geoff Langbfdea662014-07-23 14:16:32 -04003541
3542 gl::Context *context = gl::getNonLostContext();
3543
3544 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003545 {
Geoff Langbfdea662014-07-23 14:16:32 -04003546 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3547 format, type, &bufSize, data))
3548 {
3549 return;
3550 }
3551
3552 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003553 }
3554}
3555
3556void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3557 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003558{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003559 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003560 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003561 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003562
Geoff Langbfdea662014-07-23 14:16:32 -04003563 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003564 {
Geoff Langbfdea662014-07-23 14:16:32 -04003565 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003566 }
Geoff Langbfdea662014-07-23 14:16:32 -04003567
3568 gl::Context *context = gl::getNonLostContext();
3569
3570 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571 {
Geoff Langbfdea662014-07-23 14:16:32 -04003572 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3573 format, type, NULL, pixels))
3574 {
3575 return;
3576 }
3577
3578 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003579 }
3580}
3581
3582void __stdcall glReleaseShaderCompiler(void)
3583{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003584 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003585
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003586 gl::Context *context = gl::getNonLostContext();
3587
3588 if (context)
3589 {
3590 context->releaseShaderCompiler();
3591 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003592}
3593
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003594void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003596 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 +00003597 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598
Geoff Langbfdea662014-07-23 14:16:32 -04003599 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003600
Geoff Langbfdea662014-07-23 14:16:32 -04003601 if (context)
3602 {
3603 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3604 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003605 {
Geoff Langbfdea662014-07-23 14:16:32 -04003606 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003607 }
Geoff Langbfdea662014-07-23 14:16:32 -04003608
3609 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003610 }
3611}
3612
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003613void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3614{
3615 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3616}
3617
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3619{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003620 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003621
Geoff Langbfdea662014-07-23 14:16:32 -04003622 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003623
Geoff Langbfdea662014-07-23 14:16:32 -04003624 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003625 {
Geoff Langbfdea662014-07-23 14:16:32 -04003626 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003627 }
3628}
3629
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003630void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003632 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003633
Geoff Langbfdea662014-07-23 14:16:32 -04003634 if (condition != GL_ALL_COMPLETED_NV)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003635 {
Geoff Langbfdea662014-07-23 14:16:32 -04003636 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003637 }
Geoff Langbfdea662014-07-23 14:16:32 -04003638
3639 gl::Context *context = gl::getNonLostContext();
3640
3641 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003642 {
Geoff Langbfdea662014-07-23 14:16:32 -04003643 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3644
3645 if (fenceObject == NULL)
3646 {
3647 return gl::error(GL_INVALID_OPERATION);
3648 }
3649
3650 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003651 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003652}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003653
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003654void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003656 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 +00003657
Geoff Langbfdea662014-07-23 14:16:32 -04003658 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003659 {
Geoff Langbfdea662014-07-23 14:16:32 -04003660 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661 }
Geoff Langbfdea662014-07-23 14:16:32 -04003662
3663 gl::Context* context = gl::getNonLostContext();
3664
3665 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003666 {
Geoff Langbfdea662014-07-23 14:16:32 -04003667 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003668 }
3669}
3670
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003671void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003672{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003673 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003674 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003675 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003676
Geoff Lang900013c2014-07-07 11:32:19 -04003677 gl::Context* context = gl::getNonLostContext();
3678 if (context)
3679 {
3680 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3681 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3682 {
3683 return gl::error(GL_INVALID_ENUM);
3684 }
3685
3686 // No binary shader formats are supported.
3687 UNIMPLEMENTED();
3688 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003689}
3690
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003691void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003692{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003693 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 +00003694 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003695
Geoff Langbfdea662014-07-23 14:16:32 -04003696 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697 {
Geoff Langbfdea662014-07-23 14:16:32 -04003698 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003699 }
Geoff Langbfdea662014-07-23 14:16:32 -04003700
3701 gl::Context *context = gl::getNonLostContext();
3702
3703 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003704 {
Geoff Langbfdea662014-07-23 14:16:32 -04003705 gl::Shader *shaderObject = context->getShader(shader);
3706
3707 if (!shaderObject)
3708 {
3709 if (context->getProgram(shader))
3710 {
3711 return gl::error(GL_INVALID_OPERATION);
3712 }
3713 else
3714 {
3715 return gl::error(GL_INVALID_VALUE);
3716 }
3717 }
3718
3719 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003720 }
3721}
3722
3723void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3724{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003725 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003726}
3727
3728void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003730 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 +00003731
Geoff Langbfdea662014-07-23 14:16:32 -04003732 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733 {
Geoff Langbfdea662014-07-23 14:16:32 -04003734 case GL_FRONT:
3735 case GL_BACK:
3736 case GL_FRONT_AND_BACK:
3737 break;
3738 default:
3739 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003740 }
Geoff Langbfdea662014-07-23 14:16:32 -04003741
3742 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743 {
Geoff Langbfdea662014-07-23 14:16:32 -04003744 case GL_NEVER:
3745 case GL_ALWAYS:
3746 case GL_LESS:
3747 case GL_LEQUAL:
3748 case GL_EQUAL:
3749 case GL_GEQUAL:
3750 case GL_GREATER:
3751 case GL_NOTEQUAL:
3752 break;
3753 default:
3754 return gl::error(GL_INVALID_ENUM);
3755 }
3756
3757 gl::Context *context = gl::getNonLostContext();
3758
3759 if (context)
3760 {
3761 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3762 {
3763 context->getState().setStencilParams(func, ref, mask);
3764 }
3765
3766 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3767 {
3768 context->getState().setStencilBackParams(func, ref, mask);
3769 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003770 }
3771}
3772
3773void __stdcall glStencilMask(GLuint mask)
3774{
3775 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3776}
3777
3778void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003780 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003781
Geoff Langbfdea662014-07-23 14:16:32 -04003782 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003783 {
Geoff Langbfdea662014-07-23 14:16:32 -04003784 case GL_FRONT:
3785 case GL_BACK:
3786 case GL_FRONT_AND_BACK:
3787 break;
3788 default:
3789 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003790 }
Geoff Langbfdea662014-07-23 14:16:32 -04003791
3792 gl::Context *context = gl::getNonLostContext();
3793
3794 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003795 {
Geoff Langbfdea662014-07-23 14:16:32 -04003796 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3797 {
3798 context->getState().setStencilWritemask(mask);
3799 }
3800
3801 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3802 {
3803 context->getState().setStencilBackWritemask(mask);
3804 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003805 }
3806}
3807
3808void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3809{
3810 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3811}
3812
3813void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3814{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003815 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 +00003816 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003817
Geoff Langbfdea662014-07-23 14:16:32 -04003818 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003819 {
Geoff Langbfdea662014-07-23 14:16:32 -04003820 case GL_FRONT:
3821 case GL_BACK:
3822 case GL_FRONT_AND_BACK:
3823 break;
3824 default:
3825 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003826 }
Geoff Langbfdea662014-07-23 14:16:32 -04003827
3828 switch (fail)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003829 {
Geoff Langbfdea662014-07-23 14:16:32 -04003830 case GL_ZERO:
3831 case GL_KEEP:
3832 case GL_REPLACE:
3833 case GL_INCR:
3834 case GL_DECR:
3835 case GL_INVERT:
3836 case GL_INCR_WRAP:
3837 case GL_DECR_WRAP:
3838 break;
3839 default:
3840 return gl::error(GL_INVALID_ENUM);
3841 }
3842
3843 switch (zfail)
3844 {
3845 case GL_ZERO:
3846 case GL_KEEP:
3847 case GL_REPLACE:
3848 case GL_INCR:
3849 case GL_DECR:
3850 case GL_INVERT:
3851 case GL_INCR_WRAP:
3852 case GL_DECR_WRAP:
3853 break;
3854 default:
3855 return gl::error(GL_INVALID_ENUM);
3856 }
3857
3858 switch (zpass)
3859 {
3860 case GL_ZERO:
3861 case GL_KEEP:
3862 case GL_REPLACE:
3863 case GL_INCR:
3864 case GL_DECR:
3865 case GL_INVERT:
3866 case GL_INCR_WRAP:
3867 case GL_DECR_WRAP:
3868 break;
3869 default:
3870 return gl::error(GL_INVALID_ENUM);
3871 }
3872
3873 gl::Context *context = gl::getNonLostContext();
3874
3875 if (context)
3876 {
3877 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3878 {
3879 context->getState().setStencilOperations(fail, zfail, zpass);
3880 }
3881
3882 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3883 {
3884 context->getState().setStencilBackOperations(fail, zfail, zpass);
3885 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003886 }
3887}
3888
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003889GLboolean __stdcall glTestFenceNV(GLuint fence)
3890{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003891 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003892
Geoff Langbfdea662014-07-23 14:16:32 -04003893 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003894
Geoff Langbfdea662014-07-23 14:16:32 -04003895 if (context)
3896 {
3897 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3898
3899 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003900 {
Geoff Langbfdea662014-07-23 14:16:32 -04003901 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003902 }
Geoff Langbfdea662014-07-23 14:16:32 -04003903
3904 if (fenceObject->isFence() != GL_TRUE)
3905 {
3906 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
3907 }
3908
3909 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003910 }
Geoff Langbfdea662014-07-23 14:16:32 -04003911
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003912 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003913}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003914
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003915void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
3916 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003918 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05003919 "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 +00003920 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003921
Geoff Langbfdea662014-07-23 14:16:32 -04003922 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003923
Geoff Langbfdea662014-07-23 14:16:32 -04003924 if (context)
3925 {
3926 if (context->getClientVersion() < 3 &&
3927 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
3928 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003929 {
Geoff Langbfdea662014-07-23 14:16:32 -04003930 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003931 }
Geoff Langbfdea662014-07-23 14:16:32 -04003932
3933 if (context->getClientVersion() >= 3 &&
3934 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
3935 0, 0, 0, width, height, 1, border, format, type, pixels))
3936 {
3937 return;
3938 }
3939
3940 switch (target)
3941 {
3942 case GL_TEXTURE_2D:
3943 {
3944 gl::Texture2D *texture = context->getTexture2D();
3945 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3946 }
3947 break;
3948 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3949 {
3950 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3951 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3952 }
3953 break;
3954 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3955 {
3956 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3957 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3958 }
3959 break;
3960 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3961 {
3962 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3963 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3964 }
3965 break;
3966 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3967 {
3968 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3969 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3970 }
3971 break;
3972 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3973 {
3974 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3975 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3976 }
3977 break;
3978 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
3979 {
3980 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3981 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3982 }
3983 break;
3984 default: UNREACHABLE();
3985 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003986 }
3987}
3988
3989void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
3990{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003991 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
3992
Geoff Langbfdea662014-07-23 14:16:32 -04003993 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003994
Geoff Langbfdea662014-07-23 14:16:32 -04003995 if (context)
3996 {
3997 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003998 {
Geoff Langbfdea662014-07-23 14:16:32 -04003999 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004000 }
Geoff Langbfdea662014-07-23 14:16:32 -04004001
4002 gl::Texture *texture = context->getTargetTexture(target);
4003
4004 if (!texture)
4005 {
4006 return gl::error(GL_INVALID_ENUM);
4007 }
4008
4009 switch (pname)
4010 {
4011 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4012 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4013 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4014 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4015 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4016 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4017 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4018 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4019 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4020 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4021 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4022 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4023 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4024 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4025 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4026 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4027 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4028 default: UNREACHABLE(); break;
4029 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004030 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004031}
4032
4033void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4034{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004035 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004036}
4037
4038void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004040 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004041
Geoff Langbfdea662014-07-23 14:16:32 -04004042 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004043
Geoff Langbfdea662014-07-23 14:16:32 -04004044 if (context)
4045 {
4046 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004047 {
Geoff Langbfdea662014-07-23 14:16:32 -04004048 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004049 }
Geoff Langbfdea662014-07-23 14:16:32 -04004050
4051 gl::Texture *texture = context->getTargetTexture(target);
4052
4053 if (!texture)
4054 {
4055 return gl::error(GL_INVALID_ENUM);
4056 }
4057
4058 switch (pname)
4059 {
4060 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4061 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4062 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4063 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4064 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4065 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4066 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4067 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4068 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4069 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4070 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4071 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4072 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4073 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4074 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4075 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4076 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4077 default: UNREACHABLE(); break;
4078 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004079 }
4080}
4081
4082void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4083{
4084 glTexParameteri(target, pname, *params);
4085}
4086
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004087void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4088{
4089 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4090 target, levels, internalformat, width, height);
4091
Geoff Langbfdea662014-07-23 14:16:32 -04004092 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004093
Geoff Langbfdea662014-07-23 14:16:32 -04004094 if (context)
4095 {
4096 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004097 {
Geoff Langbfdea662014-07-23 14:16:32 -04004098 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004099 }
Geoff Langbfdea662014-07-23 14:16:32 -04004100
4101 if (context->getClientVersion() < 3 &&
4102 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4103 {
4104 return;
4105 }
4106
4107 if (context->getClientVersion() >= 3 &&
4108 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4109 {
4110 return;
4111 }
4112
4113 switch (target)
4114 {
4115 case GL_TEXTURE_2D:
4116 {
4117 gl::Texture2D *texture2d = context->getTexture2D();
4118 texture2d->storage(levels, internalformat, width, height);
4119 }
4120 break;
4121
4122 case GL_TEXTURE_CUBE_MAP:
4123 {
4124 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4125 textureCube->storage(levels, internalformat, width);
4126 }
4127 break;
4128
4129 default:
4130 return gl::error(GL_INVALID_ENUM);
4131 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004132 }
4133}
4134
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004135void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4136 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004137{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004138 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004139 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004140 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004141 target, level, xoffset, yoffset, width, height, format, type, pixels);
4142
Geoff Langbfdea662014-07-23 14:16:32 -04004143 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004144
Geoff Langbfdea662014-07-23 14:16:32 -04004145 if (context)
4146 {
4147 if (context->getClientVersion() < 3 &&
4148 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4149 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004150 {
Geoff Langbfdea662014-07-23 14:16:32 -04004151 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004152 }
Geoff Langbfdea662014-07-23 14:16:32 -04004153
4154 if (context->getClientVersion() >= 3 &&
4155 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4156 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4157 {
4158 return;
4159 }
4160
4161 // Zero sized uploads are valid but no-ops
4162 if (width == 0 || height == 0)
4163 {
4164 return;
4165 }
4166
4167 switch (target)
4168 {
4169 case GL_TEXTURE_2D:
4170 {
4171 gl::Texture2D *texture = context->getTexture2D();
4172 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4173 }
4174 break;
4175
4176 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4177 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4178 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4179 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4180 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4181 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4182 {
4183 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4184 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4185 }
4186 break;
4187
4188 default:
4189 UNREACHABLE();
4190 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004191 }
4192}
4193
4194void __stdcall glUniform1f(GLint location, GLfloat x)
4195{
4196 glUniform1fv(location, 1, &x);
4197}
4198
4199void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4200{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004201 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004202
Geoff Langbfdea662014-07-23 14:16:32 -04004203 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004204
Geoff Langbfdea662014-07-23 14:16:32 -04004205 if (context)
4206 {
4207 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004208 {
Geoff Langbfdea662014-07-23 14:16:32 -04004209 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004210 }
Geoff Langbfdea662014-07-23 14:16:32 -04004211
4212 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4213 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004214 }
4215}
4216
4217void __stdcall glUniform1i(GLint location, GLint x)
4218{
4219 glUniform1iv(location, 1, &x);
4220}
4221
4222void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4223{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004224 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004225
Geoff Langbfdea662014-07-23 14:16:32 -04004226 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004227
Geoff Langbfdea662014-07-23 14:16:32 -04004228 if (context)
4229 {
4230 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004231 {
Geoff Langbfdea662014-07-23 14:16:32 -04004232 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004233 }
Geoff Langbfdea662014-07-23 14:16:32 -04004234
4235 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4236 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004237 }
4238}
4239
4240void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4241{
4242 GLfloat xy[2] = {x, y};
4243
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004244 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004245}
4246
4247void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4248{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004249 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004250
Geoff Langbfdea662014-07-23 14:16:32 -04004251 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004252
Geoff Langbfdea662014-07-23 14:16:32 -04004253 if (context)
4254 {
4255 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004256 {
Geoff Langbfdea662014-07-23 14:16:32 -04004257 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
Geoff Langbfdea662014-07-23 14:16:32 -04004259
4260 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4261 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004262 }
4263}
4264
4265void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4266{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004267 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004268
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004269 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004270}
4271
4272void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004274 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004275
Geoff Langbfdea662014-07-23 14:16:32 -04004276 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004277
Geoff Langbfdea662014-07-23 14:16:32 -04004278 if (context)
4279 {
4280 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004281 {
Geoff Langbfdea662014-07-23 14:16:32 -04004282 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004283 }
Geoff Langbfdea662014-07-23 14:16:32 -04004284
4285 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4286 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004287 }
4288}
4289
4290void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4291{
4292 GLfloat xyz[3] = {x, y, z};
4293
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004294 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004295}
4296
4297void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004299 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004300
Geoff Langbfdea662014-07-23 14:16:32 -04004301 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004302
Geoff Langbfdea662014-07-23 14:16:32 -04004303 if (context)
4304 {
4305 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004306 {
Geoff Langbfdea662014-07-23 14:16:32 -04004307 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004308 }
Geoff Langbfdea662014-07-23 14:16:32 -04004309
4310 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4311 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004312 }
4313}
4314
4315void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4316{
4317 GLint xyz[3] = {x, y, z};
4318
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004319 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004320}
4321
4322void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4323{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004324 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004325
Geoff Langbfdea662014-07-23 14:16:32 -04004326 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004327
Geoff Langbfdea662014-07-23 14:16:32 -04004328 if (context)
4329 {
4330 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004331 {
Geoff Langbfdea662014-07-23 14:16:32 -04004332 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004333 }
Geoff Langbfdea662014-07-23 14:16:32 -04004334
4335 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4336 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004337 }
4338}
4339
4340void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4341{
4342 GLfloat xyzw[4] = {x, y, z, w};
4343
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004344 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345}
4346
4347void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4348{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004349 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004350
Geoff Langbfdea662014-07-23 14:16:32 -04004351 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004352
Geoff Langbfdea662014-07-23 14:16:32 -04004353 if (context)
4354 {
4355 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004356 {
Geoff Langbfdea662014-07-23 14:16:32 -04004357 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004358 }
Geoff Langbfdea662014-07-23 14:16:32 -04004359
4360 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4361 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004362 }
4363}
4364
4365void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4366{
4367 GLint xyzw[4] = {x, y, z, w};
4368
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004369 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004370}
4371
4372void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4373{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004374 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004375
Geoff Langbfdea662014-07-23 14:16:32 -04004376 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004377
Geoff Langbfdea662014-07-23 14:16:32 -04004378 if (context)
4379 {
4380 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004381 {
Geoff Langbfdea662014-07-23 14:16:32 -04004382 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004383 }
Geoff Langbfdea662014-07-23 14:16:32 -04004384
4385 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4386 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004387 }
4388}
4389
4390void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4391{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004392 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004393 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004394
Geoff Langbfdea662014-07-23 14:16:32 -04004395 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004396
Geoff Langbfdea662014-07-23 14:16:32 -04004397 if (context)
4398 {
4399 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004400 {
Geoff Langbfdea662014-07-23 14:16:32 -04004401 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004402 }
Geoff Langbfdea662014-07-23 14:16:32 -04004403
4404 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4405 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004406 }
4407}
4408
4409void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4410{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004411 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004412 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004413
Geoff Langbfdea662014-07-23 14:16:32 -04004414 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004415
Geoff Langbfdea662014-07-23 14:16:32 -04004416 if (context)
4417 {
4418 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004419 {
Geoff Langbfdea662014-07-23 14:16:32 -04004420 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004421 }
Geoff Langbfdea662014-07-23 14:16:32 -04004422
4423 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4424 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004425 }
4426}
4427
4428void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4429{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004430 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004431 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004432
Geoff Langbfdea662014-07-23 14:16:32 -04004433 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004434
Geoff Langbfdea662014-07-23 14:16:32 -04004435 if (context)
4436 {
4437 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438 {
Geoff Langbfdea662014-07-23 14:16:32 -04004439 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004440 }
Geoff Langbfdea662014-07-23 14:16:32 -04004441
4442 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4443 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004444 }
4445}
4446
4447void __stdcall glUseProgram(GLuint program)
4448{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004449 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450
Geoff Langbfdea662014-07-23 14:16:32 -04004451 gl::Context *context = gl::getNonLostContext();
4452
4453 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454 {
Geoff Langbfdea662014-07-23 14:16:32 -04004455 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004456
Geoff Langbfdea662014-07-23 14:16:32 -04004457 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004458 {
Geoff Langbfdea662014-07-23 14:16:32 -04004459 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004461 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004462 }
Geoff Langbfdea662014-07-23 14:16:32 -04004463 else
4464 {
4465 return gl::error(GL_INVALID_VALUE);
4466 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004467 }
Geoff Langbfdea662014-07-23 14:16:32 -04004468
4469 if (program != 0 && !programObject->isLinked())
4470 {
4471 return gl::error(GL_INVALID_OPERATION);
4472 }
4473
4474 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004475 }
4476}
4477
4478void __stdcall glValidateProgram(GLuint program)
4479{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004480 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004481
Geoff Langbfdea662014-07-23 14:16:32 -04004482 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004483
Geoff Langbfdea662014-07-23 14:16:32 -04004484 if (context)
4485 {
4486 gl::Program *programObject = context->getProgram(program);
4487
4488 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004489 {
Geoff Langbfdea662014-07-23 14:16:32 -04004490 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004491 {
Geoff Langbfdea662014-07-23 14:16:32 -04004492 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004493 }
Geoff Langbfdea662014-07-23 14:16:32 -04004494 else
4495 {
4496 return gl::error(GL_INVALID_VALUE);
4497 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004498 }
Geoff Langbfdea662014-07-23 14:16:32 -04004499
4500 programObject->validate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004501 }
4502}
4503
4504void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004506 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004507
Geoff Langbfdea662014-07-23 14:16:32 -04004508 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004509 {
Geoff Langbfdea662014-07-23 14:16:32 -04004510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004511 }
Geoff Langbfdea662014-07-23 14:16:32 -04004512
4513 gl::Context *context = gl::getNonLostContext();
4514
4515 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004516 {
Geoff Langbfdea662014-07-23 14:16:32 -04004517 GLfloat vals[4] = { x, 0, 0, 1 };
4518 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004519 }
4520}
4521
4522void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004524 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004525
Geoff Langbfdea662014-07-23 14:16:32 -04004526 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004527 {
Geoff Langbfdea662014-07-23 14:16:32 -04004528 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004529 }
Geoff Langbfdea662014-07-23 14:16:32 -04004530
4531 gl::Context *context = gl::getNonLostContext();
4532
4533 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004534 {
Geoff Langbfdea662014-07-23 14:16:32 -04004535 GLfloat vals[4] = { values[0], 0, 0, 1 };
4536 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004537 }
4538}
4539
4540void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4541{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004542 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543
Geoff Langbfdea662014-07-23 14:16:32 -04004544 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004545 {
Geoff Langbfdea662014-07-23 14:16:32 -04004546 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004547 }
Geoff Langbfdea662014-07-23 14:16:32 -04004548
4549 gl::Context *context = gl::getNonLostContext();
4550
4551 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004552 {
Geoff Langbfdea662014-07-23 14:16:32 -04004553 GLfloat vals[4] = { x, y, 0, 1 };
4554 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555 }
4556}
4557
4558void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004560 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004561
Geoff Langbfdea662014-07-23 14:16:32 -04004562 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004563 {
Geoff Langbfdea662014-07-23 14:16:32 -04004564 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004565 }
Geoff Langbfdea662014-07-23 14:16:32 -04004566
4567 gl::Context *context = gl::getNonLostContext();
4568
4569 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570 {
Geoff Langbfdea662014-07-23 14:16:32 -04004571 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4572 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573 }
4574}
4575
4576void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4577{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004578 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 +00004579
Geoff Langbfdea662014-07-23 14:16:32 -04004580 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004581 {
Geoff Langbfdea662014-07-23 14:16:32 -04004582 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004583 }
Geoff Langbfdea662014-07-23 14:16:32 -04004584
4585 gl::Context *context = gl::getNonLostContext();
4586
4587 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004588 {
Geoff Langbfdea662014-07-23 14:16:32 -04004589 GLfloat vals[4] = { x, y, z, 1 };
4590 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004591 }
4592}
4593
4594void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004596 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004597
Geoff Langbfdea662014-07-23 14:16:32 -04004598 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004599 {
Geoff Langbfdea662014-07-23 14:16:32 -04004600 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004601 }
Geoff Langbfdea662014-07-23 14:16:32 -04004602
4603 gl::Context *context = gl::getNonLostContext();
4604
4605 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004606 {
Geoff Langbfdea662014-07-23 14:16:32 -04004607 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4608 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609 }
4610}
4611
4612void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4613{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004614 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 +00004615
Geoff Langbfdea662014-07-23 14:16:32 -04004616 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004617 {
Geoff Langbfdea662014-07-23 14:16:32 -04004618 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619 }
Geoff Langbfdea662014-07-23 14:16:32 -04004620
4621 gl::Context *context = gl::getNonLostContext();
4622
4623 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004624 {
Geoff Langbfdea662014-07-23 14:16:32 -04004625 GLfloat vals[4] = { x, y, z, w };
4626 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 }
4628}
4629
4630void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004632 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004633
Geoff Langbfdea662014-07-23 14:16:32 -04004634 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004635 {
Geoff Langbfdea662014-07-23 14:16:32 -04004636 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004637 }
Geoff Langbfdea662014-07-23 14:16:32 -04004638
4639 gl::Context *context = gl::getNonLostContext();
4640
4641 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642 {
Geoff Langbfdea662014-07-23 14:16:32 -04004643 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004644 }
4645}
4646
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004647void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4648{
4649 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4650
Geoff Langbfdea662014-07-23 14:16:32 -04004651 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004652 {
Geoff Langbfdea662014-07-23 14:16:32 -04004653 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004654 }
Geoff Langbfdea662014-07-23 14:16:32 -04004655
4656 gl::Context *context = gl::getNonLostContext();
4657
4658 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004659 {
Geoff Langbfdea662014-07-23 14:16:32 -04004660 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004661 }
4662}
4663
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004664void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004665{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004666 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004667 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004668 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004669
Geoff Langbfdea662014-07-23 14:16:32 -04004670 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004671 {
Geoff Langbfdea662014-07-23 14:16:32 -04004672 return gl::error(GL_INVALID_VALUE);
4673 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004674
Geoff Langbfdea662014-07-23 14:16:32 -04004675 if (size < 1 || size > 4)
4676 {
4677 return gl::error(GL_INVALID_VALUE);
4678 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004679
Geoff Langbfdea662014-07-23 14:16:32 -04004680 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00004681
Geoff Langbfdea662014-07-23 14:16:32 -04004682 switch (type)
4683 {
4684 case GL_BYTE:
4685 case GL_UNSIGNED_BYTE:
4686 case GL_SHORT:
4687 case GL_UNSIGNED_SHORT:
4688 case GL_FIXED:
4689 case GL_FLOAT:
4690 break;
4691 case GL_HALF_FLOAT:
4692 case GL_INT:
4693 case GL_UNSIGNED_INT:
4694 case GL_INT_2_10_10_10_REV:
4695 case GL_UNSIGNED_INT_2_10_10_10_REV:
4696 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004698 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004699 }
Geoff Langbfdea662014-07-23 14:16:32 -04004700 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004701 {
Geoff Langbfdea662014-07-23 14:16:32 -04004702 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004703 }
Geoff Langbfdea662014-07-23 14:16:32 -04004704 default:
4705 return gl::error(GL_INVALID_ENUM);
4706 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004707
Geoff Langbfdea662014-07-23 14:16:32 -04004708 if (stride < 0)
4709 {
4710 return gl::error(GL_INVALID_VALUE);
4711 }
4712
4713 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4714 {
4715 return gl::error(GL_INVALID_OPERATION);
4716 }
4717
4718 if (context)
4719 {
4720 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4721 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4722 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4723 // and the pointer argument is not NULL.
4724 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004725 {
4726 return gl::error(GL_INVALID_OPERATION);
4727 }
4728
Geoff Langbfdea662014-07-23 14:16:32 -04004729 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4730 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004731 }
4732}
4733
4734void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4735{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004736 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 +00004737
Geoff Langbfdea662014-07-23 14:16:32 -04004738 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004739 {
Geoff Langbfdea662014-07-23 14:16:32 -04004740 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004741 }
Geoff Langbfdea662014-07-23 14:16:32 -04004742
4743 gl::Context *context = gl::getNonLostContext();
4744
4745 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004746 {
Geoff Langbfdea662014-07-23 14:16:32 -04004747 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004748 }
4749}
4750
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004751// OpenGL ES 3.0 functions
4752
4753void __stdcall glReadBuffer(GLenum mode)
4754{
4755 EVENT("(GLenum mode = 0x%X)", mode);
4756
Geoff Langbfdea662014-07-23 14:16:32 -04004757 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004758
Geoff Langbfdea662014-07-23 14:16:32 -04004759 if (context)
4760 {
4761 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004762 {
Geoff Langbfdea662014-07-23 14:16:32 -04004763 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004764 }
Geoff Langbfdea662014-07-23 14:16:32 -04004765
4766 // glReadBuffer
4767 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004768 }
4769}
4770
4771void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4772{
4773 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4774 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4775
Geoff Langbfdea662014-07-23 14:16:32 -04004776 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004777
Geoff Langbfdea662014-07-23 14:16:32 -04004778 if (context)
4779 {
4780 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004781 {
Geoff Langbfdea662014-07-23 14:16:32 -04004782 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004783 }
Geoff Langbfdea662014-07-23 14:16:32 -04004784
4785 // glDrawRangeElements
4786 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004787 }
4788}
4789
4790void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4791{
4792 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4793 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4794 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4795 target, level, internalformat, width, height, depth, border, format, type, pixels);
4796
Geoff Langbfdea662014-07-23 14:16:32 -04004797 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004798
Geoff Langbfdea662014-07-23 14:16:32 -04004799 if (context)
4800 {
4801 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004802 {
Geoff Langbfdea662014-07-23 14:16:32 -04004803 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004804 }
Geoff Langbfdea662014-07-23 14:16:32 -04004805
4806 // validateES3TexImageFormat sets the error code if there is an error
4807 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4808 0, 0, 0, width, height, depth, border, format, type, pixels))
4809 {
4810 return;
4811 }
4812
4813 switch(target)
4814 {
4815 case GL_TEXTURE_3D:
4816 {
4817 gl::Texture3D *texture = context->getTexture3D();
4818 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4819 }
4820 break;
4821
4822 case GL_TEXTURE_2D_ARRAY:
4823 {
4824 gl::Texture2DArray *texture = context->getTexture2DArray();
4825 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4826 }
4827 break;
4828
4829 default:
4830 return gl::error(GL_INVALID_ENUM);
4831 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004832 }
4833}
4834
4835void __stdcall glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels)
4836{
4837 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4838 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4839 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4840 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4841
Geoff Langbfdea662014-07-23 14:16:32 -04004842 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004843
Geoff Langbfdea662014-07-23 14:16:32 -04004844 if (context)
4845 {
4846 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004847 {
Geoff Langbfdea662014-07-23 14:16:32 -04004848 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004849 }
Geoff Langbfdea662014-07-23 14:16:32 -04004850
4851 // validateES3TexImageFormat sets the error code if there is an error
4852 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4853 xoffset, yoffset, zoffset, width, height, depth, 0,
4854 format, type, pixels))
4855 {
4856 return;
4857 }
4858
4859 // Zero sized uploads are valid but no-ops
4860 if (width == 0 || height == 0 || depth == 0)
4861 {
4862 return;
4863 }
4864
4865 switch(target)
4866 {
4867 case GL_TEXTURE_3D:
4868 {
4869 gl::Texture3D *texture = context->getTexture3D();
4870 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4871 }
4872 break;
4873
4874 case GL_TEXTURE_2D_ARRAY:
4875 {
4876 gl::Texture2DArray *texture = context->getTexture2DArray();
4877 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4878 }
4879 break;
4880
4881 default:
4882 return gl::error(GL_INVALID_ENUM);
4883 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004884 }
4885}
4886
4887void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
4888{
4889 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4890 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
4891 target, level, xoffset, yoffset, zoffset, x, y, width, height);
4892
Geoff Langbfdea662014-07-23 14:16:32 -04004893 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004894
Geoff Langbfdea662014-07-23 14:16:32 -04004895 if (context)
4896 {
4897 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004898 {
Geoff Langbfdea662014-07-23 14:16:32 -04004899 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004900 }
Geoff Langbfdea662014-07-23 14:16:32 -04004901
4902 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
4903 x, y, width, height, 0))
4904 {
4905 return;
4906 }
4907
4908 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
4909 gl::Texture *texture = NULL;
4910 switch (target)
4911 {
4912 case GL_TEXTURE_3D:
4913 texture = context->getTexture3D();
4914 break;
4915
4916 case GL_TEXTURE_2D_ARRAY:
4917 texture = context->getTexture2DArray();
4918 break;
4919
4920 default:
4921 return gl::error(GL_INVALID_ENUM);
4922 }
4923
4924 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004925 }
4926}
4927
4928void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
4929{
Geoff Langeef52cc2013-10-16 15:07:39 -04004930 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 +00004931 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
4932 "const GLvoid* data = 0x%0.8p)",
4933 target, level, internalformat, width, height, depth, border, imageSize, data);
4934
Geoff Langbfdea662014-07-23 14:16:32 -04004935 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004936
Geoff Langbfdea662014-07-23 14:16:32 -04004937 if (context)
4938 {
4939 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004940 {
Geoff Langbfdea662014-07-23 14:16:32 -04004941 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004942 }
Geoff Langbfdea662014-07-23 14:16:32 -04004943
Geoff Lang5d601382014-07-22 15:14:06 -04004944 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
4945 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04004946 {
4947 return gl::error(GL_INVALID_VALUE);
4948 }
4949
4950 // validateES3TexImageFormat sets the error code if there is an error
4951 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
4952 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
4953 {
4954 return;
4955 }
4956
4957 switch(target)
4958 {
4959 case GL_TEXTURE_3D:
4960 {
4961 gl::Texture3D *texture = context->getTexture3D();
4962 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
4963 }
4964 break;
4965
4966 case GL_TEXTURE_2D_ARRAY:
4967 {
4968 gl::Texture2DArray *texture = context->getTexture2DArray();
4969 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
4970 }
4971 break;
4972
4973 default:
4974 return gl::error(GL_INVALID_ENUM);
4975 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004976 }
4977}
4978
4979void __stdcall glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
4980{
4981 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4982 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4983 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
4984 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
4985
Geoff Langbfdea662014-07-23 14:16:32 -04004986 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004987
Geoff Langbfdea662014-07-23 14:16:32 -04004988 if (context)
4989 {
4990 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004991 {
Geoff Langbfdea662014-07-23 14:16:32 -04004992 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004993 }
Geoff Langbfdea662014-07-23 14:16:32 -04004994
Geoff Lang5d601382014-07-22 15:14:06 -04004995 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
4996 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04004997 {
4998 return gl::error(GL_INVALID_VALUE);
4999 }
5000
5001 if (!data)
5002 {
5003 return gl::error(GL_INVALID_VALUE);
5004 }
5005
5006 // validateES3TexImageFormat sets the error code if there is an error
5007 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5008 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5009 {
5010 return;
5011 }
5012
5013 // Zero sized uploads are valid but no-ops
5014 if (width == 0 || height == 0)
5015 {
5016 return;
5017 }
5018
5019 switch(target)
5020 {
5021 case GL_TEXTURE_3D:
5022 {
5023 gl::Texture3D *texture = context->getTexture3D();
5024 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5025 format, imageSize, data);
5026 }
5027 break;
5028
5029 case GL_TEXTURE_2D_ARRAY:
5030 {
5031 gl::Texture2DArray *texture = context->getTexture2DArray();
5032 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5033 format, imageSize, data);
5034 }
5035 break;
5036
5037 default:
5038 return gl::error(GL_INVALID_ENUM);
5039 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005040 }
5041}
5042
5043void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5044{
5045 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5046
Geoff Langbfdea662014-07-23 14:16:32 -04005047 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005048
Geoff Langbfdea662014-07-23 14:16:32 -04005049 if (context)
5050 {
5051 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005052 {
Geoff Langbfdea662014-07-23 14:16:32 -04005053 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005054 }
Geoff Langbfdea662014-07-23 14:16:32 -04005055
5056 if (n < 0)
5057 {
5058 return gl::error(GL_INVALID_VALUE);
5059 }
5060
5061 for (GLsizei i = 0; i < n; i++)
5062 {
5063 ids[i] = context->createQuery();
5064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005065 }
5066}
5067
5068void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5069{
5070 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5071
Geoff Langbfdea662014-07-23 14:16:32 -04005072 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005073
Geoff Langbfdea662014-07-23 14:16:32 -04005074 if (context)
5075 {
5076 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005077 {
Geoff Langbfdea662014-07-23 14:16:32 -04005078 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005079 }
Geoff Langbfdea662014-07-23 14:16:32 -04005080
5081 if (n < 0)
5082 {
5083 return gl::error(GL_INVALID_VALUE);
5084 }
5085
5086 for (GLsizei i = 0; i < n; i++)
5087 {
5088 context->deleteQuery(ids[i]);
5089 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005090 }
5091}
5092
5093GLboolean __stdcall glIsQuery(GLuint id)
5094{
5095 EVENT("(GLuint id = %u)", id);
5096
Geoff Langbfdea662014-07-23 14:16:32 -04005097 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005098
Geoff Langbfdea662014-07-23 14:16:32 -04005099 if (context)
5100 {
5101 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005102 {
Geoff Langbfdea662014-07-23 14:16:32 -04005103 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005104 }
Geoff Langbfdea662014-07-23 14:16:32 -04005105
5106 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005107 }
5108
5109 return GL_FALSE;
5110}
5111
5112void __stdcall glBeginQuery(GLenum target, GLuint id)
5113{
5114 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5115
Geoff Langbfdea662014-07-23 14:16:32 -04005116 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005117
Geoff Langbfdea662014-07-23 14:16:32 -04005118 if (context)
5119 {
5120 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005121 {
Geoff Langbfdea662014-07-23 14:16:32 -04005122 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005123 }
Geoff Langbfdea662014-07-23 14:16:32 -04005124
5125 if (!ValidateBeginQuery(context, target, id))
5126 {
5127 return;
5128 }
5129 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005130 }
5131}
5132
5133void __stdcall glEndQuery(GLenum target)
5134{
5135 EVENT("(GLenum target = 0x%X)", target);
5136
Geoff Langbfdea662014-07-23 14:16:32 -04005137 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005138
Geoff Langbfdea662014-07-23 14:16:32 -04005139 if (context)
5140 {
5141 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005142 {
Geoff Langbfdea662014-07-23 14:16:32 -04005143 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005144 }
Geoff Langbfdea662014-07-23 14:16:32 -04005145
5146 if (!ValidateEndQuery(context, target))
5147 {
5148 return;
5149 }
5150
5151 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005152 }
5153}
5154
5155void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5156{
5157 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5158
Geoff Langbfdea662014-07-23 14:16:32 -04005159 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005160
Geoff Langbfdea662014-07-23 14:16:32 -04005161 if (context)
5162 {
5163 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005164 {
Geoff Langbfdea662014-07-23 14:16:32 -04005165 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005166 }
Geoff Langbfdea662014-07-23 14:16:32 -04005167
5168 if (!ValidQueryType(context, target))
5169 {
5170 return gl::error(GL_INVALID_ENUM);
5171 }
5172
5173 switch (pname)
5174 {
5175 case GL_CURRENT_QUERY:
5176 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5177 break;
5178
5179 default:
5180 return gl::error(GL_INVALID_ENUM);
5181 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005182 }
5183}
5184
5185void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5186{
5187 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5188
Geoff Langbfdea662014-07-23 14:16:32 -04005189 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005190
Geoff Langbfdea662014-07-23 14:16:32 -04005191 if (context)
5192 {
5193 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005194 {
Geoff Langbfdea662014-07-23 14:16:32 -04005195 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005196 }
Geoff Langbfdea662014-07-23 14:16:32 -04005197
5198 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5199
5200 if (!queryObject)
5201 {
5202 return gl::error(GL_INVALID_OPERATION);
5203 }
5204
5205 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5206 {
5207 return gl::error(GL_INVALID_OPERATION);
5208 }
5209
5210 switch(pname)
5211 {
5212 case GL_QUERY_RESULT:
5213 params[0] = queryObject->getResult();
5214 break;
5215 case GL_QUERY_RESULT_AVAILABLE:
5216 params[0] = queryObject->isResultAvailable();
5217 break;
5218 default:
5219 return gl::error(GL_INVALID_ENUM);
5220 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005221 }
5222}
5223
5224GLboolean __stdcall glUnmapBuffer(GLenum target)
5225{
5226 EVENT("(GLenum target = 0x%X)", target);
5227
Geoff Langbfdea662014-07-23 14:16:32 -04005228 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005229
Geoff Langbfdea662014-07-23 14:16:32 -04005230 if (context)
5231 {
5232 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005233 {
Geoff Langbfdea662014-07-23 14:16:32 -04005234 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005235 }
Geoff Langbfdea662014-07-23 14:16:32 -04005236
5237 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005238 }
5239
5240 return GL_FALSE;
5241}
5242
5243void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5244{
5245 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5246
Geoff Langbfdea662014-07-23 14:16:32 -04005247 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005248
Geoff Langbfdea662014-07-23 14:16:32 -04005249 if (context)
5250 {
5251 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005252 {
Geoff Langbfdea662014-07-23 14:16:32 -04005253 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005254 }
Geoff Langbfdea662014-07-23 14:16:32 -04005255
5256 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005257 }
5258}
5259
5260void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5261{
Geoff Langbfdea662014-07-23 14:16:32 -04005262 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005263
Geoff Langbfdea662014-07-23 14:16:32 -04005264 if (context)
5265 {
5266 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005267 {
Geoff Langbfdea662014-07-23 14:16:32 -04005268 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005269 }
Geoff Langbfdea662014-07-23 14:16:32 -04005270
5271 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005272 }
5273}
5274
5275void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5276{
5277 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5278 location, count, transpose, value);
5279
Geoff Langbfdea662014-07-23 14:16:32 -04005280 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005281
Geoff Langbfdea662014-07-23 14:16:32 -04005282 if (context)
5283 {
5284 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005285 {
Geoff Langbfdea662014-07-23 14:16:32 -04005286 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005287 }
Geoff Langbfdea662014-07-23 14:16:32 -04005288
5289 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5290 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005291 }
5292}
5293
5294void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5295{
5296 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5297 location, count, transpose, value);
5298
Geoff Langbfdea662014-07-23 14:16:32 -04005299 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005300
Geoff Langbfdea662014-07-23 14:16:32 -04005301 if (context)
5302 {
5303 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005304 {
Geoff Langbfdea662014-07-23 14:16:32 -04005305 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005306 }
Geoff Langbfdea662014-07-23 14:16:32 -04005307
5308 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5309 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005310 }
5311}
5312
5313void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5314{
5315 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5316 location, count, transpose, value);
5317
Geoff Langbfdea662014-07-23 14:16:32 -04005318 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005319
Geoff Langbfdea662014-07-23 14:16:32 -04005320 if (context)
5321 {
5322 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005323 {
Geoff Langbfdea662014-07-23 14:16:32 -04005324 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005325 }
Geoff Langbfdea662014-07-23 14:16:32 -04005326
5327 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5328 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005329 }
5330}
5331
5332void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5333{
5334 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5335 location, count, transpose, value);
5336
Geoff Langbfdea662014-07-23 14:16:32 -04005337 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005338
Geoff Langbfdea662014-07-23 14:16:32 -04005339 if (context)
5340 {
5341 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005342 {
Geoff Langbfdea662014-07-23 14:16:32 -04005343 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005344 }
Geoff Langbfdea662014-07-23 14:16:32 -04005345
5346 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5347 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005348 }
5349}
5350
5351void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5352{
5353 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5354 location, count, transpose, value);
5355
Geoff Langbfdea662014-07-23 14:16:32 -04005356 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005357
Geoff Langbfdea662014-07-23 14:16:32 -04005358 if (context)
5359 {
5360 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005361 {
Geoff Langbfdea662014-07-23 14:16:32 -04005362 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005363 }
Geoff Langbfdea662014-07-23 14:16:32 -04005364
5365 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5366 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005367 }
5368}
5369
5370void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5371{
5372 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5373 location, count, transpose, value);
5374
Geoff Langbfdea662014-07-23 14:16:32 -04005375 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005376
Geoff Langbfdea662014-07-23 14:16:32 -04005377 if (context)
5378 {
5379 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005380 {
Geoff Langbfdea662014-07-23 14:16:32 -04005381 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005382 }
Geoff Langbfdea662014-07-23 14:16:32 -04005383
5384 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5385 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005386 }
5387}
5388
5389void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5390{
5391 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5392 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5393 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5394
Geoff Langbfdea662014-07-23 14:16:32 -04005395 gl::Context *context = gl::getNonLostContext();
5396 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005397 {
Geoff Langbfdea662014-07-23 14:16:32 -04005398 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005399 {
Geoff Langbfdea662014-07-23 14:16:32 -04005400 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005401 }
Geoff Langbfdea662014-07-23 14:16:32 -04005402
5403 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5404 dstX0, dstY0, dstX1, dstY1, mask, filter,
5405 false))
5406 {
5407 return;
5408 }
5409
5410 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5411 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005412 }
5413}
5414
5415void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5416{
5417 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5418 target, samples, internalformat, width, height);
5419
Geoff Langbfdea662014-07-23 14:16:32 -04005420 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005421
Geoff Langbfdea662014-07-23 14:16:32 -04005422 if (context)
5423 {
5424 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005425 {
Geoff Langbfdea662014-07-23 14:16:32 -04005426 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005427 }
Geoff Langbfdea662014-07-23 14:16:32 -04005428
5429 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5430 width, height, false))
5431 {
5432 return;
5433 }
5434
5435 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005436 }
5437}
5438
5439void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5440{
5441 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5442 target, attachment, texture, level, layer);
5443
Geoff Langbfdea662014-07-23 14:16:32 -04005444 gl::Context *context = gl::getNonLostContext();
5445
5446 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005447 {
Geoff Langbfdea662014-07-23 14:16:32 -04005448 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5449 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005450 {
Geoff Langbfdea662014-07-23 14:16:32 -04005451 return;
5452 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005453
Geoff Langbfdea662014-07-23 14:16:32 -04005454 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5455 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005456
Geoff Langbfdea662014-07-23 14:16:32 -04005457 gl::Texture *textureObject = context->getTexture(texture);
5458 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005459
Geoff Langbfdea662014-07-23 14:16:32 -04005460 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5461 {
5462 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5463 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5464 }
5465 else
5466 {
5467 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005468 {
Geoff Langbfdea662014-07-23 14:16:32 -04005469 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5470 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5471 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005472 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005473 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005474 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005475}
5476
5477GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5478{
5479 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5480 target, offset, length, access);
5481
Geoff Langbfdea662014-07-23 14:16:32 -04005482 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005483
Geoff Langbfdea662014-07-23 14:16:32 -04005484 if (context)
5485 {
5486 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005487 {
Geoff Langbfdea662014-07-23 14:16:32 -04005488 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005489 }
Geoff Langbfdea662014-07-23 14:16:32 -04005490
5491 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005492 }
5493
5494 return NULL;
5495}
5496
5497void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5498{
5499 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5500
Geoff Langbfdea662014-07-23 14:16:32 -04005501 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005502
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 Langbfdea662014-07-23 14:16:32 -04005507 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005508 }
Geoff Langbfdea662014-07-23 14:16:32 -04005509
5510 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005511 }
5512}
5513
5514void __stdcall glBindVertexArray(GLuint array)
5515{
5516 EVENT("(GLuint array = %u)", array);
5517
Geoff Langbfdea662014-07-23 14:16:32 -04005518 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005519
Geoff Langbfdea662014-07-23 14:16:32 -04005520 if (context)
5521 {
5522 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005523 {
Geoff Langbfdea662014-07-23 14:16:32 -04005524 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005525 }
Geoff Langbfdea662014-07-23 14:16:32 -04005526
5527 gl::VertexArray *vao = context->getVertexArray(array);
5528
5529 if (!vao)
5530 {
5531 // The default VAO should always exist
5532 ASSERT(array != 0);
5533 return gl::error(GL_INVALID_OPERATION);
5534 }
5535
5536 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005537 }
5538}
5539
5540void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5541{
5542 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5543
Geoff Langbfdea662014-07-23 14:16:32 -04005544 gl::Context *context = gl::getNonLostContext();
5545
5546 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005547 {
Geoff Langbfdea662014-07-23 14:16:32 -04005548 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005549 {
Geoff Langbfdea662014-07-23 14:16:32 -04005550 return gl::error(GL_INVALID_OPERATION);
5551 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005552
Geoff Langbfdea662014-07-23 14:16:32 -04005553 if (n < 0)
5554 {
5555 return gl::error(GL_INVALID_VALUE);
5556 }
Jamie Madilld1028542013-07-02 11:57:04 -04005557
Geoff Langbfdea662014-07-23 14:16:32 -04005558 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5559 {
5560 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005561 {
Geoff Langbfdea662014-07-23 14:16:32 -04005562 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005563 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005564 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005565 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005566}
5567
5568void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5569{
5570 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5571
Geoff Langbfdea662014-07-23 14:16:32 -04005572 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005573
Geoff Langbfdea662014-07-23 14:16:32 -04005574 if (context)
5575 {
5576 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005577 {
Geoff Langbfdea662014-07-23 14:16:32 -04005578 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005579 }
Geoff Langbfdea662014-07-23 14:16:32 -04005580
5581 if (n < 0)
5582 {
5583 return gl::error(GL_INVALID_VALUE);
5584 }
5585
5586 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5587 {
5588 arrays[arrayIndex] = context->createVertexArray();
5589 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005590 }
5591}
5592
5593GLboolean __stdcall glIsVertexArray(GLuint array)
5594{
5595 EVENT("(GLuint array = %u)", array);
5596
Geoff Langbfdea662014-07-23 14:16:32 -04005597 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005598
Geoff Langbfdea662014-07-23 14:16:32 -04005599 if (context)
5600 {
5601 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005602 {
Geoff Langbfdea662014-07-23 14:16:32 -04005603 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005604 }
Geoff Langbfdea662014-07-23 14:16:32 -04005605
5606 if (array == 0)
5607 {
5608 return GL_FALSE;
5609 }
5610
5611 gl::VertexArray *vao = context->getVertexArray(array);
5612
5613 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005614 }
5615
5616 return GL_FALSE;
5617}
5618
5619void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5620{
5621 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5622 target, index, data);
5623
Geoff Langbfdea662014-07-23 14:16:32 -04005624 gl::Context *context = gl::getNonLostContext();
5625
5626 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005627 {
Geoff Langbfdea662014-07-23 14:16:32 -04005628 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005629 {
Geoff Langbfdea662014-07-23 14:16:32 -04005630 return gl::error(GL_INVALID_OPERATION);
5631 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005632
Geoff Langbfdea662014-07-23 14:16:32 -04005633 switch (target)
5634 {
5635 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5636 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5637 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
5638 if (index >= context->getMaxTransformFeedbackBufferBindings())
5639 return gl::error(GL_INVALID_VALUE);
5640 break;
5641 case GL_UNIFORM_BUFFER_START:
5642 case GL_UNIFORM_BUFFER_SIZE:
5643 case GL_UNIFORM_BUFFER_BINDING:
5644 if (index >= context->getMaximumCombinedUniformBufferBindings())
5645 return gl::error(GL_INVALID_VALUE);
5646 break;
5647 default:
5648 return gl::error(GL_INVALID_ENUM);
5649 }
5650
5651 if (!(context->getIndexedIntegerv(target, index, data)))
5652 {
5653 GLenum nativeType;
5654 unsigned int numParams = 0;
5655 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04005656 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04005657
Geoff Langbfdea662014-07-23 14:16:32 -04005658 if (numParams == 0)
5659 return; // it is known that pname is valid, but there are no parameters to return
5660
5661 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005662 {
Geoff Langbfdea662014-07-23 14:16:32 -04005663 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5664 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5665 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005666
Geoff Langbfdea662014-07-23 14:16:32 -04005667 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005668
Geoff Langbfdea662014-07-23 14:16:32 -04005669 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005670 {
Geoff Langbfdea662014-07-23 14:16:32 -04005671 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5672 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005673 }
Geoff Langbfdea662014-07-23 14:16:32 -04005674
5675 delete [] int64Params;
5676 }
5677 else
5678 {
5679 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005680 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005681 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005682 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005683}
5684
5685void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5686{
5687 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5688
Geoff Langbfdea662014-07-23 14:16:32 -04005689 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005690
Geoff Langbfdea662014-07-23 14:16:32 -04005691 if (context)
5692 {
5693 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005694 {
Geoff Langbfdea662014-07-23 14:16:32 -04005695 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005696 }
Geoff Langbfdea662014-07-23 14:16:32 -04005697
5698 switch (primitiveMode)
5699 {
5700 case GL_TRIANGLES:
5701 case GL_LINES:
5702 case GL_POINTS:
5703 break;
5704 default:
5705 return gl::error(GL_INVALID_ENUM);
5706 }
5707
5708 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5709 ASSERT(transformFeedback != NULL);
5710
5711 if (transformFeedback->isStarted())
5712 {
5713 return gl::error(GL_INVALID_OPERATION);
5714 }
5715
5716 if (transformFeedback->isPaused())
5717 {
5718 transformFeedback->resume();
5719 }
5720 else
5721 {
5722 transformFeedback->start(primitiveMode);
5723 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005724 }
5725}
5726
5727void __stdcall glEndTransformFeedback(void)
5728{
5729 EVENT("(void)");
5730
Geoff Langbfdea662014-07-23 14:16:32 -04005731 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005732
Geoff Langbfdea662014-07-23 14:16:32 -04005733 if (context)
5734 {
5735 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005736 {
Geoff Langbfdea662014-07-23 14:16:32 -04005737 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005738 }
Geoff Langbfdea662014-07-23 14:16:32 -04005739
5740 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5741 ASSERT(transformFeedback != NULL);
5742
5743 if (!transformFeedback->isStarted())
5744 {
5745 return gl::error(GL_INVALID_OPERATION);
5746 }
5747
5748 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005749 }
5750}
5751
5752void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5753{
5754 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5755 target, index, buffer, offset, size);
5756
Geoff Langbfdea662014-07-23 14:16:32 -04005757 gl::Context *context = gl::getNonLostContext();
5758
5759 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005760 {
Geoff Langbfdea662014-07-23 14:16:32 -04005761 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005762 {
Geoff Langbfdea662014-07-23 14:16:32 -04005763 return gl::error(GL_INVALID_OPERATION);
5764 }
5765
5766 switch (target)
5767 {
5768 case GL_TRANSFORM_FEEDBACK_BUFFER:
5769 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005770 {
Geoff Langbfdea662014-07-23 14:16:32 -04005771 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005772 }
Geoff Langbfdea662014-07-23 14:16:32 -04005773 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005774
Geoff Langbfdea662014-07-23 14:16:32 -04005775 case GL_UNIFORM_BUFFER:
5776 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005777 {
Geoff Langbfdea662014-07-23 14:16:32 -04005778 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005779 }
Geoff Langbfdea662014-07-23 14:16:32 -04005780 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005781
Geoff Langbfdea662014-07-23 14:16:32 -04005782 default:
5783 return gl::error(GL_INVALID_ENUM);
5784 }
5785
5786 if (buffer != 0 && size <= 0)
5787 {
5788 return gl::error(GL_INVALID_VALUE);
5789 }
5790
5791 switch (target)
5792 {
5793 case GL_TRANSFORM_FEEDBACK_BUFFER:
5794
5795 // size and offset must be a multiple of 4
5796 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005797 {
5798 return gl::error(GL_INVALID_VALUE);
5799 }
5800
Geoff Langbfdea662014-07-23 14:16:32 -04005801 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5802 context->bindGenericTransformFeedbackBuffer(buffer);
5803 break;
5804
5805 case GL_UNIFORM_BUFFER:
5806
5807 // it is an error to bind an offset not a multiple of the alignment
5808 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005809 {
Geoff Langbfdea662014-07-23 14:16:32 -04005810 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005811 }
Geoff Langbfdea662014-07-23 14:16:32 -04005812
5813 context->bindIndexedUniformBuffer(buffer, index, offset, size);
5814 context->bindGenericUniformBuffer(buffer);
5815 break;
5816
5817 default:
5818 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005819 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005820 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005821}
5822
5823void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
5824{
5825 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
5826 target, index, buffer);
5827
Geoff Langbfdea662014-07-23 14:16:32 -04005828 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005829
Geoff Langbfdea662014-07-23 14:16:32 -04005830 if (context)
5831 {
5832 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005833 {
Geoff Langbfdea662014-07-23 14:16:32 -04005834 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005835 }
Geoff Langbfdea662014-07-23 14:16:32 -04005836
5837 switch (target)
5838 {
5839 case GL_TRANSFORM_FEEDBACK_BUFFER:
5840 if (index >= context->getMaxTransformFeedbackBufferBindings())
5841 {
5842 return gl::error(GL_INVALID_VALUE);
5843 }
5844 break;
5845
5846 case GL_UNIFORM_BUFFER:
5847 if (index >= context->getMaximumCombinedUniformBufferBindings())
5848 {
5849 return gl::error(GL_INVALID_VALUE);
5850 }
5851 break;
5852
5853 default:
5854 return gl::error(GL_INVALID_ENUM);
5855 }
5856
5857 switch (target)
5858 {
5859 case GL_TRANSFORM_FEEDBACK_BUFFER:
5860 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
5861 context->bindGenericTransformFeedbackBuffer(buffer);
5862 break;
5863
5864 case GL_UNIFORM_BUFFER:
5865 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
5866 context->bindGenericUniformBuffer(buffer);
5867 break;
5868
5869 default:
5870 UNREACHABLE();
5871 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005872 }
5873}
5874
5875void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
5876{
5877 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
5878 program, count, varyings, bufferMode);
5879
Geoff Langbfdea662014-07-23 14:16:32 -04005880 gl::Context *context = gl::getNonLostContext();
5881
5882 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005883 {
Geoff Langbfdea662014-07-23 14:16:32 -04005884 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005885 {
Geoff Langbfdea662014-07-23 14:16:32 -04005886 return gl::error(GL_INVALID_OPERATION);
5887 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005888
Geoff Langbfdea662014-07-23 14:16:32 -04005889 if (count < 0)
5890 {
5891 return gl::error(GL_INVALID_VALUE);
5892 }
5893
5894 switch (bufferMode)
5895 {
5896 case GL_INTERLEAVED_ATTRIBS:
5897 break;
5898 case GL_SEPARATE_ATTRIBS:
5899 if (static_cast<GLuint>(count) > context->getMaxTransformFeedbackBufferBindings())
Geoff Lang48dcae72014-02-05 16:28:24 -05005900 {
5901 return gl::error(GL_INVALID_VALUE);
5902 }
Geoff Langbfdea662014-07-23 14:16:32 -04005903 break;
5904 default:
5905 return gl::error(GL_INVALID_ENUM);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005906 }
Geoff Langbfdea662014-07-23 14:16:32 -04005907
5908 if (!gl::ValidProgram(context, program))
5909 {
5910 return;
5911 }
5912
5913 gl::Program *programObject = context->getProgram(program);
5914 ASSERT(programObject);
5915
5916 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005917 }
5918}
5919
5920void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
5921{
5922 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
5923 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
5924 program, index, bufSize, length, size, type, name);
5925
Geoff Langbfdea662014-07-23 14:16:32 -04005926 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005927
Geoff Langbfdea662014-07-23 14:16:32 -04005928 if (context)
5929 {
5930 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005931 {
Geoff Langbfdea662014-07-23 14:16:32 -04005932 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005933 }
Geoff Langbfdea662014-07-23 14:16:32 -04005934
5935 if (bufSize < 0)
5936 {
5937 return gl::error(GL_INVALID_VALUE);
5938 }
5939
5940 if (!gl::ValidProgram(context, program))
5941 {
5942 return;
5943 }
5944
5945 gl::Program *programObject = context->getProgram(program);
5946 ASSERT(programObject);
5947
5948 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
5949 {
5950 return gl::error(GL_INVALID_VALUE);
5951 }
5952
5953 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005954 }
5955}
5956
5957void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
5958{
5959 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
5960 index, size, type, stride, pointer);
5961
Geoff Langbfdea662014-07-23 14:16:32 -04005962 gl::Context *context = gl::getNonLostContext();
5963
5964 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005965 {
Geoff Langbfdea662014-07-23 14:16:32 -04005966 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005967 {
Geoff Langbfdea662014-07-23 14:16:32 -04005968 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005969 }
Geoff Langbfdea662014-07-23 14:16:32 -04005970 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005971
Geoff Langbfdea662014-07-23 14:16:32 -04005972 if (index >= gl::MAX_VERTEX_ATTRIBS)
5973 {
5974 return gl::error(GL_INVALID_VALUE);
5975 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005976
Geoff Langbfdea662014-07-23 14:16:32 -04005977 if (size < 1 || size > 4)
5978 {
5979 return gl::error(GL_INVALID_VALUE);
5980 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005981
Geoff Langbfdea662014-07-23 14:16:32 -04005982 switch (type)
5983 {
5984 case GL_BYTE:
5985 case GL_UNSIGNED_BYTE:
5986 case GL_SHORT:
5987 case GL_UNSIGNED_SHORT:
5988 case GL_INT:
5989 case GL_UNSIGNED_INT:
5990 case GL_INT_2_10_10_10_REV:
5991 case GL_UNSIGNED_INT_2_10_10_10_REV:
5992 break;
5993 default:
5994 return gl::error(GL_INVALID_ENUM);
5995 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005996
Geoff Langbfdea662014-07-23 14:16:32 -04005997 if (stride < 0)
5998 {
5999 return gl::error(GL_INVALID_VALUE);
6000 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006001
Geoff Langbfdea662014-07-23 14:16:32 -04006002 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6003 {
6004 return gl::error(GL_INVALID_OPERATION);
6005 }
6006
6007 if (context)
6008 {
6009 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6010 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6011 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6012 // and the pointer argument is not NULL.
6013 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006014 {
6015 return gl::error(GL_INVALID_OPERATION);
6016 }
6017
Geoff Langbfdea662014-07-23 14:16:32 -04006018 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6019 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006020 }
6021}
6022
6023void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6024{
6025 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6026 index, pname, params);
6027
Geoff Langbfdea662014-07-23 14:16:32 -04006028 gl::Context *context = gl::getNonLostContext();
6029
6030 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006031 {
Geoff Langbfdea662014-07-23 14:16:32 -04006032 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006033 {
Geoff Langbfdea662014-07-23 14:16:32 -04006034 return gl::error(GL_INVALID_OPERATION);
6035 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006036
Geoff Langbfdea662014-07-23 14:16:32 -04006037 if (index >= gl::MAX_VERTEX_ATTRIBS)
6038 {
6039 return gl::error(GL_INVALID_VALUE);
6040 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006041
Geoff Langbfdea662014-07-23 14:16:32 -04006042 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006043
Geoff Langbfdea662014-07-23 14:16:32 -04006044 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6045 {
6046 return;
6047 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006048
Geoff Langbfdea662014-07-23 14:16:32 -04006049 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6050 {
6051 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6052 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006053 {
Geoff Langbfdea662014-07-23 14:16:32 -04006054 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006055 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006056 }
Geoff Langbfdea662014-07-23 14:16:32 -04006057 else
6058 {
6059 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6060 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006061 }
6062}
6063
6064void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6065{
6066 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6067 index, pname, params);
6068
Geoff Langbfdea662014-07-23 14:16:32 -04006069 gl::Context *context = gl::getNonLostContext();
6070
6071 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006072 {
Geoff Langbfdea662014-07-23 14:16:32 -04006073 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006074 {
Geoff Langbfdea662014-07-23 14:16:32 -04006075 return gl::error(GL_INVALID_OPERATION);
6076 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006077
Geoff Langbfdea662014-07-23 14:16:32 -04006078 if (index >= gl::MAX_VERTEX_ATTRIBS)
6079 {
6080 return gl::error(GL_INVALID_VALUE);
6081 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006082
Geoff Langbfdea662014-07-23 14:16:32 -04006083 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006084
Geoff Langbfdea662014-07-23 14:16:32 -04006085 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6086 {
6087 return;
6088 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006089
Geoff Langbfdea662014-07-23 14:16:32 -04006090 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6091 {
6092 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6093 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006094 {
Geoff Langbfdea662014-07-23 14:16:32 -04006095 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006096 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006097 }
Geoff Langbfdea662014-07-23 14:16:32 -04006098 else
6099 {
6100 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6101 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006102 }
6103}
6104
6105void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6106{
6107 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6108 index, x, y, z, w);
6109
Geoff Langbfdea662014-07-23 14:16:32 -04006110 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006111
Geoff Langbfdea662014-07-23 14:16:32 -04006112 if (context)
6113 {
6114 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006115 {
Geoff Langbfdea662014-07-23 14:16:32 -04006116 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006117 }
Geoff Langbfdea662014-07-23 14:16:32 -04006118
6119 if (index >= gl::MAX_VERTEX_ATTRIBS)
6120 {
6121 return gl::error(GL_INVALID_VALUE);
6122 }
6123
6124 GLint vals[4] = { x, y, z, w };
6125 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006126 }
6127}
6128
6129void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6130{
6131 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6132 index, x, y, z, w);
6133
Geoff Langbfdea662014-07-23 14:16:32 -04006134 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006135
Geoff Langbfdea662014-07-23 14:16:32 -04006136 if (context)
6137 {
6138 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006139 {
Geoff Langbfdea662014-07-23 14:16:32 -04006140 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006141 }
Geoff Langbfdea662014-07-23 14:16:32 -04006142
6143 if (index >= gl::MAX_VERTEX_ATTRIBS)
6144 {
6145 return gl::error(GL_INVALID_VALUE);
6146 }
6147
6148 GLuint vals[4] = { x, y, z, w };
6149 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006150 }
6151}
6152
6153void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6154{
6155 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6156
Geoff Langbfdea662014-07-23 14:16:32 -04006157 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006158
Geoff Langbfdea662014-07-23 14:16:32 -04006159 if (context)
6160 {
6161 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006162 {
Geoff Langbfdea662014-07-23 14:16:32 -04006163 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006164 }
Geoff Langbfdea662014-07-23 14:16:32 -04006165
6166 if (index >= gl::MAX_VERTEX_ATTRIBS)
6167 {
6168 return gl::error(GL_INVALID_VALUE);
6169 }
6170
6171 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006172 }
6173}
6174
6175void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6176{
6177 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6178
Geoff Langbfdea662014-07-23 14:16:32 -04006179 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006180
Geoff Langbfdea662014-07-23 14:16:32 -04006181 if (context)
6182 {
6183 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006184 {
Geoff Langbfdea662014-07-23 14:16:32 -04006185 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006186 }
Geoff Langbfdea662014-07-23 14:16:32 -04006187
6188 if (index >= gl::MAX_VERTEX_ATTRIBS)
6189 {
6190 return gl::error(GL_INVALID_VALUE);
6191 }
6192
6193 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006194 }
6195}
6196
6197void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6198{
6199 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6200 program, location, params);
6201
Geoff Langbfdea662014-07-23 14:16:32 -04006202 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006203
Geoff Langbfdea662014-07-23 14:16:32 -04006204 if (context)
6205 {
Jamie Madill0063c512014-08-25 15:47:53 -04006206 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006207 {
Jamie Madill0063c512014-08-25 15:47:53 -04006208 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006209 }
Geoff Langbfdea662014-07-23 14:16:32 -04006210
Jamie Madill0063c512014-08-25 15:47:53 -04006211 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6212 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006213
Jamie Madill99a1e982014-08-25 15:47:54 -04006214 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006215 }
6216}
6217
6218GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6219{
6220 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6221 program, name);
6222
Geoff Langbfdea662014-07-23 14:16:32 -04006223 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006224
Geoff Langbfdea662014-07-23 14:16:32 -04006225 if (context)
6226 {
6227 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006228 {
Geoff Langbfdea662014-07-23 14:16:32 -04006229 return gl::error(GL_INVALID_OPERATION, -1);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006230 }
Geoff Langbfdea662014-07-23 14:16:32 -04006231
6232 if (program == 0)
6233 {
6234 return gl::error(GL_INVALID_VALUE, -1);
6235 }
6236
6237 gl::Program *programObject = context->getProgram(program);
6238
6239 if (!programObject || !programObject->isLinked())
6240 {
6241 return gl::error(GL_INVALID_OPERATION, -1);
6242 }
6243
6244 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6245 if (!programBinary)
6246 {
6247 return gl::error(GL_INVALID_OPERATION, -1);
6248 }
6249
6250 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006251 }
6252
6253 return 0;
6254}
6255
6256void __stdcall glUniform1ui(GLint location, GLuint v0)
6257{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006258 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006259}
6260
6261void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6262{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006263 const GLuint xy[] = { v0, v1 };
6264 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006265}
6266
6267void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6268{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006269 const GLuint xyz[] = { v0, v1, v2 };
6270 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006271}
6272
6273void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6274{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006275 const GLuint xyzw[] = { v0, v1, v2, v3 };
6276 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006277}
6278
6279void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6280{
6281 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6282 location, count, value);
6283
Geoff Langbfdea662014-07-23 14:16:32 -04006284 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006285
Geoff Langbfdea662014-07-23 14:16:32 -04006286 if (context)
6287 {
6288 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006289 {
Geoff Langbfdea662014-07-23 14:16:32 -04006290 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006291 }
Geoff Langbfdea662014-07-23 14:16:32 -04006292
6293 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6294 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006295 }
6296}
6297
6298void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6299{
6300 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6301 location, count, value);
6302
Geoff Langbfdea662014-07-23 14:16:32 -04006303 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006304
Geoff Langbfdea662014-07-23 14:16:32 -04006305 if (context)
6306 {
6307 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006308 {
Geoff Langbfdea662014-07-23 14:16:32 -04006309 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006310 }
Geoff Langbfdea662014-07-23 14:16:32 -04006311
6312 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6313 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006314 }
6315}
6316
6317void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6318{
6319 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6320 location, count, value);
6321
Geoff Langbfdea662014-07-23 14:16:32 -04006322 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006323
Geoff Langbfdea662014-07-23 14:16:32 -04006324 if (context)
6325 {
6326 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006327 {
Geoff Langbfdea662014-07-23 14:16:32 -04006328 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006329 }
Geoff Langbfdea662014-07-23 14:16:32 -04006330
6331 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6332 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006333 }
6334}
6335
6336void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6337{
6338 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6339 location, count, value);
6340
Geoff Langbfdea662014-07-23 14:16:32 -04006341 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006342
Geoff Langbfdea662014-07-23 14:16:32 -04006343 if (context)
6344 {
6345 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006346 {
Geoff Langbfdea662014-07-23 14:16:32 -04006347 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006348 }
Geoff Langbfdea662014-07-23 14:16:32 -04006349
6350 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6351 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006352 }
6353}
6354
6355void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6356{
6357 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6358 buffer, drawbuffer, value);
6359
Geoff Langbfdea662014-07-23 14:16:32 -04006360 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006361
Geoff Langbfdea662014-07-23 14:16:32 -04006362 if (context)
6363 {
6364 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006365 {
Geoff Langbfdea662014-07-23 14:16:32 -04006366 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006367 }
Geoff Langbfdea662014-07-23 14:16:32 -04006368
6369 switch (buffer)
6370 {
6371 case GL_COLOR:
6372 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6373 {
6374 return gl::error(GL_INVALID_VALUE);
6375 }
6376 break;
6377 case GL_STENCIL:
6378 if (drawbuffer != 0)
6379 {
6380 return gl::error(GL_INVALID_VALUE);
6381 }
6382 break;
6383 default:
6384 return gl::error(GL_INVALID_ENUM);
6385 }
6386
6387 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006388 }
6389}
6390
6391void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6392{
6393 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6394 buffer, drawbuffer, value);
6395
Geoff Langbfdea662014-07-23 14:16:32 -04006396 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006397
Geoff Langbfdea662014-07-23 14:16:32 -04006398 if (context)
6399 {
6400 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006401 {
Geoff Langbfdea662014-07-23 14:16:32 -04006402 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006403 }
Geoff Langbfdea662014-07-23 14:16:32 -04006404
6405 switch (buffer)
6406 {
6407 case GL_COLOR:
6408 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6409 {
6410 return gl::error(GL_INVALID_VALUE);
6411 }
6412 break;
6413 default:
6414 return gl::error(GL_INVALID_ENUM);
6415 }
6416
6417 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006418 }
6419}
6420
6421void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6422{
6423 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6424 buffer, drawbuffer, value);
6425
Geoff Langbfdea662014-07-23 14:16:32 -04006426 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006427
Geoff Langbfdea662014-07-23 14:16:32 -04006428 if (context)
6429 {
6430 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006431 {
Geoff Langbfdea662014-07-23 14:16:32 -04006432 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006433 }
Geoff Langbfdea662014-07-23 14:16:32 -04006434
6435 switch (buffer)
6436 {
6437 case GL_COLOR:
6438 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6439 {
6440 return gl::error(GL_INVALID_VALUE);
6441 }
6442 break;
6443 case GL_DEPTH:
6444 if (drawbuffer != 0)
6445 {
6446 return gl::error(GL_INVALID_VALUE);
6447 }
6448 break;
6449 default:
6450 return gl::error(GL_INVALID_ENUM);
6451 }
6452
6453 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006454 }
6455}
6456
6457void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6458{
6459 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6460 buffer, drawbuffer, depth, stencil);
6461
Geoff Langbfdea662014-07-23 14:16:32 -04006462 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006463
Geoff Langbfdea662014-07-23 14:16:32 -04006464 if (context)
6465 {
6466 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006467 {
Geoff Langbfdea662014-07-23 14:16:32 -04006468 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006469 }
Geoff Langbfdea662014-07-23 14:16:32 -04006470
6471 switch (buffer)
6472 {
6473 case GL_DEPTH_STENCIL:
6474 if (drawbuffer != 0)
6475 {
6476 return gl::error(GL_INVALID_VALUE);
6477 }
6478 break;
6479 default:
6480 return gl::error(GL_INVALID_ENUM);
6481 }
6482
6483 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006484 }
6485}
6486
6487const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6488{
6489 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6490
Geoff Langbfdea662014-07-23 14:16:32 -04006491 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006492
Geoff Langbfdea662014-07-23 14:16:32 -04006493 if (context)
6494 {
6495 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006496 {
Geoff Langbfdea662014-07-23 14:16:32 -04006497 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006498 }
Geoff Langbfdea662014-07-23 14:16:32 -04006499
6500 if (name != GL_EXTENSIONS)
6501 {
6502 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
6503 }
6504
6505 if (index >= context->getExtensionStringCount())
6506 {
6507 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
6508 }
6509
6510 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006511 }
6512
6513 return NULL;
6514}
6515
6516void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6517{
6518 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6519 readTarget, writeTarget, readOffset, writeOffset, size);
6520
Geoff Langbfdea662014-07-23 14:16:32 -04006521 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006522
Geoff Langbfdea662014-07-23 14:16:32 -04006523 if (context)
6524 {
6525 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006526 {
Geoff Langbfdea662014-07-23 14:16:32 -04006527 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006528 }
Geoff Langbfdea662014-07-23 14:16:32 -04006529
6530 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6531 {
6532 return gl::error(GL_INVALID_ENUM);
6533 }
6534
6535 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6536 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6537
6538 if (!readBuffer || !writeBuffer)
6539 {
6540 return gl::error(GL_INVALID_OPERATION);
6541 }
6542
Jamie Madillcfaaf722014-07-31 10:47:54 -04006543 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006544 if (readBuffer->isMapped() || writeBuffer->isMapped())
6545 {
6546 return gl::error(GL_INVALID_OPERATION);
6547 }
6548
6549 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6550 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6551 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6552 {
6553 return gl::error(GL_INVALID_VALUE);
6554 }
6555
6556 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6557 {
6558 return gl::error(GL_INVALID_VALUE);
6559 }
6560
Geoff Langbfdea662014-07-23 14:16:32 -04006561 // if size is zero, the copy is a successful no-op
6562 if (size > 0)
6563 {
6564 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6565 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006566 }
6567}
6568
6569void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6570{
6571 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6572 program, uniformCount, uniformNames, uniformIndices);
6573
Geoff Langbfdea662014-07-23 14:16:32 -04006574 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006575
Geoff Langbfdea662014-07-23 14:16:32 -04006576 if (context)
6577 {
6578 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006579 {
Geoff Langbfdea662014-07-23 14:16:32 -04006580 return gl::error(GL_INVALID_OPERATION);
6581 }
6582
6583 if (uniformCount < 0)
6584 {
6585 return gl::error(GL_INVALID_VALUE);
6586 }
6587
6588 gl::Program *programObject = context->getProgram(program);
6589
6590 if (!programObject)
6591 {
6592 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006593 {
6594 return gl::error(GL_INVALID_OPERATION);
6595 }
Geoff Langbfdea662014-07-23 14:16:32 -04006596 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006597 {
6598 return gl::error(GL_INVALID_VALUE);
6599 }
Geoff Langbfdea662014-07-23 14:16:32 -04006600 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006601
Geoff Langbfdea662014-07-23 14:16:32 -04006602 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6603 if (!programObject->isLinked() || !programBinary)
6604 {
6605 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006606 {
Geoff Langbfdea662014-07-23 14:16:32 -04006607 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006608 }
6609 }
Geoff Langbfdea662014-07-23 14:16:32 -04006610 else
6611 {
6612 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6613 {
6614 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6615 }
6616 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006617 }
6618}
6619
6620void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6621{
6622 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6623 program, uniformCount, uniformIndices, pname, params);
6624
Geoff Langbfdea662014-07-23 14:16:32 -04006625 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006626
Geoff Langbfdea662014-07-23 14:16:32 -04006627 if (context)
6628 {
6629 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006630 {
Geoff Langbfdea662014-07-23 14:16:32 -04006631 return gl::error(GL_INVALID_OPERATION);
6632 }
6633
6634 if (uniformCount < 0)
6635 {
6636 return gl::error(GL_INVALID_VALUE);
6637 }
6638
6639 gl::Program *programObject = context->getProgram(program);
6640
6641 if (!programObject)
6642 {
6643 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006644 {
6645 return gl::error(GL_INVALID_OPERATION);
6646 }
Geoff Langbfdea662014-07-23 14:16:32 -04006647 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006648 {
6649 return gl::error(GL_INVALID_VALUE);
6650 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006651 }
Geoff Langbfdea662014-07-23 14:16:32 -04006652
6653 switch (pname)
6654 {
6655 case GL_UNIFORM_TYPE:
6656 case GL_UNIFORM_SIZE:
6657 case GL_UNIFORM_NAME_LENGTH:
6658 case GL_UNIFORM_BLOCK_INDEX:
6659 case GL_UNIFORM_OFFSET:
6660 case GL_UNIFORM_ARRAY_STRIDE:
6661 case GL_UNIFORM_MATRIX_STRIDE:
6662 case GL_UNIFORM_IS_ROW_MAJOR:
6663 break;
6664 default:
6665 return gl::error(GL_INVALID_ENUM);
6666 }
6667
6668 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6669
6670 if (!programBinary && uniformCount > 0)
6671 {
6672 return gl::error(GL_INVALID_VALUE);
6673 }
6674
6675 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6676 {
6677 const GLuint index = uniformIndices[uniformId];
6678
6679 if (index >= (GLuint)programBinary->getActiveUniformCount())
6680 {
6681 return gl::error(GL_INVALID_VALUE);
6682 }
6683 }
6684
6685 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6686 {
6687 const GLuint index = uniformIndices[uniformId];
6688 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6689 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006690 }
6691}
6692
6693GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6694{
6695 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6696
Geoff Langbfdea662014-07-23 14:16:32 -04006697 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006698
Geoff Langbfdea662014-07-23 14:16:32 -04006699 if (context)
6700 {
6701 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006702 {
Geoff Langbfdea662014-07-23 14:16:32 -04006703 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
6704 }
6705
6706 gl::Program *programObject = context->getProgram(program);
6707
6708 if (!programObject)
6709 {
6710 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006711 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006712 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006713 }
Geoff Langbfdea662014-07-23 14:16:32 -04006714 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006715 {
Geoff Langbfdea662014-07-23 14:16:32 -04006716 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006717 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006718 }
Geoff Langbfdea662014-07-23 14:16:32 -04006719
6720 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6721 if (!programBinary)
6722 {
6723 return GL_INVALID_INDEX;
6724 }
6725
6726 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006727 }
6728
6729 return 0;
6730}
6731
6732void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6733{
6734 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6735 program, uniformBlockIndex, pname, params);
6736
Geoff Langbfdea662014-07-23 14:16:32 -04006737 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006738
Geoff Langbfdea662014-07-23 14:16:32 -04006739 if (context)
6740 {
6741 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006742 {
Geoff Langbfdea662014-07-23 14:16:32 -04006743 return gl::error(GL_INVALID_OPERATION);
6744 }
6745 gl::Program *programObject = context->getProgram(program);
6746
6747 if (!programObject)
6748 {
6749 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006750 {
6751 return gl::error(GL_INVALID_OPERATION);
6752 }
Geoff Langbfdea662014-07-23 14:16:32 -04006753 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006754 {
6755 return gl::error(GL_INVALID_VALUE);
6756 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006757 }
Geoff Langbfdea662014-07-23 14:16:32 -04006758
6759 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6760
6761 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6762 {
6763 return gl::error(GL_INVALID_VALUE);
6764 }
6765
6766 switch (pname)
6767 {
6768 case GL_UNIFORM_BLOCK_BINDING:
6769 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
6770 break;
6771
6772 case GL_UNIFORM_BLOCK_DATA_SIZE:
6773 case GL_UNIFORM_BLOCK_NAME_LENGTH:
6774 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
6775 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
6776 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
6777 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
6778 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
6779 break;
6780
6781 default:
6782 return gl::error(GL_INVALID_ENUM);
6783 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006784 }
6785}
6786
6787void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
6788{
6789 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
6790 program, uniformBlockIndex, bufSize, length, uniformBlockName);
6791
Geoff Langbfdea662014-07-23 14:16:32 -04006792 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006793
Geoff Langbfdea662014-07-23 14:16:32 -04006794 if (context)
6795 {
6796 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006797 {
Geoff Langbfdea662014-07-23 14:16:32 -04006798 return gl::error(GL_INVALID_OPERATION);
6799 }
6800
6801 gl::Program *programObject = context->getProgram(program);
6802
6803 if (!programObject)
6804 {
6805 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006806 {
6807 return gl::error(GL_INVALID_OPERATION);
6808 }
Geoff Langbfdea662014-07-23 14:16:32 -04006809 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006810 {
6811 return gl::error(GL_INVALID_VALUE);
6812 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006813 }
Geoff Langbfdea662014-07-23 14:16:32 -04006814
6815 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6816
6817 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6818 {
6819 return gl::error(GL_INVALID_VALUE);
6820 }
6821
6822 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006823 }
6824}
6825
6826void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
6827{
6828 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
6829 program, uniformBlockIndex, uniformBlockBinding);
6830
Geoff Langbfdea662014-07-23 14:16:32 -04006831 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006832
Geoff Langbfdea662014-07-23 14:16:32 -04006833 if (context)
6834 {
6835 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006836 {
Geoff Langbfdea662014-07-23 14:16:32 -04006837 return gl::error(GL_INVALID_OPERATION);
6838 }
6839
6840 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
6841 {
6842 return gl::error(GL_INVALID_VALUE);
6843 }
6844
6845 gl::Program *programObject = context->getProgram(program);
6846
6847 if (!programObject)
6848 {
6849 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006850 {
6851 return gl::error(GL_INVALID_OPERATION);
6852 }
Geoff Langbfdea662014-07-23 14:16:32 -04006853 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006854 {
6855 return gl::error(GL_INVALID_VALUE);
6856 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006857 }
Geoff Langbfdea662014-07-23 14:16:32 -04006858
6859 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6860
6861 // if never linked, there won't be any uniform blocks
6862 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6863 {
6864 return gl::error(GL_INVALID_VALUE);
6865 }
6866
6867 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006868 }
6869}
6870
6871void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
6872{
6873 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
6874 mode, first, count, instanceCount);
6875
Geoff Langbfdea662014-07-23 14:16:32 -04006876 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006877
Geoff Langbfdea662014-07-23 14:16:32 -04006878 if (context)
6879 {
6880 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006881 {
Geoff Langbfdea662014-07-23 14:16:32 -04006882 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006883 }
Geoff Langbfdea662014-07-23 14:16:32 -04006884
6885 // glDrawArraysInstanced
6886 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006887 }
6888}
6889
6890void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
6891{
6892 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
6893 mode, count, type, indices, instanceCount);
6894
Geoff Langbfdea662014-07-23 14:16:32 -04006895 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006896
Geoff Langbfdea662014-07-23 14:16:32 -04006897 if (context)
6898 {
6899 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006900 {
Geoff Langbfdea662014-07-23 14:16:32 -04006901 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006902 }
Geoff Langbfdea662014-07-23 14:16:32 -04006903
6904 // glDrawElementsInstanced
6905 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006906 }
6907}
6908
6909GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
6910{
6911 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
6912
Geoff Langbfdea662014-07-23 14:16:32 -04006913 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006914
Geoff Langbfdea662014-07-23 14:16:32 -04006915 if (context)
6916 {
6917 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006918 {
Geoff Langbfdea662014-07-23 14:16:32 -04006919 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006920 }
Geoff Langbfdea662014-07-23 14:16:32 -04006921
6922 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
6923 {
6924 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
6925 }
6926
6927 if (flags != 0)
6928 {
6929 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
6930 }
6931
6932 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006933 }
6934
6935 return NULL;
6936}
6937
6938GLboolean __stdcall glIsSync(GLsync sync)
6939{
6940 EVENT("(GLsync sync = 0x%0.8p)", sync);
6941
Geoff Langbfdea662014-07-23 14:16:32 -04006942 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006943
Geoff Langbfdea662014-07-23 14:16:32 -04006944 if (context)
6945 {
6946 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006947 {
Geoff Langbfdea662014-07-23 14:16:32 -04006948 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006949 }
Geoff Langbfdea662014-07-23 14:16:32 -04006950
6951 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006952 }
6953
6954 return GL_FALSE;
6955}
6956
6957void __stdcall glDeleteSync(GLsync sync)
6958{
6959 EVENT("(GLsync sync = 0x%0.8p)", sync);
6960
Geoff Langbfdea662014-07-23 14:16:32 -04006961 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006962
Geoff Langbfdea662014-07-23 14:16:32 -04006963 if (context)
6964 {
6965 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006966 {
Geoff Langbfdea662014-07-23 14:16:32 -04006967 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006968 }
Geoff Langbfdea662014-07-23 14:16:32 -04006969
6970 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
6971 {
6972 return gl::error(GL_INVALID_VALUE);
6973 }
6974
6975 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006976 }
6977}
6978
6979GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6980{
6981 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
6982 sync, flags, timeout);
6983
Geoff Langbfdea662014-07-23 14:16:32 -04006984 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006985
Geoff Langbfdea662014-07-23 14:16:32 -04006986 if (context)
6987 {
6988 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006989 {
Geoff Langbfdea662014-07-23 14:16:32 -04006990 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006991 }
Geoff Langbfdea662014-07-23 14:16:32 -04006992
6993 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
6994 {
6995 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
6996 }
6997
6998 gl::FenceSync *fenceSync = context->getFenceSync(sync);
6999
7000 if (!fenceSync)
7001 {
7002 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7003 }
7004
7005 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007006 }
7007
7008 return GL_FALSE;
7009}
7010
7011void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7012{
7013 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7014 sync, flags, timeout);
7015
Geoff Langbfdea662014-07-23 14:16:32 -04007016 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007017
Geoff Langbfdea662014-07-23 14:16:32 -04007018 if (context)
7019 {
7020 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007021 {
Geoff Langbfdea662014-07-23 14:16:32 -04007022 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007023 }
Geoff Langbfdea662014-07-23 14:16:32 -04007024
7025 if (flags != 0)
7026 {
7027 return gl::error(GL_INVALID_VALUE);
7028 }
7029
7030 if (timeout != GL_TIMEOUT_IGNORED)
7031 {
7032 return gl::error(GL_INVALID_VALUE);
7033 }
7034
7035 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7036
7037 if (!fenceSync)
7038 {
7039 return gl::error(GL_INVALID_VALUE);
7040 }
7041
7042 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007043 }
7044}
7045
7046void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7047{
7048 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7049 pname, params);
7050
Geoff Langbfdea662014-07-23 14:16:32 -04007051 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007052
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 Langbfdea662014-07-23 14:16:32 -04007057 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007058 }
Geoff Langbfdea662014-07-23 14:16:32 -04007059
7060 GLenum nativeType;
7061 unsigned int numParams = 0;
7062 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7063 {
7064 return;
7065 }
7066
7067 if (nativeType == GL_INT_64_ANGLEX)
7068 {
7069 context->getInteger64v(pname, params);
7070 }
7071 else
7072 {
7073 CastStateValues(context, nativeType, pname, numParams, params);
7074 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007075 }
7076}
7077
7078void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7079{
7080 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7081 sync, pname, bufSize, length, values);
7082
Geoff Langbfdea662014-07-23 14:16:32 -04007083 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007084
Geoff Langbfdea662014-07-23 14:16:32 -04007085 if (context)
7086 {
7087 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007088 {
Geoff Langbfdea662014-07-23 14:16:32 -04007089 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007090 }
Geoff Langbfdea662014-07-23 14:16:32 -04007091
7092 if (bufSize < 0)
7093 {
7094 return gl::error(GL_INVALID_VALUE);
7095 }
7096
7097 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7098
7099 if (!fenceSync)
7100 {
7101 return gl::error(GL_INVALID_VALUE);
7102 }
7103
7104 switch (pname)
7105 {
7106 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7107 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7108 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7109 case GL_SYNC_FLAGS: values[0] = 0; break;
7110
7111 default:
7112 return gl::error(GL_INVALID_ENUM);
7113 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007114 }
7115}
7116
7117void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7118{
7119 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7120 target, index, data);
7121
Geoff Langbfdea662014-07-23 14:16:32 -04007122 gl::Context *context = gl::getNonLostContext();
7123
7124 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007125 {
Geoff Langbfdea662014-07-23 14:16:32 -04007126 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007127 {
Geoff Langbfdea662014-07-23 14:16:32 -04007128 return gl::error(GL_INVALID_OPERATION);
7129 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007130
Geoff Langbfdea662014-07-23 14:16:32 -04007131 switch (target)
7132 {
7133 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7134 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7135 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7136 if (index >= context->getMaxTransformFeedbackBufferBindings())
7137 return gl::error(GL_INVALID_VALUE);
7138 break;
7139 case GL_UNIFORM_BUFFER_START:
7140 case GL_UNIFORM_BUFFER_SIZE:
7141 case GL_UNIFORM_BUFFER_BINDING:
7142 if (index >= context->getMaximumCombinedUniformBufferBindings())
7143 return gl::error(GL_INVALID_VALUE);
7144 break;
7145 default:
7146 return gl::error(GL_INVALID_ENUM);
7147 }
7148
7149 if (!(context->getIndexedInteger64v(target, index, data)))
7150 {
7151 GLenum nativeType;
7152 unsigned int numParams = 0;
7153 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04007154 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04007155
Geoff Langbfdea662014-07-23 14:16:32 -04007156 if (numParams == 0)
7157 return; // it is known that pname is valid, but there are no parameters to return
7158
7159 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007160 {
Geoff Langbfdea662014-07-23 14:16:32 -04007161 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007162
Geoff Langbfdea662014-07-23 14:16:32 -04007163 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007164
Geoff Langbfdea662014-07-23 14:16:32 -04007165 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007166 {
Geoff Langbfdea662014-07-23 14:16:32 -04007167 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007168 }
Geoff Langbfdea662014-07-23 14:16:32 -04007169
7170 delete [] intParams;
7171 }
7172 else
7173 {
7174 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007175 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007176 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007177 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007178}
7179
7180void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7181{
7182 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7183 target, pname, params);
7184
Geoff Langbfdea662014-07-23 14:16:32 -04007185 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007186
Geoff Langbfdea662014-07-23 14:16:32 -04007187 if (context)
7188 {
7189 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007190 {
Geoff Langbfdea662014-07-23 14:16:32 -04007191 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007192 }
Geoff Langbfdea662014-07-23 14:16:32 -04007193
7194 if (!gl::ValidBufferTarget(context, target))
7195 {
7196 return gl::error(GL_INVALID_ENUM);
7197 }
7198
7199 if (!gl::ValidBufferParameter(context, pname))
7200 {
7201 return gl::error(GL_INVALID_ENUM);
7202 }
7203
7204 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7205
7206 if (!buffer)
7207 {
7208 // A null buffer means that "0" is bound to the requested buffer target
7209 return gl::error(GL_INVALID_OPERATION);
7210 }
7211
7212 switch (pname)
7213 {
7214 case GL_BUFFER_USAGE:
7215 *params = static_cast<GLint64>(buffer->getUsage());
7216 break;
7217 case GL_BUFFER_SIZE:
7218 *params = buffer->getSize();
7219 break;
7220 case GL_BUFFER_ACCESS_FLAGS:
7221 *params = static_cast<GLint64>(buffer->getAccessFlags());
7222 break;
7223 case GL_BUFFER_MAPPED:
7224 *params = static_cast<GLint64>(buffer->isMapped());
7225 break;
7226 case GL_BUFFER_MAP_OFFSET:
7227 *params = buffer->getMapOffset();
7228 break;
7229 case GL_BUFFER_MAP_LENGTH:
7230 *params = buffer->getMapLength();
7231 break;
7232 default: UNREACHABLE(); break;
7233 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007234 }
7235}
7236
7237void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7238{
7239 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7240
Geoff Langbfdea662014-07-23 14:16:32 -04007241 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007242
Geoff Langbfdea662014-07-23 14:16:32 -04007243 if (context)
7244 {
7245 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007246 {
Geoff Langbfdea662014-07-23 14:16:32 -04007247 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007248 }
Geoff Langbfdea662014-07-23 14:16:32 -04007249
7250 if (count < 0)
7251 {
7252 return gl::error(GL_INVALID_VALUE);
7253 }
7254
7255 for (int i = 0; i < count; i++)
7256 {
7257 samplers[i] = context->createSampler();
7258 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007259 }
7260}
7261
7262void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7263{
7264 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7265
Geoff Langbfdea662014-07-23 14:16:32 -04007266 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007267
Geoff Langbfdea662014-07-23 14:16:32 -04007268 if (context)
7269 {
7270 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007271 {
Geoff Langbfdea662014-07-23 14:16:32 -04007272 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007273 }
Geoff Langbfdea662014-07-23 14:16:32 -04007274
7275 if (count < 0)
7276 {
7277 return gl::error(GL_INVALID_VALUE);
7278 }
7279
7280 for (int i = 0; i < count; i++)
7281 {
7282 context->deleteSampler(samplers[i]);
7283 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007284 }
7285}
7286
7287GLboolean __stdcall glIsSampler(GLuint sampler)
7288{
7289 EVENT("(GLuint sampler = %u)", sampler);
7290
Geoff Langbfdea662014-07-23 14:16:32 -04007291 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007292
Geoff Langbfdea662014-07-23 14:16:32 -04007293 if (context)
7294 {
7295 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007296 {
Geoff Langbfdea662014-07-23 14:16:32 -04007297 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007298 }
Geoff Langbfdea662014-07-23 14:16:32 -04007299
7300 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007301 }
7302
7303 return GL_FALSE;
7304}
7305
7306void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7307{
7308 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7309
Geoff Langbfdea662014-07-23 14:16:32 -04007310 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007311
Geoff Langbfdea662014-07-23 14:16:32 -04007312 if (context)
7313 {
7314 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007315 {
Geoff Langbfdea662014-07-23 14:16:32 -04007316 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007317 }
Geoff Langbfdea662014-07-23 14:16:32 -04007318
7319 if (sampler != 0 && !context->isSampler(sampler))
7320 {
7321 return gl::error(GL_INVALID_OPERATION);
7322 }
7323
7324 if (unit >= context->getMaximumCombinedTextureImageUnits())
7325 {
7326 return gl::error(GL_INVALID_VALUE);
7327 }
7328
7329 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007330 }
7331}
7332
7333void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7334{
7335 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7336
Geoff Langbfdea662014-07-23 14:16:32 -04007337 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007338
Geoff Langbfdea662014-07-23 14:16:32 -04007339 if (context)
7340 {
7341 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007342 {
Geoff Langbfdea662014-07-23 14:16:32 -04007343 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007344 }
Geoff Langbfdea662014-07-23 14:16:32 -04007345
7346 if (!gl::ValidateSamplerObjectParameter(pname))
7347 {
7348 return;
7349 }
7350
7351 if (!gl::ValidateTexParamParameters(context, pname, param))
7352 {
7353 return;
7354 }
7355
7356 if (!context->isSampler(sampler))
7357 {
7358 return gl::error(GL_INVALID_OPERATION);
7359 }
7360
7361 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007362 }
7363}
7364
7365void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7366{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007367 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007368}
7369
7370void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7371{
7372 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7373
Geoff Langbfdea662014-07-23 14:16:32 -04007374 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007375
Geoff Langbfdea662014-07-23 14:16:32 -04007376 if (context)
7377 {
7378 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007379 {
Geoff Langbfdea662014-07-23 14:16:32 -04007380 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007381 }
Geoff Langbfdea662014-07-23 14:16:32 -04007382
7383 if (!gl::ValidateSamplerObjectParameter(pname))
7384 {
7385 return;
7386 }
7387
7388 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7389 {
7390 return;
7391 }
7392
7393 if (!context->isSampler(sampler))
7394 {
7395 return gl::error(GL_INVALID_OPERATION);
7396 }
7397
7398 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007399 }
7400}
7401
7402void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7403{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007404 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007405}
7406
7407void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7408{
7409 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7410
Geoff Langbfdea662014-07-23 14:16:32 -04007411 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007412
Geoff Langbfdea662014-07-23 14:16:32 -04007413 if (context)
7414 {
7415 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007416 {
Geoff Langbfdea662014-07-23 14:16:32 -04007417 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007418 }
Geoff Langbfdea662014-07-23 14:16:32 -04007419
7420 if (!gl::ValidateSamplerObjectParameter(pname))
7421 {
7422 return;
7423 }
7424
7425 if (!context->isSampler(sampler))
7426 {
7427 return gl::error(GL_INVALID_OPERATION);
7428 }
7429
7430 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007431 }
7432}
7433
7434void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7435{
7436 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7437
Geoff Langbfdea662014-07-23 14:16:32 -04007438 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007439
Geoff Langbfdea662014-07-23 14:16:32 -04007440 if (context)
7441 {
7442 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007443 {
Geoff Langbfdea662014-07-23 14:16:32 -04007444 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007445 }
Geoff Langbfdea662014-07-23 14:16:32 -04007446
7447 if (!gl::ValidateSamplerObjectParameter(pname))
7448 {
7449 return;
7450 }
7451
7452 if (!context->isSampler(sampler))
7453 {
7454 return gl::error(GL_INVALID_OPERATION);
7455 }
7456
7457 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007458 }
7459}
7460
7461void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7462{
7463 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7464
Geoff Langbfdea662014-07-23 14:16:32 -04007465 if (index >= gl::MAX_VERTEX_ATTRIBS)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007466 {
Geoff Langbfdea662014-07-23 14:16:32 -04007467 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007468 }
Geoff Langbfdea662014-07-23 14:16:32 -04007469
7470 gl::Context *context = gl::getNonLostContext();
7471
7472 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007473 {
Geoff Langbfdea662014-07-23 14:16:32 -04007474 if (context->getClientVersion() < 3)
7475 {
7476 return gl::error(GL_INVALID_OPERATION);
7477 }
7478
7479 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007480 }
7481}
7482
7483void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7484{
7485 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7486
Geoff Langbfdea662014-07-23 14:16:32 -04007487 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007488
Geoff Langbfdea662014-07-23 14:16:32 -04007489 if (context)
7490 {
7491 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007492 {
Geoff Langbfdea662014-07-23 14:16:32 -04007493 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007494 }
Geoff Langbfdea662014-07-23 14:16:32 -04007495
7496 switch (target)
7497 {
7498 case GL_TRANSFORM_FEEDBACK:
7499 {
7500 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7501 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7502 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7503 {
7504 return gl::error(GL_INVALID_OPERATION);
7505 }
7506
7507 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7508 if (context->getTransformFeedback(id) == NULL)
7509 {
7510 return gl::error(GL_INVALID_OPERATION);
7511 }
7512
7513 context->bindTransformFeedback(id);
7514 }
7515 break;
7516
7517 default:
7518 return gl::error(GL_INVALID_ENUM);
7519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007520 }
7521}
7522
7523void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7524{
7525 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7526
Geoff Langbfdea662014-07-23 14:16:32 -04007527 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007528
Geoff Langbfdea662014-07-23 14:16:32 -04007529 if (context)
7530 {
7531 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007532 {
Geoff Langbfdea662014-07-23 14:16:32 -04007533 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007534 }
Geoff Langbfdea662014-07-23 14:16:32 -04007535
7536 for (int i = 0; i < n; i++)
7537 {
7538 context->deleteTransformFeedback(ids[i]);
7539 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007540 }
7541}
7542
7543void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7544{
7545 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7546
Geoff Langbfdea662014-07-23 14:16:32 -04007547 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007548
Geoff Langbfdea662014-07-23 14:16:32 -04007549 if (context)
7550 {
7551 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007552 {
Geoff Langbfdea662014-07-23 14:16:32 -04007553 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007554 }
Geoff Langbfdea662014-07-23 14:16:32 -04007555
7556 for (int i = 0; i < n; i++)
7557 {
7558 ids[i] = context->createTransformFeedback();
7559 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007560 }
7561}
7562
7563GLboolean __stdcall glIsTransformFeedback(GLuint id)
7564{
7565 EVENT("(GLuint id = %u)", id);
7566
Geoff Langbfdea662014-07-23 14:16:32 -04007567 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007568
Geoff Langbfdea662014-07-23 14:16:32 -04007569 if (context)
7570 {
7571 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007572 {
Geoff Langbfdea662014-07-23 14:16:32 -04007573 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007574 }
Geoff Langbfdea662014-07-23 14:16:32 -04007575
7576 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007577 }
7578
7579 return GL_FALSE;
7580}
7581
7582void __stdcall glPauseTransformFeedback(void)
7583{
7584 EVENT("(void)");
7585
Geoff Langbfdea662014-07-23 14:16:32 -04007586 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007587
Geoff Langbfdea662014-07-23 14:16:32 -04007588 if (context)
7589 {
7590 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007591 {
Geoff Langbfdea662014-07-23 14:16:32 -04007592 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007593 }
Geoff Langbfdea662014-07-23 14:16:32 -04007594
7595 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7596 ASSERT(transformFeedback != NULL);
7597
7598 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7599 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7600 {
7601 return gl::error(GL_INVALID_OPERATION);
7602 }
7603
7604 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007605 }
7606}
7607
7608void __stdcall glResumeTransformFeedback(void)
7609{
7610 EVENT("(void)");
7611
Geoff Langbfdea662014-07-23 14:16:32 -04007612 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007613
Geoff Langbfdea662014-07-23 14:16:32 -04007614 if (context)
7615 {
7616 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007617 {
Geoff Langbfdea662014-07-23 14:16:32 -04007618 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007619 }
Geoff Langbfdea662014-07-23 14:16:32 -04007620
7621 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7622 ASSERT(transformFeedback != NULL);
7623
7624 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7625 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7626 {
7627 return gl::error(GL_INVALID_OPERATION);
7628 }
7629
7630 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007631 }
7632}
7633
7634void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7635{
7636 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7637 program, bufSize, length, binaryFormat, binary);
7638
Geoff Langbfdea662014-07-23 14:16:32 -04007639 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007640
Geoff Langbfdea662014-07-23 14:16:32 -04007641 if (context)
7642 {
7643 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007644 {
Geoff Langbfdea662014-07-23 14:16:32 -04007645 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007646 }
Geoff Langbfdea662014-07-23 14:16:32 -04007647
7648 // glGetProgramBinary
7649 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007650 }
7651}
7652
7653void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7654{
7655 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7656 program, binaryFormat, binary, length);
7657
Geoff Langbfdea662014-07-23 14:16:32 -04007658 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007659
Geoff Langbfdea662014-07-23 14:16:32 -04007660 if (context)
7661 {
7662 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007663 {
Geoff Langbfdea662014-07-23 14:16:32 -04007664 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007665 }
Geoff Langbfdea662014-07-23 14:16:32 -04007666
7667 // glProgramBinary
7668 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007669 }
7670}
7671
7672void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7673{
7674 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7675 program, pname, value);
7676
Geoff Langbfdea662014-07-23 14:16:32 -04007677 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007678
Geoff Langbfdea662014-07-23 14:16:32 -04007679 if (context)
7680 {
7681 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007682 {
Geoff Langbfdea662014-07-23 14:16:32 -04007683 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007684 }
Geoff Langbfdea662014-07-23 14:16:32 -04007685
7686 // glProgramParameteri
7687 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007688 }
7689}
7690
7691void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7692{
7693 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7694 target, numAttachments, attachments);
7695
Geoff Langbfdea662014-07-23 14:16:32 -04007696 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007697
Geoff Langbfdea662014-07-23 14:16:32 -04007698 if (context)
7699 {
7700 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007701 {
Geoff Langbfdea662014-07-23 14:16:32 -04007702 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007703 }
Geoff Langbfdea662014-07-23 14:16:32 -04007704
7705 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7706 {
7707 return;
7708 }
7709
7710 GLuint maxDimension = context->getCaps().maxRenderbufferSize;
7711 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007712 }
7713}
7714
7715void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
7716{
7717 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
7718 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7719 target, numAttachments, attachments, x, y, width, height);
7720
Geoff Langbfdea662014-07-23 14:16:32 -04007721 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007722
Geoff Langbfdea662014-07-23 14:16:32 -04007723 if (context)
7724 {
7725 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007726 {
Geoff Langbfdea662014-07-23 14:16:32 -04007727 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007728 }
Geoff Langbfdea662014-07-23 14:16:32 -04007729
7730 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7731 {
7732 return;
7733 }
7734
7735 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007736 }
7737}
7738
7739void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7740{
7741 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7742 target, levels, internalformat, width, height);
7743
Geoff Langbfdea662014-07-23 14:16:32 -04007744 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007745
Geoff Langbfdea662014-07-23 14:16:32 -04007746 if (context)
7747 {
7748 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007749 {
Geoff Langbfdea662014-07-23 14:16:32 -04007750 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007751 }
Geoff Langbfdea662014-07-23 14:16:32 -04007752
7753 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
7754 {
7755 return;
7756 }
7757
7758 switch (target)
7759 {
7760 case GL_TEXTURE_2D:
7761 {
7762 gl::Texture2D *texture2d = context->getTexture2D();
7763 texture2d->storage(levels, internalformat, width, height);
7764 }
7765 break;
7766
7767 case GL_TEXTURE_CUBE_MAP:
7768 {
7769 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7770 textureCube->storage(levels, internalformat, width);
7771 }
7772 break;
7773
7774 default:
7775 return gl::error(GL_INVALID_ENUM);
7776 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007777 }
7778}
7779
7780void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
7781{
7782 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
7783 "GLsizei height = %d, GLsizei depth = %d)",
7784 target, levels, internalformat, width, height, depth);
7785
Geoff Langbfdea662014-07-23 14:16:32 -04007786 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007787
Geoff Langbfdea662014-07-23 14:16:32 -04007788 if (context)
7789 {
7790 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007791 {
Geoff Langbfdea662014-07-23 14:16:32 -04007792 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00007793 }
Geoff Langbfdea662014-07-23 14:16:32 -04007794
7795 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
7796 {
7797 return;
7798 }
7799
7800 switch (target)
7801 {
7802 case GL_TEXTURE_3D:
7803 {
7804 gl::Texture3D *texture3d = context->getTexture3D();
7805 texture3d->storage(levels, internalformat, width, height, depth);
7806 }
7807 break;
7808
7809 case GL_TEXTURE_2D_ARRAY:
7810 {
7811 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
7812 texture2darray->storage(levels, internalformat, width, height, depth);
7813 }
7814 break;
7815
7816 default:
7817 UNREACHABLE();
7818 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007819 }
7820}
7821
7822void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
7823{
7824 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
7825 "GLint* params = 0x%0.8p)",
7826 target, internalformat, pname, bufSize, params);
7827
Geoff Langbfdea662014-07-23 14:16:32 -04007828 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007829
Geoff Langbfdea662014-07-23 14:16:32 -04007830 if (context)
7831 {
7832 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007833 {
Geoff Langbfdea662014-07-23 14:16:32 -04007834 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007835 }
Geoff Langbfdea662014-07-23 14:16:32 -04007836
7837 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7838 if (!formatCaps.renderable)
7839 {
7840 return gl::error(GL_INVALID_ENUM);
7841 }
7842
7843 if (target != GL_RENDERBUFFER)
7844 {
7845 return gl::error(GL_INVALID_ENUM);
7846 }
7847
7848 if (bufSize < 0)
7849 {
7850 return gl::error(GL_INVALID_VALUE);
7851 }
7852
7853 switch (pname)
7854 {
7855 case GL_NUM_SAMPLE_COUNTS:
7856 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04007857 {
7858 *params = formatCaps.sampleCounts.size();
7859 }
Geoff Langbfdea662014-07-23 14:16:32 -04007860 break;
7861 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04007862 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04007863 break;
7864 default:
7865 return gl::error(GL_INVALID_ENUM);
7866 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007867 }
7868}
7869
7870// Extension functions
7871
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007872void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
7873 GLbitfield mask, GLenum filter)
7874{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007875 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007876 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
7877 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
7878 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
7879
Geoff Langbfdea662014-07-23 14:16:32 -04007880 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007881
Geoff Langbfdea662014-07-23 14:16:32 -04007882 if (context)
7883 {
7884 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
7885 dstX0, dstY0, dstX1, dstY1, mask, filter,
7886 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007887 {
Geoff Langbfdea662014-07-23 14:16:32 -04007888 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007889 }
Geoff Langbfdea662014-07-23 14:16:32 -04007890
7891 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
7892 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007893 }
7894}
7895
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007896void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
7897 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007899 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007900 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007901 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007902 target, level, internalformat, width, height, depth, border, format, type, pixels);
7903
Geoff Langbfdea662014-07-23 14:16:32 -04007904 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007905}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00007906
Geoff Langbfdea662014-07-23 14:16:32 -04007907void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007908 GLenum *binaryFormat, void *binary)
7909{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00007910 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 +00007911 program, bufSize, length, binaryFormat, binary);
7912
Geoff Langbfdea662014-07-23 14:16:32 -04007913 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007914
Geoff Langbfdea662014-07-23 14:16:32 -04007915 if (context)
7916 {
7917 gl::Program *programObject = context->getProgram(program);
7918
7919 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007920 {
Geoff Langbfdea662014-07-23 14:16:32 -04007921 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007922 }
Geoff Langbfdea662014-07-23 14:16:32 -04007923
7924 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7925
7926 if (!programBinary)
7927 {
7928 return gl::error(GL_INVALID_OPERATION);
7929 }
7930
Geoff Lang900013c2014-07-07 11:32:19 -04007931 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04007932 {
7933 return gl::error(GL_INVALID_OPERATION);
7934 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007935 }
7936}
7937
7938void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
7939 const void *binary, GLint length)
7940{
7941 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
7942 program, binaryFormat, binary, length);
7943
Geoff Langbfdea662014-07-23 14:16:32 -04007944 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007945
Geoff Langbfdea662014-07-23 14:16:32 -04007946 if (context)
7947 {
Geoff Lang900013c2014-07-07 11:32:19 -04007948 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
7949 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007950 {
Geoff Langbfdea662014-07-23 14:16:32 -04007951 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007952 }
Geoff Langbfdea662014-07-23 14:16:32 -04007953
7954 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04007955 if (!programObject)
7956 {
7957 return gl::error(GL_INVALID_OPERATION);
7958 }
7959
Geoff Lang900013c2014-07-07 11:32:19 -04007960 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007961 }
7962}
7963
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007964void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
7965{
7966 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
7967
Geoff Langbfdea662014-07-23 14:16:32 -04007968 gl::Context *context = gl::getNonLostContext();
7969
7970 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007971 {
Geoff Langbfdea662014-07-23 14:16:32 -04007972 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007973 {
Geoff Langbfdea662014-07-23 14:16:32 -04007974 return gl::error(GL_INVALID_VALUE);
7975 }
7976
7977 if (context->getState().getDrawFramebuffer()->id() == 0)
7978 {
7979 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007980 {
Geoff Langbfdea662014-07-23 14:16:32 -04007981 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007982 }
7983
Geoff Langbfdea662014-07-23 14:16:32 -04007984 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007985 {
Geoff Langbfdea662014-07-23 14:16:32 -04007986 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00007987 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007988 }
Geoff Langbfdea662014-07-23 14:16:32 -04007989 else
7990 {
7991 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
7992 {
7993 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
7994 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
7995 {
7996 return gl::error(GL_INVALID_OPERATION);
7997 }
7998 }
7999 }
8000
8001 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8002
8003 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8004 {
8005 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8006 }
8007
8008 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8009 {
8010 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8011 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008012 }
8013}
8014
Shannon Woodsb3801742014-03-27 14:59:19 -04008015void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8016{
8017 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8018
Geoff Langbfdea662014-07-23 14:16:32 -04008019 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008020
Geoff Langbfdea662014-07-23 14:16:32 -04008021 if (context)
8022 {
8023 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008024 {
Geoff Langbfdea662014-07-23 14:16:32 -04008025 return gl::error(GL_INVALID_ENUM);
Shannon Woodsb3801742014-03-27 14:59:19 -04008026 }
Geoff Langbfdea662014-07-23 14:16:32 -04008027
8028 if (pname != GL_BUFFER_MAP_POINTER)
8029 {
8030 return gl::error(GL_INVALID_ENUM);
8031 }
8032
8033 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8034
8035 if (!buffer || !buffer->isMapped())
8036 {
8037 *params = NULL;
8038 }
8039 else
8040 {
8041 *params = buffer->getMapPointer();
8042 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008043 }
8044}
8045
8046void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8047{
8048 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8049
Geoff Langbfdea662014-07-23 14:16:32 -04008050 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008051
Geoff Langbfdea662014-07-23 14:16:32 -04008052 if (context)
8053 {
8054 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008055 {
Geoff Langbfdea662014-07-23 14:16:32 -04008056 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woodsb3801742014-03-27 14:59:19 -04008057 }
Geoff Langbfdea662014-07-23 14:16:32 -04008058
8059 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8060
8061 if (buffer == NULL)
8062 {
8063 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8064 }
8065
8066 if (access != GL_WRITE_ONLY_OES)
8067 {
8068 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
8069 }
8070
8071 if (buffer->isMapped())
8072 {
8073 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8074 }
8075
8076 return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
Shannon Woodsb3801742014-03-27 14:59:19 -04008077 }
8078
8079 return NULL;
8080}
8081
8082GLboolean __stdcall glUnmapBufferOES(GLenum target)
8083{
8084 EVENT("(GLenum target = 0x%X)", target);
8085
Geoff Langbfdea662014-07-23 14:16:32 -04008086 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008087
Geoff Langbfdea662014-07-23 14:16:32 -04008088 if (context)
8089 {
8090 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008091 {
Geoff Langbfdea662014-07-23 14:16:32 -04008092 return gl::error(GL_INVALID_ENUM, GL_FALSE);
Shannon Woodsb3801742014-03-27 14:59:19 -04008093 }
Geoff Langbfdea662014-07-23 14:16:32 -04008094
8095 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8096
8097 if (buffer == NULL || !buffer->isMapped())
8098 {
8099 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8100 }
8101
8102 // TODO: detect if we had corruption. if so, throw an error and return false.
8103
8104 buffer->unmap();
8105
8106 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008107 }
8108
8109 return GL_FALSE;
8110}
8111
Shannon Woods916e7692014-03-27 16:58:22 -04008112void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8113{
8114 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8115 target, offset, length, access);
8116
Geoff Langbfdea662014-07-23 14:16:32 -04008117 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008118
Geoff Langbfdea662014-07-23 14:16:32 -04008119 if (context)
8120 {
8121 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008122 {
Geoff Langbfdea662014-07-23 14:16:32 -04008123 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woods916e7692014-03-27 16:58:22 -04008124 }
Geoff Langbfdea662014-07-23 14:16:32 -04008125
8126 if (offset < 0 || length < 0)
8127 {
8128 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8129 }
8130
8131 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8132
8133 if (buffer == NULL)
8134 {
8135 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8136 }
8137
8138 // Check for buffer overflow
8139 size_t offsetSize = static_cast<size_t>(offset);
8140 size_t lengthSize = static_cast<size_t>(length);
8141
8142 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8143 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8144 {
8145 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8146 }
8147
8148 // Check for invalid bits in the mask
8149 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8150 GL_MAP_WRITE_BIT |
8151 GL_MAP_INVALIDATE_RANGE_BIT |
8152 GL_MAP_INVALIDATE_BUFFER_BIT |
8153 GL_MAP_FLUSH_EXPLICIT_BIT |
8154 GL_MAP_UNSYNCHRONIZED_BIT;
8155
8156 if (access & ~(allAccessBits))
8157 {
8158 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8159 }
8160
8161 if (length == 0 || buffer->isMapped())
8162 {
8163 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8164 }
8165
8166 // Check for invalid bit combinations
8167 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8168 {
8169 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8170 }
8171
8172 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8173 GL_MAP_INVALIDATE_BUFFER_BIT |
8174 GL_MAP_UNSYNCHRONIZED_BIT;
8175
8176 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8177 {
8178 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8179 }
8180
8181 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8182 {
8183 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8184 }
8185
8186 return buffer->mapRange(offset, length, access);
Shannon Woods916e7692014-03-27 16:58:22 -04008187 }
8188
8189 return NULL;
8190}
8191
8192void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8193{
8194 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8195
Geoff Langbfdea662014-07-23 14:16:32 -04008196 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008197
Geoff Langbfdea662014-07-23 14:16:32 -04008198 if (context)
8199 {
8200 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008201 {
Geoff Langbfdea662014-07-23 14:16:32 -04008202 return gl::error(GL_INVALID_VALUE);
Shannon Woods916e7692014-03-27 16:58:22 -04008203 }
Geoff Langbfdea662014-07-23 14:16:32 -04008204
8205 if (!gl::ValidBufferTarget(context, target))
8206 {
8207 return gl::error(GL_INVALID_ENUM);
8208 }
8209
8210 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8211
8212 if (buffer == NULL)
8213 {
8214 return gl::error(GL_INVALID_OPERATION);
8215 }
8216
8217 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8218 {
8219 return gl::error(GL_INVALID_OPERATION);
8220 }
8221
8222 // Check for buffer overflow
8223 size_t offsetSize = static_cast<size_t>(offset);
8224 size_t lengthSize = static_cast<size_t>(length);
8225
8226 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8227 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8228 {
8229 return gl::error(GL_INVALID_VALUE);
8230 }
8231
8232 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008233 }
8234}
8235
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008236__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8237{
8238 struct Extension
8239 {
8240 const char *name;
8241 __eglMustCastToProperFunctionPointerType address;
8242 };
8243
8244 static const Extension glExtensions[] =
8245 {
8246 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008247 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008248 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008249 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8250 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8251 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8252 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8253 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8254 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8255 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008256 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008257 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008258 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8259 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8260 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8261 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008262 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8263 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8264 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8265 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8266 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8267 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8268 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008269 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008270 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8271 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8272 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008273 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008274 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8275 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8276 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008277 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8278 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8279 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008280
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008281 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008282 {
8283 if (strcmp(procname, glExtensions[ext].name) == 0)
8284 {
8285 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8286 }
8287 }
8288
8289 return NULL;
8290}
8291
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008292// Non-public functions used by EGL
8293
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008294bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008295{
8296 EVENT("(egl::Surface* surface = 0x%0.8p)",
8297 surface);
8298
Geoff Langbfdea662014-07-23 14:16:32 -04008299 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008300
Geoff Langbfdea662014-07-23 14:16:32 -04008301 if (context)
8302 {
8303 gl::Texture2D *textureObject = context->getTexture2D();
8304 ASSERT(textureObject != NULL);
8305
8306 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008307 {
Geoff Langbfdea662014-07-23 14:16:32 -04008308 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008309 }
Geoff Langbfdea662014-07-23 14:16:32 -04008310
8311 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008312 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008313
8314 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008315}
8316
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008317}