blob: 5561c7b4098ec08626a5374909da11da9ab8c513 [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
719 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, width, height))
720 {
721 return gl::error(GL_INVALID_VALUE);
722 }
723
724 switch (target)
725 {
726 case GL_TEXTURE_2D:
727 {
728 gl::Texture2D *texture = context->getTexture2D();
729 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
730 }
731 break;
732
733 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
734 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
735 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
736 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
737 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
738 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
739 {
740 gl::TextureCubeMap *texture = context->getTextureCubeMap();
741 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
742 }
743 break;
744
745 default:
746 return gl::error(GL_INVALID_ENUM);
747 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000748 }
749}
750
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000751void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
752 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000754 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000755 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000756 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000757 target, level, xoffset, yoffset, width, height, format, imageSize, data);
758
Geoff Langbfdea662014-07-23 14:16:32 -0400759 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +0000760
Geoff Langbfdea662014-07-23 14:16:32 -0400761 if (context)
762 {
763 if (context->getClientVersion() < 3 &&
764 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
765 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000766 {
Geoff Langbfdea662014-07-23 14:16:32 -0400767 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000768 }
Geoff Langbfdea662014-07-23 14:16:32 -0400769
770 if (context->getClientVersion() >= 3 &&
771 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
772 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
773 {
774 return;
775 }
776
777 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, width, height))
778 {
779 return gl::error(GL_INVALID_VALUE);
780 }
781
782 switch (target)
783 {
784 case GL_TEXTURE_2D:
785 {
786 gl::Texture2D *texture = context->getTexture2D();
787 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
788 }
789 break;
790
791 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
792 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
793 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
794 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
795 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
797 {
798 gl::TextureCubeMap *texture = context->getTextureCubeMap();
799 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
800 }
801 break;
802
803 default:
804 return gl::error(GL_INVALID_ENUM);
805 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000806 }
807}
808
809void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
810{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000811 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000812 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000813 target, level, internalformat, x, y, width, height, border);
814
Geoff Langbfdea662014-07-23 14:16:32 -0400815 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000816
Geoff Langbfdea662014-07-23 14:16:32 -0400817 if (context)
818 {
819 if (context->getClientVersion() < 3 &&
820 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
821 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000822 {
Geoff Langbfdea662014-07-23 14:16:32 -0400823 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000824 }
Geoff Langbfdea662014-07-23 14:16:32 -0400825
826 if (context->getClientVersion() >= 3 &&
827 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
828 0, 0, 0, x, y, width, height, border))
829 {
830 return;
831 }
832
833 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
834
835 switch (target)
836 {
837 case GL_TEXTURE_2D:
838 {
839 gl::Texture2D *texture = context->getTexture2D();
840 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
841 }
842 break;
843
844 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
845 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
846 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
847 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
848 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
850 {
851 gl::TextureCubeMap *texture = context->getTextureCubeMap();
852 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
853 }
854 break;
855
856 default:
857 return gl::error(GL_INVALID_ENUM);
858 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000859 }
860}
861
862void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
863{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000864 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000865 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000866 target, level, xoffset, yoffset, x, y, width, height);
867
Geoff Langbfdea662014-07-23 14:16:32 -0400868 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000869
Geoff Langbfdea662014-07-23 14:16:32 -0400870 if (context)
871 {
872 if (context->getClientVersion() < 3 &&
873 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
874 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000875 {
Geoff Langbfdea662014-07-23 14:16:32 -0400876 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000877 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000878
Geoff Langbfdea662014-07-23 14:16:32 -0400879 if (context->getClientVersion() >= 3 &&
880 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
881 xoffset, yoffset, 0, x, y, width, height, 0))
882 {
883 return;
884 }
885
886 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
887
888 switch (target)
889 {
890 case GL_TEXTURE_2D:
891 {
892 gl::Texture2D *texture = context->getTexture2D();
893 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
894 }
895 break;
896
897 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
898 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
899 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
900 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
901 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
902 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
903 {
904 gl::TextureCubeMap *texture = context->getTextureCubeMap();
905 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
906 }
907 break;
908
909 default:
910 return gl::error(GL_INVALID_ENUM);
911 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000912 }
913}
914
915GLuint __stdcall glCreateProgram(void)
916{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000917 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000918
Geoff Langbfdea662014-07-23 14:16:32 -0400919 gl::Context *context = gl::getNonLostContext();
920 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000921 {
Geoff Langbfdea662014-07-23 14:16:32 -0400922 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000923 }
924
925 return 0;
926}
927
928GLuint __stdcall glCreateShader(GLenum type)
929{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000930 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000931
Geoff Langbfdea662014-07-23 14:16:32 -0400932 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000933
Geoff Langbfdea662014-07-23 14:16:32 -0400934 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000935 {
Geoff Langbfdea662014-07-23 14:16:32 -0400936 switch (type)
937 {
938 case GL_FRAGMENT_SHADER:
939 case GL_VERTEX_SHADER:
940 return context->createShader(type);
941 default:
942 return gl::error(GL_INVALID_ENUM, 0);
943 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000944 }
945
946 return 0;
947}
948
949void __stdcall glCullFace(GLenum mode)
950{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000951 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000952
Geoff Langbfdea662014-07-23 14:16:32 -0400953 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000954 {
Geoff Langbfdea662014-07-23 14:16:32 -0400955 case GL_FRONT:
956 case GL_BACK:
957 case GL_FRONT_AND_BACK:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000958 {
Geoff Langbfdea662014-07-23 14:16:32 -0400959 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000960
Geoff Langbfdea662014-07-23 14:16:32 -0400961 if (context)
962 {
963 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000964 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000965 }
Geoff Langbfdea662014-07-23 14:16:32 -0400966 break;
967 default:
968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000969 }
970}
971
972void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
973{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000974 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000975
Geoff Langbfdea662014-07-23 14:16:32 -0400976 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000977 {
Geoff Langbfdea662014-07-23 14:16:32 -0400978 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000979 }
Geoff Langbfdea662014-07-23 14:16:32 -0400980
981 gl::Context *context = gl::getNonLostContext();
982
983 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000984 {
Geoff Langbfdea662014-07-23 14:16:32 -0400985 for (int i = 0; i < n; i++)
986 {
987 context->deleteBuffer(buffers[i]);
988 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000989 }
990}
991
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000992void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
993{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000994 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000995
Geoff Langbfdea662014-07-23 14:16:32 -0400996 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000997 {
Geoff Langbfdea662014-07-23 14:16:32 -0400998 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000999 }
Geoff Langbfdea662014-07-23 14:16:32 -04001000
1001 gl::Context *context = gl::getNonLostContext();
1002
1003 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001004 {
Geoff Langbfdea662014-07-23 14:16:32 -04001005 for (int i = 0; i < n; i++)
1006 {
1007 context->deleteFenceNV(fences[i]);
1008 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001009 }
1010}
1011
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001012void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1013{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001014 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001015
Geoff Langbfdea662014-07-23 14:16:32 -04001016 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001017 {
Geoff Langbfdea662014-07-23 14:16:32 -04001018 return gl::error(GL_INVALID_VALUE);
1019 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001020
Geoff Langbfdea662014-07-23 14:16:32 -04001021 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001022
Geoff Langbfdea662014-07-23 14:16:32 -04001023 if (context)
1024 {
1025 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001026 {
Geoff Langbfdea662014-07-23 14:16:32 -04001027 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001028 {
Geoff Langbfdea662014-07-23 14:16:32 -04001029 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001030 }
1031 }
1032 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001033}
1034
1035void __stdcall glDeleteProgram(GLuint program)
1036{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001037 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001038
Geoff Langbfdea662014-07-23 14:16:32 -04001039 if (program == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001040 {
Geoff Langbfdea662014-07-23 14:16:32 -04001041 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001042 }
Geoff Langbfdea662014-07-23 14:16:32 -04001043
1044 gl::Context *context = gl::getNonLostContext();
1045
1046 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001047 {
Geoff Langbfdea662014-07-23 14:16:32 -04001048 if (!context->getProgram(program))
1049 {
1050 if(context->getShader(program))
1051 {
1052 return gl::error(GL_INVALID_OPERATION);
1053 }
1054 else
1055 {
1056 return gl::error(GL_INVALID_VALUE);
1057 }
1058 }
1059
1060 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001061 }
1062}
1063
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001064void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1065{
1066 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1067
Geoff Langbfdea662014-07-23 14:16:32 -04001068 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001069 {
Geoff Langbfdea662014-07-23 14:16:32 -04001070 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001071 }
Geoff Langbfdea662014-07-23 14:16:32 -04001072
1073 gl::Context *context = gl::getNonLostContext();
1074
1075 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001076 {
Geoff Langbfdea662014-07-23 14:16:32 -04001077 for (int i = 0; i < n; i++)
1078 {
1079 context->deleteQuery(ids[i]);
1080 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001081 }
1082}
1083
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001084void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1085{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001086 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001087
Geoff Langbfdea662014-07-23 14:16:32 -04001088 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001089 {
Geoff Langbfdea662014-07-23 14:16:32 -04001090 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001091 }
Geoff Langbfdea662014-07-23 14:16:32 -04001092
1093 gl::Context *context = gl::getNonLostContext();
1094
1095 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001096 {
Geoff Langbfdea662014-07-23 14:16:32 -04001097 for (int i = 0; i < n; i++)
1098 {
1099 context->deleteRenderbuffer(renderbuffers[i]);
1100 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001101 }
1102}
1103
1104void __stdcall glDeleteShader(GLuint shader)
1105{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001106 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001107
Geoff Langbfdea662014-07-23 14:16:32 -04001108 if (shader == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001109 {
Geoff Langbfdea662014-07-23 14:16:32 -04001110 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001111 }
Geoff Langbfdea662014-07-23 14:16:32 -04001112
1113 gl::Context *context = gl::getNonLostContext();
1114
1115 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001116 {
Geoff Langbfdea662014-07-23 14:16:32 -04001117 if (!context->getShader(shader))
1118 {
1119 if(context->getProgram(shader))
1120 {
1121 return gl::error(GL_INVALID_OPERATION);
1122 }
1123 else
1124 {
1125 return gl::error(GL_INVALID_VALUE);
1126 }
1127 }
1128
1129 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001130 }
1131}
1132
1133void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1134{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001135 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001136
Geoff Langbfdea662014-07-23 14:16:32 -04001137 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001138 {
Geoff Langbfdea662014-07-23 14:16:32 -04001139 return gl::error(GL_INVALID_VALUE);
1140 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001141
Geoff Langbfdea662014-07-23 14:16:32 -04001142 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001143
Geoff Langbfdea662014-07-23 14:16:32 -04001144 if (context)
1145 {
1146 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001147 {
Geoff Langbfdea662014-07-23 14:16:32 -04001148 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001149 {
Geoff Langbfdea662014-07-23 14:16:32 -04001150 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001151 }
1152 }
1153 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001154}
1155
1156void __stdcall glDepthFunc(GLenum func)
1157{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001158 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001159
Geoff Langbfdea662014-07-23 14:16:32 -04001160 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001161 {
Geoff Langbfdea662014-07-23 14:16:32 -04001162 case GL_NEVER:
1163 case GL_ALWAYS:
1164 case GL_LESS:
1165 case GL_LEQUAL:
1166 case GL_EQUAL:
1167 case GL_GREATER:
1168 case GL_GEQUAL:
1169 case GL_NOTEQUAL:
1170 break;
1171 default:
1172 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001173 }
Geoff Langbfdea662014-07-23 14:16:32 -04001174
1175 gl::Context *context = gl::getNonLostContext();
1176
1177 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001178 {
Geoff Langbfdea662014-07-23 14:16:32 -04001179 context->getState().setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001180 }
1181}
1182
1183void __stdcall glDepthMask(GLboolean flag)
1184{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001185 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001186
Geoff Langbfdea662014-07-23 14:16:32 -04001187 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001188
Geoff Langbfdea662014-07-23 14:16:32 -04001189 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001190 {
Geoff Langbfdea662014-07-23 14:16:32 -04001191 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001192 }
1193}
1194
1195void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1196{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001197 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001198
Geoff Langbfdea662014-07-23 14:16:32 -04001199 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001200
Geoff Langbfdea662014-07-23 14:16:32 -04001201 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001202 {
Geoff Langbfdea662014-07-23 14:16:32 -04001203 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001204 }
1205}
1206
1207void __stdcall glDetachShader(GLuint program, GLuint shader)
1208{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001209 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001210
Geoff Langbfdea662014-07-23 14:16:32 -04001211 gl::Context *context = gl::getNonLostContext();
1212
1213 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001214 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001215
Geoff Langbfdea662014-07-23 14:16:32 -04001216 gl::Program *programObject = context->getProgram(program);
1217 gl::Shader *shaderObject = context->getShader(shader);
1218
1219 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001220 {
Geoff Langbfdea662014-07-23 14:16:32 -04001221 gl::Shader *shaderByProgramHandle;
1222 shaderByProgramHandle = context->getShader(program);
1223 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001224 {
Geoff Langbfdea662014-07-23 14:16:32 -04001225 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001226 }
Geoff Langbfdea662014-07-23 14:16:32 -04001227 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001229 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001230 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001231 }
Geoff Langbfdea662014-07-23 14:16:32 -04001232
1233 if (!shaderObject)
1234 {
1235 gl::Program *programByShaderHandle = context->getProgram(shader);
1236 if (!programByShaderHandle)
1237 {
1238 return gl::error(GL_INVALID_VALUE);
1239 }
1240 else
1241 {
1242 return gl::error(GL_INVALID_OPERATION);
1243 }
1244 }
1245
1246 if (!programObject->detachShader(shaderObject))
1247 {
1248 return gl::error(GL_INVALID_OPERATION);
1249 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001250 }
1251}
1252
1253void __stdcall glDisable(GLenum cap)
1254{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001255 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001256
Geoff Langbfdea662014-07-23 14:16:32 -04001257 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001258
Geoff Langbfdea662014-07-23 14:16:32 -04001259 if (context)
1260 {
1261 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001262 {
Geoff Langbfdea662014-07-23 14:16:32 -04001263 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001264 }
Geoff Langbfdea662014-07-23 14:16:32 -04001265
1266 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001267 }
1268}
1269
1270void __stdcall glDisableVertexAttribArray(GLuint index)
1271{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001272 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001273
Geoff Langbfdea662014-07-23 14:16:32 -04001274 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001275 {
Geoff Langbfdea662014-07-23 14:16:32 -04001276 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277 }
Geoff Langbfdea662014-07-23 14:16:32 -04001278
1279 gl::Context *context = gl::getNonLostContext();
1280
1281 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001282 {
Geoff Langbfdea662014-07-23 14:16:32 -04001283 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001284 }
1285}
1286
1287void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1288{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001289 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001290
Geoff Langbfdea662014-07-23 14:16:32 -04001291 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001292
Geoff Langbfdea662014-07-23 14:16:32 -04001293 if (context)
1294 {
1295 if (!ValidateDrawArrays(context, mode, first, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001296 {
Geoff Langbfdea662014-07-23 14:16:32 -04001297 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001298 }
Geoff Langbfdea662014-07-23 14:16:32 -04001299
1300 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001301 }
1302}
1303
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001304void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1305{
1306 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1307
Geoff Langbfdea662014-07-23 14:16:32 -04001308 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001309
Geoff Langbfdea662014-07-23 14:16:32 -04001310 if (context)
1311 {
1312 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001313 {
Geoff Langbfdea662014-07-23 14:16:32 -04001314 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001315 }
Geoff Langbfdea662014-07-23 14:16:32 -04001316
1317 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001318 }
1319}
1320
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001321void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001322{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001323 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 +00001324 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001325
Geoff Langbfdea662014-07-23 14:16:32 -04001326 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001327
Geoff Langbfdea662014-07-23 14:16:32 -04001328 if (context)
1329 {
1330 if (!ValidateDrawElements(context, mode, count, type, indices))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001331 {
Geoff Langbfdea662014-07-23 14:16:32 -04001332 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001333 }
Geoff Langbfdea662014-07-23 14:16:32 -04001334
1335 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001336 }
1337}
1338
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001339void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1340{
1341 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1342 mode, count, type, indices, primcount);
1343
Geoff Langbfdea662014-07-23 14:16:32 -04001344 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001345
Geoff Langbfdea662014-07-23 14:16:32 -04001346 if (context)
1347 {
1348 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001349 {
Geoff Langbfdea662014-07-23 14:16:32 -04001350 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001351 }
Geoff Langbfdea662014-07-23 14:16:32 -04001352
1353 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001354 }
1355}
1356
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001357void __stdcall glEnable(GLenum cap)
1358{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001359 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001360
Geoff Langbfdea662014-07-23 14:16:32 -04001361 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001362
Geoff Langbfdea662014-07-23 14:16:32 -04001363 if (context)
1364 {
1365 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001366 {
Geoff Langbfdea662014-07-23 14:16:32 -04001367 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001368 }
Geoff Langbfdea662014-07-23 14:16:32 -04001369
1370 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001371 }
1372}
1373
1374void __stdcall glEnableVertexAttribArray(GLuint index)
1375{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001376 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001377
Geoff Langbfdea662014-07-23 14:16:32 -04001378 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001379 {
Geoff Langbfdea662014-07-23 14:16:32 -04001380 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001381 }
Geoff Langbfdea662014-07-23 14:16:32 -04001382
1383 gl::Context *context = gl::getNonLostContext();
1384
1385 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001386 {
Geoff Langbfdea662014-07-23 14:16:32 -04001387 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001388 }
1389}
1390
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001391void __stdcall glEndQueryEXT(GLenum target)
1392{
1393 EVENT("GLenum target = 0x%X)", target);
1394
Geoff Langbfdea662014-07-23 14:16:32 -04001395 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001396
Geoff Langbfdea662014-07-23 14:16:32 -04001397 if (context)
1398 {
1399 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001400 {
Geoff Langbfdea662014-07-23 14:16:32 -04001401 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001402 }
Geoff Langbfdea662014-07-23 14:16:32 -04001403
1404 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001405 }
1406}
1407
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001408void __stdcall glFinishFenceNV(GLuint fence)
1409{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001410 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001411
Geoff Langbfdea662014-07-23 14:16:32 -04001412 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001413
Geoff Langbfdea662014-07-23 14:16:32 -04001414 if (context)
1415 {
1416 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1417
1418 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001419 {
Geoff Langbfdea662014-07-23 14:16:32 -04001420 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001421 }
Geoff Langbfdea662014-07-23 14:16:32 -04001422
1423 if (fenceObject->isFence() != GL_TRUE)
1424 {
1425 return gl::error(GL_INVALID_OPERATION);
1426 }
1427
1428 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001429 }
1430}
1431
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001432void __stdcall glFinish(void)
1433{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001434 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001435
Geoff Langbfdea662014-07-23 14:16:32 -04001436 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001437
Geoff Langbfdea662014-07-23 14:16:32 -04001438 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001439 {
Geoff Langbfdea662014-07-23 14:16:32 -04001440 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001441 }
1442}
1443
1444void __stdcall glFlush(void)
1445{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001446 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001447
Geoff Langbfdea662014-07-23 14:16:32 -04001448 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001449
Geoff Langbfdea662014-07-23 14:16:32 -04001450 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001451 {
Geoff Langbfdea662014-07-23 14:16:32 -04001452 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453 }
1454}
1455
1456void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1457{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001458 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001459 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001460
Geoff Langbfdea662014-07-23 14:16:32 -04001461 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001462 {
Geoff Langbfdea662014-07-23 14:16:32 -04001463 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001464 }
Geoff Langbfdea662014-07-23 14:16:32 -04001465
1466 gl::Context *context = gl::getNonLostContext();
1467
1468 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001469 {
Geoff Langbfdea662014-07-23 14:16:32 -04001470 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1471 {
1472 return;
1473 }
1474
1475 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1476 ASSERT(framebuffer);
1477
1478 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1479 {
1480 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1481 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1482 }
1483 else
1484 {
1485 switch (attachment)
1486 {
1487 case GL_DEPTH_ATTACHMENT:
1488 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1489 break;
1490 case GL_STENCIL_ATTACHMENT:
1491 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1492 break;
1493 case GL_DEPTH_STENCIL_ATTACHMENT:
1494 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1495 break;
1496 default:
1497 UNREACHABLE();
1498 break;
1499 }
1500 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001501 }
1502}
1503
1504void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001506 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001507 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001508
Geoff Langbfdea662014-07-23 14:16:32 -04001509 gl::Context *context = gl::getNonLostContext();
1510 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001511 {
Geoff Langbfdea662014-07-23 14:16:32 -04001512 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001513 {
Geoff Langbfdea662014-07-23 14:16:32 -04001514 return;
1515 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001516
Geoff Langbfdea662014-07-23 14:16:32 -04001517 if (texture == 0)
1518 {
1519 textarget = GL_NONE;
1520 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001521
Geoff Langbfdea662014-07-23 14:16:32 -04001522 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001523
Geoff Langbfdea662014-07-23 14:16:32 -04001524 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1525 {
1526 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1527 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1528 }
1529 else
1530 {
1531 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001532 {
Geoff Langbfdea662014-07-23 14:16:32 -04001533 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1534 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1535 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001536 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001537 }
1538 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001539}
1540
1541void __stdcall glFrontFace(GLenum mode)
1542{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001543 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001544
Geoff Langbfdea662014-07-23 14:16:32 -04001545 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001546 {
Geoff Langbfdea662014-07-23 14:16:32 -04001547 case GL_CW:
1548 case GL_CCW:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001549 {
Geoff Langbfdea662014-07-23 14:16:32 -04001550 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001551
Geoff Langbfdea662014-07-23 14:16:32 -04001552 if (context)
1553 {
1554 context->getState().setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001555 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001556 }
Geoff Langbfdea662014-07-23 14:16:32 -04001557 break;
1558 default:
1559 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001560 }
1561}
1562
1563void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1564{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001565 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001566
Geoff Langbfdea662014-07-23 14:16:32 -04001567 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001568 {
Geoff Langbfdea662014-07-23 14:16:32 -04001569 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001570 }
Geoff Langbfdea662014-07-23 14:16:32 -04001571
1572 gl::Context *context = gl::getNonLostContext();
1573
1574 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001575 {
Geoff Langbfdea662014-07-23 14:16:32 -04001576 for (int i = 0; i < n; i++)
1577 {
1578 buffers[i] = context->createBuffer();
1579 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001580 }
1581}
1582
1583void __stdcall glGenerateMipmap(GLenum target)
1584{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001585 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001586
Geoff Langbfdea662014-07-23 14:16:32 -04001587 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001588
Geoff Langbfdea662014-07-23 14:16:32 -04001589 if (context)
1590 {
1591 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001592 {
Geoff Langbfdea662014-07-23 14:16:32 -04001593 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001594 }
Geoff Langbfdea662014-07-23 14:16:32 -04001595
1596 gl::Texture *texture = context->getTargetTexture(target);
1597
1598 if (texture == NULL)
1599 {
1600 return gl::error(GL_INVALID_OPERATION);
1601 }
1602
1603 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1604 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
1605
1606 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1607 // unsized formats or that are color renderable and filterable. Since we do not track if
1608 // the texture was created with sized or unsized format (only sized formats are stored),
1609 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1610 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1611 // textures since they're the only texture format that can be created with unsized formats
1612 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1613 // was the last version to use add them.
1614 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1615 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1616 internalFormat == GL_ALPHA8_EXT;
1617
1618 if (gl::GetDepthBits(internalFormat) > 0 || gl::GetStencilBits(internalFormat) > 0 || !formatCaps.filterable ||
1619 (!formatCaps.renderable && !isLUMA) || gl::IsFormatCompressed(internalFormat))
1620 {
1621 return gl::error(GL_INVALID_OPERATION);
1622 }
1623
1624 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
1625 if (context->getClientVersion() == 2 && gl::GetColorEncoding(internalFormat) == GL_SRGB)
1626 {
1627 return gl::error(GL_INVALID_OPERATION);
1628 }
1629
1630 // Non-power of 2 ES2 check
1631 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1632 {
1633 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
1634 return gl::error(GL_INVALID_OPERATION);
1635 }
1636
1637 // Cube completeness check
1638 if (target == GL_TEXTURE_CUBE_MAP)
1639 {
1640 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1641 if (!textureCube->isCubeComplete())
1642 {
1643 return gl::error(GL_INVALID_OPERATION);
1644 }
1645 }
1646
1647 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001648 }
1649}
1650
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001651void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1652{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001653 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001654
Geoff Langbfdea662014-07-23 14:16:32 -04001655 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001656 {
Geoff Langbfdea662014-07-23 14:16:32 -04001657 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001658 }
Geoff Langbfdea662014-07-23 14:16:32 -04001659
1660 gl::Context *context = gl::getNonLostContext();
1661
1662 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001663 {
Geoff Langbfdea662014-07-23 14:16:32 -04001664 for (int i = 0; i < n; i++)
1665 {
1666 fences[i] = context->createFenceNV();
1667 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001668 }
1669}
1670
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001671void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1672{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001673 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001674
Geoff Langbfdea662014-07-23 14:16:32 -04001675 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001676 {
Geoff Langbfdea662014-07-23 14:16:32 -04001677 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001678 }
Geoff Langbfdea662014-07-23 14:16:32 -04001679
1680 gl::Context *context = gl::getNonLostContext();
1681
1682 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001683 {
Geoff Langbfdea662014-07-23 14:16:32 -04001684 for (int i = 0; i < n; i++)
1685 {
1686 framebuffers[i] = context->createFramebuffer();
1687 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001688 }
1689}
1690
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001691void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1692{
1693 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1694
Geoff Langbfdea662014-07-23 14:16:32 -04001695 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001696
Geoff Langbfdea662014-07-23 14:16:32 -04001697 if (context)
1698 {
1699 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001700 {
Geoff Langbfdea662014-07-23 14:16:32 -04001701 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001702 }
Geoff Langbfdea662014-07-23 14:16:32 -04001703
1704 for (GLsizei i = 0; i < n; i++)
1705 {
1706 ids[i] = context->createQuery();
1707 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001708 }
1709}
1710
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001711void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1712{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001713 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001714
Geoff Langbfdea662014-07-23 14:16:32 -04001715 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001716 {
Geoff Langbfdea662014-07-23 14:16:32 -04001717 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001718 }
Geoff Langbfdea662014-07-23 14:16:32 -04001719
1720 gl::Context *context = gl::getNonLostContext();
1721
1722 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001723 {
Geoff Langbfdea662014-07-23 14:16:32 -04001724 for (int i = 0; i < n; i++)
1725 {
1726 renderbuffers[i] = context->createRenderbuffer();
1727 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001728 }
1729}
1730
1731void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1732{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001733 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001734
Geoff Langbfdea662014-07-23 14:16:32 -04001735 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001736 {
Geoff Langbfdea662014-07-23 14:16:32 -04001737 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001738 }
Geoff Langbfdea662014-07-23 14:16:32 -04001739
1740 gl::Context *context = gl::getNonLostContext();
1741
1742 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001743 {
Geoff Langbfdea662014-07-23 14:16:32 -04001744 for (int i = 0; i < n; i++)
1745 {
1746 textures[i] = context->createTexture();
1747 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001748 }
1749}
1750
daniel@transgaming.com85423182010-04-22 13:35:27 +00001751void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001752{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001753 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001754 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001755 program, index, bufsize, length, size, type, name);
1756
Geoff Langbfdea662014-07-23 14:16:32 -04001757 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001758 {
Geoff Langbfdea662014-07-23 14:16:32 -04001759 return gl::error(GL_INVALID_VALUE);
1760 }
1761
1762 gl::Context *context = gl::getNonLostContext();
1763
1764 if (context)
1765 {
1766 gl::Program *programObject = context->getProgram(program);
1767
1768 if (!programObject)
1769 {
1770 if (context->getShader(program))
1771 {
1772 return gl::error(GL_INVALID_OPERATION);
1773 }
1774 else
1775 {
1776 return gl::error(GL_INVALID_VALUE);
1777 }
1778 }
1779
1780 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001782 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001783 }
1784
Geoff Langbfdea662014-07-23 14:16:32 -04001785 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001786 }
1787}
1788
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001789void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001790{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001791 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001792 "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 +00001793 program, index, bufsize, length, size, type, name);
1794
Geoff Langbfdea662014-07-23 14:16:32 -04001795 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001796 {
Geoff Langbfdea662014-07-23 14:16:32 -04001797 return gl::error(GL_INVALID_VALUE);
1798 }
1799
1800 gl::Context *context = gl::getNonLostContext();
1801
1802 if (context)
1803 {
1804 gl::Program *programObject = context->getProgram(program);
1805
1806 if (!programObject)
1807 {
1808 if (context->getShader(program))
1809 {
1810 return gl::error(GL_INVALID_OPERATION);
1811 }
1812 else
1813 {
1814 return gl::error(GL_INVALID_VALUE);
1815 }
1816 }
1817
1818 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001820 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001821 }
1822
Geoff Langbfdea662014-07-23 14:16:32 -04001823 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001824 }
1825}
1826
1827void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1828{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001829 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 +00001830 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001831
Geoff Langbfdea662014-07-23 14:16:32 -04001832 if (maxcount < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001833 {
Geoff Langbfdea662014-07-23 14:16:32 -04001834 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001835 }
Geoff Langbfdea662014-07-23 14:16:32 -04001836
1837 gl::Context *context = gl::getNonLostContext();
1838
1839 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001840 {
Geoff Langbfdea662014-07-23 14:16:32 -04001841 gl::Program *programObject = context->getProgram(program);
1842
1843 if (!programObject)
1844 {
1845 if (context->getShader(program))
1846 {
1847 return gl::error(GL_INVALID_OPERATION);
1848 }
1849 else
1850 {
1851 return gl::error(GL_INVALID_VALUE);
1852 }
1853 }
1854
1855 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001856 }
1857}
1858
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001859int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001860{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001861 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001862
Geoff Langbfdea662014-07-23 14:16:32 -04001863 gl::Context *context = gl::getNonLostContext();
1864
1865 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001866 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001867
Geoff Langbfdea662014-07-23 14:16:32 -04001868 gl::Program *programObject = context->getProgram(program);
1869
1870 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001871 {
Geoff Langbfdea662014-07-23 14:16:32 -04001872 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001873 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001874 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001875 }
Geoff Langbfdea662014-07-23 14:16:32 -04001876 else
1877 {
1878 return gl::error(GL_INVALID_VALUE, -1);
1879 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001880 }
Geoff Langbfdea662014-07-23 14:16:32 -04001881
1882 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1883 if (!programObject->isLinked() || !programBinary)
1884 {
1885 return gl::error(GL_INVALID_OPERATION, -1);
1886 }
1887
1888 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001889 }
1890
1891 return -1;
1892}
1893
1894void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1895{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001896 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001897
Geoff Langbfdea662014-07-23 14:16:32 -04001898 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00001899
Geoff Langbfdea662014-07-23 14:16:32 -04001900 if (context)
1901 {
1902 GLenum nativeType;
1903 unsigned int numParams = 0;
1904 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001905 {
Geoff Langbfdea662014-07-23 14:16:32 -04001906 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001907 }
Geoff Langbfdea662014-07-23 14:16:32 -04001908
1909 if (nativeType == GL_BOOL)
1910 {
1911 context->getBooleanv(pname, params);
1912 }
1913 else
1914 {
1915 CastStateValues(context, nativeType, pname, numParams, params);
1916 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001917 }
1918}
1919
1920void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1921{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001922 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 +00001923
Geoff Langbfdea662014-07-23 14:16:32 -04001924 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001925
Geoff Langbfdea662014-07-23 14:16:32 -04001926 if (context)
1927 {
1928 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001929 {
Geoff Langbfdea662014-07-23 14:16:32 -04001930 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001931 }
Geoff Langbfdea662014-07-23 14:16:32 -04001932
1933 if (!gl::ValidBufferParameter(context, pname))
1934 {
1935 return gl::error(GL_INVALID_ENUM);
1936 }
1937
1938 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
1939
1940 if (!buffer)
1941 {
1942 // A null buffer means that "0" is bound to the requested buffer target
1943 return gl::error(GL_INVALID_OPERATION);
1944 }
1945
1946 switch (pname)
1947 {
1948 case GL_BUFFER_USAGE:
1949 *params = static_cast<GLint>(buffer->getUsage());
1950 break;
1951 case GL_BUFFER_SIZE:
1952 *params = gl::clampCast<GLint>(buffer->getSize());
1953 break;
1954 case GL_BUFFER_ACCESS_FLAGS:
1955 *params = buffer->getAccessFlags();
1956 break;
1957 case GL_BUFFER_MAPPED:
1958 *params = static_cast<GLint>(buffer->isMapped());
1959 break;
1960 case GL_BUFFER_MAP_OFFSET:
1961 *params = gl::clampCast<GLint>(buffer->getMapOffset());
1962 break;
1963 case GL_BUFFER_MAP_LENGTH:
1964 *params = gl::clampCast<GLint>(buffer->getMapLength());
1965 break;
1966 default: UNREACHABLE(); break;
1967 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001968 }
1969}
1970
1971GLenum __stdcall glGetError(void)
1972{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001973 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001974
1975 gl::Context *context = gl::getContext();
1976
1977 if (context)
1978 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00001979 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001980 }
1981
1982 return GL_NO_ERROR;
1983}
1984
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001985void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
1986{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001987 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001988
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001989
Geoff Langbfdea662014-07-23 14:16:32 -04001990 gl::Context *context = gl::getNonLostContext();
1991
1992 if (context)
1993 {
1994 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1995
1996 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001997 {
Geoff Langbfdea662014-07-23 14:16:32 -04001998 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001999 }
Geoff Langbfdea662014-07-23 14:16:32 -04002000
2001 if (fenceObject->isFence() != GL_TRUE)
2002 {
2003 return gl::error(GL_INVALID_OPERATION);
2004 }
2005
2006 switch (pname)
2007 {
2008 case GL_FENCE_STATUS_NV:
2009 case GL_FENCE_CONDITION_NV:
2010 break;
2011
2012 default: return gl::error(GL_INVALID_ENUM);
2013 }
2014
2015 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002016 }
2017}
2018
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002019void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2020{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002021 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002022
Geoff Langbfdea662014-07-23 14:16:32 -04002023 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002024
Geoff Langbfdea662014-07-23 14:16:32 -04002025 if (context)
2026 {
2027 GLenum nativeType;
2028 unsigned int numParams = 0;
2029 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002030 {
Geoff Langbfdea662014-07-23 14:16:32 -04002031 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002032 }
Geoff Langbfdea662014-07-23 14:16:32 -04002033
2034 if (nativeType == GL_FLOAT)
2035 {
2036 context->getFloatv(pname, params);
2037 }
2038 else
2039 {
2040 CastStateValues(context, nativeType, pname, numParams, params);
2041 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002042 }
2043}
2044
2045void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2046{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002047 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 +00002048 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002049
Geoff Langbfdea662014-07-23 14:16:32 -04002050 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002051
Geoff Langbfdea662014-07-23 14:16:32 -04002052 if (context)
2053 {
2054 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002055 {
Geoff Langbfdea662014-07-23 14:16:32 -04002056 return gl::error(GL_INVALID_ENUM);
2057 }
2058
2059 int clientVersion = context->getClientVersion();
2060
2061 switch (pname)
2062 {
2063 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2064 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2065 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2066 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2067 break;
2068 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2069 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002071 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002072 }
Geoff Langbfdea662014-07-23 14:16:32 -04002073 break;
2074 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2075 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2076 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2077 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2078 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2079 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2080 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2081 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2082 if (clientVersion < 3)
2083 {
2084 return gl::error(GL_INVALID_ENUM);
2085 }
2086 break;
2087 default:
2088 return gl::error(GL_INVALID_ENUM);
2089 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002090
Geoff Langbfdea662014-07-23 14:16:32 -04002091 // Determine if the attachment is a valid enum
2092 switch (attachment)
2093 {
2094 case GL_BACK:
2095 case GL_FRONT:
2096 case GL_DEPTH:
2097 case GL_STENCIL:
2098 case GL_DEPTH_STENCIL_ATTACHMENT:
2099 if (clientVersion < 3)
2100 {
2101 return gl::error(GL_INVALID_ENUM);
2102 }
2103 break;
2104
2105 case GL_DEPTH_ATTACHMENT:
2106 case GL_STENCIL_ATTACHMENT:
2107 break;
2108
2109 default:
2110 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2111 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2112 {
2113 return gl::error(GL_INVALID_ENUM);
2114 }
2115 break;
2116 }
2117
2118 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2119 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2120
2121 if (framebufferHandle == 0)
2122 {
2123 if (clientVersion < 3)
2124 {
2125 return gl::error(GL_INVALID_OPERATION);
2126 }
2127
2128 switch (attachment)
2129 {
2130 case GL_BACK:
2131 case GL_DEPTH:
2132 case GL_STENCIL:
2133 break;
2134 default:
2135 return gl::error(GL_INVALID_OPERATION);
2136 }
2137 }
2138 else
2139 {
2140 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2141 {
2142 // Valid attachment query
2143 }
2144 else
2145 {
2146 switch (attachment)
2147 {
2148 case GL_DEPTH_ATTACHMENT:
2149 case GL_STENCIL_ATTACHMENT:
2150 break;
2151 case GL_DEPTH_STENCIL_ATTACHMENT:
2152 if (framebuffer->hasValidDepthStencil())
2153 {
2154 return gl::error(GL_INVALID_OPERATION);
2155 }
2156 break;
2157 default:
2158 return gl::error(GL_INVALID_OPERATION);
2159 }
2160 }
2161 }
2162
2163 GLenum attachmentType = GL_NONE;
2164 GLuint attachmentHandle = 0;
2165 GLuint attachmentLevel = 0;
2166 GLuint attachmentLayer = 0;
2167
2168 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2169
2170 if (attachmentObject)
2171 {
2172 attachmentType = attachmentObject->type();
2173 attachmentHandle = attachmentObject->id();
2174 attachmentLevel = attachmentObject->mipLevel();
2175 attachmentLayer = attachmentObject->layer();
2176 }
2177
2178 GLenum attachmentObjectType; // Type category
2179 if (framebufferHandle == 0)
2180 {
2181 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2182 }
2183 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2184 {
2185 attachmentObjectType = attachmentType;
2186 }
2187 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2188 {
2189 attachmentObjectType = GL_TEXTURE;
2190 }
2191 else
2192 {
2193 UNREACHABLE();
2194 return;
2195 }
2196
2197 if (attachmentObjectType == GL_NONE)
2198 {
2199 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2200 // is NONE, then querying any other pname will generate INVALID_ENUM.
2201
2202 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2203 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2204 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002205
Geoff Lang646559f2013-08-15 11:08:15 -04002206 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002207 {
Geoff Lang646559f2013-08-15 11:08:15 -04002208 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002209 *params = attachmentObjectType;
2210 break;
2211
Geoff Lang646559f2013-08-15 11:08:15 -04002212 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002213 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002214 {
Geoff Lang05b05022014-06-11 15:31:45 -04002215 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002216 }
Geoff Langbfdea662014-07-23 14:16:32 -04002217 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002218 break;
2219
2220 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002221 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002222 {
Geoff Langbfdea662014-07-23 14:16:32 -04002223 return gl::error(GL_INVALID_ENUM);
Geoff Lang646559f2013-08-15 11:08:15 -04002224 }
2225 else
2226 {
Geoff Langbfdea662014-07-23 14:16:32 -04002227 gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002228 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002229 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002230 }
Geoff Langbfdea662014-07-23 14:16:32 -04002231 else
2232 {
2233 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2234 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2235 ASSERT(attachmentObject != NULL);
2236
2237 switch (pname)
2238 {
2239 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2240 *params = attachmentObjectType;
2241 break;
2242
2243 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2244 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2245 {
2246 return gl::error(GL_INVALID_ENUM);
2247 }
2248 *params = attachmentHandle;
2249 break;
2250
2251 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2252 if (attachmentObjectType != GL_TEXTURE)
2253 {
2254 return gl::error(GL_INVALID_ENUM);
2255 }
2256 *params = attachmentLevel;
2257 break;
2258
2259 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2260 if (attachmentObjectType != GL_TEXTURE)
2261 {
2262 return gl::error(GL_INVALID_ENUM);
2263 }
2264 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2265 break;
2266
2267 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2268 *params = attachmentObject->getRedSize();
2269 break;
2270
2271 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2272 *params = attachmentObject->getGreenSize();
2273 break;
2274
2275 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2276 *params = attachmentObject->getBlueSize();
2277 break;
2278
2279 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2280 *params = attachmentObject->getAlphaSize();
2281 break;
2282
2283 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2284 *params = attachmentObject->getDepthSize();
2285 break;
2286
2287 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2288 *params = attachmentObject->getStencilSize();
2289 break;
2290
2291 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2292 if (attachment == GL_DEPTH_STENCIL)
2293 {
2294 gl::error(GL_INVALID_OPERATION);
2295 }
2296 *params = attachmentObject->getComponentType();
2297 break;
2298
2299 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2300 *params = attachmentObject->getColorEncoding();
2301 break;
2302
2303 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2304 if (attachmentObjectType != GL_TEXTURE)
2305 {
2306 return gl::error(GL_INVALID_ENUM);
2307 }
2308 *params = attachmentLayer;
2309 break;
2310
2311 default:
2312 UNREACHABLE();
2313 break;
2314 }
2315 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002316 }
2317}
2318
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002319GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2320{
2321 EVENT("()");
2322
Geoff Langbfdea662014-07-23 14:16:32 -04002323 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002324
Geoff Langbfdea662014-07-23 14:16:32 -04002325 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002326 {
Geoff Langbfdea662014-07-23 14:16:32 -04002327 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002328 }
Geoff Langbfdea662014-07-23 14:16:32 -04002329
2330 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002331}
2332
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002333void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2334{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002335 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002336
Geoff Langbfdea662014-07-23 14:16:32 -04002337 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002338
Geoff Langbfdea662014-07-23 14:16:32 -04002339 if (context)
2340 {
2341 GLenum nativeType;
2342 unsigned int numParams = 0;
2343
2344 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002345 {
Geoff Langbfdea662014-07-23 14:16:32 -04002346 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002347 }
Geoff Langbfdea662014-07-23 14:16:32 -04002348
2349 if (nativeType == GL_INT)
2350 {
2351 context->getIntegerv(pname, params);
2352 }
2353 else
2354 {
2355 CastStateValues(context, nativeType, pname, numParams, params);
2356 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002357 }
2358}
2359
2360void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2361{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002362 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002363
Geoff Langbfdea662014-07-23 14:16:32 -04002364 gl::Context *context = gl::getNonLostContext();
2365
2366 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002367 {
Geoff Langbfdea662014-07-23 14:16:32 -04002368 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002369
Geoff Langbfdea662014-07-23 14:16:32 -04002370 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002371 {
Geoff Langbfdea662014-07-23 14:16:32 -04002372 return gl::error(GL_INVALID_VALUE);
2373 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002374
Geoff Langbfdea662014-07-23 14:16:32 -04002375 if (context->getClientVersion() < 3)
2376 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002377 switch (pname)
2378 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002379 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002380 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002381 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002382 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002383 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002384 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002385 }
2386 }
Geoff Langbfdea662014-07-23 14:16:32 -04002387
2388 switch (pname)
2389 {
2390 case GL_DELETE_STATUS:
2391 *params = programObject->isFlaggedForDeletion();
2392 return;
2393 case GL_LINK_STATUS:
2394 *params = programObject->isLinked();
2395 return;
2396 case GL_VALIDATE_STATUS:
2397 *params = programObject->isValidated();
2398 return;
2399 case GL_INFO_LOG_LENGTH:
2400 *params = programObject->getInfoLogLength();
2401 return;
2402 case GL_ATTACHED_SHADERS:
2403 *params = programObject->getAttachedShadersCount();
2404 return;
2405 case GL_ACTIVE_ATTRIBUTES:
2406 *params = programObject->getActiveAttributeCount();
2407 return;
2408 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2409 *params = programObject->getActiveAttributeMaxLength();
2410 return;
2411 case GL_ACTIVE_UNIFORMS:
2412 *params = programObject->getActiveUniformCount();
2413 return;
2414 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2415 *params = programObject->getActiveUniformMaxLength();
2416 return;
2417 case GL_PROGRAM_BINARY_LENGTH_OES:
2418 *params = programObject->getProgramBinaryLength();
2419 return;
2420 case GL_ACTIVE_UNIFORM_BLOCKS:
2421 *params = programObject->getActiveUniformBlockCount();
2422 return;
2423 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2424 *params = programObject->getActiveUniformBlockMaxLength();
2425 break;
2426 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2427 *params = programObject->getTransformFeedbackBufferMode();
2428 break;
2429 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2430 *params = programObject->getTransformFeedbackVaryingCount();
2431 break;
2432 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2433 *params = programObject->getTransformFeedbackVaryingMaxLength();
2434 break;
2435 default:
2436 return gl::error(GL_INVALID_ENUM);
2437 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002438 }
2439}
2440
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002441void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002443 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 +00002444 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002445
Geoff Langbfdea662014-07-23 14:16:32 -04002446 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002447 {
Geoff Langbfdea662014-07-23 14:16:32 -04002448 return gl::error(GL_INVALID_VALUE);
2449 }
2450
2451 gl::Context *context = gl::getNonLostContext();
2452
2453 if (context)
2454 {
2455 gl::Program *programObject = context->getProgram(program);
2456
2457 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002458 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002459 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460 }
2461
Geoff Langbfdea662014-07-23 14:16:32 -04002462 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 }
2464}
2465
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002466void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2467{
2468 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2469
Geoff Langbfdea662014-07-23 14:16:32 -04002470 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002471
Geoff Langbfdea662014-07-23 14:16:32 -04002472 if (context)
2473 {
2474 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002475 {
Geoff Langbfdea662014-07-23 14:16:32 -04002476 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002477 }
Geoff Langbfdea662014-07-23 14:16:32 -04002478
2479 switch (pname)
2480 {
2481 case GL_CURRENT_QUERY_EXT:
2482 params[0] = context->getState().getActiveQueryId(target);
2483 break;
2484
2485 default:
2486 return gl::error(GL_INVALID_ENUM);
2487 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002488 }
2489}
2490
2491void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2492{
2493 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2494
Geoff Langbfdea662014-07-23 14:16:32 -04002495 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002496
Geoff Langbfdea662014-07-23 14:16:32 -04002497 if (context)
2498 {
2499 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2500
2501 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002502 {
Geoff Langbfdea662014-07-23 14:16:32 -04002503 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002504 }
Geoff Langbfdea662014-07-23 14:16:32 -04002505
2506 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2507 {
2508 return gl::error(GL_INVALID_OPERATION);
2509 }
2510
2511 switch(pname)
2512 {
2513 case GL_QUERY_RESULT_EXT:
2514 params[0] = queryObject->getResult();
2515 break;
2516 case GL_QUERY_RESULT_AVAILABLE_EXT:
2517 params[0] = queryObject->isResultAvailable();
2518 break;
2519 default:
2520 return gl::error(GL_INVALID_ENUM);
2521 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002522 }
2523}
2524
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002525void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2526{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002527 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 +00002528
Geoff Langbfdea662014-07-23 14:16:32 -04002529 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002530
Geoff Langbfdea662014-07-23 14:16:32 -04002531 if (context)
2532 {
2533 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002534 {
Geoff Langbfdea662014-07-23 14:16:32 -04002535 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002536 }
Geoff Langbfdea662014-07-23 14:16:32 -04002537
2538 if (context->getState().getRenderbufferId() == 0)
2539 {
2540 return gl::error(GL_INVALID_OPERATION);
2541 }
2542
2543 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2544
2545 switch (pname)
2546 {
2547 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2548 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2549 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2550 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2551 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2552 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2553 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2554 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2555 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
2556 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2557 if (!context->getExtensions().framebufferMultisample)
2558 {
2559 return gl::error(GL_INVALID_ENUM);
2560 }
2561 *params = renderbuffer->getSamples();
2562 break;
2563 default:
2564 return gl::error(GL_INVALID_ENUM);
2565 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002566 }
2567}
2568
2569void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2570{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002571 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002572
Geoff Langbfdea662014-07-23 14:16:32 -04002573 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002574
Geoff Langbfdea662014-07-23 14:16:32 -04002575 if (context)
2576 {
2577 gl::Shader *shaderObject = context->getShader(shader);
2578
2579 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002580 {
Geoff Langbfdea662014-07-23 14:16:32 -04002581 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002582 }
Geoff Langbfdea662014-07-23 14:16:32 -04002583
2584 switch (pname)
2585 {
2586 case GL_SHADER_TYPE:
2587 *params = shaderObject->getType();
2588 return;
2589 case GL_DELETE_STATUS:
2590 *params = shaderObject->isFlaggedForDeletion();
2591 return;
2592 case GL_COMPILE_STATUS:
2593 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2594 return;
2595 case GL_INFO_LOG_LENGTH:
2596 *params = shaderObject->getInfoLogLength();
2597 return;
2598 case GL_SHADER_SOURCE_LENGTH:
2599 *params = shaderObject->getSourceLength();
2600 return;
2601 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2602 *params = shaderObject->getTranslatedSourceLength();
2603 return;
2604 default:
2605 return gl::error(GL_INVALID_ENUM);
2606 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002607 }
2608}
2609
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002610void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002611{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002612 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 +00002613 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002614
Geoff Langbfdea662014-07-23 14:16:32 -04002615 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002616 {
Geoff Langbfdea662014-07-23 14:16:32 -04002617 return gl::error(GL_INVALID_VALUE);
2618 }
2619
2620 gl::Context *context = gl::getNonLostContext();
2621
2622 if (context)
2623 {
2624 gl::Shader *shaderObject = context->getShader(shader);
2625
2626 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002628 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002629 }
2630
Geoff Langbfdea662014-07-23 14:16:32 -04002631 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002632 }
2633}
2634
2635void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2636{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002637 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 +00002638 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002639
Geoff Langbfdea662014-07-23 14:16:32 -04002640 switch (shadertype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002641 {
Geoff Langbfdea662014-07-23 14:16:32 -04002642 case GL_VERTEX_SHADER:
2643 case GL_FRAGMENT_SHADER:
2644 break;
2645 default:
2646 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002647 }
Geoff Langbfdea662014-07-23 14:16:32 -04002648
2649 switch (precisiontype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002650 {
Geoff Langbfdea662014-07-23 14:16:32 -04002651 case GL_LOW_FLOAT:
2652 case GL_MEDIUM_FLOAT:
2653 case GL_HIGH_FLOAT:
2654 // Assume IEEE 754 precision
2655 range[0] = 127;
2656 range[1] = 127;
2657 *precision = 23;
2658 break;
2659 case GL_LOW_INT:
2660 case GL_MEDIUM_INT:
2661 case GL_HIGH_INT:
2662 // Some (most) hardware only supports single-precision floating-point numbers,
2663 // which can accurately represent integers up to +/-16777216
2664 range[0] = 24;
2665 range[1] = 24;
2666 *precision = 0;
2667 break;
2668 default:
2669 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002670 }
2671}
2672
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002673void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002674{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002675 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 +00002676 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002677
Geoff Langbfdea662014-07-23 14:16:32 -04002678 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002679 {
Geoff Langbfdea662014-07-23 14:16:32 -04002680 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002681 }
Geoff Langbfdea662014-07-23 14:16:32 -04002682
2683 gl::Context *context = gl::getNonLostContext();
2684
2685 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002686 {
Geoff Langbfdea662014-07-23 14:16:32 -04002687 gl::Shader *shaderObject = context->getShader(shader);
2688
2689 if (!shaderObject)
2690 {
2691 return gl::error(GL_INVALID_OPERATION);
2692 }
2693
2694 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002695 }
2696}
2697
zmo@google.coma574f782011-10-03 21:45:23 +00002698void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2699{
2700 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2701 shader, bufsize, length, source);
2702
Geoff Langbfdea662014-07-23 14:16:32 -04002703 if (bufsize < 0)
zmo@google.coma574f782011-10-03 21:45:23 +00002704 {
Geoff Langbfdea662014-07-23 14:16:32 -04002705 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00002706 }
Geoff Langbfdea662014-07-23 14:16:32 -04002707
2708 gl::Context *context = gl::getNonLostContext();
2709
2710 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002711 {
Geoff Langbfdea662014-07-23 14:16:32 -04002712 gl::Shader *shaderObject = context->getShader(shader);
2713
2714 if (!shaderObject)
2715 {
2716 return gl::error(GL_INVALID_OPERATION);
2717 }
2718
2719 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002720 }
2721}
2722
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002723const GLubyte* __stdcall glGetString(GLenum name)
2724{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002725 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726
Geoff Langbfdea662014-07-23 14:16:32 -04002727 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002728
Geoff Langbfdea662014-07-23 14:16:32 -04002729 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002730 {
Geoff Langbfdea662014-07-23 14:16:32 -04002731 case GL_VENDOR:
2732 return (GLubyte*)"Google Inc.";
2733 case GL_RENDERER:
2734 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
2735 case GL_VERSION:
2736 if (context->getClientVersion() == 2)
2737 {
2738 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2739 }
2740 else
2741 {
2742 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2743 }
2744 case GL_SHADING_LANGUAGE_VERSION:
2745 if (context->getClientVersion() == 2)
2746 {
2747 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2748 }
2749 else
2750 {
2751 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2752 }
2753 case GL_EXTENSIONS:
2754 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
2755 default:
2756 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002757 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002758}
2759
2760void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2761{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002762 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 +00002763
Geoff Langbfdea662014-07-23 14:16:32 -04002764 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002765
Geoff Langbfdea662014-07-23 14:16:32 -04002766 if (context)
2767 {
2768 gl::Texture *texture = context->getTargetTexture(target);
2769
2770 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002771 {
Geoff Langbfdea662014-07-23 14:16:32 -04002772 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002773 }
Geoff Langbfdea662014-07-23 14:16:32 -04002774
2775 switch (pname)
2776 {
2777 case GL_TEXTURE_MAG_FILTER:
2778 *params = (GLfloat)texture->getSamplerState().magFilter;
2779 break;
2780 case GL_TEXTURE_MIN_FILTER:
2781 *params = (GLfloat)texture->getSamplerState().minFilter;
2782 break;
2783 case GL_TEXTURE_WRAP_S:
2784 *params = (GLfloat)texture->getSamplerState().wrapS;
2785 break;
2786 case GL_TEXTURE_WRAP_T:
2787 *params = (GLfloat)texture->getSamplerState().wrapT;
2788 break;
2789 case GL_TEXTURE_WRAP_R:
2790 if (context->getClientVersion() < 3)
2791 {
2792 return gl::error(GL_INVALID_ENUM);
2793 }
2794 *params = (GLfloat)texture->getSamplerState().wrapR;
2795 break;
2796 case GL_TEXTURE_IMMUTABLE_FORMAT:
2797 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2798 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2799 break;
2800 case GL_TEXTURE_IMMUTABLE_LEVELS:
2801 if (context->getClientVersion() < 3)
2802 {
2803 return gl::error(GL_INVALID_ENUM);
2804 }
2805 *params = (GLfloat)texture->immutableLevelCount();
2806 break;
2807 case GL_TEXTURE_USAGE_ANGLE:
2808 *params = (GLfloat)texture->getUsage();
2809 break;
2810 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2811 if (!context->getExtensions().textureFilterAnisotropic)
2812 {
2813 return gl::error(GL_INVALID_ENUM);
2814 }
2815 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2816 break;
2817 case GL_TEXTURE_SWIZZLE_R:
2818 if (context->getClientVersion() < 3)
2819 {
2820 return gl::error(GL_INVALID_ENUM);
2821 }
2822 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2823 break;
2824 case GL_TEXTURE_SWIZZLE_G:
2825 if (context->getClientVersion() < 3)
2826 {
2827 return gl::error(GL_INVALID_ENUM);
2828 }
2829 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2830 break;
2831 case GL_TEXTURE_SWIZZLE_B:
2832 if (context->getClientVersion() < 3)
2833 {
2834 return gl::error(GL_INVALID_ENUM);
2835 }
2836 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2837 break;
2838 case GL_TEXTURE_SWIZZLE_A:
2839 if (context->getClientVersion() < 3)
2840 {
2841 return gl::error(GL_INVALID_ENUM);
2842 }
2843 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2844 break;
2845 case GL_TEXTURE_BASE_LEVEL:
2846 if (context->getClientVersion() < 3)
2847 {
2848 return gl::error(GL_INVALID_ENUM);
2849 }
2850 *params = (GLfloat)texture->getSamplerState().baseLevel;
2851 break;
2852 case GL_TEXTURE_MAX_LEVEL:
2853 if (context->getClientVersion() < 3)
2854 {
2855 return gl::error(GL_INVALID_ENUM);
2856 }
2857 *params = (GLfloat)texture->getSamplerState().maxLevel;
2858 break;
2859 case GL_TEXTURE_MIN_LOD:
2860 if (context->getClientVersion() < 3)
2861 {
2862 return gl::error(GL_INVALID_ENUM);
2863 }
2864 *params = texture->getSamplerState().minLod;
2865 break;
2866 case GL_TEXTURE_MAX_LOD:
2867 if (context->getClientVersion() < 3)
2868 {
2869 return gl::error(GL_INVALID_ENUM);
2870 }
2871 *params = texture->getSamplerState().maxLod;
2872 break;
2873 default:
2874 return gl::error(GL_INVALID_ENUM);
2875 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002876 }
2877}
2878
2879void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
2880{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002881 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 +00002882
Geoff Langbfdea662014-07-23 14:16:32 -04002883 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002884
Geoff Langbfdea662014-07-23 14:16:32 -04002885 if (context)
2886 {
2887 gl::Texture *texture = context->getTargetTexture(target);
2888
2889 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002890 {
Geoff Langbfdea662014-07-23 14:16:32 -04002891 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002892 }
Geoff Langbfdea662014-07-23 14:16:32 -04002893
2894 switch (pname)
2895 {
2896 case GL_TEXTURE_MAG_FILTER:
2897 *params = texture->getSamplerState().magFilter;
2898 break;
2899 case GL_TEXTURE_MIN_FILTER:
2900 *params = texture->getSamplerState().minFilter;
2901 break;
2902 case GL_TEXTURE_WRAP_S:
2903 *params = texture->getSamplerState().wrapS;
2904 break;
2905 case GL_TEXTURE_WRAP_T:
2906 *params = texture->getSamplerState().wrapT;
2907 break;
2908 case GL_TEXTURE_WRAP_R:
2909 if (context->getClientVersion() < 3)
2910 {
2911 return gl::error(GL_INVALID_ENUM);
2912 }
2913 *params = texture->getSamplerState().wrapR;
2914 break;
2915 case GL_TEXTURE_IMMUTABLE_FORMAT:
2916 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2917 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
2918 break;
2919 case GL_TEXTURE_IMMUTABLE_LEVELS:
2920 if (context->getClientVersion() < 3)
2921 {
2922 return gl::error(GL_INVALID_ENUM);
2923 }
2924 *params = texture->immutableLevelCount();
2925 break;
2926 case GL_TEXTURE_USAGE_ANGLE:
2927 *params = texture->getUsage();
2928 break;
2929 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2930 if (!context->getExtensions().textureFilterAnisotropic)
2931 {
2932 return gl::error(GL_INVALID_ENUM);
2933 }
2934 *params = (GLint)texture->getSamplerState().maxAnisotropy;
2935 break;
2936 case GL_TEXTURE_SWIZZLE_R:
2937 if (context->getClientVersion() < 3)
2938 {
2939 return gl::error(GL_INVALID_ENUM);
2940 }
2941 *params = texture->getSamplerState().swizzleRed;
2942 break;
2943 case GL_TEXTURE_SWIZZLE_G:
2944 if (context->getClientVersion() < 3)
2945 {
2946 return gl::error(GL_INVALID_ENUM);
2947 }
2948 *params = texture->getSamplerState().swizzleGreen;
2949 break;
2950 case GL_TEXTURE_SWIZZLE_B:
2951 if (context->getClientVersion() < 3)
2952 {
2953 return gl::error(GL_INVALID_ENUM);
2954 }
2955 *params = texture->getSamplerState().swizzleBlue;
2956 break;
2957 case GL_TEXTURE_SWIZZLE_A:
2958 if (context->getClientVersion() < 3)
2959 {
2960 return gl::error(GL_INVALID_ENUM);
2961 }
2962 *params = texture->getSamplerState().swizzleAlpha;
2963 break;
2964 case GL_TEXTURE_BASE_LEVEL:
2965 if (context->getClientVersion() < 3)
2966 {
2967 return gl::error(GL_INVALID_ENUM);
2968 }
2969 *params = texture->getSamplerState().baseLevel;
2970 break;
2971 case GL_TEXTURE_MAX_LEVEL:
2972 if (context->getClientVersion() < 3)
2973 {
2974 return gl::error(GL_INVALID_ENUM);
2975 }
2976 *params = texture->getSamplerState().maxLevel;
2977 break;
2978 case GL_TEXTURE_MIN_LOD:
2979 if (context->getClientVersion() < 3)
2980 {
2981 return gl::error(GL_INVALID_ENUM);
2982 }
2983 *params = (GLint)texture->getSamplerState().minLod;
2984 break;
2985 case GL_TEXTURE_MAX_LOD:
2986 if (context->getClientVersion() < 3)
2987 {
2988 return gl::error(GL_INVALID_ENUM);
2989 }
2990 *params = (GLint)texture->getSamplerState().maxLod;
2991 break;
2992 default:
2993 return gl::error(GL_INVALID_ENUM);
2994 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002995 }
2996}
2997
daniel@transgaming.com9a849122011-11-12 03:18:00 +00002998void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
2999{
3000 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3001 program, location, bufSize, params);
3002
Geoff Langbfdea662014-07-23 14:16:32 -04003003 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003004 {
Geoff Langbfdea662014-07-23 14:16:32 -04003005 return gl::error(GL_INVALID_VALUE);
3006 }
3007
3008 gl::Context *context = gl::getNonLostContext();
3009
3010 if (context)
3011 {
3012 if (program == 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003013 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003014 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003015 }
3016
Geoff Langbfdea662014-07-23 14:16:32 -04003017 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003018
Geoff Langbfdea662014-07-23 14:16:32 -04003019 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003020 {
Geoff Langbfdea662014-07-23 14:16:32 -04003021 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003022 }
Geoff Langbfdea662014-07-23 14:16:32 -04003023
3024 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3025 if (!programBinary)
3026 {
3027 return gl::error(GL_INVALID_OPERATION);
3028 }
3029
3030 if (!programBinary->getUniformfv(location, &bufSize, params))
3031 {
3032 return gl::error(GL_INVALID_OPERATION);
3033 }
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003034 }
3035}
3036
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003037void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003039 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003040
Geoff Langbfdea662014-07-23 14:16:32 -04003041 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003042
Geoff Langbfdea662014-07-23 14:16:32 -04003043 if (context)
3044 {
3045 if (program == 0)
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003046 {
Geoff Langbfdea662014-07-23 14:16:32 -04003047 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003048 }
Geoff Langbfdea662014-07-23 14:16:32 -04003049
3050 gl::Program *programObject = context->getProgram(program);
3051
3052 if (!programObject || !programObject->isLinked())
3053 {
3054 return gl::error(GL_INVALID_OPERATION);
3055 }
3056
3057 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3058 if (!programBinary)
3059 {
3060 return gl::error(GL_INVALID_OPERATION);
3061 }
3062
3063 if (!programBinary->getUniformfv(location, NULL, params))
3064 {
3065 return gl::error(GL_INVALID_OPERATION);
3066 }
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003067 }
3068}
3069
3070void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3071{
Geoff Langbfdea662014-07-23 14:16:32 -04003072 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003073 program, location, bufSize, params);
3074
Geoff Langbfdea662014-07-23 14:16:32 -04003075 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003076 {
Geoff Langbfdea662014-07-23 14:16:32 -04003077 return gl::error(GL_INVALID_VALUE);
3078 }
3079
3080 gl::Context *context = gl::getNonLostContext();
3081
3082 if (context)
3083 {
3084 if (program == 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003086 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003087 }
3088
Geoff Langbfdea662014-07-23 14:16:32 -04003089 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003090
Geoff Langbfdea662014-07-23 14:16:32 -04003091 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003092 {
Geoff Langbfdea662014-07-23 14:16:32 -04003093 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003094 }
Geoff Langbfdea662014-07-23 14:16:32 -04003095
3096 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3097 if (!programBinary)
3098 {
3099 return gl::error(GL_INVALID_OPERATION);
3100 }
3101
3102 if (!programBinary->getUniformiv(location, &bufSize, params))
3103 {
3104 return gl::error(GL_INVALID_OPERATION);
3105 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003106 }
3107}
3108
3109void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3110{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003111 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003112
Geoff Langbfdea662014-07-23 14:16:32 -04003113 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003114
Geoff Langbfdea662014-07-23 14:16:32 -04003115 if (context)
3116 {
3117 if (program == 0)
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003118 {
Geoff Langbfdea662014-07-23 14:16:32 -04003119 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003120 }
Geoff Langbfdea662014-07-23 14:16:32 -04003121
3122 gl::Program *programObject = context->getProgram(program);
3123
3124 if (!programObject || !programObject->isLinked())
3125 {
3126 return gl::error(GL_INVALID_OPERATION);
3127 }
3128
3129 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3130 if (!programBinary)
3131 {
3132 return gl::error(GL_INVALID_OPERATION);
3133 }
3134
3135 if (!programBinary->getUniformiv(location, NULL, params))
3136 {
3137 return gl::error(GL_INVALID_OPERATION);
3138 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003139 }
3140}
3141
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003142int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003143{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003144 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003145
Geoff Langbfdea662014-07-23 14:16:32 -04003146 gl::Context *context = gl::getNonLostContext();
3147
3148 if (strstr(name, "gl_") == name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003149 {
Geoff Langbfdea662014-07-23 14:16:32 -04003150 return -1;
3151 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003152
Geoff Langbfdea662014-07-23 14:16:32 -04003153 if (context)
3154 {
3155 gl::Program *programObject = context->getProgram(program);
3156
3157 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003158 {
Geoff Langbfdea662014-07-23 14:16:32 -04003159 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003161 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003162 }
Geoff Langbfdea662014-07-23 14:16:32 -04003163 else
3164 {
3165 return gl::error(GL_INVALID_VALUE, -1);
3166 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003167 }
Geoff Langbfdea662014-07-23 14:16:32 -04003168
3169 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3170 if (!programObject->isLinked() || !programBinary)
3171 {
3172 return gl::error(GL_INVALID_OPERATION, -1);
3173 }
3174
3175 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003176 }
3177
3178 return -1;
3179}
3180
3181void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3182{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003183 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003184
Geoff Langbfdea662014-07-23 14:16:32 -04003185 gl::Context *context = gl::getNonLostContext();
3186
3187 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003188 {
Geoff Langbfdea662014-07-23 14:16:32 -04003189 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003190 {
Geoff Langbfdea662014-07-23 14:16:32 -04003191 return gl::error(GL_INVALID_VALUE);
3192 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003193
Geoff Langbfdea662014-07-23 14:16:32 -04003194 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
3195 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3196 {
3197 return;
3198 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003199
Geoff Langbfdea662014-07-23 14:16:32 -04003200 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3201 {
3202 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3203 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003204 {
Geoff Langbfdea662014-07-23 14:16:32 -04003205 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003206 }
3207 }
Geoff Langbfdea662014-07-23 14:16:32 -04003208 else
3209 {
3210 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3211 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003212 }
3213}
3214
3215void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3216{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003217 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003218
Geoff Langbfdea662014-07-23 14:16:32 -04003219 gl::Context *context = gl::getNonLostContext();
3220
3221 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003222 {
Geoff Langbfdea662014-07-23 14:16:32 -04003223 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003224 {
Geoff Langbfdea662014-07-23 14:16:32 -04003225 return gl::error(GL_INVALID_VALUE);
3226 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003227
Geoff Langbfdea662014-07-23 14:16:32 -04003228 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003229
Geoff Langbfdea662014-07-23 14:16:32 -04003230 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3231 {
3232 return;
3233 }
Jamie Madillaff71502013-07-02 11:57:05 -04003234
Geoff Langbfdea662014-07-23 14:16:32 -04003235 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3236 {
3237 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3238 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003239 {
Geoff Langbfdea662014-07-23 14:16:32 -04003240 float currentValue = currentValueData.FloatValues[i];
3241 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003242 }
3243 }
Geoff Langbfdea662014-07-23 14:16:32 -04003244 else
3245 {
3246 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3247 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003248 }
3249}
3250
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003251void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003252{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003253 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003254
Geoff Langbfdea662014-07-23 14:16:32 -04003255 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003256
Geoff Langbfdea662014-07-23 14:16:32 -04003257 if (context)
3258 {
3259 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003260 {
Geoff Langbfdea662014-07-23 14:16:32 -04003261 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003262 }
Geoff Langbfdea662014-07-23 14:16:32 -04003263
3264 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3265 {
3266 return gl::error(GL_INVALID_ENUM);
3267 }
3268
3269 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003270 }
3271}
3272
3273void __stdcall glHint(GLenum target, GLenum mode)
3274{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003275 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003276
Geoff Langbfdea662014-07-23 14:16:32 -04003277 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003278 {
Geoff Langbfdea662014-07-23 14:16:32 -04003279 case GL_FASTEST:
3280 case GL_NICEST:
3281 case GL_DONT_CARE:
3282 break;
3283 default:
3284 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003285 }
Geoff Langbfdea662014-07-23 14:16:32 -04003286
3287 gl::Context *context = gl::getNonLostContext();
3288 switch (target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003289 {
Geoff Langbfdea662014-07-23 14:16:32 -04003290 case GL_GENERATE_MIPMAP_HINT:
3291 if (context) context->getState().setGenerateMipmapHint(mode);
3292 break;
3293 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3294 if (context) context->getState().setFragmentShaderDerivativeHint(mode);
3295 break;
3296 default:
3297 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003298 }
3299}
3300
3301GLboolean __stdcall glIsBuffer(GLuint buffer)
3302{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003303 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003304
Geoff Langbfdea662014-07-23 14:16:32 -04003305 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003306
Geoff Langbfdea662014-07-23 14:16:32 -04003307 if (context && buffer)
3308 {
3309 gl::Buffer *bufferObject = context->getBuffer(buffer);
3310
3311 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003312 {
Geoff Langbfdea662014-07-23 14:16:32 -04003313 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003314 }
3315 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003316
3317 return GL_FALSE;
3318}
3319
3320GLboolean __stdcall glIsEnabled(GLenum cap)
3321{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003322 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003323
Geoff Langbfdea662014-07-23 14:16:32 -04003324 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325
Geoff Langbfdea662014-07-23 14:16:32 -04003326 if (context)
3327 {
3328 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003329 {
Geoff Langbfdea662014-07-23 14:16:32 -04003330 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003331 }
Geoff Langbfdea662014-07-23 14:16:32 -04003332
3333 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334 }
3335
3336 return false;
3337}
3338
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003339GLboolean __stdcall glIsFenceNV(GLuint fence)
3340{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003341 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003342
Geoff Langbfdea662014-07-23 14:16:32 -04003343 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003344
Geoff Langbfdea662014-07-23 14:16:32 -04003345 if (context)
3346 {
3347 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3348
3349 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003350 {
Geoff Langbfdea662014-07-23 14:16:32 -04003351 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003352 }
Geoff Langbfdea662014-07-23 14:16:32 -04003353
3354 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003355 }
3356
3357 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003358}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003359
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003360GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3361{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003362 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003363
Geoff Langbfdea662014-07-23 14:16:32 -04003364 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003365
Geoff Langbfdea662014-07-23 14:16:32 -04003366 if (context && framebuffer)
3367 {
3368 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3369
3370 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003371 {
Geoff Langbfdea662014-07-23 14:16:32 -04003372 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003373 }
3374 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003375
3376 return GL_FALSE;
3377}
3378
3379GLboolean __stdcall glIsProgram(GLuint program)
3380{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003381 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003382
Geoff Langbfdea662014-07-23 14:16:32 -04003383 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003384
Geoff Langbfdea662014-07-23 14:16:32 -04003385 if (context && program)
3386 {
3387 gl::Program *programObject = context->getProgram(program);
3388
3389 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003390 {
Geoff Langbfdea662014-07-23 14:16:32 -04003391 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003392 }
3393 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003394
3395 return GL_FALSE;
3396}
3397
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003398GLboolean __stdcall glIsQueryEXT(GLuint id)
3399{
3400 EVENT("(GLuint id = %d)", id);
3401
Geoff Langbfdea662014-07-23 14:16:32 -04003402 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003403
Geoff Langbfdea662014-07-23 14:16:32 -04003404 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003405 {
Geoff Langbfdea662014-07-23 14:16:32 -04003406 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003407 }
3408
3409 return GL_FALSE;
3410}
3411
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003412GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3413{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003414 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415
Geoff Langbfdea662014-07-23 14:16:32 -04003416 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003417
Geoff Langbfdea662014-07-23 14:16:32 -04003418 if (context && renderbuffer)
3419 {
3420 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3421
3422 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003423 {
Geoff Langbfdea662014-07-23 14:16:32 -04003424 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003425 }
3426 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427
3428 return GL_FALSE;
3429}
3430
3431GLboolean __stdcall glIsShader(GLuint shader)
3432{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003433 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003434
Geoff Langbfdea662014-07-23 14:16:32 -04003435 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003436
Geoff Langbfdea662014-07-23 14:16:32 -04003437 if (context && shader)
3438 {
3439 gl::Shader *shaderObject = context->getShader(shader);
3440
3441 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003442 {
Geoff Langbfdea662014-07-23 14:16:32 -04003443 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003444 }
3445 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003446
3447 return GL_FALSE;
3448}
3449
3450GLboolean __stdcall glIsTexture(GLuint texture)
3451{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003452 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003453
Geoff Langbfdea662014-07-23 14:16:32 -04003454 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003455
Geoff Langbfdea662014-07-23 14:16:32 -04003456 if (context && texture)
3457 {
3458 gl::Texture *textureObject = context->getTexture(texture);
3459
3460 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003461 {
Geoff Langbfdea662014-07-23 14:16:32 -04003462 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003463 }
3464 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003465
3466 return GL_FALSE;
3467}
3468
3469void __stdcall glLineWidth(GLfloat width)
3470{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003471 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003472
Geoff Langbfdea662014-07-23 14:16:32 -04003473 if (width <= 0.0f)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003474 {
Geoff Langbfdea662014-07-23 14:16:32 -04003475 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003476 }
Geoff Langbfdea662014-07-23 14:16:32 -04003477
3478 gl::Context *context = gl::getNonLostContext();
3479
3480 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003481 {
Geoff Langbfdea662014-07-23 14:16:32 -04003482 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003483 }
3484}
3485
3486void __stdcall glLinkProgram(GLuint program)
3487{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003488 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003489
Geoff Langbfdea662014-07-23 14:16:32 -04003490 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003491
Geoff Langbfdea662014-07-23 14:16:32 -04003492 if (context)
3493 {
3494 gl::Program *programObject = context->getProgram(program);
3495
3496 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003497 {
Geoff Langbfdea662014-07-23 14:16:32 -04003498 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003499 {
Geoff Langbfdea662014-07-23 14:16:32 -04003500 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003501 }
Geoff Langbfdea662014-07-23 14:16:32 -04003502 else
3503 {
3504 return gl::error(GL_INVALID_VALUE);
3505 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003506 }
Geoff Langbfdea662014-07-23 14:16:32 -04003507
3508 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003509 }
3510}
3511
3512void __stdcall glPixelStorei(GLenum pname, GLint param)
3513{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003514 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003515
Geoff Langbfdea662014-07-23 14:16:32 -04003516 gl::Context *context = gl::getNonLostContext();
3517
3518 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003519 {
Geoff Langbfdea662014-07-23 14:16:32 -04003520 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003521 {
Geoff Langbfdea662014-07-23 14:16:32 -04003522 case GL_UNPACK_ALIGNMENT:
3523 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003524 {
Geoff Langbfdea662014-07-23 14:16:32 -04003525 return gl::error(GL_INVALID_VALUE);
3526 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003527
Geoff Langbfdea662014-07-23 14:16:32 -04003528 context->getState().setUnpackAlignment(param);
3529 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003530
Geoff Langbfdea662014-07-23 14:16:32 -04003531 case GL_PACK_ALIGNMENT:
3532 if (param != 1 && param != 2 && param != 4 && param != 8)
3533 {
3534 return gl::error(GL_INVALID_VALUE);
3535 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003536
Geoff Langbfdea662014-07-23 14:16:32 -04003537 context->getState().setPackAlignment(param);
3538 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003539
Geoff Langbfdea662014-07-23 14:16:32 -04003540 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3541 context->getState().setPackReverseRowOrder(param != 0);
3542 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003543
Geoff Langbfdea662014-07-23 14:16:32 -04003544 case GL_UNPACK_IMAGE_HEIGHT:
3545 case GL_UNPACK_SKIP_IMAGES:
3546 case GL_UNPACK_ROW_LENGTH:
3547 case GL_UNPACK_SKIP_ROWS:
3548 case GL_UNPACK_SKIP_PIXELS:
3549 case GL_PACK_ROW_LENGTH:
3550 case GL_PACK_SKIP_ROWS:
3551 case GL_PACK_SKIP_PIXELS:
3552 if (context->getClientVersion() < 3)
3553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003554 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003555 }
Geoff Langbfdea662014-07-23 14:16:32 -04003556 UNIMPLEMENTED();
3557 break;
3558
3559 default:
3560 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003561 }
3562 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003563}
3564
3565void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3566{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003567 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568
Geoff Langbfdea662014-07-23 14:16:32 -04003569 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00003570
Geoff Langbfdea662014-07-23 14:16:32 -04003571 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003572 {
Geoff Langbfdea662014-07-23 14:16:32 -04003573 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574 }
3575}
3576
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003577void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3578 GLenum format, GLenum type, GLsizei bufSize,
3579 GLvoid *data)
3580{
3581 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3582 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3583 x, y, width, height, format, type, bufSize, data);
3584
Geoff Langbfdea662014-07-23 14:16:32 -04003585 if (width < 0 || height < 0 || bufSize < 0)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003586 {
Geoff Langbfdea662014-07-23 14:16:32 -04003587 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003588 }
Geoff Langbfdea662014-07-23 14:16:32 -04003589
3590 gl::Context *context = gl::getNonLostContext();
3591
3592 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003593 {
Geoff Langbfdea662014-07-23 14:16:32 -04003594 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3595 format, type, &bufSize, data))
3596 {
3597 return;
3598 }
3599
3600 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003601 }
3602}
3603
3604void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3605 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003607 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003608 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003609 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003610
Geoff Langbfdea662014-07-23 14:16:32 -04003611 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003612 {
Geoff Langbfdea662014-07-23 14:16:32 -04003613 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003614 }
Geoff Langbfdea662014-07-23 14:16:32 -04003615
3616 gl::Context *context = gl::getNonLostContext();
3617
3618 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003619 {
Geoff Langbfdea662014-07-23 14:16:32 -04003620 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3621 format, type, NULL, pixels))
3622 {
3623 return;
3624 }
3625
3626 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003627 }
3628}
3629
3630void __stdcall glReleaseShaderCompiler(void)
3631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003632 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003633
Geoff Langbfdea662014-07-23 14:16:32 -04003634 gl::Shader::releaseCompiler();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003635}
3636
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003637void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003638{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003639 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 +00003640 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003641
Geoff Langbfdea662014-07-23 14:16:32 -04003642 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003643
Geoff Langbfdea662014-07-23 14:16:32 -04003644 if (context)
3645 {
3646 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3647 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003648 {
Geoff Langbfdea662014-07-23 14:16:32 -04003649 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003650 }
Geoff Langbfdea662014-07-23 14:16:32 -04003651
3652 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003653 }
3654}
3655
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003656void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3657{
3658 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3659}
3660
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3662{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003663 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664
Geoff Langbfdea662014-07-23 14:16:32 -04003665 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003666
Geoff Langbfdea662014-07-23 14:16:32 -04003667 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003668 {
Geoff Langbfdea662014-07-23 14:16:32 -04003669 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670 }
3671}
3672
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003673void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3674{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003675 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003676
Geoff Langbfdea662014-07-23 14:16:32 -04003677 if (condition != GL_ALL_COMPLETED_NV)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003678 {
Geoff Langbfdea662014-07-23 14:16:32 -04003679 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003680 }
Geoff Langbfdea662014-07-23 14:16:32 -04003681
3682 gl::Context *context = gl::getNonLostContext();
3683
3684 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003685 {
Geoff Langbfdea662014-07-23 14:16:32 -04003686 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3687
3688 if (fenceObject == NULL)
3689 {
3690 return gl::error(GL_INVALID_OPERATION);
3691 }
3692
3693 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003694 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003695}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003696
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3698{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003699 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 +00003700
Geoff Langbfdea662014-07-23 14:16:32 -04003701 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003702 {
Geoff Langbfdea662014-07-23 14:16:32 -04003703 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003704 }
Geoff Langbfdea662014-07-23 14:16:32 -04003705
3706 gl::Context* context = gl::getNonLostContext();
3707
3708 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003709 {
Geoff Langbfdea662014-07-23 14:16:32 -04003710 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003711 }
3712}
3713
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003714void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003716 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003717 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003718 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003719
Geoff Langbfdea662014-07-23 14:16:32 -04003720 // No binary shader formats are supported.
3721 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003722}
3723
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003724void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003725{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003726 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 +00003727 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003728
Geoff Langbfdea662014-07-23 14:16:32 -04003729 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003730 {
Geoff Langbfdea662014-07-23 14:16:32 -04003731 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003732 }
Geoff Langbfdea662014-07-23 14:16:32 -04003733
3734 gl::Context *context = gl::getNonLostContext();
3735
3736 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003737 {
Geoff Langbfdea662014-07-23 14:16:32 -04003738 gl::Shader *shaderObject = context->getShader(shader);
3739
3740 if (!shaderObject)
3741 {
3742 if (context->getProgram(shader))
3743 {
3744 return gl::error(GL_INVALID_OPERATION);
3745 }
3746 else
3747 {
3748 return gl::error(GL_INVALID_VALUE);
3749 }
3750 }
3751
3752 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003753 }
3754}
3755
3756void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3757{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003758 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003759}
3760
3761void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3762{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003763 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 +00003764
Geoff Langbfdea662014-07-23 14:16:32 -04003765 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003766 {
Geoff Langbfdea662014-07-23 14:16:32 -04003767 case GL_FRONT:
3768 case GL_BACK:
3769 case GL_FRONT_AND_BACK:
3770 break;
3771 default:
3772 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003773 }
Geoff Langbfdea662014-07-23 14:16:32 -04003774
3775 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003776 {
Geoff Langbfdea662014-07-23 14:16:32 -04003777 case GL_NEVER:
3778 case GL_ALWAYS:
3779 case GL_LESS:
3780 case GL_LEQUAL:
3781 case GL_EQUAL:
3782 case GL_GEQUAL:
3783 case GL_GREATER:
3784 case GL_NOTEQUAL:
3785 break;
3786 default:
3787 return gl::error(GL_INVALID_ENUM);
3788 }
3789
3790 gl::Context *context = gl::getNonLostContext();
3791
3792 if (context)
3793 {
3794 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3795 {
3796 context->getState().setStencilParams(func, ref, mask);
3797 }
3798
3799 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3800 {
3801 context->getState().setStencilBackParams(func, ref, mask);
3802 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003803 }
3804}
3805
3806void __stdcall glStencilMask(GLuint mask)
3807{
3808 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3809}
3810
3811void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3812{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003813 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003814
Geoff Langbfdea662014-07-23 14:16:32 -04003815 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003816 {
Geoff Langbfdea662014-07-23 14:16:32 -04003817 case GL_FRONT:
3818 case GL_BACK:
3819 case GL_FRONT_AND_BACK:
3820 break;
3821 default:
3822 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003823 }
Geoff Langbfdea662014-07-23 14:16:32 -04003824
3825 gl::Context *context = gl::getNonLostContext();
3826
3827 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003828 {
Geoff Langbfdea662014-07-23 14:16:32 -04003829 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3830 {
3831 context->getState().setStencilWritemask(mask);
3832 }
3833
3834 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3835 {
3836 context->getState().setStencilBackWritemask(mask);
3837 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838 }
3839}
3840
3841void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3842{
3843 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3844}
3845
3846void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3847{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003848 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 +00003849 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003850
Geoff Langbfdea662014-07-23 14:16:32 -04003851 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003852 {
Geoff Langbfdea662014-07-23 14:16:32 -04003853 case GL_FRONT:
3854 case GL_BACK:
3855 case GL_FRONT_AND_BACK:
3856 break;
3857 default:
3858 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003859 }
Geoff Langbfdea662014-07-23 14:16:32 -04003860
3861 switch (fail)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003862 {
Geoff Langbfdea662014-07-23 14:16:32 -04003863 case GL_ZERO:
3864 case GL_KEEP:
3865 case GL_REPLACE:
3866 case GL_INCR:
3867 case GL_DECR:
3868 case GL_INVERT:
3869 case GL_INCR_WRAP:
3870 case GL_DECR_WRAP:
3871 break;
3872 default:
3873 return gl::error(GL_INVALID_ENUM);
3874 }
3875
3876 switch (zfail)
3877 {
3878 case GL_ZERO:
3879 case GL_KEEP:
3880 case GL_REPLACE:
3881 case GL_INCR:
3882 case GL_DECR:
3883 case GL_INVERT:
3884 case GL_INCR_WRAP:
3885 case GL_DECR_WRAP:
3886 break;
3887 default:
3888 return gl::error(GL_INVALID_ENUM);
3889 }
3890
3891 switch (zpass)
3892 {
3893 case GL_ZERO:
3894 case GL_KEEP:
3895 case GL_REPLACE:
3896 case GL_INCR:
3897 case GL_DECR:
3898 case GL_INVERT:
3899 case GL_INCR_WRAP:
3900 case GL_DECR_WRAP:
3901 break;
3902 default:
3903 return gl::error(GL_INVALID_ENUM);
3904 }
3905
3906 gl::Context *context = gl::getNonLostContext();
3907
3908 if (context)
3909 {
3910 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3911 {
3912 context->getState().setStencilOperations(fail, zfail, zpass);
3913 }
3914
3915 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3916 {
3917 context->getState().setStencilBackOperations(fail, zfail, zpass);
3918 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003919 }
3920}
3921
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003922GLboolean __stdcall glTestFenceNV(GLuint fence)
3923{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003924 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003925
Geoff Langbfdea662014-07-23 14:16:32 -04003926 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003927
Geoff Langbfdea662014-07-23 14:16:32 -04003928 if (context)
3929 {
3930 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3931
3932 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003933 {
Geoff Langbfdea662014-07-23 14:16:32 -04003934 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003935 }
Geoff Langbfdea662014-07-23 14:16:32 -04003936
3937 if (fenceObject->isFence() != GL_TRUE)
3938 {
3939 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
3940 }
3941
3942 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003943 }
Geoff Langbfdea662014-07-23 14:16:32 -04003944
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003945 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003946}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003947
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003948void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
3949 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003950{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003951 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05003952 "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 +00003953 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003954
Geoff Langbfdea662014-07-23 14:16:32 -04003955 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003956
Geoff Langbfdea662014-07-23 14:16:32 -04003957 if (context)
3958 {
3959 if (context->getClientVersion() < 3 &&
3960 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
3961 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003962 {
Geoff Langbfdea662014-07-23 14:16:32 -04003963 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003964 }
Geoff Langbfdea662014-07-23 14:16:32 -04003965
3966 if (context->getClientVersion() >= 3 &&
3967 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
3968 0, 0, 0, width, height, 1, border, format, type, pixels))
3969 {
3970 return;
3971 }
3972
3973 switch (target)
3974 {
3975 case GL_TEXTURE_2D:
3976 {
3977 gl::Texture2D *texture = context->getTexture2D();
3978 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3979 }
3980 break;
3981 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3982 {
3983 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3984 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3985 }
3986 break;
3987 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3988 {
3989 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3990 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3991 }
3992 break;
3993 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3994 {
3995 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3996 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3997 }
3998 break;
3999 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4000 {
4001 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4002 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4003 }
4004 break;
4005 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4006 {
4007 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4008 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4009 }
4010 break;
4011 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4012 {
4013 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4014 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4015 }
4016 break;
4017 default: UNREACHABLE();
4018 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004019 }
4020}
4021
4022void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4023{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004024 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4025
Geoff Langbfdea662014-07-23 14:16:32 -04004026 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004027
Geoff Langbfdea662014-07-23 14:16:32 -04004028 if (context)
4029 {
4030 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004031 {
Geoff Langbfdea662014-07-23 14:16:32 -04004032 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004033 }
Geoff Langbfdea662014-07-23 14:16:32 -04004034
4035 gl::Texture *texture = context->getTargetTexture(target);
4036
4037 if (!texture)
4038 {
4039 return gl::error(GL_INVALID_ENUM);
4040 }
4041
4042 switch (pname)
4043 {
4044 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4045 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4046 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4047 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4048 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4049 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4050 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4051 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4052 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4053 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4054 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4055 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4056 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4057 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4058 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4059 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4060 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4061 default: UNREACHABLE(); break;
4062 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004063 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004064}
4065
4066void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4067{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004068 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004069}
4070
4071void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4072{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004073 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004074
Geoff Langbfdea662014-07-23 14:16:32 -04004075 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004076
Geoff Langbfdea662014-07-23 14:16:32 -04004077 if (context)
4078 {
4079 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004080 {
Geoff Langbfdea662014-07-23 14:16:32 -04004081 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082 }
Geoff Langbfdea662014-07-23 14:16:32 -04004083
4084 gl::Texture *texture = context->getTargetTexture(target);
4085
4086 if (!texture)
4087 {
4088 return gl::error(GL_INVALID_ENUM);
4089 }
4090
4091 switch (pname)
4092 {
4093 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4094 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4095 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4096 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4097 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4098 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4099 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4100 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4101 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4102 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4103 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4104 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4105 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4106 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4107 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4108 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4109 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4110 default: UNREACHABLE(); break;
4111 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004112 }
4113}
4114
4115void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4116{
4117 glTexParameteri(target, pname, *params);
4118}
4119
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004120void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4121{
4122 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4123 target, levels, internalformat, width, height);
4124
Geoff Langbfdea662014-07-23 14:16:32 -04004125 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004126
Geoff Langbfdea662014-07-23 14:16:32 -04004127 if (context)
4128 {
4129 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004130 {
Geoff Langbfdea662014-07-23 14:16:32 -04004131 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004132 }
Geoff Langbfdea662014-07-23 14:16:32 -04004133
4134 if (context->getClientVersion() < 3 &&
4135 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4136 {
4137 return;
4138 }
4139
4140 if (context->getClientVersion() >= 3 &&
4141 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4142 {
4143 return;
4144 }
4145
4146 switch (target)
4147 {
4148 case GL_TEXTURE_2D:
4149 {
4150 gl::Texture2D *texture2d = context->getTexture2D();
4151 texture2d->storage(levels, internalformat, width, height);
4152 }
4153 break;
4154
4155 case GL_TEXTURE_CUBE_MAP:
4156 {
4157 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4158 textureCube->storage(levels, internalformat, width);
4159 }
4160 break;
4161
4162 default:
4163 return gl::error(GL_INVALID_ENUM);
4164 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004165 }
4166}
4167
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004168void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4169 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004171 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004172 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004173 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004174 target, level, xoffset, yoffset, width, height, format, type, pixels);
4175
Geoff Langbfdea662014-07-23 14:16:32 -04004176 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004177
Geoff Langbfdea662014-07-23 14:16:32 -04004178 if (context)
4179 {
4180 if (context->getClientVersion() < 3 &&
4181 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4182 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004183 {
Geoff Langbfdea662014-07-23 14:16:32 -04004184 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004185 }
Geoff Langbfdea662014-07-23 14:16:32 -04004186
4187 if (context->getClientVersion() >= 3 &&
4188 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4189 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4190 {
4191 return;
4192 }
4193
4194 // Zero sized uploads are valid but no-ops
4195 if (width == 0 || height == 0)
4196 {
4197 return;
4198 }
4199
4200 switch (target)
4201 {
4202 case GL_TEXTURE_2D:
4203 {
4204 gl::Texture2D *texture = context->getTexture2D();
4205 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4206 }
4207 break;
4208
4209 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4210 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4211 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4212 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4213 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4214 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4215 {
4216 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4217 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4218 }
4219 break;
4220
4221 default:
4222 UNREACHABLE();
4223 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004224 }
4225}
4226
4227void __stdcall glUniform1f(GLint location, GLfloat x)
4228{
4229 glUniform1fv(location, 1, &x);
4230}
4231
4232void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004234 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004235
Geoff Langbfdea662014-07-23 14:16:32 -04004236 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004237
Geoff Langbfdea662014-07-23 14:16:32 -04004238 if (context)
4239 {
4240 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004241 {
Geoff Langbfdea662014-07-23 14:16:32 -04004242 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004243 }
Geoff Langbfdea662014-07-23 14:16:32 -04004244
4245 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4246 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004247 }
4248}
4249
4250void __stdcall glUniform1i(GLint location, GLint x)
4251{
4252 glUniform1iv(location, 1, &x);
4253}
4254
4255void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4256{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004257 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258
Geoff Langbfdea662014-07-23 14:16:32 -04004259 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004260
Geoff Langbfdea662014-07-23 14:16:32 -04004261 if (context)
4262 {
4263 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004264 {
Geoff Langbfdea662014-07-23 14:16:32 -04004265 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004266 }
Geoff Langbfdea662014-07-23 14:16:32 -04004267
4268 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4269 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004270 }
4271}
4272
4273void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4274{
4275 GLfloat xy[2] = {x, y};
4276
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004277 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004278}
4279
4280void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4281{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004282 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004283
Geoff Langbfdea662014-07-23 14:16:32 -04004284 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004285
Geoff Langbfdea662014-07-23 14:16:32 -04004286 if (context)
4287 {
4288 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004289 {
Geoff Langbfdea662014-07-23 14:16:32 -04004290 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291 }
Geoff Langbfdea662014-07-23 14:16:32 -04004292
4293 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4294 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004295 }
4296}
4297
4298void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4299{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004300 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004301
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004302 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004303}
4304
4305void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4306{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004307 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004308
Geoff Langbfdea662014-07-23 14:16:32 -04004309 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004310
Geoff Langbfdea662014-07-23 14:16:32 -04004311 if (context)
4312 {
4313 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004314 {
Geoff Langbfdea662014-07-23 14:16:32 -04004315 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004316 }
Geoff Langbfdea662014-07-23 14:16:32 -04004317
4318 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4319 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004320 }
4321}
4322
4323void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4324{
4325 GLfloat xyz[3] = {x, y, z};
4326
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004327 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004328}
4329
4330void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4331{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004332 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004333
Geoff Langbfdea662014-07-23 14:16:32 -04004334 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004335
Geoff Langbfdea662014-07-23 14:16:32 -04004336 if (context)
4337 {
4338 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004339 {
Geoff Langbfdea662014-07-23 14:16:32 -04004340 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004341 }
Geoff Langbfdea662014-07-23 14:16:32 -04004342
4343 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4344 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345 }
4346}
4347
4348void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4349{
4350 GLint xyz[3] = {x, y, z};
4351
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004352 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004353}
4354
4355void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4356{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004357 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004358
Geoff Langbfdea662014-07-23 14:16:32 -04004359 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004360
Geoff Langbfdea662014-07-23 14:16:32 -04004361 if (context)
4362 {
4363 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004364 {
Geoff Langbfdea662014-07-23 14:16:32 -04004365 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004366 }
Geoff Langbfdea662014-07-23 14:16:32 -04004367
4368 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4369 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004370 }
4371}
4372
4373void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4374{
4375 GLfloat xyzw[4] = {x, y, z, w};
4376
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004377 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004378}
4379
4380void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4381{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004382 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004383
Geoff Langbfdea662014-07-23 14:16:32 -04004384 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004385
Geoff Langbfdea662014-07-23 14:16:32 -04004386 if (context)
4387 {
4388 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004389 {
Geoff Langbfdea662014-07-23 14:16:32 -04004390 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004391 }
Geoff Langbfdea662014-07-23 14:16:32 -04004392
4393 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4394 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004395 }
4396}
4397
4398void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4399{
4400 GLint xyzw[4] = {x, y, z, w};
4401
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004402 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004403}
4404
4405void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4406{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004407 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004408
Geoff Langbfdea662014-07-23 14:16:32 -04004409 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004410
Geoff Langbfdea662014-07-23 14:16:32 -04004411 if (context)
4412 {
4413 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004414 {
Geoff Langbfdea662014-07-23 14:16:32 -04004415 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004416 }
Geoff Langbfdea662014-07-23 14:16:32 -04004417
4418 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4419 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004420 }
4421}
4422
4423void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4424{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004425 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004426 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004427
Geoff Langbfdea662014-07-23 14:16:32 -04004428 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004429
Geoff Langbfdea662014-07-23 14:16:32 -04004430 if (context)
4431 {
4432 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004433 {
Geoff Langbfdea662014-07-23 14:16:32 -04004434 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004435 }
Geoff Langbfdea662014-07-23 14:16:32 -04004436
4437 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4438 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004439 }
4440}
4441
4442void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4443{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004444 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004445 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004446
Geoff Langbfdea662014-07-23 14:16:32 -04004447 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004448
Geoff Langbfdea662014-07-23 14:16:32 -04004449 if (context)
4450 {
4451 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452 {
Geoff Langbfdea662014-07-23 14:16:32 -04004453 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454 }
Geoff Langbfdea662014-07-23 14:16:32 -04004455
4456 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4457 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004458 }
4459}
4460
4461void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4462{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004463 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004464 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004465
Geoff Langbfdea662014-07-23 14:16:32 -04004466 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004467
Geoff Langbfdea662014-07-23 14:16:32 -04004468 if (context)
4469 {
4470 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004471 {
Geoff Langbfdea662014-07-23 14:16:32 -04004472 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004473 }
Geoff Langbfdea662014-07-23 14:16:32 -04004474
4475 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4476 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004477 }
4478}
4479
4480void __stdcall glUseProgram(GLuint program)
4481{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004482 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004483
Geoff Langbfdea662014-07-23 14:16:32 -04004484 gl::Context *context = gl::getNonLostContext();
4485
4486 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004487 {
Geoff Langbfdea662014-07-23 14:16:32 -04004488 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004489
Geoff Langbfdea662014-07-23 14:16:32 -04004490 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004491 {
Geoff Langbfdea662014-07-23 14:16:32 -04004492 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004494 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004495 }
Geoff Langbfdea662014-07-23 14:16:32 -04004496 else
4497 {
4498 return gl::error(GL_INVALID_VALUE);
4499 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004500 }
Geoff Langbfdea662014-07-23 14:16:32 -04004501
4502 if (program != 0 && !programObject->isLinked())
4503 {
4504 return gl::error(GL_INVALID_OPERATION);
4505 }
4506
4507 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508 }
4509}
4510
4511void __stdcall glValidateProgram(GLuint program)
4512{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004513 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004514
Geoff Langbfdea662014-07-23 14:16:32 -04004515 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004516
Geoff Langbfdea662014-07-23 14:16:32 -04004517 if (context)
4518 {
4519 gl::Program *programObject = context->getProgram(program);
4520
4521 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004522 {
Geoff Langbfdea662014-07-23 14:16:32 -04004523 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004524 {
Geoff Langbfdea662014-07-23 14:16:32 -04004525 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004526 }
Geoff Langbfdea662014-07-23 14:16:32 -04004527 else
4528 {
4529 return gl::error(GL_INVALID_VALUE);
4530 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004531 }
Geoff Langbfdea662014-07-23 14:16:32 -04004532
4533 programObject->validate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004534 }
4535}
4536
4537void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4538{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004539 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004540
Geoff Langbfdea662014-07-23 14:16:32 -04004541 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004542 {
Geoff Langbfdea662014-07-23 14:16:32 -04004543 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004544 }
Geoff Langbfdea662014-07-23 14:16:32 -04004545
4546 gl::Context *context = gl::getNonLostContext();
4547
4548 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004549 {
Geoff Langbfdea662014-07-23 14:16:32 -04004550 GLfloat vals[4] = { x, 0, 0, 1 };
4551 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004552 }
4553}
4554
4555void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4556{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004557 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004558
Geoff Langbfdea662014-07-23 14:16:32 -04004559 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004560 {
Geoff Langbfdea662014-07-23 14:16:32 -04004561 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562 }
Geoff Langbfdea662014-07-23 14:16:32 -04004563
4564 gl::Context *context = gl::getNonLostContext();
4565
4566 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004567 {
Geoff Langbfdea662014-07-23 14:16:32 -04004568 GLfloat vals[4] = { values[0], 0, 0, 1 };
4569 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570 }
4571}
4572
4573void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4574{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004575 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004576
Geoff Langbfdea662014-07-23 14:16:32 -04004577 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004578 {
Geoff Langbfdea662014-07-23 14:16:32 -04004579 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004580 }
Geoff Langbfdea662014-07-23 14:16:32 -04004581
4582 gl::Context *context = gl::getNonLostContext();
4583
4584 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004585 {
Geoff Langbfdea662014-07-23 14:16:32 -04004586 GLfloat vals[4] = { x, y, 0, 1 };
4587 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004588 }
4589}
4590
4591void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4592{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004593 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004594
Geoff Langbfdea662014-07-23 14:16:32 -04004595 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004596 {
Geoff Langbfdea662014-07-23 14:16:32 -04004597 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004598 }
Geoff Langbfdea662014-07-23 14:16:32 -04004599
4600 gl::Context *context = gl::getNonLostContext();
4601
4602 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004603 {
Geoff Langbfdea662014-07-23 14:16:32 -04004604 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4605 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004606 }
4607}
4608
4609void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004611 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 +00004612
Geoff Langbfdea662014-07-23 14:16:32 -04004613 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004614 {
Geoff Langbfdea662014-07-23 14:16:32 -04004615 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004616 }
Geoff Langbfdea662014-07-23 14:16:32 -04004617
4618 gl::Context *context = gl::getNonLostContext();
4619
4620 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004621 {
Geoff Langbfdea662014-07-23 14:16:32 -04004622 GLfloat vals[4] = { x, y, z, 1 };
4623 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004624 }
4625}
4626
4627void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4628{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004629 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004630
Geoff Langbfdea662014-07-23 14:16:32 -04004631 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004632 {
Geoff Langbfdea662014-07-23 14:16:32 -04004633 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634 }
Geoff Langbfdea662014-07-23 14:16:32 -04004635
4636 gl::Context *context = gl::getNonLostContext();
4637
4638 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004639 {
Geoff Langbfdea662014-07-23 14:16:32 -04004640 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4641 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642 }
4643}
4644
4645void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4646{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004647 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 +00004648
Geoff Langbfdea662014-07-23 14:16:32 -04004649 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004650 {
Geoff Langbfdea662014-07-23 14:16:32 -04004651 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004652 }
Geoff Langbfdea662014-07-23 14:16:32 -04004653
4654 gl::Context *context = gl::getNonLostContext();
4655
4656 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004657 {
Geoff Langbfdea662014-07-23 14:16:32 -04004658 GLfloat vals[4] = { x, y, z, w };
4659 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004660 }
4661}
4662
4663void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004665 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004666
Geoff Langbfdea662014-07-23 14:16:32 -04004667 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004668 {
Geoff Langbfdea662014-07-23 14:16:32 -04004669 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670 }
Geoff Langbfdea662014-07-23 14:16:32 -04004671
4672 gl::Context *context = gl::getNonLostContext();
4673
4674 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004675 {
Geoff Langbfdea662014-07-23 14:16:32 -04004676 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004677 }
4678}
4679
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004680void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4681{
4682 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4683
Geoff Langbfdea662014-07-23 14:16:32 -04004684 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004685 {
Geoff Langbfdea662014-07-23 14:16:32 -04004686 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004687 }
Geoff Langbfdea662014-07-23 14:16:32 -04004688
4689 gl::Context *context = gl::getNonLostContext();
4690
4691 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004692 {
Geoff Langbfdea662014-07-23 14:16:32 -04004693 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004694 }
4695}
4696
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004697void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004698{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004699 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004700 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004701 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004702
Geoff Langbfdea662014-07-23 14:16:32 -04004703 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004704 {
Geoff Langbfdea662014-07-23 14:16:32 -04004705 return gl::error(GL_INVALID_VALUE);
4706 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004707
Geoff Langbfdea662014-07-23 14:16:32 -04004708 if (size < 1 || size > 4)
4709 {
4710 return gl::error(GL_INVALID_VALUE);
4711 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004712
Geoff Langbfdea662014-07-23 14:16:32 -04004713 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00004714
Geoff Langbfdea662014-07-23 14:16:32 -04004715 switch (type)
4716 {
4717 case GL_BYTE:
4718 case GL_UNSIGNED_BYTE:
4719 case GL_SHORT:
4720 case GL_UNSIGNED_SHORT:
4721 case GL_FIXED:
4722 case GL_FLOAT:
4723 break;
4724 case GL_HALF_FLOAT:
4725 case GL_INT:
4726 case GL_UNSIGNED_INT:
4727 case GL_INT_2_10_10_10_REV:
4728 case GL_UNSIGNED_INT_2_10_10_10_REV:
4729 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004731 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004732 }
Geoff Langbfdea662014-07-23 14:16:32 -04004733 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004734 {
Geoff Langbfdea662014-07-23 14:16:32 -04004735 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004736 }
Geoff Langbfdea662014-07-23 14:16:32 -04004737 default:
4738 return gl::error(GL_INVALID_ENUM);
4739 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004740
Geoff Langbfdea662014-07-23 14:16:32 -04004741 if (stride < 0)
4742 {
4743 return gl::error(GL_INVALID_VALUE);
4744 }
4745
4746 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4747 {
4748 return gl::error(GL_INVALID_OPERATION);
4749 }
4750
4751 if (context)
4752 {
4753 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4754 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4755 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4756 // and the pointer argument is not NULL.
4757 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004758 {
4759 return gl::error(GL_INVALID_OPERATION);
4760 }
4761
Geoff Langbfdea662014-07-23 14:16:32 -04004762 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4763 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004764 }
4765}
4766
4767void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4768{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004769 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 +00004770
Geoff Langbfdea662014-07-23 14:16:32 -04004771 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004772 {
Geoff Langbfdea662014-07-23 14:16:32 -04004773 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004774 }
Geoff Langbfdea662014-07-23 14:16:32 -04004775
4776 gl::Context *context = gl::getNonLostContext();
4777
4778 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004779 {
Geoff Langbfdea662014-07-23 14:16:32 -04004780 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004781 }
4782}
4783
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004784// OpenGL ES 3.0 functions
4785
4786void __stdcall glReadBuffer(GLenum mode)
4787{
4788 EVENT("(GLenum mode = 0x%X)", mode);
4789
Geoff Langbfdea662014-07-23 14:16:32 -04004790 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004791
Geoff Langbfdea662014-07-23 14:16:32 -04004792 if (context)
4793 {
4794 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004795 {
Geoff Langbfdea662014-07-23 14:16:32 -04004796 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004797 }
Geoff Langbfdea662014-07-23 14:16:32 -04004798
4799 // glReadBuffer
4800 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004801 }
4802}
4803
4804void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4805{
4806 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4807 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4808
Geoff Langbfdea662014-07-23 14:16:32 -04004809 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004810
Geoff Langbfdea662014-07-23 14:16:32 -04004811 if (context)
4812 {
4813 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004814 {
Geoff Langbfdea662014-07-23 14:16:32 -04004815 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004816 }
Geoff Langbfdea662014-07-23 14:16:32 -04004817
4818 // glDrawRangeElements
4819 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004820 }
4821}
4822
4823void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4824{
4825 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4826 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4827 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4828 target, level, internalformat, width, height, depth, border, format, type, pixels);
4829
Geoff Langbfdea662014-07-23 14:16:32 -04004830 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004831
Geoff Langbfdea662014-07-23 14:16:32 -04004832 if (context)
4833 {
4834 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004835 {
Geoff Langbfdea662014-07-23 14:16:32 -04004836 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004837 }
Geoff Langbfdea662014-07-23 14:16:32 -04004838
4839 // validateES3TexImageFormat sets the error code if there is an error
4840 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4841 0, 0, 0, width, height, depth, border, format, type, pixels))
4842 {
4843 return;
4844 }
4845
4846 switch(target)
4847 {
4848 case GL_TEXTURE_3D:
4849 {
4850 gl::Texture3D *texture = context->getTexture3D();
4851 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4852 }
4853 break;
4854
4855 case GL_TEXTURE_2D_ARRAY:
4856 {
4857 gl::Texture2DArray *texture = context->getTexture2DArray();
4858 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4859 }
4860 break;
4861
4862 default:
4863 return gl::error(GL_INVALID_ENUM);
4864 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004865 }
4866}
4867
4868void __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)
4869{
4870 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4871 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4872 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4873 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4874
Geoff Langbfdea662014-07-23 14:16:32 -04004875 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004876
Geoff Langbfdea662014-07-23 14:16:32 -04004877 if (context)
4878 {
4879 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004880 {
Geoff Langbfdea662014-07-23 14:16:32 -04004881 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004882 }
Geoff Langbfdea662014-07-23 14:16:32 -04004883
4884 // validateES3TexImageFormat sets the error code if there is an error
4885 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4886 xoffset, yoffset, zoffset, width, height, depth, 0,
4887 format, type, pixels))
4888 {
4889 return;
4890 }
4891
4892 // Zero sized uploads are valid but no-ops
4893 if (width == 0 || height == 0 || depth == 0)
4894 {
4895 return;
4896 }
4897
4898 switch(target)
4899 {
4900 case GL_TEXTURE_3D:
4901 {
4902 gl::Texture3D *texture = context->getTexture3D();
4903 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4904 }
4905 break;
4906
4907 case GL_TEXTURE_2D_ARRAY:
4908 {
4909 gl::Texture2DArray *texture = context->getTexture2DArray();
4910 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4911 }
4912 break;
4913
4914 default:
4915 return gl::error(GL_INVALID_ENUM);
4916 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004917 }
4918}
4919
4920void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
4921{
4922 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4923 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
4924 target, level, xoffset, yoffset, zoffset, x, y, width, height);
4925
Geoff Langbfdea662014-07-23 14:16:32 -04004926 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004927
Geoff Langbfdea662014-07-23 14:16:32 -04004928 if (context)
4929 {
4930 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004931 {
Geoff Langbfdea662014-07-23 14:16:32 -04004932 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004933 }
Geoff Langbfdea662014-07-23 14:16:32 -04004934
4935 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
4936 x, y, width, height, 0))
4937 {
4938 return;
4939 }
4940
4941 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
4942 gl::Texture *texture = NULL;
4943 switch (target)
4944 {
4945 case GL_TEXTURE_3D:
4946 texture = context->getTexture3D();
4947 break;
4948
4949 case GL_TEXTURE_2D_ARRAY:
4950 texture = context->getTexture2DArray();
4951 break;
4952
4953 default:
4954 return gl::error(GL_INVALID_ENUM);
4955 }
4956
4957 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004958 }
4959}
4960
4961void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
4962{
Geoff Langeef52cc2013-10-16 15:07:39 -04004963 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 +00004964 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
4965 "const GLvoid* data = 0x%0.8p)",
4966 target, level, internalformat, width, height, depth, border, imageSize, data);
4967
Geoff Langbfdea662014-07-23 14:16:32 -04004968 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004969
Geoff Langbfdea662014-07-23 14:16:32 -04004970 if (context)
4971 {
4972 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004973 {
Geoff Langbfdea662014-07-23 14:16:32 -04004974 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004975 }
Geoff Langbfdea662014-07-23 14:16:32 -04004976
4977 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, width, height))
4978 {
4979 return gl::error(GL_INVALID_VALUE);
4980 }
4981
4982 // validateES3TexImageFormat sets the error code if there is an error
4983 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
4984 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
4985 {
4986 return;
4987 }
4988
4989 switch(target)
4990 {
4991 case GL_TEXTURE_3D:
4992 {
4993 gl::Texture3D *texture = context->getTexture3D();
4994 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
4995 }
4996 break;
4997
4998 case GL_TEXTURE_2D_ARRAY:
4999 {
5000 gl::Texture2DArray *texture = context->getTexture2DArray();
5001 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5002 }
5003 break;
5004
5005 default:
5006 return gl::error(GL_INVALID_ENUM);
5007 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005008 }
5009}
5010
5011void __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)
5012{
5013 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5014 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5015 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5016 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5017
Geoff Langbfdea662014-07-23 14:16:32 -04005018 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005019
Geoff Langbfdea662014-07-23 14:16:32 -04005020 if (context)
5021 {
5022 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005023 {
Geoff Langbfdea662014-07-23 14:16:32 -04005024 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005025 }
Geoff Langbfdea662014-07-23 14:16:32 -04005026
5027 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, width, height))
5028 {
5029 return gl::error(GL_INVALID_VALUE);
5030 }
5031
5032 if (!data)
5033 {
5034 return gl::error(GL_INVALID_VALUE);
5035 }
5036
5037 // validateES3TexImageFormat sets the error code if there is an error
5038 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5039 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5040 {
5041 return;
5042 }
5043
5044 // Zero sized uploads are valid but no-ops
5045 if (width == 0 || height == 0)
5046 {
5047 return;
5048 }
5049
5050 switch(target)
5051 {
5052 case GL_TEXTURE_3D:
5053 {
5054 gl::Texture3D *texture = context->getTexture3D();
5055 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5056 format, imageSize, data);
5057 }
5058 break;
5059
5060 case GL_TEXTURE_2D_ARRAY:
5061 {
5062 gl::Texture2DArray *texture = context->getTexture2DArray();
5063 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5064 format, imageSize, data);
5065 }
5066 break;
5067
5068 default:
5069 return gl::error(GL_INVALID_ENUM);
5070 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005071 }
5072}
5073
5074void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5075{
5076 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5077
Geoff Langbfdea662014-07-23 14:16:32 -04005078 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005079
Geoff Langbfdea662014-07-23 14:16:32 -04005080 if (context)
5081 {
5082 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005083 {
Geoff Langbfdea662014-07-23 14:16:32 -04005084 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005085 }
Geoff Langbfdea662014-07-23 14:16:32 -04005086
5087 if (n < 0)
5088 {
5089 return gl::error(GL_INVALID_VALUE);
5090 }
5091
5092 for (GLsizei i = 0; i < n; i++)
5093 {
5094 ids[i] = context->createQuery();
5095 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005096 }
5097}
5098
5099void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5100{
5101 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5102
Geoff Langbfdea662014-07-23 14:16:32 -04005103 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005104
Geoff Langbfdea662014-07-23 14:16:32 -04005105 if (context)
5106 {
5107 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005108 {
Geoff Langbfdea662014-07-23 14:16:32 -04005109 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005110 }
Geoff Langbfdea662014-07-23 14:16:32 -04005111
5112 if (n < 0)
5113 {
5114 return gl::error(GL_INVALID_VALUE);
5115 }
5116
5117 for (GLsizei i = 0; i < n; i++)
5118 {
5119 context->deleteQuery(ids[i]);
5120 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005121 }
5122}
5123
5124GLboolean __stdcall glIsQuery(GLuint id)
5125{
5126 EVENT("(GLuint id = %u)", id);
5127
Geoff Langbfdea662014-07-23 14:16:32 -04005128 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005129
Geoff Langbfdea662014-07-23 14:16:32 -04005130 if (context)
5131 {
5132 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005133 {
Geoff Langbfdea662014-07-23 14:16:32 -04005134 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005135 }
Geoff Langbfdea662014-07-23 14:16:32 -04005136
5137 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005138 }
5139
5140 return GL_FALSE;
5141}
5142
5143void __stdcall glBeginQuery(GLenum target, GLuint id)
5144{
5145 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5146
Geoff Langbfdea662014-07-23 14:16:32 -04005147 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005148
Geoff Langbfdea662014-07-23 14:16:32 -04005149 if (context)
5150 {
5151 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005152 {
Geoff Langbfdea662014-07-23 14:16:32 -04005153 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005154 }
Geoff Langbfdea662014-07-23 14:16:32 -04005155
5156 if (!ValidateBeginQuery(context, target, id))
5157 {
5158 return;
5159 }
5160 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005161 }
5162}
5163
5164void __stdcall glEndQuery(GLenum target)
5165{
5166 EVENT("(GLenum target = 0x%X)", target);
5167
Geoff Langbfdea662014-07-23 14:16:32 -04005168 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005169
Geoff Langbfdea662014-07-23 14:16:32 -04005170 if (context)
5171 {
5172 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005173 {
Geoff Langbfdea662014-07-23 14:16:32 -04005174 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005175 }
Geoff Langbfdea662014-07-23 14:16:32 -04005176
5177 if (!ValidateEndQuery(context, target))
5178 {
5179 return;
5180 }
5181
5182 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005183 }
5184}
5185
5186void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5187{
5188 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5189
Geoff Langbfdea662014-07-23 14:16:32 -04005190 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005191
Geoff Langbfdea662014-07-23 14:16:32 -04005192 if (context)
5193 {
5194 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005195 {
Geoff Langbfdea662014-07-23 14:16:32 -04005196 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005197 }
Geoff Langbfdea662014-07-23 14:16:32 -04005198
5199 if (!ValidQueryType(context, target))
5200 {
5201 return gl::error(GL_INVALID_ENUM);
5202 }
5203
5204 switch (pname)
5205 {
5206 case GL_CURRENT_QUERY:
5207 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5208 break;
5209
5210 default:
5211 return gl::error(GL_INVALID_ENUM);
5212 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005213 }
5214}
5215
5216void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5217{
5218 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5219
Geoff Langbfdea662014-07-23 14:16:32 -04005220 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005221
Geoff Langbfdea662014-07-23 14:16:32 -04005222 if (context)
5223 {
5224 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005225 {
Geoff Langbfdea662014-07-23 14:16:32 -04005226 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005227 }
Geoff Langbfdea662014-07-23 14:16:32 -04005228
5229 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5230
5231 if (!queryObject)
5232 {
5233 return gl::error(GL_INVALID_OPERATION);
5234 }
5235
5236 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5237 {
5238 return gl::error(GL_INVALID_OPERATION);
5239 }
5240
5241 switch(pname)
5242 {
5243 case GL_QUERY_RESULT:
5244 params[0] = queryObject->getResult();
5245 break;
5246 case GL_QUERY_RESULT_AVAILABLE:
5247 params[0] = queryObject->isResultAvailable();
5248 break;
5249 default:
5250 return gl::error(GL_INVALID_ENUM);
5251 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005252 }
5253}
5254
5255GLboolean __stdcall glUnmapBuffer(GLenum target)
5256{
5257 EVENT("(GLenum target = 0x%X)", target);
5258
Geoff Langbfdea662014-07-23 14:16:32 -04005259 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005260
Geoff Langbfdea662014-07-23 14:16:32 -04005261 if (context)
5262 {
5263 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005264 {
Geoff Langbfdea662014-07-23 14:16:32 -04005265 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005266 }
Geoff Langbfdea662014-07-23 14:16:32 -04005267
5268 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005269 }
5270
5271 return GL_FALSE;
5272}
5273
5274void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5275{
5276 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5277
Geoff Langbfdea662014-07-23 14:16:32 -04005278 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005279
Geoff Langbfdea662014-07-23 14:16:32 -04005280 if (context)
5281 {
5282 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005283 {
Geoff Langbfdea662014-07-23 14:16:32 -04005284 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005285 }
Geoff Langbfdea662014-07-23 14:16:32 -04005286
5287 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005288 }
5289}
5290
5291void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5292{
Geoff Langbfdea662014-07-23 14:16:32 -04005293 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005294
Geoff Langbfdea662014-07-23 14:16:32 -04005295 if (context)
5296 {
5297 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005298 {
Geoff Langbfdea662014-07-23 14:16:32 -04005299 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005300 }
Geoff Langbfdea662014-07-23 14:16:32 -04005301
5302 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005303 }
5304}
5305
5306void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5307{
5308 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5309 location, count, transpose, value);
5310
Geoff Langbfdea662014-07-23 14:16:32 -04005311 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005312
Geoff Langbfdea662014-07-23 14:16:32 -04005313 if (context)
5314 {
5315 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005316 {
Geoff Langbfdea662014-07-23 14:16:32 -04005317 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005318 }
Geoff Langbfdea662014-07-23 14:16:32 -04005319
5320 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5321 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005322 }
5323}
5324
5325void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5326{
5327 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5328 location, count, transpose, value);
5329
Geoff Langbfdea662014-07-23 14:16:32 -04005330 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005331
Geoff Langbfdea662014-07-23 14:16:32 -04005332 if (context)
5333 {
5334 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005335 {
Geoff Langbfdea662014-07-23 14:16:32 -04005336 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005337 }
Geoff Langbfdea662014-07-23 14:16:32 -04005338
5339 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5340 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005341 }
5342}
5343
5344void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5345{
5346 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5347 location, count, transpose, value);
5348
Geoff Langbfdea662014-07-23 14:16:32 -04005349 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005350
Geoff Langbfdea662014-07-23 14:16:32 -04005351 if (context)
5352 {
5353 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005354 {
Geoff Langbfdea662014-07-23 14:16:32 -04005355 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005356 }
Geoff Langbfdea662014-07-23 14:16:32 -04005357
5358 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5359 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005360 }
5361}
5362
5363void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5364{
5365 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5366 location, count, transpose, value);
5367
Geoff Langbfdea662014-07-23 14:16:32 -04005368 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005369
Geoff Langbfdea662014-07-23 14:16:32 -04005370 if (context)
5371 {
5372 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005373 {
Geoff Langbfdea662014-07-23 14:16:32 -04005374 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005375 }
Geoff Langbfdea662014-07-23 14:16:32 -04005376
5377 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5378 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005379 }
5380}
5381
5382void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5383{
5384 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5385 location, count, transpose, value);
5386
Geoff Langbfdea662014-07-23 14:16:32 -04005387 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005388
Geoff Langbfdea662014-07-23 14:16:32 -04005389 if (context)
5390 {
5391 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005392 {
Geoff Langbfdea662014-07-23 14:16:32 -04005393 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005394 }
Geoff Langbfdea662014-07-23 14:16:32 -04005395
5396 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5397 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005398 }
5399}
5400
5401void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5402{
5403 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5404 location, count, transpose, value);
5405
Geoff Langbfdea662014-07-23 14:16:32 -04005406 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005407
Geoff Langbfdea662014-07-23 14:16:32 -04005408 if (context)
5409 {
5410 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005411 {
Geoff Langbfdea662014-07-23 14:16:32 -04005412 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005413 }
Geoff Langbfdea662014-07-23 14:16:32 -04005414
5415 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5416 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005417 }
5418}
5419
5420void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5421{
5422 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5423 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5424 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5425
Geoff Langbfdea662014-07-23 14:16:32 -04005426 gl::Context *context = gl::getNonLostContext();
5427 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005428 {
Geoff Langbfdea662014-07-23 14:16:32 -04005429 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005430 {
Geoff Langbfdea662014-07-23 14:16:32 -04005431 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005432 }
Geoff Langbfdea662014-07-23 14:16:32 -04005433
5434 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5435 dstX0, dstY0, dstX1, dstY1, mask, filter,
5436 false))
5437 {
5438 return;
5439 }
5440
5441 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5442 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005443 }
5444}
5445
5446void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5447{
5448 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5449 target, samples, internalformat, width, height);
5450
Geoff Langbfdea662014-07-23 14:16:32 -04005451 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005452
Geoff Langbfdea662014-07-23 14:16:32 -04005453 if (context)
5454 {
5455 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005456 {
Geoff Langbfdea662014-07-23 14:16:32 -04005457 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005458 }
Geoff Langbfdea662014-07-23 14:16:32 -04005459
5460 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5461 width, height, false))
5462 {
5463 return;
5464 }
5465
5466 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005467 }
5468}
5469
5470void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5471{
5472 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5473 target, attachment, texture, level, layer);
5474
Geoff Langbfdea662014-07-23 14:16:32 -04005475 gl::Context *context = gl::getNonLostContext();
5476
5477 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005478 {
Geoff Langbfdea662014-07-23 14:16:32 -04005479 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5480 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005481 {
Geoff Langbfdea662014-07-23 14:16:32 -04005482 return;
5483 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005484
Geoff Langbfdea662014-07-23 14:16:32 -04005485 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5486 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005487
Geoff Langbfdea662014-07-23 14:16:32 -04005488 gl::Texture *textureObject = context->getTexture(texture);
5489 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005490
Geoff Langbfdea662014-07-23 14:16:32 -04005491 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5492 {
5493 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5494 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5495 }
5496 else
5497 {
5498 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005499 {
Geoff Langbfdea662014-07-23 14:16:32 -04005500 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5501 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5502 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005503 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005504 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005505 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005506}
5507
5508GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5509{
5510 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5511 target, offset, length, access);
5512
Geoff Langbfdea662014-07-23 14:16:32 -04005513 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005514
Geoff Langbfdea662014-07-23 14:16:32 -04005515 if (context)
5516 {
5517 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005518 {
Geoff Langbfdea662014-07-23 14:16:32 -04005519 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005520 }
Geoff Langbfdea662014-07-23 14:16:32 -04005521
5522 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005523 }
5524
5525 return NULL;
5526}
5527
5528void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5529{
5530 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5531
Geoff Langbfdea662014-07-23 14:16:32 -04005532 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005533
Geoff Langbfdea662014-07-23 14:16:32 -04005534 if (context)
5535 {
5536 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005537 {
Geoff Langbfdea662014-07-23 14:16:32 -04005538 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005539 }
Geoff Langbfdea662014-07-23 14:16:32 -04005540
5541 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005542 }
5543}
5544
5545void __stdcall glBindVertexArray(GLuint array)
5546{
5547 EVENT("(GLuint array = %u)", array);
5548
Geoff Langbfdea662014-07-23 14:16:32 -04005549 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005550
Geoff Langbfdea662014-07-23 14:16:32 -04005551 if (context)
5552 {
5553 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005554 {
Geoff Langbfdea662014-07-23 14:16:32 -04005555 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005556 }
Geoff Langbfdea662014-07-23 14:16:32 -04005557
5558 gl::VertexArray *vao = context->getVertexArray(array);
5559
5560 if (!vao)
5561 {
5562 // The default VAO should always exist
5563 ASSERT(array != 0);
5564 return gl::error(GL_INVALID_OPERATION);
5565 }
5566
5567 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005568 }
5569}
5570
5571void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5572{
5573 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5574
Geoff Langbfdea662014-07-23 14:16:32 -04005575 gl::Context *context = gl::getNonLostContext();
5576
5577 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005578 {
Geoff Langbfdea662014-07-23 14:16:32 -04005579 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005580 {
Geoff Langbfdea662014-07-23 14:16:32 -04005581 return gl::error(GL_INVALID_OPERATION);
5582 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005583
Geoff Langbfdea662014-07-23 14:16:32 -04005584 if (n < 0)
5585 {
5586 return gl::error(GL_INVALID_VALUE);
5587 }
Jamie Madilld1028542013-07-02 11:57:04 -04005588
Geoff Langbfdea662014-07-23 14:16:32 -04005589 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5590 {
5591 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005592 {
Geoff Langbfdea662014-07-23 14:16:32 -04005593 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005594 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005595 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005596 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005597}
5598
5599void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5600{
5601 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5602
Geoff Langbfdea662014-07-23 14:16:32 -04005603 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005604
Geoff Langbfdea662014-07-23 14:16:32 -04005605 if (context)
5606 {
5607 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005608 {
Geoff Langbfdea662014-07-23 14:16:32 -04005609 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005610 }
Geoff Langbfdea662014-07-23 14:16:32 -04005611
5612 if (n < 0)
5613 {
5614 return gl::error(GL_INVALID_VALUE);
5615 }
5616
5617 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5618 {
5619 arrays[arrayIndex] = context->createVertexArray();
5620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005621 }
5622}
5623
5624GLboolean __stdcall glIsVertexArray(GLuint array)
5625{
5626 EVENT("(GLuint array = %u)", array);
5627
Geoff Langbfdea662014-07-23 14:16:32 -04005628 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005629
Geoff Langbfdea662014-07-23 14:16:32 -04005630 if (context)
5631 {
5632 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005633 {
Geoff Langbfdea662014-07-23 14:16:32 -04005634 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005635 }
Geoff Langbfdea662014-07-23 14:16:32 -04005636
5637 if (array == 0)
5638 {
5639 return GL_FALSE;
5640 }
5641
5642 gl::VertexArray *vao = context->getVertexArray(array);
5643
5644 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005645 }
5646
5647 return GL_FALSE;
5648}
5649
5650void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5651{
5652 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5653 target, index, data);
5654
Geoff Langbfdea662014-07-23 14:16:32 -04005655 gl::Context *context = gl::getNonLostContext();
5656
5657 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005658 {
Geoff Langbfdea662014-07-23 14:16:32 -04005659 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005660 {
Geoff Langbfdea662014-07-23 14:16:32 -04005661 return gl::error(GL_INVALID_OPERATION);
5662 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005663
Geoff Langbfdea662014-07-23 14:16:32 -04005664 switch (target)
5665 {
5666 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5667 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5668 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
5669 if (index >= context->getMaxTransformFeedbackBufferBindings())
5670 return gl::error(GL_INVALID_VALUE);
5671 break;
5672 case GL_UNIFORM_BUFFER_START:
5673 case GL_UNIFORM_BUFFER_SIZE:
5674 case GL_UNIFORM_BUFFER_BINDING:
5675 if (index >= context->getMaximumCombinedUniformBufferBindings())
5676 return gl::error(GL_INVALID_VALUE);
5677 break;
5678 default:
5679 return gl::error(GL_INVALID_ENUM);
5680 }
5681
5682 if (!(context->getIndexedIntegerv(target, index, data)))
5683 {
5684 GLenum nativeType;
5685 unsigned int numParams = 0;
5686 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04005687 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04005688
Geoff Langbfdea662014-07-23 14:16:32 -04005689 if (numParams == 0)
5690 return; // it is known that pname is valid, but there are no parameters to return
5691
5692 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005693 {
Geoff Langbfdea662014-07-23 14:16:32 -04005694 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5695 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5696 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005697
Geoff Langbfdea662014-07-23 14:16:32 -04005698 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005699
Geoff Langbfdea662014-07-23 14:16:32 -04005700 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005701 {
Geoff Langbfdea662014-07-23 14:16:32 -04005702 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5703 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005704 }
Geoff Langbfdea662014-07-23 14:16:32 -04005705
5706 delete [] int64Params;
5707 }
5708 else
5709 {
5710 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005711 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005712 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005713 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005714}
5715
5716void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5717{
5718 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5719
Geoff Langbfdea662014-07-23 14:16:32 -04005720 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005721
Geoff Langbfdea662014-07-23 14:16:32 -04005722 if (context)
5723 {
5724 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005725 {
Geoff Langbfdea662014-07-23 14:16:32 -04005726 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005727 }
Geoff Langbfdea662014-07-23 14:16:32 -04005728
5729 switch (primitiveMode)
5730 {
5731 case GL_TRIANGLES:
5732 case GL_LINES:
5733 case GL_POINTS:
5734 break;
5735 default:
5736 return gl::error(GL_INVALID_ENUM);
5737 }
5738
5739 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5740 ASSERT(transformFeedback != NULL);
5741
5742 if (transformFeedback->isStarted())
5743 {
5744 return gl::error(GL_INVALID_OPERATION);
5745 }
5746
5747 if (transformFeedback->isPaused())
5748 {
5749 transformFeedback->resume();
5750 }
5751 else
5752 {
5753 transformFeedback->start(primitiveMode);
5754 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005755 }
5756}
5757
5758void __stdcall glEndTransformFeedback(void)
5759{
5760 EVENT("(void)");
5761
Geoff Langbfdea662014-07-23 14:16:32 -04005762 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005763
Geoff Langbfdea662014-07-23 14:16:32 -04005764 if (context)
5765 {
5766 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005767 {
Geoff Langbfdea662014-07-23 14:16:32 -04005768 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005769 }
Geoff Langbfdea662014-07-23 14:16:32 -04005770
5771 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5772 ASSERT(transformFeedback != NULL);
5773
5774 if (!transformFeedback->isStarted())
5775 {
5776 return gl::error(GL_INVALID_OPERATION);
5777 }
5778
5779 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005780 }
5781}
5782
5783void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5784{
5785 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5786 target, index, buffer, offset, size);
5787
Geoff Langbfdea662014-07-23 14:16:32 -04005788 gl::Context *context = gl::getNonLostContext();
5789
5790 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005791 {
Geoff Langbfdea662014-07-23 14:16:32 -04005792 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005793 {
Geoff Langbfdea662014-07-23 14:16:32 -04005794 return gl::error(GL_INVALID_OPERATION);
5795 }
5796
5797 switch (target)
5798 {
5799 case GL_TRANSFORM_FEEDBACK_BUFFER:
5800 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005801 {
Geoff Langbfdea662014-07-23 14:16:32 -04005802 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005803 }
Geoff Langbfdea662014-07-23 14:16:32 -04005804 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005805
Geoff Langbfdea662014-07-23 14:16:32 -04005806 case GL_UNIFORM_BUFFER:
5807 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005808 {
Geoff Langbfdea662014-07-23 14:16:32 -04005809 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005810 }
Geoff Langbfdea662014-07-23 14:16:32 -04005811 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005812
Geoff Langbfdea662014-07-23 14:16:32 -04005813 default:
5814 return gl::error(GL_INVALID_ENUM);
5815 }
5816
5817 if (buffer != 0 && size <= 0)
5818 {
5819 return gl::error(GL_INVALID_VALUE);
5820 }
5821
5822 switch (target)
5823 {
5824 case GL_TRANSFORM_FEEDBACK_BUFFER:
5825
5826 // size and offset must be a multiple of 4
5827 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005828 {
5829 return gl::error(GL_INVALID_VALUE);
5830 }
5831
Geoff Langbfdea662014-07-23 14:16:32 -04005832 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5833 context->bindGenericTransformFeedbackBuffer(buffer);
5834 break;
5835
5836 case GL_UNIFORM_BUFFER:
5837
5838 // it is an error to bind an offset not a multiple of the alignment
5839 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005840 {
Geoff Langbfdea662014-07-23 14:16:32 -04005841 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005842 }
Geoff Langbfdea662014-07-23 14:16:32 -04005843
5844 context->bindIndexedUniformBuffer(buffer, index, offset, size);
5845 context->bindGenericUniformBuffer(buffer);
5846 break;
5847
5848 default:
5849 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005850 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005851 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005852}
5853
5854void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
5855{
5856 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
5857 target, index, buffer);
5858
Geoff Langbfdea662014-07-23 14:16:32 -04005859 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005860
Geoff Langbfdea662014-07-23 14:16:32 -04005861 if (context)
5862 {
5863 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005864 {
Geoff Langbfdea662014-07-23 14:16:32 -04005865 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005866 }
Geoff Langbfdea662014-07-23 14:16:32 -04005867
5868 switch (target)
5869 {
5870 case GL_TRANSFORM_FEEDBACK_BUFFER:
5871 if (index >= context->getMaxTransformFeedbackBufferBindings())
5872 {
5873 return gl::error(GL_INVALID_VALUE);
5874 }
5875 break;
5876
5877 case GL_UNIFORM_BUFFER:
5878 if (index >= context->getMaximumCombinedUniformBufferBindings())
5879 {
5880 return gl::error(GL_INVALID_VALUE);
5881 }
5882 break;
5883
5884 default:
5885 return gl::error(GL_INVALID_ENUM);
5886 }
5887
5888 switch (target)
5889 {
5890 case GL_TRANSFORM_FEEDBACK_BUFFER:
5891 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
5892 context->bindGenericTransformFeedbackBuffer(buffer);
5893 break;
5894
5895 case GL_UNIFORM_BUFFER:
5896 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
5897 context->bindGenericUniformBuffer(buffer);
5898 break;
5899
5900 default:
5901 UNREACHABLE();
5902 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005903 }
5904}
5905
5906void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
5907{
5908 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
5909 program, count, varyings, bufferMode);
5910
Geoff Langbfdea662014-07-23 14:16:32 -04005911 gl::Context *context = gl::getNonLostContext();
5912
5913 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005914 {
Geoff Langbfdea662014-07-23 14:16:32 -04005915 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005916 {
Geoff Langbfdea662014-07-23 14:16:32 -04005917 return gl::error(GL_INVALID_OPERATION);
5918 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005919
Geoff Langbfdea662014-07-23 14:16:32 -04005920 if (count < 0)
5921 {
5922 return gl::error(GL_INVALID_VALUE);
5923 }
5924
5925 switch (bufferMode)
5926 {
5927 case GL_INTERLEAVED_ATTRIBS:
5928 break;
5929 case GL_SEPARATE_ATTRIBS:
5930 if (static_cast<GLuint>(count) > context->getMaxTransformFeedbackBufferBindings())
Geoff Lang48dcae72014-02-05 16:28:24 -05005931 {
5932 return gl::error(GL_INVALID_VALUE);
5933 }
Geoff Langbfdea662014-07-23 14:16:32 -04005934 break;
5935 default:
5936 return gl::error(GL_INVALID_ENUM);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005937 }
Geoff Langbfdea662014-07-23 14:16:32 -04005938
5939 if (!gl::ValidProgram(context, program))
5940 {
5941 return;
5942 }
5943
5944 gl::Program *programObject = context->getProgram(program);
5945 ASSERT(programObject);
5946
5947 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005948 }
5949}
5950
5951void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
5952{
5953 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
5954 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
5955 program, index, bufSize, length, size, type, name);
5956
Geoff Langbfdea662014-07-23 14:16:32 -04005957 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005958
Geoff Langbfdea662014-07-23 14:16:32 -04005959 if (context)
5960 {
5961 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005962 {
Geoff Langbfdea662014-07-23 14:16:32 -04005963 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005964 }
Geoff Langbfdea662014-07-23 14:16:32 -04005965
5966 if (bufSize < 0)
5967 {
5968 return gl::error(GL_INVALID_VALUE);
5969 }
5970
5971 if (!gl::ValidProgram(context, program))
5972 {
5973 return;
5974 }
5975
5976 gl::Program *programObject = context->getProgram(program);
5977 ASSERT(programObject);
5978
5979 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
5980 {
5981 return gl::error(GL_INVALID_VALUE);
5982 }
5983
5984 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005985 }
5986}
5987
5988void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
5989{
5990 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
5991 index, size, type, stride, pointer);
5992
Geoff Langbfdea662014-07-23 14:16:32 -04005993 gl::Context *context = gl::getNonLostContext();
5994
5995 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005996 {
Geoff Langbfdea662014-07-23 14:16:32 -04005997 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005998 {
Geoff Langbfdea662014-07-23 14:16:32 -04005999 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006000 }
Geoff Langbfdea662014-07-23 14:16:32 -04006001 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006002
Geoff Langbfdea662014-07-23 14:16:32 -04006003 if (index >= gl::MAX_VERTEX_ATTRIBS)
6004 {
6005 return gl::error(GL_INVALID_VALUE);
6006 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006007
Geoff Langbfdea662014-07-23 14:16:32 -04006008 if (size < 1 || size > 4)
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 switch (type)
6014 {
6015 case GL_BYTE:
6016 case GL_UNSIGNED_BYTE:
6017 case GL_SHORT:
6018 case GL_UNSIGNED_SHORT:
6019 case GL_INT:
6020 case GL_UNSIGNED_INT:
6021 case GL_INT_2_10_10_10_REV:
6022 case GL_UNSIGNED_INT_2_10_10_10_REV:
6023 break;
6024 default:
6025 return gl::error(GL_INVALID_ENUM);
6026 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006027
Geoff Langbfdea662014-07-23 14:16:32 -04006028 if (stride < 0)
6029 {
6030 return gl::error(GL_INVALID_VALUE);
6031 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006032
Geoff Langbfdea662014-07-23 14:16:32 -04006033 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6034 {
6035 return gl::error(GL_INVALID_OPERATION);
6036 }
6037
6038 if (context)
6039 {
6040 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6041 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6042 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6043 // and the pointer argument is not NULL.
6044 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006045 {
6046 return gl::error(GL_INVALID_OPERATION);
6047 }
6048
Geoff Langbfdea662014-07-23 14:16:32 -04006049 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6050 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006051 }
6052}
6053
6054void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6055{
6056 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6057 index, pname, params);
6058
Geoff Langbfdea662014-07-23 14:16:32 -04006059 gl::Context *context = gl::getNonLostContext();
6060
6061 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006062 {
Geoff Langbfdea662014-07-23 14:16:32 -04006063 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006064 {
Geoff Langbfdea662014-07-23 14:16:32 -04006065 return gl::error(GL_INVALID_OPERATION);
6066 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006067
Geoff Langbfdea662014-07-23 14:16:32 -04006068 if (index >= gl::MAX_VERTEX_ATTRIBS)
6069 {
6070 return gl::error(GL_INVALID_VALUE);
6071 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006072
Geoff Langbfdea662014-07-23 14:16:32 -04006073 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006074
Geoff Langbfdea662014-07-23 14:16:32 -04006075 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6076 {
6077 return;
6078 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006079
Geoff Langbfdea662014-07-23 14:16:32 -04006080 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6081 {
6082 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6083 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006084 {
Geoff Langbfdea662014-07-23 14:16:32 -04006085 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006086 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006087 }
Geoff Langbfdea662014-07-23 14:16:32 -04006088 else
6089 {
6090 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6091 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006092 }
6093}
6094
6095void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6096{
6097 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6098 index, pname, params);
6099
Geoff Langbfdea662014-07-23 14:16:32 -04006100 gl::Context *context = gl::getNonLostContext();
6101
6102 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006103 {
Geoff Langbfdea662014-07-23 14:16:32 -04006104 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006105 {
Geoff Langbfdea662014-07-23 14:16:32 -04006106 return gl::error(GL_INVALID_OPERATION);
6107 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006108
Geoff Langbfdea662014-07-23 14:16:32 -04006109 if (index >= gl::MAX_VERTEX_ATTRIBS)
6110 {
6111 return gl::error(GL_INVALID_VALUE);
6112 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006113
Geoff Langbfdea662014-07-23 14:16:32 -04006114 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006115
Geoff Langbfdea662014-07-23 14:16:32 -04006116 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6117 {
6118 return;
6119 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006120
Geoff Langbfdea662014-07-23 14:16:32 -04006121 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6122 {
6123 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6124 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006125 {
Geoff Langbfdea662014-07-23 14:16:32 -04006126 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006127 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006128 }
Geoff Langbfdea662014-07-23 14:16:32 -04006129 else
6130 {
6131 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6132 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006133 }
6134}
6135
6136void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6137{
6138 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6139 index, x, y, z, w);
6140
Geoff Langbfdea662014-07-23 14:16:32 -04006141 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006142
Geoff Langbfdea662014-07-23 14:16:32 -04006143 if (context)
6144 {
6145 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006146 {
Geoff Langbfdea662014-07-23 14:16:32 -04006147 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006148 }
Geoff Langbfdea662014-07-23 14:16:32 -04006149
6150 if (index >= gl::MAX_VERTEX_ATTRIBS)
6151 {
6152 return gl::error(GL_INVALID_VALUE);
6153 }
6154
6155 GLint vals[4] = { x, y, z, w };
6156 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006157 }
6158}
6159
6160void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6161{
6162 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6163 index, x, y, z, w);
6164
Geoff Langbfdea662014-07-23 14:16:32 -04006165 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006166
Geoff Langbfdea662014-07-23 14:16:32 -04006167 if (context)
6168 {
6169 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006170 {
Geoff Langbfdea662014-07-23 14:16:32 -04006171 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006172 }
Geoff Langbfdea662014-07-23 14:16:32 -04006173
6174 if (index >= gl::MAX_VERTEX_ATTRIBS)
6175 {
6176 return gl::error(GL_INVALID_VALUE);
6177 }
6178
6179 GLuint vals[4] = { x, y, z, w };
6180 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006181 }
6182}
6183
6184void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6185{
6186 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6187
Geoff Langbfdea662014-07-23 14:16:32 -04006188 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006189
Geoff Langbfdea662014-07-23 14:16:32 -04006190 if (context)
6191 {
6192 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006193 {
Geoff Langbfdea662014-07-23 14:16:32 -04006194 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006195 }
Geoff Langbfdea662014-07-23 14:16:32 -04006196
6197 if (index >= gl::MAX_VERTEX_ATTRIBS)
6198 {
6199 return gl::error(GL_INVALID_VALUE);
6200 }
6201
6202 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006203 }
6204}
6205
6206void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6207{
6208 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6209
Geoff Langbfdea662014-07-23 14:16:32 -04006210 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006211
Geoff Langbfdea662014-07-23 14:16:32 -04006212 if (context)
6213 {
6214 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006215 {
Geoff Langbfdea662014-07-23 14:16:32 -04006216 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006217 }
Geoff Langbfdea662014-07-23 14:16:32 -04006218
6219 if (index >= gl::MAX_VERTEX_ATTRIBS)
6220 {
6221 return gl::error(GL_INVALID_VALUE);
6222 }
6223
6224 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006225 }
6226}
6227
6228void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6229{
6230 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6231 program, location, params);
6232
Geoff Langbfdea662014-07-23 14:16:32 -04006233 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006234
Geoff Langbfdea662014-07-23 14:16:32 -04006235 if (context)
6236 {
6237 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006238 {
Geoff Langbfdea662014-07-23 14:16:32 -04006239 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006240 }
Geoff Langbfdea662014-07-23 14:16:32 -04006241
6242 if (program == 0)
6243 {
6244 return gl::error(GL_INVALID_VALUE);
6245 }
6246
6247 gl::Program *programObject = context->getProgram(program);
6248
6249 if (!programObject || !programObject->isLinked())
6250 {
6251 return gl::error(GL_INVALID_OPERATION);
6252 }
6253
6254 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6255 if (!programBinary)
6256 {
6257 return gl::error(GL_INVALID_OPERATION);
6258 }
6259
6260 if (!programBinary->getUniformuiv(location, NULL, params))
6261 {
6262 return gl::error(GL_INVALID_OPERATION);
6263 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006264 }
6265}
6266
6267GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6268{
6269 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6270 program, name);
6271
Geoff Langbfdea662014-07-23 14:16:32 -04006272 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006273
Geoff Langbfdea662014-07-23 14:16:32 -04006274 if (context)
6275 {
6276 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006277 {
Geoff Langbfdea662014-07-23 14:16:32 -04006278 return gl::error(GL_INVALID_OPERATION, -1);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006279 }
Geoff Langbfdea662014-07-23 14:16:32 -04006280
6281 if (program == 0)
6282 {
6283 return gl::error(GL_INVALID_VALUE, -1);
6284 }
6285
6286 gl::Program *programObject = context->getProgram(program);
6287
6288 if (!programObject || !programObject->isLinked())
6289 {
6290 return gl::error(GL_INVALID_OPERATION, -1);
6291 }
6292
6293 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6294 if (!programBinary)
6295 {
6296 return gl::error(GL_INVALID_OPERATION, -1);
6297 }
6298
6299 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006300 }
6301
6302 return 0;
6303}
6304
6305void __stdcall glUniform1ui(GLint location, GLuint v0)
6306{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006307 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006308}
6309
6310void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6311{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006312 const GLuint xy[] = { v0, v1 };
6313 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006314}
6315
6316void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6317{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006318 const GLuint xyz[] = { v0, v1, v2 };
6319 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006320}
6321
6322void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6323{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006324 const GLuint xyzw[] = { v0, v1, v2, v3 };
6325 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006326}
6327
6328void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6329{
6330 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6331 location, count, value);
6332
Geoff Langbfdea662014-07-23 14:16:32 -04006333 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006334
Geoff Langbfdea662014-07-23 14:16:32 -04006335 if (context)
6336 {
6337 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006338 {
Geoff Langbfdea662014-07-23 14:16:32 -04006339 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006340 }
Geoff Langbfdea662014-07-23 14:16:32 -04006341
6342 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6343 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006344 }
6345}
6346
6347void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6348{
6349 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6350 location, count, value);
6351
Geoff Langbfdea662014-07-23 14:16:32 -04006352 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006353
Geoff Langbfdea662014-07-23 14:16:32 -04006354 if (context)
6355 {
6356 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006357 {
Geoff Langbfdea662014-07-23 14:16:32 -04006358 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006359 }
Geoff Langbfdea662014-07-23 14:16:32 -04006360
6361 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6362 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006363 }
6364}
6365
6366void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6367{
6368 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6369 location, count, value);
6370
Geoff Langbfdea662014-07-23 14:16:32 -04006371 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006372
Geoff Langbfdea662014-07-23 14:16:32 -04006373 if (context)
6374 {
6375 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006376 {
Geoff Langbfdea662014-07-23 14:16:32 -04006377 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006378 }
Geoff Langbfdea662014-07-23 14:16:32 -04006379
6380 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6381 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006382 }
6383}
6384
6385void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6386{
6387 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6388 location, count, value);
6389
Geoff Langbfdea662014-07-23 14:16:32 -04006390 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006391
Geoff Langbfdea662014-07-23 14:16:32 -04006392 if (context)
6393 {
6394 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006395 {
Geoff Langbfdea662014-07-23 14:16:32 -04006396 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006397 }
Geoff Langbfdea662014-07-23 14:16:32 -04006398
6399 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6400 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006401 }
6402}
6403
6404void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6405{
6406 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6407 buffer, drawbuffer, value);
6408
Geoff Langbfdea662014-07-23 14:16:32 -04006409 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006410
Geoff Langbfdea662014-07-23 14:16:32 -04006411 if (context)
6412 {
6413 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006414 {
Geoff Langbfdea662014-07-23 14:16:32 -04006415 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006416 }
Geoff Langbfdea662014-07-23 14:16:32 -04006417
6418 switch (buffer)
6419 {
6420 case GL_COLOR:
6421 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6422 {
6423 return gl::error(GL_INVALID_VALUE);
6424 }
6425 break;
6426 case GL_STENCIL:
6427 if (drawbuffer != 0)
6428 {
6429 return gl::error(GL_INVALID_VALUE);
6430 }
6431 break;
6432 default:
6433 return gl::error(GL_INVALID_ENUM);
6434 }
6435
6436 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006437 }
6438}
6439
6440void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6441{
6442 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6443 buffer, drawbuffer, value);
6444
Geoff Langbfdea662014-07-23 14:16:32 -04006445 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006446
Geoff Langbfdea662014-07-23 14:16:32 -04006447 if (context)
6448 {
6449 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006450 {
Geoff Langbfdea662014-07-23 14:16:32 -04006451 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006452 }
Geoff Langbfdea662014-07-23 14:16:32 -04006453
6454 switch (buffer)
6455 {
6456 case GL_COLOR:
6457 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6458 {
6459 return gl::error(GL_INVALID_VALUE);
6460 }
6461 break;
6462 default:
6463 return gl::error(GL_INVALID_ENUM);
6464 }
6465
6466 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006467 }
6468}
6469
6470void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6471{
6472 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6473 buffer, drawbuffer, value);
6474
Geoff Langbfdea662014-07-23 14:16:32 -04006475 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006476
Geoff Langbfdea662014-07-23 14:16:32 -04006477 if (context)
6478 {
6479 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006480 {
Geoff Langbfdea662014-07-23 14:16:32 -04006481 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006482 }
Geoff Langbfdea662014-07-23 14:16:32 -04006483
6484 switch (buffer)
6485 {
6486 case GL_COLOR:
6487 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6488 {
6489 return gl::error(GL_INVALID_VALUE);
6490 }
6491 break;
6492 case GL_DEPTH:
6493 if (drawbuffer != 0)
6494 {
6495 return gl::error(GL_INVALID_VALUE);
6496 }
6497 break;
6498 default:
6499 return gl::error(GL_INVALID_ENUM);
6500 }
6501
6502 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006503 }
6504}
6505
6506void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6507{
6508 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6509 buffer, drawbuffer, depth, stencil);
6510
Geoff Langbfdea662014-07-23 14:16:32 -04006511 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006512
Geoff Langbfdea662014-07-23 14:16:32 -04006513 if (context)
6514 {
6515 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006516 {
Geoff Langbfdea662014-07-23 14:16:32 -04006517 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006518 }
Geoff Langbfdea662014-07-23 14:16:32 -04006519
6520 switch (buffer)
6521 {
6522 case GL_DEPTH_STENCIL:
6523 if (drawbuffer != 0)
6524 {
6525 return gl::error(GL_INVALID_VALUE);
6526 }
6527 break;
6528 default:
6529 return gl::error(GL_INVALID_ENUM);
6530 }
6531
6532 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006533 }
6534}
6535
6536const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6537{
6538 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6539
Geoff Langbfdea662014-07-23 14:16:32 -04006540 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006541
Geoff Langbfdea662014-07-23 14:16:32 -04006542 if (context)
6543 {
6544 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006545 {
Geoff Langbfdea662014-07-23 14:16:32 -04006546 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006547 }
Geoff Langbfdea662014-07-23 14:16:32 -04006548
6549 if (name != GL_EXTENSIONS)
6550 {
6551 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
6552 }
6553
6554 if (index >= context->getExtensionStringCount())
6555 {
6556 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
6557 }
6558
6559 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006560 }
6561
6562 return NULL;
6563}
6564
6565void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6566{
6567 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6568 readTarget, writeTarget, readOffset, writeOffset, size);
6569
Geoff Langbfdea662014-07-23 14:16:32 -04006570 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006571
Geoff Langbfdea662014-07-23 14:16:32 -04006572 if (context)
6573 {
6574 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006575 {
Geoff Langbfdea662014-07-23 14:16:32 -04006576 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006577 }
Geoff Langbfdea662014-07-23 14:16:32 -04006578
6579 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6580 {
6581 return gl::error(GL_INVALID_ENUM);
6582 }
6583
6584 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6585 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6586
6587 if (!readBuffer || !writeBuffer)
6588 {
6589 return gl::error(GL_INVALID_OPERATION);
6590 }
6591
Jamie Madillcfaaf722014-07-31 10:47:54 -04006592 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006593 if (readBuffer->isMapped() || writeBuffer->isMapped())
6594 {
6595 return gl::error(GL_INVALID_OPERATION);
6596 }
6597
6598 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6599 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6600 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6601 {
6602 return gl::error(GL_INVALID_VALUE);
6603 }
6604
6605 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6606 {
6607 return gl::error(GL_INVALID_VALUE);
6608 }
6609
Geoff Langbfdea662014-07-23 14:16:32 -04006610 // if size is zero, the copy is a successful no-op
6611 if (size > 0)
6612 {
6613 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006615 }
6616}
6617
6618void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6619{
6620 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6621 program, uniformCount, uniformNames, uniformIndices);
6622
Geoff Langbfdea662014-07-23 14:16:32 -04006623 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006624
Geoff Langbfdea662014-07-23 14:16:32 -04006625 if (context)
6626 {
6627 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006628 {
Geoff Langbfdea662014-07-23 14:16:32 -04006629 return gl::error(GL_INVALID_OPERATION);
6630 }
6631
6632 if (uniformCount < 0)
6633 {
6634 return gl::error(GL_INVALID_VALUE);
6635 }
6636
6637 gl::Program *programObject = context->getProgram(program);
6638
6639 if (!programObject)
6640 {
6641 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006642 {
6643 return gl::error(GL_INVALID_OPERATION);
6644 }
Geoff Langbfdea662014-07-23 14:16:32 -04006645 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006646 {
6647 return gl::error(GL_INVALID_VALUE);
6648 }
Geoff Langbfdea662014-07-23 14:16:32 -04006649 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006650
Geoff Langbfdea662014-07-23 14:16:32 -04006651 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6652 if (!programObject->isLinked() || !programBinary)
6653 {
6654 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006655 {
Geoff Langbfdea662014-07-23 14:16:32 -04006656 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006657 }
6658 }
Geoff Langbfdea662014-07-23 14:16:32 -04006659 else
6660 {
6661 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6662 {
6663 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6664 }
6665 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006666 }
6667}
6668
6669void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6670{
6671 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6672 program, uniformCount, uniformIndices, pname, params);
6673
Geoff Langbfdea662014-07-23 14:16:32 -04006674 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006675
Geoff Langbfdea662014-07-23 14:16:32 -04006676 if (context)
6677 {
6678 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006679 {
Geoff Langbfdea662014-07-23 14:16:32 -04006680 return gl::error(GL_INVALID_OPERATION);
6681 }
6682
6683 if (uniformCount < 0)
6684 {
6685 return gl::error(GL_INVALID_VALUE);
6686 }
6687
6688 gl::Program *programObject = context->getProgram(program);
6689
6690 if (!programObject)
6691 {
6692 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006693 {
6694 return gl::error(GL_INVALID_OPERATION);
6695 }
Geoff Langbfdea662014-07-23 14:16:32 -04006696 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006697 {
6698 return gl::error(GL_INVALID_VALUE);
6699 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006700 }
Geoff Langbfdea662014-07-23 14:16:32 -04006701
6702 switch (pname)
6703 {
6704 case GL_UNIFORM_TYPE:
6705 case GL_UNIFORM_SIZE:
6706 case GL_UNIFORM_NAME_LENGTH:
6707 case GL_UNIFORM_BLOCK_INDEX:
6708 case GL_UNIFORM_OFFSET:
6709 case GL_UNIFORM_ARRAY_STRIDE:
6710 case GL_UNIFORM_MATRIX_STRIDE:
6711 case GL_UNIFORM_IS_ROW_MAJOR:
6712 break;
6713 default:
6714 return gl::error(GL_INVALID_ENUM);
6715 }
6716
6717 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6718
6719 if (!programBinary && uniformCount > 0)
6720 {
6721 return gl::error(GL_INVALID_VALUE);
6722 }
6723
6724 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6725 {
6726 const GLuint index = uniformIndices[uniformId];
6727
6728 if (index >= (GLuint)programBinary->getActiveUniformCount())
6729 {
6730 return gl::error(GL_INVALID_VALUE);
6731 }
6732 }
6733
6734 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6735 {
6736 const GLuint index = uniformIndices[uniformId];
6737 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6738 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006739 }
6740}
6741
6742GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6743{
6744 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6745
Geoff Langbfdea662014-07-23 14:16:32 -04006746 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006747
Geoff Langbfdea662014-07-23 14:16:32 -04006748 if (context)
6749 {
6750 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006751 {
Geoff Langbfdea662014-07-23 14:16:32 -04006752 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
6753 }
6754
6755 gl::Program *programObject = context->getProgram(program);
6756
6757 if (!programObject)
6758 {
6759 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006760 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006761 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006762 }
Geoff Langbfdea662014-07-23 14:16:32 -04006763 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006764 {
Geoff Langbfdea662014-07-23 14:16:32 -04006765 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006766 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006767 }
Geoff Langbfdea662014-07-23 14:16:32 -04006768
6769 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6770 if (!programBinary)
6771 {
6772 return GL_INVALID_INDEX;
6773 }
6774
6775 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006776 }
6777
6778 return 0;
6779}
6780
6781void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6782{
6783 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6784 program, uniformBlockIndex, pname, params);
6785
Geoff Langbfdea662014-07-23 14:16:32 -04006786 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006787
Geoff Langbfdea662014-07-23 14:16:32 -04006788 if (context)
6789 {
6790 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006791 {
Geoff Langbfdea662014-07-23 14:16:32 -04006792 return gl::error(GL_INVALID_OPERATION);
6793 }
6794 gl::Program *programObject = context->getProgram(program);
6795
6796 if (!programObject)
6797 {
6798 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006799 {
6800 return gl::error(GL_INVALID_OPERATION);
6801 }
Geoff Langbfdea662014-07-23 14:16:32 -04006802 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006803 {
6804 return gl::error(GL_INVALID_VALUE);
6805 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006806 }
Geoff Langbfdea662014-07-23 14:16:32 -04006807
6808 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6809
6810 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6811 {
6812 return gl::error(GL_INVALID_VALUE);
6813 }
6814
6815 switch (pname)
6816 {
6817 case GL_UNIFORM_BLOCK_BINDING:
6818 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
6819 break;
6820
6821 case GL_UNIFORM_BLOCK_DATA_SIZE:
6822 case GL_UNIFORM_BLOCK_NAME_LENGTH:
6823 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
6824 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
6825 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
6826 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
6827 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
6828 break;
6829
6830 default:
6831 return gl::error(GL_INVALID_ENUM);
6832 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006833 }
6834}
6835
6836void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
6837{
6838 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
6839 program, uniformBlockIndex, bufSize, length, uniformBlockName);
6840
Geoff Langbfdea662014-07-23 14:16:32 -04006841 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006842
Geoff Langbfdea662014-07-23 14:16:32 -04006843 if (context)
6844 {
6845 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006846 {
Geoff Langbfdea662014-07-23 14:16:32 -04006847 return gl::error(GL_INVALID_OPERATION);
6848 }
6849
6850 gl::Program *programObject = context->getProgram(program);
6851
6852 if (!programObject)
6853 {
6854 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006855 {
6856 return gl::error(GL_INVALID_OPERATION);
6857 }
Geoff Langbfdea662014-07-23 14:16:32 -04006858 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006859 {
6860 return gl::error(GL_INVALID_VALUE);
6861 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006862 }
Geoff Langbfdea662014-07-23 14:16:32 -04006863
6864 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6865
6866 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6867 {
6868 return gl::error(GL_INVALID_VALUE);
6869 }
6870
6871 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006872 }
6873}
6874
6875void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
6876{
6877 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
6878 program, uniformBlockIndex, uniformBlockBinding);
6879
Geoff Langbfdea662014-07-23 14:16:32 -04006880 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006881
Geoff Langbfdea662014-07-23 14:16:32 -04006882 if (context)
6883 {
6884 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006885 {
Geoff Langbfdea662014-07-23 14:16:32 -04006886 return gl::error(GL_INVALID_OPERATION);
6887 }
6888
6889 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
6890 {
6891 return gl::error(GL_INVALID_VALUE);
6892 }
6893
6894 gl::Program *programObject = context->getProgram(program);
6895
6896 if (!programObject)
6897 {
6898 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006899 {
6900 return gl::error(GL_INVALID_OPERATION);
6901 }
Geoff Langbfdea662014-07-23 14:16:32 -04006902 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006903 {
6904 return gl::error(GL_INVALID_VALUE);
6905 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006906 }
Geoff Langbfdea662014-07-23 14:16:32 -04006907
6908 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6909
6910 // if never linked, there won't be any uniform blocks
6911 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6912 {
6913 return gl::error(GL_INVALID_VALUE);
6914 }
6915
6916 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006917 }
6918}
6919
6920void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
6921{
6922 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
6923 mode, first, count, instanceCount);
6924
Geoff Langbfdea662014-07-23 14:16:32 -04006925 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006926
Geoff Langbfdea662014-07-23 14:16:32 -04006927 if (context)
6928 {
6929 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006930 {
Geoff Langbfdea662014-07-23 14:16:32 -04006931 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006932 }
Geoff Langbfdea662014-07-23 14:16:32 -04006933
6934 // glDrawArraysInstanced
6935 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006936 }
6937}
6938
6939void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
6940{
6941 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
6942 mode, count, type, indices, instanceCount);
6943
Geoff Langbfdea662014-07-23 14:16:32 -04006944 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006945
Geoff Langbfdea662014-07-23 14:16:32 -04006946 if (context)
6947 {
6948 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006949 {
Geoff Langbfdea662014-07-23 14:16:32 -04006950 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006951 }
Geoff Langbfdea662014-07-23 14:16:32 -04006952
6953 // glDrawElementsInstanced
6954 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006955 }
6956}
6957
6958GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
6959{
6960 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
6961
Geoff Langbfdea662014-07-23 14:16:32 -04006962 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006963
Geoff Langbfdea662014-07-23 14:16:32 -04006964 if (context)
6965 {
6966 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006967 {
Geoff Langbfdea662014-07-23 14:16:32 -04006968 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006969 }
Geoff Langbfdea662014-07-23 14:16:32 -04006970
6971 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
6972 {
6973 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
6974 }
6975
6976 if (flags != 0)
6977 {
6978 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
6979 }
6980
6981 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006982 }
6983
6984 return NULL;
6985}
6986
6987GLboolean __stdcall glIsSync(GLsync sync)
6988{
6989 EVENT("(GLsync sync = 0x%0.8p)", sync);
6990
Geoff Langbfdea662014-07-23 14:16:32 -04006991 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006992
Geoff Langbfdea662014-07-23 14:16:32 -04006993 if (context)
6994 {
6995 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006996 {
Geoff Langbfdea662014-07-23 14:16:32 -04006997 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006998 }
Geoff Langbfdea662014-07-23 14:16:32 -04006999
7000 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007001 }
7002
7003 return GL_FALSE;
7004}
7005
7006void __stdcall glDeleteSync(GLsync sync)
7007{
7008 EVENT("(GLsync sync = 0x%0.8p)", sync);
7009
Geoff Langbfdea662014-07-23 14:16:32 -04007010 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007011
Geoff Langbfdea662014-07-23 14:16:32 -04007012 if (context)
7013 {
7014 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007015 {
Geoff Langbfdea662014-07-23 14:16:32 -04007016 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007017 }
Geoff Langbfdea662014-07-23 14:16:32 -04007018
7019 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7020 {
7021 return gl::error(GL_INVALID_VALUE);
7022 }
7023
7024 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007025 }
7026}
7027
7028GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7029{
7030 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7031 sync, flags, timeout);
7032
Geoff Langbfdea662014-07-23 14:16:32 -04007033 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007034
Geoff Langbfdea662014-07-23 14:16:32 -04007035 if (context)
7036 {
7037 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007038 {
Geoff Langbfdea662014-07-23 14:16:32 -04007039 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007040 }
Geoff Langbfdea662014-07-23 14:16:32 -04007041
7042 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7043 {
7044 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7045 }
7046
7047 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7048
7049 if (!fenceSync)
7050 {
7051 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7052 }
7053
7054 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007055 }
7056
7057 return GL_FALSE;
7058}
7059
7060void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7061{
7062 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7063 sync, flags, timeout);
7064
Geoff Langbfdea662014-07-23 14:16:32 -04007065 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007066
Geoff Langbfdea662014-07-23 14:16:32 -04007067 if (context)
7068 {
7069 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007070 {
Geoff Langbfdea662014-07-23 14:16:32 -04007071 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007072 }
Geoff Langbfdea662014-07-23 14:16:32 -04007073
7074 if (flags != 0)
7075 {
7076 return gl::error(GL_INVALID_VALUE);
7077 }
7078
7079 if (timeout != GL_TIMEOUT_IGNORED)
7080 {
7081 return gl::error(GL_INVALID_VALUE);
7082 }
7083
7084 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7085
7086 if (!fenceSync)
7087 {
7088 return gl::error(GL_INVALID_VALUE);
7089 }
7090
7091 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007092 }
7093}
7094
7095void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7096{
7097 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7098 pname, params);
7099
Geoff Langbfdea662014-07-23 14:16:32 -04007100 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007101
Geoff Langbfdea662014-07-23 14:16:32 -04007102 if (context)
7103 {
7104 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007105 {
Geoff Langbfdea662014-07-23 14:16:32 -04007106 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007107 }
Geoff Langbfdea662014-07-23 14:16:32 -04007108
7109 GLenum nativeType;
7110 unsigned int numParams = 0;
7111 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7112 {
7113 return;
7114 }
7115
7116 if (nativeType == GL_INT_64_ANGLEX)
7117 {
7118 context->getInteger64v(pname, params);
7119 }
7120 else
7121 {
7122 CastStateValues(context, nativeType, pname, numParams, params);
7123 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007124 }
7125}
7126
7127void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7128{
7129 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7130 sync, pname, bufSize, length, values);
7131
Geoff Langbfdea662014-07-23 14:16:32 -04007132 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007133
Geoff Langbfdea662014-07-23 14:16:32 -04007134 if (context)
7135 {
7136 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007137 {
Geoff Langbfdea662014-07-23 14:16:32 -04007138 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007139 }
Geoff Langbfdea662014-07-23 14:16:32 -04007140
7141 if (bufSize < 0)
7142 {
7143 return gl::error(GL_INVALID_VALUE);
7144 }
7145
7146 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7147
7148 if (!fenceSync)
7149 {
7150 return gl::error(GL_INVALID_VALUE);
7151 }
7152
7153 switch (pname)
7154 {
7155 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7156 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7157 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7158 case GL_SYNC_FLAGS: values[0] = 0; break;
7159
7160 default:
7161 return gl::error(GL_INVALID_ENUM);
7162 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007163 }
7164}
7165
7166void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7167{
7168 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7169 target, index, data);
7170
Geoff Langbfdea662014-07-23 14:16:32 -04007171 gl::Context *context = gl::getNonLostContext();
7172
7173 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007174 {
Geoff Langbfdea662014-07-23 14:16:32 -04007175 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007176 {
Geoff Langbfdea662014-07-23 14:16:32 -04007177 return gl::error(GL_INVALID_OPERATION);
7178 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007179
Geoff Langbfdea662014-07-23 14:16:32 -04007180 switch (target)
7181 {
7182 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7183 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7184 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7185 if (index >= context->getMaxTransformFeedbackBufferBindings())
7186 return gl::error(GL_INVALID_VALUE);
7187 break;
7188 case GL_UNIFORM_BUFFER_START:
7189 case GL_UNIFORM_BUFFER_SIZE:
7190 case GL_UNIFORM_BUFFER_BINDING:
7191 if (index >= context->getMaximumCombinedUniformBufferBindings())
7192 return gl::error(GL_INVALID_VALUE);
7193 break;
7194 default:
7195 return gl::error(GL_INVALID_ENUM);
7196 }
7197
7198 if (!(context->getIndexedInteger64v(target, index, data)))
7199 {
7200 GLenum nativeType;
7201 unsigned int numParams = 0;
7202 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04007203 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04007204
Geoff Langbfdea662014-07-23 14:16:32 -04007205 if (numParams == 0)
7206 return; // it is known that pname is valid, but there are no parameters to return
7207
7208 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007209 {
Geoff Langbfdea662014-07-23 14:16:32 -04007210 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007211
Geoff Langbfdea662014-07-23 14:16:32 -04007212 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007213
Geoff Langbfdea662014-07-23 14:16:32 -04007214 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007215 {
Geoff Langbfdea662014-07-23 14:16:32 -04007216 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007217 }
Geoff Langbfdea662014-07-23 14:16:32 -04007218
7219 delete [] intParams;
7220 }
7221 else
7222 {
7223 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007224 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007225 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007226 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007227}
7228
7229void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7230{
7231 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7232 target, pname, params);
7233
Geoff Langbfdea662014-07-23 14:16:32 -04007234 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007235
Geoff Langbfdea662014-07-23 14:16:32 -04007236 if (context)
7237 {
7238 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007239 {
Geoff Langbfdea662014-07-23 14:16:32 -04007240 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007241 }
Geoff Langbfdea662014-07-23 14:16:32 -04007242
7243 if (!gl::ValidBufferTarget(context, target))
7244 {
7245 return gl::error(GL_INVALID_ENUM);
7246 }
7247
7248 if (!gl::ValidBufferParameter(context, pname))
7249 {
7250 return gl::error(GL_INVALID_ENUM);
7251 }
7252
7253 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7254
7255 if (!buffer)
7256 {
7257 // A null buffer means that "0" is bound to the requested buffer target
7258 return gl::error(GL_INVALID_OPERATION);
7259 }
7260
7261 switch (pname)
7262 {
7263 case GL_BUFFER_USAGE:
7264 *params = static_cast<GLint64>(buffer->getUsage());
7265 break;
7266 case GL_BUFFER_SIZE:
7267 *params = buffer->getSize();
7268 break;
7269 case GL_BUFFER_ACCESS_FLAGS:
7270 *params = static_cast<GLint64>(buffer->getAccessFlags());
7271 break;
7272 case GL_BUFFER_MAPPED:
7273 *params = static_cast<GLint64>(buffer->isMapped());
7274 break;
7275 case GL_BUFFER_MAP_OFFSET:
7276 *params = buffer->getMapOffset();
7277 break;
7278 case GL_BUFFER_MAP_LENGTH:
7279 *params = buffer->getMapLength();
7280 break;
7281 default: UNREACHABLE(); break;
7282 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007283 }
7284}
7285
7286void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7287{
7288 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7289
Geoff Langbfdea662014-07-23 14:16:32 -04007290 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007291
Geoff Langbfdea662014-07-23 14:16:32 -04007292 if (context)
7293 {
7294 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007295 {
Geoff Langbfdea662014-07-23 14:16:32 -04007296 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007297 }
Geoff Langbfdea662014-07-23 14:16:32 -04007298
7299 if (count < 0)
7300 {
7301 return gl::error(GL_INVALID_VALUE);
7302 }
7303
7304 for (int i = 0; i < count; i++)
7305 {
7306 samplers[i] = context->createSampler();
7307 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007308 }
7309}
7310
7311void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7312{
7313 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7314
Geoff Langbfdea662014-07-23 14:16:32 -04007315 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007316
Geoff Langbfdea662014-07-23 14:16:32 -04007317 if (context)
7318 {
7319 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007320 {
Geoff Langbfdea662014-07-23 14:16:32 -04007321 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007322 }
Geoff Langbfdea662014-07-23 14:16:32 -04007323
7324 if (count < 0)
7325 {
7326 return gl::error(GL_INVALID_VALUE);
7327 }
7328
7329 for (int i = 0; i < count; i++)
7330 {
7331 context->deleteSampler(samplers[i]);
7332 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007333 }
7334}
7335
7336GLboolean __stdcall glIsSampler(GLuint sampler)
7337{
7338 EVENT("(GLuint sampler = %u)", sampler);
7339
Geoff Langbfdea662014-07-23 14:16:32 -04007340 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007341
Geoff Langbfdea662014-07-23 14:16:32 -04007342 if (context)
7343 {
7344 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007345 {
Geoff Langbfdea662014-07-23 14:16:32 -04007346 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007347 }
Geoff Langbfdea662014-07-23 14:16:32 -04007348
7349 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007350 }
7351
7352 return GL_FALSE;
7353}
7354
7355void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7356{
7357 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7358
Geoff Langbfdea662014-07-23 14:16:32 -04007359 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007360
Geoff Langbfdea662014-07-23 14:16:32 -04007361 if (context)
7362 {
7363 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007364 {
Geoff Langbfdea662014-07-23 14:16:32 -04007365 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007366 }
Geoff Langbfdea662014-07-23 14:16:32 -04007367
7368 if (sampler != 0 && !context->isSampler(sampler))
7369 {
7370 return gl::error(GL_INVALID_OPERATION);
7371 }
7372
7373 if (unit >= context->getMaximumCombinedTextureImageUnits())
7374 {
7375 return gl::error(GL_INVALID_VALUE);
7376 }
7377
7378 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007379 }
7380}
7381
7382void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7383{
7384 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7385
Geoff Langbfdea662014-07-23 14:16:32 -04007386 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007387
Geoff Langbfdea662014-07-23 14:16:32 -04007388 if (context)
7389 {
7390 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007391 {
Geoff Langbfdea662014-07-23 14:16:32 -04007392 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007393 }
Geoff Langbfdea662014-07-23 14:16:32 -04007394
7395 if (!gl::ValidateSamplerObjectParameter(pname))
7396 {
7397 return;
7398 }
7399
7400 if (!gl::ValidateTexParamParameters(context, pname, param))
7401 {
7402 return;
7403 }
7404
7405 if (!context->isSampler(sampler))
7406 {
7407 return gl::error(GL_INVALID_OPERATION);
7408 }
7409
7410 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007411 }
7412}
7413
7414void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7415{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007416 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007417}
7418
7419void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7420{
7421 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7422
Geoff Langbfdea662014-07-23 14:16:32 -04007423 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007424
Geoff Langbfdea662014-07-23 14:16:32 -04007425 if (context)
7426 {
7427 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007428 {
Geoff Langbfdea662014-07-23 14:16:32 -04007429 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007430 }
Geoff Langbfdea662014-07-23 14:16:32 -04007431
7432 if (!gl::ValidateSamplerObjectParameter(pname))
7433 {
7434 return;
7435 }
7436
7437 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7438 {
7439 return;
7440 }
7441
7442 if (!context->isSampler(sampler))
7443 {
7444 return gl::error(GL_INVALID_OPERATION);
7445 }
7446
7447 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007448 }
7449}
7450
7451void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7452{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007453 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007454}
7455
7456void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7457{
7458 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7459
Geoff Langbfdea662014-07-23 14:16:32 -04007460 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007461
Geoff Langbfdea662014-07-23 14:16:32 -04007462 if (context)
7463 {
7464 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007465 {
Geoff Langbfdea662014-07-23 14:16:32 -04007466 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007467 }
Geoff Langbfdea662014-07-23 14:16:32 -04007468
7469 if (!gl::ValidateSamplerObjectParameter(pname))
7470 {
7471 return;
7472 }
7473
7474 if (!context->isSampler(sampler))
7475 {
7476 return gl::error(GL_INVALID_OPERATION);
7477 }
7478
7479 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007480 }
7481}
7482
7483void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7484{
7485 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7486
Geoff Langbfdea662014-07-23 14:16:32 -04007487 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007488
Geoff Langbfdea662014-07-23 14:16:32 -04007489 if (context)
7490 {
7491 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007492 {
Geoff Langbfdea662014-07-23 14:16:32 -04007493 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007494 }
Geoff Langbfdea662014-07-23 14:16:32 -04007495
7496 if (!gl::ValidateSamplerObjectParameter(pname))
7497 {
7498 return;
7499 }
7500
7501 if (!context->isSampler(sampler))
7502 {
7503 return gl::error(GL_INVALID_OPERATION);
7504 }
7505
7506 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007507 }
7508}
7509
7510void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7511{
7512 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7513
Geoff Langbfdea662014-07-23 14:16:32 -04007514 if (index >= gl::MAX_VERTEX_ATTRIBS)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007515 {
Geoff Langbfdea662014-07-23 14:16:32 -04007516 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007517 }
Geoff Langbfdea662014-07-23 14:16:32 -04007518
7519 gl::Context *context = gl::getNonLostContext();
7520
7521 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007522 {
Geoff Langbfdea662014-07-23 14:16:32 -04007523 if (context->getClientVersion() < 3)
7524 {
7525 return gl::error(GL_INVALID_OPERATION);
7526 }
7527
7528 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007529 }
7530}
7531
7532void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7533{
7534 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7535
Geoff Langbfdea662014-07-23 14:16:32 -04007536 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007537
Geoff Langbfdea662014-07-23 14:16:32 -04007538 if (context)
7539 {
7540 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007541 {
Geoff Langbfdea662014-07-23 14:16:32 -04007542 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007543 }
Geoff Langbfdea662014-07-23 14:16:32 -04007544
7545 switch (target)
7546 {
7547 case GL_TRANSFORM_FEEDBACK:
7548 {
7549 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7550 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7551 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7552 {
7553 return gl::error(GL_INVALID_OPERATION);
7554 }
7555
7556 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7557 if (context->getTransformFeedback(id) == NULL)
7558 {
7559 return gl::error(GL_INVALID_OPERATION);
7560 }
7561
7562 context->bindTransformFeedback(id);
7563 }
7564 break;
7565
7566 default:
7567 return gl::error(GL_INVALID_ENUM);
7568 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007569 }
7570}
7571
7572void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7573{
7574 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7575
Geoff Langbfdea662014-07-23 14:16:32 -04007576 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007577
Geoff Langbfdea662014-07-23 14:16:32 -04007578 if (context)
7579 {
7580 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007581 {
Geoff Langbfdea662014-07-23 14:16:32 -04007582 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007583 }
Geoff Langbfdea662014-07-23 14:16:32 -04007584
7585 for (int i = 0; i < n; i++)
7586 {
7587 context->deleteTransformFeedback(ids[i]);
7588 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007589 }
7590}
7591
7592void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7593{
7594 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7595
Geoff Langbfdea662014-07-23 14:16:32 -04007596 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007597
Geoff Langbfdea662014-07-23 14:16:32 -04007598 if (context)
7599 {
7600 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007601 {
Geoff Langbfdea662014-07-23 14:16:32 -04007602 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007603 }
Geoff Langbfdea662014-07-23 14:16:32 -04007604
7605 for (int i = 0; i < n; i++)
7606 {
7607 ids[i] = context->createTransformFeedback();
7608 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007609 }
7610}
7611
7612GLboolean __stdcall glIsTransformFeedback(GLuint id)
7613{
7614 EVENT("(GLuint id = %u)", id);
7615
Geoff Langbfdea662014-07-23 14:16:32 -04007616 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007617
Geoff Langbfdea662014-07-23 14:16:32 -04007618 if (context)
7619 {
7620 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007621 {
Geoff Langbfdea662014-07-23 14:16:32 -04007622 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007623 }
Geoff Langbfdea662014-07-23 14:16:32 -04007624
7625 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007626 }
7627
7628 return GL_FALSE;
7629}
7630
7631void __stdcall glPauseTransformFeedback(void)
7632{
7633 EVENT("(void)");
7634
Geoff Langbfdea662014-07-23 14:16:32 -04007635 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007636
Geoff Langbfdea662014-07-23 14:16:32 -04007637 if (context)
7638 {
7639 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007640 {
Geoff Langbfdea662014-07-23 14:16:32 -04007641 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007642 }
Geoff Langbfdea662014-07-23 14:16:32 -04007643
7644 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7645 ASSERT(transformFeedback != NULL);
7646
7647 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7648 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7649 {
7650 return gl::error(GL_INVALID_OPERATION);
7651 }
7652
7653 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007654 }
7655}
7656
7657void __stdcall glResumeTransformFeedback(void)
7658{
7659 EVENT("(void)");
7660
Geoff Langbfdea662014-07-23 14:16:32 -04007661 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007662
Geoff Langbfdea662014-07-23 14:16:32 -04007663 if (context)
7664 {
7665 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007666 {
Geoff Langbfdea662014-07-23 14:16:32 -04007667 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007668 }
Geoff Langbfdea662014-07-23 14:16:32 -04007669
7670 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7671 ASSERT(transformFeedback != NULL);
7672
7673 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7674 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7675 {
7676 return gl::error(GL_INVALID_OPERATION);
7677 }
7678
7679 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007680 }
7681}
7682
7683void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7684{
7685 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7686 program, bufSize, length, binaryFormat, binary);
7687
Geoff Langbfdea662014-07-23 14:16:32 -04007688 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007689
Geoff Langbfdea662014-07-23 14:16:32 -04007690 if (context)
7691 {
7692 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007693 {
Geoff Langbfdea662014-07-23 14:16:32 -04007694 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007695 }
Geoff Langbfdea662014-07-23 14:16:32 -04007696
7697 // glGetProgramBinary
7698 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007699 }
7700}
7701
7702void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7703{
7704 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7705 program, binaryFormat, binary, length);
7706
Geoff Langbfdea662014-07-23 14:16:32 -04007707 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007708
Geoff Langbfdea662014-07-23 14:16:32 -04007709 if (context)
7710 {
7711 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007712 {
Geoff Langbfdea662014-07-23 14:16:32 -04007713 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007714 }
Geoff Langbfdea662014-07-23 14:16:32 -04007715
7716 // glProgramBinary
7717 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007718 }
7719}
7720
7721void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7722{
7723 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7724 program, pname, value);
7725
Geoff Langbfdea662014-07-23 14:16:32 -04007726 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007727
Geoff Langbfdea662014-07-23 14:16:32 -04007728 if (context)
7729 {
7730 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007731 {
Geoff Langbfdea662014-07-23 14:16:32 -04007732 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007733 }
Geoff Langbfdea662014-07-23 14:16:32 -04007734
7735 // glProgramParameteri
7736 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007737 }
7738}
7739
7740void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7741{
7742 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7743 target, numAttachments, attachments);
7744
Geoff Langbfdea662014-07-23 14:16:32 -04007745 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007746
Geoff Langbfdea662014-07-23 14:16:32 -04007747 if (context)
7748 {
7749 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007750 {
Geoff Langbfdea662014-07-23 14:16:32 -04007751 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007752 }
Geoff Langbfdea662014-07-23 14:16:32 -04007753
7754 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7755 {
7756 return;
7757 }
7758
7759 GLuint maxDimension = context->getCaps().maxRenderbufferSize;
7760 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007761 }
7762}
7763
7764void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
7765{
7766 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
7767 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7768 target, numAttachments, attachments, x, y, width, height);
7769
Geoff Langbfdea662014-07-23 14:16:32 -04007770 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007771
Geoff Langbfdea662014-07-23 14:16:32 -04007772 if (context)
7773 {
7774 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007775 {
Geoff Langbfdea662014-07-23 14:16:32 -04007776 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007777 }
Geoff Langbfdea662014-07-23 14:16:32 -04007778
7779 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7780 {
7781 return;
7782 }
7783
7784 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007785 }
7786}
7787
7788void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7789{
7790 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7791 target, levels, internalformat, width, height);
7792
Geoff Langbfdea662014-07-23 14:16:32 -04007793 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007794
Geoff Langbfdea662014-07-23 14:16:32 -04007795 if (context)
7796 {
7797 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007798 {
Geoff Langbfdea662014-07-23 14:16:32 -04007799 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007800 }
Geoff Langbfdea662014-07-23 14:16:32 -04007801
7802 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
7803 {
7804 return;
7805 }
7806
7807 switch (target)
7808 {
7809 case GL_TEXTURE_2D:
7810 {
7811 gl::Texture2D *texture2d = context->getTexture2D();
7812 texture2d->storage(levels, internalformat, width, height);
7813 }
7814 break;
7815
7816 case GL_TEXTURE_CUBE_MAP:
7817 {
7818 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7819 textureCube->storage(levels, internalformat, width);
7820 }
7821 break;
7822
7823 default:
7824 return gl::error(GL_INVALID_ENUM);
7825 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007826 }
7827}
7828
7829void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
7830{
7831 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
7832 "GLsizei height = %d, GLsizei depth = %d)",
7833 target, levels, internalformat, width, height, depth);
7834
Geoff Langbfdea662014-07-23 14:16:32 -04007835 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007836
Geoff Langbfdea662014-07-23 14:16:32 -04007837 if (context)
7838 {
7839 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007840 {
Geoff Langbfdea662014-07-23 14:16:32 -04007841 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00007842 }
Geoff Langbfdea662014-07-23 14:16:32 -04007843
7844 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
7845 {
7846 return;
7847 }
7848
7849 switch (target)
7850 {
7851 case GL_TEXTURE_3D:
7852 {
7853 gl::Texture3D *texture3d = context->getTexture3D();
7854 texture3d->storage(levels, internalformat, width, height, depth);
7855 }
7856 break;
7857
7858 case GL_TEXTURE_2D_ARRAY:
7859 {
7860 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
7861 texture2darray->storage(levels, internalformat, width, height, depth);
7862 }
7863 break;
7864
7865 default:
7866 UNREACHABLE();
7867 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007868 }
7869}
7870
7871void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
7872{
7873 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
7874 "GLint* params = 0x%0.8p)",
7875 target, internalformat, pname, bufSize, params);
7876
Geoff Langbfdea662014-07-23 14:16:32 -04007877 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007878
Geoff Langbfdea662014-07-23 14:16:32 -04007879 if (context)
7880 {
7881 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007882 {
Geoff Langbfdea662014-07-23 14:16:32 -04007883 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007884 }
Geoff Langbfdea662014-07-23 14:16:32 -04007885
7886 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7887 if (!formatCaps.renderable)
7888 {
7889 return gl::error(GL_INVALID_ENUM);
7890 }
7891
7892 if (target != GL_RENDERBUFFER)
7893 {
7894 return gl::error(GL_INVALID_ENUM);
7895 }
7896
7897 if (bufSize < 0)
7898 {
7899 return gl::error(GL_INVALID_VALUE);
7900 }
7901
7902 switch (pname)
7903 {
7904 case GL_NUM_SAMPLE_COUNTS:
7905 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04007906 {
7907 *params = formatCaps.sampleCounts.size();
7908 }
Geoff Langbfdea662014-07-23 14:16:32 -04007909 break;
7910 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04007911 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04007912 break;
7913 default:
7914 return gl::error(GL_INVALID_ENUM);
7915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007916 }
7917}
7918
7919// Extension functions
7920
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007921void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
7922 GLbitfield mask, GLenum filter)
7923{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007924 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007925 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
7926 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
7927 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
7928
Geoff Langbfdea662014-07-23 14:16:32 -04007929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007930
Geoff Langbfdea662014-07-23 14:16:32 -04007931 if (context)
7932 {
7933 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
7934 dstX0, dstY0, dstX1, dstY1, mask, filter,
7935 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007936 {
Geoff Langbfdea662014-07-23 14:16:32 -04007937 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007938 }
Geoff Langbfdea662014-07-23 14:16:32 -04007939
7940 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
7941 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007942 }
7943}
7944
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007945void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
7946 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007947{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007948 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007949 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007950 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007951 target, level, internalformat, width, height, depth, border, format, type, pixels);
7952
Geoff Langbfdea662014-07-23 14:16:32 -04007953 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007954}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00007955
Geoff Langbfdea662014-07-23 14:16:32 -04007956void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007957 GLenum *binaryFormat, void *binary)
7958{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00007959 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 +00007960 program, bufSize, length, binaryFormat, binary);
7961
Geoff Langbfdea662014-07-23 14:16:32 -04007962 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007963
Geoff Langbfdea662014-07-23 14:16:32 -04007964 if (context)
7965 {
7966 gl::Program *programObject = context->getProgram(program);
7967
7968 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007969 {
Geoff Langbfdea662014-07-23 14:16:32 -04007970 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007971 }
Geoff Langbfdea662014-07-23 14:16:32 -04007972
7973 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7974
7975 if (!programBinary)
7976 {
7977 return gl::error(GL_INVALID_OPERATION);
7978 }
7979
7980 if (!programBinary->save(binary, bufSize, length))
7981 {
7982 return gl::error(GL_INVALID_OPERATION);
7983 }
7984
7985 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007986 }
7987}
7988
7989void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
7990 const void *binary, GLint length)
7991{
7992 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
7993 program, binaryFormat, binary, length);
7994
Geoff Langbfdea662014-07-23 14:16:32 -04007995 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007996
Geoff Langbfdea662014-07-23 14:16:32 -04007997 if (context)
7998 {
7999 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008000 {
Geoff Langbfdea662014-07-23 14:16:32 -04008001 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008002 }
Geoff Langbfdea662014-07-23 14:16:32 -04008003
8004 gl::Program *programObject = context->getProgram(program);
8005
8006 if (!programObject)
8007 {
8008 return gl::error(GL_INVALID_OPERATION);
8009 }
8010
8011 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008012 }
8013}
8014
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008015void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8016{
8017 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8018
Geoff Langbfdea662014-07-23 14:16:32 -04008019 gl::Context *context = gl::getNonLostContext();
8020
8021 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008022 {
Geoff Langbfdea662014-07-23 14:16:32 -04008023 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008024 {
Geoff Langbfdea662014-07-23 14:16:32 -04008025 return gl::error(GL_INVALID_VALUE);
8026 }
8027
8028 if (context->getState().getDrawFramebuffer()->id() == 0)
8029 {
8030 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008031 {
Geoff Langbfdea662014-07-23 14:16:32 -04008032 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008033 }
8034
Geoff Langbfdea662014-07-23 14:16:32 -04008035 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
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.com2fa73c52013-04-13 03:37:20 +00008038 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008039 }
Geoff Langbfdea662014-07-23 14:16:32 -04008040 else
8041 {
8042 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8043 {
8044 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8045 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8046 {
8047 return gl::error(GL_INVALID_OPERATION);
8048 }
8049 }
8050 }
8051
8052 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8053
8054 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8055 {
8056 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8057 }
8058
8059 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8060 {
8061 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8062 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008063 }
8064}
8065
Shannon Woodsb3801742014-03-27 14:59:19 -04008066void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8067{
8068 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8069
Geoff Langbfdea662014-07-23 14:16:32 -04008070 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008071
Geoff Langbfdea662014-07-23 14:16:32 -04008072 if (context)
8073 {
8074 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008075 {
Geoff Langbfdea662014-07-23 14:16:32 -04008076 return gl::error(GL_INVALID_ENUM);
Shannon Woodsb3801742014-03-27 14:59:19 -04008077 }
Geoff Langbfdea662014-07-23 14:16:32 -04008078
8079 if (pname != GL_BUFFER_MAP_POINTER)
8080 {
8081 return gl::error(GL_INVALID_ENUM);
8082 }
8083
8084 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8085
8086 if (!buffer || !buffer->isMapped())
8087 {
8088 *params = NULL;
8089 }
8090 else
8091 {
8092 *params = buffer->getMapPointer();
8093 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008094 }
8095}
8096
8097void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8098{
8099 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8100
Geoff Langbfdea662014-07-23 14:16:32 -04008101 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008102
Geoff Langbfdea662014-07-23 14:16:32 -04008103 if (context)
8104 {
8105 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008106 {
Geoff Langbfdea662014-07-23 14:16:32 -04008107 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woodsb3801742014-03-27 14:59:19 -04008108 }
Geoff Langbfdea662014-07-23 14:16:32 -04008109
8110 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8111
8112 if (buffer == NULL)
8113 {
8114 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8115 }
8116
8117 if (access != GL_WRITE_ONLY_OES)
8118 {
8119 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
8120 }
8121
8122 if (buffer->isMapped())
8123 {
8124 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8125 }
8126
8127 return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
Shannon Woodsb3801742014-03-27 14:59:19 -04008128 }
8129
8130 return NULL;
8131}
8132
8133GLboolean __stdcall glUnmapBufferOES(GLenum target)
8134{
8135 EVENT("(GLenum target = 0x%X)", target);
8136
Geoff Langbfdea662014-07-23 14:16:32 -04008137 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008138
Geoff Langbfdea662014-07-23 14:16:32 -04008139 if (context)
8140 {
8141 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008142 {
Geoff Langbfdea662014-07-23 14:16:32 -04008143 return gl::error(GL_INVALID_ENUM, GL_FALSE);
Shannon Woodsb3801742014-03-27 14:59:19 -04008144 }
Geoff Langbfdea662014-07-23 14:16:32 -04008145
8146 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8147
8148 if (buffer == NULL || !buffer->isMapped())
8149 {
8150 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8151 }
8152
8153 // TODO: detect if we had corruption. if so, throw an error and return false.
8154
8155 buffer->unmap();
8156
8157 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008158 }
8159
8160 return GL_FALSE;
8161}
8162
Shannon Woods916e7692014-03-27 16:58:22 -04008163void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8164{
8165 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8166 target, offset, length, access);
8167
Geoff Langbfdea662014-07-23 14:16:32 -04008168 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008169
Geoff Langbfdea662014-07-23 14:16:32 -04008170 if (context)
8171 {
8172 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008173 {
Geoff Langbfdea662014-07-23 14:16:32 -04008174 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woods916e7692014-03-27 16:58:22 -04008175 }
Geoff Langbfdea662014-07-23 14:16:32 -04008176
8177 if (offset < 0 || length < 0)
8178 {
8179 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8180 }
8181
8182 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8183
8184 if (buffer == NULL)
8185 {
8186 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8187 }
8188
8189 // Check for buffer overflow
8190 size_t offsetSize = static_cast<size_t>(offset);
8191 size_t lengthSize = static_cast<size_t>(length);
8192
8193 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8194 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8195 {
8196 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8197 }
8198
8199 // Check for invalid bits in the mask
8200 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8201 GL_MAP_WRITE_BIT |
8202 GL_MAP_INVALIDATE_RANGE_BIT |
8203 GL_MAP_INVALIDATE_BUFFER_BIT |
8204 GL_MAP_FLUSH_EXPLICIT_BIT |
8205 GL_MAP_UNSYNCHRONIZED_BIT;
8206
8207 if (access & ~(allAccessBits))
8208 {
8209 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8210 }
8211
8212 if (length == 0 || buffer->isMapped())
8213 {
8214 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8215 }
8216
8217 // Check for invalid bit combinations
8218 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8219 {
8220 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8221 }
8222
8223 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8224 GL_MAP_INVALIDATE_BUFFER_BIT |
8225 GL_MAP_UNSYNCHRONIZED_BIT;
8226
8227 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8228 {
8229 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8230 }
8231
8232 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8233 {
8234 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8235 }
8236
8237 return buffer->mapRange(offset, length, access);
Shannon Woods916e7692014-03-27 16:58:22 -04008238 }
8239
8240 return NULL;
8241}
8242
8243void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8244{
8245 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8246
Geoff Langbfdea662014-07-23 14:16:32 -04008247 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008248
Geoff Langbfdea662014-07-23 14:16:32 -04008249 if (context)
8250 {
8251 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008252 {
Geoff Langbfdea662014-07-23 14:16:32 -04008253 return gl::error(GL_INVALID_VALUE);
Shannon Woods916e7692014-03-27 16:58:22 -04008254 }
Geoff Langbfdea662014-07-23 14:16:32 -04008255
8256 if (!gl::ValidBufferTarget(context, target))
8257 {
8258 return gl::error(GL_INVALID_ENUM);
8259 }
8260
8261 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8262
8263 if (buffer == NULL)
8264 {
8265 return gl::error(GL_INVALID_OPERATION);
8266 }
8267
8268 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8269 {
8270 return gl::error(GL_INVALID_OPERATION);
8271 }
8272
8273 // Check for buffer overflow
8274 size_t offsetSize = static_cast<size_t>(offset);
8275 size_t lengthSize = static_cast<size_t>(length);
8276
8277 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8278 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8279 {
8280 return gl::error(GL_INVALID_VALUE);
8281 }
8282
8283 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008284 }
8285}
8286
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008287__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8288{
8289 struct Extension
8290 {
8291 const char *name;
8292 __eglMustCastToProperFunctionPointerType address;
8293 };
8294
8295 static const Extension glExtensions[] =
8296 {
8297 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008298 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008299 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008300 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8301 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8302 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8303 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8304 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8305 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8306 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008307 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008308 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008309 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8310 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8311 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8312 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008313 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8314 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8315 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8316 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8317 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8318 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8319 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008320 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008321 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8322 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8323 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008324 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008325 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8326 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8327 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008328 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8329 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8330 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008331
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008332 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008333 {
8334 if (strcmp(procname, glExtensions[ext].name) == 0)
8335 {
8336 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8337 }
8338 }
8339
8340 return NULL;
8341}
8342
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008343// Non-public functions used by EGL
8344
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008345bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008346{
8347 EVENT("(egl::Surface* surface = 0x%0.8p)",
8348 surface);
8349
Geoff Langbfdea662014-07-23 14:16:32 -04008350 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008351
Geoff Langbfdea662014-07-23 14:16:32 -04008352 if (context)
8353 {
8354 gl::Texture2D *textureObject = context->getTexture2D();
8355 ASSERT(textureObject != NULL);
8356
8357 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008358 {
Geoff Langbfdea662014-07-23 14:16:32 -04008359 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008360 }
Geoff Langbfdea662014-07-23 14:16:32 -04008361
8362 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008363 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008364
8365 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008366}
8367
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008368}