blob: 73f4572fac8a4442c767f27b8d8df3db5ff4c7fa [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 {
1297 if (!ValidateDrawArrays(context, mode, first, count))
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 {
1332 if (!ValidateDrawElements(context, mode, count, type, indices))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001333 {
Geoff Langbfdea662014-07-23 14:16:32 -04001334 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001335 }
Geoff Langbfdea662014-07-23 14:16:32 -04001336
1337 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001338 }
1339}
1340
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001341void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1342{
1343 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1344 mode, count, type, indices, primcount);
1345
Geoff Langbfdea662014-07-23 14:16:32 -04001346 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001347
Geoff Langbfdea662014-07-23 14:16:32 -04001348 if (context)
1349 {
1350 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001351 {
Geoff Langbfdea662014-07-23 14:16:32 -04001352 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001353 }
Geoff Langbfdea662014-07-23 14:16:32 -04001354
1355 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001356 }
1357}
1358
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001359void __stdcall glEnable(GLenum cap)
1360{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001361 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001362
Geoff Langbfdea662014-07-23 14:16:32 -04001363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001364
Geoff Langbfdea662014-07-23 14:16:32 -04001365 if (context)
1366 {
1367 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001368 {
Geoff Langbfdea662014-07-23 14:16:32 -04001369 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001370 }
Geoff Langbfdea662014-07-23 14:16:32 -04001371
1372 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001373 }
1374}
1375
1376void __stdcall glEnableVertexAttribArray(GLuint index)
1377{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001378 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001379
Geoff Langbfdea662014-07-23 14:16:32 -04001380 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001381 {
Geoff Langbfdea662014-07-23 14:16:32 -04001382 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001383 }
Geoff Langbfdea662014-07-23 14:16:32 -04001384
1385 gl::Context *context = gl::getNonLostContext();
1386
1387 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001388 {
Geoff Langbfdea662014-07-23 14:16:32 -04001389 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001390 }
1391}
1392
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001393void __stdcall glEndQueryEXT(GLenum target)
1394{
1395 EVENT("GLenum target = 0x%X)", target);
1396
Geoff Langbfdea662014-07-23 14:16:32 -04001397 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001398
Geoff Langbfdea662014-07-23 14:16:32 -04001399 if (context)
1400 {
1401 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001402 {
Geoff Langbfdea662014-07-23 14:16:32 -04001403 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001404 }
Geoff Langbfdea662014-07-23 14:16:32 -04001405
1406 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001407 }
1408}
1409
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001410void __stdcall glFinishFenceNV(GLuint fence)
1411{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001412 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001413
Geoff Langbfdea662014-07-23 14:16:32 -04001414 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001415
Geoff Langbfdea662014-07-23 14:16:32 -04001416 if (context)
1417 {
1418 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1419
1420 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001421 {
Geoff Langbfdea662014-07-23 14:16:32 -04001422 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001423 }
Geoff Langbfdea662014-07-23 14:16:32 -04001424
1425 if (fenceObject->isFence() != GL_TRUE)
1426 {
1427 return gl::error(GL_INVALID_OPERATION);
1428 }
1429
1430 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001431 }
1432}
1433
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001434void __stdcall glFinish(void)
1435{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001436 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001437
Geoff Langbfdea662014-07-23 14:16:32 -04001438 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001439
Geoff Langbfdea662014-07-23 14:16:32 -04001440 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001441 {
Geoff Langbfdea662014-07-23 14:16:32 -04001442 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001443 }
1444}
1445
1446void __stdcall glFlush(void)
1447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001448 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001449
Geoff Langbfdea662014-07-23 14:16:32 -04001450 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001451
Geoff Langbfdea662014-07-23 14:16:32 -04001452 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453 {
Geoff Langbfdea662014-07-23 14:16:32 -04001454 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001455 }
1456}
1457
1458void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001460 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001461 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001462
Geoff Langbfdea662014-07-23 14:16:32 -04001463 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001464 {
Geoff Langbfdea662014-07-23 14:16:32 -04001465 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001466 }
Geoff Langbfdea662014-07-23 14:16:32 -04001467
1468 gl::Context *context = gl::getNonLostContext();
1469
1470 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001471 {
Geoff Langbfdea662014-07-23 14:16:32 -04001472 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1473 {
1474 return;
1475 }
1476
1477 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1478 ASSERT(framebuffer);
1479
1480 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1481 {
1482 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1483 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1484 }
1485 else
1486 {
1487 switch (attachment)
1488 {
1489 case GL_DEPTH_ATTACHMENT:
1490 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1491 break;
1492 case GL_STENCIL_ATTACHMENT:
1493 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1494 break;
1495 case GL_DEPTH_STENCIL_ATTACHMENT:
1496 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1497 break;
1498 default:
1499 UNREACHABLE();
1500 break;
1501 }
1502 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001503 }
1504}
1505
1506void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1507{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001508 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001509 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001510
Geoff Langbfdea662014-07-23 14:16:32 -04001511 gl::Context *context = gl::getNonLostContext();
1512 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001513 {
Geoff Langbfdea662014-07-23 14:16:32 -04001514 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001515 {
Geoff Langbfdea662014-07-23 14:16:32 -04001516 return;
1517 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001518
Geoff Langbfdea662014-07-23 14:16:32 -04001519 if (texture == 0)
1520 {
1521 textarget = GL_NONE;
1522 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001523
Geoff Langbfdea662014-07-23 14:16:32 -04001524 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001525
Geoff Langbfdea662014-07-23 14:16:32 -04001526 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1527 {
1528 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1529 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1530 }
1531 else
1532 {
1533 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001534 {
Geoff Langbfdea662014-07-23 14:16:32 -04001535 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1536 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1537 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001538 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001539 }
1540 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001541}
1542
1543void __stdcall glFrontFace(GLenum mode)
1544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001545 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001546
Geoff Langbfdea662014-07-23 14:16:32 -04001547 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001548 {
Geoff Langbfdea662014-07-23 14:16:32 -04001549 case GL_CW:
1550 case GL_CCW:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001551 {
Geoff Langbfdea662014-07-23 14:16:32 -04001552 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001553
Geoff Langbfdea662014-07-23 14:16:32 -04001554 if (context)
1555 {
1556 context->getState().setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001557 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001558 }
Geoff Langbfdea662014-07-23 14:16:32 -04001559 break;
1560 default:
1561 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001562 }
1563}
1564
1565void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1566{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001567 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001568
Geoff Langbfdea662014-07-23 14:16:32 -04001569 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001570 {
Geoff Langbfdea662014-07-23 14:16:32 -04001571 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001572 }
Geoff Langbfdea662014-07-23 14:16:32 -04001573
1574 gl::Context *context = gl::getNonLostContext();
1575
1576 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001577 {
Geoff Langbfdea662014-07-23 14:16:32 -04001578 for (int i = 0; i < n; i++)
1579 {
1580 buffers[i] = context->createBuffer();
1581 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001582 }
1583}
1584
1585void __stdcall glGenerateMipmap(GLenum target)
1586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001587 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001588
Geoff Langbfdea662014-07-23 14:16:32 -04001589 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001590
Geoff Langbfdea662014-07-23 14:16:32 -04001591 if (context)
1592 {
1593 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001594 {
Geoff Langbfdea662014-07-23 14:16:32 -04001595 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001596 }
Geoff Langbfdea662014-07-23 14:16:32 -04001597
1598 gl::Texture *texture = context->getTargetTexture(target);
1599
1600 if (texture == NULL)
1601 {
1602 return gl::error(GL_INVALID_OPERATION);
1603 }
1604
1605 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1606 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001607 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001608
1609 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1610 // unsized formats or that are color renderable and filterable. Since we do not track if
1611 // the texture was created with sized or unsized format (only sized formats are stored),
1612 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1613 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1614 // textures since they're the only texture format that can be created with unsized formats
1615 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1616 // was the last version to use add them.
1617 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1618 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1619 internalFormat == GL_ALPHA8_EXT;
1620
Geoff Lang5d601382014-07-22 15:14:06 -04001621 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1622 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001623 {
1624 return gl::error(GL_INVALID_OPERATION);
1625 }
1626
1627 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001628 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001629 {
1630 return gl::error(GL_INVALID_OPERATION);
1631 }
1632
1633 // Non-power of 2 ES2 check
1634 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1635 {
1636 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
1637 return gl::error(GL_INVALID_OPERATION);
1638 }
1639
1640 // Cube completeness check
1641 if (target == GL_TEXTURE_CUBE_MAP)
1642 {
1643 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1644 if (!textureCube->isCubeComplete())
1645 {
1646 return gl::error(GL_INVALID_OPERATION);
1647 }
1648 }
1649
1650 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001651 }
1652}
1653
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001654void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001656 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001657
Geoff Langbfdea662014-07-23 14:16:32 -04001658 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001659 {
Geoff Langbfdea662014-07-23 14:16:32 -04001660 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001661 }
Geoff Langbfdea662014-07-23 14:16:32 -04001662
1663 gl::Context *context = gl::getNonLostContext();
1664
1665 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001666 {
Geoff Langbfdea662014-07-23 14:16:32 -04001667 for (int i = 0; i < n; i++)
1668 {
1669 fences[i] = context->createFenceNV();
1670 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001671 }
1672}
1673
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001674void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1675{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001676 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001677
Geoff Langbfdea662014-07-23 14:16:32 -04001678 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001679 {
Geoff Langbfdea662014-07-23 14:16:32 -04001680 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001681 }
Geoff Langbfdea662014-07-23 14:16:32 -04001682
1683 gl::Context *context = gl::getNonLostContext();
1684
1685 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001686 {
Geoff Langbfdea662014-07-23 14:16:32 -04001687 for (int i = 0; i < n; i++)
1688 {
1689 framebuffers[i] = context->createFramebuffer();
1690 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001691 }
1692}
1693
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001694void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1695{
1696 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1697
Geoff Langbfdea662014-07-23 14:16:32 -04001698 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001699
Geoff Langbfdea662014-07-23 14:16:32 -04001700 if (context)
1701 {
1702 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001703 {
Geoff Langbfdea662014-07-23 14:16:32 -04001704 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001705 }
Geoff Langbfdea662014-07-23 14:16:32 -04001706
1707 for (GLsizei i = 0; i < n; i++)
1708 {
1709 ids[i] = context->createQuery();
1710 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001711 }
1712}
1713
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001714void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001716 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001717
Geoff Langbfdea662014-07-23 14:16:32 -04001718 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001719 {
Geoff Langbfdea662014-07-23 14:16:32 -04001720 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001721 }
Geoff Langbfdea662014-07-23 14:16:32 -04001722
1723 gl::Context *context = gl::getNonLostContext();
1724
1725 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001726 {
Geoff Langbfdea662014-07-23 14:16:32 -04001727 for (int i = 0; i < n; i++)
1728 {
1729 renderbuffers[i] = context->createRenderbuffer();
1730 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001731 }
1732}
1733
1734void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1735{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001736 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001737
Geoff Langbfdea662014-07-23 14:16:32 -04001738 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001739 {
Geoff Langbfdea662014-07-23 14:16:32 -04001740 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001741 }
Geoff Langbfdea662014-07-23 14:16:32 -04001742
1743 gl::Context *context = gl::getNonLostContext();
1744
1745 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001746 {
Geoff Langbfdea662014-07-23 14:16:32 -04001747 for (int i = 0; i < n; i++)
1748 {
1749 textures[i] = context->createTexture();
1750 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001751 }
1752}
1753
daniel@transgaming.com85423182010-04-22 13:35:27 +00001754void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001755{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001756 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001757 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001758 program, index, bufsize, length, size, type, name);
1759
Geoff Langbfdea662014-07-23 14:16:32 -04001760 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001761 {
Geoff Langbfdea662014-07-23 14:16:32 -04001762 return gl::error(GL_INVALID_VALUE);
1763 }
1764
1765 gl::Context *context = gl::getNonLostContext();
1766
1767 if (context)
1768 {
1769 gl::Program *programObject = context->getProgram(program);
1770
1771 if (!programObject)
1772 {
1773 if (context->getShader(program))
1774 {
1775 return gl::error(GL_INVALID_OPERATION);
1776 }
1777 else
1778 {
1779 return gl::error(GL_INVALID_VALUE);
1780 }
1781 }
1782
1783 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001785 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001786 }
1787
Geoff Langbfdea662014-07-23 14:16:32 -04001788 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001789 }
1790}
1791
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001792void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001793{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001794 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001795 "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 +00001796 program, index, bufsize, length, size, type, name);
1797
Geoff Langbfdea662014-07-23 14:16:32 -04001798 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001799 {
Geoff Langbfdea662014-07-23 14:16:32 -04001800 return gl::error(GL_INVALID_VALUE);
1801 }
1802
1803 gl::Context *context = gl::getNonLostContext();
1804
1805 if (context)
1806 {
1807 gl::Program *programObject = context->getProgram(program);
1808
1809 if (!programObject)
1810 {
1811 if (context->getShader(program))
1812 {
1813 return gl::error(GL_INVALID_OPERATION);
1814 }
1815 else
1816 {
1817 return gl::error(GL_INVALID_VALUE);
1818 }
1819 }
1820
1821 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001823 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001824 }
1825
Geoff Langbfdea662014-07-23 14:16:32 -04001826 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001827 }
1828}
1829
1830void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1831{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001832 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 +00001833 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001834
Geoff Langbfdea662014-07-23 14:16:32 -04001835 if (maxcount < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001836 {
Geoff Langbfdea662014-07-23 14:16:32 -04001837 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001838 }
Geoff Langbfdea662014-07-23 14:16:32 -04001839
1840 gl::Context *context = gl::getNonLostContext();
1841
1842 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001843 {
Geoff Langbfdea662014-07-23 14:16:32 -04001844 gl::Program *programObject = context->getProgram(program);
1845
1846 if (!programObject)
1847 {
1848 if (context->getShader(program))
1849 {
1850 return gl::error(GL_INVALID_OPERATION);
1851 }
1852 else
1853 {
1854 return gl::error(GL_INVALID_VALUE);
1855 }
1856 }
1857
1858 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001859 }
1860}
1861
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001862int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001863{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001864 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001865
Geoff Langbfdea662014-07-23 14:16:32 -04001866 gl::Context *context = gl::getNonLostContext();
1867
1868 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001869 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001870
Geoff Langbfdea662014-07-23 14:16:32 -04001871 gl::Program *programObject = context->getProgram(program);
1872
1873 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001874 {
Geoff Langbfdea662014-07-23 14:16:32 -04001875 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001876 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001877 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001878 }
Geoff Langbfdea662014-07-23 14:16:32 -04001879 else
1880 {
1881 return gl::error(GL_INVALID_VALUE, -1);
1882 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001883 }
Geoff Langbfdea662014-07-23 14:16:32 -04001884
1885 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1886 if (!programObject->isLinked() || !programBinary)
1887 {
1888 return gl::error(GL_INVALID_OPERATION, -1);
1889 }
1890
1891 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001892 }
1893
1894 return -1;
1895}
1896
1897void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001899 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001900
Geoff Langbfdea662014-07-23 14:16:32 -04001901 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00001902
Geoff Langbfdea662014-07-23 14:16:32 -04001903 if (context)
1904 {
1905 GLenum nativeType;
1906 unsigned int numParams = 0;
1907 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001908 {
Geoff Langbfdea662014-07-23 14:16:32 -04001909 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001910 }
Geoff Langbfdea662014-07-23 14:16:32 -04001911
1912 if (nativeType == GL_BOOL)
1913 {
1914 context->getBooleanv(pname, params);
1915 }
1916 else
1917 {
1918 CastStateValues(context, nativeType, pname, numParams, params);
1919 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001920 }
1921}
1922
1923void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001925 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 +00001926
Geoff Langbfdea662014-07-23 14:16:32 -04001927 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001928
Geoff Langbfdea662014-07-23 14:16:32 -04001929 if (context)
1930 {
1931 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001932 {
Geoff Langbfdea662014-07-23 14:16:32 -04001933 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001934 }
Geoff Langbfdea662014-07-23 14:16:32 -04001935
1936 if (!gl::ValidBufferParameter(context, pname))
1937 {
1938 return gl::error(GL_INVALID_ENUM);
1939 }
1940
1941 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
1942
1943 if (!buffer)
1944 {
1945 // A null buffer means that "0" is bound to the requested buffer target
1946 return gl::error(GL_INVALID_OPERATION);
1947 }
1948
1949 switch (pname)
1950 {
1951 case GL_BUFFER_USAGE:
1952 *params = static_cast<GLint>(buffer->getUsage());
1953 break;
1954 case GL_BUFFER_SIZE:
1955 *params = gl::clampCast<GLint>(buffer->getSize());
1956 break;
1957 case GL_BUFFER_ACCESS_FLAGS:
1958 *params = buffer->getAccessFlags();
1959 break;
1960 case GL_BUFFER_MAPPED:
1961 *params = static_cast<GLint>(buffer->isMapped());
1962 break;
1963 case GL_BUFFER_MAP_OFFSET:
1964 *params = gl::clampCast<GLint>(buffer->getMapOffset());
1965 break;
1966 case GL_BUFFER_MAP_LENGTH:
1967 *params = gl::clampCast<GLint>(buffer->getMapLength());
1968 break;
1969 default: UNREACHABLE(); break;
1970 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001971 }
1972}
1973
1974GLenum __stdcall glGetError(void)
1975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001976 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001977
1978 gl::Context *context = gl::getContext();
1979
1980 if (context)
1981 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00001982 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001983 }
1984
1985 return GL_NO_ERROR;
1986}
1987
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001988void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
1989{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001990 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001991
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001992
Geoff Langbfdea662014-07-23 14:16:32 -04001993 gl::Context *context = gl::getNonLostContext();
1994
1995 if (context)
1996 {
1997 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1998
1999 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002000 {
Geoff Langbfdea662014-07-23 14:16:32 -04002001 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002002 }
Geoff Langbfdea662014-07-23 14:16:32 -04002003
2004 if (fenceObject->isFence() != GL_TRUE)
2005 {
2006 return gl::error(GL_INVALID_OPERATION);
2007 }
2008
2009 switch (pname)
2010 {
2011 case GL_FENCE_STATUS_NV:
2012 case GL_FENCE_CONDITION_NV:
2013 break;
2014
2015 default: return gl::error(GL_INVALID_ENUM);
2016 }
2017
2018 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002019 }
2020}
2021
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002022void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2023{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002024 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002025
Geoff Langbfdea662014-07-23 14:16:32 -04002026 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002027
Geoff Langbfdea662014-07-23 14:16:32 -04002028 if (context)
2029 {
2030 GLenum nativeType;
2031 unsigned int numParams = 0;
2032 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002033 {
Geoff Langbfdea662014-07-23 14:16:32 -04002034 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002035 }
Geoff Langbfdea662014-07-23 14:16:32 -04002036
2037 if (nativeType == GL_FLOAT)
2038 {
2039 context->getFloatv(pname, params);
2040 }
2041 else
2042 {
2043 CastStateValues(context, nativeType, pname, numParams, params);
2044 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002045 }
2046}
2047
2048void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002050 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 +00002051 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002052
Geoff Langbfdea662014-07-23 14:16:32 -04002053 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002054
Geoff Langbfdea662014-07-23 14:16:32 -04002055 if (context)
2056 {
2057 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002058 {
Geoff Langbfdea662014-07-23 14:16:32 -04002059 return gl::error(GL_INVALID_ENUM);
2060 }
2061
2062 int clientVersion = context->getClientVersion();
2063
2064 switch (pname)
2065 {
2066 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2067 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2068 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2069 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2070 break;
2071 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2072 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002074 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002075 }
Geoff Langbfdea662014-07-23 14:16:32 -04002076 break;
2077 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2078 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2079 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2080 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2081 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2082 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2083 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2084 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2085 if (clientVersion < 3)
2086 {
2087 return gl::error(GL_INVALID_ENUM);
2088 }
2089 break;
2090 default:
2091 return gl::error(GL_INVALID_ENUM);
2092 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002093
Geoff Langbfdea662014-07-23 14:16:32 -04002094 // Determine if the attachment is a valid enum
2095 switch (attachment)
2096 {
2097 case GL_BACK:
2098 case GL_FRONT:
2099 case GL_DEPTH:
2100 case GL_STENCIL:
2101 case GL_DEPTH_STENCIL_ATTACHMENT:
2102 if (clientVersion < 3)
2103 {
2104 return gl::error(GL_INVALID_ENUM);
2105 }
2106 break;
2107
2108 case GL_DEPTH_ATTACHMENT:
2109 case GL_STENCIL_ATTACHMENT:
2110 break;
2111
2112 default:
2113 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2114 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2115 {
2116 return gl::error(GL_INVALID_ENUM);
2117 }
2118 break;
2119 }
2120
2121 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2122 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2123
2124 if (framebufferHandle == 0)
2125 {
2126 if (clientVersion < 3)
2127 {
2128 return gl::error(GL_INVALID_OPERATION);
2129 }
2130
2131 switch (attachment)
2132 {
2133 case GL_BACK:
2134 case GL_DEPTH:
2135 case GL_STENCIL:
2136 break;
2137 default:
2138 return gl::error(GL_INVALID_OPERATION);
2139 }
2140 }
2141 else
2142 {
2143 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2144 {
2145 // Valid attachment query
2146 }
2147 else
2148 {
2149 switch (attachment)
2150 {
2151 case GL_DEPTH_ATTACHMENT:
2152 case GL_STENCIL_ATTACHMENT:
2153 break;
2154 case GL_DEPTH_STENCIL_ATTACHMENT:
2155 if (framebuffer->hasValidDepthStencil())
2156 {
2157 return gl::error(GL_INVALID_OPERATION);
2158 }
2159 break;
2160 default:
2161 return gl::error(GL_INVALID_OPERATION);
2162 }
2163 }
2164 }
2165
2166 GLenum attachmentType = GL_NONE;
2167 GLuint attachmentHandle = 0;
2168 GLuint attachmentLevel = 0;
2169 GLuint attachmentLayer = 0;
2170
2171 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2172
2173 if (attachmentObject)
2174 {
2175 attachmentType = attachmentObject->type();
2176 attachmentHandle = attachmentObject->id();
2177 attachmentLevel = attachmentObject->mipLevel();
2178 attachmentLayer = attachmentObject->layer();
2179 }
2180
2181 GLenum attachmentObjectType; // Type category
2182 if (framebufferHandle == 0)
2183 {
2184 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2185 }
2186 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2187 {
2188 attachmentObjectType = attachmentType;
2189 }
2190 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2191 {
2192 attachmentObjectType = GL_TEXTURE;
2193 }
2194 else
2195 {
2196 UNREACHABLE();
2197 return;
2198 }
2199
2200 if (attachmentObjectType == GL_NONE)
2201 {
2202 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2203 // is NONE, then querying any other pname will generate INVALID_ENUM.
2204
2205 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2206 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2207 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002208
Geoff Lang646559f2013-08-15 11:08:15 -04002209 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002210 {
Geoff Lang646559f2013-08-15 11:08:15 -04002211 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002212 *params = attachmentObjectType;
2213 break;
2214
Geoff Lang646559f2013-08-15 11:08:15 -04002215 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002216 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002217 {
Geoff Lang05b05022014-06-11 15:31:45 -04002218 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002219 }
Geoff Langbfdea662014-07-23 14:16:32 -04002220 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002221 break;
2222
2223 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002224 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002225 {
Geoff Langbfdea662014-07-23 14:16:32 -04002226 return gl::error(GL_INVALID_ENUM);
Geoff Lang646559f2013-08-15 11:08:15 -04002227 }
2228 else
2229 {
Geoff Langbfdea662014-07-23 14:16:32 -04002230 gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002231 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002232 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002233 }
Geoff Langbfdea662014-07-23 14:16:32 -04002234 else
2235 {
2236 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2237 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2238 ASSERT(attachmentObject != NULL);
2239
2240 switch (pname)
2241 {
2242 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2243 *params = attachmentObjectType;
2244 break;
2245
2246 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2247 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2248 {
2249 return gl::error(GL_INVALID_ENUM);
2250 }
2251 *params = attachmentHandle;
2252 break;
2253
2254 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2255 if (attachmentObjectType != GL_TEXTURE)
2256 {
2257 return gl::error(GL_INVALID_ENUM);
2258 }
2259 *params = attachmentLevel;
2260 break;
2261
2262 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2263 if (attachmentObjectType != GL_TEXTURE)
2264 {
2265 return gl::error(GL_INVALID_ENUM);
2266 }
2267 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2268 break;
2269
2270 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2271 *params = attachmentObject->getRedSize();
2272 break;
2273
2274 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2275 *params = attachmentObject->getGreenSize();
2276 break;
2277
2278 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2279 *params = attachmentObject->getBlueSize();
2280 break;
2281
2282 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2283 *params = attachmentObject->getAlphaSize();
2284 break;
2285
2286 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2287 *params = attachmentObject->getDepthSize();
2288 break;
2289
2290 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2291 *params = attachmentObject->getStencilSize();
2292 break;
2293
2294 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2295 if (attachment == GL_DEPTH_STENCIL)
2296 {
2297 gl::error(GL_INVALID_OPERATION);
2298 }
2299 *params = attachmentObject->getComponentType();
2300 break;
2301
2302 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2303 *params = attachmentObject->getColorEncoding();
2304 break;
2305
2306 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2307 if (attachmentObjectType != GL_TEXTURE)
2308 {
2309 return gl::error(GL_INVALID_ENUM);
2310 }
2311 *params = attachmentLayer;
2312 break;
2313
2314 default:
2315 UNREACHABLE();
2316 break;
2317 }
2318 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002319 }
2320}
2321
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002322GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2323{
2324 EVENT("()");
2325
Geoff Langbfdea662014-07-23 14:16:32 -04002326 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002327
Geoff Langbfdea662014-07-23 14:16:32 -04002328 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002329 {
Geoff Langbfdea662014-07-23 14:16:32 -04002330 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002331 }
Geoff Langbfdea662014-07-23 14:16:32 -04002332
2333 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002334}
2335
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002336void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2337{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002338 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002339
Geoff Langbfdea662014-07-23 14:16:32 -04002340 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002341
Geoff Langbfdea662014-07-23 14:16:32 -04002342 if (context)
2343 {
2344 GLenum nativeType;
2345 unsigned int numParams = 0;
2346
2347 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002348 {
Geoff Langbfdea662014-07-23 14:16:32 -04002349 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002350 }
Geoff Langbfdea662014-07-23 14:16:32 -04002351
2352 if (nativeType == GL_INT)
2353 {
2354 context->getIntegerv(pname, params);
2355 }
2356 else
2357 {
2358 CastStateValues(context, nativeType, pname, numParams, params);
2359 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002360 }
2361}
2362
2363void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2364{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002365 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002366
Geoff Langbfdea662014-07-23 14:16:32 -04002367 gl::Context *context = gl::getNonLostContext();
2368
2369 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002370 {
Geoff Langbfdea662014-07-23 14:16:32 -04002371 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002372
Geoff Langbfdea662014-07-23 14:16:32 -04002373 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002374 {
Geoff Langbfdea662014-07-23 14:16:32 -04002375 return gl::error(GL_INVALID_VALUE);
2376 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002377
Geoff Langbfdea662014-07-23 14:16:32 -04002378 if (context->getClientVersion() < 3)
2379 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002380 switch (pname)
2381 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002382 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002383 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002384 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002385 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002386 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002387 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002388 }
2389 }
Geoff Langbfdea662014-07-23 14:16:32 -04002390
2391 switch (pname)
2392 {
2393 case GL_DELETE_STATUS:
2394 *params = programObject->isFlaggedForDeletion();
2395 return;
2396 case GL_LINK_STATUS:
2397 *params = programObject->isLinked();
2398 return;
2399 case GL_VALIDATE_STATUS:
2400 *params = programObject->isValidated();
2401 return;
2402 case GL_INFO_LOG_LENGTH:
2403 *params = programObject->getInfoLogLength();
2404 return;
2405 case GL_ATTACHED_SHADERS:
2406 *params = programObject->getAttachedShadersCount();
2407 return;
2408 case GL_ACTIVE_ATTRIBUTES:
2409 *params = programObject->getActiveAttributeCount();
2410 return;
2411 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2412 *params = programObject->getActiveAttributeMaxLength();
2413 return;
2414 case GL_ACTIVE_UNIFORMS:
2415 *params = programObject->getActiveUniformCount();
2416 return;
2417 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2418 *params = programObject->getActiveUniformMaxLength();
2419 return;
2420 case GL_PROGRAM_BINARY_LENGTH_OES:
2421 *params = programObject->getProgramBinaryLength();
2422 return;
2423 case GL_ACTIVE_UNIFORM_BLOCKS:
2424 *params = programObject->getActiveUniformBlockCount();
2425 return;
2426 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2427 *params = programObject->getActiveUniformBlockMaxLength();
2428 break;
2429 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2430 *params = programObject->getTransformFeedbackBufferMode();
2431 break;
2432 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2433 *params = programObject->getTransformFeedbackVaryingCount();
2434 break;
2435 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2436 *params = programObject->getTransformFeedbackVaryingMaxLength();
2437 break;
2438 default:
2439 return gl::error(GL_INVALID_ENUM);
2440 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441 }
2442}
2443
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002444void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002445{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002446 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 +00002447 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002448
Geoff Langbfdea662014-07-23 14:16:32 -04002449 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002450 {
Geoff Langbfdea662014-07-23 14:16:32 -04002451 return gl::error(GL_INVALID_VALUE);
2452 }
2453
2454 gl::Context *context = gl::getNonLostContext();
2455
2456 if (context)
2457 {
2458 gl::Program *programObject = context->getProgram(program);
2459
2460 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002462 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 }
2464
Geoff Langbfdea662014-07-23 14:16:32 -04002465 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002466 }
2467}
2468
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002469void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2470{
2471 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2472
Geoff Langbfdea662014-07-23 14:16:32 -04002473 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002474
Geoff Langbfdea662014-07-23 14:16:32 -04002475 if (context)
2476 {
2477 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002478 {
Geoff Langbfdea662014-07-23 14:16:32 -04002479 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002480 }
Geoff Langbfdea662014-07-23 14:16:32 -04002481
2482 switch (pname)
2483 {
2484 case GL_CURRENT_QUERY_EXT:
2485 params[0] = context->getState().getActiveQueryId(target);
2486 break;
2487
2488 default:
2489 return gl::error(GL_INVALID_ENUM);
2490 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002491 }
2492}
2493
2494void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2495{
2496 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2497
Geoff Langbfdea662014-07-23 14:16:32 -04002498 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002499
Geoff Langbfdea662014-07-23 14:16:32 -04002500 if (context)
2501 {
2502 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2503
2504 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002505 {
Geoff Langbfdea662014-07-23 14:16:32 -04002506 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002507 }
Geoff Langbfdea662014-07-23 14:16:32 -04002508
2509 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2510 {
2511 return gl::error(GL_INVALID_OPERATION);
2512 }
2513
2514 switch(pname)
2515 {
2516 case GL_QUERY_RESULT_EXT:
2517 params[0] = queryObject->getResult();
2518 break;
2519 case GL_QUERY_RESULT_AVAILABLE_EXT:
2520 params[0] = queryObject->isResultAvailable();
2521 break;
2522 default:
2523 return gl::error(GL_INVALID_ENUM);
2524 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002525 }
2526}
2527
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002528void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2529{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002530 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 +00002531
Geoff Langbfdea662014-07-23 14:16:32 -04002532 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002533
Geoff Langbfdea662014-07-23 14:16:32 -04002534 if (context)
2535 {
2536 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002537 {
Geoff Langbfdea662014-07-23 14:16:32 -04002538 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002539 }
Geoff Langbfdea662014-07-23 14:16:32 -04002540
2541 if (context->getState().getRenderbufferId() == 0)
2542 {
2543 return gl::error(GL_INVALID_OPERATION);
2544 }
2545
2546 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2547
2548 switch (pname)
2549 {
2550 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2551 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2552 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2553 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2554 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2555 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2556 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2557 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2558 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
2559 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2560 if (!context->getExtensions().framebufferMultisample)
2561 {
2562 return gl::error(GL_INVALID_ENUM);
2563 }
2564 *params = renderbuffer->getSamples();
2565 break;
2566 default:
2567 return gl::error(GL_INVALID_ENUM);
2568 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002569 }
2570}
2571
2572void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2573{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002574 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002575
Geoff Langbfdea662014-07-23 14:16:32 -04002576 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002577
Geoff Langbfdea662014-07-23 14:16:32 -04002578 if (context)
2579 {
2580 gl::Shader *shaderObject = context->getShader(shader);
2581
2582 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002583 {
Geoff Langbfdea662014-07-23 14:16:32 -04002584 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002585 }
Geoff Langbfdea662014-07-23 14:16:32 -04002586
2587 switch (pname)
2588 {
2589 case GL_SHADER_TYPE:
2590 *params = shaderObject->getType();
2591 return;
2592 case GL_DELETE_STATUS:
2593 *params = shaderObject->isFlaggedForDeletion();
2594 return;
2595 case GL_COMPILE_STATUS:
2596 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2597 return;
2598 case GL_INFO_LOG_LENGTH:
2599 *params = shaderObject->getInfoLogLength();
2600 return;
2601 case GL_SHADER_SOURCE_LENGTH:
2602 *params = shaderObject->getSourceLength();
2603 return;
2604 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2605 *params = shaderObject->getTranslatedSourceLength();
2606 return;
2607 default:
2608 return gl::error(GL_INVALID_ENUM);
2609 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002610 }
2611}
2612
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002613void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002614{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002615 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 +00002616 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002617
Geoff Langbfdea662014-07-23 14:16:32 -04002618 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002619 {
Geoff Langbfdea662014-07-23 14:16:32 -04002620 return gl::error(GL_INVALID_VALUE);
2621 }
2622
2623 gl::Context *context = gl::getNonLostContext();
2624
2625 if (context)
2626 {
2627 gl::Shader *shaderObject = context->getShader(shader);
2628
2629 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002631 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002632 }
2633
Geoff Langbfdea662014-07-23 14:16:32 -04002634 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002635 }
2636}
2637
2638void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2639{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002640 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 +00002641 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002642
Geoff Langbfdea662014-07-23 14:16:32 -04002643 switch (shadertype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002644 {
Geoff Langbfdea662014-07-23 14:16:32 -04002645 case GL_VERTEX_SHADER:
2646 case GL_FRAGMENT_SHADER:
2647 break;
2648 default:
2649 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002650 }
Geoff Langbfdea662014-07-23 14:16:32 -04002651
2652 switch (precisiontype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002653 {
Geoff Langbfdea662014-07-23 14:16:32 -04002654 case GL_LOW_FLOAT:
2655 case GL_MEDIUM_FLOAT:
2656 case GL_HIGH_FLOAT:
2657 // Assume IEEE 754 precision
2658 range[0] = 127;
2659 range[1] = 127;
2660 *precision = 23;
2661 break;
2662 case GL_LOW_INT:
2663 case GL_MEDIUM_INT:
2664 case GL_HIGH_INT:
2665 // Some (most) hardware only supports single-precision floating-point numbers,
2666 // which can accurately represent integers up to +/-16777216
2667 range[0] = 24;
2668 range[1] = 24;
2669 *precision = 0;
2670 break;
2671 default:
2672 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002673 }
2674}
2675
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002676void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002677{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002678 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 +00002679 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002680
Geoff Langbfdea662014-07-23 14:16:32 -04002681 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002682 {
Geoff Langbfdea662014-07-23 14:16:32 -04002683 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002684 }
Geoff Langbfdea662014-07-23 14:16:32 -04002685
2686 gl::Context *context = gl::getNonLostContext();
2687
2688 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002689 {
Geoff Langbfdea662014-07-23 14:16:32 -04002690 gl::Shader *shaderObject = context->getShader(shader);
2691
2692 if (!shaderObject)
2693 {
2694 return gl::error(GL_INVALID_OPERATION);
2695 }
2696
2697 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002698 }
2699}
2700
zmo@google.coma574f782011-10-03 21:45:23 +00002701void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2702{
2703 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2704 shader, bufsize, length, source);
2705
Geoff Langbfdea662014-07-23 14:16:32 -04002706 if (bufsize < 0)
zmo@google.coma574f782011-10-03 21:45:23 +00002707 {
Geoff Langbfdea662014-07-23 14:16:32 -04002708 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00002709 }
Geoff Langbfdea662014-07-23 14:16:32 -04002710
2711 gl::Context *context = gl::getNonLostContext();
2712
2713 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002714 {
Geoff Langbfdea662014-07-23 14:16:32 -04002715 gl::Shader *shaderObject = context->getShader(shader);
2716
2717 if (!shaderObject)
2718 {
2719 return gl::error(GL_INVALID_OPERATION);
2720 }
2721
2722 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002723 }
2724}
2725
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726const GLubyte* __stdcall glGetString(GLenum name)
2727{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002728 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002729
Geoff Langbfdea662014-07-23 14:16:32 -04002730 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002731
Geoff Langbfdea662014-07-23 14:16:32 -04002732 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002733 {
Geoff Langbfdea662014-07-23 14:16:32 -04002734 case GL_VENDOR:
2735 return (GLubyte*)"Google Inc.";
2736 case GL_RENDERER:
2737 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
2738 case GL_VERSION:
2739 if (context->getClientVersion() == 2)
2740 {
2741 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2742 }
2743 else
2744 {
2745 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2746 }
2747 case GL_SHADING_LANGUAGE_VERSION:
2748 if (context->getClientVersion() == 2)
2749 {
2750 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2751 }
2752 else
2753 {
2754 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2755 }
2756 case GL_EXTENSIONS:
2757 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
2758 default:
2759 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002760 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002761}
2762
2763void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2764{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002765 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 +00002766
Geoff Langbfdea662014-07-23 14:16:32 -04002767 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002768
Geoff Langbfdea662014-07-23 14:16:32 -04002769 if (context)
2770 {
2771 gl::Texture *texture = context->getTargetTexture(target);
2772
2773 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002774 {
Geoff Langbfdea662014-07-23 14:16:32 -04002775 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002776 }
Geoff Langbfdea662014-07-23 14:16:32 -04002777
2778 switch (pname)
2779 {
2780 case GL_TEXTURE_MAG_FILTER:
2781 *params = (GLfloat)texture->getSamplerState().magFilter;
2782 break;
2783 case GL_TEXTURE_MIN_FILTER:
2784 *params = (GLfloat)texture->getSamplerState().minFilter;
2785 break;
2786 case GL_TEXTURE_WRAP_S:
2787 *params = (GLfloat)texture->getSamplerState().wrapS;
2788 break;
2789 case GL_TEXTURE_WRAP_T:
2790 *params = (GLfloat)texture->getSamplerState().wrapT;
2791 break;
2792 case GL_TEXTURE_WRAP_R:
2793 if (context->getClientVersion() < 3)
2794 {
2795 return gl::error(GL_INVALID_ENUM);
2796 }
2797 *params = (GLfloat)texture->getSamplerState().wrapR;
2798 break;
2799 case GL_TEXTURE_IMMUTABLE_FORMAT:
2800 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2801 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2802 break;
2803 case GL_TEXTURE_IMMUTABLE_LEVELS:
2804 if (context->getClientVersion() < 3)
2805 {
2806 return gl::error(GL_INVALID_ENUM);
2807 }
2808 *params = (GLfloat)texture->immutableLevelCount();
2809 break;
2810 case GL_TEXTURE_USAGE_ANGLE:
2811 *params = (GLfloat)texture->getUsage();
2812 break;
2813 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2814 if (!context->getExtensions().textureFilterAnisotropic)
2815 {
2816 return gl::error(GL_INVALID_ENUM);
2817 }
2818 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2819 break;
2820 case GL_TEXTURE_SWIZZLE_R:
2821 if (context->getClientVersion() < 3)
2822 {
2823 return gl::error(GL_INVALID_ENUM);
2824 }
2825 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2826 break;
2827 case GL_TEXTURE_SWIZZLE_G:
2828 if (context->getClientVersion() < 3)
2829 {
2830 return gl::error(GL_INVALID_ENUM);
2831 }
2832 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2833 break;
2834 case GL_TEXTURE_SWIZZLE_B:
2835 if (context->getClientVersion() < 3)
2836 {
2837 return gl::error(GL_INVALID_ENUM);
2838 }
2839 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2840 break;
2841 case GL_TEXTURE_SWIZZLE_A:
2842 if (context->getClientVersion() < 3)
2843 {
2844 return gl::error(GL_INVALID_ENUM);
2845 }
2846 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2847 break;
2848 case GL_TEXTURE_BASE_LEVEL:
2849 if (context->getClientVersion() < 3)
2850 {
2851 return gl::error(GL_INVALID_ENUM);
2852 }
2853 *params = (GLfloat)texture->getSamplerState().baseLevel;
2854 break;
2855 case GL_TEXTURE_MAX_LEVEL:
2856 if (context->getClientVersion() < 3)
2857 {
2858 return gl::error(GL_INVALID_ENUM);
2859 }
2860 *params = (GLfloat)texture->getSamplerState().maxLevel;
2861 break;
2862 case GL_TEXTURE_MIN_LOD:
2863 if (context->getClientVersion() < 3)
2864 {
2865 return gl::error(GL_INVALID_ENUM);
2866 }
2867 *params = texture->getSamplerState().minLod;
2868 break;
2869 case GL_TEXTURE_MAX_LOD:
2870 if (context->getClientVersion() < 3)
2871 {
2872 return gl::error(GL_INVALID_ENUM);
2873 }
2874 *params = texture->getSamplerState().maxLod;
2875 break;
2876 default:
2877 return gl::error(GL_INVALID_ENUM);
2878 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002879 }
2880}
2881
2882void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
2883{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002884 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 +00002885
Geoff Langbfdea662014-07-23 14:16:32 -04002886 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002887
Geoff Langbfdea662014-07-23 14:16:32 -04002888 if (context)
2889 {
2890 gl::Texture *texture = context->getTargetTexture(target);
2891
2892 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002893 {
Geoff Langbfdea662014-07-23 14:16:32 -04002894 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002895 }
Geoff Langbfdea662014-07-23 14:16:32 -04002896
2897 switch (pname)
2898 {
2899 case GL_TEXTURE_MAG_FILTER:
2900 *params = texture->getSamplerState().magFilter;
2901 break;
2902 case GL_TEXTURE_MIN_FILTER:
2903 *params = texture->getSamplerState().minFilter;
2904 break;
2905 case GL_TEXTURE_WRAP_S:
2906 *params = texture->getSamplerState().wrapS;
2907 break;
2908 case GL_TEXTURE_WRAP_T:
2909 *params = texture->getSamplerState().wrapT;
2910 break;
2911 case GL_TEXTURE_WRAP_R:
2912 if (context->getClientVersion() < 3)
2913 {
2914 return gl::error(GL_INVALID_ENUM);
2915 }
2916 *params = texture->getSamplerState().wrapR;
2917 break;
2918 case GL_TEXTURE_IMMUTABLE_FORMAT:
2919 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2920 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
2921 break;
2922 case GL_TEXTURE_IMMUTABLE_LEVELS:
2923 if (context->getClientVersion() < 3)
2924 {
2925 return gl::error(GL_INVALID_ENUM);
2926 }
2927 *params = texture->immutableLevelCount();
2928 break;
2929 case GL_TEXTURE_USAGE_ANGLE:
2930 *params = texture->getUsage();
2931 break;
2932 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2933 if (!context->getExtensions().textureFilterAnisotropic)
2934 {
2935 return gl::error(GL_INVALID_ENUM);
2936 }
2937 *params = (GLint)texture->getSamplerState().maxAnisotropy;
2938 break;
2939 case GL_TEXTURE_SWIZZLE_R:
2940 if (context->getClientVersion() < 3)
2941 {
2942 return gl::error(GL_INVALID_ENUM);
2943 }
2944 *params = texture->getSamplerState().swizzleRed;
2945 break;
2946 case GL_TEXTURE_SWIZZLE_G:
2947 if (context->getClientVersion() < 3)
2948 {
2949 return gl::error(GL_INVALID_ENUM);
2950 }
2951 *params = texture->getSamplerState().swizzleGreen;
2952 break;
2953 case GL_TEXTURE_SWIZZLE_B:
2954 if (context->getClientVersion() < 3)
2955 {
2956 return gl::error(GL_INVALID_ENUM);
2957 }
2958 *params = texture->getSamplerState().swizzleBlue;
2959 break;
2960 case GL_TEXTURE_SWIZZLE_A:
2961 if (context->getClientVersion() < 3)
2962 {
2963 return gl::error(GL_INVALID_ENUM);
2964 }
2965 *params = texture->getSamplerState().swizzleAlpha;
2966 break;
2967 case GL_TEXTURE_BASE_LEVEL:
2968 if (context->getClientVersion() < 3)
2969 {
2970 return gl::error(GL_INVALID_ENUM);
2971 }
2972 *params = texture->getSamplerState().baseLevel;
2973 break;
2974 case GL_TEXTURE_MAX_LEVEL:
2975 if (context->getClientVersion() < 3)
2976 {
2977 return gl::error(GL_INVALID_ENUM);
2978 }
2979 *params = texture->getSamplerState().maxLevel;
2980 break;
2981 case GL_TEXTURE_MIN_LOD:
2982 if (context->getClientVersion() < 3)
2983 {
2984 return gl::error(GL_INVALID_ENUM);
2985 }
2986 *params = (GLint)texture->getSamplerState().minLod;
2987 break;
2988 case GL_TEXTURE_MAX_LOD:
2989 if (context->getClientVersion() < 3)
2990 {
2991 return gl::error(GL_INVALID_ENUM);
2992 }
2993 *params = (GLint)texture->getSamplerState().maxLod;
2994 break;
2995 default:
2996 return gl::error(GL_INVALID_ENUM);
2997 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002998 }
2999}
3000
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003001void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3002{
3003 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3004 program, location, bufSize, params);
3005
Geoff Langbfdea662014-07-23 14:16:32 -04003006 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003007 {
Geoff Langbfdea662014-07-23 14:16:32 -04003008 return gl::error(GL_INVALID_VALUE);
3009 }
3010
3011 gl::Context *context = gl::getNonLostContext();
3012
3013 if (context)
3014 {
3015 if (program == 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003016 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003017 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003018 }
3019
Geoff Langbfdea662014-07-23 14:16:32 -04003020 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003021
Geoff Langbfdea662014-07-23 14:16:32 -04003022 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003023 {
Geoff Langbfdea662014-07-23 14:16:32 -04003024 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003025 }
Geoff Langbfdea662014-07-23 14:16:32 -04003026
3027 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3028 if (!programBinary)
3029 {
3030 return gl::error(GL_INVALID_OPERATION);
3031 }
3032
3033 if (!programBinary->getUniformfv(location, &bufSize, params))
3034 {
3035 return gl::error(GL_INVALID_OPERATION);
3036 }
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003037 }
3038}
3039
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003040void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3041{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003042 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003043
Geoff Langbfdea662014-07-23 14:16:32 -04003044 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003045
Geoff Langbfdea662014-07-23 14:16:32 -04003046 if (context)
3047 {
3048 if (program == 0)
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003049 {
Geoff Langbfdea662014-07-23 14:16:32 -04003050 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003051 }
Geoff Langbfdea662014-07-23 14:16:32 -04003052
3053 gl::Program *programObject = context->getProgram(program);
3054
3055 if (!programObject || !programObject->isLinked())
3056 {
3057 return gl::error(GL_INVALID_OPERATION);
3058 }
3059
3060 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3061 if (!programBinary)
3062 {
3063 return gl::error(GL_INVALID_OPERATION);
3064 }
3065
3066 if (!programBinary->getUniformfv(location, NULL, params))
3067 {
3068 return gl::error(GL_INVALID_OPERATION);
3069 }
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003070 }
3071}
3072
3073void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3074{
Geoff Langbfdea662014-07-23 14:16:32 -04003075 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003076 program, location, bufSize, params);
3077
Geoff Langbfdea662014-07-23 14:16:32 -04003078 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003079 {
Geoff Langbfdea662014-07-23 14:16:32 -04003080 return gl::error(GL_INVALID_VALUE);
3081 }
3082
3083 gl::Context *context = gl::getNonLostContext();
3084
3085 if (context)
3086 {
3087 if (program == 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003089 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003090 }
3091
Geoff Langbfdea662014-07-23 14:16:32 -04003092 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003093
Geoff Langbfdea662014-07-23 14:16:32 -04003094 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003095 {
Geoff Langbfdea662014-07-23 14:16:32 -04003096 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003097 }
Geoff Langbfdea662014-07-23 14:16:32 -04003098
3099 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3100 if (!programBinary)
3101 {
3102 return gl::error(GL_INVALID_OPERATION);
3103 }
3104
3105 if (!programBinary->getUniformiv(location, &bufSize, params))
3106 {
3107 return gl::error(GL_INVALID_OPERATION);
3108 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003109 }
3110}
3111
3112void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3113{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003114 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115
Geoff Langbfdea662014-07-23 14:16:32 -04003116 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003117
Geoff Langbfdea662014-07-23 14:16:32 -04003118 if (context)
3119 {
3120 if (program == 0)
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003121 {
Geoff Langbfdea662014-07-23 14:16:32 -04003122 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003123 }
Geoff Langbfdea662014-07-23 14:16:32 -04003124
3125 gl::Program *programObject = context->getProgram(program);
3126
3127 if (!programObject || !programObject->isLinked())
3128 {
3129 return gl::error(GL_INVALID_OPERATION);
3130 }
3131
3132 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3133 if (!programBinary)
3134 {
3135 return gl::error(GL_INVALID_OPERATION);
3136 }
3137
3138 if (!programBinary->getUniformiv(location, NULL, params))
3139 {
3140 return gl::error(GL_INVALID_OPERATION);
3141 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003142 }
3143}
3144
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003145int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003146{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003147 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148
Geoff Langbfdea662014-07-23 14:16:32 -04003149 gl::Context *context = gl::getNonLostContext();
3150
3151 if (strstr(name, "gl_") == name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003152 {
Geoff Langbfdea662014-07-23 14:16:32 -04003153 return -1;
3154 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003155
Geoff Langbfdea662014-07-23 14:16:32 -04003156 if (context)
3157 {
3158 gl::Program *programObject = context->getProgram(program);
3159
3160 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003161 {
Geoff Langbfdea662014-07-23 14:16:32 -04003162 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003164 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003165 }
Geoff Langbfdea662014-07-23 14:16:32 -04003166 else
3167 {
3168 return gl::error(GL_INVALID_VALUE, -1);
3169 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003170 }
Geoff Langbfdea662014-07-23 14:16:32 -04003171
3172 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3173 if (!programObject->isLinked() || !programBinary)
3174 {
3175 return gl::error(GL_INVALID_OPERATION, -1);
3176 }
3177
3178 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003179 }
3180
3181 return -1;
3182}
3183
3184void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3185{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003186 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187
Geoff Langbfdea662014-07-23 14:16:32 -04003188 gl::Context *context = gl::getNonLostContext();
3189
3190 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003191 {
Geoff Langbfdea662014-07-23 14:16:32 -04003192 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003193 {
Geoff Langbfdea662014-07-23 14:16:32 -04003194 return gl::error(GL_INVALID_VALUE);
3195 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003196
Geoff Langbfdea662014-07-23 14:16:32 -04003197 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
3198 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3199 {
3200 return;
3201 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003202
Geoff Langbfdea662014-07-23 14:16:32 -04003203 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3204 {
3205 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3206 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003207 {
Geoff Langbfdea662014-07-23 14:16:32 -04003208 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003209 }
3210 }
Geoff Langbfdea662014-07-23 14:16:32 -04003211 else
3212 {
3213 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3214 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003215 }
3216}
3217
3218void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3219{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003220 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003221
Geoff Langbfdea662014-07-23 14:16:32 -04003222 gl::Context *context = gl::getNonLostContext();
3223
3224 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003225 {
Geoff Langbfdea662014-07-23 14:16:32 -04003226 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003227 {
Geoff Langbfdea662014-07-23 14:16:32 -04003228 return gl::error(GL_INVALID_VALUE);
3229 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003230
Geoff Langbfdea662014-07-23 14:16:32 -04003231 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003232
Geoff Langbfdea662014-07-23 14:16:32 -04003233 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3234 {
3235 return;
3236 }
Jamie Madillaff71502013-07-02 11:57:05 -04003237
Geoff Langbfdea662014-07-23 14:16:32 -04003238 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3239 {
3240 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3241 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003242 {
Geoff Langbfdea662014-07-23 14:16:32 -04003243 float currentValue = currentValueData.FloatValues[i];
3244 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003245 }
3246 }
Geoff Langbfdea662014-07-23 14:16:32 -04003247 else
3248 {
3249 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3250 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003251 }
3252}
3253
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003254void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003255{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003256 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
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)
3261 {
3262 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003263 {
Geoff Langbfdea662014-07-23 14:16:32 -04003264 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003265 }
Geoff Langbfdea662014-07-23 14:16:32 -04003266
3267 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3268 {
3269 return gl::error(GL_INVALID_ENUM);
3270 }
3271
3272 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003273 }
3274}
3275
3276void __stdcall glHint(GLenum target, GLenum mode)
3277{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003278 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003279
Geoff Langbfdea662014-07-23 14:16:32 -04003280 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003281 {
Geoff Langbfdea662014-07-23 14:16:32 -04003282 case GL_FASTEST:
3283 case GL_NICEST:
3284 case GL_DONT_CARE:
3285 break;
3286 default:
3287 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003288 }
Geoff Langbfdea662014-07-23 14:16:32 -04003289
3290 gl::Context *context = gl::getNonLostContext();
3291 switch (target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003292 {
Geoff Langbfdea662014-07-23 14:16:32 -04003293 case GL_GENERATE_MIPMAP_HINT:
3294 if (context) context->getState().setGenerateMipmapHint(mode);
3295 break;
3296 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3297 if (context) context->getState().setFragmentShaderDerivativeHint(mode);
3298 break;
3299 default:
3300 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003301 }
3302}
3303
3304GLboolean __stdcall glIsBuffer(GLuint buffer)
3305{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003306 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003307
Geoff Langbfdea662014-07-23 14:16:32 -04003308 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003309
Geoff Langbfdea662014-07-23 14:16:32 -04003310 if (context && buffer)
3311 {
3312 gl::Buffer *bufferObject = context->getBuffer(buffer);
3313
3314 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003315 {
Geoff Langbfdea662014-07-23 14:16:32 -04003316 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003317 }
3318 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003319
3320 return GL_FALSE;
3321}
3322
3323GLboolean __stdcall glIsEnabled(GLenum cap)
3324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003325 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003326
Geoff Langbfdea662014-07-23 14:16:32 -04003327 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
Geoff Langbfdea662014-07-23 14:16:32 -04003329 if (context)
3330 {
3331 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003332 {
Geoff Langbfdea662014-07-23 14:16:32 -04003333 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334 }
Geoff Langbfdea662014-07-23 14:16:32 -04003335
3336 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003337 }
3338
3339 return false;
3340}
3341
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003342GLboolean __stdcall glIsFenceNV(GLuint fence)
3343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003344 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003345
Geoff Langbfdea662014-07-23 14:16:32 -04003346 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003347
Geoff Langbfdea662014-07-23 14:16:32 -04003348 if (context)
3349 {
3350 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3351
3352 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003353 {
Geoff Langbfdea662014-07-23 14:16:32 -04003354 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003355 }
Geoff Langbfdea662014-07-23 14:16:32 -04003356
3357 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003358 }
3359
3360 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003361}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003362
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003363GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3364{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003365 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003366
Geoff Langbfdea662014-07-23 14:16:32 -04003367 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003368
Geoff Langbfdea662014-07-23 14:16:32 -04003369 if (context && framebuffer)
3370 {
3371 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3372
3373 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003374 {
Geoff Langbfdea662014-07-23 14:16:32 -04003375 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003376 }
3377 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003378
3379 return GL_FALSE;
3380}
3381
3382GLboolean __stdcall glIsProgram(GLuint program)
3383{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003384 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003385
Geoff Langbfdea662014-07-23 14:16:32 -04003386 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003387
Geoff Langbfdea662014-07-23 14:16:32 -04003388 if (context && program)
3389 {
3390 gl::Program *programObject = context->getProgram(program);
3391
3392 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003393 {
Geoff Langbfdea662014-07-23 14:16:32 -04003394 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003395 }
3396 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397
3398 return GL_FALSE;
3399}
3400
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003401GLboolean __stdcall glIsQueryEXT(GLuint id)
3402{
3403 EVENT("(GLuint id = %d)", id);
3404
Geoff Langbfdea662014-07-23 14:16:32 -04003405 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003406
Geoff Langbfdea662014-07-23 14:16:32 -04003407 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003408 {
Geoff Langbfdea662014-07-23 14:16:32 -04003409 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003410 }
3411
3412 return GL_FALSE;
3413}
3414
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3416{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003417 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418
Geoff Langbfdea662014-07-23 14:16:32 -04003419 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003420
Geoff Langbfdea662014-07-23 14:16:32 -04003421 if (context && renderbuffer)
3422 {
3423 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3424
3425 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003426 {
Geoff Langbfdea662014-07-23 14:16:32 -04003427 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428 }
3429 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003430
3431 return GL_FALSE;
3432}
3433
3434GLboolean __stdcall glIsShader(GLuint shader)
3435{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003436 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003437
Geoff Langbfdea662014-07-23 14:16:32 -04003438 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003439
Geoff Langbfdea662014-07-23 14:16:32 -04003440 if (context && shader)
3441 {
3442 gl::Shader *shaderObject = context->getShader(shader);
3443
3444 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003445 {
Geoff Langbfdea662014-07-23 14:16:32 -04003446 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003447 }
3448 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449
3450 return GL_FALSE;
3451}
3452
3453GLboolean __stdcall glIsTexture(GLuint texture)
3454{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003455 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003456
Geoff Langbfdea662014-07-23 14:16:32 -04003457 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003458
Geoff Langbfdea662014-07-23 14:16:32 -04003459 if (context && texture)
3460 {
3461 gl::Texture *textureObject = context->getTexture(texture);
3462
3463 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003464 {
Geoff Langbfdea662014-07-23 14:16:32 -04003465 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466 }
3467 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468
3469 return GL_FALSE;
3470}
3471
3472void __stdcall glLineWidth(GLfloat width)
3473{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003474 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003475
Geoff Langbfdea662014-07-23 14:16:32 -04003476 if (width <= 0.0f)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003477 {
Geoff Langbfdea662014-07-23 14:16:32 -04003478 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003479 }
Geoff Langbfdea662014-07-23 14:16:32 -04003480
3481 gl::Context *context = gl::getNonLostContext();
3482
3483 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003484 {
Geoff Langbfdea662014-07-23 14:16:32 -04003485 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003486 }
3487}
3488
3489void __stdcall glLinkProgram(GLuint program)
3490{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003491 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003492
Geoff Langbfdea662014-07-23 14:16:32 -04003493 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494
Geoff Langbfdea662014-07-23 14:16:32 -04003495 if (context)
3496 {
3497 gl::Program *programObject = context->getProgram(program);
3498
3499 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003500 {
Geoff Langbfdea662014-07-23 14:16:32 -04003501 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502 {
Geoff Langbfdea662014-07-23 14:16:32 -04003503 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003504 }
Geoff Langbfdea662014-07-23 14:16:32 -04003505 else
3506 {
3507 return gl::error(GL_INVALID_VALUE);
3508 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003509 }
Geoff Langbfdea662014-07-23 14:16:32 -04003510
3511 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003512 }
3513}
3514
3515void __stdcall glPixelStorei(GLenum pname, GLint param)
3516{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003517 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003518
Geoff Langbfdea662014-07-23 14:16:32 -04003519 gl::Context *context = gl::getNonLostContext();
3520
3521 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003522 {
Geoff Langbfdea662014-07-23 14:16:32 -04003523 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003524 {
Geoff Langbfdea662014-07-23 14:16:32 -04003525 case GL_UNPACK_ALIGNMENT:
3526 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003527 {
Geoff Langbfdea662014-07-23 14:16:32 -04003528 return gl::error(GL_INVALID_VALUE);
3529 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003530
Geoff Langbfdea662014-07-23 14:16:32 -04003531 context->getState().setUnpackAlignment(param);
3532 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003533
Geoff Langbfdea662014-07-23 14:16:32 -04003534 case GL_PACK_ALIGNMENT:
3535 if (param != 1 && param != 2 && param != 4 && param != 8)
3536 {
3537 return gl::error(GL_INVALID_VALUE);
3538 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003539
Geoff Langbfdea662014-07-23 14:16:32 -04003540 context->getState().setPackAlignment(param);
3541 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003542
Geoff Langbfdea662014-07-23 14:16:32 -04003543 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3544 context->getState().setPackReverseRowOrder(param != 0);
3545 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003546
Geoff Langbfdea662014-07-23 14:16:32 -04003547 case GL_UNPACK_IMAGE_HEIGHT:
3548 case GL_UNPACK_SKIP_IMAGES:
3549 case GL_UNPACK_ROW_LENGTH:
3550 case GL_UNPACK_SKIP_ROWS:
3551 case GL_UNPACK_SKIP_PIXELS:
3552 case GL_PACK_ROW_LENGTH:
3553 case GL_PACK_SKIP_ROWS:
3554 case GL_PACK_SKIP_PIXELS:
3555 if (context->getClientVersion() < 3)
3556 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003557 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003558 }
Geoff Langbfdea662014-07-23 14:16:32 -04003559 UNIMPLEMENTED();
3560 break;
3561
3562 default:
3563 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003564 }
3565 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003566}
3567
3568void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3569{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003570 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571
Geoff Langbfdea662014-07-23 14:16:32 -04003572 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00003573
Geoff Langbfdea662014-07-23 14:16:32 -04003574 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003575 {
Geoff Langbfdea662014-07-23 14:16:32 -04003576 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003577 }
3578}
3579
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003580void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3581 GLenum format, GLenum type, GLsizei bufSize,
3582 GLvoid *data)
3583{
3584 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3585 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3586 x, y, width, height, format, type, bufSize, data);
3587
Geoff Langbfdea662014-07-23 14:16:32 -04003588 if (width < 0 || height < 0 || bufSize < 0)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003589 {
Geoff Langbfdea662014-07-23 14:16:32 -04003590 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003591 }
Geoff Langbfdea662014-07-23 14:16:32 -04003592
3593 gl::Context *context = gl::getNonLostContext();
3594
3595 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003596 {
Geoff Langbfdea662014-07-23 14:16:32 -04003597 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3598 format, type, &bufSize, data))
3599 {
3600 return;
3601 }
3602
3603 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003604 }
3605}
3606
3607void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3608 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003609{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003610 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003611 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003612 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003613
Geoff Langbfdea662014-07-23 14:16:32 -04003614 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003615 {
Geoff Langbfdea662014-07-23 14:16:32 -04003616 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617 }
Geoff Langbfdea662014-07-23 14:16:32 -04003618
3619 gl::Context *context = gl::getNonLostContext();
3620
3621 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003622 {
Geoff Langbfdea662014-07-23 14:16:32 -04003623 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3624 format, type, NULL, pixels))
3625 {
3626 return;
3627 }
3628
3629 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003630 }
3631}
3632
3633void __stdcall glReleaseShaderCompiler(void)
3634{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003635 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003636
Geoff Langbfdea662014-07-23 14:16:32 -04003637 gl::Shader::releaseCompiler();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003638}
3639
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003640void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003641{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003642 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 +00003643 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003644
Geoff Langbfdea662014-07-23 14:16:32 -04003645 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003646
Geoff Langbfdea662014-07-23 14:16:32 -04003647 if (context)
3648 {
3649 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3650 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003651 {
Geoff Langbfdea662014-07-23 14:16:32 -04003652 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003653 }
Geoff Langbfdea662014-07-23 14:16:32 -04003654
3655 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003656 }
3657}
3658
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003659void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3660{
3661 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3662}
3663
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3665{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003666 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003667
Geoff Langbfdea662014-07-23 14:16:32 -04003668 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003669
Geoff Langbfdea662014-07-23 14:16:32 -04003670 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003671 {
Geoff Langbfdea662014-07-23 14:16:32 -04003672 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003673 }
3674}
3675
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003676void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3677{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003678 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003679
Geoff Langbfdea662014-07-23 14:16:32 -04003680 if (condition != GL_ALL_COMPLETED_NV)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003681 {
Geoff Langbfdea662014-07-23 14:16:32 -04003682 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003683 }
Geoff Langbfdea662014-07-23 14:16:32 -04003684
3685 gl::Context *context = gl::getNonLostContext();
3686
3687 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003688 {
Geoff Langbfdea662014-07-23 14:16:32 -04003689 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3690
3691 if (fenceObject == NULL)
3692 {
3693 return gl::error(GL_INVALID_OPERATION);
3694 }
3695
3696 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003697 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003698}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003699
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003700void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3701{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003702 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 +00003703
Geoff Langbfdea662014-07-23 14:16:32 -04003704 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003705 {
Geoff Langbfdea662014-07-23 14:16:32 -04003706 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003707 }
Geoff Langbfdea662014-07-23 14:16:32 -04003708
3709 gl::Context* context = gl::getNonLostContext();
3710
3711 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003712 {
Geoff Langbfdea662014-07-23 14:16:32 -04003713 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003714 }
3715}
3716
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003717void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003718{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003719 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003720 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003721 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003722
Geoff Langbfdea662014-07-23 14:16:32 -04003723 // No binary shader formats are supported.
3724 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003725}
3726
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003727void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003728{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003729 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 +00003730 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003731
Geoff Langbfdea662014-07-23 14:16:32 -04003732 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733 {
Geoff Langbfdea662014-07-23 14:16:32 -04003734 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003735 }
Geoff Langbfdea662014-07-23 14:16:32 -04003736
3737 gl::Context *context = gl::getNonLostContext();
3738
3739 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003740 {
Geoff Langbfdea662014-07-23 14:16:32 -04003741 gl::Shader *shaderObject = context->getShader(shader);
3742
3743 if (!shaderObject)
3744 {
3745 if (context->getProgram(shader))
3746 {
3747 return gl::error(GL_INVALID_OPERATION);
3748 }
3749 else
3750 {
3751 return gl::error(GL_INVALID_VALUE);
3752 }
3753 }
3754
3755 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003756 }
3757}
3758
3759void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3760{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003761 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003762}
3763
3764void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3765{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003766 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 +00003767
Geoff Langbfdea662014-07-23 14:16:32 -04003768 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003769 {
Geoff Langbfdea662014-07-23 14:16:32 -04003770 case GL_FRONT:
3771 case GL_BACK:
3772 case GL_FRONT_AND_BACK:
3773 break;
3774 default:
3775 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003776 }
Geoff Langbfdea662014-07-23 14:16:32 -04003777
3778 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003779 {
Geoff Langbfdea662014-07-23 14:16:32 -04003780 case GL_NEVER:
3781 case GL_ALWAYS:
3782 case GL_LESS:
3783 case GL_LEQUAL:
3784 case GL_EQUAL:
3785 case GL_GEQUAL:
3786 case GL_GREATER:
3787 case GL_NOTEQUAL:
3788 break;
3789 default:
3790 return gl::error(GL_INVALID_ENUM);
3791 }
3792
3793 gl::Context *context = gl::getNonLostContext();
3794
3795 if (context)
3796 {
3797 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3798 {
3799 context->getState().setStencilParams(func, ref, mask);
3800 }
3801
3802 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3803 {
3804 context->getState().setStencilBackParams(func, ref, mask);
3805 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003806 }
3807}
3808
3809void __stdcall glStencilMask(GLuint mask)
3810{
3811 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3812}
3813
3814void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3815{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003816 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003817
Geoff Langbfdea662014-07-23 14:16:32 -04003818 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003819 {
Geoff Langbfdea662014-07-23 14:16:32 -04003820 case GL_FRONT:
3821 case GL_BACK:
3822 case GL_FRONT_AND_BACK:
3823 break;
3824 default:
3825 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003826 }
Geoff Langbfdea662014-07-23 14:16:32 -04003827
3828 gl::Context *context = gl::getNonLostContext();
3829
3830 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003831 {
Geoff Langbfdea662014-07-23 14:16:32 -04003832 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3833 {
3834 context->getState().setStencilWritemask(mask);
3835 }
3836
3837 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3838 {
3839 context->getState().setStencilBackWritemask(mask);
3840 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003841 }
3842}
3843
3844void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3845{
3846 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3847}
3848
3849void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3850{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003851 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 +00003852 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003853
Geoff Langbfdea662014-07-23 14:16:32 -04003854 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003855 {
Geoff Langbfdea662014-07-23 14:16:32 -04003856 case GL_FRONT:
3857 case GL_BACK:
3858 case GL_FRONT_AND_BACK:
3859 break;
3860 default:
3861 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003862 }
Geoff Langbfdea662014-07-23 14:16:32 -04003863
3864 switch (fail)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003865 {
Geoff Langbfdea662014-07-23 14:16:32 -04003866 case GL_ZERO:
3867 case GL_KEEP:
3868 case GL_REPLACE:
3869 case GL_INCR:
3870 case GL_DECR:
3871 case GL_INVERT:
3872 case GL_INCR_WRAP:
3873 case GL_DECR_WRAP:
3874 break;
3875 default:
3876 return gl::error(GL_INVALID_ENUM);
3877 }
3878
3879 switch (zfail)
3880 {
3881 case GL_ZERO:
3882 case GL_KEEP:
3883 case GL_REPLACE:
3884 case GL_INCR:
3885 case GL_DECR:
3886 case GL_INVERT:
3887 case GL_INCR_WRAP:
3888 case GL_DECR_WRAP:
3889 break;
3890 default:
3891 return gl::error(GL_INVALID_ENUM);
3892 }
3893
3894 switch (zpass)
3895 {
3896 case GL_ZERO:
3897 case GL_KEEP:
3898 case GL_REPLACE:
3899 case GL_INCR:
3900 case GL_DECR:
3901 case GL_INVERT:
3902 case GL_INCR_WRAP:
3903 case GL_DECR_WRAP:
3904 break;
3905 default:
3906 return gl::error(GL_INVALID_ENUM);
3907 }
3908
3909 gl::Context *context = gl::getNonLostContext();
3910
3911 if (context)
3912 {
3913 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3914 {
3915 context->getState().setStencilOperations(fail, zfail, zpass);
3916 }
3917
3918 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3919 {
3920 context->getState().setStencilBackOperations(fail, zfail, zpass);
3921 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003922 }
3923}
3924
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003925GLboolean __stdcall glTestFenceNV(GLuint fence)
3926{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003927 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003928
Geoff Langbfdea662014-07-23 14:16:32 -04003929 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003930
Geoff Langbfdea662014-07-23 14:16:32 -04003931 if (context)
3932 {
3933 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3934
3935 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003936 {
Geoff Langbfdea662014-07-23 14:16:32 -04003937 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003938 }
Geoff Langbfdea662014-07-23 14:16:32 -04003939
3940 if (fenceObject->isFence() != GL_TRUE)
3941 {
3942 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
3943 }
3944
3945 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003946 }
Geoff Langbfdea662014-07-23 14:16:32 -04003947
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003948 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003949}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003950
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003951void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
3952 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003953{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003954 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05003955 "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 +00003956 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003957
Geoff Langbfdea662014-07-23 14:16:32 -04003958 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003959
Geoff Langbfdea662014-07-23 14:16:32 -04003960 if (context)
3961 {
3962 if (context->getClientVersion() < 3 &&
3963 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
3964 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003965 {
Geoff Langbfdea662014-07-23 14:16:32 -04003966 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003967 }
Geoff Langbfdea662014-07-23 14:16:32 -04003968
3969 if (context->getClientVersion() >= 3 &&
3970 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
3971 0, 0, 0, width, height, 1, border, format, type, pixels))
3972 {
3973 return;
3974 }
3975
3976 switch (target)
3977 {
3978 case GL_TEXTURE_2D:
3979 {
3980 gl::Texture2D *texture = context->getTexture2D();
3981 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3982 }
3983 break;
3984 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3985 {
3986 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3987 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3988 }
3989 break;
3990 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3991 {
3992 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3993 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3994 }
3995 break;
3996 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3997 {
3998 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3999 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4000 }
4001 break;
4002 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4003 {
4004 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4005 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4006 }
4007 break;
4008 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4009 {
4010 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4011 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4012 }
4013 break;
4014 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4015 {
4016 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4017 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4018 }
4019 break;
4020 default: UNREACHABLE();
4021 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004022 }
4023}
4024
4025void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4026{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004027 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4028
Geoff Langbfdea662014-07-23 14:16:32 -04004029 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004030
Geoff Langbfdea662014-07-23 14:16:32 -04004031 if (context)
4032 {
4033 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004034 {
Geoff Langbfdea662014-07-23 14:16:32 -04004035 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004036 }
Geoff Langbfdea662014-07-23 14:16:32 -04004037
4038 gl::Texture *texture = context->getTargetTexture(target);
4039
4040 if (!texture)
4041 {
4042 return gl::error(GL_INVALID_ENUM);
4043 }
4044
4045 switch (pname)
4046 {
4047 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4048 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4049 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4050 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4051 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4052 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4053 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4054 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4055 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4056 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4057 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4058 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4059 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4060 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4061 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4062 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4063 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4064 default: UNREACHABLE(); break;
4065 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004066 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004067}
4068
4069void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4070{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004071 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004072}
4073
4074void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4075{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004076 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077
Geoff Langbfdea662014-07-23 14:16:32 -04004078 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004079
Geoff Langbfdea662014-07-23 14:16:32 -04004080 if (context)
4081 {
4082 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004083 {
Geoff Langbfdea662014-07-23 14:16:32 -04004084 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004085 }
Geoff Langbfdea662014-07-23 14:16:32 -04004086
4087 gl::Texture *texture = context->getTargetTexture(target);
4088
4089 if (!texture)
4090 {
4091 return gl::error(GL_INVALID_ENUM);
4092 }
4093
4094 switch (pname)
4095 {
4096 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4097 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4098 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4099 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4100 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4101 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4102 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4103 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4104 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4105 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4106 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4107 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4108 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4109 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4110 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4111 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4112 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4113 default: UNREACHABLE(); break;
4114 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004115 }
4116}
4117
4118void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4119{
4120 glTexParameteri(target, pname, *params);
4121}
4122
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004123void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4124{
4125 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4126 target, levels, internalformat, width, height);
4127
Geoff Langbfdea662014-07-23 14:16:32 -04004128 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004129
Geoff Langbfdea662014-07-23 14:16:32 -04004130 if (context)
4131 {
4132 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004133 {
Geoff Langbfdea662014-07-23 14:16:32 -04004134 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004135 }
Geoff Langbfdea662014-07-23 14:16:32 -04004136
4137 if (context->getClientVersion() < 3 &&
4138 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4139 {
4140 return;
4141 }
4142
4143 if (context->getClientVersion() >= 3 &&
4144 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4145 {
4146 return;
4147 }
4148
4149 switch (target)
4150 {
4151 case GL_TEXTURE_2D:
4152 {
4153 gl::Texture2D *texture2d = context->getTexture2D();
4154 texture2d->storage(levels, internalformat, width, height);
4155 }
4156 break;
4157
4158 case GL_TEXTURE_CUBE_MAP:
4159 {
4160 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4161 textureCube->storage(levels, internalformat, width);
4162 }
4163 break;
4164
4165 default:
4166 return gl::error(GL_INVALID_ENUM);
4167 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004168 }
4169}
4170
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004171void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4172 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004173{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004174 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004175 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004176 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004177 target, level, xoffset, yoffset, width, height, format, type, pixels);
4178
Geoff Langbfdea662014-07-23 14:16:32 -04004179 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004180
Geoff Langbfdea662014-07-23 14:16:32 -04004181 if (context)
4182 {
4183 if (context->getClientVersion() < 3 &&
4184 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4185 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004186 {
Geoff Langbfdea662014-07-23 14:16:32 -04004187 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004188 }
Geoff Langbfdea662014-07-23 14:16:32 -04004189
4190 if (context->getClientVersion() >= 3 &&
4191 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4192 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4193 {
4194 return;
4195 }
4196
4197 // Zero sized uploads are valid but no-ops
4198 if (width == 0 || height == 0)
4199 {
4200 return;
4201 }
4202
4203 switch (target)
4204 {
4205 case GL_TEXTURE_2D:
4206 {
4207 gl::Texture2D *texture = context->getTexture2D();
4208 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4209 }
4210 break;
4211
4212 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4213 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4214 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4215 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4216 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4217 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4218 {
4219 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4220 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4221 }
4222 break;
4223
4224 default:
4225 UNREACHABLE();
4226 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004227 }
4228}
4229
4230void __stdcall glUniform1f(GLint location, GLfloat x)
4231{
4232 glUniform1fv(location, 1, &x);
4233}
4234
4235void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4236{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004237 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004238
Geoff Langbfdea662014-07-23 14:16:32 -04004239 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004240
Geoff Langbfdea662014-07-23 14:16:32 -04004241 if (context)
4242 {
4243 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004244 {
Geoff Langbfdea662014-07-23 14:16:32 -04004245 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004246 }
Geoff Langbfdea662014-07-23 14:16:32 -04004247
4248 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4249 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004250 }
4251}
4252
4253void __stdcall glUniform1i(GLint location, GLint x)
4254{
4255 glUniform1iv(location, 1, &x);
4256}
4257
4258void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4259{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004260 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004261
Geoff Langbfdea662014-07-23 14:16:32 -04004262 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004263
Geoff Langbfdea662014-07-23 14:16:32 -04004264 if (context)
4265 {
4266 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004267 {
Geoff Langbfdea662014-07-23 14:16:32 -04004268 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004269 }
Geoff Langbfdea662014-07-23 14:16:32 -04004270
4271 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4272 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004273 }
4274}
4275
4276void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4277{
4278 GLfloat xy[2] = {x, y};
4279
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004280 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004281}
4282
4283void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4284{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004285 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004286
Geoff Langbfdea662014-07-23 14:16:32 -04004287 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004288
Geoff Langbfdea662014-07-23 14:16:32 -04004289 if (context)
4290 {
4291 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004292 {
Geoff Langbfdea662014-07-23 14:16:32 -04004293 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004294 }
Geoff Langbfdea662014-07-23 14:16:32 -04004295
4296 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4297 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004298 }
4299}
4300
4301void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4302{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004303 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004304
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004305 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004306}
4307
4308void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4309{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004310 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004311
Geoff Langbfdea662014-07-23 14:16:32 -04004312 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004313
Geoff Langbfdea662014-07-23 14:16:32 -04004314 if (context)
4315 {
4316 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004317 {
Geoff Langbfdea662014-07-23 14:16:32 -04004318 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004319 }
Geoff Langbfdea662014-07-23 14:16:32 -04004320
4321 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4322 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004323 }
4324}
4325
4326void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4327{
4328 GLfloat xyz[3] = {x, y, z};
4329
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004330 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004331}
4332
4333void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4334{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004335 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004336
Geoff Langbfdea662014-07-23 14:16:32 -04004337 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004338
Geoff Langbfdea662014-07-23 14:16:32 -04004339 if (context)
4340 {
4341 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004342 {
Geoff Langbfdea662014-07-23 14:16:32 -04004343 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004344 }
Geoff Langbfdea662014-07-23 14:16:32 -04004345
4346 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4347 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004348 }
4349}
4350
4351void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4352{
4353 GLint xyz[3] = {x, y, z};
4354
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004355 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004356}
4357
4358void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4359{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004360 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004361
Geoff Langbfdea662014-07-23 14:16:32 -04004362 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004363
Geoff Langbfdea662014-07-23 14:16:32 -04004364 if (context)
4365 {
4366 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004367 {
Geoff Langbfdea662014-07-23 14:16:32 -04004368 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004369 }
Geoff Langbfdea662014-07-23 14:16:32 -04004370
4371 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4372 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004373 }
4374}
4375
4376void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4377{
4378 GLfloat xyzw[4] = {x, y, z, w};
4379
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004380 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004381}
4382
4383void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4384{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004385 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004386
Geoff Langbfdea662014-07-23 14:16:32 -04004387 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004388
Geoff Langbfdea662014-07-23 14:16:32 -04004389 if (context)
4390 {
4391 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004392 {
Geoff Langbfdea662014-07-23 14:16:32 -04004393 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004394 }
Geoff Langbfdea662014-07-23 14:16:32 -04004395
4396 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4397 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004398 }
4399}
4400
4401void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4402{
4403 GLint xyzw[4] = {x, y, z, w};
4404
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004405 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004406}
4407
4408void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4409{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004410 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004411
Geoff Langbfdea662014-07-23 14:16:32 -04004412 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004413
Geoff Langbfdea662014-07-23 14:16:32 -04004414 if (context)
4415 {
4416 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004417 {
Geoff Langbfdea662014-07-23 14:16:32 -04004418 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004419 }
Geoff Langbfdea662014-07-23 14:16:32 -04004420
4421 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4422 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004423 }
4424}
4425
4426void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4427{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004428 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004429 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004430
Geoff Langbfdea662014-07-23 14:16:32 -04004431 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004432
Geoff Langbfdea662014-07-23 14:16:32 -04004433 if (context)
4434 {
4435 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004436 {
Geoff Langbfdea662014-07-23 14:16:32 -04004437 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438 }
Geoff Langbfdea662014-07-23 14:16:32 -04004439
4440 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4441 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442 }
4443}
4444
4445void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4446{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004447 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004448 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004449
Geoff Langbfdea662014-07-23 14:16:32 -04004450 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004451
Geoff Langbfdea662014-07-23 14:16:32 -04004452 if (context)
4453 {
4454 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004455 {
Geoff Langbfdea662014-07-23 14:16:32 -04004456 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004457 }
Geoff Langbfdea662014-07-23 14:16:32 -04004458
4459 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4460 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004461 }
4462}
4463
4464void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4465{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004466 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004467 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004468
Geoff Langbfdea662014-07-23 14:16:32 -04004469 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004470
Geoff Langbfdea662014-07-23 14:16:32 -04004471 if (context)
4472 {
4473 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004474 {
Geoff Langbfdea662014-07-23 14:16:32 -04004475 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004476 }
Geoff Langbfdea662014-07-23 14:16:32 -04004477
4478 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4479 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480 }
4481}
4482
4483void __stdcall glUseProgram(GLuint program)
4484{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004485 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004486
Geoff Langbfdea662014-07-23 14:16:32 -04004487 gl::Context *context = gl::getNonLostContext();
4488
4489 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490 {
Geoff Langbfdea662014-07-23 14:16:32 -04004491 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004492
Geoff Langbfdea662014-07-23 14:16:32 -04004493 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004494 {
Geoff Langbfdea662014-07-23 14:16:32 -04004495 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004496 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004497 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004498 }
Geoff Langbfdea662014-07-23 14:16:32 -04004499 else
4500 {
4501 return gl::error(GL_INVALID_VALUE);
4502 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004503 }
Geoff Langbfdea662014-07-23 14:16:32 -04004504
4505 if (program != 0 && !programObject->isLinked())
4506 {
4507 return gl::error(GL_INVALID_OPERATION);
4508 }
4509
4510 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004511 }
4512}
4513
4514void __stdcall glValidateProgram(GLuint program)
4515{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004516 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004517
Geoff Langbfdea662014-07-23 14:16:32 -04004518 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004519
Geoff Langbfdea662014-07-23 14:16:32 -04004520 if (context)
4521 {
4522 gl::Program *programObject = context->getProgram(program);
4523
4524 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004525 {
Geoff Langbfdea662014-07-23 14:16:32 -04004526 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004527 {
Geoff Langbfdea662014-07-23 14:16:32 -04004528 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004529 }
Geoff Langbfdea662014-07-23 14:16:32 -04004530 else
4531 {
4532 return gl::error(GL_INVALID_VALUE);
4533 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004534 }
Geoff Langbfdea662014-07-23 14:16:32 -04004535
4536 programObject->validate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004537 }
4538}
4539
4540void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4541{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004542 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543
Geoff Langbfdea662014-07-23 14:16:32 -04004544 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004545 {
Geoff Langbfdea662014-07-23 14:16:32 -04004546 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004547 }
Geoff Langbfdea662014-07-23 14:16:32 -04004548
4549 gl::Context *context = gl::getNonLostContext();
4550
4551 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004552 {
Geoff Langbfdea662014-07-23 14:16:32 -04004553 GLfloat vals[4] = { x, 0, 0, 1 };
4554 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555 }
4556}
4557
4558void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004560 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004561
Geoff Langbfdea662014-07-23 14:16:32 -04004562 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004563 {
Geoff Langbfdea662014-07-23 14:16:32 -04004564 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004565 }
Geoff Langbfdea662014-07-23 14:16:32 -04004566
4567 gl::Context *context = gl::getNonLostContext();
4568
4569 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570 {
Geoff Langbfdea662014-07-23 14:16:32 -04004571 GLfloat vals[4] = { values[0], 0, 0, 1 };
4572 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573 }
4574}
4575
4576void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4577{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004578 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004579
Geoff Langbfdea662014-07-23 14:16:32 -04004580 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004581 {
Geoff Langbfdea662014-07-23 14:16:32 -04004582 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004583 }
Geoff Langbfdea662014-07-23 14:16:32 -04004584
4585 gl::Context *context = gl::getNonLostContext();
4586
4587 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004588 {
Geoff Langbfdea662014-07-23 14:16:32 -04004589 GLfloat vals[4] = { x, y, 0, 1 };
4590 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004591 }
4592}
4593
4594void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004596 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004597
Geoff Langbfdea662014-07-23 14:16:32 -04004598 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004599 {
Geoff Langbfdea662014-07-23 14:16:32 -04004600 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004601 }
Geoff Langbfdea662014-07-23 14:16:32 -04004602
4603 gl::Context *context = gl::getNonLostContext();
4604
4605 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004606 {
Geoff Langbfdea662014-07-23 14:16:32 -04004607 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4608 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609 }
4610}
4611
4612void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4613{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004614 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 +00004615
Geoff Langbfdea662014-07-23 14:16:32 -04004616 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004617 {
Geoff Langbfdea662014-07-23 14:16:32 -04004618 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619 }
Geoff Langbfdea662014-07-23 14:16:32 -04004620
4621 gl::Context *context = gl::getNonLostContext();
4622
4623 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004624 {
Geoff Langbfdea662014-07-23 14:16:32 -04004625 GLfloat vals[4] = { x, y, z, 1 };
4626 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 }
4628}
4629
4630void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004632 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004633
Geoff Langbfdea662014-07-23 14:16:32 -04004634 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004635 {
Geoff Langbfdea662014-07-23 14:16:32 -04004636 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004637 }
Geoff Langbfdea662014-07-23 14:16:32 -04004638
4639 gl::Context *context = gl::getNonLostContext();
4640
4641 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642 {
Geoff Langbfdea662014-07-23 14:16:32 -04004643 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4644 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004645 }
4646}
4647
4648void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4649{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004650 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 +00004651
Geoff Langbfdea662014-07-23 14:16:32 -04004652 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004653 {
Geoff Langbfdea662014-07-23 14:16:32 -04004654 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004655 }
Geoff Langbfdea662014-07-23 14:16:32 -04004656
4657 gl::Context *context = gl::getNonLostContext();
4658
4659 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004660 {
Geoff Langbfdea662014-07-23 14:16:32 -04004661 GLfloat vals[4] = { x, y, z, w };
4662 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004663 }
4664}
4665
4666void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4667{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004668 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004669
Geoff Langbfdea662014-07-23 14:16:32 -04004670 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004671 {
Geoff Langbfdea662014-07-23 14:16:32 -04004672 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004673 }
Geoff Langbfdea662014-07-23 14:16:32 -04004674
4675 gl::Context *context = gl::getNonLostContext();
4676
4677 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004678 {
Geoff Langbfdea662014-07-23 14:16:32 -04004679 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004680 }
4681}
4682
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004683void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4684{
4685 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4686
Geoff Langbfdea662014-07-23 14:16:32 -04004687 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004688 {
Geoff Langbfdea662014-07-23 14:16:32 -04004689 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004690 }
Geoff Langbfdea662014-07-23 14:16:32 -04004691
4692 gl::Context *context = gl::getNonLostContext();
4693
4694 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004695 {
Geoff Langbfdea662014-07-23 14:16:32 -04004696 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004697 }
4698}
4699
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004700void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004701{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004702 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004703 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004704 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004705
Geoff Langbfdea662014-07-23 14:16:32 -04004706 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004707 {
Geoff Langbfdea662014-07-23 14:16:32 -04004708 return gl::error(GL_INVALID_VALUE);
4709 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004710
Geoff Langbfdea662014-07-23 14:16:32 -04004711 if (size < 1 || size > 4)
4712 {
4713 return gl::error(GL_INVALID_VALUE);
4714 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004715
Geoff Langbfdea662014-07-23 14:16:32 -04004716 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00004717
Geoff Langbfdea662014-07-23 14:16:32 -04004718 switch (type)
4719 {
4720 case GL_BYTE:
4721 case GL_UNSIGNED_BYTE:
4722 case GL_SHORT:
4723 case GL_UNSIGNED_SHORT:
4724 case GL_FIXED:
4725 case GL_FLOAT:
4726 break;
4727 case GL_HALF_FLOAT:
4728 case GL_INT:
4729 case GL_UNSIGNED_INT:
4730 case GL_INT_2_10_10_10_REV:
4731 case GL_UNSIGNED_INT_2_10_10_10_REV:
4732 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004734 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004735 }
Geoff Langbfdea662014-07-23 14:16:32 -04004736 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004737 {
Geoff Langbfdea662014-07-23 14:16:32 -04004738 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004739 }
Geoff Langbfdea662014-07-23 14:16:32 -04004740 default:
4741 return gl::error(GL_INVALID_ENUM);
4742 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004743
Geoff Langbfdea662014-07-23 14:16:32 -04004744 if (stride < 0)
4745 {
4746 return gl::error(GL_INVALID_VALUE);
4747 }
4748
4749 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4750 {
4751 return gl::error(GL_INVALID_OPERATION);
4752 }
4753
4754 if (context)
4755 {
4756 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4757 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4758 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4759 // and the pointer argument is not NULL.
4760 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004761 {
4762 return gl::error(GL_INVALID_OPERATION);
4763 }
4764
Geoff Langbfdea662014-07-23 14:16:32 -04004765 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4766 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004767 }
4768}
4769
4770void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4771{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004772 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 +00004773
Geoff Langbfdea662014-07-23 14:16:32 -04004774 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004775 {
Geoff Langbfdea662014-07-23 14:16:32 -04004776 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004777 }
Geoff Langbfdea662014-07-23 14:16:32 -04004778
4779 gl::Context *context = gl::getNonLostContext();
4780
4781 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004782 {
Geoff Langbfdea662014-07-23 14:16:32 -04004783 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004784 }
4785}
4786
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004787// OpenGL ES 3.0 functions
4788
4789void __stdcall glReadBuffer(GLenum mode)
4790{
4791 EVENT("(GLenum mode = 0x%X)", mode);
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);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004800 }
Geoff Langbfdea662014-07-23 14:16:32 -04004801
4802 // glReadBuffer
4803 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004804 }
4805}
4806
4807void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4808{
4809 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4810 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4811
Geoff Langbfdea662014-07-23 14:16:32 -04004812 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004813
Geoff Langbfdea662014-07-23 14:16:32 -04004814 if (context)
4815 {
4816 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004817 {
Geoff Langbfdea662014-07-23 14:16:32 -04004818 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004819 }
Geoff Langbfdea662014-07-23 14:16:32 -04004820
4821 // glDrawRangeElements
4822 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004823 }
4824}
4825
4826void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4827{
4828 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4829 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4830 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4831 target, level, internalformat, width, height, depth, border, format, type, pixels);
4832
Geoff Langbfdea662014-07-23 14:16:32 -04004833 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004834
Geoff Langbfdea662014-07-23 14:16:32 -04004835 if (context)
4836 {
4837 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004838 {
Geoff Langbfdea662014-07-23 14:16:32 -04004839 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004840 }
Geoff Langbfdea662014-07-23 14:16:32 -04004841
4842 // validateES3TexImageFormat sets the error code if there is an error
4843 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4844 0, 0, 0, width, height, depth, border, format, type, pixels))
4845 {
4846 return;
4847 }
4848
4849 switch(target)
4850 {
4851 case GL_TEXTURE_3D:
4852 {
4853 gl::Texture3D *texture = context->getTexture3D();
4854 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4855 }
4856 break;
4857
4858 case GL_TEXTURE_2D_ARRAY:
4859 {
4860 gl::Texture2DArray *texture = context->getTexture2DArray();
4861 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4862 }
4863 break;
4864
4865 default:
4866 return gl::error(GL_INVALID_ENUM);
4867 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004868 }
4869}
4870
4871void __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)
4872{
4873 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4874 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4875 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4876 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4877
Geoff Langbfdea662014-07-23 14:16:32 -04004878 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004879
Geoff Langbfdea662014-07-23 14:16:32 -04004880 if (context)
4881 {
4882 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004883 {
Geoff Langbfdea662014-07-23 14:16:32 -04004884 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004885 }
Geoff Langbfdea662014-07-23 14:16:32 -04004886
4887 // validateES3TexImageFormat sets the error code if there is an error
4888 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4889 xoffset, yoffset, zoffset, width, height, depth, 0,
4890 format, type, pixels))
4891 {
4892 return;
4893 }
4894
4895 // Zero sized uploads are valid but no-ops
4896 if (width == 0 || height == 0 || depth == 0)
4897 {
4898 return;
4899 }
4900
4901 switch(target)
4902 {
4903 case GL_TEXTURE_3D:
4904 {
4905 gl::Texture3D *texture = context->getTexture3D();
4906 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4907 }
4908 break;
4909
4910 case GL_TEXTURE_2D_ARRAY:
4911 {
4912 gl::Texture2DArray *texture = context->getTexture2DArray();
4913 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4914 }
4915 break;
4916
4917 default:
4918 return gl::error(GL_INVALID_ENUM);
4919 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004920 }
4921}
4922
4923void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
4924{
4925 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4926 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
4927 target, level, xoffset, yoffset, zoffset, x, y, width, height);
4928
Geoff Langbfdea662014-07-23 14:16:32 -04004929 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004930
Geoff Langbfdea662014-07-23 14:16:32 -04004931 if (context)
4932 {
4933 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004934 {
Geoff Langbfdea662014-07-23 14:16:32 -04004935 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004936 }
Geoff Langbfdea662014-07-23 14:16:32 -04004937
4938 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
4939 x, y, width, height, 0))
4940 {
4941 return;
4942 }
4943
4944 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
4945 gl::Texture *texture = NULL;
4946 switch (target)
4947 {
4948 case GL_TEXTURE_3D:
4949 texture = context->getTexture3D();
4950 break;
4951
4952 case GL_TEXTURE_2D_ARRAY:
4953 texture = context->getTexture2DArray();
4954 break;
4955
4956 default:
4957 return gl::error(GL_INVALID_ENUM);
4958 }
4959
4960 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004961 }
4962}
4963
4964void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
4965{
Geoff Langeef52cc2013-10-16 15:07:39 -04004966 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 +00004967 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
4968 "const GLvoid* data = 0x%0.8p)",
4969 target, level, internalformat, width, height, depth, border, imageSize, data);
4970
Geoff Langbfdea662014-07-23 14:16:32 -04004971 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004972
Geoff Langbfdea662014-07-23 14:16:32 -04004973 if (context)
4974 {
4975 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004976 {
Geoff Langbfdea662014-07-23 14:16:32 -04004977 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004978 }
Geoff Langbfdea662014-07-23 14:16:32 -04004979
Geoff Lang5d601382014-07-22 15:14:06 -04004980 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
4981 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04004982 {
4983 return gl::error(GL_INVALID_VALUE);
4984 }
4985
4986 // validateES3TexImageFormat sets the error code if there is an error
4987 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
4988 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
4989 {
4990 return;
4991 }
4992
4993 switch(target)
4994 {
4995 case GL_TEXTURE_3D:
4996 {
4997 gl::Texture3D *texture = context->getTexture3D();
4998 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
4999 }
5000 break;
5001
5002 case GL_TEXTURE_2D_ARRAY:
5003 {
5004 gl::Texture2DArray *texture = context->getTexture2DArray();
5005 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5006 }
5007 break;
5008
5009 default:
5010 return gl::error(GL_INVALID_ENUM);
5011 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005012 }
5013}
5014
5015void __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)
5016{
5017 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5018 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5019 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5020 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5021
Geoff Langbfdea662014-07-23 14:16:32 -04005022 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005023
Geoff Langbfdea662014-07-23 14:16:32 -04005024 if (context)
5025 {
5026 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005027 {
Geoff Langbfdea662014-07-23 14:16:32 -04005028 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005029 }
Geoff Langbfdea662014-07-23 14:16:32 -04005030
Geoff Lang5d601382014-07-22 15:14:06 -04005031 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5032 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005033 {
5034 return gl::error(GL_INVALID_VALUE);
5035 }
5036
5037 if (!data)
5038 {
5039 return gl::error(GL_INVALID_VALUE);
5040 }
5041
5042 // validateES3TexImageFormat sets the error code if there is an error
5043 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5044 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5045 {
5046 return;
5047 }
5048
5049 // Zero sized uploads are valid but no-ops
5050 if (width == 0 || height == 0)
5051 {
5052 return;
5053 }
5054
5055 switch(target)
5056 {
5057 case GL_TEXTURE_3D:
5058 {
5059 gl::Texture3D *texture = context->getTexture3D();
5060 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5061 format, imageSize, data);
5062 }
5063 break;
5064
5065 case GL_TEXTURE_2D_ARRAY:
5066 {
5067 gl::Texture2DArray *texture = context->getTexture2DArray();
5068 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5069 format, imageSize, data);
5070 }
5071 break;
5072
5073 default:
5074 return gl::error(GL_INVALID_ENUM);
5075 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005076 }
5077}
5078
5079void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5080{
5081 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5082
Geoff Langbfdea662014-07-23 14:16:32 -04005083 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005084
Geoff Langbfdea662014-07-23 14:16:32 -04005085 if (context)
5086 {
5087 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005088 {
Geoff Langbfdea662014-07-23 14:16:32 -04005089 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005090 }
Geoff Langbfdea662014-07-23 14:16:32 -04005091
5092 if (n < 0)
5093 {
5094 return gl::error(GL_INVALID_VALUE);
5095 }
5096
5097 for (GLsizei i = 0; i < n; i++)
5098 {
5099 ids[i] = context->createQuery();
5100 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005101 }
5102}
5103
5104void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5105{
5106 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5107
Geoff Langbfdea662014-07-23 14:16:32 -04005108 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005109
Geoff Langbfdea662014-07-23 14:16:32 -04005110 if (context)
5111 {
5112 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005113 {
Geoff Langbfdea662014-07-23 14:16:32 -04005114 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005115 }
Geoff Langbfdea662014-07-23 14:16:32 -04005116
5117 if (n < 0)
5118 {
5119 return gl::error(GL_INVALID_VALUE);
5120 }
5121
5122 for (GLsizei i = 0; i < n; i++)
5123 {
5124 context->deleteQuery(ids[i]);
5125 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005126 }
5127}
5128
5129GLboolean __stdcall glIsQuery(GLuint id)
5130{
5131 EVENT("(GLuint id = %u)", id);
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, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005140 }
Geoff Langbfdea662014-07-23 14:16:32 -04005141
5142 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005143 }
5144
5145 return GL_FALSE;
5146}
5147
5148void __stdcall glBeginQuery(GLenum target, GLuint id)
5149{
5150 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5151
Geoff Langbfdea662014-07-23 14:16:32 -04005152 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005153
Geoff Langbfdea662014-07-23 14:16:32 -04005154 if (context)
5155 {
5156 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005157 {
Geoff Langbfdea662014-07-23 14:16:32 -04005158 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005159 }
Geoff Langbfdea662014-07-23 14:16:32 -04005160
5161 if (!ValidateBeginQuery(context, target, id))
5162 {
5163 return;
5164 }
5165 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005166 }
5167}
5168
5169void __stdcall glEndQuery(GLenum target)
5170{
5171 EVENT("(GLenum target = 0x%X)", target);
5172
Geoff Langbfdea662014-07-23 14:16:32 -04005173 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005174
Geoff Langbfdea662014-07-23 14:16:32 -04005175 if (context)
5176 {
5177 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005178 {
Geoff Langbfdea662014-07-23 14:16:32 -04005179 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005180 }
Geoff Langbfdea662014-07-23 14:16:32 -04005181
5182 if (!ValidateEndQuery(context, target))
5183 {
5184 return;
5185 }
5186
5187 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005188 }
5189}
5190
5191void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5192{
5193 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5194
Geoff Langbfdea662014-07-23 14:16:32 -04005195 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005196
Geoff Langbfdea662014-07-23 14:16:32 -04005197 if (context)
5198 {
5199 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005200 {
Geoff Langbfdea662014-07-23 14:16:32 -04005201 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005202 }
Geoff Langbfdea662014-07-23 14:16:32 -04005203
5204 if (!ValidQueryType(context, target))
5205 {
5206 return gl::error(GL_INVALID_ENUM);
5207 }
5208
5209 switch (pname)
5210 {
5211 case GL_CURRENT_QUERY:
5212 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5213 break;
5214
5215 default:
5216 return gl::error(GL_INVALID_ENUM);
5217 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005218 }
5219}
5220
5221void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5222{
5223 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5224
Geoff Langbfdea662014-07-23 14:16:32 -04005225 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005226
Geoff Langbfdea662014-07-23 14:16:32 -04005227 if (context)
5228 {
5229 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005230 {
Geoff Langbfdea662014-07-23 14:16:32 -04005231 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005232 }
Geoff Langbfdea662014-07-23 14:16:32 -04005233
5234 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5235
5236 if (!queryObject)
5237 {
5238 return gl::error(GL_INVALID_OPERATION);
5239 }
5240
5241 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5242 {
5243 return gl::error(GL_INVALID_OPERATION);
5244 }
5245
5246 switch(pname)
5247 {
5248 case GL_QUERY_RESULT:
5249 params[0] = queryObject->getResult();
5250 break;
5251 case GL_QUERY_RESULT_AVAILABLE:
5252 params[0] = queryObject->isResultAvailable();
5253 break;
5254 default:
5255 return gl::error(GL_INVALID_ENUM);
5256 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005257 }
5258}
5259
5260GLboolean __stdcall glUnmapBuffer(GLenum target)
5261{
5262 EVENT("(GLenum target = 0x%X)", target);
5263
Geoff Langbfdea662014-07-23 14:16:32 -04005264 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005265
Geoff Langbfdea662014-07-23 14:16:32 -04005266 if (context)
5267 {
5268 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005269 {
Geoff Langbfdea662014-07-23 14:16:32 -04005270 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005271 }
Geoff Langbfdea662014-07-23 14:16:32 -04005272
5273 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005274 }
5275
5276 return GL_FALSE;
5277}
5278
5279void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5280{
5281 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5282
Geoff Langbfdea662014-07-23 14:16:32 -04005283 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005284
Geoff Langbfdea662014-07-23 14:16:32 -04005285 if (context)
5286 {
5287 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005288 {
Geoff Langbfdea662014-07-23 14:16:32 -04005289 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005290 }
Geoff Langbfdea662014-07-23 14:16:32 -04005291
5292 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005293 }
5294}
5295
5296void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5297{
Geoff Langbfdea662014-07-23 14:16:32 -04005298 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005299
Geoff Langbfdea662014-07-23 14:16:32 -04005300 if (context)
5301 {
5302 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005303 {
Geoff Langbfdea662014-07-23 14:16:32 -04005304 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005305 }
Geoff Langbfdea662014-07-23 14:16:32 -04005306
5307 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005308 }
5309}
5310
5311void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5312{
5313 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5314 location, count, transpose, value);
5315
Geoff Langbfdea662014-07-23 14:16:32 -04005316 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005317
Geoff Langbfdea662014-07-23 14:16:32 -04005318 if (context)
5319 {
5320 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005321 {
Geoff Langbfdea662014-07-23 14:16:32 -04005322 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005323 }
Geoff Langbfdea662014-07-23 14:16:32 -04005324
5325 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5326 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005327 }
5328}
5329
5330void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5331{
5332 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5333 location, count, transpose, value);
5334
Geoff Langbfdea662014-07-23 14:16:32 -04005335 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005336
Geoff Langbfdea662014-07-23 14:16:32 -04005337 if (context)
5338 {
5339 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005340 {
Geoff Langbfdea662014-07-23 14:16:32 -04005341 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005342 }
Geoff Langbfdea662014-07-23 14:16:32 -04005343
5344 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5345 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005346 }
5347}
5348
5349void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5350{
5351 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5352 location, count, transpose, value);
5353
Geoff Langbfdea662014-07-23 14:16:32 -04005354 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005355
Geoff Langbfdea662014-07-23 14:16:32 -04005356 if (context)
5357 {
5358 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005359 {
Geoff Langbfdea662014-07-23 14:16:32 -04005360 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005361 }
Geoff Langbfdea662014-07-23 14:16:32 -04005362
5363 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5364 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005365 }
5366}
5367
5368void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5369{
5370 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5371 location, count, transpose, value);
5372
Geoff Langbfdea662014-07-23 14:16:32 -04005373 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005374
Geoff Langbfdea662014-07-23 14:16:32 -04005375 if (context)
5376 {
5377 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005378 {
Geoff Langbfdea662014-07-23 14:16:32 -04005379 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005380 }
Geoff Langbfdea662014-07-23 14:16:32 -04005381
5382 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5383 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005384 }
5385}
5386
5387void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5388{
5389 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5390 location, count, transpose, value);
5391
Geoff Langbfdea662014-07-23 14:16:32 -04005392 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005393
Geoff Langbfdea662014-07-23 14:16:32 -04005394 if (context)
5395 {
5396 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005397 {
Geoff Langbfdea662014-07-23 14:16:32 -04005398 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005399 }
Geoff Langbfdea662014-07-23 14:16:32 -04005400
5401 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5402 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005403 }
5404}
5405
5406void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5407{
5408 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5409 location, count, transpose, value);
5410
Geoff Langbfdea662014-07-23 14:16:32 -04005411 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005412
Geoff Langbfdea662014-07-23 14:16:32 -04005413 if (context)
5414 {
5415 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005416 {
Geoff Langbfdea662014-07-23 14:16:32 -04005417 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005418 }
Geoff Langbfdea662014-07-23 14:16:32 -04005419
5420 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5421 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005422 }
5423}
5424
5425void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5426{
5427 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5428 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5429 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5430
Geoff Langbfdea662014-07-23 14:16:32 -04005431 gl::Context *context = gl::getNonLostContext();
5432 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005433 {
Geoff Langbfdea662014-07-23 14:16:32 -04005434 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005435 {
Geoff Langbfdea662014-07-23 14:16:32 -04005436 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005437 }
Geoff Langbfdea662014-07-23 14:16:32 -04005438
5439 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5440 dstX0, dstY0, dstX1, dstY1, mask, filter,
5441 false))
5442 {
5443 return;
5444 }
5445
5446 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5447 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005448 }
5449}
5450
5451void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5452{
5453 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5454 target, samples, internalformat, width, height);
5455
Geoff Langbfdea662014-07-23 14:16:32 -04005456 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005457
Geoff Langbfdea662014-07-23 14:16:32 -04005458 if (context)
5459 {
5460 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005461 {
Geoff Langbfdea662014-07-23 14:16:32 -04005462 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005463 }
Geoff Langbfdea662014-07-23 14:16:32 -04005464
5465 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5466 width, height, false))
5467 {
5468 return;
5469 }
5470
5471 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005472 }
5473}
5474
5475void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5476{
5477 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5478 target, attachment, texture, level, layer);
5479
Geoff Langbfdea662014-07-23 14:16:32 -04005480 gl::Context *context = gl::getNonLostContext();
5481
5482 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005483 {
Geoff Langbfdea662014-07-23 14:16:32 -04005484 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5485 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005486 {
Geoff Langbfdea662014-07-23 14:16:32 -04005487 return;
5488 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005489
Geoff Langbfdea662014-07-23 14:16:32 -04005490 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5491 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005492
Geoff Langbfdea662014-07-23 14:16:32 -04005493 gl::Texture *textureObject = context->getTexture(texture);
5494 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005495
Geoff Langbfdea662014-07-23 14:16:32 -04005496 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5497 {
5498 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5499 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5500 }
5501 else
5502 {
5503 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005504 {
Geoff Langbfdea662014-07-23 14:16:32 -04005505 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5506 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5507 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005508 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005509 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005510 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005511}
5512
5513GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5514{
5515 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5516 target, offset, length, access);
5517
Geoff Langbfdea662014-07-23 14:16:32 -04005518 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005519
Geoff Langbfdea662014-07-23 14:16:32 -04005520 if (context)
5521 {
5522 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005523 {
Geoff Langbfdea662014-07-23 14:16:32 -04005524 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005525 }
Geoff Langbfdea662014-07-23 14:16:32 -04005526
5527 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005528 }
5529
5530 return NULL;
5531}
5532
5533void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5534{
5535 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5536
Geoff Langbfdea662014-07-23 14:16:32 -04005537 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005538
Geoff Langbfdea662014-07-23 14:16:32 -04005539 if (context)
5540 {
5541 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005542 {
Geoff Langbfdea662014-07-23 14:16:32 -04005543 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005544 }
Geoff Langbfdea662014-07-23 14:16:32 -04005545
5546 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005547 }
5548}
5549
5550void __stdcall glBindVertexArray(GLuint array)
5551{
5552 EVENT("(GLuint array = %u)", array);
5553
Geoff Langbfdea662014-07-23 14:16:32 -04005554 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005555
Geoff Langbfdea662014-07-23 14:16:32 -04005556 if (context)
5557 {
5558 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005559 {
Geoff Langbfdea662014-07-23 14:16:32 -04005560 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005561 }
Geoff Langbfdea662014-07-23 14:16:32 -04005562
5563 gl::VertexArray *vao = context->getVertexArray(array);
5564
5565 if (!vao)
5566 {
5567 // The default VAO should always exist
5568 ASSERT(array != 0);
5569 return gl::error(GL_INVALID_OPERATION);
5570 }
5571
5572 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005573 }
5574}
5575
5576void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5577{
5578 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5579
Geoff Langbfdea662014-07-23 14:16:32 -04005580 gl::Context *context = gl::getNonLostContext();
5581
5582 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005583 {
Geoff Langbfdea662014-07-23 14:16:32 -04005584 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005585 {
Geoff Langbfdea662014-07-23 14:16:32 -04005586 return gl::error(GL_INVALID_OPERATION);
5587 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005588
Geoff Langbfdea662014-07-23 14:16:32 -04005589 if (n < 0)
5590 {
5591 return gl::error(GL_INVALID_VALUE);
5592 }
Jamie Madilld1028542013-07-02 11:57:04 -04005593
Geoff Langbfdea662014-07-23 14:16:32 -04005594 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5595 {
5596 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005597 {
Geoff Langbfdea662014-07-23 14:16:32 -04005598 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005599 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005600 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005601 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005602}
5603
5604void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5605{
5606 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5607
Geoff Langbfdea662014-07-23 14:16:32 -04005608 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005609
Geoff Langbfdea662014-07-23 14:16:32 -04005610 if (context)
5611 {
5612 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005613 {
Geoff Langbfdea662014-07-23 14:16:32 -04005614 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005615 }
Geoff Langbfdea662014-07-23 14:16:32 -04005616
5617 if (n < 0)
5618 {
5619 return gl::error(GL_INVALID_VALUE);
5620 }
5621
5622 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5623 {
5624 arrays[arrayIndex] = context->createVertexArray();
5625 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005626 }
5627}
5628
5629GLboolean __stdcall glIsVertexArray(GLuint array)
5630{
5631 EVENT("(GLuint array = %u)", array);
5632
Geoff Langbfdea662014-07-23 14:16:32 -04005633 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005634
Geoff Langbfdea662014-07-23 14:16:32 -04005635 if (context)
5636 {
5637 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005638 {
Geoff Langbfdea662014-07-23 14:16:32 -04005639 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005640 }
Geoff Langbfdea662014-07-23 14:16:32 -04005641
5642 if (array == 0)
5643 {
5644 return GL_FALSE;
5645 }
5646
5647 gl::VertexArray *vao = context->getVertexArray(array);
5648
5649 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005650 }
5651
5652 return GL_FALSE;
5653}
5654
5655void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5656{
5657 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5658 target, index, data);
5659
Geoff Langbfdea662014-07-23 14:16:32 -04005660 gl::Context *context = gl::getNonLostContext();
5661
5662 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005663 {
Geoff Langbfdea662014-07-23 14:16:32 -04005664 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005665 {
Geoff Langbfdea662014-07-23 14:16:32 -04005666 return gl::error(GL_INVALID_OPERATION);
5667 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005668
Geoff Langbfdea662014-07-23 14:16:32 -04005669 switch (target)
5670 {
5671 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5672 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5673 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
5674 if (index >= context->getMaxTransformFeedbackBufferBindings())
5675 return gl::error(GL_INVALID_VALUE);
5676 break;
5677 case GL_UNIFORM_BUFFER_START:
5678 case GL_UNIFORM_BUFFER_SIZE:
5679 case GL_UNIFORM_BUFFER_BINDING:
5680 if (index >= context->getMaximumCombinedUniformBufferBindings())
5681 return gl::error(GL_INVALID_VALUE);
5682 break;
5683 default:
5684 return gl::error(GL_INVALID_ENUM);
5685 }
5686
5687 if (!(context->getIndexedIntegerv(target, index, data)))
5688 {
5689 GLenum nativeType;
5690 unsigned int numParams = 0;
5691 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04005692 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04005693
Geoff Langbfdea662014-07-23 14:16:32 -04005694 if (numParams == 0)
5695 return; // it is known that pname is valid, but there are no parameters to return
5696
5697 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005698 {
Geoff Langbfdea662014-07-23 14:16:32 -04005699 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5700 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5701 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005702
Geoff Langbfdea662014-07-23 14:16:32 -04005703 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005704
Geoff Langbfdea662014-07-23 14:16:32 -04005705 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005706 {
Geoff Langbfdea662014-07-23 14:16:32 -04005707 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5708 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005709 }
Geoff Langbfdea662014-07-23 14:16:32 -04005710
5711 delete [] int64Params;
5712 }
5713 else
5714 {
5715 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005716 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005717 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005718 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005719}
5720
5721void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5722{
5723 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5724
Geoff Langbfdea662014-07-23 14:16:32 -04005725 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005726
Geoff Langbfdea662014-07-23 14:16:32 -04005727 if (context)
5728 {
5729 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005730 {
Geoff Langbfdea662014-07-23 14:16:32 -04005731 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005732 }
Geoff Langbfdea662014-07-23 14:16:32 -04005733
5734 switch (primitiveMode)
5735 {
5736 case GL_TRIANGLES:
5737 case GL_LINES:
5738 case GL_POINTS:
5739 break;
5740 default:
5741 return gl::error(GL_INVALID_ENUM);
5742 }
5743
5744 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5745 ASSERT(transformFeedback != NULL);
5746
5747 if (transformFeedback->isStarted())
5748 {
5749 return gl::error(GL_INVALID_OPERATION);
5750 }
5751
5752 if (transformFeedback->isPaused())
5753 {
5754 transformFeedback->resume();
5755 }
5756 else
5757 {
5758 transformFeedback->start(primitiveMode);
5759 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005760 }
5761}
5762
5763void __stdcall glEndTransformFeedback(void)
5764{
5765 EVENT("(void)");
5766
Geoff Langbfdea662014-07-23 14:16:32 -04005767 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005768
Geoff Langbfdea662014-07-23 14:16:32 -04005769 if (context)
5770 {
5771 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005772 {
Geoff Langbfdea662014-07-23 14:16:32 -04005773 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005774 }
Geoff Langbfdea662014-07-23 14:16:32 -04005775
5776 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5777 ASSERT(transformFeedback != NULL);
5778
5779 if (!transformFeedback->isStarted())
5780 {
5781 return gl::error(GL_INVALID_OPERATION);
5782 }
5783
5784 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005785 }
5786}
5787
5788void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5789{
5790 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5791 target, index, buffer, offset, size);
5792
Geoff Langbfdea662014-07-23 14:16:32 -04005793 gl::Context *context = gl::getNonLostContext();
5794
5795 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005796 {
Geoff Langbfdea662014-07-23 14:16:32 -04005797 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005798 {
Geoff Langbfdea662014-07-23 14:16:32 -04005799 return gl::error(GL_INVALID_OPERATION);
5800 }
5801
5802 switch (target)
5803 {
5804 case GL_TRANSFORM_FEEDBACK_BUFFER:
5805 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005806 {
Geoff Langbfdea662014-07-23 14:16:32 -04005807 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005808 }
Geoff Langbfdea662014-07-23 14:16:32 -04005809 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005810
Geoff Langbfdea662014-07-23 14:16:32 -04005811 case GL_UNIFORM_BUFFER:
5812 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005813 {
Geoff Langbfdea662014-07-23 14:16:32 -04005814 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005815 }
Geoff Langbfdea662014-07-23 14:16:32 -04005816 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005817
Geoff Langbfdea662014-07-23 14:16:32 -04005818 default:
5819 return gl::error(GL_INVALID_ENUM);
5820 }
5821
5822 if (buffer != 0 && size <= 0)
5823 {
5824 return gl::error(GL_INVALID_VALUE);
5825 }
5826
5827 switch (target)
5828 {
5829 case GL_TRANSFORM_FEEDBACK_BUFFER:
5830
5831 // size and offset must be a multiple of 4
5832 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005833 {
5834 return gl::error(GL_INVALID_VALUE);
5835 }
5836
Geoff Langbfdea662014-07-23 14:16:32 -04005837 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5838 context->bindGenericTransformFeedbackBuffer(buffer);
5839 break;
5840
5841 case GL_UNIFORM_BUFFER:
5842
5843 // it is an error to bind an offset not a multiple of the alignment
5844 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005845 {
Geoff Langbfdea662014-07-23 14:16:32 -04005846 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005847 }
Geoff Langbfdea662014-07-23 14:16:32 -04005848
5849 context->bindIndexedUniformBuffer(buffer, index, offset, size);
5850 context->bindGenericUniformBuffer(buffer);
5851 break;
5852
5853 default:
5854 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005855 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005856 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005857}
5858
5859void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
5860{
5861 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
5862 target, index, buffer);
5863
Geoff Langbfdea662014-07-23 14:16:32 -04005864 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005865
Geoff Langbfdea662014-07-23 14:16:32 -04005866 if (context)
5867 {
5868 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005869 {
Geoff Langbfdea662014-07-23 14:16:32 -04005870 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005871 }
Geoff Langbfdea662014-07-23 14:16:32 -04005872
5873 switch (target)
5874 {
5875 case GL_TRANSFORM_FEEDBACK_BUFFER:
5876 if (index >= context->getMaxTransformFeedbackBufferBindings())
5877 {
5878 return gl::error(GL_INVALID_VALUE);
5879 }
5880 break;
5881
5882 case GL_UNIFORM_BUFFER:
5883 if (index >= context->getMaximumCombinedUniformBufferBindings())
5884 {
5885 return gl::error(GL_INVALID_VALUE);
5886 }
5887 break;
5888
5889 default:
5890 return gl::error(GL_INVALID_ENUM);
5891 }
5892
5893 switch (target)
5894 {
5895 case GL_TRANSFORM_FEEDBACK_BUFFER:
5896 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
5897 context->bindGenericTransformFeedbackBuffer(buffer);
5898 break;
5899
5900 case GL_UNIFORM_BUFFER:
5901 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
5902 context->bindGenericUniformBuffer(buffer);
5903 break;
5904
5905 default:
5906 UNREACHABLE();
5907 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005908 }
5909}
5910
5911void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
5912{
5913 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
5914 program, count, varyings, bufferMode);
5915
Geoff Langbfdea662014-07-23 14:16:32 -04005916 gl::Context *context = gl::getNonLostContext();
5917
5918 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005919 {
Geoff Langbfdea662014-07-23 14:16:32 -04005920 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005921 {
Geoff Langbfdea662014-07-23 14:16:32 -04005922 return gl::error(GL_INVALID_OPERATION);
5923 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005924
Geoff Langbfdea662014-07-23 14:16:32 -04005925 if (count < 0)
5926 {
5927 return gl::error(GL_INVALID_VALUE);
5928 }
5929
5930 switch (bufferMode)
5931 {
5932 case GL_INTERLEAVED_ATTRIBS:
5933 break;
5934 case GL_SEPARATE_ATTRIBS:
5935 if (static_cast<GLuint>(count) > context->getMaxTransformFeedbackBufferBindings())
Geoff Lang48dcae72014-02-05 16:28:24 -05005936 {
5937 return gl::error(GL_INVALID_VALUE);
5938 }
Geoff Langbfdea662014-07-23 14:16:32 -04005939 break;
5940 default:
5941 return gl::error(GL_INVALID_ENUM);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005942 }
Geoff Langbfdea662014-07-23 14:16:32 -04005943
5944 if (!gl::ValidProgram(context, program))
5945 {
5946 return;
5947 }
5948
5949 gl::Program *programObject = context->getProgram(program);
5950 ASSERT(programObject);
5951
5952 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005953 }
5954}
5955
5956void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
5957{
5958 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
5959 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
5960 program, index, bufSize, length, size, type, name);
5961
Geoff Langbfdea662014-07-23 14:16:32 -04005962 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005963
Geoff Langbfdea662014-07-23 14:16:32 -04005964 if (context)
5965 {
5966 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005967 {
Geoff Langbfdea662014-07-23 14:16:32 -04005968 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005969 }
Geoff Langbfdea662014-07-23 14:16:32 -04005970
5971 if (bufSize < 0)
5972 {
5973 return gl::error(GL_INVALID_VALUE);
5974 }
5975
5976 if (!gl::ValidProgram(context, program))
5977 {
5978 return;
5979 }
5980
5981 gl::Program *programObject = context->getProgram(program);
5982 ASSERT(programObject);
5983
5984 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
5985 {
5986 return gl::error(GL_INVALID_VALUE);
5987 }
5988
5989 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005990 }
5991}
5992
5993void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
5994{
5995 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
5996 index, size, type, stride, pointer);
5997
Geoff Langbfdea662014-07-23 14:16:32 -04005998 gl::Context *context = gl::getNonLostContext();
5999
6000 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006001 {
Geoff Langbfdea662014-07-23 14:16:32 -04006002 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006003 {
Geoff Langbfdea662014-07-23 14:16:32 -04006004 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006005 }
Geoff Langbfdea662014-07-23 14:16:32 -04006006 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006007
Geoff Langbfdea662014-07-23 14:16:32 -04006008 if (index >= gl::MAX_VERTEX_ATTRIBS)
6009 {
6010 return gl::error(GL_INVALID_VALUE);
6011 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006012
Geoff Langbfdea662014-07-23 14:16:32 -04006013 if (size < 1 || size > 4)
6014 {
6015 return gl::error(GL_INVALID_VALUE);
6016 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006017
Geoff Langbfdea662014-07-23 14:16:32 -04006018 switch (type)
6019 {
6020 case GL_BYTE:
6021 case GL_UNSIGNED_BYTE:
6022 case GL_SHORT:
6023 case GL_UNSIGNED_SHORT:
6024 case GL_INT:
6025 case GL_UNSIGNED_INT:
6026 case GL_INT_2_10_10_10_REV:
6027 case GL_UNSIGNED_INT_2_10_10_10_REV:
6028 break;
6029 default:
6030 return gl::error(GL_INVALID_ENUM);
6031 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006032
Geoff Langbfdea662014-07-23 14:16:32 -04006033 if (stride < 0)
6034 {
6035 return gl::error(GL_INVALID_VALUE);
6036 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006037
Geoff Langbfdea662014-07-23 14:16:32 -04006038 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6039 {
6040 return gl::error(GL_INVALID_OPERATION);
6041 }
6042
6043 if (context)
6044 {
6045 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6046 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6047 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6048 // and the pointer argument is not NULL.
6049 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006050 {
6051 return gl::error(GL_INVALID_OPERATION);
6052 }
6053
Geoff Langbfdea662014-07-23 14:16:32 -04006054 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6055 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006056 }
6057}
6058
6059void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6060{
6061 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6062 index, pname, params);
6063
Geoff Langbfdea662014-07-23 14:16:32 -04006064 gl::Context *context = gl::getNonLostContext();
6065
6066 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006067 {
Geoff Langbfdea662014-07-23 14:16:32 -04006068 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006069 {
Geoff Langbfdea662014-07-23 14:16:32 -04006070 return gl::error(GL_INVALID_OPERATION);
6071 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006072
Geoff Langbfdea662014-07-23 14:16:32 -04006073 if (index >= gl::MAX_VERTEX_ATTRIBS)
6074 {
6075 return gl::error(GL_INVALID_VALUE);
6076 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006077
Geoff Langbfdea662014-07-23 14:16:32 -04006078 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006079
Geoff Langbfdea662014-07-23 14:16:32 -04006080 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6081 {
6082 return;
6083 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006084
Geoff Langbfdea662014-07-23 14:16:32 -04006085 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6086 {
6087 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6088 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006089 {
Geoff Langbfdea662014-07-23 14:16:32 -04006090 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006091 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006092 }
Geoff Langbfdea662014-07-23 14:16:32 -04006093 else
6094 {
6095 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6096 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006097 }
6098}
6099
6100void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6101{
6102 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6103 index, pname, params);
6104
Geoff Langbfdea662014-07-23 14:16:32 -04006105 gl::Context *context = gl::getNonLostContext();
6106
6107 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006108 {
Geoff Langbfdea662014-07-23 14:16:32 -04006109 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006110 {
Geoff Langbfdea662014-07-23 14:16:32 -04006111 return gl::error(GL_INVALID_OPERATION);
6112 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006113
Geoff Langbfdea662014-07-23 14:16:32 -04006114 if (index >= gl::MAX_VERTEX_ATTRIBS)
6115 {
6116 return gl::error(GL_INVALID_VALUE);
6117 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006118
Geoff Langbfdea662014-07-23 14:16:32 -04006119 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006120
Geoff Langbfdea662014-07-23 14:16:32 -04006121 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6122 {
6123 return;
6124 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006125
Geoff Langbfdea662014-07-23 14:16:32 -04006126 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6127 {
6128 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6129 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006130 {
Geoff Langbfdea662014-07-23 14:16:32 -04006131 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006132 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006133 }
Geoff Langbfdea662014-07-23 14:16:32 -04006134 else
6135 {
6136 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6137 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006138 }
6139}
6140
6141void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6142{
6143 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6144 index, x, y, z, w);
6145
Geoff Langbfdea662014-07-23 14:16:32 -04006146 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006147
Geoff Langbfdea662014-07-23 14:16:32 -04006148 if (context)
6149 {
6150 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006151 {
Geoff Langbfdea662014-07-23 14:16:32 -04006152 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006153 }
Geoff Langbfdea662014-07-23 14:16:32 -04006154
6155 if (index >= gl::MAX_VERTEX_ATTRIBS)
6156 {
6157 return gl::error(GL_INVALID_VALUE);
6158 }
6159
6160 GLint vals[4] = { x, y, z, w };
6161 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006162 }
6163}
6164
6165void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6166{
6167 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6168 index, x, y, z, w);
6169
Geoff Langbfdea662014-07-23 14:16:32 -04006170 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006171
Geoff Langbfdea662014-07-23 14:16:32 -04006172 if (context)
6173 {
6174 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006175 {
Geoff Langbfdea662014-07-23 14:16:32 -04006176 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006177 }
Geoff Langbfdea662014-07-23 14:16:32 -04006178
6179 if (index >= gl::MAX_VERTEX_ATTRIBS)
6180 {
6181 return gl::error(GL_INVALID_VALUE);
6182 }
6183
6184 GLuint vals[4] = { x, y, z, w };
6185 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006186 }
6187}
6188
6189void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6190{
6191 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6192
Geoff Langbfdea662014-07-23 14:16:32 -04006193 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006194
Geoff Langbfdea662014-07-23 14:16:32 -04006195 if (context)
6196 {
6197 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006198 {
Geoff Langbfdea662014-07-23 14:16:32 -04006199 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006200 }
Geoff Langbfdea662014-07-23 14:16:32 -04006201
6202 if (index >= gl::MAX_VERTEX_ATTRIBS)
6203 {
6204 return gl::error(GL_INVALID_VALUE);
6205 }
6206
6207 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006208 }
6209}
6210
6211void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6212{
6213 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6214
Geoff Langbfdea662014-07-23 14:16:32 -04006215 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006216
Geoff Langbfdea662014-07-23 14:16:32 -04006217 if (context)
6218 {
6219 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006220 {
Geoff Langbfdea662014-07-23 14:16:32 -04006221 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006222 }
Geoff Langbfdea662014-07-23 14:16:32 -04006223
6224 if (index >= gl::MAX_VERTEX_ATTRIBS)
6225 {
6226 return gl::error(GL_INVALID_VALUE);
6227 }
6228
6229 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006230 }
6231}
6232
6233void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6234{
6235 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6236 program, location, params);
6237
Geoff Langbfdea662014-07-23 14:16:32 -04006238 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006239
Geoff Langbfdea662014-07-23 14:16:32 -04006240 if (context)
6241 {
6242 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006243 {
Geoff Langbfdea662014-07-23 14:16:32 -04006244 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006245 }
Geoff Langbfdea662014-07-23 14:16:32 -04006246
6247 if (program == 0)
6248 {
6249 return gl::error(GL_INVALID_VALUE);
6250 }
6251
6252 gl::Program *programObject = context->getProgram(program);
6253
6254 if (!programObject || !programObject->isLinked())
6255 {
6256 return gl::error(GL_INVALID_OPERATION);
6257 }
6258
6259 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6260 if (!programBinary)
6261 {
6262 return gl::error(GL_INVALID_OPERATION);
6263 }
6264
6265 if (!programBinary->getUniformuiv(location, NULL, params))
6266 {
6267 return gl::error(GL_INVALID_OPERATION);
6268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006269 }
6270}
6271
6272GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6273{
6274 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6275 program, name);
6276
Geoff Langbfdea662014-07-23 14:16:32 -04006277 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006278
Geoff Langbfdea662014-07-23 14:16:32 -04006279 if (context)
6280 {
6281 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006282 {
Geoff Langbfdea662014-07-23 14:16:32 -04006283 return gl::error(GL_INVALID_OPERATION, -1);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006284 }
Geoff Langbfdea662014-07-23 14:16:32 -04006285
6286 if (program == 0)
6287 {
6288 return gl::error(GL_INVALID_VALUE, -1);
6289 }
6290
6291 gl::Program *programObject = context->getProgram(program);
6292
6293 if (!programObject || !programObject->isLinked())
6294 {
6295 return gl::error(GL_INVALID_OPERATION, -1);
6296 }
6297
6298 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6299 if (!programBinary)
6300 {
6301 return gl::error(GL_INVALID_OPERATION, -1);
6302 }
6303
6304 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006305 }
6306
6307 return 0;
6308}
6309
6310void __stdcall glUniform1ui(GLint location, GLuint v0)
6311{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006312 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006313}
6314
6315void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6316{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006317 const GLuint xy[] = { v0, v1 };
6318 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006319}
6320
6321void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6322{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006323 const GLuint xyz[] = { v0, v1, v2 };
6324 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006325}
6326
6327void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6328{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006329 const GLuint xyzw[] = { v0, v1, v2, v3 };
6330 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006331}
6332
6333void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6334{
6335 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6336 location, count, value);
6337
Geoff Langbfdea662014-07-23 14:16:32 -04006338 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006339
Geoff Langbfdea662014-07-23 14:16:32 -04006340 if (context)
6341 {
6342 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006343 {
Geoff Langbfdea662014-07-23 14:16:32 -04006344 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006345 }
Geoff Langbfdea662014-07-23 14:16:32 -04006346
6347 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6348 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006349 }
6350}
6351
6352void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6353{
6354 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6355 location, count, value);
6356
Geoff Langbfdea662014-07-23 14:16:32 -04006357 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006358
Geoff Langbfdea662014-07-23 14:16:32 -04006359 if (context)
6360 {
6361 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006362 {
Geoff Langbfdea662014-07-23 14:16:32 -04006363 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006364 }
Geoff Langbfdea662014-07-23 14:16:32 -04006365
6366 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6367 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006368 }
6369}
6370
6371void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6372{
6373 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6374 location, count, value);
6375
Geoff Langbfdea662014-07-23 14:16:32 -04006376 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006377
Geoff Langbfdea662014-07-23 14:16:32 -04006378 if (context)
6379 {
6380 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006381 {
Geoff Langbfdea662014-07-23 14:16:32 -04006382 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006383 }
Geoff Langbfdea662014-07-23 14:16:32 -04006384
6385 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6386 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006387 }
6388}
6389
6390void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6391{
6392 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6393 location, count, value);
6394
Geoff Langbfdea662014-07-23 14:16:32 -04006395 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006396
Geoff Langbfdea662014-07-23 14:16:32 -04006397 if (context)
6398 {
6399 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006400 {
Geoff Langbfdea662014-07-23 14:16:32 -04006401 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006402 }
Geoff Langbfdea662014-07-23 14:16:32 -04006403
6404 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6405 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006406 }
6407}
6408
6409void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6410{
6411 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6412 buffer, drawbuffer, value);
6413
Geoff Langbfdea662014-07-23 14:16:32 -04006414 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006415
Geoff Langbfdea662014-07-23 14:16:32 -04006416 if (context)
6417 {
6418 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006419 {
Geoff Langbfdea662014-07-23 14:16:32 -04006420 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006421 }
Geoff Langbfdea662014-07-23 14:16:32 -04006422
6423 switch (buffer)
6424 {
6425 case GL_COLOR:
6426 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6427 {
6428 return gl::error(GL_INVALID_VALUE);
6429 }
6430 break;
6431 case GL_STENCIL:
6432 if (drawbuffer != 0)
6433 {
6434 return gl::error(GL_INVALID_VALUE);
6435 }
6436 break;
6437 default:
6438 return gl::error(GL_INVALID_ENUM);
6439 }
6440
6441 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006442 }
6443}
6444
6445void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6446{
6447 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6448 buffer, drawbuffer, value);
6449
Geoff Langbfdea662014-07-23 14:16:32 -04006450 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006451
Geoff Langbfdea662014-07-23 14:16:32 -04006452 if (context)
6453 {
6454 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006455 {
Geoff Langbfdea662014-07-23 14:16:32 -04006456 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006457 }
Geoff Langbfdea662014-07-23 14:16:32 -04006458
6459 switch (buffer)
6460 {
6461 case GL_COLOR:
6462 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6463 {
6464 return gl::error(GL_INVALID_VALUE);
6465 }
6466 break;
6467 default:
6468 return gl::error(GL_INVALID_ENUM);
6469 }
6470
6471 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006472 }
6473}
6474
6475void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6476{
6477 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6478 buffer, drawbuffer, value);
6479
Geoff Langbfdea662014-07-23 14:16:32 -04006480 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006481
Geoff Langbfdea662014-07-23 14:16:32 -04006482 if (context)
6483 {
6484 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006485 {
Geoff Langbfdea662014-07-23 14:16:32 -04006486 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006487 }
Geoff Langbfdea662014-07-23 14:16:32 -04006488
6489 switch (buffer)
6490 {
6491 case GL_COLOR:
6492 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6493 {
6494 return gl::error(GL_INVALID_VALUE);
6495 }
6496 break;
6497 case GL_DEPTH:
6498 if (drawbuffer != 0)
6499 {
6500 return gl::error(GL_INVALID_VALUE);
6501 }
6502 break;
6503 default:
6504 return gl::error(GL_INVALID_ENUM);
6505 }
6506
6507 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006508 }
6509}
6510
6511void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6512{
6513 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6514 buffer, drawbuffer, depth, stencil);
6515
Geoff Langbfdea662014-07-23 14:16:32 -04006516 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006517
Geoff Langbfdea662014-07-23 14:16:32 -04006518 if (context)
6519 {
6520 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006521 {
Geoff Langbfdea662014-07-23 14:16:32 -04006522 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006523 }
Geoff Langbfdea662014-07-23 14:16:32 -04006524
6525 switch (buffer)
6526 {
6527 case GL_DEPTH_STENCIL:
6528 if (drawbuffer != 0)
6529 {
6530 return gl::error(GL_INVALID_VALUE);
6531 }
6532 break;
6533 default:
6534 return gl::error(GL_INVALID_ENUM);
6535 }
6536
6537 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006538 }
6539}
6540
6541const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6542{
6543 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6544
Geoff Langbfdea662014-07-23 14:16:32 -04006545 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006546
Geoff Langbfdea662014-07-23 14:16:32 -04006547 if (context)
6548 {
6549 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006550 {
Geoff Langbfdea662014-07-23 14:16:32 -04006551 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006552 }
Geoff Langbfdea662014-07-23 14:16:32 -04006553
6554 if (name != GL_EXTENSIONS)
6555 {
6556 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
6557 }
6558
6559 if (index >= context->getExtensionStringCount())
6560 {
6561 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
6562 }
6563
6564 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006565 }
6566
6567 return NULL;
6568}
6569
6570void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6571{
6572 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6573 readTarget, writeTarget, readOffset, writeOffset, size);
6574
Geoff Langbfdea662014-07-23 14:16:32 -04006575 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006576
Geoff Langbfdea662014-07-23 14:16:32 -04006577 if (context)
6578 {
6579 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006580 {
Geoff Langbfdea662014-07-23 14:16:32 -04006581 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006582 }
Geoff Langbfdea662014-07-23 14:16:32 -04006583
6584 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6585 {
6586 return gl::error(GL_INVALID_ENUM);
6587 }
6588
6589 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6590 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6591
6592 if (!readBuffer || !writeBuffer)
6593 {
6594 return gl::error(GL_INVALID_OPERATION);
6595 }
6596
Jamie Madillcfaaf722014-07-31 10:47:54 -04006597 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006598 if (readBuffer->isMapped() || writeBuffer->isMapped())
6599 {
6600 return gl::error(GL_INVALID_OPERATION);
6601 }
6602
6603 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6604 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6605 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6606 {
6607 return gl::error(GL_INVALID_VALUE);
6608 }
6609
6610 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6611 {
6612 return gl::error(GL_INVALID_VALUE);
6613 }
6614
Geoff Langbfdea662014-07-23 14:16:32 -04006615 // if size is zero, the copy is a successful no-op
6616 if (size > 0)
6617 {
6618 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6619 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006620 }
6621}
6622
6623void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6624{
6625 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6626 program, uniformCount, uniformNames, uniformIndices);
6627
Geoff Langbfdea662014-07-23 14:16:32 -04006628 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006629
Geoff Langbfdea662014-07-23 14:16:32 -04006630 if (context)
6631 {
6632 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006633 {
Geoff Langbfdea662014-07-23 14:16:32 -04006634 return gl::error(GL_INVALID_OPERATION);
6635 }
6636
6637 if (uniformCount < 0)
6638 {
6639 return gl::error(GL_INVALID_VALUE);
6640 }
6641
6642 gl::Program *programObject = context->getProgram(program);
6643
6644 if (!programObject)
6645 {
6646 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006647 {
6648 return gl::error(GL_INVALID_OPERATION);
6649 }
Geoff Langbfdea662014-07-23 14:16:32 -04006650 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006651 {
6652 return gl::error(GL_INVALID_VALUE);
6653 }
Geoff Langbfdea662014-07-23 14:16:32 -04006654 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006655
Geoff Langbfdea662014-07-23 14:16:32 -04006656 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6657 if (!programObject->isLinked() || !programBinary)
6658 {
6659 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006660 {
Geoff Langbfdea662014-07-23 14:16:32 -04006661 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006662 }
6663 }
Geoff Langbfdea662014-07-23 14:16:32 -04006664 else
6665 {
6666 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6667 {
6668 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6669 }
6670 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006671 }
6672}
6673
6674void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6675{
6676 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6677 program, uniformCount, uniformIndices, pname, params);
6678
Geoff Langbfdea662014-07-23 14:16:32 -04006679 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006680
Geoff Langbfdea662014-07-23 14:16:32 -04006681 if (context)
6682 {
6683 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006684 {
Geoff Langbfdea662014-07-23 14:16:32 -04006685 return gl::error(GL_INVALID_OPERATION);
6686 }
6687
6688 if (uniformCount < 0)
6689 {
6690 return gl::error(GL_INVALID_VALUE);
6691 }
6692
6693 gl::Program *programObject = context->getProgram(program);
6694
6695 if (!programObject)
6696 {
6697 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006698 {
6699 return gl::error(GL_INVALID_OPERATION);
6700 }
Geoff Langbfdea662014-07-23 14:16:32 -04006701 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006702 {
6703 return gl::error(GL_INVALID_VALUE);
6704 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006705 }
Geoff Langbfdea662014-07-23 14:16:32 -04006706
6707 switch (pname)
6708 {
6709 case GL_UNIFORM_TYPE:
6710 case GL_UNIFORM_SIZE:
6711 case GL_UNIFORM_NAME_LENGTH:
6712 case GL_UNIFORM_BLOCK_INDEX:
6713 case GL_UNIFORM_OFFSET:
6714 case GL_UNIFORM_ARRAY_STRIDE:
6715 case GL_UNIFORM_MATRIX_STRIDE:
6716 case GL_UNIFORM_IS_ROW_MAJOR:
6717 break;
6718 default:
6719 return gl::error(GL_INVALID_ENUM);
6720 }
6721
6722 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6723
6724 if (!programBinary && uniformCount > 0)
6725 {
6726 return gl::error(GL_INVALID_VALUE);
6727 }
6728
6729 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6730 {
6731 const GLuint index = uniformIndices[uniformId];
6732
6733 if (index >= (GLuint)programBinary->getActiveUniformCount())
6734 {
6735 return gl::error(GL_INVALID_VALUE);
6736 }
6737 }
6738
6739 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6740 {
6741 const GLuint index = uniformIndices[uniformId];
6742 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006744 }
6745}
6746
6747GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6748{
6749 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6750
Geoff Langbfdea662014-07-23 14:16:32 -04006751 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006752
Geoff Langbfdea662014-07-23 14:16:32 -04006753 if (context)
6754 {
6755 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006756 {
Geoff Langbfdea662014-07-23 14:16:32 -04006757 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
6758 }
6759
6760 gl::Program *programObject = context->getProgram(program);
6761
6762 if (!programObject)
6763 {
6764 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006765 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006766 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006767 }
Geoff Langbfdea662014-07-23 14:16:32 -04006768 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006769 {
Geoff Langbfdea662014-07-23 14:16:32 -04006770 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006771 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006772 }
Geoff Langbfdea662014-07-23 14:16:32 -04006773
6774 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6775 if (!programBinary)
6776 {
6777 return GL_INVALID_INDEX;
6778 }
6779
6780 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006781 }
6782
6783 return 0;
6784}
6785
6786void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6787{
6788 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6789 program, uniformBlockIndex, pname, params);
6790
Geoff Langbfdea662014-07-23 14:16:32 -04006791 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006792
Geoff Langbfdea662014-07-23 14:16:32 -04006793 if (context)
6794 {
6795 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006796 {
Geoff Langbfdea662014-07-23 14:16:32 -04006797 return gl::error(GL_INVALID_OPERATION);
6798 }
6799 gl::Program *programObject = context->getProgram(program);
6800
6801 if (!programObject)
6802 {
6803 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006804 {
6805 return gl::error(GL_INVALID_OPERATION);
6806 }
Geoff Langbfdea662014-07-23 14:16:32 -04006807 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006808 {
6809 return gl::error(GL_INVALID_VALUE);
6810 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006811 }
Geoff Langbfdea662014-07-23 14:16:32 -04006812
6813 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6814
6815 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6816 {
6817 return gl::error(GL_INVALID_VALUE);
6818 }
6819
6820 switch (pname)
6821 {
6822 case GL_UNIFORM_BLOCK_BINDING:
6823 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
6824 break;
6825
6826 case GL_UNIFORM_BLOCK_DATA_SIZE:
6827 case GL_UNIFORM_BLOCK_NAME_LENGTH:
6828 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
6829 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
6830 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
6831 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
6832 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
6833 break;
6834
6835 default:
6836 return gl::error(GL_INVALID_ENUM);
6837 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006838 }
6839}
6840
6841void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
6842{
6843 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
6844 program, uniformBlockIndex, bufSize, length, uniformBlockName);
6845
Geoff Langbfdea662014-07-23 14:16:32 -04006846 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006847
Geoff Langbfdea662014-07-23 14:16:32 -04006848 if (context)
6849 {
6850 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006851 {
Geoff Langbfdea662014-07-23 14:16:32 -04006852 return gl::error(GL_INVALID_OPERATION);
6853 }
6854
6855 gl::Program *programObject = context->getProgram(program);
6856
6857 if (!programObject)
6858 {
6859 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006860 {
6861 return gl::error(GL_INVALID_OPERATION);
6862 }
Geoff Langbfdea662014-07-23 14:16:32 -04006863 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006864 {
6865 return gl::error(GL_INVALID_VALUE);
6866 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006867 }
Geoff Langbfdea662014-07-23 14:16:32 -04006868
6869 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6870
6871 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6872 {
6873 return gl::error(GL_INVALID_VALUE);
6874 }
6875
6876 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006877 }
6878}
6879
6880void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
6881{
6882 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
6883 program, uniformBlockIndex, uniformBlockBinding);
6884
Geoff Langbfdea662014-07-23 14:16:32 -04006885 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006886
Geoff Langbfdea662014-07-23 14:16:32 -04006887 if (context)
6888 {
6889 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006890 {
Geoff Langbfdea662014-07-23 14:16:32 -04006891 return gl::error(GL_INVALID_OPERATION);
6892 }
6893
6894 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
6895 {
6896 return gl::error(GL_INVALID_VALUE);
6897 }
6898
6899 gl::Program *programObject = context->getProgram(program);
6900
6901 if (!programObject)
6902 {
6903 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006904 {
6905 return gl::error(GL_INVALID_OPERATION);
6906 }
Geoff Langbfdea662014-07-23 14:16:32 -04006907 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006908 {
6909 return gl::error(GL_INVALID_VALUE);
6910 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006911 }
Geoff Langbfdea662014-07-23 14:16:32 -04006912
6913 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6914
6915 // if never linked, there won't be any uniform blocks
6916 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6917 {
6918 return gl::error(GL_INVALID_VALUE);
6919 }
6920
6921 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006922 }
6923}
6924
6925void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
6926{
6927 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
6928 mode, first, count, instanceCount);
6929
Geoff Langbfdea662014-07-23 14:16:32 -04006930 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006931
Geoff Langbfdea662014-07-23 14:16:32 -04006932 if (context)
6933 {
6934 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006935 {
Geoff Langbfdea662014-07-23 14:16:32 -04006936 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006937 }
Geoff Langbfdea662014-07-23 14:16:32 -04006938
6939 // glDrawArraysInstanced
6940 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006941 }
6942}
6943
6944void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
6945{
6946 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
6947 mode, count, type, indices, instanceCount);
6948
Geoff Langbfdea662014-07-23 14:16:32 -04006949 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006950
Geoff Langbfdea662014-07-23 14:16:32 -04006951 if (context)
6952 {
6953 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006954 {
Geoff Langbfdea662014-07-23 14:16:32 -04006955 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006956 }
Geoff Langbfdea662014-07-23 14:16:32 -04006957
6958 // glDrawElementsInstanced
6959 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006960 }
6961}
6962
6963GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
6964{
6965 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
6966
Geoff Langbfdea662014-07-23 14:16:32 -04006967 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006968
Geoff Langbfdea662014-07-23 14:16:32 -04006969 if (context)
6970 {
6971 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006972 {
Geoff Langbfdea662014-07-23 14:16:32 -04006973 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006974 }
Geoff Langbfdea662014-07-23 14:16:32 -04006975
6976 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
6977 {
6978 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
6979 }
6980
6981 if (flags != 0)
6982 {
6983 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
6984 }
6985
6986 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006987 }
6988
6989 return NULL;
6990}
6991
6992GLboolean __stdcall glIsSync(GLsync sync)
6993{
6994 EVENT("(GLsync sync = 0x%0.8p)", sync);
6995
Geoff Langbfdea662014-07-23 14:16:32 -04006996 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006997
Geoff Langbfdea662014-07-23 14:16:32 -04006998 if (context)
6999 {
7000 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007001 {
Geoff Langbfdea662014-07-23 14:16:32 -04007002 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007003 }
Geoff Langbfdea662014-07-23 14:16:32 -04007004
7005 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007006 }
7007
7008 return GL_FALSE;
7009}
7010
7011void __stdcall glDeleteSync(GLsync sync)
7012{
7013 EVENT("(GLsync sync = 0x%0.8p)", sync);
7014
Geoff Langbfdea662014-07-23 14:16:32 -04007015 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007016
Geoff Langbfdea662014-07-23 14:16:32 -04007017 if (context)
7018 {
7019 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007020 {
Geoff Langbfdea662014-07-23 14:16:32 -04007021 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007022 }
Geoff Langbfdea662014-07-23 14:16:32 -04007023
7024 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7025 {
7026 return gl::error(GL_INVALID_VALUE);
7027 }
7028
7029 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007030 }
7031}
7032
7033GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7034{
7035 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7036 sync, flags, timeout);
7037
Geoff Langbfdea662014-07-23 14:16:32 -04007038 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007039
Geoff Langbfdea662014-07-23 14:16:32 -04007040 if (context)
7041 {
7042 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007043 {
Geoff Langbfdea662014-07-23 14:16:32 -04007044 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007045 }
Geoff Langbfdea662014-07-23 14:16:32 -04007046
7047 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7048 {
7049 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7050 }
7051
7052 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7053
7054 if (!fenceSync)
7055 {
7056 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7057 }
7058
7059 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007060 }
7061
7062 return GL_FALSE;
7063}
7064
7065void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7066{
7067 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7068 sync, flags, timeout);
7069
Geoff Langbfdea662014-07-23 14:16:32 -04007070 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007071
Geoff Langbfdea662014-07-23 14:16:32 -04007072 if (context)
7073 {
7074 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007075 {
Geoff Langbfdea662014-07-23 14:16:32 -04007076 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007077 }
Geoff Langbfdea662014-07-23 14:16:32 -04007078
7079 if (flags != 0)
7080 {
7081 return gl::error(GL_INVALID_VALUE);
7082 }
7083
7084 if (timeout != GL_TIMEOUT_IGNORED)
7085 {
7086 return gl::error(GL_INVALID_VALUE);
7087 }
7088
7089 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7090
7091 if (!fenceSync)
7092 {
7093 return gl::error(GL_INVALID_VALUE);
7094 }
7095
7096 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007097 }
7098}
7099
7100void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7101{
7102 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7103 pname, params);
7104
Geoff Langbfdea662014-07-23 14:16:32 -04007105 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007106
Geoff Langbfdea662014-07-23 14:16:32 -04007107 if (context)
7108 {
7109 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007110 {
Geoff Langbfdea662014-07-23 14:16:32 -04007111 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007112 }
Geoff Langbfdea662014-07-23 14:16:32 -04007113
7114 GLenum nativeType;
7115 unsigned int numParams = 0;
7116 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7117 {
7118 return;
7119 }
7120
7121 if (nativeType == GL_INT_64_ANGLEX)
7122 {
7123 context->getInteger64v(pname, params);
7124 }
7125 else
7126 {
7127 CastStateValues(context, nativeType, pname, numParams, params);
7128 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007129 }
7130}
7131
7132void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7133{
7134 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7135 sync, pname, bufSize, length, values);
7136
Geoff Langbfdea662014-07-23 14:16:32 -04007137 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007138
Geoff Langbfdea662014-07-23 14:16:32 -04007139 if (context)
7140 {
7141 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007142 {
Geoff Langbfdea662014-07-23 14:16:32 -04007143 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007144 }
Geoff Langbfdea662014-07-23 14:16:32 -04007145
7146 if (bufSize < 0)
7147 {
7148 return gl::error(GL_INVALID_VALUE);
7149 }
7150
7151 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7152
7153 if (!fenceSync)
7154 {
7155 return gl::error(GL_INVALID_VALUE);
7156 }
7157
7158 switch (pname)
7159 {
7160 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7161 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7162 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7163 case GL_SYNC_FLAGS: values[0] = 0; break;
7164
7165 default:
7166 return gl::error(GL_INVALID_ENUM);
7167 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007168 }
7169}
7170
7171void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7172{
7173 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7174 target, index, data);
7175
Geoff Langbfdea662014-07-23 14:16:32 -04007176 gl::Context *context = gl::getNonLostContext();
7177
7178 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007179 {
Geoff Langbfdea662014-07-23 14:16:32 -04007180 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007181 {
Geoff Langbfdea662014-07-23 14:16:32 -04007182 return gl::error(GL_INVALID_OPERATION);
7183 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007184
Geoff Langbfdea662014-07-23 14:16:32 -04007185 switch (target)
7186 {
7187 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7188 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7189 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7190 if (index >= context->getMaxTransformFeedbackBufferBindings())
7191 return gl::error(GL_INVALID_VALUE);
7192 break;
7193 case GL_UNIFORM_BUFFER_START:
7194 case GL_UNIFORM_BUFFER_SIZE:
7195 case GL_UNIFORM_BUFFER_BINDING:
7196 if (index >= context->getMaximumCombinedUniformBufferBindings())
7197 return gl::error(GL_INVALID_VALUE);
7198 break;
7199 default:
7200 return gl::error(GL_INVALID_ENUM);
7201 }
7202
7203 if (!(context->getIndexedInteger64v(target, index, data)))
7204 {
7205 GLenum nativeType;
7206 unsigned int numParams = 0;
7207 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04007208 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04007209
Geoff Langbfdea662014-07-23 14:16:32 -04007210 if (numParams == 0)
7211 return; // it is known that pname is valid, but there are no parameters to return
7212
7213 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007214 {
Geoff Langbfdea662014-07-23 14:16:32 -04007215 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007216
Geoff Langbfdea662014-07-23 14:16:32 -04007217 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007218
Geoff Langbfdea662014-07-23 14:16:32 -04007219 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007220 {
Geoff Langbfdea662014-07-23 14:16:32 -04007221 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007222 }
Geoff Langbfdea662014-07-23 14:16:32 -04007223
7224 delete [] intParams;
7225 }
7226 else
7227 {
7228 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007229 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007230 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007231 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007232}
7233
7234void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7235{
7236 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7237 target, pname, params);
7238
Geoff Langbfdea662014-07-23 14:16:32 -04007239 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007240
Geoff Langbfdea662014-07-23 14:16:32 -04007241 if (context)
7242 {
7243 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007244 {
Geoff Langbfdea662014-07-23 14:16:32 -04007245 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007246 }
Geoff Langbfdea662014-07-23 14:16:32 -04007247
7248 if (!gl::ValidBufferTarget(context, target))
7249 {
7250 return gl::error(GL_INVALID_ENUM);
7251 }
7252
7253 if (!gl::ValidBufferParameter(context, pname))
7254 {
7255 return gl::error(GL_INVALID_ENUM);
7256 }
7257
7258 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7259
7260 if (!buffer)
7261 {
7262 // A null buffer means that "0" is bound to the requested buffer target
7263 return gl::error(GL_INVALID_OPERATION);
7264 }
7265
7266 switch (pname)
7267 {
7268 case GL_BUFFER_USAGE:
7269 *params = static_cast<GLint64>(buffer->getUsage());
7270 break;
7271 case GL_BUFFER_SIZE:
7272 *params = buffer->getSize();
7273 break;
7274 case GL_BUFFER_ACCESS_FLAGS:
7275 *params = static_cast<GLint64>(buffer->getAccessFlags());
7276 break;
7277 case GL_BUFFER_MAPPED:
7278 *params = static_cast<GLint64>(buffer->isMapped());
7279 break;
7280 case GL_BUFFER_MAP_OFFSET:
7281 *params = buffer->getMapOffset();
7282 break;
7283 case GL_BUFFER_MAP_LENGTH:
7284 *params = buffer->getMapLength();
7285 break;
7286 default: UNREACHABLE(); break;
7287 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007288 }
7289}
7290
7291void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7292{
7293 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7294
Geoff Langbfdea662014-07-23 14:16:32 -04007295 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007296
Geoff Langbfdea662014-07-23 14:16:32 -04007297 if (context)
7298 {
7299 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007300 {
Geoff Langbfdea662014-07-23 14:16:32 -04007301 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007302 }
Geoff Langbfdea662014-07-23 14:16:32 -04007303
7304 if (count < 0)
7305 {
7306 return gl::error(GL_INVALID_VALUE);
7307 }
7308
7309 for (int i = 0; i < count; i++)
7310 {
7311 samplers[i] = context->createSampler();
7312 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007313 }
7314}
7315
7316void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7317{
7318 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7319
Geoff Langbfdea662014-07-23 14:16:32 -04007320 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007321
Geoff Langbfdea662014-07-23 14:16:32 -04007322 if (context)
7323 {
7324 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007325 {
Geoff Langbfdea662014-07-23 14:16:32 -04007326 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007327 }
Geoff Langbfdea662014-07-23 14:16:32 -04007328
7329 if (count < 0)
7330 {
7331 return gl::error(GL_INVALID_VALUE);
7332 }
7333
7334 for (int i = 0; i < count; i++)
7335 {
7336 context->deleteSampler(samplers[i]);
7337 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007338 }
7339}
7340
7341GLboolean __stdcall glIsSampler(GLuint sampler)
7342{
7343 EVENT("(GLuint sampler = %u)", sampler);
7344
Geoff Langbfdea662014-07-23 14:16:32 -04007345 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007346
Geoff Langbfdea662014-07-23 14:16:32 -04007347 if (context)
7348 {
7349 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007350 {
Geoff Langbfdea662014-07-23 14:16:32 -04007351 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007352 }
Geoff Langbfdea662014-07-23 14:16:32 -04007353
7354 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007355 }
7356
7357 return GL_FALSE;
7358}
7359
7360void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7361{
7362 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7363
Geoff Langbfdea662014-07-23 14:16:32 -04007364 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007365
Geoff Langbfdea662014-07-23 14:16:32 -04007366 if (context)
7367 {
7368 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007369 {
Geoff Langbfdea662014-07-23 14:16:32 -04007370 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007371 }
Geoff Langbfdea662014-07-23 14:16:32 -04007372
7373 if (sampler != 0 && !context->isSampler(sampler))
7374 {
7375 return gl::error(GL_INVALID_OPERATION);
7376 }
7377
7378 if (unit >= context->getMaximumCombinedTextureImageUnits())
7379 {
7380 return gl::error(GL_INVALID_VALUE);
7381 }
7382
7383 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007384 }
7385}
7386
7387void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7388{
7389 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7390
Geoff Langbfdea662014-07-23 14:16:32 -04007391 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007392
Geoff Langbfdea662014-07-23 14:16:32 -04007393 if (context)
7394 {
7395 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007396 {
Geoff Langbfdea662014-07-23 14:16:32 -04007397 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007398 }
Geoff Langbfdea662014-07-23 14:16:32 -04007399
7400 if (!gl::ValidateSamplerObjectParameter(pname))
7401 {
7402 return;
7403 }
7404
7405 if (!gl::ValidateTexParamParameters(context, pname, param))
7406 {
7407 return;
7408 }
7409
7410 if (!context->isSampler(sampler))
7411 {
7412 return gl::error(GL_INVALID_OPERATION);
7413 }
7414
7415 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007416 }
7417}
7418
7419void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7420{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007421 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007422}
7423
7424void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7425{
7426 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7427
Geoff Langbfdea662014-07-23 14:16:32 -04007428 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007429
Geoff Langbfdea662014-07-23 14:16:32 -04007430 if (context)
7431 {
7432 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007433 {
Geoff Langbfdea662014-07-23 14:16:32 -04007434 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007435 }
Geoff Langbfdea662014-07-23 14:16:32 -04007436
7437 if (!gl::ValidateSamplerObjectParameter(pname))
7438 {
7439 return;
7440 }
7441
7442 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7443 {
7444 return;
7445 }
7446
7447 if (!context->isSampler(sampler))
7448 {
7449 return gl::error(GL_INVALID_OPERATION);
7450 }
7451
7452 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007453 }
7454}
7455
7456void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7457{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007458 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007459}
7460
7461void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7462{
7463 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7464
Geoff Langbfdea662014-07-23 14:16:32 -04007465 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007466
Geoff Langbfdea662014-07-23 14:16:32 -04007467 if (context)
7468 {
7469 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007470 {
Geoff Langbfdea662014-07-23 14:16:32 -04007471 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007472 }
Geoff Langbfdea662014-07-23 14:16:32 -04007473
7474 if (!gl::ValidateSamplerObjectParameter(pname))
7475 {
7476 return;
7477 }
7478
7479 if (!context->isSampler(sampler))
7480 {
7481 return gl::error(GL_INVALID_OPERATION);
7482 }
7483
7484 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007485 }
7486}
7487
7488void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7489{
7490 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7491
Geoff Langbfdea662014-07-23 14:16:32 -04007492 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007493
Geoff Langbfdea662014-07-23 14:16:32 -04007494 if (context)
7495 {
7496 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007497 {
Geoff Langbfdea662014-07-23 14:16:32 -04007498 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007499 }
Geoff Langbfdea662014-07-23 14:16:32 -04007500
7501 if (!gl::ValidateSamplerObjectParameter(pname))
7502 {
7503 return;
7504 }
7505
7506 if (!context->isSampler(sampler))
7507 {
7508 return gl::error(GL_INVALID_OPERATION);
7509 }
7510
7511 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007512 }
7513}
7514
7515void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7516{
7517 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7518
Geoff Langbfdea662014-07-23 14:16:32 -04007519 if (index >= gl::MAX_VERTEX_ATTRIBS)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007520 {
Geoff Langbfdea662014-07-23 14:16:32 -04007521 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007522 }
Geoff Langbfdea662014-07-23 14:16:32 -04007523
7524 gl::Context *context = gl::getNonLostContext();
7525
7526 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007527 {
Geoff Langbfdea662014-07-23 14:16:32 -04007528 if (context->getClientVersion() < 3)
7529 {
7530 return gl::error(GL_INVALID_OPERATION);
7531 }
7532
7533 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007534 }
7535}
7536
7537void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7538{
7539 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7540
Geoff Langbfdea662014-07-23 14:16:32 -04007541 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007542
Geoff Langbfdea662014-07-23 14:16:32 -04007543 if (context)
7544 {
7545 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007546 {
Geoff Langbfdea662014-07-23 14:16:32 -04007547 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007548 }
Geoff Langbfdea662014-07-23 14:16:32 -04007549
7550 switch (target)
7551 {
7552 case GL_TRANSFORM_FEEDBACK:
7553 {
7554 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7555 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7556 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7557 {
7558 return gl::error(GL_INVALID_OPERATION);
7559 }
7560
7561 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7562 if (context->getTransformFeedback(id) == NULL)
7563 {
7564 return gl::error(GL_INVALID_OPERATION);
7565 }
7566
7567 context->bindTransformFeedback(id);
7568 }
7569 break;
7570
7571 default:
7572 return gl::error(GL_INVALID_ENUM);
7573 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007574 }
7575}
7576
7577void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7578{
7579 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7580
Geoff Langbfdea662014-07-23 14:16:32 -04007581 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007582
Geoff Langbfdea662014-07-23 14:16:32 -04007583 if (context)
7584 {
7585 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007586 {
Geoff Langbfdea662014-07-23 14:16:32 -04007587 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007588 }
Geoff Langbfdea662014-07-23 14:16:32 -04007589
7590 for (int i = 0; i < n; i++)
7591 {
7592 context->deleteTransformFeedback(ids[i]);
7593 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007594 }
7595}
7596
7597void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7598{
7599 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7600
Geoff Langbfdea662014-07-23 14:16:32 -04007601 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007602
Geoff Langbfdea662014-07-23 14:16:32 -04007603 if (context)
7604 {
7605 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007606 {
Geoff Langbfdea662014-07-23 14:16:32 -04007607 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007608 }
Geoff Langbfdea662014-07-23 14:16:32 -04007609
7610 for (int i = 0; i < n; i++)
7611 {
7612 ids[i] = context->createTransformFeedback();
7613 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007614 }
7615}
7616
7617GLboolean __stdcall glIsTransformFeedback(GLuint id)
7618{
7619 EVENT("(GLuint id = %u)", id);
7620
Geoff Langbfdea662014-07-23 14:16:32 -04007621 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007622
Geoff Langbfdea662014-07-23 14:16:32 -04007623 if (context)
7624 {
7625 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007626 {
Geoff Langbfdea662014-07-23 14:16:32 -04007627 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007628 }
Geoff Langbfdea662014-07-23 14:16:32 -04007629
7630 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007631 }
7632
7633 return GL_FALSE;
7634}
7635
7636void __stdcall glPauseTransformFeedback(void)
7637{
7638 EVENT("(void)");
7639
Geoff Langbfdea662014-07-23 14:16:32 -04007640 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007641
Geoff Langbfdea662014-07-23 14:16:32 -04007642 if (context)
7643 {
7644 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007645 {
Geoff Langbfdea662014-07-23 14:16:32 -04007646 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007647 }
Geoff Langbfdea662014-07-23 14:16:32 -04007648
7649 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7650 ASSERT(transformFeedback != NULL);
7651
7652 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7653 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7654 {
7655 return gl::error(GL_INVALID_OPERATION);
7656 }
7657
7658 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007659 }
7660}
7661
7662void __stdcall glResumeTransformFeedback(void)
7663{
7664 EVENT("(void)");
7665
Geoff Langbfdea662014-07-23 14:16:32 -04007666 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007667
Geoff Langbfdea662014-07-23 14:16:32 -04007668 if (context)
7669 {
7670 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007671 {
Geoff Langbfdea662014-07-23 14:16:32 -04007672 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007673 }
Geoff Langbfdea662014-07-23 14:16:32 -04007674
7675 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7676 ASSERT(transformFeedback != NULL);
7677
7678 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7679 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7680 {
7681 return gl::error(GL_INVALID_OPERATION);
7682 }
7683
7684 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007685 }
7686}
7687
7688void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7689{
7690 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7691 program, bufSize, length, binaryFormat, binary);
7692
Geoff Langbfdea662014-07-23 14:16:32 -04007693 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007694
Geoff Langbfdea662014-07-23 14:16:32 -04007695 if (context)
7696 {
7697 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007698 {
Geoff Langbfdea662014-07-23 14:16:32 -04007699 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007700 }
Geoff Langbfdea662014-07-23 14:16:32 -04007701
7702 // glGetProgramBinary
7703 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007704 }
7705}
7706
7707void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7708{
7709 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7710 program, binaryFormat, binary, length);
7711
Geoff Langbfdea662014-07-23 14:16:32 -04007712 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007713
Geoff Langbfdea662014-07-23 14:16:32 -04007714 if (context)
7715 {
7716 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007717 {
Geoff Langbfdea662014-07-23 14:16:32 -04007718 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007719 }
Geoff Langbfdea662014-07-23 14:16:32 -04007720
7721 // glProgramBinary
7722 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007723 }
7724}
7725
7726void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7727{
7728 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7729 program, pname, value);
7730
Geoff Langbfdea662014-07-23 14:16:32 -04007731 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007732
Geoff Langbfdea662014-07-23 14:16:32 -04007733 if (context)
7734 {
7735 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007736 {
Geoff Langbfdea662014-07-23 14:16:32 -04007737 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007738 }
Geoff Langbfdea662014-07-23 14:16:32 -04007739
7740 // glProgramParameteri
7741 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007742 }
7743}
7744
7745void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7746{
7747 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7748 target, numAttachments, attachments);
7749
Geoff Langbfdea662014-07-23 14:16:32 -04007750 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007751
Geoff Langbfdea662014-07-23 14:16:32 -04007752 if (context)
7753 {
7754 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007755 {
Geoff Langbfdea662014-07-23 14:16:32 -04007756 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007757 }
Geoff Langbfdea662014-07-23 14:16:32 -04007758
7759 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7760 {
7761 return;
7762 }
7763
7764 GLuint maxDimension = context->getCaps().maxRenderbufferSize;
7765 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007766 }
7767}
7768
7769void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
7770{
7771 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
7772 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7773 target, numAttachments, attachments, x, y, width, height);
7774
Geoff Langbfdea662014-07-23 14:16:32 -04007775 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007776
Geoff Langbfdea662014-07-23 14:16:32 -04007777 if (context)
7778 {
7779 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007780 {
Geoff Langbfdea662014-07-23 14:16:32 -04007781 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007782 }
Geoff Langbfdea662014-07-23 14:16:32 -04007783
7784 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7785 {
7786 return;
7787 }
7788
7789 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007790 }
7791}
7792
7793void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7794{
7795 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7796 target, levels, internalformat, width, height);
7797
Geoff Langbfdea662014-07-23 14:16:32 -04007798 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007799
Geoff Langbfdea662014-07-23 14:16:32 -04007800 if (context)
7801 {
7802 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007803 {
Geoff Langbfdea662014-07-23 14:16:32 -04007804 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007805 }
Geoff Langbfdea662014-07-23 14:16:32 -04007806
7807 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
7808 {
7809 return;
7810 }
7811
7812 switch (target)
7813 {
7814 case GL_TEXTURE_2D:
7815 {
7816 gl::Texture2D *texture2d = context->getTexture2D();
7817 texture2d->storage(levels, internalformat, width, height);
7818 }
7819 break;
7820
7821 case GL_TEXTURE_CUBE_MAP:
7822 {
7823 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7824 textureCube->storage(levels, internalformat, width);
7825 }
7826 break;
7827
7828 default:
7829 return gl::error(GL_INVALID_ENUM);
7830 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007831 }
7832}
7833
7834void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
7835{
7836 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
7837 "GLsizei height = %d, GLsizei depth = %d)",
7838 target, levels, internalformat, width, height, depth);
7839
Geoff Langbfdea662014-07-23 14:16:32 -04007840 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007841
Geoff Langbfdea662014-07-23 14:16:32 -04007842 if (context)
7843 {
7844 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007845 {
Geoff Langbfdea662014-07-23 14:16:32 -04007846 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00007847 }
Geoff Langbfdea662014-07-23 14:16:32 -04007848
7849 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
7850 {
7851 return;
7852 }
7853
7854 switch (target)
7855 {
7856 case GL_TEXTURE_3D:
7857 {
7858 gl::Texture3D *texture3d = context->getTexture3D();
7859 texture3d->storage(levels, internalformat, width, height, depth);
7860 }
7861 break;
7862
7863 case GL_TEXTURE_2D_ARRAY:
7864 {
7865 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
7866 texture2darray->storage(levels, internalformat, width, height, depth);
7867 }
7868 break;
7869
7870 default:
7871 UNREACHABLE();
7872 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007873 }
7874}
7875
7876void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
7877{
7878 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
7879 "GLint* params = 0x%0.8p)",
7880 target, internalformat, pname, bufSize, params);
7881
Geoff Langbfdea662014-07-23 14:16:32 -04007882 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007883
Geoff Langbfdea662014-07-23 14:16:32 -04007884 if (context)
7885 {
7886 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007887 {
Geoff Langbfdea662014-07-23 14:16:32 -04007888 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007889 }
Geoff Langbfdea662014-07-23 14:16:32 -04007890
7891 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7892 if (!formatCaps.renderable)
7893 {
7894 return gl::error(GL_INVALID_ENUM);
7895 }
7896
7897 if (target != GL_RENDERBUFFER)
7898 {
7899 return gl::error(GL_INVALID_ENUM);
7900 }
7901
7902 if (bufSize < 0)
7903 {
7904 return gl::error(GL_INVALID_VALUE);
7905 }
7906
7907 switch (pname)
7908 {
7909 case GL_NUM_SAMPLE_COUNTS:
7910 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04007911 {
7912 *params = formatCaps.sampleCounts.size();
7913 }
Geoff Langbfdea662014-07-23 14:16:32 -04007914 break;
7915 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04007916 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04007917 break;
7918 default:
7919 return gl::error(GL_INVALID_ENUM);
7920 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007921 }
7922}
7923
7924// Extension functions
7925
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007926void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
7927 GLbitfield mask, GLenum filter)
7928{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007929 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007930 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
7931 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
7932 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
7933
Geoff Langbfdea662014-07-23 14:16:32 -04007934 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007935
Geoff Langbfdea662014-07-23 14:16:32 -04007936 if (context)
7937 {
7938 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
7939 dstX0, dstY0, dstX1, dstY1, mask, filter,
7940 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007941 {
Geoff Langbfdea662014-07-23 14:16:32 -04007942 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007943 }
Geoff Langbfdea662014-07-23 14:16:32 -04007944
7945 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
7946 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007947 }
7948}
7949
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007950void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
7951 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007952{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007953 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007954 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007955 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007956 target, level, internalformat, width, height, depth, border, format, type, pixels);
7957
Geoff Langbfdea662014-07-23 14:16:32 -04007958 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007959}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00007960
Geoff Langbfdea662014-07-23 14:16:32 -04007961void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007962 GLenum *binaryFormat, void *binary)
7963{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00007964 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 +00007965 program, bufSize, length, binaryFormat, binary);
7966
Geoff Langbfdea662014-07-23 14:16:32 -04007967 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007968
Geoff Langbfdea662014-07-23 14:16:32 -04007969 if (context)
7970 {
7971 gl::Program *programObject = context->getProgram(program);
7972
7973 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007974 {
Geoff Langbfdea662014-07-23 14:16:32 -04007975 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007976 }
Geoff Langbfdea662014-07-23 14:16:32 -04007977
7978 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7979
7980 if (!programBinary)
7981 {
7982 return gl::error(GL_INVALID_OPERATION);
7983 }
7984
7985 if (!programBinary->save(binary, bufSize, length))
7986 {
7987 return gl::error(GL_INVALID_OPERATION);
7988 }
7989
7990 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007991 }
7992}
7993
7994void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
7995 const void *binary, GLint length)
7996{
7997 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
7998 program, binaryFormat, binary, length);
7999
Geoff Langbfdea662014-07-23 14:16:32 -04008000 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008001
Geoff Langbfdea662014-07-23 14:16:32 -04008002 if (context)
8003 {
8004 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008005 {
Geoff Langbfdea662014-07-23 14:16:32 -04008006 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008007 }
Geoff Langbfdea662014-07-23 14:16:32 -04008008
8009 gl::Program *programObject = context->getProgram(program);
8010
8011 if (!programObject)
8012 {
8013 return gl::error(GL_INVALID_OPERATION);
8014 }
8015
8016 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008017 }
8018}
8019
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008020void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8021{
8022 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8023
Geoff Langbfdea662014-07-23 14:16:32 -04008024 gl::Context *context = gl::getNonLostContext();
8025
8026 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008027 {
Geoff Langbfdea662014-07-23 14:16:32 -04008028 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008029 {
Geoff Langbfdea662014-07-23 14:16:32 -04008030 return gl::error(GL_INVALID_VALUE);
8031 }
8032
8033 if (context->getState().getDrawFramebuffer()->id() == 0)
8034 {
8035 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008036 {
Geoff Langbfdea662014-07-23 14:16:32 -04008037 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008038 }
8039
Geoff Langbfdea662014-07-23 14:16:32 -04008040 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008041 {
Geoff Langbfdea662014-07-23 14:16:32 -04008042 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008043 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008044 }
Geoff Langbfdea662014-07-23 14:16:32 -04008045 else
8046 {
8047 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8048 {
8049 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8050 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8051 {
8052 return gl::error(GL_INVALID_OPERATION);
8053 }
8054 }
8055 }
8056
8057 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8058
8059 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8060 {
8061 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8062 }
8063
8064 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8065 {
8066 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8067 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008068 }
8069}
8070
Shannon Woodsb3801742014-03-27 14:59:19 -04008071void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8072{
8073 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8074
Geoff Langbfdea662014-07-23 14:16:32 -04008075 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008076
Geoff Langbfdea662014-07-23 14:16:32 -04008077 if (context)
8078 {
8079 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008080 {
Geoff Langbfdea662014-07-23 14:16:32 -04008081 return gl::error(GL_INVALID_ENUM);
Shannon Woodsb3801742014-03-27 14:59:19 -04008082 }
Geoff Langbfdea662014-07-23 14:16:32 -04008083
8084 if (pname != GL_BUFFER_MAP_POINTER)
8085 {
8086 return gl::error(GL_INVALID_ENUM);
8087 }
8088
8089 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8090
8091 if (!buffer || !buffer->isMapped())
8092 {
8093 *params = NULL;
8094 }
8095 else
8096 {
8097 *params = buffer->getMapPointer();
8098 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008099 }
8100}
8101
8102void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8103{
8104 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8105
Geoff Langbfdea662014-07-23 14:16:32 -04008106 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008107
Geoff Langbfdea662014-07-23 14:16:32 -04008108 if (context)
8109 {
8110 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008111 {
Geoff Langbfdea662014-07-23 14:16:32 -04008112 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woodsb3801742014-03-27 14:59:19 -04008113 }
Geoff Langbfdea662014-07-23 14:16:32 -04008114
8115 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8116
8117 if (buffer == NULL)
8118 {
8119 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8120 }
8121
8122 if (access != GL_WRITE_ONLY_OES)
8123 {
8124 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
8125 }
8126
8127 if (buffer->isMapped())
8128 {
8129 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8130 }
8131
8132 return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
Shannon Woodsb3801742014-03-27 14:59:19 -04008133 }
8134
8135 return NULL;
8136}
8137
8138GLboolean __stdcall glUnmapBufferOES(GLenum target)
8139{
8140 EVENT("(GLenum target = 0x%X)", target);
8141
Geoff Langbfdea662014-07-23 14:16:32 -04008142 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008143
Geoff Langbfdea662014-07-23 14:16:32 -04008144 if (context)
8145 {
8146 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008147 {
Geoff Langbfdea662014-07-23 14:16:32 -04008148 return gl::error(GL_INVALID_ENUM, GL_FALSE);
Shannon Woodsb3801742014-03-27 14:59:19 -04008149 }
Geoff Langbfdea662014-07-23 14:16:32 -04008150
8151 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8152
8153 if (buffer == NULL || !buffer->isMapped())
8154 {
8155 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8156 }
8157
8158 // TODO: detect if we had corruption. if so, throw an error and return false.
8159
8160 buffer->unmap();
8161
8162 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008163 }
8164
8165 return GL_FALSE;
8166}
8167
Shannon Woods916e7692014-03-27 16:58:22 -04008168void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8169{
8170 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8171 target, offset, length, access);
8172
Geoff Langbfdea662014-07-23 14:16:32 -04008173 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008174
Geoff Langbfdea662014-07-23 14:16:32 -04008175 if (context)
8176 {
8177 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008178 {
Geoff Langbfdea662014-07-23 14:16:32 -04008179 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woods916e7692014-03-27 16:58:22 -04008180 }
Geoff Langbfdea662014-07-23 14:16:32 -04008181
8182 if (offset < 0 || length < 0)
8183 {
8184 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8185 }
8186
8187 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8188
8189 if (buffer == NULL)
8190 {
8191 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8192 }
8193
8194 // Check for buffer overflow
8195 size_t offsetSize = static_cast<size_t>(offset);
8196 size_t lengthSize = static_cast<size_t>(length);
8197
8198 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8199 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8200 {
8201 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8202 }
8203
8204 // Check for invalid bits in the mask
8205 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8206 GL_MAP_WRITE_BIT |
8207 GL_MAP_INVALIDATE_RANGE_BIT |
8208 GL_MAP_INVALIDATE_BUFFER_BIT |
8209 GL_MAP_FLUSH_EXPLICIT_BIT |
8210 GL_MAP_UNSYNCHRONIZED_BIT;
8211
8212 if (access & ~(allAccessBits))
8213 {
8214 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8215 }
8216
8217 if (length == 0 || buffer->isMapped())
8218 {
8219 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8220 }
8221
8222 // Check for invalid bit combinations
8223 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8224 {
8225 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8226 }
8227
8228 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8229 GL_MAP_INVALIDATE_BUFFER_BIT |
8230 GL_MAP_UNSYNCHRONIZED_BIT;
8231
8232 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8233 {
8234 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8235 }
8236
8237 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8238 {
8239 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8240 }
8241
8242 return buffer->mapRange(offset, length, access);
Shannon Woods916e7692014-03-27 16:58:22 -04008243 }
8244
8245 return NULL;
8246}
8247
8248void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8249{
8250 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8251
Geoff Langbfdea662014-07-23 14:16:32 -04008252 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008253
Geoff Langbfdea662014-07-23 14:16:32 -04008254 if (context)
8255 {
8256 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008257 {
Geoff Langbfdea662014-07-23 14:16:32 -04008258 return gl::error(GL_INVALID_VALUE);
Shannon Woods916e7692014-03-27 16:58:22 -04008259 }
Geoff Langbfdea662014-07-23 14:16:32 -04008260
8261 if (!gl::ValidBufferTarget(context, target))
8262 {
8263 return gl::error(GL_INVALID_ENUM);
8264 }
8265
8266 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8267
8268 if (buffer == NULL)
8269 {
8270 return gl::error(GL_INVALID_OPERATION);
8271 }
8272
8273 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8274 {
8275 return gl::error(GL_INVALID_OPERATION);
8276 }
8277
8278 // Check for buffer overflow
8279 size_t offsetSize = static_cast<size_t>(offset);
8280 size_t lengthSize = static_cast<size_t>(length);
8281
8282 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8283 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8284 {
8285 return gl::error(GL_INVALID_VALUE);
8286 }
8287
8288 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008289 }
8290}
8291
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008292__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8293{
8294 struct Extension
8295 {
8296 const char *name;
8297 __eglMustCastToProperFunctionPointerType address;
8298 };
8299
8300 static const Extension glExtensions[] =
8301 {
8302 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008303 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008304 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008305 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8306 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8307 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8308 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8309 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8310 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8311 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008312 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008313 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008314 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8315 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8316 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8317 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008318 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8319 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8320 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8321 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8322 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8323 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8324 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008325 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008326 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8327 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8328 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008329 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008330 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8331 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8332 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008333 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8334 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8335 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008336
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008337 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008338 {
8339 if (strcmp(procname, glExtensions[ext].name) == 0)
8340 {
8341 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8342 }
8343 }
8344
8345 return NULL;
8346}
8347
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008348// Non-public functions used by EGL
8349
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008350bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008351{
8352 EVENT("(egl::Surface* surface = 0x%0.8p)",
8353 surface);
8354
Geoff Langbfdea662014-07-23 14:16:32 -04008355 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008356
Geoff Langbfdea662014-07-23 14:16:32 -04008357 if (context)
8358 {
8359 gl::Texture2D *textureObject = context->getTexture2D();
8360 ASSERT(textureObject != NULL);
8361
8362 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008363 {
Geoff Langbfdea662014-07-23 14:16:32 -04008364 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008365 }
Geoff Langbfdea662014-07-23 14:16:32 -04008366
8367 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008368 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008369
8370 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008371}
8372
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008373}