blob: aeeddcca92d90d430c3580f0985d8bd53c02d247 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
Geoff Lang48dcae72014-02-05 16:28:24 -05003// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040024#include "libGLESv2/VertexArray.h"
Brandon Jones5bf98292014-06-06 17:19:38 -070025#include "libGLESv2/VertexAttribute.h"
Geoff Langc8058452014-02-03 12:04:11 -050026#include "libGLESv2/TransformFeedback.h"
Jamie Madille261b442014-06-25 12:42:21 -040027#include "libGLESv2/FramebufferAttachment.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000028
Geoff Lange8ebe7f2013-08-05 15:03:13 -040029#include "libGLESv2/validationES.h"
30#include "libGLESv2/validationES2.h"
31#include "libGLESv2/validationES3.h"
Jamie Madill55856b12014-01-02 13:59:50 -050032#include "libGLESv2/queryconversions.h"
Jamie Madill478fdb22013-07-19 16:36:59 -040033
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034extern "C"
35{
36
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000037// OpenGL ES 2.0 functions
38
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039void __stdcall glActiveTexture(GLenum texture)
40{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000041 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000042
Geoff Langbfdea662014-07-23 14:16:32 -040043 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000044
Geoff Langbfdea662014-07-23 14:16:32 -040045 if (context)
46 {
47 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000048 {
Geoff Langbfdea662014-07-23 14:16:32 -040049 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000050 }
Geoff Langbfdea662014-07-23 14:16:32 -040051
52 context->getState().setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000053 }
54}
55
56void __stdcall glAttachShader(GLuint program, GLuint shader)
57{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000058 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000059
Geoff Langbfdea662014-07-23 14:16:32 -040060 gl::Context *context = gl::getNonLostContext();
61
62 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000063 {
Geoff Langbfdea662014-07-23 14:16:32 -040064 gl::Program *programObject = context->getProgram(program);
65 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066
Geoff Langbfdea662014-07-23 14:16:32 -040067 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000068 {
Geoff Langbfdea662014-07-23 14:16:32 -040069 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000071 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072 }
Geoff Langbfdea662014-07-23 14:16:32 -040073 else
74 {
75 return gl::error(GL_INVALID_VALUE);
76 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000077 }
Geoff Langbfdea662014-07-23 14:16:32 -040078
79 if (!shaderObject)
80 {
81 if (context->getProgram(shader))
82 {
83 return gl::error(GL_INVALID_OPERATION);
84 }
85 else
86 {
87 return gl::error(GL_INVALID_VALUE);
88 }
89 }
90
91 if (!programObject->attachShader(shaderObject))
92 {
93 return gl::error(GL_INVALID_OPERATION);
94 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095 }
96}
97
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000098void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
99{
100 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
101
Geoff Langbfdea662014-07-23 14:16:32 -0400102 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000103
Geoff Langbfdea662014-07-23 14:16:32 -0400104 if (context)
105 {
106 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000107 {
Geoff Langbfdea662014-07-23 14:16:32 -0400108 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000109 }
Geoff Langbfdea662014-07-23 14:16:32 -0400110
111 context->beginQuery(target, id);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000112 }
113}
114
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000115void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000116{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000117 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000118
Geoff Langbfdea662014-07-23 14:16:32 -0400119 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120 {
Geoff Langbfdea662014-07-23 14:16:32 -0400121 return gl::error(GL_INVALID_VALUE);
122 }
123
124 gl::Context *context = gl::getNonLostContext();
125
126 if (context)
127 {
128 gl::Program *programObject = context->getProgram(program);
129
130 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000131 {
Geoff Langbfdea662014-07-23 14:16:32 -0400132 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000134 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135 }
Geoff Langbfdea662014-07-23 14:16:32 -0400136 else
137 {
138 return gl::error(GL_INVALID_VALUE);
139 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000140 }
Geoff Langbfdea662014-07-23 14:16:32 -0400141
142 if (strncmp(name, "gl_", 3) == 0)
143 {
144 return gl::error(GL_INVALID_OPERATION);
145 }
146
147 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000148 }
149}
150
151void __stdcall glBindBuffer(GLenum target, GLuint buffer)
152{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000153 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000154
Geoff Langbfdea662014-07-23 14:16:32 -0400155 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000156
Geoff Langbfdea662014-07-23 14:16:32 -0400157 if (context)
158 {
159 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000160 {
Geoff Langbfdea662014-07-23 14:16:32 -0400161 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000162 }
Geoff Langbfdea662014-07-23 14:16:32 -0400163
164 switch (target)
165 {
166 case GL_ARRAY_BUFFER:
167 context->bindArrayBuffer(buffer);
168 return;
169 case GL_ELEMENT_ARRAY_BUFFER:
170 context->bindElementArrayBuffer(buffer);
171 return;
172 case GL_COPY_READ_BUFFER:
173 context->bindCopyReadBuffer(buffer);
174 return;
175 case GL_COPY_WRITE_BUFFER:
176 context->bindCopyWriteBuffer(buffer);
177 return;
178 case GL_PIXEL_PACK_BUFFER:
179 context->bindPixelPackBuffer(buffer);
180 return;
181 case GL_PIXEL_UNPACK_BUFFER:
182 context->bindPixelUnpackBuffer(buffer);
183 return;
184 case GL_UNIFORM_BUFFER:
185 context->bindGenericUniformBuffer(buffer);
186 return;
187 case GL_TRANSFORM_FEEDBACK_BUFFER:
188 context->bindGenericTransformFeedbackBuffer(buffer);
189 return;
190 default:
191 return gl::error(GL_INVALID_ENUM);
192 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000193 }
194}
195
196void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
197{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000198 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000199
Geoff Langbfdea662014-07-23 14:16:32 -0400200 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000201 {
Geoff Langbfdea662014-07-23 14:16:32 -0400202 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000203 }
Geoff Langbfdea662014-07-23 14:16:32 -0400204
205 gl::Context *context = gl::getNonLostContext();
206
207 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000208 {
Geoff Langbfdea662014-07-23 14:16:32 -0400209 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
210 {
211 context->bindReadFramebuffer(framebuffer);
212 }
213
214 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
215 {
216 context->bindDrawFramebuffer(framebuffer);
217 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000218 }
219}
220
221void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
222{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000223 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000224
Geoff Langbfdea662014-07-23 14:16:32 -0400225 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000226 {
Geoff Langbfdea662014-07-23 14:16:32 -0400227 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000228 }
Geoff Langbfdea662014-07-23 14:16:32 -0400229
230 gl::Context *context = gl::getNonLostContext();
231
232 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000233 {
Geoff Langbfdea662014-07-23 14:16:32 -0400234 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000235 }
236}
237
238void __stdcall glBindTexture(GLenum target, GLuint texture)
239{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000240 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000241
Geoff Langbfdea662014-07-23 14:16:32 -0400242 gl::Context *context = gl::getNonLostContext();
243
244 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000245 {
Geoff Langbfdea662014-07-23 14:16:32 -0400246 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000247
Geoff Langbfdea662014-07-23 14:16:32 -0400248 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000249 {
Geoff Langbfdea662014-07-23 14:16:32 -0400250 return gl::error(GL_INVALID_OPERATION);
251 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000252
Geoff Langbfdea662014-07-23 14:16:32 -0400253 switch (target)
254 {
255 case GL_TEXTURE_2D:
256 context->bindTexture2D(texture);
257 return;
258 case GL_TEXTURE_CUBE_MAP:
259 context->bindTextureCubeMap(texture);
260 return;
261 case GL_TEXTURE_3D:
262 if (context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000263 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000264 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000265 }
Geoff Langbfdea662014-07-23 14:16:32 -0400266 context->bindTexture3D(texture);
267 return;
268 case GL_TEXTURE_2D_ARRAY:
269 if (context->getClientVersion() < 3)
270 {
271 return gl::error(GL_INVALID_ENUM);
272 }
273 context->bindTexture2DArray(texture);
274 return;
275 default:
276 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000277 }
278 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000279}
280
281void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
282{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000283 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000284 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000285
Geoff Langbfdea662014-07-23 14:16:32 -0400286 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287
Geoff Langbfdea662014-07-23 14:16:32 -0400288 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000289 {
Geoff Langbfdea662014-07-23 14:16:32 -0400290 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000291 }
292}
293
294void __stdcall glBlendEquation(GLenum mode)
295{
296 glBlendEquationSeparate(mode, mode);
297}
298
299void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
300{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000301 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000302
Geoff Langbfdea662014-07-23 14:16:32 -0400303 gl::Context *context = gl::getNonLostContext();
304
305 switch (modeRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000306 {
Geoff Langbfdea662014-07-23 14:16:32 -0400307 case GL_FUNC_ADD:
308 case GL_FUNC_SUBTRACT:
309 case GL_FUNC_REVERSE_SUBTRACT:
310 case GL_MIN:
311 case GL_MAX:
312 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000313
Geoff Langbfdea662014-07-23 14:16:32 -0400314 default:
315 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000316 }
Geoff Langbfdea662014-07-23 14:16:32 -0400317
318 switch (modeAlpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000319 {
Geoff Langbfdea662014-07-23 14:16:32 -0400320 case GL_FUNC_ADD:
321 case GL_FUNC_SUBTRACT:
322 case GL_FUNC_REVERSE_SUBTRACT:
323 case GL_MIN:
324 case GL_MAX:
325 break;
326
327 default:
328 return gl::error(GL_INVALID_ENUM);
329 }
330
331 if (context)
332 {
333 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000334 }
335}
336
337void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
338{
339 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
340}
341
342void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000344 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 +0000345 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000346
Geoff Langbfdea662014-07-23 14:16:32 -0400347 gl::Context *context = gl::getNonLostContext();
348
349 switch (srcRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000350 {
Geoff Langbfdea662014-07-23 14:16:32 -0400351 case GL_ZERO:
352 case GL_ONE:
353 case GL_SRC_COLOR:
354 case GL_ONE_MINUS_SRC_COLOR:
355 case GL_DST_COLOR:
356 case GL_ONE_MINUS_DST_COLOR:
357 case GL_SRC_ALPHA:
358 case GL_ONE_MINUS_SRC_ALPHA:
359 case GL_DST_ALPHA:
360 case GL_ONE_MINUS_DST_ALPHA:
361 case GL_CONSTANT_COLOR:
362 case GL_ONE_MINUS_CONSTANT_COLOR:
363 case GL_CONSTANT_ALPHA:
364 case GL_ONE_MINUS_CONSTANT_ALPHA:
365 case GL_SRC_ALPHA_SATURATE:
366 break;
367 default:
368 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000369 }
Geoff Langbfdea662014-07-23 14:16:32 -0400370
371 switch (dstRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000372 {
Geoff Langbfdea662014-07-23 14:16:32 -0400373 case GL_ZERO:
374 case GL_ONE:
375 case GL_SRC_COLOR:
376 case GL_ONE_MINUS_SRC_COLOR:
377 case GL_DST_COLOR:
378 case GL_ONE_MINUS_DST_COLOR:
379 case GL_SRC_ALPHA:
380 case GL_ONE_MINUS_SRC_ALPHA:
381 case GL_DST_ALPHA:
382 case GL_ONE_MINUS_DST_ALPHA:
383 case GL_CONSTANT_COLOR:
384 case GL_ONE_MINUS_CONSTANT_COLOR:
385 case GL_CONSTANT_ALPHA:
386 case GL_ONE_MINUS_CONSTANT_ALPHA:
387 break;
388
389 case GL_SRC_ALPHA_SATURATE:
390 if (!context || context->getClientVersion() < 3)
391 {
392 return gl::error(GL_INVALID_ENUM);
393 }
394 break;
395
396 default:
397 return gl::error(GL_INVALID_ENUM);
398 }
399
400 switch (srcAlpha)
401 {
402 case GL_ZERO:
403 case GL_ONE:
404 case GL_SRC_COLOR:
405 case GL_ONE_MINUS_SRC_COLOR:
406 case GL_DST_COLOR:
407 case GL_ONE_MINUS_DST_COLOR:
408 case GL_SRC_ALPHA:
409 case GL_ONE_MINUS_SRC_ALPHA:
410 case GL_DST_ALPHA:
411 case GL_ONE_MINUS_DST_ALPHA:
412 case GL_CONSTANT_COLOR:
413 case GL_ONE_MINUS_CONSTANT_COLOR:
414 case GL_CONSTANT_ALPHA:
415 case GL_ONE_MINUS_CONSTANT_ALPHA:
416 case GL_SRC_ALPHA_SATURATE:
417 break;
418 default:
419 return gl::error(GL_INVALID_ENUM);
420 }
421
422 switch (dstAlpha)
423 {
424 case GL_ZERO:
425 case GL_ONE:
426 case GL_SRC_COLOR:
427 case GL_ONE_MINUS_SRC_COLOR:
428 case GL_DST_COLOR:
429 case GL_ONE_MINUS_DST_COLOR:
430 case GL_SRC_ALPHA:
431 case GL_ONE_MINUS_SRC_ALPHA:
432 case GL_DST_ALPHA:
433 case GL_ONE_MINUS_DST_ALPHA:
434 case GL_CONSTANT_COLOR:
435 case GL_ONE_MINUS_CONSTANT_COLOR:
436 case GL_CONSTANT_ALPHA:
437 case GL_ONE_MINUS_CONSTANT_ALPHA:
438 break;
439
440 case GL_SRC_ALPHA_SATURATE:
441 if (!context || context->getClientVersion() < 3)
442 {
443 return gl::error(GL_INVALID_ENUM);
444 }
445 break;
446
447 default:
448 return gl::error(GL_INVALID_ENUM);
449 }
450
451 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
452 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
453
454 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
455 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
456
457 if (constantColorUsed && constantAlphaUsed)
458 {
459 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
460 return gl::error(GL_INVALID_OPERATION);
461 }
462
463 if (context)
464 {
465 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000466 }
467}
468
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000469void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000470{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000471 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 +0000472 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000473
Geoff Langbfdea662014-07-23 14:16:32 -0400474 if (size < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000475 {
Geoff Langbfdea662014-07-23 14:16:32 -0400476 return gl::error(GL_INVALID_VALUE);
477 }
478
479 gl::Context *context = gl::getNonLostContext();
480
481 switch (usage)
482 {
483 case GL_STREAM_DRAW:
484 case GL_STATIC_DRAW:
485 case GL_DYNAMIC_DRAW:
486 break;
487
488 case GL_STREAM_READ:
489 case GL_STREAM_COPY:
490 case GL_STATIC_READ:
491 case GL_STATIC_COPY:
492 case GL_DYNAMIC_READ:
493 case GL_DYNAMIC_COPY:
494 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000495 {
Geoff Langbfdea662014-07-23 14:16:32 -0400496 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000497 }
Geoff Langbfdea662014-07-23 14:16:32 -0400498 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000499
Geoff Langbfdea662014-07-23 14:16:32 -0400500 default:
501 return gl::error(GL_INVALID_ENUM);
502 }
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +0000503
Geoff Langbfdea662014-07-23 14:16:32 -0400504 if (context)
505 {
506 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000508 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000509 }
510
Geoff Langbfdea662014-07-23 14:16:32 -0400511 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
512
513 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000514 {
Geoff Langbfdea662014-07-23 14:16:32 -0400515 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000516 }
Geoff Langbfdea662014-07-23 14:16:32 -0400517
518 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000519 }
520}
521
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000522void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000524 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 +0000525 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000526
Geoff Langbfdea662014-07-23 14:16:32 -0400527 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000528 {
Geoff Langbfdea662014-07-23 14:16:32 -0400529 return gl::error(GL_INVALID_VALUE);
530 }
531
532 if (data == NULL)
533 {
534 return;
535 }
536
537 gl::Context *context = gl::getNonLostContext();
538
539 if (context)
540 {
541 if (!gl::ValidBufferTarget(context, target))
542 {
543 return gl::error(GL_INVALID_ENUM);
544 }
545
546 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
547
548 if (!buffer)
549 {
550 return gl::error(GL_INVALID_OPERATION);
551 }
552
553 if (buffer->isMapped())
554 {
555 return gl::error(GL_INVALID_OPERATION);
556 }
557
558 // Check for possible overflow of size + offset
559 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
560 {
561 return gl::error(GL_OUT_OF_MEMORY);
562 }
563
564 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000566 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000567 }
568
Geoff Langbfdea662014-07-23 14:16:32 -0400569 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000570 }
571}
572
573GLenum __stdcall glCheckFramebufferStatus(GLenum target)
574{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000575 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000576
Geoff Langbfdea662014-07-23 14:16:32 -0400577 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000578 {
Geoff Langbfdea662014-07-23 14:16:32 -0400579 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000580 }
Geoff Langbfdea662014-07-23 14:16:32 -0400581
582 gl::Context *context = gl::getNonLostContext();
583
584 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000585 {
Geoff Langbfdea662014-07-23 14:16:32 -0400586 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
587 ASSERT(framebuffer);
588 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000589 }
590
591 return 0;
592}
593
594void __stdcall glClear(GLbitfield mask)
595{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000596 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000597
Geoff Langbfdea662014-07-23 14:16:32 -0400598 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000599
Geoff Langbfdea662014-07-23 14:16:32 -0400600 if (context)
601 {
602 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
603
604 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000605 {
Geoff Langbfdea662014-07-23 14:16:32 -0400606 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000607 }
Geoff Langbfdea662014-07-23 14:16:32 -0400608
609 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
610 {
611 return gl::error(GL_INVALID_VALUE);
612 }
613
614 context->clear(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000615 }
616}
617
618void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
619{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000620 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000621 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000622
Geoff Langbfdea662014-07-23 14:16:32 -0400623 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000624
Geoff Langbfdea662014-07-23 14:16:32 -0400625 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000626 {
Geoff Langbfdea662014-07-23 14:16:32 -0400627 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000628 }
629}
630
631void __stdcall glClearDepthf(GLclampf depth)
632{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000633 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000634
Geoff Langbfdea662014-07-23 14:16:32 -0400635 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000636
Geoff Langbfdea662014-07-23 14:16:32 -0400637 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000638 {
Geoff Langbfdea662014-07-23 14:16:32 -0400639 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000640 }
641}
642
643void __stdcall glClearStencil(GLint s)
644{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000645 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000646
Geoff Langbfdea662014-07-23 14:16:32 -0400647 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000648
Geoff Langbfdea662014-07-23 14:16:32 -0400649 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000650 {
Geoff Langbfdea662014-07-23 14:16:32 -0400651 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000652 }
653}
654
655void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
656{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000657 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000658 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000659
Geoff Langbfdea662014-07-23 14:16:32 -0400660 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000661
Geoff Langbfdea662014-07-23 14:16:32 -0400662 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000663 {
Geoff Langbfdea662014-07-23 14:16:32 -0400664 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000665 }
666}
667
668void __stdcall glCompileShader(GLuint shader)
669{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000670 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000671
Geoff Langbfdea662014-07-23 14:16:32 -0400672 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000673
Geoff Langbfdea662014-07-23 14:16:32 -0400674 if (context)
675 {
676 gl::Shader *shaderObject = context->getShader(shader);
677
678 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000679 {
Geoff Langbfdea662014-07-23 14:16:32 -0400680 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000681 {
Geoff Langbfdea662014-07-23 14:16:32 -0400682 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000683 }
Geoff Langbfdea662014-07-23 14:16:32 -0400684 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000686 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000687 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000688 }
Geoff Langbfdea662014-07-23 14:16:32 -0400689
690 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000691 }
Geoff Langbfdea662014-07-23 14:16:32 -0400692}
693
694void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
695 GLint border, GLsizei imageSize, const GLvoid* data)
696{
697 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
698 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
699 target, level, internalformat, width, height, border, imageSize, data);
700
701 gl::Context *context = gl::getNonLostContext();
702
703 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000704 {
Geoff Langbfdea662014-07-23 14:16:32 -0400705 if (context->getClientVersion() < 3 &&
706 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
707 0, 0, width, height, border, GL_NONE, GL_NONE, data))
708 {
709 return;
710 }
711
712 if (context->getClientVersion() >= 3 &&
713 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
714 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
715 {
716 return;
717 }
718
Geoff Lang5d601382014-07-22 15:14:06 -0400719 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
720 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400721 {
722 return gl::error(GL_INVALID_VALUE);
723 }
724
725 switch (target)
726 {
727 case GL_TEXTURE_2D:
728 {
729 gl::Texture2D *texture = context->getTexture2D();
730 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
731 }
732 break;
733
734 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
735 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
736 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
737 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
738 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
739 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
740 {
741 gl::TextureCubeMap *texture = context->getTextureCubeMap();
742 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
743 }
744 break;
745
746 default:
747 return gl::error(GL_INVALID_ENUM);
748 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000749 }
750}
751
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000752void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
753 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000754{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000755 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000756 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000757 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000758 target, level, xoffset, yoffset, width, height, format, imageSize, data);
759
Geoff Langbfdea662014-07-23 14:16:32 -0400760 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +0000761
Geoff Langbfdea662014-07-23 14:16:32 -0400762 if (context)
763 {
764 if (context->getClientVersion() < 3 &&
765 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
766 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000767 {
Geoff Langbfdea662014-07-23 14:16:32 -0400768 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000769 }
Geoff Langbfdea662014-07-23 14:16:32 -0400770
771 if (context->getClientVersion() >= 3 &&
772 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
773 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
774 {
775 return;
776 }
777
Geoff Lang5d601382014-07-22 15:14:06 -0400778 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
779 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400780 {
781 return gl::error(GL_INVALID_VALUE);
782 }
783
784 switch (target)
785 {
786 case GL_TEXTURE_2D:
787 {
788 gl::Texture2D *texture = context->getTexture2D();
789 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
790 }
791 break;
792
793 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
794 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
795 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
797 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
798 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
799 {
800 gl::TextureCubeMap *texture = context->getTextureCubeMap();
801 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
802 }
803 break;
804
805 default:
806 return gl::error(GL_INVALID_ENUM);
807 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000808 }
809}
810
811void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
812{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000813 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000814 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000815 target, level, internalformat, x, y, width, height, border);
816
Geoff Langbfdea662014-07-23 14:16:32 -0400817 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000818
Geoff Langbfdea662014-07-23 14:16:32 -0400819 if (context)
820 {
821 if (context->getClientVersion() < 3 &&
822 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
823 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000824 {
Geoff Langbfdea662014-07-23 14:16:32 -0400825 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000826 }
Geoff Langbfdea662014-07-23 14:16:32 -0400827
828 if (context->getClientVersion() >= 3 &&
829 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
830 0, 0, 0, x, y, width, height, border))
831 {
832 return;
833 }
834
835 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
836
837 switch (target)
838 {
839 case GL_TEXTURE_2D:
840 {
841 gl::Texture2D *texture = context->getTexture2D();
842 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
843 }
844 break;
845
846 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
847 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
848 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
852 {
853 gl::TextureCubeMap *texture = context->getTextureCubeMap();
854 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
855 }
856 break;
857
858 default:
859 return gl::error(GL_INVALID_ENUM);
860 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000861 }
862}
863
864void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
865{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000866 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000867 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000868 target, level, xoffset, yoffset, x, y, width, height);
869
Geoff Langbfdea662014-07-23 14:16:32 -0400870 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000871
Geoff Langbfdea662014-07-23 14:16:32 -0400872 if (context)
873 {
874 if (context->getClientVersion() < 3 &&
875 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
876 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000877 {
Geoff Langbfdea662014-07-23 14:16:32 -0400878 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000879 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000880
Geoff Langbfdea662014-07-23 14:16:32 -0400881 if (context->getClientVersion() >= 3 &&
882 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
883 xoffset, yoffset, 0, x, y, width, height, 0))
884 {
885 return;
886 }
887
888 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
889
890 switch (target)
891 {
892 case GL_TEXTURE_2D:
893 {
894 gl::Texture2D *texture = context->getTexture2D();
895 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
896 }
897 break;
898
899 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
900 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
901 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
902 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
903 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
904 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
905 {
906 gl::TextureCubeMap *texture = context->getTextureCubeMap();
907 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
908 }
909 break;
910
911 default:
912 return gl::error(GL_INVALID_ENUM);
913 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000914 }
915}
916
917GLuint __stdcall glCreateProgram(void)
918{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000919 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000920
Geoff Langbfdea662014-07-23 14:16:32 -0400921 gl::Context *context = gl::getNonLostContext();
922 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000923 {
Geoff Langbfdea662014-07-23 14:16:32 -0400924 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000925 }
926
927 return 0;
928}
929
930GLuint __stdcall glCreateShader(GLenum type)
931{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000932 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000933
Geoff Langbfdea662014-07-23 14:16:32 -0400934 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000935
Geoff Langbfdea662014-07-23 14:16:32 -0400936 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000937 {
Geoff Langbfdea662014-07-23 14:16:32 -0400938 switch (type)
939 {
940 case GL_FRAGMENT_SHADER:
941 case GL_VERTEX_SHADER:
942 return context->createShader(type);
943 default:
944 return gl::error(GL_INVALID_ENUM, 0);
945 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000946 }
947
948 return 0;
949}
950
951void __stdcall glCullFace(GLenum mode)
952{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000953 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000954
Geoff Langbfdea662014-07-23 14:16:32 -0400955 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000956 {
Geoff Langbfdea662014-07-23 14:16:32 -0400957 case GL_FRONT:
958 case GL_BACK:
959 case GL_FRONT_AND_BACK:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000960 {
Geoff Langbfdea662014-07-23 14:16:32 -0400961 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000962
Geoff Langbfdea662014-07-23 14:16:32 -0400963 if (context)
964 {
965 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000966 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000967 }
Geoff Langbfdea662014-07-23 14:16:32 -0400968 break;
969 default:
970 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000971 }
972}
973
974void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000976 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000977
Geoff Langbfdea662014-07-23 14:16:32 -0400978 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000979 {
Geoff Langbfdea662014-07-23 14:16:32 -0400980 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000981 }
Geoff Langbfdea662014-07-23 14:16:32 -0400982
983 gl::Context *context = gl::getNonLostContext();
984
985 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000986 {
Geoff Langbfdea662014-07-23 14:16:32 -0400987 for (int i = 0; i < n; i++)
988 {
989 context->deleteBuffer(buffers[i]);
990 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000991 }
992}
993
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000994void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
995{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000996 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000997
Geoff Langbfdea662014-07-23 14:16:32 -0400998 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000999 {
Geoff Langbfdea662014-07-23 14:16:32 -04001000 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001001 }
Geoff Langbfdea662014-07-23 14:16:32 -04001002
1003 gl::Context *context = gl::getNonLostContext();
1004
1005 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001006 {
Geoff Langbfdea662014-07-23 14:16:32 -04001007 for (int i = 0; i < n; i++)
1008 {
1009 context->deleteFenceNV(fences[i]);
1010 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001011 }
1012}
1013
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001014void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1015{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001016 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001017
Geoff Langbfdea662014-07-23 14:16:32 -04001018 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001019 {
Geoff Langbfdea662014-07-23 14:16:32 -04001020 return gl::error(GL_INVALID_VALUE);
1021 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001022
Geoff Langbfdea662014-07-23 14:16:32 -04001023 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001024
Geoff Langbfdea662014-07-23 14:16:32 -04001025 if (context)
1026 {
1027 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001028 {
Geoff Langbfdea662014-07-23 14:16:32 -04001029 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001030 {
Geoff Langbfdea662014-07-23 14:16:32 -04001031 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001032 }
1033 }
1034 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001035}
1036
1037void __stdcall glDeleteProgram(GLuint program)
1038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001039 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001040
Geoff Langbfdea662014-07-23 14:16:32 -04001041 if (program == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001042 {
Geoff Langbfdea662014-07-23 14:16:32 -04001043 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001044 }
Geoff Langbfdea662014-07-23 14:16:32 -04001045
1046 gl::Context *context = gl::getNonLostContext();
1047
1048 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001049 {
Geoff Langbfdea662014-07-23 14:16:32 -04001050 if (!context->getProgram(program))
1051 {
1052 if(context->getShader(program))
1053 {
1054 return gl::error(GL_INVALID_OPERATION);
1055 }
1056 else
1057 {
1058 return gl::error(GL_INVALID_VALUE);
1059 }
1060 }
1061
1062 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001063 }
1064}
1065
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001066void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1067{
1068 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1069
Geoff Langbfdea662014-07-23 14:16:32 -04001070 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001071 {
Geoff Langbfdea662014-07-23 14:16:32 -04001072 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001073 }
Geoff Langbfdea662014-07-23 14:16:32 -04001074
1075 gl::Context *context = gl::getNonLostContext();
1076
1077 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001078 {
Geoff Langbfdea662014-07-23 14:16:32 -04001079 for (int i = 0; i < n; i++)
1080 {
1081 context->deleteQuery(ids[i]);
1082 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001083 }
1084}
1085
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001086void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1087{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001088 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001089
Geoff Langbfdea662014-07-23 14:16:32 -04001090 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001091 {
Geoff Langbfdea662014-07-23 14:16:32 -04001092 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001093 }
Geoff Langbfdea662014-07-23 14:16:32 -04001094
1095 gl::Context *context = gl::getNonLostContext();
1096
1097 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001098 {
Geoff Langbfdea662014-07-23 14:16:32 -04001099 for (int i = 0; i < n; i++)
1100 {
1101 context->deleteRenderbuffer(renderbuffers[i]);
1102 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001103 }
1104}
1105
1106void __stdcall glDeleteShader(GLuint shader)
1107{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001108 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001109
Geoff Langbfdea662014-07-23 14:16:32 -04001110 if (shader == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001111 {
Geoff Langbfdea662014-07-23 14:16:32 -04001112 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001113 }
Geoff Langbfdea662014-07-23 14:16:32 -04001114
1115 gl::Context *context = gl::getNonLostContext();
1116
1117 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001118 {
Geoff Langbfdea662014-07-23 14:16:32 -04001119 if (!context->getShader(shader))
1120 {
1121 if(context->getProgram(shader))
1122 {
1123 return gl::error(GL_INVALID_OPERATION);
1124 }
1125 else
1126 {
1127 return gl::error(GL_INVALID_VALUE);
1128 }
1129 }
1130
1131 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001132 }
1133}
1134
1135void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001137 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001138
Geoff Langbfdea662014-07-23 14:16:32 -04001139 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001140 {
Geoff Langbfdea662014-07-23 14:16:32 -04001141 return gl::error(GL_INVALID_VALUE);
1142 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001143
Geoff Langbfdea662014-07-23 14:16:32 -04001144 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001145
Geoff Langbfdea662014-07-23 14:16:32 -04001146 if (context)
1147 {
1148 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001149 {
Geoff Langbfdea662014-07-23 14:16:32 -04001150 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001151 {
Geoff Langbfdea662014-07-23 14:16:32 -04001152 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001153 }
1154 }
1155 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001156}
1157
1158void __stdcall glDepthFunc(GLenum func)
1159{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001160 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001161
Geoff Langbfdea662014-07-23 14:16:32 -04001162 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001163 {
Geoff Langbfdea662014-07-23 14:16:32 -04001164 case GL_NEVER:
1165 case GL_ALWAYS:
1166 case GL_LESS:
1167 case GL_LEQUAL:
1168 case GL_EQUAL:
1169 case GL_GREATER:
1170 case GL_GEQUAL:
1171 case GL_NOTEQUAL:
1172 break;
1173 default:
1174 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001175 }
Geoff Langbfdea662014-07-23 14:16:32 -04001176
1177 gl::Context *context = gl::getNonLostContext();
1178
1179 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001180 {
Geoff Langbfdea662014-07-23 14:16:32 -04001181 context->getState().setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001182 }
1183}
1184
1185void __stdcall glDepthMask(GLboolean flag)
1186{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001187 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001188
Geoff Langbfdea662014-07-23 14:16:32 -04001189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001190
Geoff Langbfdea662014-07-23 14:16:32 -04001191 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001192 {
Geoff Langbfdea662014-07-23 14:16:32 -04001193 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001194 }
1195}
1196
1197void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1198{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001199 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001200
Geoff Langbfdea662014-07-23 14:16:32 -04001201 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001202
Geoff Langbfdea662014-07-23 14:16:32 -04001203 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001204 {
Geoff Langbfdea662014-07-23 14:16:32 -04001205 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001206 }
1207}
1208
1209void __stdcall glDetachShader(GLuint program, GLuint shader)
1210{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001211 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001212
Geoff Langbfdea662014-07-23 14:16:32 -04001213 gl::Context *context = gl::getNonLostContext();
1214
1215 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001216 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001217
Geoff Langbfdea662014-07-23 14:16:32 -04001218 gl::Program *programObject = context->getProgram(program);
1219 gl::Shader *shaderObject = context->getShader(shader);
1220
1221 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001222 {
Geoff Langbfdea662014-07-23 14:16:32 -04001223 gl::Shader *shaderByProgramHandle;
1224 shaderByProgramHandle = context->getShader(program);
1225 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001226 {
Geoff Langbfdea662014-07-23 14:16:32 -04001227 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001228 }
Geoff Langbfdea662014-07-23 14:16:32 -04001229 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001231 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001232 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001233 }
Geoff Langbfdea662014-07-23 14:16:32 -04001234
1235 if (!shaderObject)
1236 {
1237 gl::Program *programByShaderHandle = context->getProgram(shader);
1238 if (!programByShaderHandle)
1239 {
1240 return gl::error(GL_INVALID_VALUE);
1241 }
1242 else
1243 {
1244 return gl::error(GL_INVALID_OPERATION);
1245 }
1246 }
1247
1248 if (!programObject->detachShader(shaderObject))
1249 {
1250 return gl::error(GL_INVALID_OPERATION);
1251 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001252 }
1253}
1254
1255void __stdcall glDisable(GLenum cap)
1256{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001257 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001258
Geoff Langbfdea662014-07-23 14:16:32 -04001259 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001260
Geoff Langbfdea662014-07-23 14:16:32 -04001261 if (context)
1262 {
1263 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001264 {
Geoff Langbfdea662014-07-23 14:16:32 -04001265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266 }
Geoff Langbfdea662014-07-23 14:16:32 -04001267
1268 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001269 }
1270}
1271
1272void __stdcall glDisableVertexAttribArray(GLuint index)
1273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001274 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001275
Geoff Langbfdea662014-07-23 14:16:32 -04001276 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277 {
Geoff Langbfdea662014-07-23 14:16:32 -04001278 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001279 }
Geoff Langbfdea662014-07-23 14:16:32 -04001280
1281 gl::Context *context = gl::getNonLostContext();
1282
1283 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001284 {
Geoff Langbfdea662014-07-23 14:16:32 -04001285 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001286 }
1287}
1288
1289void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001291 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001292
Geoff Langbfdea662014-07-23 14:16:32 -04001293 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001294
Geoff Langbfdea662014-07-23 14:16:32 -04001295 if (context)
1296 {
Jamie Madill2b976812014-08-25 15:47:49 -04001297 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001298 {
Geoff Langbfdea662014-07-23 14:16:32 -04001299 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001300 }
Geoff Langbfdea662014-07-23 14:16:32 -04001301
1302 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001303 }
1304}
1305
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001306void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1307{
1308 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1309
Geoff Langbfdea662014-07-23 14:16:32 -04001310 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001311
Geoff Langbfdea662014-07-23 14:16:32 -04001312 if (context)
1313 {
1314 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001315 {
Geoff Langbfdea662014-07-23 14:16:32 -04001316 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001317 }
Geoff Langbfdea662014-07-23 14:16:32 -04001318
1319 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001320 }
1321}
1322
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001323void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001325 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 +00001326 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001327
Geoff Langbfdea662014-07-23 14:16:32 -04001328 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001329
Geoff Langbfdea662014-07-23 14:16:32 -04001330 if (context)
1331 {
Jamie Madill2b976812014-08-25 15:47:49 -04001332 rx::RangeUI indexRange;
1333 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001334 {
Geoff Langbfdea662014-07-23 14:16:32 -04001335 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001336 }
Geoff Langbfdea662014-07-23 14:16:32 -04001337
Jamie Madill2b976812014-08-25 15:47:49 -04001338 context->drawElements(mode, count, type, indices, 0, indexRange);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001339 }
1340}
1341
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001342void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1343{
1344 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1345 mode, count, type, indices, primcount);
1346
Geoff Langbfdea662014-07-23 14:16:32 -04001347 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001348
Geoff Langbfdea662014-07-23 14:16:32 -04001349 if (context)
1350 {
Jamie Madill2b976812014-08-25 15:47:49 -04001351 rx::RangeUI indexRange;
1352 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001353 {
Geoff Langbfdea662014-07-23 14:16:32 -04001354 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001355 }
Geoff Langbfdea662014-07-23 14:16:32 -04001356
Jamie Madill2b976812014-08-25 15:47:49 -04001357 context->drawElements(mode, count, type, indices, primcount, indexRange);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001358 }
1359}
1360
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001361void __stdcall glEnable(GLenum cap)
1362{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001363 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001364
Geoff Langbfdea662014-07-23 14:16:32 -04001365 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001366
Geoff Langbfdea662014-07-23 14:16:32 -04001367 if (context)
1368 {
1369 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001370 {
Geoff Langbfdea662014-07-23 14:16:32 -04001371 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001372 }
Geoff Langbfdea662014-07-23 14:16:32 -04001373
1374 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001375 }
1376}
1377
1378void __stdcall glEnableVertexAttribArray(GLuint index)
1379{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001380 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001381
Geoff Langbfdea662014-07-23 14:16:32 -04001382 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001383 {
Geoff Langbfdea662014-07-23 14:16:32 -04001384 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001385 }
Geoff Langbfdea662014-07-23 14:16:32 -04001386
1387 gl::Context *context = gl::getNonLostContext();
1388
1389 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001390 {
Geoff Langbfdea662014-07-23 14:16:32 -04001391 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001392 }
1393}
1394
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001395void __stdcall glEndQueryEXT(GLenum target)
1396{
1397 EVENT("GLenum target = 0x%X)", target);
1398
Geoff Langbfdea662014-07-23 14:16:32 -04001399 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001400
Geoff Langbfdea662014-07-23 14:16:32 -04001401 if (context)
1402 {
1403 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001404 {
Geoff Langbfdea662014-07-23 14:16:32 -04001405 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001406 }
Geoff Langbfdea662014-07-23 14:16:32 -04001407
1408 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001409 }
1410}
1411
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001412void __stdcall glFinishFenceNV(GLuint fence)
1413{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001414 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001415
Geoff Langbfdea662014-07-23 14:16:32 -04001416 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001417
Geoff Langbfdea662014-07-23 14:16:32 -04001418 if (context)
1419 {
1420 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1421
1422 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001423 {
Geoff Langbfdea662014-07-23 14:16:32 -04001424 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001425 }
Geoff Langbfdea662014-07-23 14:16:32 -04001426
1427 if (fenceObject->isFence() != GL_TRUE)
1428 {
1429 return gl::error(GL_INVALID_OPERATION);
1430 }
1431
1432 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001433 }
1434}
1435
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001436void __stdcall glFinish(void)
1437{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001438 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001439
Geoff Langbfdea662014-07-23 14:16:32 -04001440 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001441
Geoff Langbfdea662014-07-23 14:16:32 -04001442 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001443 {
Geoff Langbfdea662014-07-23 14:16:32 -04001444 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001445 }
1446}
1447
1448void __stdcall glFlush(void)
1449{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001450 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001451
Geoff Langbfdea662014-07-23 14:16:32 -04001452 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453
Geoff Langbfdea662014-07-23 14:16:32 -04001454 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001455 {
Geoff Langbfdea662014-07-23 14:16:32 -04001456 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001457 }
1458}
1459
1460void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1461{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001462 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001463 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001464
Geoff Langbfdea662014-07-23 14:16:32 -04001465 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001466 {
Geoff Langbfdea662014-07-23 14:16:32 -04001467 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001468 }
Geoff Langbfdea662014-07-23 14:16:32 -04001469
1470 gl::Context *context = gl::getNonLostContext();
1471
1472 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001473 {
Geoff Langbfdea662014-07-23 14:16:32 -04001474 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1475 {
1476 return;
1477 }
1478
1479 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1480 ASSERT(framebuffer);
1481
1482 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1483 {
1484 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1485 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1486 }
1487 else
1488 {
1489 switch (attachment)
1490 {
1491 case GL_DEPTH_ATTACHMENT:
1492 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1493 break;
1494 case GL_STENCIL_ATTACHMENT:
1495 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1496 break;
1497 case GL_DEPTH_STENCIL_ATTACHMENT:
1498 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1499 break;
1500 default:
1501 UNREACHABLE();
1502 break;
1503 }
1504 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001505 }
1506}
1507
1508void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1509{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001510 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001511 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001512
Geoff Langbfdea662014-07-23 14:16:32 -04001513 gl::Context *context = gl::getNonLostContext();
1514 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001515 {
Geoff Langbfdea662014-07-23 14:16:32 -04001516 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001517 {
Geoff Langbfdea662014-07-23 14:16:32 -04001518 return;
1519 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001520
Geoff Langbfdea662014-07-23 14:16:32 -04001521 if (texture == 0)
1522 {
1523 textarget = GL_NONE;
1524 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001525
Geoff Langbfdea662014-07-23 14:16:32 -04001526 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001527
Geoff Langbfdea662014-07-23 14:16:32 -04001528 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1529 {
1530 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1531 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1532 }
1533 else
1534 {
1535 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001536 {
Geoff Langbfdea662014-07-23 14:16:32 -04001537 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1538 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1539 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001540 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001541 }
1542 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001543}
1544
1545void __stdcall glFrontFace(GLenum mode)
1546{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001547 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001548
Geoff Langbfdea662014-07-23 14:16:32 -04001549 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001550 {
Geoff Langbfdea662014-07-23 14:16:32 -04001551 case GL_CW:
1552 case GL_CCW:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001553 {
Geoff Langbfdea662014-07-23 14:16:32 -04001554 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001555
Geoff Langbfdea662014-07-23 14:16:32 -04001556 if (context)
1557 {
1558 context->getState().setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001559 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001560 }
Geoff Langbfdea662014-07-23 14:16:32 -04001561 break;
1562 default:
1563 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001564 }
1565}
1566
1567void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1568{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001569 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001570
Geoff Langbfdea662014-07-23 14:16:32 -04001571 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001572 {
Geoff Langbfdea662014-07-23 14:16:32 -04001573 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001574 }
Geoff Langbfdea662014-07-23 14:16:32 -04001575
1576 gl::Context *context = gl::getNonLostContext();
1577
1578 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001579 {
Geoff Langbfdea662014-07-23 14:16:32 -04001580 for (int i = 0; i < n; i++)
1581 {
1582 buffers[i] = context->createBuffer();
1583 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001584 }
1585}
1586
1587void __stdcall glGenerateMipmap(GLenum target)
1588{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001589 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001590
Geoff Langbfdea662014-07-23 14:16:32 -04001591 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001592
Geoff Langbfdea662014-07-23 14:16:32 -04001593 if (context)
1594 {
1595 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001596 {
Geoff Langbfdea662014-07-23 14:16:32 -04001597 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001598 }
Geoff Langbfdea662014-07-23 14:16:32 -04001599
1600 gl::Texture *texture = context->getTargetTexture(target);
1601
1602 if (texture == NULL)
1603 {
1604 return gl::error(GL_INVALID_OPERATION);
1605 }
1606
1607 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1608 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001609 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001610
1611 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1612 // unsized formats or that are color renderable and filterable. Since we do not track if
1613 // the texture was created with sized or unsized format (only sized formats are stored),
1614 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1615 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1616 // textures since they're the only texture format that can be created with unsized formats
1617 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1618 // was the last version to use add them.
1619 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1620 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1621 internalFormat == GL_ALPHA8_EXT;
1622
Geoff Lang5d601382014-07-22 15:14:06 -04001623 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1624 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001625 {
1626 return gl::error(GL_INVALID_OPERATION);
1627 }
1628
1629 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001630 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001631 {
1632 return gl::error(GL_INVALID_OPERATION);
1633 }
1634
1635 // Non-power of 2 ES2 check
1636 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1637 {
1638 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
1639 return gl::error(GL_INVALID_OPERATION);
1640 }
1641
1642 // Cube completeness check
1643 if (target == GL_TEXTURE_CUBE_MAP)
1644 {
1645 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1646 if (!textureCube->isCubeComplete())
1647 {
1648 return gl::error(GL_INVALID_OPERATION);
1649 }
1650 }
1651
1652 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001653 }
1654}
1655
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001656void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1657{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001658 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001659
Geoff Langbfdea662014-07-23 14:16:32 -04001660 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001661 {
Geoff Langbfdea662014-07-23 14:16:32 -04001662 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001663 }
Geoff Langbfdea662014-07-23 14:16:32 -04001664
1665 gl::Context *context = gl::getNonLostContext();
1666
1667 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001668 {
Geoff Langbfdea662014-07-23 14:16:32 -04001669 for (int i = 0; i < n; i++)
1670 {
1671 fences[i] = context->createFenceNV();
1672 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001673 }
1674}
1675
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001676void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1677{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001678 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001679
Geoff Langbfdea662014-07-23 14:16:32 -04001680 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001681 {
Geoff Langbfdea662014-07-23 14:16:32 -04001682 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001683 }
Geoff Langbfdea662014-07-23 14:16:32 -04001684
1685 gl::Context *context = gl::getNonLostContext();
1686
1687 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001688 {
Geoff Langbfdea662014-07-23 14:16:32 -04001689 for (int i = 0; i < n; i++)
1690 {
1691 framebuffers[i] = context->createFramebuffer();
1692 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001693 }
1694}
1695
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001696void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1697{
1698 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1699
Geoff Langbfdea662014-07-23 14:16:32 -04001700 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001701
Geoff Langbfdea662014-07-23 14:16:32 -04001702 if (context)
1703 {
1704 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001705 {
Geoff Langbfdea662014-07-23 14:16:32 -04001706 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001707 }
Geoff Langbfdea662014-07-23 14:16:32 -04001708
1709 for (GLsizei i = 0; i < n; i++)
1710 {
1711 ids[i] = context->createQuery();
1712 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001713 }
1714}
1715
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001716void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1717{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001718 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001719
Geoff Langbfdea662014-07-23 14:16:32 -04001720 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001721 {
Geoff Langbfdea662014-07-23 14:16:32 -04001722 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001723 }
Geoff Langbfdea662014-07-23 14:16:32 -04001724
1725 gl::Context *context = gl::getNonLostContext();
1726
1727 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001728 {
Geoff Langbfdea662014-07-23 14:16:32 -04001729 for (int i = 0; i < n; i++)
1730 {
1731 renderbuffers[i] = context->createRenderbuffer();
1732 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001733 }
1734}
1735
1736void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1737{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001738 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001739
Geoff Langbfdea662014-07-23 14:16:32 -04001740 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001741 {
Geoff Langbfdea662014-07-23 14:16:32 -04001742 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001743 }
Geoff Langbfdea662014-07-23 14:16:32 -04001744
1745 gl::Context *context = gl::getNonLostContext();
1746
1747 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001748 {
Geoff Langbfdea662014-07-23 14:16:32 -04001749 for (int i = 0; i < n; i++)
1750 {
1751 textures[i] = context->createTexture();
1752 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001753 }
1754}
1755
daniel@transgaming.com85423182010-04-22 13:35:27 +00001756void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001757{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001758 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001759 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001760 program, index, bufsize, length, size, type, name);
1761
Geoff Langbfdea662014-07-23 14:16:32 -04001762 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001763 {
Geoff Langbfdea662014-07-23 14:16:32 -04001764 return gl::error(GL_INVALID_VALUE);
1765 }
1766
1767 gl::Context *context = gl::getNonLostContext();
1768
1769 if (context)
1770 {
1771 gl::Program *programObject = context->getProgram(program);
1772
1773 if (!programObject)
1774 {
1775 if (context->getShader(program))
1776 {
1777 return gl::error(GL_INVALID_OPERATION);
1778 }
1779 else
1780 {
1781 return gl::error(GL_INVALID_VALUE);
1782 }
1783 }
1784
1785 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001787 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001788 }
1789
Geoff Langbfdea662014-07-23 14:16:32 -04001790 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001791 }
1792}
1793
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001794void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001795{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001796 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001797 "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 +00001798 program, index, bufsize, length, size, type, name);
1799
Geoff Langbfdea662014-07-23 14:16:32 -04001800 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001801 {
Geoff Langbfdea662014-07-23 14:16:32 -04001802 return gl::error(GL_INVALID_VALUE);
1803 }
1804
1805 gl::Context *context = gl::getNonLostContext();
1806
1807 if (context)
1808 {
1809 gl::Program *programObject = context->getProgram(program);
1810
1811 if (!programObject)
1812 {
1813 if (context->getShader(program))
1814 {
1815 return gl::error(GL_INVALID_OPERATION);
1816 }
1817 else
1818 {
1819 return gl::error(GL_INVALID_VALUE);
1820 }
1821 }
1822
1823 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001824 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001825 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001826 }
1827
Geoff Langbfdea662014-07-23 14:16:32 -04001828 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001829 }
1830}
1831
1832void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1833{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001834 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 +00001835 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001836
Geoff Langbfdea662014-07-23 14:16:32 -04001837 if (maxcount < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001838 {
Geoff Langbfdea662014-07-23 14:16:32 -04001839 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001840 }
Geoff Langbfdea662014-07-23 14:16:32 -04001841
1842 gl::Context *context = gl::getNonLostContext();
1843
1844 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001845 {
Geoff Langbfdea662014-07-23 14:16:32 -04001846 gl::Program *programObject = context->getProgram(program);
1847
1848 if (!programObject)
1849 {
1850 if (context->getShader(program))
1851 {
1852 return gl::error(GL_INVALID_OPERATION);
1853 }
1854 else
1855 {
1856 return gl::error(GL_INVALID_VALUE);
1857 }
1858 }
1859
1860 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001861 }
1862}
1863
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001864int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001865{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001866 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001867
Geoff Langbfdea662014-07-23 14:16:32 -04001868 gl::Context *context = gl::getNonLostContext();
1869
1870 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001871 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001872
Geoff Langbfdea662014-07-23 14:16:32 -04001873 gl::Program *programObject = context->getProgram(program);
1874
1875 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001876 {
Geoff Langbfdea662014-07-23 14:16:32 -04001877 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001878 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001879 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001880 }
Geoff Langbfdea662014-07-23 14:16:32 -04001881 else
1882 {
1883 return gl::error(GL_INVALID_VALUE, -1);
1884 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001885 }
Geoff Langbfdea662014-07-23 14:16:32 -04001886
1887 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1888 if (!programObject->isLinked() || !programBinary)
1889 {
1890 return gl::error(GL_INVALID_OPERATION, -1);
1891 }
1892
1893 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001894 }
1895
1896 return -1;
1897}
1898
1899void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1900{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001901 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001902
Geoff Langbfdea662014-07-23 14:16:32 -04001903 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00001904
Geoff Langbfdea662014-07-23 14:16:32 -04001905 if (context)
1906 {
1907 GLenum nativeType;
1908 unsigned int numParams = 0;
1909 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001910 {
Geoff Langbfdea662014-07-23 14:16:32 -04001911 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001912 }
Geoff Langbfdea662014-07-23 14:16:32 -04001913
1914 if (nativeType == GL_BOOL)
1915 {
1916 context->getBooleanv(pname, params);
1917 }
1918 else
1919 {
1920 CastStateValues(context, nativeType, pname, numParams, params);
1921 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001922 }
1923}
1924
1925void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1926{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001927 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 +00001928
Geoff Langbfdea662014-07-23 14:16:32 -04001929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001930
Geoff Langbfdea662014-07-23 14:16:32 -04001931 if (context)
1932 {
1933 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001934 {
Geoff Langbfdea662014-07-23 14:16:32 -04001935 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001936 }
Geoff Langbfdea662014-07-23 14:16:32 -04001937
1938 if (!gl::ValidBufferParameter(context, pname))
1939 {
1940 return gl::error(GL_INVALID_ENUM);
1941 }
1942
1943 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
1944
1945 if (!buffer)
1946 {
1947 // A null buffer means that "0" is bound to the requested buffer target
1948 return gl::error(GL_INVALID_OPERATION);
1949 }
1950
1951 switch (pname)
1952 {
1953 case GL_BUFFER_USAGE:
1954 *params = static_cast<GLint>(buffer->getUsage());
1955 break;
1956 case GL_BUFFER_SIZE:
1957 *params = gl::clampCast<GLint>(buffer->getSize());
1958 break;
1959 case GL_BUFFER_ACCESS_FLAGS:
1960 *params = buffer->getAccessFlags();
1961 break;
1962 case GL_BUFFER_MAPPED:
1963 *params = static_cast<GLint>(buffer->isMapped());
1964 break;
1965 case GL_BUFFER_MAP_OFFSET:
1966 *params = gl::clampCast<GLint>(buffer->getMapOffset());
1967 break;
1968 case GL_BUFFER_MAP_LENGTH:
1969 *params = gl::clampCast<GLint>(buffer->getMapLength());
1970 break;
1971 default: UNREACHABLE(); break;
1972 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001973 }
1974}
1975
1976GLenum __stdcall glGetError(void)
1977{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001978 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979
1980 gl::Context *context = gl::getContext();
1981
1982 if (context)
1983 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00001984 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001985 }
1986
1987 return GL_NO_ERROR;
1988}
1989
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001990void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
1991{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001992 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001993
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001994
Geoff Langbfdea662014-07-23 14:16:32 -04001995 gl::Context *context = gl::getNonLostContext();
1996
1997 if (context)
1998 {
1999 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2000
2001 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002002 {
Geoff Langbfdea662014-07-23 14:16:32 -04002003 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002004 }
Geoff Langbfdea662014-07-23 14:16:32 -04002005
2006 if (fenceObject->isFence() != GL_TRUE)
2007 {
2008 return gl::error(GL_INVALID_OPERATION);
2009 }
2010
2011 switch (pname)
2012 {
2013 case GL_FENCE_STATUS_NV:
2014 case GL_FENCE_CONDITION_NV:
2015 break;
2016
2017 default: return gl::error(GL_INVALID_ENUM);
2018 }
2019
2020 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002021 }
2022}
2023
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002024void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2025{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002026 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002027
Geoff Langbfdea662014-07-23 14:16:32 -04002028 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002029
Geoff Langbfdea662014-07-23 14:16:32 -04002030 if (context)
2031 {
2032 GLenum nativeType;
2033 unsigned int numParams = 0;
2034 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002035 {
Geoff Langbfdea662014-07-23 14:16:32 -04002036 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002037 }
Geoff Langbfdea662014-07-23 14:16:32 -04002038
2039 if (nativeType == GL_FLOAT)
2040 {
2041 context->getFloatv(pname, params);
2042 }
2043 else
2044 {
2045 CastStateValues(context, nativeType, pname, numParams, params);
2046 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002047 }
2048}
2049
2050void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2051{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002052 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 +00002053 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002054
Geoff Langbfdea662014-07-23 14:16:32 -04002055 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002056
Geoff Langbfdea662014-07-23 14:16:32 -04002057 if (context)
2058 {
2059 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002060 {
Geoff Langbfdea662014-07-23 14:16:32 -04002061 return gl::error(GL_INVALID_ENUM);
2062 }
2063
2064 int clientVersion = context->getClientVersion();
2065
2066 switch (pname)
2067 {
2068 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2069 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2070 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2071 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2072 break;
2073 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2074 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002076 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002077 }
Geoff Langbfdea662014-07-23 14:16:32 -04002078 break;
2079 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2080 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2081 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2082 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2083 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2084 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2085 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2086 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2087 if (clientVersion < 3)
2088 {
2089 return gl::error(GL_INVALID_ENUM);
2090 }
2091 break;
2092 default:
2093 return gl::error(GL_INVALID_ENUM);
2094 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002095
Geoff Langbfdea662014-07-23 14:16:32 -04002096 // Determine if the attachment is a valid enum
2097 switch (attachment)
2098 {
2099 case GL_BACK:
2100 case GL_FRONT:
2101 case GL_DEPTH:
2102 case GL_STENCIL:
2103 case GL_DEPTH_STENCIL_ATTACHMENT:
2104 if (clientVersion < 3)
2105 {
2106 return gl::error(GL_INVALID_ENUM);
2107 }
2108 break;
2109
2110 case GL_DEPTH_ATTACHMENT:
2111 case GL_STENCIL_ATTACHMENT:
2112 break;
2113
2114 default:
2115 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2116 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2117 {
2118 return gl::error(GL_INVALID_ENUM);
2119 }
2120 break;
2121 }
2122
2123 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2124 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2125
2126 if (framebufferHandle == 0)
2127 {
2128 if (clientVersion < 3)
2129 {
2130 return gl::error(GL_INVALID_OPERATION);
2131 }
2132
2133 switch (attachment)
2134 {
2135 case GL_BACK:
2136 case GL_DEPTH:
2137 case GL_STENCIL:
2138 break;
2139 default:
2140 return gl::error(GL_INVALID_OPERATION);
2141 }
2142 }
2143 else
2144 {
2145 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2146 {
2147 // Valid attachment query
2148 }
2149 else
2150 {
2151 switch (attachment)
2152 {
2153 case GL_DEPTH_ATTACHMENT:
2154 case GL_STENCIL_ATTACHMENT:
2155 break;
2156 case GL_DEPTH_STENCIL_ATTACHMENT:
2157 if (framebuffer->hasValidDepthStencil())
2158 {
2159 return gl::error(GL_INVALID_OPERATION);
2160 }
2161 break;
2162 default:
2163 return gl::error(GL_INVALID_OPERATION);
2164 }
2165 }
2166 }
2167
2168 GLenum attachmentType = GL_NONE;
2169 GLuint attachmentHandle = 0;
2170 GLuint attachmentLevel = 0;
2171 GLuint attachmentLayer = 0;
2172
2173 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2174
2175 if (attachmentObject)
2176 {
2177 attachmentType = attachmentObject->type();
2178 attachmentHandle = attachmentObject->id();
2179 attachmentLevel = attachmentObject->mipLevel();
2180 attachmentLayer = attachmentObject->layer();
2181 }
2182
2183 GLenum attachmentObjectType; // Type category
2184 if (framebufferHandle == 0)
2185 {
2186 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2187 }
2188 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2189 {
2190 attachmentObjectType = attachmentType;
2191 }
2192 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2193 {
2194 attachmentObjectType = GL_TEXTURE;
2195 }
2196 else
2197 {
2198 UNREACHABLE();
2199 return;
2200 }
2201
2202 if (attachmentObjectType == GL_NONE)
2203 {
2204 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2205 // is NONE, then querying any other pname will generate INVALID_ENUM.
2206
2207 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2208 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2209 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002210
Geoff Lang646559f2013-08-15 11:08:15 -04002211 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002212 {
Geoff Lang646559f2013-08-15 11:08:15 -04002213 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002214 *params = attachmentObjectType;
2215 break;
2216
Geoff Lang646559f2013-08-15 11:08:15 -04002217 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002218 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002219 {
Geoff Lang05b05022014-06-11 15:31:45 -04002220 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002221 }
Geoff Langbfdea662014-07-23 14:16:32 -04002222 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002223 break;
2224
2225 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002226 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002227 {
Geoff Langbfdea662014-07-23 14:16:32 -04002228 return gl::error(GL_INVALID_ENUM);
Geoff Lang646559f2013-08-15 11:08:15 -04002229 }
2230 else
2231 {
Geoff Langbfdea662014-07-23 14:16:32 -04002232 gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002233 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002234 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002235 }
Geoff Langbfdea662014-07-23 14:16:32 -04002236 else
2237 {
2238 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2239 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2240 ASSERT(attachmentObject != NULL);
2241
2242 switch (pname)
2243 {
2244 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2245 *params = attachmentObjectType;
2246 break;
2247
2248 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2249 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2250 {
2251 return gl::error(GL_INVALID_ENUM);
2252 }
2253 *params = attachmentHandle;
2254 break;
2255
2256 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2257 if (attachmentObjectType != GL_TEXTURE)
2258 {
2259 return gl::error(GL_INVALID_ENUM);
2260 }
2261 *params = attachmentLevel;
2262 break;
2263
2264 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2265 if (attachmentObjectType != GL_TEXTURE)
2266 {
2267 return gl::error(GL_INVALID_ENUM);
2268 }
2269 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2270 break;
2271
2272 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2273 *params = attachmentObject->getRedSize();
2274 break;
2275
2276 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2277 *params = attachmentObject->getGreenSize();
2278 break;
2279
2280 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2281 *params = attachmentObject->getBlueSize();
2282 break;
2283
2284 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2285 *params = attachmentObject->getAlphaSize();
2286 break;
2287
2288 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2289 *params = attachmentObject->getDepthSize();
2290 break;
2291
2292 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2293 *params = attachmentObject->getStencilSize();
2294 break;
2295
2296 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2297 if (attachment == GL_DEPTH_STENCIL)
2298 {
2299 gl::error(GL_INVALID_OPERATION);
2300 }
2301 *params = attachmentObject->getComponentType();
2302 break;
2303
2304 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2305 *params = attachmentObject->getColorEncoding();
2306 break;
2307
2308 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2309 if (attachmentObjectType != GL_TEXTURE)
2310 {
2311 return gl::error(GL_INVALID_ENUM);
2312 }
2313 *params = attachmentLayer;
2314 break;
2315
2316 default:
2317 UNREACHABLE();
2318 break;
2319 }
2320 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002321 }
2322}
2323
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002324GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2325{
2326 EVENT("()");
2327
Geoff Langbfdea662014-07-23 14:16:32 -04002328 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002329
Geoff Langbfdea662014-07-23 14:16:32 -04002330 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002331 {
Geoff Langbfdea662014-07-23 14:16:32 -04002332 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002333 }
Geoff Langbfdea662014-07-23 14:16:32 -04002334
2335 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002336}
2337
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002338void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2339{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002340 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002341
Geoff Langbfdea662014-07-23 14:16:32 -04002342 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002343
Geoff Langbfdea662014-07-23 14:16:32 -04002344 if (context)
2345 {
2346 GLenum nativeType;
2347 unsigned int numParams = 0;
2348
2349 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002350 {
Geoff Langbfdea662014-07-23 14:16:32 -04002351 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002352 }
Geoff Langbfdea662014-07-23 14:16:32 -04002353
2354 if (nativeType == GL_INT)
2355 {
2356 context->getIntegerv(pname, params);
2357 }
2358 else
2359 {
2360 CastStateValues(context, nativeType, pname, numParams, params);
2361 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002362 }
2363}
2364
2365void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2366{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002367 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002368
Geoff Langbfdea662014-07-23 14:16:32 -04002369 gl::Context *context = gl::getNonLostContext();
2370
2371 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002372 {
Geoff Langbfdea662014-07-23 14:16:32 -04002373 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002374
Geoff Langbfdea662014-07-23 14:16:32 -04002375 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002376 {
Geoff Langbfdea662014-07-23 14:16:32 -04002377 return gl::error(GL_INVALID_VALUE);
2378 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002379
Geoff Langbfdea662014-07-23 14:16:32 -04002380 if (context->getClientVersion() < 3)
2381 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002382 switch (pname)
2383 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002384 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002385 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002386 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002387 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002388 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002389 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002390 }
2391 }
Geoff Langbfdea662014-07-23 14:16:32 -04002392
2393 switch (pname)
2394 {
2395 case GL_DELETE_STATUS:
2396 *params = programObject->isFlaggedForDeletion();
2397 return;
2398 case GL_LINK_STATUS:
2399 *params = programObject->isLinked();
2400 return;
2401 case GL_VALIDATE_STATUS:
2402 *params = programObject->isValidated();
2403 return;
2404 case GL_INFO_LOG_LENGTH:
2405 *params = programObject->getInfoLogLength();
2406 return;
2407 case GL_ATTACHED_SHADERS:
2408 *params = programObject->getAttachedShadersCount();
2409 return;
2410 case GL_ACTIVE_ATTRIBUTES:
2411 *params = programObject->getActiveAttributeCount();
2412 return;
2413 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2414 *params = programObject->getActiveAttributeMaxLength();
2415 return;
2416 case GL_ACTIVE_UNIFORMS:
2417 *params = programObject->getActiveUniformCount();
2418 return;
2419 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2420 *params = programObject->getActiveUniformMaxLength();
2421 return;
2422 case GL_PROGRAM_BINARY_LENGTH_OES:
2423 *params = programObject->getProgramBinaryLength();
2424 return;
2425 case GL_ACTIVE_UNIFORM_BLOCKS:
2426 *params = programObject->getActiveUniformBlockCount();
2427 return;
2428 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2429 *params = programObject->getActiveUniformBlockMaxLength();
2430 break;
2431 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2432 *params = programObject->getTransformFeedbackBufferMode();
2433 break;
2434 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2435 *params = programObject->getTransformFeedbackVaryingCount();
2436 break;
2437 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2438 *params = programObject->getTransformFeedbackVaryingMaxLength();
2439 break;
2440 default:
2441 return gl::error(GL_INVALID_ENUM);
2442 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002443 }
2444}
2445
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002446void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002448 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 +00002449 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002450
Geoff Langbfdea662014-07-23 14:16:32 -04002451 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002452 {
Geoff Langbfdea662014-07-23 14:16:32 -04002453 return gl::error(GL_INVALID_VALUE);
2454 }
2455
2456 gl::Context *context = gl::getNonLostContext();
2457
2458 if (context)
2459 {
2460 gl::Program *programObject = context->getProgram(program);
2461
2462 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002464 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002465 }
2466
Geoff Langbfdea662014-07-23 14:16:32 -04002467 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002468 }
2469}
2470
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002471void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2472{
2473 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2474
Geoff Langbfdea662014-07-23 14:16:32 -04002475 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002476
Geoff Langbfdea662014-07-23 14:16:32 -04002477 if (context)
2478 {
2479 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002480 {
Geoff Langbfdea662014-07-23 14:16:32 -04002481 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002482 }
Geoff Langbfdea662014-07-23 14:16:32 -04002483
2484 switch (pname)
2485 {
2486 case GL_CURRENT_QUERY_EXT:
2487 params[0] = context->getState().getActiveQueryId(target);
2488 break;
2489
2490 default:
2491 return gl::error(GL_INVALID_ENUM);
2492 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002493 }
2494}
2495
2496void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2497{
2498 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2499
Geoff Langbfdea662014-07-23 14:16:32 -04002500 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002501
Geoff Langbfdea662014-07-23 14:16:32 -04002502 if (context)
2503 {
2504 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2505
2506 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002507 {
Geoff Langbfdea662014-07-23 14:16:32 -04002508 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002509 }
Geoff Langbfdea662014-07-23 14:16:32 -04002510
2511 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2512 {
2513 return gl::error(GL_INVALID_OPERATION);
2514 }
2515
2516 switch(pname)
2517 {
2518 case GL_QUERY_RESULT_EXT:
2519 params[0] = queryObject->getResult();
2520 break;
2521 case GL_QUERY_RESULT_AVAILABLE_EXT:
2522 params[0] = queryObject->isResultAvailable();
2523 break;
2524 default:
2525 return gl::error(GL_INVALID_ENUM);
2526 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002527 }
2528}
2529
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002530void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2531{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002532 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 +00002533
Geoff Langbfdea662014-07-23 14:16:32 -04002534 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002535
Geoff Langbfdea662014-07-23 14:16:32 -04002536 if (context)
2537 {
2538 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002539 {
Geoff Langbfdea662014-07-23 14:16:32 -04002540 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002541 }
Geoff Langbfdea662014-07-23 14:16:32 -04002542
2543 if (context->getState().getRenderbufferId() == 0)
2544 {
2545 return gl::error(GL_INVALID_OPERATION);
2546 }
2547
2548 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2549
2550 switch (pname)
2551 {
2552 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2553 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2554 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2555 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2556 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2557 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2558 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2559 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2560 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
2561 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2562 if (!context->getExtensions().framebufferMultisample)
2563 {
2564 return gl::error(GL_INVALID_ENUM);
2565 }
2566 *params = renderbuffer->getSamples();
2567 break;
2568 default:
2569 return gl::error(GL_INVALID_ENUM);
2570 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002571 }
2572}
2573
2574void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2575{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002576 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002577
Geoff Langbfdea662014-07-23 14:16:32 -04002578 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002579
Geoff Langbfdea662014-07-23 14:16:32 -04002580 if (context)
2581 {
2582 gl::Shader *shaderObject = context->getShader(shader);
2583
2584 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002585 {
Geoff Langbfdea662014-07-23 14:16:32 -04002586 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002587 }
Geoff Langbfdea662014-07-23 14:16:32 -04002588
2589 switch (pname)
2590 {
2591 case GL_SHADER_TYPE:
2592 *params = shaderObject->getType();
2593 return;
2594 case GL_DELETE_STATUS:
2595 *params = shaderObject->isFlaggedForDeletion();
2596 return;
2597 case GL_COMPILE_STATUS:
2598 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2599 return;
2600 case GL_INFO_LOG_LENGTH:
2601 *params = shaderObject->getInfoLogLength();
2602 return;
2603 case GL_SHADER_SOURCE_LENGTH:
2604 *params = shaderObject->getSourceLength();
2605 return;
2606 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2607 *params = shaderObject->getTranslatedSourceLength();
2608 return;
2609 default:
2610 return gl::error(GL_INVALID_ENUM);
2611 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002612 }
2613}
2614
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002615void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002616{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002617 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 +00002618 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002619
Geoff Langbfdea662014-07-23 14:16:32 -04002620 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002621 {
Geoff Langbfdea662014-07-23 14:16:32 -04002622 return gl::error(GL_INVALID_VALUE);
2623 }
2624
2625 gl::Context *context = gl::getNonLostContext();
2626
2627 if (context)
2628 {
2629 gl::Shader *shaderObject = context->getShader(shader);
2630
2631 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002633 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002634 }
2635
Geoff Langbfdea662014-07-23 14:16:32 -04002636 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002637 }
2638}
2639
2640void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2641{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002642 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 +00002643 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002644
Geoff Langbfdea662014-07-23 14:16:32 -04002645 switch (shadertype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002646 {
Geoff Langbfdea662014-07-23 14:16:32 -04002647 case GL_VERTEX_SHADER:
2648 case GL_FRAGMENT_SHADER:
2649 break;
2650 default:
2651 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002652 }
Geoff Langbfdea662014-07-23 14:16:32 -04002653
2654 switch (precisiontype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002655 {
Geoff Langbfdea662014-07-23 14:16:32 -04002656 case GL_LOW_FLOAT:
2657 case GL_MEDIUM_FLOAT:
2658 case GL_HIGH_FLOAT:
2659 // Assume IEEE 754 precision
2660 range[0] = 127;
2661 range[1] = 127;
2662 *precision = 23;
2663 break;
2664 case GL_LOW_INT:
2665 case GL_MEDIUM_INT:
2666 case GL_HIGH_INT:
2667 // Some (most) hardware only supports single-precision floating-point numbers,
2668 // which can accurately represent integers up to +/-16777216
2669 range[0] = 24;
2670 range[1] = 24;
2671 *precision = 0;
2672 break;
2673 default:
2674 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002675 }
2676}
2677
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002678void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002680 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 +00002681 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002682
Geoff Langbfdea662014-07-23 14:16:32 -04002683 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002684 {
Geoff Langbfdea662014-07-23 14:16:32 -04002685 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002686 }
Geoff Langbfdea662014-07-23 14:16:32 -04002687
2688 gl::Context *context = gl::getNonLostContext();
2689
2690 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002691 {
Geoff Langbfdea662014-07-23 14:16:32 -04002692 gl::Shader *shaderObject = context->getShader(shader);
2693
2694 if (!shaderObject)
2695 {
2696 return gl::error(GL_INVALID_OPERATION);
2697 }
2698
2699 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002700 }
2701}
2702
zmo@google.coma574f782011-10-03 21:45:23 +00002703void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2704{
2705 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2706 shader, bufsize, length, source);
2707
Geoff Langbfdea662014-07-23 14:16:32 -04002708 if (bufsize < 0)
zmo@google.coma574f782011-10-03 21:45:23 +00002709 {
Geoff Langbfdea662014-07-23 14:16:32 -04002710 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00002711 }
Geoff Langbfdea662014-07-23 14:16:32 -04002712
2713 gl::Context *context = gl::getNonLostContext();
2714
2715 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002716 {
Geoff Langbfdea662014-07-23 14:16:32 -04002717 gl::Shader *shaderObject = context->getShader(shader);
2718
2719 if (!shaderObject)
2720 {
2721 return gl::error(GL_INVALID_OPERATION);
2722 }
2723
2724 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002725 }
2726}
2727
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002728const GLubyte* __stdcall glGetString(GLenum name)
2729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002730 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002731
Geoff Langbfdea662014-07-23 14:16:32 -04002732 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002733
Geoff Langbfdea662014-07-23 14:16:32 -04002734 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735 {
Geoff Langbfdea662014-07-23 14:16:32 -04002736 case GL_VENDOR:
2737 return (GLubyte*)"Google Inc.";
2738 case GL_RENDERER:
2739 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
2740 case GL_VERSION:
2741 if (context->getClientVersion() == 2)
2742 {
2743 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2744 }
2745 else
2746 {
2747 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2748 }
2749 case GL_SHADING_LANGUAGE_VERSION:
2750 if (context->getClientVersion() == 2)
2751 {
2752 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2753 }
2754 else
2755 {
2756 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2757 }
2758 case GL_EXTENSIONS:
2759 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
2760 default:
2761 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002763}
2764
2765void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2766{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002767 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 +00002768
Geoff Langbfdea662014-07-23 14:16:32 -04002769 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002770
Geoff Langbfdea662014-07-23 14:16:32 -04002771 if (context)
2772 {
2773 gl::Texture *texture = context->getTargetTexture(target);
2774
2775 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002776 {
Geoff Langbfdea662014-07-23 14:16:32 -04002777 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002778 }
Geoff Langbfdea662014-07-23 14:16:32 -04002779
2780 switch (pname)
2781 {
2782 case GL_TEXTURE_MAG_FILTER:
2783 *params = (GLfloat)texture->getSamplerState().magFilter;
2784 break;
2785 case GL_TEXTURE_MIN_FILTER:
2786 *params = (GLfloat)texture->getSamplerState().minFilter;
2787 break;
2788 case GL_TEXTURE_WRAP_S:
2789 *params = (GLfloat)texture->getSamplerState().wrapS;
2790 break;
2791 case GL_TEXTURE_WRAP_T:
2792 *params = (GLfloat)texture->getSamplerState().wrapT;
2793 break;
2794 case GL_TEXTURE_WRAP_R:
2795 if (context->getClientVersion() < 3)
2796 {
2797 return gl::error(GL_INVALID_ENUM);
2798 }
2799 *params = (GLfloat)texture->getSamplerState().wrapR;
2800 break;
2801 case GL_TEXTURE_IMMUTABLE_FORMAT:
2802 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2803 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2804 break;
2805 case GL_TEXTURE_IMMUTABLE_LEVELS:
2806 if (context->getClientVersion() < 3)
2807 {
2808 return gl::error(GL_INVALID_ENUM);
2809 }
2810 *params = (GLfloat)texture->immutableLevelCount();
2811 break;
2812 case GL_TEXTURE_USAGE_ANGLE:
2813 *params = (GLfloat)texture->getUsage();
2814 break;
2815 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2816 if (!context->getExtensions().textureFilterAnisotropic)
2817 {
2818 return gl::error(GL_INVALID_ENUM);
2819 }
2820 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2821 break;
2822 case GL_TEXTURE_SWIZZLE_R:
2823 if (context->getClientVersion() < 3)
2824 {
2825 return gl::error(GL_INVALID_ENUM);
2826 }
2827 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2828 break;
2829 case GL_TEXTURE_SWIZZLE_G:
2830 if (context->getClientVersion() < 3)
2831 {
2832 return gl::error(GL_INVALID_ENUM);
2833 }
2834 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2835 break;
2836 case GL_TEXTURE_SWIZZLE_B:
2837 if (context->getClientVersion() < 3)
2838 {
2839 return gl::error(GL_INVALID_ENUM);
2840 }
2841 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2842 break;
2843 case GL_TEXTURE_SWIZZLE_A:
2844 if (context->getClientVersion() < 3)
2845 {
2846 return gl::error(GL_INVALID_ENUM);
2847 }
2848 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2849 break;
2850 case GL_TEXTURE_BASE_LEVEL:
2851 if (context->getClientVersion() < 3)
2852 {
2853 return gl::error(GL_INVALID_ENUM);
2854 }
2855 *params = (GLfloat)texture->getSamplerState().baseLevel;
2856 break;
2857 case GL_TEXTURE_MAX_LEVEL:
2858 if (context->getClientVersion() < 3)
2859 {
2860 return gl::error(GL_INVALID_ENUM);
2861 }
2862 *params = (GLfloat)texture->getSamplerState().maxLevel;
2863 break;
2864 case GL_TEXTURE_MIN_LOD:
2865 if (context->getClientVersion() < 3)
2866 {
2867 return gl::error(GL_INVALID_ENUM);
2868 }
2869 *params = texture->getSamplerState().minLod;
2870 break;
2871 case GL_TEXTURE_MAX_LOD:
2872 if (context->getClientVersion() < 3)
2873 {
2874 return gl::error(GL_INVALID_ENUM);
2875 }
2876 *params = texture->getSamplerState().maxLod;
2877 break;
2878 default:
2879 return gl::error(GL_INVALID_ENUM);
2880 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002881 }
2882}
2883
2884void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
2885{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002886 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 +00002887
Geoff Langbfdea662014-07-23 14:16:32 -04002888 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002889
Geoff Langbfdea662014-07-23 14:16:32 -04002890 if (context)
2891 {
2892 gl::Texture *texture = context->getTargetTexture(target);
2893
2894 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002895 {
Geoff Langbfdea662014-07-23 14:16:32 -04002896 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002897 }
Geoff Langbfdea662014-07-23 14:16:32 -04002898
2899 switch (pname)
2900 {
2901 case GL_TEXTURE_MAG_FILTER:
2902 *params = texture->getSamplerState().magFilter;
2903 break;
2904 case GL_TEXTURE_MIN_FILTER:
2905 *params = texture->getSamplerState().minFilter;
2906 break;
2907 case GL_TEXTURE_WRAP_S:
2908 *params = texture->getSamplerState().wrapS;
2909 break;
2910 case GL_TEXTURE_WRAP_T:
2911 *params = texture->getSamplerState().wrapT;
2912 break;
2913 case GL_TEXTURE_WRAP_R:
2914 if (context->getClientVersion() < 3)
2915 {
2916 return gl::error(GL_INVALID_ENUM);
2917 }
2918 *params = texture->getSamplerState().wrapR;
2919 break;
2920 case GL_TEXTURE_IMMUTABLE_FORMAT:
2921 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2922 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
2923 break;
2924 case GL_TEXTURE_IMMUTABLE_LEVELS:
2925 if (context->getClientVersion() < 3)
2926 {
2927 return gl::error(GL_INVALID_ENUM);
2928 }
2929 *params = texture->immutableLevelCount();
2930 break;
2931 case GL_TEXTURE_USAGE_ANGLE:
2932 *params = texture->getUsage();
2933 break;
2934 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2935 if (!context->getExtensions().textureFilterAnisotropic)
2936 {
2937 return gl::error(GL_INVALID_ENUM);
2938 }
2939 *params = (GLint)texture->getSamplerState().maxAnisotropy;
2940 break;
2941 case GL_TEXTURE_SWIZZLE_R:
2942 if (context->getClientVersion() < 3)
2943 {
2944 return gl::error(GL_INVALID_ENUM);
2945 }
2946 *params = texture->getSamplerState().swizzleRed;
2947 break;
2948 case GL_TEXTURE_SWIZZLE_G:
2949 if (context->getClientVersion() < 3)
2950 {
2951 return gl::error(GL_INVALID_ENUM);
2952 }
2953 *params = texture->getSamplerState().swizzleGreen;
2954 break;
2955 case GL_TEXTURE_SWIZZLE_B:
2956 if (context->getClientVersion() < 3)
2957 {
2958 return gl::error(GL_INVALID_ENUM);
2959 }
2960 *params = texture->getSamplerState().swizzleBlue;
2961 break;
2962 case GL_TEXTURE_SWIZZLE_A:
2963 if (context->getClientVersion() < 3)
2964 {
2965 return gl::error(GL_INVALID_ENUM);
2966 }
2967 *params = texture->getSamplerState().swizzleAlpha;
2968 break;
2969 case GL_TEXTURE_BASE_LEVEL:
2970 if (context->getClientVersion() < 3)
2971 {
2972 return gl::error(GL_INVALID_ENUM);
2973 }
2974 *params = texture->getSamplerState().baseLevel;
2975 break;
2976 case GL_TEXTURE_MAX_LEVEL:
2977 if (context->getClientVersion() < 3)
2978 {
2979 return gl::error(GL_INVALID_ENUM);
2980 }
2981 *params = texture->getSamplerState().maxLevel;
2982 break;
2983 case GL_TEXTURE_MIN_LOD:
2984 if (context->getClientVersion() < 3)
2985 {
2986 return gl::error(GL_INVALID_ENUM);
2987 }
2988 *params = (GLint)texture->getSamplerState().minLod;
2989 break;
2990 case GL_TEXTURE_MAX_LOD:
2991 if (context->getClientVersion() < 3)
2992 {
2993 return gl::error(GL_INVALID_ENUM);
2994 }
2995 *params = (GLint)texture->getSamplerState().maxLod;
2996 break;
2997 default:
2998 return gl::error(GL_INVALID_ENUM);
2999 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003000 }
3001}
3002
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003003void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3004{
3005 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3006 program, location, bufSize, params);
3007
Geoff Langbfdea662014-07-23 14:16:32 -04003008 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003009 {
Geoff Langbfdea662014-07-23 14:16:32 -04003010 return gl::error(GL_INVALID_VALUE);
3011 }
3012
3013 gl::Context *context = gl::getNonLostContext();
3014
3015 if (context)
3016 {
Jamie Madill0063c512014-08-25 15:47:53 -04003017 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003018 {
Jamie Madill0063c512014-08-25 15:47:53 -04003019 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003020 }
3021
Jamie Madill0063c512014-08-25 15:47:53 -04003022 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3023 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003024
Jamie Madill99a1e982014-08-25 15:47:54 -04003025 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003026 }
3027}
3028
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003029void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3030{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003031 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003032
Geoff Langbfdea662014-07-23 14:16:32 -04003033 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003034
Geoff Langbfdea662014-07-23 14:16:32 -04003035 if (context)
3036 {
Jamie Madill0063c512014-08-25 15:47:53 -04003037 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003038 {
Jamie Madill0063c512014-08-25 15:47:53 -04003039 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003040 }
Geoff Langbfdea662014-07-23 14:16:32 -04003041
Jamie Madill0063c512014-08-25 15:47:53 -04003042 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3043 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003044
Jamie Madill99a1e982014-08-25 15:47:54 -04003045 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003046 }
3047}
3048
3049void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3050{
Geoff Langbfdea662014-07-23 14:16:32 -04003051 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003052 program, location, bufSize, params);
3053
Geoff Langbfdea662014-07-23 14:16:32 -04003054 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003055 {
Geoff Langbfdea662014-07-23 14:16:32 -04003056 return gl::error(GL_INVALID_VALUE);
3057 }
3058
3059 gl::Context *context = gl::getNonLostContext();
3060
3061 if (context)
3062 {
Jamie Madill0063c512014-08-25 15:47:53 -04003063 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003064 {
Jamie Madill0063c512014-08-25 15:47:53 -04003065 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003066 }
3067
Jamie Madill0063c512014-08-25 15:47:53 -04003068 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3069 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003070
Jamie Madill99a1e982014-08-25 15:47:54 -04003071 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003072 }
3073}
3074
3075void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3076{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003077 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003078
Geoff Langbfdea662014-07-23 14:16:32 -04003079 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003080
Geoff Langbfdea662014-07-23 14:16:32 -04003081 if (context)
3082 {
Jamie Madill0063c512014-08-25 15:47:53 -04003083 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003084 {
Jamie Madill0063c512014-08-25 15:47:53 -04003085 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003086 }
Geoff Langbfdea662014-07-23 14:16:32 -04003087
Jamie Madill0063c512014-08-25 15:47:53 -04003088 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3089 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003090
Jamie Madill99a1e982014-08-25 15:47:54 -04003091 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003092 }
3093}
3094
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003095int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003097 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003098
Geoff Langbfdea662014-07-23 14:16:32 -04003099 gl::Context *context = gl::getNonLostContext();
3100
3101 if (strstr(name, "gl_") == name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003102 {
Geoff Langbfdea662014-07-23 14:16:32 -04003103 return -1;
3104 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003105
Geoff Langbfdea662014-07-23 14:16:32 -04003106 if (context)
3107 {
3108 gl::Program *programObject = context->getProgram(program);
3109
3110 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003111 {
Geoff Langbfdea662014-07-23 14:16:32 -04003112 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003114 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115 }
Geoff Langbfdea662014-07-23 14:16:32 -04003116 else
3117 {
3118 return gl::error(GL_INVALID_VALUE, -1);
3119 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003120 }
Geoff Langbfdea662014-07-23 14:16:32 -04003121
3122 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3123 if (!programObject->isLinked() || !programBinary)
3124 {
3125 return gl::error(GL_INVALID_OPERATION, -1);
3126 }
3127
3128 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003129 }
3130
3131 return -1;
3132}
3133
3134void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3135{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003136 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003137
Geoff Langbfdea662014-07-23 14:16:32 -04003138 gl::Context *context = gl::getNonLostContext();
3139
3140 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003141 {
Geoff Langbfdea662014-07-23 14:16:32 -04003142 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003143 {
Geoff Langbfdea662014-07-23 14:16:32 -04003144 return gl::error(GL_INVALID_VALUE);
3145 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003146
Geoff Langbfdea662014-07-23 14:16:32 -04003147 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
3148 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3149 {
3150 return;
3151 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003152
Geoff Langbfdea662014-07-23 14:16:32 -04003153 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3154 {
3155 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3156 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003157 {
Geoff Langbfdea662014-07-23 14:16:32 -04003158 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003159 }
3160 }
Geoff Langbfdea662014-07-23 14:16:32 -04003161 else
3162 {
3163 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3164 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003165 }
3166}
3167
3168void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3169{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003170 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003171
Geoff Langbfdea662014-07-23 14:16:32 -04003172 gl::Context *context = gl::getNonLostContext();
3173
3174 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003175 {
Geoff Langbfdea662014-07-23 14:16:32 -04003176 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003177 {
Geoff Langbfdea662014-07-23 14:16:32 -04003178 return gl::error(GL_INVALID_VALUE);
3179 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003180
Geoff Langbfdea662014-07-23 14:16:32 -04003181 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003182
Geoff Langbfdea662014-07-23 14:16:32 -04003183 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3184 {
3185 return;
3186 }
Jamie Madillaff71502013-07-02 11:57:05 -04003187
Geoff Langbfdea662014-07-23 14:16:32 -04003188 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3189 {
3190 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3191 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003192 {
Geoff Langbfdea662014-07-23 14:16:32 -04003193 float currentValue = currentValueData.FloatValues[i];
3194 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003195 }
3196 }
Geoff Langbfdea662014-07-23 14:16:32 -04003197 else
3198 {
3199 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3200 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003201 }
3202}
3203
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003204void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003205{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003206 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003207
Geoff Langbfdea662014-07-23 14:16:32 -04003208 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003209
Geoff Langbfdea662014-07-23 14:16:32 -04003210 if (context)
3211 {
3212 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003213 {
Geoff Langbfdea662014-07-23 14:16:32 -04003214 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003215 }
Geoff Langbfdea662014-07-23 14:16:32 -04003216
3217 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3218 {
3219 return gl::error(GL_INVALID_ENUM);
3220 }
3221
3222 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003223 }
3224}
3225
3226void __stdcall glHint(GLenum target, GLenum mode)
3227{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003228 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229
Geoff Langbfdea662014-07-23 14:16:32 -04003230 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003231 {
Geoff Langbfdea662014-07-23 14:16:32 -04003232 case GL_FASTEST:
3233 case GL_NICEST:
3234 case GL_DONT_CARE:
3235 break;
3236 default:
3237 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003238 }
Geoff Langbfdea662014-07-23 14:16:32 -04003239
3240 gl::Context *context = gl::getNonLostContext();
3241 switch (target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003242 {
Geoff Langbfdea662014-07-23 14:16:32 -04003243 case GL_GENERATE_MIPMAP_HINT:
3244 if (context) context->getState().setGenerateMipmapHint(mode);
3245 break;
3246 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3247 if (context) context->getState().setFragmentShaderDerivativeHint(mode);
3248 break;
3249 default:
3250 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003251 }
3252}
3253
3254GLboolean __stdcall glIsBuffer(GLuint buffer)
3255{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003256 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003257
Geoff Langbfdea662014-07-23 14:16:32 -04003258 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003259
Geoff Langbfdea662014-07-23 14:16:32 -04003260 if (context && buffer)
3261 {
3262 gl::Buffer *bufferObject = context->getBuffer(buffer);
3263
3264 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003265 {
Geoff Langbfdea662014-07-23 14:16:32 -04003266 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003267 }
3268 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003269
3270 return GL_FALSE;
3271}
3272
3273GLboolean __stdcall glIsEnabled(GLenum cap)
3274{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003275 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003276
Geoff Langbfdea662014-07-23 14:16:32 -04003277 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003278
Geoff Langbfdea662014-07-23 14:16:32 -04003279 if (context)
3280 {
3281 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003282 {
Geoff Langbfdea662014-07-23 14:16:32 -04003283 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003284 }
Geoff Langbfdea662014-07-23 14:16:32 -04003285
3286 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003287 }
3288
3289 return false;
3290}
3291
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003292GLboolean __stdcall glIsFenceNV(GLuint fence)
3293{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003294 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003295
Geoff Langbfdea662014-07-23 14:16:32 -04003296 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003297
Geoff Langbfdea662014-07-23 14:16:32 -04003298 if (context)
3299 {
3300 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3301
3302 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003303 {
Geoff Langbfdea662014-07-23 14:16:32 -04003304 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003305 }
Geoff Langbfdea662014-07-23 14:16:32 -04003306
3307 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003308 }
3309
3310 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003311}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003312
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003313GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3314{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003315 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003316
Geoff Langbfdea662014-07-23 14:16:32 -04003317 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003318
Geoff Langbfdea662014-07-23 14:16:32 -04003319 if (context && framebuffer)
3320 {
3321 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3322
3323 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003324 {
Geoff Langbfdea662014-07-23 14:16:32 -04003325 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003326 }
3327 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
3329 return GL_FALSE;
3330}
3331
3332GLboolean __stdcall glIsProgram(GLuint program)
3333{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003334 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003335
Geoff Langbfdea662014-07-23 14:16:32 -04003336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003337
Geoff Langbfdea662014-07-23 14:16:32 -04003338 if (context && program)
3339 {
3340 gl::Program *programObject = context->getProgram(program);
3341
3342 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003343 {
Geoff Langbfdea662014-07-23 14:16:32 -04003344 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003345 }
3346 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003347
3348 return GL_FALSE;
3349}
3350
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003351GLboolean __stdcall glIsQueryEXT(GLuint id)
3352{
3353 EVENT("(GLuint id = %d)", id);
3354
Geoff Langbfdea662014-07-23 14:16:32 -04003355 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003356
Geoff Langbfdea662014-07-23 14:16:32 -04003357 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003358 {
Geoff Langbfdea662014-07-23 14:16:32 -04003359 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003360 }
3361
3362 return GL_FALSE;
3363}
3364
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003365GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3366{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003367 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003368
Geoff Langbfdea662014-07-23 14:16:32 -04003369 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003370
Geoff Langbfdea662014-07-23 14:16:32 -04003371 if (context && renderbuffer)
3372 {
3373 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3374
3375 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003376 {
Geoff Langbfdea662014-07-23 14:16:32 -04003377 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003378 }
3379 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003380
3381 return GL_FALSE;
3382}
3383
3384GLboolean __stdcall glIsShader(GLuint shader)
3385{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003386 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003387
Geoff Langbfdea662014-07-23 14:16:32 -04003388 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003389
Geoff Langbfdea662014-07-23 14:16:32 -04003390 if (context && shader)
3391 {
3392 gl::Shader *shaderObject = context->getShader(shader);
3393
3394 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003395 {
Geoff Langbfdea662014-07-23 14:16:32 -04003396 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397 }
3398 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003399
3400 return GL_FALSE;
3401}
3402
3403GLboolean __stdcall glIsTexture(GLuint texture)
3404{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003405 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003406
Geoff Langbfdea662014-07-23 14:16:32 -04003407 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003408
Geoff Langbfdea662014-07-23 14:16:32 -04003409 if (context && texture)
3410 {
3411 gl::Texture *textureObject = context->getTexture(texture);
3412
3413 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003414 {
Geoff Langbfdea662014-07-23 14:16:32 -04003415 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003416 }
3417 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418
3419 return GL_FALSE;
3420}
3421
3422void __stdcall glLineWidth(GLfloat width)
3423{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003424 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003425
Geoff Langbfdea662014-07-23 14:16:32 -04003426 if (width <= 0.0f)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427 {
Geoff Langbfdea662014-07-23 14:16:32 -04003428 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003429 }
Geoff Langbfdea662014-07-23 14:16:32 -04003430
3431 gl::Context *context = gl::getNonLostContext();
3432
3433 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003434 {
Geoff Langbfdea662014-07-23 14:16:32 -04003435 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003436 }
3437}
3438
3439void __stdcall glLinkProgram(GLuint program)
3440{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003441 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003442
Geoff Langbfdea662014-07-23 14:16:32 -04003443 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003444
Geoff Langbfdea662014-07-23 14:16:32 -04003445 if (context)
3446 {
3447 gl::Program *programObject = context->getProgram(program);
3448
3449 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003450 {
Geoff Langbfdea662014-07-23 14:16:32 -04003451 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003452 {
Geoff Langbfdea662014-07-23 14:16:32 -04003453 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003454 }
Geoff Langbfdea662014-07-23 14:16:32 -04003455 else
3456 {
3457 return gl::error(GL_INVALID_VALUE);
3458 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003459 }
Geoff Langbfdea662014-07-23 14:16:32 -04003460
3461 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003462 }
3463}
3464
3465void __stdcall glPixelStorei(GLenum pname, GLint param)
3466{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003467 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468
Geoff Langbfdea662014-07-23 14:16:32 -04003469 gl::Context *context = gl::getNonLostContext();
3470
3471 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003472 {
Geoff Langbfdea662014-07-23 14:16:32 -04003473 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003474 {
Geoff Langbfdea662014-07-23 14:16:32 -04003475 case GL_UNPACK_ALIGNMENT:
3476 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003477 {
Geoff Langbfdea662014-07-23 14:16:32 -04003478 return gl::error(GL_INVALID_VALUE);
3479 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003480
Geoff Langbfdea662014-07-23 14:16:32 -04003481 context->getState().setUnpackAlignment(param);
3482 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003483
Geoff Langbfdea662014-07-23 14:16:32 -04003484 case GL_PACK_ALIGNMENT:
3485 if (param != 1 && param != 2 && param != 4 && param != 8)
3486 {
3487 return gl::error(GL_INVALID_VALUE);
3488 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003489
Geoff Langbfdea662014-07-23 14:16:32 -04003490 context->getState().setPackAlignment(param);
3491 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003492
Geoff Langbfdea662014-07-23 14:16:32 -04003493 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3494 context->getState().setPackReverseRowOrder(param != 0);
3495 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003496
Geoff Langbfdea662014-07-23 14:16:32 -04003497 case GL_UNPACK_IMAGE_HEIGHT:
3498 case GL_UNPACK_SKIP_IMAGES:
3499 case GL_UNPACK_ROW_LENGTH:
3500 case GL_UNPACK_SKIP_ROWS:
3501 case GL_UNPACK_SKIP_PIXELS:
3502 case GL_PACK_ROW_LENGTH:
3503 case GL_PACK_SKIP_ROWS:
3504 case GL_PACK_SKIP_PIXELS:
3505 if (context->getClientVersion() < 3)
3506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003507 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003508 }
Geoff Langbfdea662014-07-23 14:16:32 -04003509 UNIMPLEMENTED();
3510 break;
3511
3512 default:
3513 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003514 }
3515 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003516}
3517
3518void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3519{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003520 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003521
Geoff Langbfdea662014-07-23 14:16:32 -04003522 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00003523
Geoff Langbfdea662014-07-23 14:16:32 -04003524 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003525 {
Geoff Langbfdea662014-07-23 14:16:32 -04003526 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003527 }
3528}
3529
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003530void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3531 GLenum format, GLenum type, GLsizei bufSize,
3532 GLvoid *data)
3533{
3534 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3535 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3536 x, y, width, height, format, type, bufSize, data);
3537
Geoff Langbfdea662014-07-23 14:16:32 -04003538 if (width < 0 || height < 0 || bufSize < 0)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003539 {
Geoff Langbfdea662014-07-23 14:16:32 -04003540 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003541 }
Geoff Langbfdea662014-07-23 14:16:32 -04003542
3543 gl::Context *context = gl::getNonLostContext();
3544
3545 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003546 {
Geoff Langbfdea662014-07-23 14:16:32 -04003547 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3548 format, type, &bufSize, data))
3549 {
3550 return;
3551 }
3552
3553 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003554 }
3555}
3556
3557void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3558 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003560 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003561 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003562 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003563
Geoff Langbfdea662014-07-23 14:16:32 -04003564 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003565 {
Geoff Langbfdea662014-07-23 14:16:32 -04003566 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003567 }
Geoff Langbfdea662014-07-23 14:16:32 -04003568
3569 gl::Context *context = gl::getNonLostContext();
3570
3571 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003572 {
Geoff Langbfdea662014-07-23 14:16:32 -04003573 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3574 format, type, NULL, pixels))
3575 {
3576 return;
3577 }
3578
3579 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003580 }
3581}
3582
3583void __stdcall glReleaseShaderCompiler(void)
3584{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003585 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003586
Geoff Langbfdea662014-07-23 14:16:32 -04003587 gl::Shader::releaseCompiler();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003588}
3589
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003590void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003591{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003592 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 +00003593 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594
Geoff Langbfdea662014-07-23 14:16:32 -04003595 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003596
Geoff Langbfdea662014-07-23 14:16:32 -04003597 if (context)
3598 {
3599 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3600 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003601 {
Geoff Langbfdea662014-07-23 14:16:32 -04003602 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003603 }
Geoff Langbfdea662014-07-23 14:16:32 -04003604
3605 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606 }
3607}
3608
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003609void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3610{
3611 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3612}
3613
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003614void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3615{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003616 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617
Geoff Langbfdea662014-07-23 14:16:32 -04003618 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003619
Geoff Langbfdea662014-07-23 14:16:32 -04003620 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003621 {
Geoff Langbfdea662014-07-23 14:16:32 -04003622 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003623 }
3624}
3625
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003626void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3627{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003628 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003629
Geoff Langbfdea662014-07-23 14:16:32 -04003630 if (condition != GL_ALL_COMPLETED_NV)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003631 {
Geoff Langbfdea662014-07-23 14:16:32 -04003632 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003633 }
Geoff Langbfdea662014-07-23 14:16:32 -04003634
3635 gl::Context *context = gl::getNonLostContext();
3636
3637 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003638 {
Geoff Langbfdea662014-07-23 14:16:32 -04003639 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3640
3641 if (fenceObject == NULL)
3642 {
3643 return gl::error(GL_INVALID_OPERATION);
3644 }
3645
3646 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003647 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003648}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003649
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003650void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3651{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003652 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 +00003653
Geoff Langbfdea662014-07-23 14:16:32 -04003654 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003655 {
Geoff Langbfdea662014-07-23 14:16:32 -04003656 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003657 }
Geoff Langbfdea662014-07-23 14:16:32 -04003658
3659 gl::Context* context = gl::getNonLostContext();
3660
3661 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003662 {
Geoff Langbfdea662014-07-23 14:16:32 -04003663 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664 }
3665}
3666
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003667void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003668{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003669 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003670 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003671 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003672
Geoff Lang900013c2014-07-07 11:32:19 -04003673 gl::Context* context = gl::getNonLostContext();
3674 if (context)
3675 {
3676 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3677 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3678 {
3679 return gl::error(GL_INVALID_ENUM);
3680 }
3681
3682 // No binary shader formats are supported.
3683 UNIMPLEMENTED();
3684 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003685}
3686
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003687void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003688{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003689 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 +00003690 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003691
Geoff Langbfdea662014-07-23 14:16:32 -04003692 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003693 {
Geoff Langbfdea662014-07-23 14:16:32 -04003694 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003695 }
Geoff Langbfdea662014-07-23 14:16:32 -04003696
3697 gl::Context *context = gl::getNonLostContext();
3698
3699 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003700 {
Geoff Langbfdea662014-07-23 14:16:32 -04003701 gl::Shader *shaderObject = context->getShader(shader);
3702
3703 if (!shaderObject)
3704 {
3705 if (context->getProgram(shader))
3706 {
3707 return gl::error(GL_INVALID_OPERATION);
3708 }
3709 else
3710 {
3711 return gl::error(GL_INVALID_VALUE);
3712 }
3713 }
3714
3715 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003716 }
3717}
3718
3719void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3720{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003721 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003722}
3723
3724void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3725{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003726 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 +00003727
Geoff Langbfdea662014-07-23 14:16:32 -04003728 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003729 {
Geoff Langbfdea662014-07-23 14:16:32 -04003730 case GL_FRONT:
3731 case GL_BACK:
3732 case GL_FRONT_AND_BACK:
3733 break;
3734 default:
3735 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003736 }
Geoff Langbfdea662014-07-23 14:16:32 -04003737
3738 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003739 {
Geoff Langbfdea662014-07-23 14:16:32 -04003740 case GL_NEVER:
3741 case GL_ALWAYS:
3742 case GL_LESS:
3743 case GL_LEQUAL:
3744 case GL_EQUAL:
3745 case GL_GEQUAL:
3746 case GL_GREATER:
3747 case GL_NOTEQUAL:
3748 break;
3749 default:
3750 return gl::error(GL_INVALID_ENUM);
3751 }
3752
3753 gl::Context *context = gl::getNonLostContext();
3754
3755 if (context)
3756 {
3757 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3758 {
3759 context->getState().setStencilParams(func, ref, mask);
3760 }
3761
3762 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3763 {
3764 context->getState().setStencilBackParams(func, ref, mask);
3765 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003766 }
3767}
3768
3769void __stdcall glStencilMask(GLuint mask)
3770{
3771 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3772}
3773
3774void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3775{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003776 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003777
Geoff Langbfdea662014-07-23 14:16:32 -04003778 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003779 {
Geoff Langbfdea662014-07-23 14:16:32 -04003780 case GL_FRONT:
3781 case GL_BACK:
3782 case GL_FRONT_AND_BACK:
3783 break;
3784 default:
3785 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003786 }
Geoff Langbfdea662014-07-23 14:16:32 -04003787
3788 gl::Context *context = gl::getNonLostContext();
3789
3790 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003791 {
Geoff Langbfdea662014-07-23 14:16:32 -04003792 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3793 {
3794 context->getState().setStencilWritemask(mask);
3795 }
3796
3797 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3798 {
3799 context->getState().setStencilBackWritemask(mask);
3800 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003801 }
3802}
3803
3804void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3805{
3806 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3807}
3808
3809void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3810{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003811 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 +00003812 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003813
Geoff Langbfdea662014-07-23 14:16:32 -04003814 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003815 {
Geoff Langbfdea662014-07-23 14:16:32 -04003816 case GL_FRONT:
3817 case GL_BACK:
3818 case GL_FRONT_AND_BACK:
3819 break;
3820 default:
3821 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003822 }
Geoff Langbfdea662014-07-23 14:16:32 -04003823
3824 switch (fail)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003825 {
Geoff Langbfdea662014-07-23 14:16:32 -04003826 case GL_ZERO:
3827 case GL_KEEP:
3828 case GL_REPLACE:
3829 case GL_INCR:
3830 case GL_DECR:
3831 case GL_INVERT:
3832 case GL_INCR_WRAP:
3833 case GL_DECR_WRAP:
3834 break;
3835 default:
3836 return gl::error(GL_INVALID_ENUM);
3837 }
3838
3839 switch (zfail)
3840 {
3841 case GL_ZERO:
3842 case GL_KEEP:
3843 case GL_REPLACE:
3844 case GL_INCR:
3845 case GL_DECR:
3846 case GL_INVERT:
3847 case GL_INCR_WRAP:
3848 case GL_DECR_WRAP:
3849 break;
3850 default:
3851 return gl::error(GL_INVALID_ENUM);
3852 }
3853
3854 switch (zpass)
3855 {
3856 case GL_ZERO:
3857 case GL_KEEP:
3858 case GL_REPLACE:
3859 case GL_INCR:
3860 case GL_DECR:
3861 case GL_INVERT:
3862 case GL_INCR_WRAP:
3863 case GL_DECR_WRAP:
3864 break;
3865 default:
3866 return gl::error(GL_INVALID_ENUM);
3867 }
3868
3869 gl::Context *context = gl::getNonLostContext();
3870
3871 if (context)
3872 {
3873 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3874 {
3875 context->getState().setStencilOperations(fail, zfail, zpass);
3876 }
3877
3878 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3879 {
3880 context->getState().setStencilBackOperations(fail, zfail, zpass);
3881 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003882 }
3883}
3884
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003885GLboolean __stdcall glTestFenceNV(GLuint fence)
3886{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003887 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003888
Geoff Langbfdea662014-07-23 14:16:32 -04003889 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003890
Geoff Langbfdea662014-07-23 14:16:32 -04003891 if (context)
3892 {
3893 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3894
3895 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003896 {
Geoff Langbfdea662014-07-23 14:16:32 -04003897 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003898 }
Geoff Langbfdea662014-07-23 14:16:32 -04003899
3900 if (fenceObject->isFence() != GL_TRUE)
3901 {
3902 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
3903 }
3904
3905 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003906 }
Geoff Langbfdea662014-07-23 14:16:32 -04003907
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003908 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003909}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003910
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003911void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
3912 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003913{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003914 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05003915 "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 +00003916 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003917
Geoff Langbfdea662014-07-23 14:16:32 -04003918 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003919
Geoff Langbfdea662014-07-23 14:16:32 -04003920 if (context)
3921 {
3922 if (context->getClientVersion() < 3 &&
3923 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
3924 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003925 {
Geoff Langbfdea662014-07-23 14:16:32 -04003926 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003927 }
Geoff Langbfdea662014-07-23 14:16:32 -04003928
3929 if (context->getClientVersion() >= 3 &&
3930 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
3931 0, 0, 0, width, height, 1, border, format, type, pixels))
3932 {
3933 return;
3934 }
3935
3936 switch (target)
3937 {
3938 case GL_TEXTURE_2D:
3939 {
3940 gl::Texture2D *texture = context->getTexture2D();
3941 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3942 }
3943 break;
3944 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3945 {
3946 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3947 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3948 }
3949 break;
3950 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3951 {
3952 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3953 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3954 }
3955 break;
3956 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3957 {
3958 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3959 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3960 }
3961 break;
3962 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3963 {
3964 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3965 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3966 }
3967 break;
3968 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3969 {
3970 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3971 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3972 }
3973 break;
3974 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
3975 {
3976 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3977 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3978 }
3979 break;
3980 default: UNREACHABLE();
3981 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003982 }
3983}
3984
3985void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
3986{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003987 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
3988
Geoff Langbfdea662014-07-23 14:16:32 -04003989 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003990
Geoff Langbfdea662014-07-23 14:16:32 -04003991 if (context)
3992 {
3993 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003994 {
Geoff Langbfdea662014-07-23 14:16:32 -04003995 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003996 }
Geoff Langbfdea662014-07-23 14:16:32 -04003997
3998 gl::Texture *texture = context->getTargetTexture(target);
3999
4000 if (!texture)
4001 {
4002 return gl::error(GL_INVALID_ENUM);
4003 }
4004
4005 switch (pname)
4006 {
4007 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4008 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4009 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4010 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4011 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4012 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4013 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4014 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4015 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4016 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4017 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4018 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4019 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4020 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4021 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4022 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4023 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4024 default: UNREACHABLE(); break;
4025 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004026 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004027}
4028
4029void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4030{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004031 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004032}
4033
4034void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4035{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004036 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004037
Geoff Langbfdea662014-07-23 14:16:32 -04004038 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004039
Geoff Langbfdea662014-07-23 14:16:32 -04004040 if (context)
4041 {
4042 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004043 {
Geoff Langbfdea662014-07-23 14:16:32 -04004044 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004045 }
Geoff Langbfdea662014-07-23 14:16:32 -04004046
4047 gl::Texture *texture = context->getTargetTexture(target);
4048
4049 if (!texture)
4050 {
4051 return gl::error(GL_INVALID_ENUM);
4052 }
4053
4054 switch (pname)
4055 {
4056 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4057 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4058 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4059 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4060 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4061 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4062 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4063 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4064 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4065 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4066 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4067 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4068 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4069 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4070 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4071 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4072 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4073 default: UNREACHABLE(); break;
4074 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004075 }
4076}
4077
4078void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4079{
4080 glTexParameteri(target, pname, *params);
4081}
4082
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004083void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4084{
4085 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4086 target, levels, internalformat, width, height);
4087
Geoff Langbfdea662014-07-23 14:16:32 -04004088 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004089
Geoff Langbfdea662014-07-23 14:16:32 -04004090 if (context)
4091 {
4092 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004093 {
Geoff Langbfdea662014-07-23 14:16:32 -04004094 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004095 }
Geoff Langbfdea662014-07-23 14:16:32 -04004096
4097 if (context->getClientVersion() < 3 &&
4098 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4099 {
4100 return;
4101 }
4102
4103 if (context->getClientVersion() >= 3 &&
4104 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4105 {
4106 return;
4107 }
4108
4109 switch (target)
4110 {
4111 case GL_TEXTURE_2D:
4112 {
4113 gl::Texture2D *texture2d = context->getTexture2D();
4114 texture2d->storage(levels, internalformat, width, height);
4115 }
4116 break;
4117
4118 case GL_TEXTURE_CUBE_MAP:
4119 {
4120 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4121 textureCube->storage(levels, internalformat, width);
4122 }
4123 break;
4124
4125 default:
4126 return gl::error(GL_INVALID_ENUM);
4127 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004128 }
4129}
4130
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004131void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4132 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004133{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004134 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004135 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004136 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004137 target, level, xoffset, yoffset, width, height, format, type, pixels);
4138
Geoff Langbfdea662014-07-23 14:16:32 -04004139 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004140
Geoff Langbfdea662014-07-23 14:16:32 -04004141 if (context)
4142 {
4143 if (context->getClientVersion() < 3 &&
4144 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4145 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004146 {
Geoff Langbfdea662014-07-23 14:16:32 -04004147 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004148 }
Geoff Langbfdea662014-07-23 14:16:32 -04004149
4150 if (context->getClientVersion() >= 3 &&
4151 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4152 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4153 {
4154 return;
4155 }
4156
4157 // Zero sized uploads are valid but no-ops
4158 if (width == 0 || height == 0)
4159 {
4160 return;
4161 }
4162
4163 switch (target)
4164 {
4165 case GL_TEXTURE_2D:
4166 {
4167 gl::Texture2D *texture = context->getTexture2D();
4168 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4169 }
4170 break;
4171
4172 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4173 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4174 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4175 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4176 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4177 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4178 {
4179 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4180 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4181 }
4182 break;
4183
4184 default:
4185 UNREACHABLE();
4186 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004187 }
4188}
4189
4190void __stdcall glUniform1f(GLint location, GLfloat x)
4191{
4192 glUniform1fv(location, 1, &x);
4193}
4194
4195void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4196{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004197 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004198
Geoff Langbfdea662014-07-23 14:16:32 -04004199 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004200
Geoff Langbfdea662014-07-23 14:16:32 -04004201 if (context)
4202 {
4203 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004204 {
Geoff Langbfdea662014-07-23 14:16:32 -04004205 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004206 }
Geoff Langbfdea662014-07-23 14:16:32 -04004207
4208 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4209 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004210 }
4211}
4212
4213void __stdcall glUniform1i(GLint location, GLint x)
4214{
4215 glUniform1iv(location, 1, &x);
4216}
4217
4218void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4219{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004220 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004221
Geoff Langbfdea662014-07-23 14:16:32 -04004222 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004223
Geoff Langbfdea662014-07-23 14:16:32 -04004224 if (context)
4225 {
4226 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004227 {
Geoff Langbfdea662014-07-23 14:16:32 -04004228 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004229 }
Geoff Langbfdea662014-07-23 14:16:32 -04004230
4231 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4232 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004233 }
4234}
4235
4236void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4237{
4238 GLfloat xy[2] = {x, y};
4239
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004240 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004241}
4242
4243void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4244{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004245 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004246
Geoff Langbfdea662014-07-23 14:16:32 -04004247 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004248
Geoff Langbfdea662014-07-23 14:16:32 -04004249 if (context)
4250 {
4251 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004252 {
Geoff Langbfdea662014-07-23 14:16:32 -04004253 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004254 }
Geoff Langbfdea662014-07-23 14:16:32 -04004255
4256 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4257 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
4259}
4260
4261void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4262{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004263 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004264
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004265 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004266}
4267
4268void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4269{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004270 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004271
Geoff Langbfdea662014-07-23 14:16:32 -04004272 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004273
Geoff Langbfdea662014-07-23 14:16:32 -04004274 if (context)
4275 {
4276 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004277 {
Geoff Langbfdea662014-07-23 14:16:32 -04004278 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004279 }
Geoff Langbfdea662014-07-23 14:16:32 -04004280
4281 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4282 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004283 }
4284}
4285
4286void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4287{
4288 GLfloat xyz[3] = {x, y, z};
4289
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004290 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291}
4292
4293void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4294{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004295 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004296
Geoff Langbfdea662014-07-23 14:16:32 -04004297 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004298
Geoff Langbfdea662014-07-23 14:16:32 -04004299 if (context)
4300 {
4301 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004302 {
Geoff Langbfdea662014-07-23 14:16:32 -04004303 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004304 }
Geoff Langbfdea662014-07-23 14:16:32 -04004305
4306 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4307 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004308 }
4309}
4310
4311void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4312{
4313 GLint xyz[3] = {x, y, z};
4314
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004315 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004316}
4317
4318void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4319{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004320 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004321
Geoff Langbfdea662014-07-23 14:16:32 -04004322 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004323
Geoff Langbfdea662014-07-23 14:16:32 -04004324 if (context)
4325 {
4326 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004327 {
Geoff Langbfdea662014-07-23 14:16:32 -04004328 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004329 }
Geoff Langbfdea662014-07-23 14:16:32 -04004330
4331 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4332 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004333 }
4334}
4335
4336void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4337{
4338 GLfloat xyzw[4] = {x, y, z, w};
4339
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004340 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004341}
4342
4343void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4344{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004345 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004346
Geoff Langbfdea662014-07-23 14:16:32 -04004347 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004348
Geoff Langbfdea662014-07-23 14:16:32 -04004349 if (context)
4350 {
4351 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004352 {
Geoff Langbfdea662014-07-23 14:16:32 -04004353 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004354 }
Geoff Langbfdea662014-07-23 14:16:32 -04004355
4356 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4357 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004358 }
4359}
4360
4361void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4362{
4363 GLint xyzw[4] = {x, y, z, w};
4364
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004365 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004366}
4367
4368void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4369{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004370 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004371
Geoff Langbfdea662014-07-23 14:16:32 -04004372 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004373
Geoff Langbfdea662014-07-23 14:16:32 -04004374 if (context)
4375 {
4376 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004377 {
Geoff Langbfdea662014-07-23 14:16:32 -04004378 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004379 }
Geoff Langbfdea662014-07-23 14:16:32 -04004380
4381 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4382 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004383 }
4384}
4385
4386void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4387{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004388 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004389 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004390
Geoff Langbfdea662014-07-23 14:16:32 -04004391 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004392
Geoff Langbfdea662014-07-23 14:16:32 -04004393 if (context)
4394 {
4395 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004396 {
Geoff Langbfdea662014-07-23 14:16:32 -04004397 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004398 }
Geoff Langbfdea662014-07-23 14:16:32 -04004399
4400 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4401 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004402 }
4403}
4404
4405void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4406{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004407 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004408 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004409
Geoff Langbfdea662014-07-23 14:16:32 -04004410 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004411
Geoff Langbfdea662014-07-23 14:16:32 -04004412 if (context)
4413 {
4414 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004415 {
Geoff Langbfdea662014-07-23 14:16:32 -04004416 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004417 }
Geoff Langbfdea662014-07-23 14:16:32 -04004418
4419 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4420 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004421 }
4422}
4423
4424void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4425{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004426 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004427 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004428
Geoff Langbfdea662014-07-23 14:16:32 -04004429 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004430
Geoff Langbfdea662014-07-23 14:16:32 -04004431 if (context)
4432 {
4433 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004434 {
Geoff Langbfdea662014-07-23 14:16:32 -04004435 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004436 }
Geoff Langbfdea662014-07-23 14:16:32 -04004437
4438 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4439 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004440 }
4441}
4442
4443void __stdcall glUseProgram(GLuint program)
4444{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004445 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004446
Geoff Langbfdea662014-07-23 14:16:32 -04004447 gl::Context *context = gl::getNonLostContext();
4448
4449 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450 {
Geoff Langbfdea662014-07-23 14:16:32 -04004451 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452
Geoff Langbfdea662014-07-23 14:16:32 -04004453 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454 {
Geoff Langbfdea662014-07-23 14:16:32 -04004455 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004456 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004457 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004458 }
Geoff Langbfdea662014-07-23 14:16:32 -04004459 else
4460 {
4461 return gl::error(GL_INVALID_VALUE);
4462 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004463 }
Geoff Langbfdea662014-07-23 14:16:32 -04004464
4465 if (program != 0 && !programObject->isLinked())
4466 {
4467 return gl::error(GL_INVALID_OPERATION);
4468 }
4469
4470 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004471 }
4472}
4473
4474void __stdcall glValidateProgram(GLuint program)
4475{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004476 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004477
Geoff Langbfdea662014-07-23 14:16:32 -04004478 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004479
Geoff Langbfdea662014-07-23 14:16:32 -04004480 if (context)
4481 {
4482 gl::Program *programObject = context->getProgram(program);
4483
4484 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004485 {
Geoff Langbfdea662014-07-23 14:16:32 -04004486 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004487 {
Geoff Langbfdea662014-07-23 14:16:32 -04004488 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004489 }
Geoff Langbfdea662014-07-23 14:16:32 -04004490 else
4491 {
4492 return gl::error(GL_INVALID_VALUE);
4493 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004494 }
Geoff Langbfdea662014-07-23 14:16:32 -04004495
4496 programObject->validate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004497 }
4498}
4499
4500void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4501{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004502 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004503
Geoff Langbfdea662014-07-23 14:16:32 -04004504 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004505 {
Geoff Langbfdea662014-07-23 14:16:32 -04004506 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004507 }
Geoff Langbfdea662014-07-23 14:16:32 -04004508
4509 gl::Context *context = gl::getNonLostContext();
4510
4511 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004512 {
Geoff Langbfdea662014-07-23 14:16:32 -04004513 GLfloat vals[4] = { x, 0, 0, 1 };
4514 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004515 }
4516}
4517
4518void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4519{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004520 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004521
Geoff Langbfdea662014-07-23 14:16:32 -04004522 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004523 {
Geoff Langbfdea662014-07-23 14:16:32 -04004524 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004525 }
Geoff Langbfdea662014-07-23 14:16:32 -04004526
4527 gl::Context *context = gl::getNonLostContext();
4528
4529 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004530 {
Geoff Langbfdea662014-07-23 14:16:32 -04004531 GLfloat vals[4] = { values[0], 0, 0, 1 };
4532 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004533 }
4534}
4535
4536void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4537{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004538 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004539
Geoff Langbfdea662014-07-23 14:16:32 -04004540 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004541 {
Geoff Langbfdea662014-07-23 14:16:32 -04004542 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543 }
Geoff Langbfdea662014-07-23 14:16:32 -04004544
4545 gl::Context *context = gl::getNonLostContext();
4546
4547 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004548 {
Geoff Langbfdea662014-07-23 14:16:32 -04004549 GLfloat vals[4] = { x, y, 0, 1 };
4550 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004551 }
4552}
4553
4554void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4555{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004556 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557
Geoff Langbfdea662014-07-23 14:16:32 -04004558 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004559 {
Geoff Langbfdea662014-07-23 14:16:32 -04004560 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004561 }
Geoff Langbfdea662014-07-23 14:16:32 -04004562
4563 gl::Context *context = gl::getNonLostContext();
4564
4565 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004566 {
Geoff Langbfdea662014-07-23 14:16:32 -04004567 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4568 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004569 }
4570}
4571
4572void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4573{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004574 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 +00004575
Geoff Langbfdea662014-07-23 14:16:32 -04004576 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004577 {
Geoff Langbfdea662014-07-23 14:16:32 -04004578 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004579 }
Geoff Langbfdea662014-07-23 14:16:32 -04004580
4581 gl::Context *context = gl::getNonLostContext();
4582
4583 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004584 {
Geoff Langbfdea662014-07-23 14:16:32 -04004585 GLfloat vals[4] = { x, y, z, 1 };
4586 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004587 }
4588}
4589
4590void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4591{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004592 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004593
Geoff Langbfdea662014-07-23 14:16:32 -04004594 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004595 {
Geoff Langbfdea662014-07-23 14:16:32 -04004596 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004597 }
Geoff Langbfdea662014-07-23 14:16:32 -04004598
4599 gl::Context *context = gl::getNonLostContext();
4600
4601 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004602 {
Geoff Langbfdea662014-07-23 14:16:32 -04004603 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4604 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004605 }
4606}
4607
4608void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4609{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004610 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 +00004611
Geoff Langbfdea662014-07-23 14:16:32 -04004612 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004613 {
Geoff Langbfdea662014-07-23 14:16:32 -04004614 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004615 }
Geoff Langbfdea662014-07-23 14:16:32 -04004616
4617 gl::Context *context = gl::getNonLostContext();
4618
4619 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004620 {
Geoff Langbfdea662014-07-23 14:16:32 -04004621 GLfloat vals[4] = { x, y, z, w };
4622 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004623 }
4624}
4625
4626void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4627{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004628 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004629
Geoff Langbfdea662014-07-23 14:16:32 -04004630 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004631 {
Geoff Langbfdea662014-07-23 14:16:32 -04004632 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004633 }
Geoff Langbfdea662014-07-23 14:16:32 -04004634
4635 gl::Context *context = gl::getNonLostContext();
4636
4637 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004638 {
Geoff Langbfdea662014-07-23 14:16:32 -04004639 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004640 }
4641}
4642
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004643void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4644{
4645 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4646
Geoff Langbfdea662014-07-23 14:16:32 -04004647 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004648 {
Geoff Langbfdea662014-07-23 14:16:32 -04004649 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004650 }
Geoff Langbfdea662014-07-23 14:16:32 -04004651
4652 gl::Context *context = gl::getNonLostContext();
4653
4654 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004655 {
Geoff Langbfdea662014-07-23 14:16:32 -04004656 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004657 }
4658}
4659
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004660void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004662 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004663 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004664 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004665
Geoff Langbfdea662014-07-23 14:16:32 -04004666 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004667 {
Geoff Langbfdea662014-07-23 14:16:32 -04004668 return gl::error(GL_INVALID_VALUE);
4669 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670
Geoff Langbfdea662014-07-23 14:16:32 -04004671 if (size < 1 || size > 4)
4672 {
4673 return gl::error(GL_INVALID_VALUE);
4674 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004675
Geoff Langbfdea662014-07-23 14:16:32 -04004676 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00004677
Geoff Langbfdea662014-07-23 14:16:32 -04004678 switch (type)
4679 {
4680 case GL_BYTE:
4681 case GL_UNSIGNED_BYTE:
4682 case GL_SHORT:
4683 case GL_UNSIGNED_SHORT:
4684 case GL_FIXED:
4685 case GL_FLOAT:
4686 break;
4687 case GL_HALF_FLOAT:
4688 case GL_INT:
4689 case GL_UNSIGNED_INT:
4690 case GL_INT_2_10_10_10_REV:
4691 case GL_UNSIGNED_INT_2_10_10_10_REV:
4692 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004694 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004695 }
Geoff Langbfdea662014-07-23 14:16:32 -04004696 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004697 {
Geoff Langbfdea662014-07-23 14:16:32 -04004698 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004699 }
Geoff Langbfdea662014-07-23 14:16:32 -04004700 default:
4701 return gl::error(GL_INVALID_ENUM);
4702 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004703
Geoff Langbfdea662014-07-23 14:16:32 -04004704 if (stride < 0)
4705 {
4706 return gl::error(GL_INVALID_VALUE);
4707 }
4708
4709 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4710 {
4711 return gl::error(GL_INVALID_OPERATION);
4712 }
4713
4714 if (context)
4715 {
4716 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4717 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4718 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4719 // and the pointer argument is not NULL.
4720 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004721 {
4722 return gl::error(GL_INVALID_OPERATION);
4723 }
4724
Geoff Langbfdea662014-07-23 14:16:32 -04004725 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4726 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004727 }
4728}
4729
4730void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4731{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004732 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 +00004733
Geoff Langbfdea662014-07-23 14:16:32 -04004734 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004735 {
Geoff Langbfdea662014-07-23 14:16:32 -04004736 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004737 }
Geoff Langbfdea662014-07-23 14:16:32 -04004738
4739 gl::Context *context = gl::getNonLostContext();
4740
4741 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004742 {
Geoff Langbfdea662014-07-23 14:16:32 -04004743 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004744 }
4745}
4746
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004747// OpenGL ES 3.0 functions
4748
4749void __stdcall glReadBuffer(GLenum mode)
4750{
4751 EVENT("(GLenum mode = 0x%X)", mode);
4752
Geoff Langbfdea662014-07-23 14:16:32 -04004753 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004754
Geoff Langbfdea662014-07-23 14:16:32 -04004755 if (context)
4756 {
4757 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004758 {
Geoff Langbfdea662014-07-23 14:16:32 -04004759 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004760 }
Geoff Langbfdea662014-07-23 14:16:32 -04004761
4762 // glReadBuffer
4763 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004764 }
4765}
4766
4767void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4768{
4769 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4770 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4771
Geoff Langbfdea662014-07-23 14:16:32 -04004772 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004773
Geoff Langbfdea662014-07-23 14:16:32 -04004774 if (context)
4775 {
4776 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004777 {
Geoff Langbfdea662014-07-23 14:16:32 -04004778 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004779 }
Geoff Langbfdea662014-07-23 14:16:32 -04004780
4781 // glDrawRangeElements
4782 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004783 }
4784}
4785
4786void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4787{
4788 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4789 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4790 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4791 target, level, internalformat, width, height, depth, border, format, type, pixels);
4792
Geoff Langbfdea662014-07-23 14:16:32 -04004793 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004794
Geoff Langbfdea662014-07-23 14:16:32 -04004795 if (context)
4796 {
4797 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004798 {
Geoff Langbfdea662014-07-23 14:16:32 -04004799 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004800 }
Geoff Langbfdea662014-07-23 14:16:32 -04004801
4802 // validateES3TexImageFormat sets the error code if there is an error
4803 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4804 0, 0, 0, width, height, depth, border, format, type, pixels))
4805 {
4806 return;
4807 }
4808
4809 switch(target)
4810 {
4811 case GL_TEXTURE_3D:
4812 {
4813 gl::Texture3D *texture = context->getTexture3D();
4814 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4815 }
4816 break;
4817
4818 case GL_TEXTURE_2D_ARRAY:
4819 {
4820 gl::Texture2DArray *texture = context->getTexture2DArray();
4821 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4822 }
4823 break;
4824
4825 default:
4826 return gl::error(GL_INVALID_ENUM);
4827 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004828 }
4829}
4830
4831void __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)
4832{
4833 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4834 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4835 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4836 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4837
Geoff Langbfdea662014-07-23 14:16:32 -04004838 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004839
Geoff Langbfdea662014-07-23 14:16:32 -04004840 if (context)
4841 {
4842 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004843 {
Geoff Langbfdea662014-07-23 14:16:32 -04004844 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004845 }
Geoff Langbfdea662014-07-23 14:16:32 -04004846
4847 // validateES3TexImageFormat sets the error code if there is an error
4848 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4849 xoffset, yoffset, zoffset, width, height, depth, 0,
4850 format, type, pixels))
4851 {
4852 return;
4853 }
4854
4855 // Zero sized uploads are valid but no-ops
4856 if (width == 0 || height == 0 || depth == 0)
4857 {
4858 return;
4859 }
4860
4861 switch(target)
4862 {
4863 case GL_TEXTURE_3D:
4864 {
4865 gl::Texture3D *texture = context->getTexture3D();
4866 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4867 }
4868 break;
4869
4870 case GL_TEXTURE_2D_ARRAY:
4871 {
4872 gl::Texture2DArray *texture = context->getTexture2DArray();
4873 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4874 }
4875 break;
4876
4877 default:
4878 return gl::error(GL_INVALID_ENUM);
4879 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004880 }
4881}
4882
4883void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
4884{
4885 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4886 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
4887 target, level, xoffset, yoffset, zoffset, x, y, width, height);
4888
Geoff Langbfdea662014-07-23 14:16:32 -04004889 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004890
Geoff Langbfdea662014-07-23 14:16:32 -04004891 if (context)
4892 {
4893 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004894 {
Geoff Langbfdea662014-07-23 14:16:32 -04004895 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004896 }
Geoff Langbfdea662014-07-23 14:16:32 -04004897
4898 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
4899 x, y, width, height, 0))
4900 {
4901 return;
4902 }
4903
4904 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
4905 gl::Texture *texture = NULL;
4906 switch (target)
4907 {
4908 case GL_TEXTURE_3D:
4909 texture = context->getTexture3D();
4910 break;
4911
4912 case GL_TEXTURE_2D_ARRAY:
4913 texture = context->getTexture2DArray();
4914 break;
4915
4916 default:
4917 return gl::error(GL_INVALID_ENUM);
4918 }
4919
4920 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004921 }
4922}
4923
4924void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
4925{
Geoff Langeef52cc2013-10-16 15:07:39 -04004926 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 +00004927 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
4928 "const GLvoid* data = 0x%0.8p)",
4929 target, level, internalformat, width, height, depth, border, imageSize, data);
4930
Geoff Langbfdea662014-07-23 14:16:32 -04004931 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004932
Geoff Langbfdea662014-07-23 14:16:32 -04004933 if (context)
4934 {
4935 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004936 {
Geoff Langbfdea662014-07-23 14:16:32 -04004937 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004938 }
Geoff Langbfdea662014-07-23 14:16:32 -04004939
Geoff Lang5d601382014-07-22 15:14:06 -04004940 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
4941 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04004942 {
4943 return gl::error(GL_INVALID_VALUE);
4944 }
4945
4946 // validateES3TexImageFormat sets the error code if there is an error
4947 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
4948 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
4949 {
4950 return;
4951 }
4952
4953 switch(target)
4954 {
4955 case GL_TEXTURE_3D:
4956 {
4957 gl::Texture3D *texture = context->getTexture3D();
4958 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
4959 }
4960 break;
4961
4962 case GL_TEXTURE_2D_ARRAY:
4963 {
4964 gl::Texture2DArray *texture = context->getTexture2DArray();
4965 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
4966 }
4967 break;
4968
4969 default:
4970 return gl::error(GL_INVALID_ENUM);
4971 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004972 }
4973}
4974
4975void __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)
4976{
4977 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4978 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4979 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
4980 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
4981
Geoff Langbfdea662014-07-23 14:16:32 -04004982 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004983
Geoff Langbfdea662014-07-23 14:16:32 -04004984 if (context)
4985 {
4986 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004987 {
Geoff Langbfdea662014-07-23 14:16:32 -04004988 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004989 }
Geoff Langbfdea662014-07-23 14:16:32 -04004990
Geoff Lang5d601382014-07-22 15:14:06 -04004991 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
4992 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04004993 {
4994 return gl::error(GL_INVALID_VALUE);
4995 }
4996
4997 if (!data)
4998 {
4999 return gl::error(GL_INVALID_VALUE);
5000 }
5001
5002 // validateES3TexImageFormat sets the error code if there is an error
5003 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5004 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5005 {
5006 return;
5007 }
5008
5009 // Zero sized uploads are valid but no-ops
5010 if (width == 0 || height == 0)
5011 {
5012 return;
5013 }
5014
5015 switch(target)
5016 {
5017 case GL_TEXTURE_3D:
5018 {
5019 gl::Texture3D *texture = context->getTexture3D();
5020 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5021 format, imageSize, data);
5022 }
5023 break;
5024
5025 case GL_TEXTURE_2D_ARRAY:
5026 {
5027 gl::Texture2DArray *texture = context->getTexture2DArray();
5028 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5029 format, imageSize, data);
5030 }
5031 break;
5032
5033 default:
5034 return gl::error(GL_INVALID_ENUM);
5035 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005036 }
5037}
5038
5039void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5040{
5041 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5042
Geoff Langbfdea662014-07-23 14:16:32 -04005043 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005044
Geoff Langbfdea662014-07-23 14:16:32 -04005045 if (context)
5046 {
5047 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005048 {
Geoff Langbfdea662014-07-23 14:16:32 -04005049 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005050 }
Geoff Langbfdea662014-07-23 14:16:32 -04005051
5052 if (n < 0)
5053 {
5054 return gl::error(GL_INVALID_VALUE);
5055 }
5056
5057 for (GLsizei i = 0; i < n; i++)
5058 {
5059 ids[i] = context->createQuery();
5060 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005061 }
5062}
5063
5064void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5065{
5066 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5067
Geoff Langbfdea662014-07-23 14:16:32 -04005068 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005069
Geoff Langbfdea662014-07-23 14:16:32 -04005070 if (context)
5071 {
5072 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005073 {
Geoff Langbfdea662014-07-23 14:16:32 -04005074 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005075 }
Geoff Langbfdea662014-07-23 14:16:32 -04005076
5077 if (n < 0)
5078 {
5079 return gl::error(GL_INVALID_VALUE);
5080 }
5081
5082 for (GLsizei i = 0; i < n; i++)
5083 {
5084 context->deleteQuery(ids[i]);
5085 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005086 }
5087}
5088
5089GLboolean __stdcall glIsQuery(GLuint id)
5090{
5091 EVENT("(GLuint id = %u)", id);
5092
Geoff Langbfdea662014-07-23 14:16:32 -04005093 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005094
Geoff Langbfdea662014-07-23 14:16:32 -04005095 if (context)
5096 {
5097 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005098 {
Geoff Langbfdea662014-07-23 14:16:32 -04005099 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005100 }
Geoff Langbfdea662014-07-23 14:16:32 -04005101
5102 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005103 }
5104
5105 return GL_FALSE;
5106}
5107
5108void __stdcall glBeginQuery(GLenum target, GLuint id)
5109{
5110 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5111
Geoff Langbfdea662014-07-23 14:16:32 -04005112 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005113
Geoff Langbfdea662014-07-23 14:16:32 -04005114 if (context)
5115 {
5116 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005117 {
Geoff Langbfdea662014-07-23 14:16:32 -04005118 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005119 }
Geoff Langbfdea662014-07-23 14:16:32 -04005120
5121 if (!ValidateBeginQuery(context, target, id))
5122 {
5123 return;
5124 }
5125 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005126 }
5127}
5128
5129void __stdcall glEndQuery(GLenum target)
5130{
5131 EVENT("(GLenum target = 0x%X)", target);
5132
Geoff Langbfdea662014-07-23 14:16:32 -04005133 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005134
Geoff Langbfdea662014-07-23 14:16:32 -04005135 if (context)
5136 {
5137 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005138 {
Geoff Langbfdea662014-07-23 14:16:32 -04005139 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005140 }
Geoff Langbfdea662014-07-23 14:16:32 -04005141
5142 if (!ValidateEndQuery(context, target))
5143 {
5144 return;
5145 }
5146
5147 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005148 }
5149}
5150
5151void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5152{
5153 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5154
Geoff Langbfdea662014-07-23 14:16:32 -04005155 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005156
Geoff Langbfdea662014-07-23 14:16:32 -04005157 if (context)
5158 {
5159 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005160 {
Geoff Langbfdea662014-07-23 14:16:32 -04005161 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005162 }
Geoff Langbfdea662014-07-23 14:16:32 -04005163
5164 if (!ValidQueryType(context, target))
5165 {
5166 return gl::error(GL_INVALID_ENUM);
5167 }
5168
5169 switch (pname)
5170 {
5171 case GL_CURRENT_QUERY:
5172 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5173 break;
5174
5175 default:
5176 return gl::error(GL_INVALID_ENUM);
5177 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005178 }
5179}
5180
5181void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5182{
5183 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5184
Geoff Langbfdea662014-07-23 14:16:32 -04005185 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005186
Geoff Langbfdea662014-07-23 14:16:32 -04005187 if (context)
5188 {
5189 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005190 {
Geoff Langbfdea662014-07-23 14:16:32 -04005191 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005192 }
Geoff Langbfdea662014-07-23 14:16:32 -04005193
5194 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5195
5196 if (!queryObject)
5197 {
5198 return gl::error(GL_INVALID_OPERATION);
5199 }
5200
5201 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5202 {
5203 return gl::error(GL_INVALID_OPERATION);
5204 }
5205
5206 switch(pname)
5207 {
5208 case GL_QUERY_RESULT:
5209 params[0] = queryObject->getResult();
5210 break;
5211 case GL_QUERY_RESULT_AVAILABLE:
5212 params[0] = queryObject->isResultAvailable();
5213 break;
5214 default:
5215 return gl::error(GL_INVALID_ENUM);
5216 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005217 }
5218}
5219
5220GLboolean __stdcall glUnmapBuffer(GLenum target)
5221{
5222 EVENT("(GLenum target = 0x%X)", target);
5223
Geoff Langbfdea662014-07-23 14:16:32 -04005224 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005225
Geoff Langbfdea662014-07-23 14:16:32 -04005226 if (context)
5227 {
5228 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005229 {
Geoff Langbfdea662014-07-23 14:16:32 -04005230 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005231 }
Geoff Langbfdea662014-07-23 14:16:32 -04005232
5233 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005234 }
5235
5236 return GL_FALSE;
5237}
5238
5239void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5240{
5241 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5242
Geoff Langbfdea662014-07-23 14:16:32 -04005243 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005244
Geoff Langbfdea662014-07-23 14:16:32 -04005245 if (context)
5246 {
5247 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005248 {
Geoff Langbfdea662014-07-23 14:16:32 -04005249 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005250 }
Geoff Langbfdea662014-07-23 14:16:32 -04005251
5252 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005253 }
5254}
5255
5256void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5257{
Geoff Langbfdea662014-07-23 14:16:32 -04005258 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005259
Geoff Langbfdea662014-07-23 14:16:32 -04005260 if (context)
5261 {
5262 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005263 {
Geoff Langbfdea662014-07-23 14:16:32 -04005264 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005265 }
Geoff Langbfdea662014-07-23 14:16:32 -04005266
5267 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005268 }
5269}
5270
5271void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5272{
5273 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5274 location, count, transpose, value);
5275
Geoff Langbfdea662014-07-23 14:16:32 -04005276 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005277
Geoff Langbfdea662014-07-23 14:16:32 -04005278 if (context)
5279 {
5280 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005281 {
Geoff Langbfdea662014-07-23 14:16:32 -04005282 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005283 }
Geoff Langbfdea662014-07-23 14:16:32 -04005284
5285 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5286 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005287 }
5288}
5289
5290void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5291{
5292 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5293 location, count, transpose, value);
5294
Geoff Langbfdea662014-07-23 14:16:32 -04005295 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005296
Geoff Langbfdea662014-07-23 14:16:32 -04005297 if (context)
5298 {
5299 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005300 {
Geoff Langbfdea662014-07-23 14:16:32 -04005301 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005302 }
Geoff Langbfdea662014-07-23 14:16:32 -04005303
5304 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5305 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005306 }
5307}
5308
5309void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5310{
5311 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5312 location, count, transpose, value);
5313
Geoff Langbfdea662014-07-23 14:16:32 -04005314 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005315
Geoff Langbfdea662014-07-23 14:16:32 -04005316 if (context)
5317 {
5318 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005319 {
Geoff Langbfdea662014-07-23 14:16:32 -04005320 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005321 }
Geoff Langbfdea662014-07-23 14:16:32 -04005322
5323 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5324 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005325 }
5326}
5327
5328void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5329{
5330 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5331 location, count, transpose, value);
5332
Geoff Langbfdea662014-07-23 14:16:32 -04005333 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005334
Geoff Langbfdea662014-07-23 14:16:32 -04005335 if (context)
5336 {
5337 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005338 {
Geoff Langbfdea662014-07-23 14:16:32 -04005339 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005340 }
Geoff Langbfdea662014-07-23 14:16:32 -04005341
5342 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5343 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005344 }
5345}
5346
5347void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5348{
5349 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5350 location, count, transpose, value);
5351
Geoff Langbfdea662014-07-23 14:16:32 -04005352 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005353
Geoff Langbfdea662014-07-23 14:16:32 -04005354 if (context)
5355 {
5356 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005357 {
Geoff Langbfdea662014-07-23 14:16:32 -04005358 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005359 }
Geoff Langbfdea662014-07-23 14:16:32 -04005360
5361 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5362 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005363 }
5364}
5365
5366void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5367{
5368 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5369 location, count, transpose, value);
5370
Geoff Langbfdea662014-07-23 14:16:32 -04005371 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005372
Geoff Langbfdea662014-07-23 14:16:32 -04005373 if (context)
5374 {
5375 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005376 {
Geoff Langbfdea662014-07-23 14:16:32 -04005377 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005378 }
Geoff Langbfdea662014-07-23 14:16:32 -04005379
5380 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5381 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005382 }
5383}
5384
5385void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5386{
5387 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5388 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5389 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5390
Geoff Langbfdea662014-07-23 14:16:32 -04005391 gl::Context *context = gl::getNonLostContext();
5392 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005393 {
Geoff Langbfdea662014-07-23 14:16:32 -04005394 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005395 {
Geoff Langbfdea662014-07-23 14:16:32 -04005396 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005397 }
Geoff Langbfdea662014-07-23 14:16:32 -04005398
5399 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5400 dstX0, dstY0, dstX1, dstY1, mask, filter,
5401 false))
5402 {
5403 return;
5404 }
5405
5406 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5407 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005408 }
5409}
5410
5411void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5412{
5413 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5414 target, samples, internalformat, width, height);
5415
Geoff Langbfdea662014-07-23 14:16:32 -04005416 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005417
Geoff Langbfdea662014-07-23 14:16:32 -04005418 if (context)
5419 {
5420 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005421 {
Geoff Langbfdea662014-07-23 14:16:32 -04005422 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005423 }
Geoff Langbfdea662014-07-23 14:16:32 -04005424
5425 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5426 width, height, false))
5427 {
5428 return;
5429 }
5430
5431 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005432 }
5433}
5434
5435void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5436{
5437 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5438 target, attachment, texture, level, layer);
5439
Geoff Langbfdea662014-07-23 14:16:32 -04005440 gl::Context *context = gl::getNonLostContext();
5441
5442 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005443 {
Geoff Langbfdea662014-07-23 14:16:32 -04005444 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5445 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005446 {
Geoff Langbfdea662014-07-23 14:16:32 -04005447 return;
5448 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005449
Geoff Langbfdea662014-07-23 14:16:32 -04005450 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5451 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005452
Geoff Langbfdea662014-07-23 14:16:32 -04005453 gl::Texture *textureObject = context->getTexture(texture);
5454 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005455
Geoff Langbfdea662014-07-23 14:16:32 -04005456 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5457 {
5458 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5459 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5460 }
5461 else
5462 {
5463 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005464 {
Geoff Langbfdea662014-07-23 14:16:32 -04005465 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5466 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5467 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005468 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005469 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005470 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005471}
5472
5473GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5474{
5475 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5476 target, offset, length, access);
5477
Geoff Langbfdea662014-07-23 14:16:32 -04005478 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005479
Geoff Langbfdea662014-07-23 14:16:32 -04005480 if (context)
5481 {
5482 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005483 {
Geoff Langbfdea662014-07-23 14:16:32 -04005484 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005485 }
Geoff Langbfdea662014-07-23 14:16:32 -04005486
5487 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005488 }
5489
5490 return NULL;
5491}
5492
5493void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5494{
5495 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5496
Geoff Langbfdea662014-07-23 14:16:32 -04005497 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005498
Geoff Langbfdea662014-07-23 14:16:32 -04005499 if (context)
5500 {
5501 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005502 {
Geoff Langbfdea662014-07-23 14:16:32 -04005503 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005504 }
Geoff Langbfdea662014-07-23 14:16:32 -04005505
5506 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005507 }
5508}
5509
5510void __stdcall glBindVertexArray(GLuint array)
5511{
5512 EVENT("(GLuint array = %u)", array);
5513
Geoff Langbfdea662014-07-23 14:16:32 -04005514 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005515
Geoff Langbfdea662014-07-23 14:16:32 -04005516 if (context)
5517 {
5518 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005519 {
Geoff Langbfdea662014-07-23 14:16:32 -04005520 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005521 }
Geoff Langbfdea662014-07-23 14:16:32 -04005522
5523 gl::VertexArray *vao = context->getVertexArray(array);
5524
5525 if (!vao)
5526 {
5527 // The default VAO should always exist
5528 ASSERT(array != 0);
5529 return gl::error(GL_INVALID_OPERATION);
5530 }
5531
5532 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005533 }
5534}
5535
5536void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5537{
5538 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5539
Geoff Langbfdea662014-07-23 14:16:32 -04005540 gl::Context *context = gl::getNonLostContext();
5541
5542 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005543 {
Geoff Langbfdea662014-07-23 14:16:32 -04005544 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005545 {
Geoff Langbfdea662014-07-23 14:16:32 -04005546 return gl::error(GL_INVALID_OPERATION);
5547 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005548
Geoff Langbfdea662014-07-23 14:16:32 -04005549 if (n < 0)
5550 {
5551 return gl::error(GL_INVALID_VALUE);
5552 }
Jamie Madilld1028542013-07-02 11:57:04 -04005553
Geoff Langbfdea662014-07-23 14:16:32 -04005554 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5555 {
5556 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005557 {
Geoff Langbfdea662014-07-23 14:16:32 -04005558 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005559 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005560 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005561 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005562}
5563
5564void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5565{
5566 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5567
Geoff Langbfdea662014-07-23 14:16:32 -04005568 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005569
Geoff Langbfdea662014-07-23 14:16:32 -04005570 if (context)
5571 {
5572 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005573 {
Geoff Langbfdea662014-07-23 14:16:32 -04005574 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005575 }
Geoff Langbfdea662014-07-23 14:16:32 -04005576
5577 if (n < 0)
5578 {
5579 return gl::error(GL_INVALID_VALUE);
5580 }
5581
5582 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5583 {
5584 arrays[arrayIndex] = context->createVertexArray();
5585 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005586 }
5587}
5588
5589GLboolean __stdcall glIsVertexArray(GLuint array)
5590{
5591 EVENT("(GLuint array = %u)", array);
5592
Geoff Langbfdea662014-07-23 14:16:32 -04005593 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005594
Geoff Langbfdea662014-07-23 14:16:32 -04005595 if (context)
5596 {
5597 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005598 {
Geoff Langbfdea662014-07-23 14:16:32 -04005599 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005600 }
Geoff Langbfdea662014-07-23 14:16:32 -04005601
5602 if (array == 0)
5603 {
5604 return GL_FALSE;
5605 }
5606
5607 gl::VertexArray *vao = context->getVertexArray(array);
5608
5609 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005610 }
5611
5612 return GL_FALSE;
5613}
5614
5615void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5616{
5617 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5618 target, index, data);
5619
Geoff Langbfdea662014-07-23 14:16:32 -04005620 gl::Context *context = gl::getNonLostContext();
5621
5622 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005623 {
Geoff Langbfdea662014-07-23 14:16:32 -04005624 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005625 {
Geoff Langbfdea662014-07-23 14:16:32 -04005626 return gl::error(GL_INVALID_OPERATION);
5627 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005628
Geoff Langbfdea662014-07-23 14:16:32 -04005629 switch (target)
5630 {
5631 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5632 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5633 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
5634 if (index >= context->getMaxTransformFeedbackBufferBindings())
5635 return gl::error(GL_INVALID_VALUE);
5636 break;
5637 case GL_UNIFORM_BUFFER_START:
5638 case GL_UNIFORM_BUFFER_SIZE:
5639 case GL_UNIFORM_BUFFER_BINDING:
5640 if (index >= context->getMaximumCombinedUniformBufferBindings())
5641 return gl::error(GL_INVALID_VALUE);
5642 break;
5643 default:
5644 return gl::error(GL_INVALID_ENUM);
5645 }
5646
5647 if (!(context->getIndexedIntegerv(target, index, data)))
5648 {
5649 GLenum nativeType;
5650 unsigned int numParams = 0;
5651 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04005652 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04005653
Geoff Langbfdea662014-07-23 14:16:32 -04005654 if (numParams == 0)
5655 return; // it is known that pname is valid, but there are no parameters to return
5656
5657 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005658 {
Geoff Langbfdea662014-07-23 14:16:32 -04005659 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5660 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5661 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005662
Geoff Langbfdea662014-07-23 14:16:32 -04005663 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005664
Geoff Langbfdea662014-07-23 14:16:32 -04005665 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005666 {
Geoff Langbfdea662014-07-23 14:16:32 -04005667 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5668 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005669 }
Geoff Langbfdea662014-07-23 14:16:32 -04005670
5671 delete [] int64Params;
5672 }
5673 else
5674 {
5675 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005676 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005677 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005678 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005679}
5680
5681void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5682{
5683 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5684
Geoff Langbfdea662014-07-23 14:16:32 -04005685 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005686
Geoff Langbfdea662014-07-23 14:16:32 -04005687 if (context)
5688 {
5689 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005690 {
Geoff Langbfdea662014-07-23 14:16:32 -04005691 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005692 }
Geoff Langbfdea662014-07-23 14:16:32 -04005693
5694 switch (primitiveMode)
5695 {
5696 case GL_TRIANGLES:
5697 case GL_LINES:
5698 case GL_POINTS:
5699 break;
5700 default:
5701 return gl::error(GL_INVALID_ENUM);
5702 }
5703
5704 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5705 ASSERT(transformFeedback != NULL);
5706
5707 if (transformFeedback->isStarted())
5708 {
5709 return gl::error(GL_INVALID_OPERATION);
5710 }
5711
5712 if (transformFeedback->isPaused())
5713 {
5714 transformFeedback->resume();
5715 }
5716 else
5717 {
5718 transformFeedback->start(primitiveMode);
5719 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005720 }
5721}
5722
5723void __stdcall glEndTransformFeedback(void)
5724{
5725 EVENT("(void)");
5726
Geoff Langbfdea662014-07-23 14:16:32 -04005727 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005728
Geoff Langbfdea662014-07-23 14:16:32 -04005729 if (context)
5730 {
5731 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005732 {
Geoff Langbfdea662014-07-23 14:16:32 -04005733 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005734 }
Geoff Langbfdea662014-07-23 14:16:32 -04005735
5736 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5737 ASSERT(transformFeedback != NULL);
5738
5739 if (!transformFeedback->isStarted())
5740 {
5741 return gl::error(GL_INVALID_OPERATION);
5742 }
5743
5744 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005745 }
5746}
5747
5748void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5749{
5750 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5751 target, index, buffer, offset, size);
5752
Geoff Langbfdea662014-07-23 14:16:32 -04005753 gl::Context *context = gl::getNonLostContext();
5754
5755 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005756 {
Geoff Langbfdea662014-07-23 14:16:32 -04005757 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005758 {
Geoff Langbfdea662014-07-23 14:16:32 -04005759 return gl::error(GL_INVALID_OPERATION);
5760 }
5761
5762 switch (target)
5763 {
5764 case GL_TRANSFORM_FEEDBACK_BUFFER:
5765 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005766 {
Geoff Langbfdea662014-07-23 14:16:32 -04005767 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005768 }
Geoff Langbfdea662014-07-23 14:16:32 -04005769 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005770
Geoff Langbfdea662014-07-23 14:16:32 -04005771 case GL_UNIFORM_BUFFER:
5772 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005773 {
Geoff Langbfdea662014-07-23 14:16:32 -04005774 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005775 }
Geoff Langbfdea662014-07-23 14:16:32 -04005776 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005777
Geoff Langbfdea662014-07-23 14:16:32 -04005778 default:
5779 return gl::error(GL_INVALID_ENUM);
5780 }
5781
5782 if (buffer != 0 && size <= 0)
5783 {
5784 return gl::error(GL_INVALID_VALUE);
5785 }
5786
5787 switch (target)
5788 {
5789 case GL_TRANSFORM_FEEDBACK_BUFFER:
5790
5791 // size and offset must be a multiple of 4
5792 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005793 {
5794 return gl::error(GL_INVALID_VALUE);
5795 }
5796
Geoff Langbfdea662014-07-23 14:16:32 -04005797 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5798 context->bindGenericTransformFeedbackBuffer(buffer);
5799 break;
5800
5801 case GL_UNIFORM_BUFFER:
5802
5803 // it is an error to bind an offset not a multiple of the alignment
5804 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005805 {
Geoff Langbfdea662014-07-23 14:16:32 -04005806 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005807 }
Geoff Langbfdea662014-07-23 14:16:32 -04005808
5809 context->bindIndexedUniformBuffer(buffer, index, offset, size);
5810 context->bindGenericUniformBuffer(buffer);
5811 break;
5812
5813 default:
5814 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005815 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005816 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005817}
5818
5819void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
5820{
5821 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
5822 target, index, buffer);
5823
Geoff Langbfdea662014-07-23 14:16:32 -04005824 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005825
Geoff Langbfdea662014-07-23 14:16:32 -04005826 if (context)
5827 {
5828 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005829 {
Geoff Langbfdea662014-07-23 14:16:32 -04005830 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005831 }
Geoff Langbfdea662014-07-23 14:16:32 -04005832
5833 switch (target)
5834 {
5835 case GL_TRANSFORM_FEEDBACK_BUFFER:
5836 if (index >= context->getMaxTransformFeedbackBufferBindings())
5837 {
5838 return gl::error(GL_INVALID_VALUE);
5839 }
5840 break;
5841
5842 case GL_UNIFORM_BUFFER:
5843 if (index >= context->getMaximumCombinedUniformBufferBindings())
5844 {
5845 return gl::error(GL_INVALID_VALUE);
5846 }
5847 break;
5848
5849 default:
5850 return gl::error(GL_INVALID_ENUM);
5851 }
5852
5853 switch (target)
5854 {
5855 case GL_TRANSFORM_FEEDBACK_BUFFER:
5856 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
5857 context->bindGenericTransformFeedbackBuffer(buffer);
5858 break;
5859
5860 case GL_UNIFORM_BUFFER:
5861 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
5862 context->bindGenericUniformBuffer(buffer);
5863 break;
5864
5865 default:
5866 UNREACHABLE();
5867 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005868 }
5869}
5870
5871void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
5872{
5873 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
5874 program, count, varyings, bufferMode);
5875
Geoff Langbfdea662014-07-23 14:16:32 -04005876 gl::Context *context = gl::getNonLostContext();
5877
5878 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005879 {
Geoff Langbfdea662014-07-23 14:16:32 -04005880 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005881 {
Geoff Langbfdea662014-07-23 14:16:32 -04005882 return gl::error(GL_INVALID_OPERATION);
5883 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005884
Geoff Langbfdea662014-07-23 14:16:32 -04005885 if (count < 0)
5886 {
5887 return gl::error(GL_INVALID_VALUE);
5888 }
5889
5890 switch (bufferMode)
5891 {
5892 case GL_INTERLEAVED_ATTRIBS:
5893 break;
5894 case GL_SEPARATE_ATTRIBS:
5895 if (static_cast<GLuint>(count) > context->getMaxTransformFeedbackBufferBindings())
Geoff Lang48dcae72014-02-05 16:28:24 -05005896 {
5897 return gl::error(GL_INVALID_VALUE);
5898 }
Geoff Langbfdea662014-07-23 14:16:32 -04005899 break;
5900 default:
5901 return gl::error(GL_INVALID_ENUM);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005902 }
Geoff Langbfdea662014-07-23 14:16:32 -04005903
5904 if (!gl::ValidProgram(context, program))
5905 {
5906 return;
5907 }
5908
5909 gl::Program *programObject = context->getProgram(program);
5910 ASSERT(programObject);
5911
5912 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005913 }
5914}
5915
5916void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
5917{
5918 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
5919 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
5920 program, index, bufSize, length, size, type, name);
5921
Geoff Langbfdea662014-07-23 14:16:32 -04005922 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005923
Geoff Langbfdea662014-07-23 14:16:32 -04005924 if (context)
5925 {
5926 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005927 {
Geoff Langbfdea662014-07-23 14:16:32 -04005928 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005929 }
Geoff Langbfdea662014-07-23 14:16:32 -04005930
5931 if (bufSize < 0)
5932 {
5933 return gl::error(GL_INVALID_VALUE);
5934 }
5935
5936 if (!gl::ValidProgram(context, program))
5937 {
5938 return;
5939 }
5940
5941 gl::Program *programObject = context->getProgram(program);
5942 ASSERT(programObject);
5943
5944 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
5945 {
5946 return gl::error(GL_INVALID_VALUE);
5947 }
5948
5949 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005950 }
5951}
5952
5953void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
5954{
5955 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
5956 index, size, type, stride, pointer);
5957
Geoff Langbfdea662014-07-23 14:16:32 -04005958 gl::Context *context = gl::getNonLostContext();
5959
5960 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005961 {
Geoff Langbfdea662014-07-23 14:16:32 -04005962 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005963 {
Geoff Langbfdea662014-07-23 14:16:32 -04005964 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005965 }
Geoff Langbfdea662014-07-23 14:16:32 -04005966 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005967
Geoff Langbfdea662014-07-23 14:16:32 -04005968 if (index >= gl::MAX_VERTEX_ATTRIBS)
5969 {
5970 return gl::error(GL_INVALID_VALUE);
5971 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005972
Geoff Langbfdea662014-07-23 14:16:32 -04005973 if (size < 1 || size > 4)
5974 {
5975 return gl::error(GL_INVALID_VALUE);
5976 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005977
Geoff Langbfdea662014-07-23 14:16:32 -04005978 switch (type)
5979 {
5980 case GL_BYTE:
5981 case GL_UNSIGNED_BYTE:
5982 case GL_SHORT:
5983 case GL_UNSIGNED_SHORT:
5984 case GL_INT:
5985 case GL_UNSIGNED_INT:
5986 case GL_INT_2_10_10_10_REV:
5987 case GL_UNSIGNED_INT_2_10_10_10_REV:
5988 break;
5989 default:
5990 return gl::error(GL_INVALID_ENUM);
5991 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005992
Geoff Langbfdea662014-07-23 14:16:32 -04005993 if (stride < 0)
5994 {
5995 return gl::error(GL_INVALID_VALUE);
5996 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005997
Geoff Langbfdea662014-07-23 14:16:32 -04005998 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
5999 {
6000 return gl::error(GL_INVALID_OPERATION);
6001 }
6002
6003 if (context)
6004 {
6005 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6006 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6007 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6008 // and the pointer argument is not NULL.
6009 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006010 {
6011 return gl::error(GL_INVALID_OPERATION);
6012 }
6013
Geoff Langbfdea662014-07-23 14:16:32 -04006014 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6015 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006016 }
6017}
6018
6019void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6020{
6021 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6022 index, pname, params);
6023
Geoff Langbfdea662014-07-23 14:16:32 -04006024 gl::Context *context = gl::getNonLostContext();
6025
6026 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006027 {
Geoff Langbfdea662014-07-23 14:16:32 -04006028 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006029 {
Geoff Langbfdea662014-07-23 14:16:32 -04006030 return gl::error(GL_INVALID_OPERATION);
6031 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006032
Geoff Langbfdea662014-07-23 14:16:32 -04006033 if (index >= gl::MAX_VERTEX_ATTRIBS)
6034 {
6035 return gl::error(GL_INVALID_VALUE);
6036 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006037
Geoff Langbfdea662014-07-23 14:16:32 -04006038 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006039
Geoff Langbfdea662014-07-23 14:16:32 -04006040 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6041 {
6042 return;
6043 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006044
Geoff Langbfdea662014-07-23 14:16:32 -04006045 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6046 {
6047 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6048 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006049 {
Geoff Langbfdea662014-07-23 14:16:32 -04006050 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006051 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006052 }
Geoff Langbfdea662014-07-23 14:16:32 -04006053 else
6054 {
6055 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6056 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006057 }
6058}
6059
6060void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6061{
6062 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6063 index, pname, params);
6064
Geoff Langbfdea662014-07-23 14:16:32 -04006065 gl::Context *context = gl::getNonLostContext();
6066
6067 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006068 {
Geoff Langbfdea662014-07-23 14:16:32 -04006069 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006070 {
Geoff Langbfdea662014-07-23 14:16:32 -04006071 return gl::error(GL_INVALID_OPERATION);
6072 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006073
Geoff Langbfdea662014-07-23 14:16:32 -04006074 if (index >= gl::MAX_VERTEX_ATTRIBS)
6075 {
6076 return gl::error(GL_INVALID_VALUE);
6077 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006078
Geoff Langbfdea662014-07-23 14:16:32 -04006079 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006080
Geoff Langbfdea662014-07-23 14:16:32 -04006081 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6082 {
6083 return;
6084 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006085
Geoff Langbfdea662014-07-23 14:16:32 -04006086 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6087 {
6088 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6089 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006090 {
Geoff Langbfdea662014-07-23 14:16:32 -04006091 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006092 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006093 }
Geoff Langbfdea662014-07-23 14:16:32 -04006094 else
6095 {
6096 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6097 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006098 }
6099}
6100
6101void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6102{
6103 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6104 index, x, y, z, w);
6105
Geoff Langbfdea662014-07-23 14:16:32 -04006106 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006107
Geoff Langbfdea662014-07-23 14:16:32 -04006108 if (context)
6109 {
6110 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006111 {
Geoff Langbfdea662014-07-23 14:16:32 -04006112 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006113 }
Geoff Langbfdea662014-07-23 14:16:32 -04006114
6115 if (index >= gl::MAX_VERTEX_ATTRIBS)
6116 {
6117 return gl::error(GL_INVALID_VALUE);
6118 }
6119
6120 GLint vals[4] = { x, y, z, w };
6121 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006122 }
6123}
6124
6125void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6126{
6127 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6128 index, x, y, z, w);
6129
Geoff Langbfdea662014-07-23 14:16:32 -04006130 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006131
Geoff Langbfdea662014-07-23 14:16:32 -04006132 if (context)
6133 {
6134 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006135 {
Geoff Langbfdea662014-07-23 14:16:32 -04006136 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006137 }
Geoff Langbfdea662014-07-23 14:16:32 -04006138
6139 if (index >= gl::MAX_VERTEX_ATTRIBS)
6140 {
6141 return gl::error(GL_INVALID_VALUE);
6142 }
6143
6144 GLuint vals[4] = { x, y, z, w };
6145 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006146 }
6147}
6148
6149void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6150{
6151 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6152
Geoff Langbfdea662014-07-23 14:16:32 -04006153 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006154
Geoff Langbfdea662014-07-23 14:16:32 -04006155 if (context)
6156 {
6157 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006158 {
Geoff Langbfdea662014-07-23 14:16:32 -04006159 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006160 }
Geoff Langbfdea662014-07-23 14:16:32 -04006161
6162 if (index >= gl::MAX_VERTEX_ATTRIBS)
6163 {
6164 return gl::error(GL_INVALID_VALUE);
6165 }
6166
6167 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006168 }
6169}
6170
6171void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6172{
6173 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6174
Geoff Langbfdea662014-07-23 14:16:32 -04006175 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006176
Geoff Langbfdea662014-07-23 14:16:32 -04006177 if (context)
6178 {
6179 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006180 {
Geoff Langbfdea662014-07-23 14:16:32 -04006181 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006182 }
Geoff Langbfdea662014-07-23 14:16:32 -04006183
6184 if (index >= gl::MAX_VERTEX_ATTRIBS)
6185 {
6186 return gl::error(GL_INVALID_VALUE);
6187 }
6188
6189 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006190 }
6191}
6192
6193void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6194{
6195 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6196 program, location, params);
6197
Geoff Langbfdea662014-07-23 14:16:32 -04006198 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006199
Geoff Langbfdea662014-07-23 14:16:32 -04006200 if (context)
6201 {
Jamie Madill0063c512014-08-25 15:47:53 -04006202 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006203 {
Jamie Madill0063c512014-08-25 15:47:53 -04006204 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006205 }
Geoff Langbfdea662014-07-23 14:16:32 -04006206
Jamie Madill0063c512014-08-25 15:47:53 -04006207 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6208 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006209
Jamie Madill99a1e982014-08-25 15:47:54 -04006210 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006211 }
6212}
6213
6214GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6215{
6216 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6217 program, name);
6218
Geoff Langbfdea662014-07-23 14:16:32 -04006219 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006220
Geoff Langbfdea662014-07-23 14:16:32 -04006221 if (context)
6222 {
6223 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006224 {
Geoff Langbfdea662014-07-23 14:16:32 -04006225 return gl::error(GL_INVALID_OPERATION, -1);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006226 }
Geoff Langbfdea662014-07-23 14:16:32 -04006227
6228 if (program == 0)
6229 {
6230 return gl::error(GL_INVALID_VALUE, -1);
6231 }
6232
6233 gl::Program *programObject = context->getProgram(program);
6234
6235 if (!programObject || !programObject->isLinked())
6236 {
6237 return gl::error(GL_INVALID_OPERATION, -1);
6238 }
6239
6240 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6241 if (!programBinary)
6242 {
6243 return gl::error(GL_INVALID_OPERATION, -1);
6244 }
6245
6246 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006247 }
6248
6249 return 0;
6250}
6251
6252void __stdcall glUniform1ui(GLint location, GLuint v0)
6253{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006254 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006255}
6256
6257void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6258{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006259 const GLuint xy[] = { v0, v1 };
6260 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006261}
6262
6263void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6264{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006265 const GLuint xyz[] = { v0, v1, v2 };
6266 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006267}
6268
6269void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6270{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006271 const GLuint xyzw[] = { v0, v1, v2, v3 };
6272 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006273}
6274
6275void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6276{
6277 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6278 location, count, value);
6279
Geoff Langbfdea662014-07-23 14:16:32 -04006280 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006281
Geoff Langbfdea662014-07-23 14:16:32 -04006282 if (context)
6283 {
6284 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006285 {
Geoff Langbfdea662014-07-23 14:16:32 -04006286 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006287 }
Geoff Langbfdea662014-07-23 14:16:32 -04006288
6289 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6290 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006291 }
6292}
6293
6294void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6295{
6296 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6297 location, count, value);
6298
Geoff Langbfdea662014-07-23 14:16:32 -04006299 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006300
Geoff Langbfdea662014-07-23 14:16:32 -04006301 if (context)
6302 {
6303 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006304 {
Geoff Langbfdea662014-07-23 14:16:32 -04006305 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006306 }
Geoff Langbfdea662014-07-23 14:16:32 -04006307
6308 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6309 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006310 }
6311}
6312
6313void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6314{
6315 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6316 location, count, value);
6317
Geoff Langbfdea662014-07-23 14:16:32 -04006318 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006319
Geoff Langbfdea662014-07-23 14:16:32 -04006320 if (context)
6321 {
6322 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006323 {
Geoff Langbfdea662014-07-23 14:16:32 -04006324 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006325 }
Geoff Langbfdea662014-07-23 14:16:32 -04006326
6327 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6328 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006329 }
6330}
6331
6332void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6333{
6334 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6335 location, count, value);
6336
Geoff Langbfdea662014-07-23 14:16:32 -04006337 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006338
Geoff Langbfdea662014-07-23 14:16:32 -04006339 if (context)
6340 {
6341 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006342 {
Geoff Langbfdea662014-07-23 14:16:32 -04006343 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006344 }
Geoff Langbfdea662014-07-23 14:16:32 -04006345
6346 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6347 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006348 }
6349}
6350
6351void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6352{
6353 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6354 buffer, drawbuffer, value);
6355
Geoff Langbfdea662014-07-23 14:16:32 -04006356 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006357
Geoff Langbfdea662014-07-23 14:16:32 -04006358 if (context)
6359 {
6360 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006361 {
Geoff Langbfdea662014-07-23 14:16:32 -04006362 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006363 }
Geoff Langbfdea662014-07-23 14:16:32 -04006364
6365 switch (buffer)
6366 {
6367 case GL_COLOR:
6368 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6369 {
6370 return gl::error(GL_INVALID_VALUE);
6371 }
6372 break;
6373 case GL_STENCIL:
6374 if (drawbuffer != 0)
6375 {
6376 return gl::error(GL_INVALID_VALUE);
6377 }
6378 break;
6379 default:
6380 return gl::error(GL_INVALID_ENUM);
6381 }
6382
6383 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006384 }
6385}
6386
6387void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6388{
6389 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6390 buffer, drawbuffer, value);
6391
Geoff Langbfdea662014-07-23 14:16:32 -04006392 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006393
Geoff Langbfdea662014-07-23 14:16:32 -04006394 if (context)
6395 {
6396 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006397 {
Geoff Langbfdea662014-07-23 14:16:32 -04006398 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006399 }
Geoff Langbfdea662014-07-23 14:16:32 -04006400
6401 switch (buffer)
6402 {
6403 case GL_COLOR:
6404 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6405 {
6406 return gl::error(GL_INVALID_VALUE);
6407 }
6408 break;
6409 default:
6410 return gl::error(GL_INVALID_ENUM);
6411 }
6412
6413 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006414 }
6415}
6416
6417void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6418{
6419 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6420 buffer, drawbuffer, value);
6421
Geoff Langbfdea662014-07-23 14:16:32 -04006422 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006423
Geoff Langbfdea662014-07-23 14:16:32 -04006424 if (context)
6425 {
6426 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006427 {
Geoff Langbfdea662014-07-23 14:16:32 -04006428 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006429 }
Geoff Langbfdea662014-07-23 14:16:32 -04006430
6431 switch (buffer)
6432 {
6433 case GL_COLOR:
6434 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6435 {
6436 return gl::error(GL_INVALID_VALUE);
6437 }
6438 break;
6439 case GL_DEPTH:
6440 if (drawbuffer != 0)
6441 {
6442 return gl::error(GL_INVALID_VALUE);
6443 }
6444 break;
6445 default:
6446 return gl::error(GL_INVALID_ENUM);
6447 }
6448
6449 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006450 }
6451}
6452
6453void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6454{
6455 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6456 buffer, drawbuffer, depth, stencil);
6457
Geoff Langbfdea662014-07-23 14:16:32 -04006458 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006459
Geoff Langbfdea662014-07-23 14:16:32 -04006460 if (context)
6461 {
6462 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006463 {
Geoff Langbfdea662014-07-23 14:16:32 -04006464 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006465 }
Geoff Langbfdea662014-07-23 14:16:32 -04006466
6467 switch (buffer)
6468 {
6469 case GL_DEPTH_STENCIL:
6470 if (drawbuffer != 0)
6471 {
6472 return gl::error(GL_INVALID_VALUE);
6473 }
6474 break;
6475 default:
6476 return gl::error(GL_INVALID_ENUM);
6477 }
6478
6479 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006480 }
6481}
6482
6483const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6484{
6485 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6486
Geoff Langbfdea662014-07-23 14:16:32 -04006487 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006488
Geoff Langbfdea662014-07-23 14:16:32 -04006489 if (context)
6490 {
6491 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006492 {
Geoff Langbfdea662014-07-23 14:16:32 -04006493 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006494 }
Geoff Langbfdea662014-07-23 14:16:32 -04006495
6496 if (name != GL_EXTENSIONS)
6497 {
6498 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
6499 }
6500
6501 if (index >= context->getExtensionStringCount())
6502 {
6503 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
6504 }
6505
6506 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006507 }
6508
6509 return NULL;
6510}
6511
6512void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6513{
6514 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6515 readTarget, writeTarget, readOffset, writeOffset, size);
6516
Geoff Langbfdea662014-07-23 14:16:32 -04006517 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006518
Geoff Langbfdea662014-07-23 14:16:32 -04006519 if (context)
6520 {
6521 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006522 {
Geoff Langbfdea662014-07-23 14:16:32 -04006523 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006524 }
Geoff Langbfdea662014-07-23 14:16:32 -04006525
6526 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6527 {
6528 return gl::error(GL_INVALID_ENUM);
6529 }
6530
6531 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6532 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6533
6534 if (!readBuffer || !writeBuffer)
6535 {
6536 return gl::error(GL_INVALID_OPERATION);
6537 }
6538
Jamie Madillcfaaf722014-07-31 10:47:54 -04006539 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006540 if (readBuffer->isMapped() || writeBuffer->isMapped())
6541 {
6542 return gl::error(GL_INVALID_OPERATION);
6543 }
6544
6545 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6546 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6547 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6548 {
6549 return gl::error(GL_INVALID_VALUE);
6550 }
6551
6552 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6553 {
6554 return gl::error(GL_INVALID_VALUE);
6555 }
6556
Geoff Langbfdea662014-07-23 14:16:32 -04006557 // if size is zero, the copy is a successful no-op
6558 if (size > 0)
6559 {
6560 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6561 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006562 }
6563}
6564
6565void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6566{
6567 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6568 program, uniformCount, uniformNames, uniformIndices);
6569
Geoff Langbfdea662014-07-23 14:16:32 -04006570 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006571
Geoff Langbfdea662014-07-23 14:16:32 -04006572 if (context)
6573 {
6574 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006575 {
Geoff Langbfdea662014-07-23 14:16:32 -04006576 return gl::error(GL_INVALID_OPERATION);
6577 }
6578
6579 if (uniformCount < 0)
6580 {
6581 return gl::error(GL_INVALID_VALUE);
6582 }
6583
6584 gl::Program *programObject = context->getProgram(program);
6585
6586 if (!programObject)
6587 {
6588 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006589 {
6590 return gl::error(GL_INVALID_OPERATION);
6591 }
Geoff Langbfdea662014-07-23 14:16:32 -04006592 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006593 {
6594 return gl::error(GL_INVALID_VALUE);
6595 }
Geoff Langbfdea662014-07-23 14:16:32 -04006596 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006597
Geoff Langbfdea662014-07-23 14:16:32 -04006598 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6599 if (!programObject->isLinked() || !programBinary)
6600 {
6601 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006602 {
Geoff Langbfdea662014-07-23 14:16:32 -04006603 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006604 }
6605 }
Geoff Langbfdea662014-07-23 14:16:32 -04006606 else
6607 {
6608 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6609 {
6610 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6611 }
6612 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006613 }
6614}
6615
6616void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6617{
6618 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6619 program, uniformCount, uniformIndices, pname, params);
6620
Geoff Langbfdea662014-07-23 14:16:32 -04006621 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006622
Geoff Langbfdea662014-07-23 14:16:32 -04006623 if (context)
6624 {
6625 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006626 {
Geoff Langbfdea662014-07-23 14:16:32 -04006627 return gl::error(GL_INVALID_OPERATION);
6628 }
6629
6630 if (uniformCount < 0)
6631 {
6632 return gl::error(GL_INVALID_VALUE);
6633 }
6634
6635 gl::Program *programObject = context->getProgram(program);
6636
6637 if (!programObject)
6638 {
6639 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006640 {
6641 return gl::error(GL_INVALID_OPERATION);
6642 }
Geoff Langbfdea662014-07-23 14:16:32 -04006643 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006644 {
6645 return gl::error(GL_INVALID_VALUE);
6646 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006647 }
Geoff Langbfdea662014-07-23 14:16:32 -04006648
6649 switch (pname)
6650 {
6651 case GL_UNIFORM_TYPE:
6652 case GL_UNIFORM_SIZE:
6653 case GL_UNIFORM_NAME_LENGTH:
6654 case GL_UNIFORM_BLOCK_INDEX:
6655 case GL_UNIFORM_OFFSET:
6656 case GL_UNIFORM_ARRAY_STRIDE:
6657 case GL_UNIFORM_MATRIX_STRIDE:
6658 case GL_UNIFORM_IS_ROW_MAJOR:
6659 break;
6660 default:
6661 return gl::error(GL_INVALID_ENUM);
6662 }
6663
6664 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6665
6666 if (!programBinary && uniformCount > 0)
6667 {
6668 return gl::error(GL_INVALID_VALUE);
6669 }
6670
6671 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6672 {
6673 const GLuint index = uniformIndices[uniformId];
6674
6675 if (index >= (GLuint)programBinary->getActiveUniformCount())
6676 {
6677 return gl::error(GL_INVALID_VALUE);
6678 }
6679 }
6680
6681 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6682 {
6683 const GLuint index = uniformIndices[uniformId];
6684 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6685 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006686 }
6687}
6688
6689GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6690{
6691 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6692
Geoff Langbfdea662014-07-23 14:16:32 -04006693 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006694
Geoff Langbfdea662014-07-23 14:16:32 -04006695 if (context)
6696 {
6697 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006698 {
Geoff Langbfdea662014-07-23 14:16:32 -04006699 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
6700 }
6701
6702 gl::Program *programObject = context->getProgram(program);
6703
6704 if (!programObject)
6705 {
6706 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006707 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006708 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006709 }
Geoff Langbfdea662014-07-23 14:16:32 -04006710 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006711 {
Geoff Langbfdea662014-07-23 14:16:32 -04006712 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006713 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006714 }
Geoff Langbfdea662014-07-23 14:16:32 -04006715
6716 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6717 if (!programBinary)
6718 {
6719 return GL_INVALID_INDEX;
6720 }
6721
6722 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006723 }
6724
6725 return 0;
6726}
6727
6728void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6729{
6730 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6731 program, uniformBlockIndex, pname, params);
6732
Geoff Langbfdea662014-07-23 14:16:32 -04006733 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006734
Geoff Langbfdea662014-07-23 14:16:32 -04006735 if (context)
6736 {
6737 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006738 {
Geoff Langbfdea662014-07-23 14:16:32 -04006739 return gl::error(GL_INVALID_OPERATION);
6740 }
6741 gl::Program *programObject = context->getProgram(program);
6742
6743 if (!programObject)
6744 {
6745 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006746 {
6747 return gl::error(GL_INVALID_OPERATION);
6748 }
Geoff Langbfdea662014-07-23 14:16:32 -04006749 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006750 {
6751 return gl::error(GL_INVALID_VALUE);
6752 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006753 }
Geoff Langbfdea662014-07-23 14:16:32 -04006754
6755 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6756
6757 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6758 {
6759 return gl::error(GL_INVALID_VALUE);
6760 }
6761
6762 switch (pname)
6763 {
6764 case GL_UNIFORM_BLOCK_BINDING:
6765 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
6766 break;
6767
6768 case GL_UNIFORM_BLOCK_DATA_SIZE:
6769 case GL_UNIFORM_BLOCK_NAME_LENGTH:
6770 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
6771 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
6772 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
6773 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
6774 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
6775 break;
6776
6777 default:
6778 return gl::error(GL_INVALID_ENUM);
6779 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006780 }
6781}
6782
6783void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
6784{
6785 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
6786 program, uniformBlockIndex, bufSize, length, uniformBlockName);
6787
Geoff Langbfdea662014-07-23 14:16:32 -04006788 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006789
Geoff Langbfdea662014-07-23 14:16:32 -04006790 if (context)
6791 {
6792 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006793 {
Geoff Langbfdea662014-07-23 14:16:32 -04006794 return gl::error(GL_INVALID_OPERATION);
6795 }
6796
6797 gl::Program *programObject = context->getProgram(program);
6798
6799 if (!programObject)
6800 {
6801 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006802 {
6803 return gl::error(GL_INVALID_OPERATION);
6804 }
Geoff Langbfdea662014-07-23 14:16:32 -04006805 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006806 {
6807 return gl::error(GL_INVALID_VALUE);
6808 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006809 }
Geoff Langbfdea662014-07-23 14:16:32 -04006810
6811 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6812
6813 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6814 {
6815 return gl::error(GL_INVALID_VALUE);
6816 }
6817
6818 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006819 }
6820}
6821
6822void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
6823{
6824 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
6825 program, uniformBlockIndex, uniformBlockBinding);
6826
Geoff Langbfdea662014-07-23 14:16:32 -04006827 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006828
Geoff Langbfdea662014-07-23 14:16:32 -04006829 if (context)
6830 {
6831 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006832 {
Geoff Langbfdea662014-07-23 14:16:32 -04006833 return gl::error(GL_INVALID_OPERATION);
6834 }
6835
6836 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
6837 {
6838 return gl::error(GL_INVALID_VALUE);
6839 }
6840
6841 gl::Program *programObject = context->getProgram(program);
6842
6843 if (!programObject)
6844 {
6845 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006846 {
6847 return gl::error(GL_INVALID_OPERATION);
6848 }
Geoff Langbfdea662014-07-23 14:16:32 -04006849 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006850 {
6851 return gl::error(GL_INVALID_VALUE);
6852 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006853 }
Geoff Langbfdea662014-07-23 14:16:32 -04006854
6855 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6856
6857 // if never linked, there won't be any uniform blocks
6858 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6859 {
6860 return gl::error(GL_INVALID_VALUE);
6861 }
6862
6863 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006864 }
6865}
6866
6867void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
6868{
6869 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
6870 mode, first, count, instanceCount);
6871
Geoff Langbfdea662014-07-23 14:16:32 -04006872 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006873
Geoff Langbfdea662014-07-23 14:16:32 -04006874 if (context)
6875 {
6876 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006877 {
Geoff Langbfdea662014-07-23 14:16:32 -04006878 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006879 }
Geoff Langbfdea662014-07-23 14:16:32 -04006880
6881 // glDrawArraysInstanced
6882 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006883 }
6884}
6885
6886void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
6887{
6888 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
6889 mode, count, type, indices, instanceCount);
6890
Geoff Langbfdea662014-07-23 14:16:32 -04006891 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006892
Geoff Langbfdea662014-07-23 14:16:32 -04006893 if (context)
6894 {
6895 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006896 {
Geoff Langbfdea662014-07-23 14:16:32 -04006897 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006898 }
Geoff Langbfdea662014-07-23 14:16:32 -04006899
6900 // glDrawElementsInstanced
6901 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006902 }
6903}
6904
6905GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
6906{
6907 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
6908
Geoff Langbfdea662014-07-23 14:16:32 -04006909 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006910
Geoff Langbfdea662014-07-23 14:16:32 -04006911 if (context)
6912 {
6913 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006914 {
Geoff Langbfdea662014-07-23 14:16:32 -04006915 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006916 }
Geoff Langbfdea662014-07-23 14:16:32 -04006917
6918 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
6919 {
6920 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
6921 }
6922
6923 if (flags != 0)
6924 {
6925 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
6926 }
6927
6928 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006929 }
6930
6931 return NULL;
6932}
6933
6934GLboolean __stdcall glIsSync(GLsync sync)
6935{
6936 EVENT("(GLsync sync = 0x%0.8p)", sync);
6937
Geoff Langbfdea662014-07-23 14:16:32 -04006938 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006939
Geoff Langbfdea662014-07-23 14:16:32 -04006940 if (context)
6941 {
6942 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006943 {
Geoff Langbfdea662014-07-23 14:16:32 -04006944 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006945 }
Geoff Langbfdea662014-07-23 14:16:32 -04006946
6947 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006948 }
6949
6950 return GL_FALSE;
6951}
6952
6953void __stdcall glDeleteSync(GLsync sync)
6954{
6955 EVENT("(GLsync sync = 0x%0.8p)", sync);
6956
Geoff Langbfdea662014-07-23 14:16:32 -04006957 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006958
Geoff Langbfdea662014-07-23 14:16:32 -04006959 if (context)
6960 {
6961 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006962 {
Geoff Langbfdea662014-07-23 14:16:32 -04006963 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006964 }
Geoff Langbfdea662014-07-23 14:16:32 -04006965
6966 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
6967 {
6968 return gl::error(GL_INVALID_VALUE);
6969 }
6970
6971 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006972 }
6973}
6974
6975GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6976{
6977 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
6978 sync, flags, timeout);
6979
Geoff Langbfdea662014-07-23 14:16:32 -04006980 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006981
Geoff Langbfdea662014-07-23 14:16:32 -04006982 if (context)
6983 {
6984 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006985 {
Geoff Langbfdea662014-07-23 14:16:32 -04006986 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006987 }
Geoff Langbfdea662014-07-23 14:16:32 -04006988
6989 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
6990 {
6991 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
6992 }
6993
6994 gl::FenceSync *fenceSync = context->getFenceSync(sync);
6995
6996 if (!fenceSync)
6997 {
6998 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
6999 }
7000
7001 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007002 }
7003
7004 return GL_FALSE;
7005}
7006
7007void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7008{
7009 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7010 sync, flags, timeout);
7011
Geoff Langbfdea662014-07-23 14:16:32 -04007012 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007013
Geoff Langbfdea662014-07-23 14:16:32 -04007014 if (context)
7015 {
7016 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007017 {
Geoff Langbfdea662014-07-23 14:16:32 -04007018 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007019 }
Geoff Langbfdea662014-07-23 14:16:32 -04007020
7021 if (flags != 0)
7022 {
7023 return gl::error(GL_INVALID_VALUE);
7024 }
7025
7026 if (timeout != GL_TIMEOUT_IGNORED)
7027 {
7028 return gl::error(GL_INVALID_VALUE);
7029 }
7030
7031 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7032
7033 if (!fenceSync)
7034 {
7035 return gl::error(GL_INVALID_VALUE);
7036 }
7037
7038 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007039 }
7040}
7041
7042void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7043{
7044 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7045 pname, params);
7046
Geoff Langbfdea662014-07-23 14:16:32 -04007047 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007048
Geoff Langbfdea662014-07-23 14:16:32 -04007049 if (context)
7050 {
7051 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007052 {
Geoff Langbfdea662014-07-23 14:16:32 -04007053 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007054 }
Geoff Langbfdea662014-07-23 14:16:32 -04007055
7056 GLenum nativeType;
7057 unsigned int numParams = 0;
7058 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7059 {
7060 return;
7061 }
7062
7063 if (nativeType == GL_INT_64_ANGLEX)
7064 {
7065 context->getInteger64v(pname, params);
7066 }
7067 else
7068 {
7069 CastStateValues(context, nativeType, pname, numParams, params);
7070 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007071 }
7072}
7073
7074void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7075{
7076 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7077 sync, pname, bufSize, length, values);
7078
Geoff Langbfdea662014-07-23 14:16:32 -04007079 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007080
Geoff Langbfdea662014-07-23 14:16:32 -04007081 if (context)
7082 {
7083 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007084 {
Geoff Langbfdea662014-07-23 14:16:32 -04007085 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007086 }
Geoff Langbfdea662014-07-23 14:16:32 -04007087
7088 if (bufSize < 0)
7089 {
7090 return gl::error(GL_INVALID_VALUE);
7091 }
7092
7093 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7094
7095 if (!fenceSync)
7096 {
7097 return gl::error(GL_INVALID_VALUE);
7098 }
7099
7100 switch (pname)
7101 {
7102 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7103 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7104 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7105 case GL_SYNC_FLAGS: values[0] = 0; break;
7106
7107 default:
7108 return gl::error(GL_INVALID_ENUM);
7109 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007110 }
7111}
7112
7113void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7114{
7115 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7116 target, index, data);
7117
Geoff Langbfdea662014-07-23 14:16:32 -04007118 gl::Context *context = gl::getNonLostContext();
7119
7120 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007121 {
Geoff Langbfdea662014-07-23 14:16:32 -04007122 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007123 {
Geoff Langbfdea662014-07-23 14:16:32 -04007124 return gl::error(GL_INVALID_OPERATION);
7125 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007126
Geoff Langbfdea662014-07-23 14:16:32 -04007127 switch (target)
7128 {
7129 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7130 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7131 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7132 if (index >= context->getMaxTransformFeedbackBufferBindings())
7133 return gl::error(GL_INVALID_VALUE);
7134 break;
7135 case GL_UNIFORM_BUFFER_START:
7136 case GL_UNIFORM_BUFFER_SIZE:
7137 case GL_UNIFORM_BUFFER_BINDING:
7138 if (index >= context->getMaximumCombinedUniformBufferBindings())
7139 return gl::error(GL_INVALID_VALUE);
7140 break;
7141 default:
7142 return gl::error(GL_INVALID_ENUM);
7143 }
7144
7145 if (!(context->getIndexedInteger64v(target, index, data)))
7146 {
7147 GLenum nativeType;
7148 unsigned int numParams = 0;
7149 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04007150 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04007151
Geoff Langbfdea662014-07-23 14:16:32 -04007152 if (numParams == 0)
7153 return; // it is known that pname is valid, but there are no parameters to return
7154
7155 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007156 {
Geoff Langbfdea662014-07-23 14:16:32 -04007157 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007158
Geoff Langbfdea662014-07-23 14:16:32 -04007159 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007160
Geoff Langbfdea662014-07-23 14:16:32 -04007161 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007162 {
Geoff Langbfdea662014-07-23 14:16:32 -04007163 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007164 }
Geoff Langbfdea662014-07-23 14:16:32 -04007165
7166 delete [] intParams;
7167 }
7168 else
7169 {
7170 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007171 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007172 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007173 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007174}
7175
7176void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7177{
7178 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7179 target, pname, params);
7180
Geoff Langbfdea662014-07-23 14:16:32 -04007181 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007182
Geoff Langbfdea662014-07-23 14:16:32 -04007183 if (context)
7184 {
7185 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007186 {
Geoff Langbfdea662014-07-23 14:16:32 -04007187 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007188 }
Geoff Langbfdea662014-07-23 14:16:32 -04007189
7190 if (!gl::ValidBufferTarget(context, target))
7191 {
7192 return gl::error(GL_INVALID_ENUM);
7193 }
7194
7195 if (!gl::ValidBufferParameter(context, pname))
7196 {
7197 return gl::error(GL_INVALID_ENUM);
7198 }
7199
7200 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7201
7202 if (!buffer)
7203 {
7204 // A null buffer means that "0" is bound to the requested buffer target
7205 return gl::error(GL_INVALID_OPERATION);
7206 }
7207
7208 switch (pname)
7209 {
7210 case GL_BUFFER_USAGE:
7211 *params = static_cast<GLint64>(buffer->getUsage());
7212 break;
7213 case GL_BUFFER_SIZE:
7214 *params = buffer->getSize();
7215 break;
7216 case GL_BUFFER_ACCESS_FLAGS:
7217 *params = static_cast<GLint64>(buffer->getAccessFlags());
7218 break;
7219 case GL_BUFFER_MAPPED:
7220 *params = static_cast<GLint64>(buffer->isMapped());
7221 break;
7222 case GL_BUFFER_MAP_OFFSET:
7223 *params = buffer->getMapOffset();
7224 break;
7225 case GL_BUFFER_MAP_LENGTH:
7226 *params = buffer->getMapLength();
7227 break;
7228 default: UNREACHABLE(); break;
7229 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007230 }
7231}
7232
7233void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7234{
7235 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7236
Geoff Langbfdea662014-07-23 14:16:32 -04007237 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007238
Geoff Langbfdea662014-07-23 14:16:32 -04007239 if (context)
7240 {
7241 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007242 {
Geoff Langbfdea662014-07-23 14:16:32 -04007243 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007244 }
Geoff Langbfdea662014-07-23 14:16:32 -04007245
7246 if (count < 0)
7247 {
7248 return gl::error(GL_INVALID_VALUE);
7249 }
7250
7251 for (int i = 0; i < count; i++)
7252 {
7253 samplers[i] = context->createSampler();
7254 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007255 }
7256}
7257
7258void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7259{
7260 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7261
Geoff Langbfdea662014-07-23 14:16:32 -04007262 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007263
Geoff Langbfdea662014-07-23 14:16:32 -04007264 if (context)
7265 {
7266 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007267 {
Geoff Langbfdea662014-07-23 14:16:32 -04007268 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007269 }
Geoff Langbfdea662014-07-23 14:16:32 -04007270
7271 if (count < 0)
7272 {
7273 return gl::error(GL_INVALID_VALUE);
7274 }
7275
7276 for (int i = 0; i < count; i++)
7277 {
7278 context->deleteSampler(samplers[i]);
7279 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007280 }
7281}
7282
7283GLboolean __stdcall glIsSampler(GLuint sampler)
7284{
7285 EVENT("(GLuint sampler = %u)", sampler);
7286
Geoff Langbfdea662014-07-23 14:16:32 -04007287 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007288
Geoff Langbfdea662014-07-23 14:16:32 -04007289 if (context)
7290 {
7291 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007292 {
Geoff Langbfdea662014-07-23 14:16:32 -04007293 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007294 }
Geoff Langbfdea662014-07-23 14:16:32 -04007295
7296 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007297 }
7298
7299 return GL_FALSE;
7300}
7301
7302void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7303{
7304 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7305
Geoff Langbfdea662014-07-23 14:16:32 -04007306 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007307
Geoff Langbfdea662014-07-23 14:16:32 -04007308 if (context)
7309 {
7310 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007311 {
Geoff Langbfdea662014-07-23 14:16:32 -04007312 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007313 }
Geoff Langbfdea662014-07-23 14:16:32 -04007314
7315 if (sampler != 0 && !context->isSampler(sampler))
7316 {
7317 return gl::error(GL_INVALID_OPERATION);
7318 }
7319
7320 if (unit >= context->getMaximumCombinedTextureImageUnits())
7321 {
7322 return gl::error(GL_INVALID_VALUE);
7323 }
7324
7325 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007326 }
7327}
7328
7329void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7330{
7331 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7332
Geoff Langbfdea662014-07-23 14:16:32 -04007333 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007334
Geoff Langbfdea662014-07-23 14:16:32 -04007335 if (context)
7336 {
7337 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007338 {
Geoff Langbfdea662014-07-23 14:16:32 -04007339 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007340 }
Geoff Langbfdea662014-07-23 14:16:32 -04007341
7342 if (!gl::ValidateSamplerObjectParameter(pname))
7343 {
7344 return;
7345 }
7346
7347 if (!gl::ValidateTexParamParameters(context, pname, param))
7348 {
7349 return;
7350 }
7351
7352 if (!context->isSampler(sampler))
7353 {
7354 return gl::error(GL_INVALID_OPERATION);
7355 }
7356
7357 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007358 }
7359}
7360
7361void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7362{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007363 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007364}
7365
7366void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7367{
7368 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7369
Geoff Langbfdea662014-07-23 14:16:32 -04007370 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007371
Geoff Langbfdea662014-07-23 14:16:32 -04007372 if (context)
7373 {
7374 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007375 {
Geoff Langbfdea662014-07-23 14:16:32 -04007376 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007377 }
Geoff Langbfdea662014-07-23 14:16:32 -04007378
7379 if (!gl::ValidateSamplerObjectParameter(pname))
7380 {
7381 return;
7382 }
7383
7384 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7385 {
7386 return;
7387 }
7388
7389 if (!context->isSampler(sampler))
7390 {
7391 return gl::error(GL_INVALID_OPERATION);
7392 }
7393
7394 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007395 }
7396}
7397
7398void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7399{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007400 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007401}
7402
7403void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7404{
7405 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7406
Geoff Langbfdea662014-07-23 14:16:32 -04007407 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007408
Geoff Langbfdea662014-07-23 14:16:32 -04007409 if (context)
7410 {
7411 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007412 {
Geoff Langbfdea662014-07-23 14:16:32 -04007413 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007414 }
Geoff Langbfdea662014-07-23 14:16:32 -04007415
7416 if (!gl::ValidateSamplerObjectParameter(pname))
7417 {
7418 return;
7419 }
7420
7421 if (!context->isSampler(sampler))
7422 {
7423 return gl::error(GL_INVALID_OPERATION);
7424 }
7425
7426 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007427 }
7428}
7429
7430void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7431{
7432 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7433
Geoff Langbfdea662014-07-23 14:16:32 -04007434 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007435
Geoff Langbfdea662014-07-23 14:16:32 -04007436 if (context)
7437 {
7438 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007439 {
Geoff Langbfdea662014-07-23 14:16:32 -04007440 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007441 }
Geoff Langbfdea662014-07-23 14:16:32 -04007442
7443 if (!gl::ValidateSamplerObjectParameter(pname))
7444 {
7445 return;
7446 }
7447
7448 if (!context->isSampler(sampler))
7449 {
7450 return gl::error(GL_INVALID_OPERATION);
7451 }
7452
7453 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007454 }
7455}
7456
7457void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7458{
7459 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7460
Geoff Langbfdea662014-07-23 14:16:32 -04007461 if (index >= gl::MAX_VERTEX_ATTRIBS)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007462 {
Geoff Langbfdea662014-07-23 14:16:32 -04007463 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007464 }
Geoff Langbfdea662014-07-23 14:16:32 -04007465
7466 gl::Context *context = gl::getNonLostContext();
7467
7468 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007469 {
Geoff Langbfdea662014-07-23 14:16:32 -04007470 if (context->getClientVersion() < 3)
7471 {
7472 return gl::error(GL_INVALID_OPERATION);
7473 }
7474
7475 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007476 }
7477}
7478
7479void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7480{
7481 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7482
Geoff Langbfdea662014-07-23 14:16:32 -04007483 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007484
Geoff Langbfdea662014-07-23 14:16:32 -04007485 if (context)
7486 {
7487 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007488 {
Geoff Langbfdea662014-07-23 14:16:32 -04007489 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007490 }
Geoff Langbfdea662014-07-23 14:16:32 -04007491
7492 switch (target)
7493 {
7494 case GL_TRANSFORM_FEEDBACK:
7495 {
7496 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7497 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7498 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7499 {
7500 return gl::error(GL_INVALID_OPERATION);
7501 }
7502
7503 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7504 if (context->getTransformFeedback(id) == NULL)
7505 {
7506 return gl::error(GL_INVALID_OPERATION);
7507 }
7508
7509 context->bindTransformFeedback(id);
7510 }
7511 break;
7512
7513 default:
7514 return gl::error(GL_INVALID_ENUM);
7515 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007516 }
7517}
7518
7519void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7520{
7521 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7522
Geoff Langbfdea662014-07-23 14:16:32 -04007523 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007524
Geoff Langbfdea662014-07-23 14:16:32 -04007525 if (context)
7526 {
7527 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007528 {
Geoff Langbfdea662014-07-23 14:16:32 -04007529 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007530 }
Geoff Langbfdea662014-07-23 14:16:32 -04007531
7532 for (int i = 0; i < n; i++)
7533 {
7534 context->deleteTransformFeedback(ids[i]);
7535 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007536 }
7537}
7538
7539void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7540{
7541 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7542
Geoff Langbfdea662014-07-23 14:16:32 -04007543 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007544
Geoff Langbfdea662014-07-23 14:16:32 -04007545 if (context)
7546 {
7547 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007548 {
Geoff Langbfdea662014-07-23 14:16:32 -04007549 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007550 }
Geoff Langbfdea662014-07-23 14:16:32 -04007551
7552 for (int i = 0; i < n; i++)
7553 {
7554 ids[i] = context->createTransformFeedback();
7555 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007556 }
7557}
7558
7559GLboolean __stdcall glIsTransformFeedback(GLuint id)
7560{
7561 EVENT("(GLuint id = %u)", id);
7562
Geoff Langbfdea662014-07-23 14:16:32 -04007563 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007564
Geoff Langbfdea662014-07-23 14:16:32 -04007565 if (context)
7566 {
7567 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007568 {
Geoff Langbfdea662014-07-23 14:16:32 -04007569 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007570 }
Geoff Langbfdea662014-07-23 14:16:32 -04007571
7572 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007573 }
7574
7575 return GL_FALSE;
7576}
7577
7578void __stdcall glPauseTransformFeedback(void)
7579{
7580 EVENT("(void)");
7581
Geoff Langbfdea662014-07-23 14:16:32 -04007582 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007583
Geoff Langbfdea662014-07-23 14:16:32 -04007584 if (context)
7585 {
7586 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007587 {
Geoff Langbfdea662014-07-23 14:16:32 -04007588 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007589 }
Geoff Langbfdea662014-07-23 14:16:32 -04007590
7591 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7592 ASSERT(transformFeedback != NULL);
7593
7594 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7595 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7596 {
7597 return gl::error(GL_INVALID_OPERATION);
7598 }
7599
7600 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007601 }
7602}
7603
7604void __stdcall glResumeTransformFeedback(void)
7605{
7606 EVENT("(void)");
7607
Geoff Langbfdea662014-07-23 14:16:32 -04007608 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007609
Geoff Langbfdea662014-07-23 14:16:32 -04007610 if (context)
7611 {
7612 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007613 {
Geoff Langbfdea662014-07-23 14:16:32 -04007614 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007615 }
Geoff Langbfdea662014-07-23 14:16:32 -04007616
7617 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7618 ASSERT(transformFeedback != NULL);
7619
7620 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7621 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7622 {
7623 return gl::error(GL_INVALID_OPERATION);
7624 }
7625
7626 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007627 }
7628}
7629
7630void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7631{
7632 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7633 program, bufSize, length, binaryFormat, binary);
7634
Geoff Langbfdea662014-07-23 14:16:32 -04007635 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007636
Geoff Langbfdea662014-07-23 14:16:32 -04007637 if (context)
7638 {
7639 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007640 {
Geoff Langbfdea662014-07-23 14:16:32 -04007641 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007642 }
Geoff Langbfdea662014-07-23 14:16:32 -04007643
7644 // glGetProgramBinary
7645 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007646 }
7647}
7648
7649void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7650{
7651 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7652 program, binaryFormat, binary, length);
7653
Geoff Langbfdea662014-07-23 14:16:32 -04007654 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007655
Geoff Langbfdea662014-07-23 14:16:32 -04007656 if (context)
7657 {
7658 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007659 {
Geoff Langbfdea662014-07-23 14:16:32 -04007660 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007661 }
Geoff Langbfdea662014-07-23 14:16:32 -04007662
7663 // glProgramBinary
7664 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007665 }
7666}
7667
7668void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7669{
7670 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7671 program, pname, value);
7672
Geoff Langbfdea662014-07-23 14:16:32 -04007673 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007674
Geoff Langbfdea662014-07-23 14:16:32 -04007675 if (context)
7676 {
7677 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007678 {
Geoff Langbfdea662014-07-23 14:16:32 -04007679 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007680 }
Geoff Langbfdea662014-07-23 14:16:32 -04007681
7682 // glProgramParameteri
7683 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007684 }
7685}
7686
7687void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7688{
7689 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7690 target, numAttachments, attachments);
7691
Geoff Langbfdea662014-07-23 14:16:32 -04007692 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007693
Geoff Langbfdea662014-07-23 14:16:32 -04007694 if (context)
7695 {
7696 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007697 {
Geoff Langbfdea662014-07-23 14:16:32 -04007698 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007699 }
Geoff Langbfdea662014-07-23 14:16:32 -04007700
7701 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7702 {
7703 return;
7704 }
7705
7706 GLuint maxDimension = context->getCaps().maxRenderbufferSize;
7707 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007708 }
7709}
7710
7711void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
7712{
7713 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
7714 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7715 target, numAttachments, attachments, x, y, width, height);
7716
Geoff Langbfdea662014-07-23 14:16:32 -04007717 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007718
Geoff Langbfdea662014-07-23 14:16:32 -04007719 if (context)
7720 {
7721 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007722 {
Geoff Langbfdea662014-07-23 14:16:32 -04007723 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007724 }
Geoff Langbfdea662014-07-23 14:16:32 -04007725
7726 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7727 {
7728 return;
7729 }
7730
7731 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007732 }
7733}
7734
7735void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7736{
7737 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7738 target, levels, internalformat, width, height);
7739
Geoff Langbfdea662014-07-23 14:16:32 -04007740 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007741
Geoff Langbfdea662014-07-23 14:16:32 -04007742 if (context)
7743 {
7744 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007745 {
Geoff Langbfdea662014-07-23 14:16:32 -04007746 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007747 }
Geoff Langbfdea662014-07-23 14:16:32 -04007748
7749 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
7750 {
7751 return;
7752 }
7753
7754 switch (target)
7755 {
7756 case GL_TEXTURE_2D:
7757 {
7758 gl::Texture2D *texture2d = context->getTexture2D();
7759 texture2d->storage(levels, internalformat, width, height);
7760 }
7761 break;
7762
7763 case GL_TEXTURE_CUBE_MAP:
7764 {
7765 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7766 textureCube->storage(levels, internalformat, width);
7767 }
7768 break;
7769
7770 default:
7771 return gl::error(GL_INVALID_ENUM);
7772 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007773 }
7774}
7775
7776void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
7777{
7778 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
7779 "GLsizei height = %d, GLsizei depth = %d)",
7780 target, levels, internalformat, width, height, depth);
7781
Geoff Langbfdea662014-07-23 14:16:32 -04007782 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007783
Geoff Langbfdea662014-07-23 14:16:32 -04007784 if (context)
7785 {
7786 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007787 {
Geoff Langbfdea662014-07-23 14:16:32 -04007788 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00007789 }
Geoff Langbfdea662014-07-23 14:16:32 -04007790
7791 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
7792 {
7793 return;
7794 }
7795
7796 switch (target)
7797 {
7798 case GL_TEXTURE_3D:
7799 {
7800 gl::Texture3D *texture3d = context->getTexture3D();
7801 texture3d->storage(levels, internalformat, width, height, depth);
7802 }
7803 break;
7804
7805 case GL_TEXTURE_2D_ARRAY:
7806 {
7807 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
7808 texture2darray->storage(levels, internalformat, width, height, depth);
7809 }
7810 break;
7811
7812 default:
7813 UNREACHABLE();
7814 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007815 }
7816}
7817
7818void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
7819{
7820 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
7821 "GLint* params = 0x%0.8p)",
7822 target, internalformat, pname, bufSize, params);
7823
Geoff Langbfdea662014-07-23 14:16:32 -04007824 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007825
Geoff Langbfdea662014-07-23 14:16:32 -04007826 if (context)
7827 {
7828 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007829 {
Geoff Langbfdea662014-07-23 14:16:32 -04007830 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007831 }
Geoff Langbfdea662014-07-23 14:16:32 -04007832
7833 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7834 if (!formatCaps.renderable)
7835 {
7836 return gl::error(GL_INVALID_ENUM);
7837 }
7838
7839 if (target != GL_RENDERBUFFER)
7840 {
7841 return gl::error(GL_INVALID_ENUM);
7842 }
7843
7844 if (bufSize < 0)
7845 {
7846 return gl::error(GL_INVALID_VALUE);
7847 }
7848
7849 switch (pname)
7850 {
7851 case GL_NUM_SAMPLE_COUNTS:
7852 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04007853 {
7854 *params = formatCaps.sampleCounts.size();
7855 }
Geoff Langbfdea662014-07-23 14:16:32 -04007856 break;
7857 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04007858 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04007859 break;
7860 default:
7861 return gl::error(GL_INVALID_ENUM);
7862 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007863 }
7864}
7865
7866// Extension functions
7867
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007868void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
7869 GLbitfield mask, GLenum filter)
7870{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007871 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007872 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
7873 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
7874 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
7875
Geoff Langbfdea662014-07-23 14:16:32 -04007876 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007877
Geoff Langbfdea662014-07-23 14:16:32 -04007878 if (context)
7879 {
7880 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
7881 dstX0, dstY0, dstX1, dstY1, mask, filter,
7882 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007883 {
Geoff Langbfdea662014-07-23 14:16:32 -04007884 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007885 }
Geoff Langbfdea662014-07-23 14:16:32 -04007886
7887 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
7888 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007889 }
7890}
7891
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007892void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
7893 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007894{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007895 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007896 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007897 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007898 target, level, internalformat, width, height, depth, border, format, type, pixels);
7899
Geoff Langbfdea662014-07-23 14:16:32 -04007900 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007901}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00007902
Geoff Langbfdea662014-07-23 14:16:32 -04007903void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007904 GLenum *binaryFormat, void *binary)
7905{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00007906 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 +00007907 program, bufSize, length, binaryFormat, binary);
7908
Geoff Langbfdea662014-07-23 14:16:32 -04007909 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007910
Geoff Langbfdea662014-07-23 14:16:32 -04007911 if (context)
7912 {
7913 gl::Program *programObject = context->getProgram(program);
7914
7915 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007916 {
Geoff Langbfdea662014-07-23 14:16:32 -04007917 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007918 }
Geoff Langbfdea662014-07-23 14:16:32 -04007919
7920 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7921
7922 if (!programBinary)
7923 {
7924 return gl::error(GL_INVALID_OPERATION);
7925 }
7926
Geoff Lang900013c2014-07-07 11:32:19 -04007927 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04007928 {
7929 return gl::error(GL_INVALID_OPERATION);
7930 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007931 }
7932}
7933
7934void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
7935 const void *binary, GLint length)
7936{
7937 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
7938 program, binaryFormat, binary, length);
7939
Geoff Langbfdea662014-07-23 14:16:32 -04007940 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007941
Geoff Langbfdea662014-07-23 14:16:32 -04007942 if (context)
7943 {
Geoff Lang900013c2014-07-07 11:32:19 -04007944 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
7945 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007946 {
Geoff Langbfdea662014-07-23 14:16:32 -04007947 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007948 }
Geoff Langbfdea662014-07-23 14:16:32 -04007949
7950 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04007951 if (!programObject)
7952 {
7953 return gl::error(GL_INVALID_OPERATION);
7954 }
7955
Geoff Lang900013c2014-07-07 11:32:19 -04007956 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007957 }
7958}
7959
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007960void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
7961{
7962 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
7963
Geoff Langbfdea662014-07-23 14:16:32 -04007964 gl::Context *context = gl::getNonLostContext();
7965
7966 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007967 {
Geoff Langbfdea662014-07-23 14:16:32 -04007968 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007969 {
Geoff Langbfdea662014-07-23 14:16:32 -04007970 return gl::error(GL_INVALID_VALUE);
7971 }
7972
7973 if (context->getState().getDrawFramebuffer()->id() == 0)
7974 {
7975 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007976 {
Geoff Langbfdea662014-07-23 14:16:32 -04007977 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007978 }
7979
Geoff Langbfdea662014-07-23 14:16:32 -04007980 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007981 {
Geoff Langbfdea662014-07-23 14:16:32 -04007982 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00007983 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007984 }
Geoff Langbfdea662014-07-23 14:16:32 -04007985 else
7986 {
7987 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
7988 {
7989 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
7990 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
7991 {
7992 return gl::error(GL_INVALID_OPERATION);
7993 }
7994 }
7995 }
7996
7997 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
7998
7999 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8000 {
8001 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8002 }
8003
8004 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8005 {
8006 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8007 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008008 }
8009}
8010
Shannon Woodsb3801742014-03-27 14:59:19 -04008011void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8012{
8013 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8014
Geoff Langbfdea662014-07-23 14:16:32 -04008015 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008016
Geoff Langbfdea662014-07-23 14:16:32 -04008017 if (context)
8018 {
8019 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008020 {
Geoff Langbfdea662014-07-23 14:16:32 -04008021 return gl::error(GL_INVALID_ENUM);
Shannon Woodsb3801742014-03-27 14:59:19 -04008022 }
Geoff Langbfdea662014-07-23 14:16:32 -04008023
8024 if (pname != GL_BUFFER_MAP_POINTER)
8025 {
8026 return gl::error(GL_INVALID_ENUM);
8027 }
8028
8029 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8030
8031 if (!buffer || !buffer->isMapped())
8032 {
8033 *params = NULL;
8034 }
8035 else
8036 {
8037 *params = buffer->getMapPointer();
8038 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008039 }
8040}
8041
8042void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8043{
8044 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8045
Geoff Langbfdea662014-07-23 14:16:32 -04008046 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008047
Geoff Langbfdea662014-07-23 14:16:32 -04008048 if (context)
8049 {
8050 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008051 {
Geoff Langbfdea662014-07-23 14:16:32 -04008052 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woodsb3801742014-03-27 14:59:19 -04008053 }
Geoff Langbfdea662014-07-23 14:16:32 -04008054
8055 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8056
8057 if (buffer == NULL)
8058 {
8059 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8060 }
8061
8062 if (access != GL_WRITE_ONLY_OES)
8063 {
8064 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
8065 }
8066
8067 if (buffer->isMapped())
8068 {
8069 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8070 }
8071
8072 return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
Shannon Woodsb3801742014-03-27 14:59:19 -04008073 }
8074
8075 return NULL;
8076}
8077
8078GLboolean __stdcall glUnmapBufferOES(GLenum target)
8079{
8080 EVENT("(GLenum target = 0x%X)", target);
8081
Geoff Langbfdea662014-07-23 14:16:32 -04008082 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008083
Geoff Langbfdea662014-07-23 14:16:32 -04008084 if (context)
8085 {
8086 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008087 {
Geoff Langbfdea662014-07-23 14:16:32 -04008088 return gl::error(GL_INVALID_ENUM, GL_FALSE);
Shannon Woodsb3801742014-03-27 14:59:19 -04008089 }
Geoff Langbfdea662014-07-23 14:16:32 -04008090
8091 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8092
8093 if (buffer == NULL || !buffer->isMapped())
8094 {
8095 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8096 }
8097
8098 // TODO: detect if we had corruption. if so, throw an error and return false.
8099
8100 buffer->unmap();
8101
8102 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008103 }
8104
8105 return GL_FALSE;
8106}
8107
Shannon Woods916e7692014-03-27 16:58:22 -04008108void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8109{
8110 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8111 target, offset, length, access);
8112
Geoff Langbfdea662014-07-23 14:16:32 -04008113 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008114
Geoff Langbfdea662014-07-23 14:16:32 -04008115 if (context)
8116 {
8117 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008118 {
Geoff Langbfdea662014-07-23 14:16:32 -04008119 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woods916e7692014-03-27 16:58:22 -04008120 }
Geoff Langbfdea662014-07-23 14:16:32 -04008121
8122 if (offset < 0 || length < 0)
8123 {
8124 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8125 }
8126
8127 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8128
8129 if (buffer == NULL)
8130 {
8131 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8132 }
8133
8134 // Check for buffer overflow
8135 size_t offsetSize = static_cast<size_t>(offset);
8136 size_t lengthSize = static_cast<size_t>(length);
8137
8138 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8139 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8140 {
8141 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8142 }
8143
8144 // Check for invalid bits in the mask
8145 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8146 GL_MAP_WRITE_BIT |
8147 GL_MAP_INVALIDATE_RANGE_BIT |
8148 GL_MAP_INVALIDATE_BUFFER_BIT |
8149 GL_MAP_FLUSH_EXPLICIT_BIT |
8150 GL_MAP_UNSYNCHRONIZED_BIT;
8151
8152 if (access & ~(allAccessBits))
8153 {
8154 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8155 }
8156
8157 if (length == 0 || buffer->isMapped())
8158 {
8159 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8160 }
8161
8162 // Check for invalid bit combinations
8163 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8164 {
8165 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8166 }
8167
8168 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8169 GL_MAP_INVALIDATE_BUFFER_BIT |
8170 GL_MAP_UNSYNCHRONIZED_BIT;
8171
8172 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8173 {
8174 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8175 }
8176
8177 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8178 {
8179 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8180 }
8181
8182 return buffer->mapRange(offset, length, access);
Shannon Woods916e7692014-03-27 16:58:22 -04008183 }
8184
8185 return NULL;
8186}
8187
8188void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8189{
8190 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8191
Geoff Langbfdea662014-07-23 14:16:32 -04008192 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008193
Geoff Langbfdea662014-07-23 14:16:32 -04008194 if (context)
8195 {
8196 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008197 {
Geoff Langbfdea662014-07-23 14:16:32 -04008198 return gl::error(GL_INVALID_VALUE);
Shannon Woods916e7692014-03-27 16:58:22 -04008199 }
Geoff Langbfdea662014-07-23 14:16:32 -04008200
8201 if (!gl::ValidBufferTarget(context, target))
8202 {
8203 return gl::error(GL_INVALID_ENUM);
8204 }
8205
8206 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8207
8208 if (buffer == NULL)
8209 {
8210 return gl::error(GL_INVALID_OPERATION);
8211 }
8212
8213 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8214 {
8215 return gl::error(GL_INVALID_OPERATION);
8216 }
8217
8218 // Check for buffer overflow
8219 size_t offsetSize = static_cast<size_t>(offset);
8220 size_t lengthSize = static_cast<size_t>(length);
8221
8222 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8223 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8224 {
8225 return gl::error(GL_INVALID_VALUE);
8226 }
8227
8228 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008229 }
8230}
8231
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008232__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8233{
8234 struct Extension
8235 {
8236 const char *name;
8237 __eglMustCastToProperFunctionPointerType address;
8238 };
8239
8240 static const Extension glExtensions[] =
8241 {
8242 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008243 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008244 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008245 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8246 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8247 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8248 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8249 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8250 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8251 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008252 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008253 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008254 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8255 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8256 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8257 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008258 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8259 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8260 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8261 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8262 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8263 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8264 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008265 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008266 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8267 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8268 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008269 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008270 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8271 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8272 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008273 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8274 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8275 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008276
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008277 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008278 {
8279 if (strcmp(procname, glExtensions[ext].name) == 0)
8280 {
8281 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8282 }
8283 }
8284
8285 return NULL;
8286}
8287
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008288// Non-public functions used by EGL
8289
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008290bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008291{
8292 EVENT("(egl::Surface* surface = 0x%0.8p)",
8293 surface);
8294
Geoff Langbfdea662014-07-23 14:16:32 -04008295 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008296
Geoff Langbfdea662014-07-23 14:16:32 -04008297 if (context)
8298 {
8299 gl::Texture2D *textureObject = context->getTexture2D();
8300 ASSERT(textureObject != NULL);
8301
8302 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008303 {
Geoff Langbfdea662014-07-23 14:16:32 -04008304 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008305 }
Geoff Langbfdea662014-07-23 14:16:32 -04008306
8307 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008308 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008309
8310 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008311}
8312
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008313}