blob: 345d8209a3ab95f438d2bfe41f2fd88b131e2779 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
Geoff Lang48dcae72014-02-05 16:28:24 -05003// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040024#include "libGLESv2/VertexArray.h"
Brandon Jones5bf98292014-06-06 17:19:38 -070025#include "libGLESv2/VertexAttribute.h"
Geoff Langc8058452014-02-03 12:04:11 -050026#include "libGLESv2/TransformFeedback.h"
Jamie Madille261b442014-06-25 12:42:21 -040027#include "libGLESv2/FramebufferAttachment.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000028
Geoff Lange8ebe7f2013-08-05 15:03:13 -040029#include "libGLESv2/validationES.h"
30#include "libGLESv2/validationES2.h"
31#include "libGLESv2/validationES3.h"
Jamie Madill55856b12014-01-02 13:59:50 -050032#include "libGLESv2/queryconversions.h"
Jamie Madill478fdb22013-07-19 16:36:59 -040033
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034extern "C"
35{
36
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000037// OpenGL ES 2.0 functions
38
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039void __stdcall glActiveTexture(GLenum texture)
40{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000041 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000042
Geoff Langbfdea662014-07-23 14:16:32 -040043 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000044
Geoff Langbfdea662014-07-23 14:16:32 -040045 if (context)
46 {
47 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000048 {
Geoff Langbfdea662014-07-23 14:16:32 -040049 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000050 }
Geoff Langbfdea662014-07-23 14:16:32 -040051
52 context->getState().setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000053 }
54}
55
56void __stdcall glAttachShader(GLuint program, GLuint shader)
57{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000058 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000059
Geoff Langbfdea662014-07-23 14:16:32 -040060 gl::Context *context = gl::getNonLostContext();
61
62 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000063 {
Geoff Langbfdea662014-07-23 14:16:32 -040064 gl::Program *programObject = context->getProgram(program);
65 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066
Geoff Langbfdea662014-07-23 14:16:32 -040067 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000068 {
Geoff Langbfdea662014-07-23 14:16:32 -040069 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000071 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072 }
Geoff Langbfdea662014-07-23 14:16:32 -040073 else
74 {
75 return gl::error(GL_INVALID_VALUE);
76 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000077 }
Geoff Langbfdea662014-07-23 14:16:32 -040078
79 if (!shaderObject)
80 {
81 if (context->getProgram(shader))
82 {
83 return gl::error(GL_INVALID_OPERATION);
84 }
85 else
86 {
87 return gl::error(GL_INVALID_VALUE);
88 }
89 }
90
91 if (!programObject->attachShader(shaderObject))
92 {
93 return gl::error(GL_INVALID_OPERATION);
94 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095 }
96}
97
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000098void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
99{
100 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
101
Geoff Langbfdea662014-07-23 14:16:32 -0400102 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000103
Geoff Langbfdea662014-07-23 14:16:32 -0400104 if (context)
105 {
106 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000107 {
Geoff Langbfdea662014-07-23 14:16:32 -0400108 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000109 }
Geoff Langbfdea662014-07-23 14:16:32 -0400110
111 context->beginQuery(target, id);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000112 }
113}
114
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000115void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000116{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000117 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000118
Geoff Langbfdea662014-07-23 14:16:32 -0400119 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120 {
Geoff Langbfdea662014-07-23 14:16:32 -0400121 return gl::error(GL_INVALID_VALUE);
122 }
123
124 gl::Context *context = gl::getNonLostContext();
125
126 if (context)
127 {
128 gl::Program *programObject = context->getProgram(program);
129
130 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000131 {
Geoff Langbfdea662014-07-23 14:16:32 -0400132 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000134 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135 }
Geoff Langbfdea662014-07-23 14:16:32 -0400136 else
137 {
138 return gl::error(GL_INVALID_VALUE);
139 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000140 }
Geoff Langbfdea662014-07-23 14:16:32 -0400141
142 if (strncmp(name, "gl_", 3) == 0)
143 {
144 return gl::error(GL_INVALID_OPERATION);
145 }
146
147 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000148 }
149}
150
151void __stdcall glBindBuffer(GLenum target, GLuint buffer)
152{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000153 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000154
Geoff Langbfdea662014-07-23 14:16:32 -0400155 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000156
Geoff Langbfdea662014-07-23 14:16:32 -0400157 if (context)
158 {
159 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000160 {
Geoff Langbfdea662014-07-23 14:16:32 -0400161 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000162 }
Geoff Langbfdea662014-07-23 14:16:32 -0400163
164 switch (target)
165 {
166 case GL_ARRAY_BUFFER:
167 context->bindArrayBuffer(buffer);
168 return;
169 case GL_ELEMENT_ARRAY_BUFFER:
170 context->bindElementArrayBuffer(buffer);
171 return;
172 case GL_COPY_READ_BUFFER:
173 context->bindCopyReadBuffer(buffer);
174 return;
175 case GL_COPY_WRITE_BUFFER:
176 context->bindCopyWriteBuffer(buffer);
177 return;
178 case GL_PIXEL_PACK_BUFFER:
179 context->bindPixelPackBuffer(buffer);
180 return;
181 case GL_PIXEL_UNPACK_BUFFER:
182 context->bindPixelUnpackBuffer(buffer);
183 return;
184 case GL_UNIFORM_BUFFER:
185 context->bindGenericUniformBuffer(buffer);
186 return;
187 case GL_TRANSFORM_FEEDBACK_BUFFER:
188 context->bindGenericTransformFeedbackBuffer(buffer);
189 return;
190 default:
191 return gl::error(GL_INVALID_ENUM);
192 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000193 }
194}
195
196void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
197{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000198 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000199
Geoff Langbfdea662014-07-23 14:16:32 -0400200 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000201 {
Geoff Langbfdea662014-07-23 14:16:32 -0400202 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000203 }
Geoff Langbfdea662014-07-23 14:16:32 -0400204
205 gl::Context *context = gl::getNonLostContext();
206
207 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000208 {
Geoff Langbfdea662014-07-23 14:16:32 -0400209 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
210 {
211 context->bindReadFramebuffer(framebuffer);
212 }
213
214 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
215 {
216 context->bindDrawFramebuffer(framebuffer);
217 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000218 }
219}
220
221void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
222{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000223 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000224
Geoff Langbfdea662014-07-23 14:16:32 -0400225 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000226 {
Geoff Langbfdea662014-07-23 14:16:32 -0400227 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000228 }
Geoff Langbfdea662014-07-23 14:16:32 -0400229
230 gl::Context *context = gl::getNonLostContext();
231
232 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000233 {
Geoff Langbfdea662014-07-23 14:16:32 -0400234 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000235 }
236}
237
238void __stdcall glBindTexture(GLenum target, GLuint texture)
239{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000240 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000241
Geoff Langbfdea662014-07-23 14:16:32 -0400242 gl::Context *context = gl::getNonLostContext();
243
244 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000245 {
Geoff Langbfdea662014-07-23 14:16:32 -0400246 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000247
Geoff Langbfdea662014-07-23 14:16:32 -0400248 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000249 {
Geoff Langbfdea662014-07-23 14:16:32 -0400250 return gl::error(GL_INVALID_OPERATION);
251 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000252
Geoff Langbfdea662014-07-23 14:16:32 -0400253 switch (target)
254 {
255 case GL_TEXTURE_2D:
256 context->bindTexture2D(texture);
257 return;
258 case GL_TEXTURE_CUBE_MAP:
259 context->bindTextureCubeMap(texture);
260 return;
261 case GL_TEXTURE_3D:
262 if (context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000263 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000264 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000265 }
Geoff Langbfdea662014-07-23 14:16:32 -0400266 context->bindTexture3D(texture);
267 return;
268 case GL_TEXTURE_2D_ARRAY:
269 if (context->getClientVersion() < 3)
270 {
271 return gl::error(GL_INVALID_ENUM);
272 }
273 context->bindTexture2DArray(texture);
274 return;
275 default:
276 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000277 }
278 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000279}
280
281void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
282{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000283 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000284 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000285
Geoff Langbfdea662014-07-23 14:16:32 -0400286 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287
Geoff Langbfdea662014-07-23 14:16:32 -0400288 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000289 {
Geoff Langbfdea662014-07-23 14:16:32 -0400290 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000291 }
292}
293
294void __stdcall glBlendEquation(GLenum mode)
295{
296 glBlendEquationSeparate(mode, mode);
297}
298
299void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
300{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000301 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000302
Geoff Langbfdea662014-07-23 14:16:32 -0400303 gl::Context *context = gl::getNonLostContext();
304
305 switch (modeRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000306 {
Geoff Langbfdea662014-07-23 14:16:32 -0400307 case GL_FUNC_ADD:
308 case GL_FUNC_SUBTRACT:
309 case GL_FUNC_REVERSE_SUBTRACT:
310 case GL_MIN:
311 case GL_MAX:
312 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000313
Geoff Langbfdea662014-07-23 14:16:32 -0400314 default:
315 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000316 }
Geoff Langbfdea662014-07-23 14:16:32 -0400317
318 switch (modeAlpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000319 {
Geoff Langbfdea662014-07-23 14:16:32 -0400320 case GL_FUNC_ADD:
321 case GL_FUNC_SUBTRACT:
322 case GL_FUNC_REVERSE_SUBTRACT:
323 case GL_MIN:
324 case GL_MAX:
325 break;
326
327 default:
328 return gl::error(GL_INVALID_ENUM);
329 }
330
331 if (context)
332 {
333 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000334 }
335}
336
337void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
338{
339 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
340}
341
342void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000344 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000345 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000346
Geoff Langbfdea662014-07-23 14:16:32 -0400347 gl::Context *context = gl::getNonLostContext();
348
349 switch (srcRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000350 {
Geoff Langbfdea662014-07-23 14:16:32 -0400351 case GL_ZERO:
352 case GL_ONE:
353 case GL_SRC_COLOR:
354 case GL_ONE_MINUS_SRC_COLOR:
355 case GL_DST_COLOR:
356 case GL_ONE_MINUS_DST_COLOR:
357 case GL_SRC_ALPHA:
358 case GL_ONE_MINUS_SRC_ALPHA:
359 case GL_DST_ALPHA:
360 case GL_ONE_MINUS_DST_ALPHA:
361 case GL_CONSTANT_COLOR:
362 case GL_ONE_MINUS_CONSTANT_COLOR:
363 case GL_CONSTANT_ALPHA:
364 case GL_ONE_MINUS_CONSTANT_ALPHA:
365 case GL_SRC_ALPHA_SATURATE:
366 break;
367 default:
368 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000369 }
Geoff Langbfdea662014-07-23 14:16:32 -0400370
371 switch (dstRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000372 {
Geoff Langbfdea662014-07-23 14:16:32 -0400373 case GL_ZERO:
374 case GL_ONE:
375 case GL_SRC_COLOR:
376 case GL_ONE_MINUS_SRC_COLOR:
377 case GL_DST_COLOR:
378 case GL_ONE_MINUS_DST_COLOR:
379 case GL_SRC_ALPHA:
380 case GL_ONE_MINUS_SRC_ALPHA:
381 case GL_DST_ALPHA:
382 case GL_ONE_MINUS_DST_ALPHA:
383 case GL_CONSTANT_COLOR:
384 case GL_ONE_MINUS_CONSTANT_COLOR:
385 case GL_CONSTANT_ALPHA:
386 case GL_ONE_MINUS_CONSTANT_ALPHA:
387 break;
388
389 case GL_SRC_ALPHA_SATURATE:
390 if (!context || context->getClientVersion() < 3)
391 {
392 return gl::error(GL_INVALID_ENUM);
393 }
394 break;
395
396 default:
397 return gl::error(GL_INVALID_ENUM);
398 }
399
400 switch (srcAlpha)
401 {
402 case GL_ZERO:
403 case GL_ONE:
404 case GL_SRC_COLOR:
405 case GL_ONE_MINUS_SRC_COLOR:
406 case GL_DST_COLOR:
407 case GL_ONE_MINUS_DST_COLOR:
408 case GL_SRC_ALPHA:
409 case GL_ONE_MINUS_SRC_ALPHA:
410 case GL_DST_ALPHA:
411 case GL_ONE_MINUS_DST_ALPHA:
412 case GL_CONSTANT_COLOR:
413 case GL_ONE_MINUS_CONSTANT_COLOR:
414 case GL_CONSTANT_ALPHA:
415 case GL_ONE_MINUS_CONSTANT_ALPHA:
416 case GL_SRC_ALPHA_SATURATE:
417 break;
418 default:
419 return gl::error(GL_INVALID_ENUM);
420 }
421
422 switch (dstAlpha)
423 {
424 case GL_ZERO:
425 case GL_ONE:
426 case GL_SRC_COLOR:
427 case GL_ONE_MINUS_SRC_COLOR:
428 case GL_DST_COLOR:
429 case GL_ONE_MINUS_DST_COLOR:
430 case GL_SRC_ALPHA:
431 case GL_ONE_MINUS_SRC_ALPHA:
432 case GL_DST_ALPHA:
433 case GL_ONE_MINUS_DST_ALPHA:
434 case GL_CONSTANT_COLOR:
435 case GL_ONE_MINUS_CONSTANT_COLOR:
436 case GL_CONSTANT_ALPHA:
437 case GL_ONE_MINUS_CONSTANT_ALPHA:
438 break;
439
440 case GL_SRC_ALPHA_SATURATE:
441 if (!context || context->getClientVersion() < 3)
442 {
443 return gl::error(GL_INVALID_ENUM);
444 }
445 break;
446
447 default:
448 return gl::error(GL_INVALID_ENUM);
449 }
450
451 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
452 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
453
454 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
455 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
456
457 if (constantColorUsed && constantAlphaUsed)
458 {
459 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
460 return gl::error(GL_INVALID_OPERATION);
461 }
462
463 if (context)
464 {
465 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000466 }
467}
468
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000469void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000470{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000471 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000472 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000473
Geoff Langbfdea662014-07-23 14:16:32 -0400474 if (size < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000475 {
Geoff Langbfdea662014-07-23 14:16:32 -0400476 return gl::error(GL_INVALID_VALUE);
477 }
478
479 gl::Context *context = gl::getNonLostContext();
480
481 switch (usage)
482 {
483 case GL_STREAM_DRAW:
484 case GL_STATIC_DRAW:
485 case GL_DYNAMIC_DRAW:
486 break;
487
488 case GL_STREAM_READ:
489 case GL_STREAM_COPY:
490 case GL_STATIC_READ:
491 case GL_STATIC_COPY:
492 case GL_DYNAMIC_READ:
493 case GL_DYNAMIC_COPY:
494 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000495 {
Geoff Langbfdea662014-07-23 14:16:32 -0400496 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000497 }
Geoff Langbfdea662014-07-23 14:16:32 -0400498 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000499
Geoff Langbfdea662014-07-23 14:16:32 -0400500 default:
501 return gl::error(GL_INVALID_ENUM);
502 }
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +0000503
Geoff Langbfdea662014-07-23 14:16:32 -0400504 if (context)
505 {
506 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000508 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000509 }
510
Geoff Langbfdea662014-07-23 14:16:32 -0400511 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
512
513 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000514 {
Geoff Langbfdea662014-07-23 14:16:32 -0400515 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000516 }
Geoff Langbfdea662014-07-23 14:16:32 -0400517
518 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000519 }
520}
521
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000522void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000524 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000525 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000526
Geoff Langbfdea662014-07-23 14:16:32 -0400527 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000528 {
Geoff Langbfdea662014-07-23 14:16:32 -0400529 return gl::error(GL_INVALID_VALUE);
530 }
531
532 if (data == NULL)
533 {
534 return;
535 }
536
537 gl::Context *context = gl::getNonLostContext();
538
539 if (context)
540 {
541 if (!gl::ValidBufferTarget(context, target))
542 {
543 return gl::error(GL_INVALID_ENUM);
544 }
545
546 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
547
548 if (!buffer)
549 {
550 return gl::error(GL_INVALID_OPERATION);
551 }
552
553 if (buffer->isMapped())
554 {
555 return gl::error(GL_INVALID_OPERATION);
556 }
557
558 // Check for possible overflow of size + offset
559 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
560 {
561 return gl::error(GL_OUT_OF_MEMORY);
562 }
563
564 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000566 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000567 }
568
Geoff Langbfdea662014-07-23 14:16:32 -0400569 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000570 }
571}
572
573GLenum __stdcall glCheckFramebufferStatus(GLenum target)
574{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000575 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000576
Geoff Langbfdea662014-07-23 14:16:32 -0400577 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000578 {
Geoff Langbfdea662014-07-23 14:16:32 -0400579 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000580 }
Geoff Langbfdea662014-07-23 14:16:32 -0400581
582 gl::Context *context = gl::getNonLostContext();
583
584 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000585 {
Geoff Langbfdea662014-07-23 14:16:32 -0400586 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
587 ASSERT(framebuffer);
588 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000589 }
590
591 return 0;
592}
593
594void __stdcall glClear(GLbitfield mask)
595{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000596 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000597
Geoff Langbfdea662014-07-23 14:16:32 -0400598 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000599
Geoff Langbfdea662014-07-23 14:16:32 -0400600 if (context)
601 {
602 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
603
604 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000605 {
Geoff Langbfdea662014-07-23 14:16:32 -0400606 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000607 }
Geoff Langbfdea662014-07-23 14:16:32 -0400608
609 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
610 {
611 return gl::error(GL_INVALID_VALUE);
612 }
613
614 context->clear(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000615 }
616}
617
618void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
619{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000620 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000621 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000622
Geoff Langbfdea662014-07-23 14:16:32 -0400623 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000624
Geoff Langbfdea662014-07-23 14:16:32 -0400625 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000626 {
Geoff Langbfdea662014-07-23 14:16:32 -0400627 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000628 }
629}
630
631void __stdcall glClearDepthf(GLclampf depth)
632{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000633 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000634
Geoff Langbfdea662014-07-23 14:16:32 -0400635 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000636
Geoff Langbfdea662014-07-23 14:16:32 -0400637 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000638 {
Geoff Langbfdea662014-07-23 14:16:32 -0400639 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000640 }
641}
642
643void __stdcall glClearStencil(GLint s)
644{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000645 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000646
Geoff Langbfdea662014-07-23 14:16:32 -0400647 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000648
Geoff Langbfdea662014-07-23 14:16:32 -0400649 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000650 {
Geoff Langbfdea662014-07-23 14:16:32 -0400651 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000652 }
653}
654
655void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
656{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000657 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000658 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000659
Geoff Langbfdea662014-07-23 14:16:32 -0400660 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000661
Geoff Langbfdea662014-07-23 14:16:32 -0400662 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000663 {
Geoff Langbfdea662014-07-23 14:16:32 -0400664 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000665 }
666}
667
668void __stdcall glCompileShader(GLuint shader)
669{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000670 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000671
Geoff Langbfdea662014-07-23 14:16:32 -0400672 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000673
Geoff Langbfdea662014-07-23 14:16:32 -0400674 if (context)
675 {
676 gl::Shader *shaderObject = context->getShader(shader);
677
678 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000679 {
Geoff Langbfdea662014-07-23 14:16:32 -0400680 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000681 {
Geoff Langbfdea662014-07-23 14:16:32 -0400682 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000683 }
Geoff Langbfdea662014-07-23 14:16:32 -0400684 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000686 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000687 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000688 }
Geoff Langbfdea662014-07-23 14:16:32 -0400689
690 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000691 }
Geoff Langbfdea662014-07-23 14:16:32 -0400692}
693
694void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
695 GLint border, GLsizei imageSize, const GLvoid* data)
696{
697 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
698 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
699 target, level, internalformat, width, height, border, imageSize, data);
700
701 gl::Context *context = gl::getNonLostContext();
702
703 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000704 {
Geoff Langbfdea662014-07-23 14:16:32 -0400705 if (context->getClientVersion() < 3 &&
706 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
707 0, 0, width, height, border, GL_NONE, GL_NONE, data))
708 {
709 return;
710 }
711
712 if (context->getClientVersion() >= 3 &&
713 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
714 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
715 {
716 return;
717 }
718
Geoff Lang5d601382014-07-22 15:14:06 -0400719 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
720 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400721 {
722 return gl::error(GL_INVALID_VALUE);
723 }
724
725 switch (target)
726 {
727 case GL_TEXTURE_2D:
728 {
729 gl::Texture2D *texture = context->getTexture2D();
730 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
731 }
732 break;
733
734 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
735 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
736 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
737 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
738 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
739 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
740 {
741 gl::TextureCubeMap *texture = context->getTextureCubeMap();
742 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
743 }
744 break;
745
746 default:
747 return gl::error(GL_INVALID_ENUM);
748 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000749 }
750}
751
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000752void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
753 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000754{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000755 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000756 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000757 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000758 target, level, xoffset, yoffset, width, height, format, imageSize, data);
759
Geoff Langbfdea662014-07-23 14:16:32 -0400760 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +0000761
Geoff Langbfdea662014-07-23 14:16:32 -0400762 if (context)
763 {
764 if (context->getClientVersion() < 3 &&
765 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
766 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000767 {
Geoff Langbfdea662014-07-23 14:16:32 -0400768 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000769 }
Geoff Langbfdea662014-07-23 14:16:32 -0400770
771 if (context->getClientVersion() >= 3 &&
772 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
773 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
774 {
775 return;
776 }
777
Geoff Lang5d601382014-07-22 15:14:06 -0400778 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
779 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400780 {
781 return gl::error(GL_INVALID_VALUE);
782 }
783
784 switch (target)
785 {
786 case GL_TEXTURE_2D:
787 {
788 gl::Texture2D *texture = context->getTexture2D();
789 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
790 }
791 break;
792
793 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
794 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
795 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
797 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
798 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
799 {
800 gl::TextureCubeMap *texture = context->getTextureCubeMap();
801 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
802 }
803 break;
804
805 default:
806 return gl::error(GL_INVALID_ENUM);
807 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000808 }
809}
810
811void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
812{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000813 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000814 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000815 target, level, internalformat, x, y, width, height, border);
816
Geoff Langbfdea662014-07-23 14:16:32 -0400817 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000818
Geoff Langbfdea662014-07-23 14:16:32 -0400819 if (context)
820 {
821 if (context->getClientVersion() < 3 &&
822 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
823 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000824 {
Geoff Langbfdea662014-07-23 14:16:32 -0400825 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000826 }
Geoff Langbfdea662014-07-23 14:16:32 -0400827
828 if (context->getClientVersion() >= 3 &&
829 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
830 0, 0, 0, x, y, width, height, border))
831 {
832 return;
833 }
834
835 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
836
837 switch (target)
838 {
839 case GL_TEXTURE_2D:
840 {
841 gl::Texture2D *texture = context->getTexture2D();
842 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
843 }
844 break;
845
846 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
847 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
848 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
852 {
853 gl::TextureCubeMap *texture = context->getTextureCubeMap();
854 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
855 }
856 break;
857
858 default:
859 return gl::error(GL_INVALID_ENUM);
860 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000861 }
862}
863
864void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
865{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000866 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000867 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000868 target, level, xoffset, yoffset, x, y, width, height);
869
Geoff Langbfdea662014-07-23 14:16:32 -0400870 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000871
Geoff Langbfdea662014-07-23 14:16:32 -0400872 if (context)
873 {
874 if (context->getClientVersion() < 3 &&
875 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
876 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000877 {
Geoff Langbfdea662014-07-23 14:16:32 -0400878 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000879 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000880
Geoff Langbfdea662014-07-23 14:16:32 -0400881 if (context->getClientVersion() >= 3 &&
882 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
883 xoffset, yoffset, 0, x, y, width, height, 0))
884 {
885 return;
886 }
887
888 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
889
890 switch (target)
891 {
892 case GL_TEXTURE_2D:
893 {
894 gl::Texture2D *texture = context->getTexture2D();
895 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
896 }
897 break;
898
899 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
900 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
901 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
902 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
903 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
904 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
905 {
906 gl::TextureCubeMap *texture = context->getTextureCubeMap();
907 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
908 }
909 break;
910
911 default:
912 return gl::error(GL_INVALID_ENUM);
913 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000914 }
915}
916
917GLuint __stdcall glCreateProgram(void)
918{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000919 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000920
Geoff Langbfdea662014-07-23 14:16:32 -0400921 gl::Context *context = gl::getNonLostContext();
922 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000923 {
Geoff Langbfdea662014-07-23 14:16:32 -0400924 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000925 }
926
927 return 0;
928}
929
930GLuint __stdcall glCreateShader(GLenum type)
931{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000932 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000933
Geoff Langbfdea662014-07-23 14:16:32 -0400934 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000935
Geoff Langbfdea662014-07-23 14:16:32 -0400936 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000937 {
Geoff Langbfdea662014-07-23 14:16:32 -0400938 switch (type)
939 {
940 case GL_FRAGMENT_SHADER:
941 case GL_VERTEX_SHADER:
942 return context->createShader(type);
943 default:
944 return gl::error(GL_INVALID_ENUM, 0);
945 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000946 }
947
948 return 0;
949}
950
951void __stdcall glCullFace(GLenum mode)
952{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000953 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000954
Geoff Langbfdea662014-07-23 14:16:32 -0400955 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000956 {
Geoff Langbfdea662014-07-23 14:16:32 -0400957 case GL_FRONT:
958 case GL_BACK:
959 case GL_FRONT_AND_BACK:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000960 {
Geoff Langbfdea662014-07-23 14:16:32 -0400961 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000962
Geoff Langbfdea662014-07-23 14:16:32 -0400963 if (context)
964 {
965 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000966 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000967 }
Geoff Langbfdea662014-07-23 14:16:32 -0400968 break;
969 default:
970 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000971 }
972}
973
974void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000976 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000977
Geoff Langbfdea662014-07-23 14:16:32 -0400978 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000979 {
Geoff Langbfdea662014-07-23 14:16:32 -0400980 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000981 }
Geoff Langbfdea662014-07-23 14:16:32 -0400982
983 gl::Context *context = gl::getNonLostContext();
984
985 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000986 {
Geoff Langbfdea662014-07-23 14:16:32 -0400987 for (int i = 0; i < n; i++)
988 {
989 context->deleteBuffer(buffers[i]);
990 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000991 }
992}
993
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000994void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
995{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000996 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000997
Geoff Langbfdea662014-07-23 14:16:32 -0400998 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000999 {
Geoff Langbfdea662014-07-23 14:16:32 -04001000 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001001 }
Geoff Langbfdea662014-07-23 14:16:32 -04001002
1003 gl::Context *context = gl::getNonLostContext();
1004
1005 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001006 {
Geoff Langbfdea662014-07-23 14:16:32 -04001007 for (int i = 0; i < n; i++)
1008 {
1009 context->deleteFenceNV(fences[i]);
1010 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001011 }
1012}
1013
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001014void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1015{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001016 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001017
Geoff Langbfdea662014-07-23 14:16:32 -04001018 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001019 {
Geoff Langbfdea662014-07-23 14:16:32 -04001020 return gl::error(GL_INVALID_VALUE);
1021 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001022
Geoff Langbfdea662014-07-23 14:16:32 -04001023 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001024
Geoff Langbfdea662014-07-23 14:16:32 -04001025 if (context)
1026 {
1027 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001028 {
Geoff Langbfdea662014-07-23 14:16:32 -04001029 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001030 {
Geoff Langbfdea662014-07-23 14:16:32 -04001031 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001032 }
1033 }
1034 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001035}
1036
1037void __stdcall glDeleteProgram(GLuint program)
1038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001039 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001040
Geoff Langbfdea662014-07-23 14:16:32 -04001041 if (program == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001042 {
Geoff Langbfdea662014-07-23 14:16:32 -04001043 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001044 }
Geoff Langbfdea662014-07-23 14:16:32 -04001045
1046 gl::Context *context = gl::getNonLostContext();
1047
1048 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001049 {
Geoff Langbfdea662014-07-23 14:16:32 -04001050 if (!context->getProgram(program))
1051 {
1052 if(context->getShader(program))
1053 {
1054 return gl::error(GL_INVALID_OPERATION);
1055 }
1056 else
1057 {
1058 return gl::error(GL_INVALID_VALUE);
1059 }
1060 }
1061
1062 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001063 }
1064}
1065
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001066void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1067{
1068 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1069
Geoff Langbfdea662014-07-23 14:16:32 -04001070 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001071 {
Geoff Langbfdea662014-07-23 14:16:32 -04001072 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001073 }
Geoff Langbfdea662014-07-23 14:16:32 -04001074
1075 gl::Context *context = gl::getNonLostContext();
1076
1077 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001078 {
Geoff Langbfdea662014-07-23 14:16:32 -04001079 for (int i = 0; i < n; i++)
1080 {
1081 context->deleteQuery(ids[i]);
1082 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001083 }
1084}
1085
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001086void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1087{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001088 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001089
Geoff Langbfdea662014-07-23 14:16:32 -04001090 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001091 {
Geoff Langbfdea662014-07-23 14:16:32 -04001092 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001093 }
Geoff Langbfdea662014-07-23 14:16:32 -04001094
1095 gl::Context *context = gl::getNonLostContext();
1096
1097 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001098 {
Geoff Langbfdea662014-07-23 14:16:32 -04001099 for (int i = 0; i < n; i++)
1100 {
1101 context->deleteRenderbuffer(renderbuffers[i]);
1102 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001103 }
1104}
1105
1106void __stdcall glDeleteShader(GLuint shader)
1107{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001108 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001109
Geoff Langbfdea662014-07-23 14:16:32 -04001110 if (shader == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001111 {
Geoff Langbfdea662014-07-23 14:16:32 -04001112 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001113 }
Geoff Langbfdea662014-07-23 14:16:32 -04001114
1115 gl::Context *context = gl::getNonLostContext();
1116
1117 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001118 {
Geoff Langbfdea662014-07-23 14:16:32 -04001119 if (!context->getShader(shader))
1120 {
1121 if(context->getProgram(shader))
1122 {
1123 return gl::error(GL_INVALID_OPERATION);
1124 }
1125 else
1126 {
1127 return gl::error(GL_INVALID_VALUE);
1128 }
1129 }
1130
1131 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001132 }
1133}
1134
1135void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001137 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001138
Geoff Langbfdea662014-07-23 14:16:32 -04001139 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001140 {
Geoff Langbfdea662014-07-23 14:16:32 -04001141 return gl::error(GL_INVALID_VALUE);
1142 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001143
Geoff Langbfdea662014-07-23 14:16:32 -04001144 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001145
Geoff Langbfdea662014-07-23 14:16:32 -04001146 if (context)
1147 {
1148 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001149 {
Geoff Langbfdea662014-07-23 14:16:32 -04001150 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001151 {
Geoff Langbfdea662014-07-23 14:16:32 -04001152 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001153 }
1154 }
1155 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001156}
1157
1158void __stdcall glDepthFunc(GLenum func)
1159{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001160 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001161
Geoff Langbfdea662014-07-23 14:16:32 -04001162 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001163 {
Geoff Langbfdea662014-07-23 14:16:32 -04001164 case GL_NEVER:
1165 case GL_ALWAYS:
1166 case GL_LESS:
1167 case GL_LEQUAL:
1168 case GL_EQUAL:
1169 case GL_GREATER:
1170 case GL_GEQUAL:
1171 case GL_NOTEQUAL:
1172 break;
1173 default:
1174 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001175 }
Geoff Langbfdea662014-07-23 14:16:32 -04001176
1177 gl::Context *context = gl::getNonLostContext();
1178
1179 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001180 {
Geoff Langbfdea662014-07-23 14:16:32 -04001181 context->getState().setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001182 }
1183}
1184
1185void __stdcall glDepthMask(GLboolean flag)
1186{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001187 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001188
Geoff Langbfdea662014-07-23 14:16:32 -04001189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001190
Geoff Langbfdea662014-07-23 14:16:32 -04001191 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001192 {
Geoff Langbfdea662014-07-23 14:16:32 -04001193 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001194 }
1195}
1196
1197void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1198{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001199 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001200
Geoff Langbfdea662014-07-23 14:16:32 -04001201 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001202
Geoff Langbfdea662014-07-23 14:16:32 -04001203 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001204 {
Geoff Langbfdea662014-07-23 14:16:32 -04001205 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001206 }
1207}
1208
1209void __stdcall glDetachShader(GLuint program, GLuint shader)
1210{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001211 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001212
Geoff Langbfdea662014-07-23 14:16:32 -04001213 gl::Context *context = gl::getNonLostContext();
1214
1215 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001216 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001217
Geoff Langbfdea662014-07-23 14:16:32 -04001218 gl::Program *programObject = context->getProgram(program);
1219 gl::Shader *shaderObject = context->getShader(shader);
1220
1221 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001222 {
Geoff Langbfdea662014-07-23 14:16:32 -04001223 gl::Shader *shaderByProgramHandle;
1224 shaderByProgramHandle = context->getShader(program);
1225 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001226 {
Geoff Langbfdea662014-07-23 14:16:32 -04001227 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001228 }
Geoff Langbfdea662014-07-23 14:16:32 -04001229 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001231 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001232 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001233 }
Geoff Langbfdea662014-07-23 14:16:32 -04001234
1235 if (!shaderObject)
1236 {
1237 gl::Program *programByShaderHandle = context->getProgram(shader);
1238 if (!programByShaderHandle)
1239 {
1240 return gl::error(GL_INVALID_VALUE);
1241 }
1242 else
1243 {
1244 return gl::error(GL_INVALID_OPERATION);
1245 }
1246 }
1247
1248 if (!programObject->detachShader(shaderObject))
1249 {
1250 return gl::error(GL_INVALID_OPERATION);
1251 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001252 }
1253}
1254
1255void __stdcall glDisable(GLenum cap)
1256{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001257 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001258
Geoff Langbfdea662014-07-23 14:16:32 -04001259 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001260
Geoff Langbfdea662014-07-23 14:16:32 -04001261 if (context)
1262 {
1263 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001264 {
Geoff Langbfdea662014-07-23 14:16:32 -04001265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266 }
Geoff Langbfdea662014-07-23 14:16:32 -04001267
1268 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001269 }
1270}
1271
1272void __stdcall glDisableVertexAttribArray(GLuint index)
1273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001274 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001275
Geoff Langbfdea662014-07-23 14:16:32 -04001276 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277 {
Geoff Langbfdea662014-07-23 14:16:32 -04001278 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001279 }
Geoff Langbfdea662014-07-23 14:16:32 -04001280
1281 gl::Context *context = gl::getNonLostContext();
1282
1283 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001284 {
Geoff Langbfdea662014-07-23 14:16:32 -04001285 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001286 }
1287}
1288
1289void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001291 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001292
Geoff Langbfdea662014-07-23 14:16:32 -04001293 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001294
Geoff Langbfdea662014-07-23 14:16:32 -04001295 if (context)
1296 {
1297 if (!ValidateDrawArrays(context, mode, first, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001298 {
Geoff Langbfdea662014-07-23 14:16:32 -04001299 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001300 }
Geoff Langbfdea662014-07-23 14:16:32 -04001301
1302 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001303 }
1304}
1305
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001306void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1307{
1308 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1309
Geoff Langbfdea662014-07-23 14:16:32 -04001310 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001311
Geoff Langbfdea662014-07-23 14:16:32 -04001312 if (context)
1313 {
1314 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001315 {
Geoff Langbfdea662014-07-23 14:16:32 -04001316 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001317 }
Geoff Langbfdea662014-07-23 14:16:32 -04001318
1319 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001320 }
1321}
1322
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001323void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001325 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001326 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001327
Geoff Langbfdea662014-07-23 14:16:32 -04001328 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001329
Geoff Langbfdea662014-07-23 14:16:32 -04001330 if (context)
1331 {
1332 if (!ValidateDrawElements(context, mode, count, type, indices))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001333 {
Geoff Langbfdea662014-07-23 14:16:32 -04001334 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001335 }
Geoff Langbfdea662014-07-23 14:16:32 -04001336
1337 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001338 }
1339}
1340
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001341void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1342{
1343 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1344 mode, count, type, indices, primcount);
1345
Geoff Langbfdea662014-07-23 14:16:32 -04001346 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001347
Geoff Langbfdea662014-07-23 14:16:32 -04001348 if (context)
1349 {
1350 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001351 {
Geoff Langbfdea662014-07-23 14:16:32 -04001352 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001353 }
Geoff Langbfdea662014-07-23 14:16:32 -04001354
1355 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001356 }
1357}
1358
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001359void __stdcall glEnable(GLenum cap)
1360{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001361 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001362
Geoff Langbfdea662014-07-23 14:16:32 -04001363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001364
Geoff Langbfdea662014-07-23 14:16:32 -04001365 if (context)
1366 {
1367 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001368 {
Geoff Langbfdea662014-07-23 14:16:32 -04001369 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001370 }
Geoff Langbfdea662014-07-23 14:16:32 -04001371
1372 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001373 }
1374}
1375
1376void __stdcall glEnableVertexAttribArray(GLuint index)
1377{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001378 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001379
Geoff Langbfdea662014-07-23 14:16:32 -04001380 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001381 {
Geoff Langbfdea662014-07-23 14:16:32 -04001382 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001383 }
Geoff Langbfdea662014-07-23 14:16:32 -04001384
1385 gl::Context *context = gl::getNonLostContext();
1386
1387 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001388 {
Geoff Langbfdea662014-07-23 14:16:32 -04001389 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001390 }
1391}
1392
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001393void __stdcall glEndQueryEXT(GLenum target)
1394{
1395 EVENT("GLenum target = 0x%X)", target);
1396
Geoff Langbfdea662014-07-23 14:16:32 -04001397 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001398
Geoff Langbfdea662014-07-23 14:16:32 -04001399 if (context)
1400 {
1401 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001402 {
Geoff Langbfdea662014-07-23 14:16:32 -04001403 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001404 }
Geoff Langbfdea662014-07-23 14:16:32 -04001405
1406 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001407 }
1408}
1409
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001410void __stdcall glFinishFenceNV(GLuint fence)
1411{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001412 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001413
Geoff Langbfdea662014-07-23 14:16:32 -04001414 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001415
Geoff Langbfdea662014-07-23 14:16:32 -04001416 if (context)
1417 {
1418 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1419
1420 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001421 {
Geoff Langbfdea662014-07-23 14:16:32 -04001422 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001423 }
Geoff Langbfdea662014-07-23 14:16:32 -04001424
1425 if (fenceObject->isFence() != GL_TRUE)
1426 {
1427 return gl::error(GL_INVALID_OPERATION);
1428 }
1429
1430 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001431 }
1432}
1433
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001434void __stdcall glFinish(void)
1435{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001436 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001437
Geoff Langbfdea662014-07-23 14:16:32 -04001438 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001439
Geoff Langbfdea662014-07-23 14:16:32 -04001440 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001441 {
Geoff Langbfdea662014-07-23 14:16:32 -04001442 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001443 }
1444}
1445
1446void __stdcall glFlush(void)
1447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001448 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001449
Geoff Langbfdea662014-07-23 14:16:32 -04001450 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001451
Geoff Langbfdea662014-07-23 14:16:32 -04001452 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453 {
Geoff Langbfdea662014-07-23 14:16:32 -04001454 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001455 }
1456}
1457
1458void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001460 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001461 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001462
Geoff Langbfdea662014-07-23 14:16:32 -04001463 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001464 {
Geoff Langbfdea662014-07-23 14:16:32 -04001465 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001466 }
Geoff Langbfdea662014-07-23 14:16:32 -04001467
1468 gl::Context *context = gl::getNonLostContext();
1469
1470 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001471 {
Geoff Langbfdea662014-07-23 14:16:32 -04001472 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1473 {
1474 return;
1475 }
1476
1477 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1478 ASSERT(framebuffer);
1479
1480 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1481 {
1482 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1483 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1484 }
1485 else
1486 {
1487 switch (attachment)
1488 {
1489 case GL_DEPTH_ATTACHMENT:
1490 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1491 break;
1492 case GL_STENCIL_ATTACHMENT:
1493 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1494 break;
1495 case GL_DEPTH_STENCIL_ATTACHMENT:
1496 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1497 break;
1498 default:
1499 UNREACHABLE();
1500 break;
1501 }
1502 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001503 }
1504}
1505
1506void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1507{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001508 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001509 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001510
Geoff Langbfdea662014-07-23 14:16:32 -04001511 gl::Context *context = gl::getNonLostContext();
1512 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001513 {
Geoff Langbfdea662014-07-23 14:16:32 -04001514 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001515 {
Geoff Langbfdea662014-07-23 14:16:32 -04001516 return;
1517 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001518
Geoff Langbfdea662014-07-23 14:16:32 -04001519 if (texture == 0)
1520 {
1521 textarget = GL_NONE;
1522 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001523
Geoff Langbfdea662014-07-23 14:16:32 -04001524 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001525
Geoff Langbfdea662014-07-23 14:16:32 -04001526 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1527 {
1528 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1529 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1530 }
1531 else
1532 {
1533 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001534 {
Geoff Langbfdea662014-07-23 14:16:32 -04001535 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1536 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1537 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001538 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001539 }
1540 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001541}
1542
1543void __stdcall glFrontFace(GLenum mode)
1544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001545 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001546
Geoff Langbfdea662014-07-23 14:16:32 -04001547 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001548 {
Geoff Langbfdea662014-07-23 14:16:32 -04001549 case GL_CW:
1550 case GL_CCW:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001551 {
Geoff Langbfdea662014-07-23 14:16:32 -04001552 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001553
Geoff Langbfdea662014-07-23 14:16:32 -04001554 if (context)
1555 {
1556 context->getState().setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001557 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001558 }
Geoff Langbfdea662014-07-23 14:16:32 -04001559 break;
1560 default:
1561 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001562 }
1563}
1564
1565void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1566{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001567 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001568
Geoff Langbfdea662014-07-23 14:16:32 -04001569 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001570 {
Geoff Langbfdea662014-07-23 14:16:32 -04001571 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001572 }
Geoff Langbfdea662014-07-23 14:16:32 -04001573
1574 gl::Context *context = gl::getNonLostContext();
1575
1576 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001577 {
Geoff Langbfdea662014-07-23 14:16:32 -04001578 for (int i = 0; i < n; i++)
1579 {
1580 buffers[i] = context->createBuffer();
1581 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001582 }
1583}
1584
1585void __stdcall glGenerateMipmap(GLenum target)
1586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001587 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001588
Geoff Langbfdea662014-07-23 14:16:32 -04001589 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001590
Geoff Langbfdea662014-07-23 14:16:32 -04001591 if (context)
1592 {
1593 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001594 {
Geoff Langbfdea662014-07-23 14:16:32 -04001595 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001596 }
Geoff Langbfdea662014-07-23 14:16:32 -04001597
1598 gl::Texture *texture = context->getTargetTexture(target);
1599
1600 if (texture == NULL)
1601 {
1602 return gl::error(GL_INVALID_OPERATION);
1603 }
1604
1605 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1606 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001607 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001608
1609 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1610 // unsized formats or that are color renderable and filterable. Since we do not track if
1611 // the texture was created with sized or unsized format (only sized formats are stored),
1612 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1613 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1614 // textures since they're the only texture format that can be created with unsized formats
1615 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1616 // was the last version to use add them.
1617 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1618 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1619 internalFormat == GL_ALPHA8_EXT;
1620
Geoff Lang5d601382014-07-22 15:14:06 -04001621 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1622 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001623 {
1624 return gl::error(GL_INVALID_OPERATION);
1625 }
1626
1627 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001628 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001629 {
1630 return gl::error(GL_INVALID_OPERATION);
1631 }
1632
1633 // Non-power of 2 ES2 check
1634 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1635 {
1636 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
1637 return gl::error(GL_INVALID_OPERATION);
1638 }
1639
1640 // Cube completeness check
1641 if (target == GL_TEXTURE_CUBE_MAP)
1642 {
1643 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1644 if (!textureCube->isCubeComplete())
1645 {
1646 return gl::error(GL_INVALID_OPERATION);
1647 }
1648 }
1649
1650 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001651 }
1652}
1653
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001654void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001656 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001657
Geoff Langbfdea662014-07-23 14:16:32 -04001658 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001659 {
Geoff Langbfdea662014-07-23 14:16:32 -04001660 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001661 }
Geoff Langbfdea662014-07-23 14:16:32 -04001662
1663 gl::Context *context = gl::getNonLostContext();
1664
1665 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001666 {
Geoff Langbfdea662014-07-23 14:16:32 -04001667 for (int i = 0; i < n; i++)
1668 {
1669 fences[i] = context->createFenceNV();
1670 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001671 }
1672}
1673
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001674void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1675{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001676 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001677
Geoff Langbfdea662014-07-23 14:16:32 -04001678 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001679 {
Geoff Langbfdea662014-07-23 14:16:32 -04001680 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001681 }
Geoff Langbfdea662014-07-23 14:16:32 -04001682
1683 gl::Context *context = gl::getNonLostContext();
1684
1685 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001686 {
Geoff Langbfdea662014-07-23 14:16:32 -04001687 for (int i = 0; i < n; i++)
1688 {
1689 framebuffers[i] = context->createFramebuffer();
1690 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001691 }
1692}
1693
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001694void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1695{
1696 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1697
Geoff Langbfdea662014-07-23 14:16:32 -04001698 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001699
Geoff Langbfdea662014-07-23 14:16:32 -04001700 if (context)
1701 {
1702 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001703 {
Geoff Langbfdea662014-07-23 14:16:32 -04001704 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001705 }
Geoff Langbfdea662014-07-23 14:16:32 -04001706
1707 for (GLsizei i = 0; i < n; i++)
1708 {
1709 ids[i] = context->createQuery();
1710 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001711 }
1712}
1713
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001714void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001716 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001717
Geoff Langbfdea662014-07-23 14:16:32 -04001718 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001719 {
Geoff Langbfdea662014-07-23 14:16:32 -04001720 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001721 }
Geoff Langbfdea662014-07-23 14:16:32 -04001722
1723 gl::Context *context = gl::getNonLostContext();
1724
1725 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001726 {
Geoff Langbfdea662014-07-23 14:16:32 -04001727 for (int i = 0; i < n; i++)
1728 {
1729 renderbuffers[i] = context->createRenderbuffer();
1730 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001731 }
1732}
1733
1734void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1735{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001736 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001737
Geoff Langbfdea662014-07-23 14:16:32 -04001738 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001739 {
Geoff Langbfdea662014-07-23 14:16:32 -04001740 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001741 }
Geoff Langbfdea662014-07-23 14:16:32 -04001742
1743 gl::Context *context = gl::getNonLostContext();
1744
1745 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001746 {
Geoff Langbfdea662014-07-23 14:16:32 -04001747 for (int i = 0; i < n; i++)
1748 {
1749 textures[i] = context->createTexture();
1750 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001751 }
1752}
1753
daniel@transgaming.com85423182010-04-22 13:35:27 +00001754void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001755{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001756 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001757 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001758 program, index, bufsize, length, size, type, name);
1759
Geoff Langbfdea662014-07-23 14:16:32 -04001760 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001761 {
Geoff Langbfdea662014-07-23 14:16:32 -04001762 return gl::error(GL_INVALID_VALUE);
1763 }
1764
1765 gl::Context *context = gl::getNonLostContext();
1766
1767 if (context)
1768 {
1769 gl::Program *programObject = context->getProgram(program);
1770
1771 if (!programObject)
1772 {
1773 if (context->getShader(program))
1774 {
1775 return gl::error(GL_INVALID_OPERATION);
1776 }
1777 else
1778 {
1779 return gl::error(GL_INVALID_VALUE);
1780 }
1781 }
1782
1783 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001785 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001786 }
1787
Geoff Langbfdea662014-07-23 14:16:32 -04001788 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001789 }
1790}
1791
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001792void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001793{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001794 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001795 "GLsizei* length = 0x%0.8p, GLint* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001796 program, index, bufsize, length, size, type, name);
1797
Geoff Langbfdea662014-07-23 14:16:32 -04001798 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001799 {
Geoff Langbfdea662014-07-23 14:16:32 -04001800 return gl::error(GL_INVALID_VALUE);
1801 }
1802
1803 gl::Context *context = gl::getNonLostContext();
1804
1805 if (context)
1806 {
1807 gl::Program *programObject = context->getProgram(program);
1808
1809 if (!programObject)
1810 {
1811 if (context->getShader(program))
1812 {
1813 return gl::error(GL_INVALID_OPERATION);
1814 }
1815 else
1816 {
1817 return gl::error(GL_INVALID_VALUE);
1818 }
1819 }
1820
1821 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001823 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001824 }
1825
Geoff Langbfdea662014-07-23 14:16:32 -04001826 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001827 }
1828}
1829
1830void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1831{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001832 EVENT("(GLuint program = %d, GLsizei maxcount = %d, GLsizei* count = 0x%0.8p, GLuint* shaders = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001833 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001834
Geoff Langbfdea662014-07-23 14:16:32 -04001835 if (maxcount < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001836 {
Geoff Langbfdea662014-07-23 14:16:32 -04001837 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001838 }
Geoff Langbfdea662014-07-23 14:16:32 -04001839
1840 gl::Context *context = gl::getNonLostContext();
1841
1842 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001843 {
Geoff Langbfdea662014-07-23 14:16:32 -04001844 gl::Program *programObject = context->getProgram(program);
1845
1846 if (!programObject)
1847 {
1848 if (context->getShader(program))
1849 {
1850 return gl::error(GL_INVALID_OPERATION);
1851 }
1852 else
1853 {
1854 return gl::error(GL_INVALID_VALUE);
1855 }
1856 }
1857
1858 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001859 }
1860}
1861
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001862int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001863{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001864 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001865
Geoff Langbfdea662014-07-23 14:16:32 -04001866 gl::Context *context = gl::getNonLostContext();
1867
1868 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001869 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001870
Geoff Langbfdea662014-07-23 14:16:32 -04001871 gl::Program *programObject = context->getProgram(program);
1872
1873 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001874 {
Geoff Langbfdea662014-07-23 14:16:32 -04001875 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001876 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001877 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001878 }
Geoff Langbfdea662014-07-23 14:16:32 -04001879 else
1880 {
1881 return gl::error(GL_INVALID_VALUE, -1);
1882 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001883 }
Geoff Langbfdea662014-07-23 14:16:32 -04001884
1885 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1886 if (!programObject->isLinked() || !programBinary)
1887 {
1888 return gl::error(GL_INVALID_OPERATION, -1);
1889 }
1890
1891 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001892 }
1893
1894 return -1;
1895}
1896
1897void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001899 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001900
Geoff Langbfdea662014-07-23 14:16:32 -04001901 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00001902
Geoff Langbfdea662014-07-23 14:16:32 -04001903 if (context)
1904 {
1905 GLenum nativeType;
1906 unsigned int numParams = 0;
1907 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001908 {
Geoff Langbfdea662014-07-23 14:16:32 -04001909 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001910 }
Geoff Langbfdea662014-07-23 14:16:32 -04001911
1912 if (nativeType == GL_BOOL)
1913 {
1914 context->getBooleanv(pname, params);
1915 }
1916 else
1917 {
1918 CastStateValues(context, nativeType, pname, numParams, params);
1919 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001920 }
1921}
1922
1923void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001925 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001926
Geoff Langbfdea662014-07-23 14:16:32 -04001927 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001928
Geoff Langbfdea662014-07-23 14:16:32 -04001929 if (context)
1930 {
1931 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001932 {
Geoff Langbfdea662014-07-23 14:16:32 -04001933 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001934 }
Geoff Langbfdea662014-07-23 14:16:32 -04001935
1936 if (!gl::ValidBufferParameter(context, pname))
1937 {
1938 return gl::error(GL_INVALID_ENUM);
1939 }
1940
1941 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
1942
1943 if (!buffer)
1944 {
1945 // A null buffer means that "0" is bound to the requested buffer target
1946 return gl::error(GL_INVALID_OPERATION);
1947 }
1948
1949 switch (pname)
1950 {
1951 case GL_BUFFER_USAGE:
1952 *params = static_cast<GLint>(buffer->getUsage());
1953 break;
1954 case GL_BUFFER_SIZE:
1955 *params = gl::clampCast<GLint>(buffer->getSize());
1956 break;
1957 case GL_BUFFER_ACCESS_FLAGS:
1958 *params = buffer->getAccessFlags();
1959 break;
1960 case GL_BUFFER_MAPPED:
1961 *params = static_cast<GLint>(buffer->isMapped());
1962 break;
1963 case GL_BUFFER_MAP_OFFSET:
1964 *params = gl::clampCast<GLint>(buffer->getMapOffset());
1965 break;
1966 case GL_BUFFER_MAP_LENGTH:
1967 *params = gl::clampCast<GLint>(buffer->getMapLength());
1968 break;
1969 default: UNREACHABLE(); break;
1970 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001971 }
1972}
1973
1974GLenum __stdcall glGetError(void)
1975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001976 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001977
1978 gl::Context *context = gl::getContext();
1979
1980 if (context)
1981 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00001982 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001983 }
1984
1985 return GL_NO_ERROR;
1986}
1987
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001988void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
1989{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001990 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001991
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001992
Geoff Langbfdea662014-07-23 14:16:32 -04001993 gl::Context *context = gl::getNonLostContext();
1994
1995 if (context)
1996 {
1997 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1998
1999 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002000 {
Geoff Langbfdea662014-07-23 14:16:32 -04002001 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002002 }
Geoff Langbfdea662014-07-23 14:16:32 -04002003
2004 if (fenceObject->isFence() != GL_TRUE)
2005 {
2006 return gl::error(GL_INVALID_OPERATION);
2007 }
2008
2009 switch (pname)
2010 {
2011 case GL_FENCE_STATUS_NV:
2012 case GL_FENCE_CONDITION_NV:
2013 break;
2014
2015 default: return gl::error(GL_INVALID_ENUM);
2016 }
2017
2018 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002019 }
2020}
2021
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002022void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2023{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002024 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002025
Geoff Langbfdea662014-07-23 14:16:32 -04002026 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002027
Geoff Langbfdea662014-07-23 14:16:32 -04002028 if (context)
2029 {
2030 GLenum nativeType;
2031 unsigned int numParams = 0;
2032 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002033 {
Geoff Langbfdea662014-07-23 14:16:32 -04002034 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002035 }
Geoff Langbfdea662014-07-23 14:16:32 -04002036
2037 if (nativeType == GL_FLOAT)
2038 {
2039 context->getFloatv(pname, params);
2040 }
2041 else
2042 {
2043 CastStateValues(context, nativeType, pname, numParams, params);
2044 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002045 }
2046}
2047
2048void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002050 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002051 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002052
Geoff Langbfdea662014-07-23 14:16:32 -04002053 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002054
Geoff Langbfdea662014-07-23 14:16:32 -04002055 if (context)
2056 {
2057 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002058 {
Geoff Langbfdea662014-07-23 14:16:32 -04002059 return gl::error(GL_INVALID_ENUM);
2060 }
2061
2062 int clientVersion = context->getClientVersion();
2063
2064 switch (pname)
2065 {
2066 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2067 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2068 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2069 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2070 break;
2071 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2072 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002074 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002075 }
Geoff Langbfdea662014-07-23 14:16:32 -04002076 break;
2077 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2078 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2079 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2080 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2081 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2082 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2083 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2084 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2085 if (clientVersion < 3)
2086 {
2087 return gl::error(GL_INVALID_ENUM);
2088 }
2089 break;
2090 default:
2091 return gl::error(GL_INVALID_ENUM);
2092 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002093
Geoff Langbfdea662014-07-23 14:16:32 -04002094 // Determine if the attachment is a valid enum
2095 switch (attachment)
2096 {
2097 case GL_BACK:
2098 case GL_FRONT:
2099 case GL_DEPTH:
2100 case GL_STENCIL:
2101 case GL_DEPTH_STENCIL_ATTACHMENT:
2102 if (clientVersion < 3)
2103 {
2104 return gl::error(GL_INVALID_ENUM);
2105 }
2106 break;
2107
2108 case GL_DEPTH_ATTACHMENT:
2109 case GL_STENCIL_ATTACHMENT:
2110 break;
2111
2112 default:
2113 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2114 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2115 {
2116 return gl::error(GL_INVALID_ENUM);
2117 }
2118 break;
2119 }
2120
2121 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2122 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2123
2124 if (framebufferHandle == 0)
2125 {
2126 if (clientVersion < 3)
2127 {
2128 return gl::error(GL_INVALID_OPERATION);
2129 }
2130
2131 switch (attachment)
2132 {
2133 case GL_BACK:
2134 case GL_DEPTH:
2135 case GL_STENCIL:
2136 break;
2137 default:
2138 return gl::error(GL_INVALID_OPERATION);
2139 }
2140 }
2141 else
2142 {
2143 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2144 {
2145 // Valid attachment query
2146 }
2147 else
2148 {
2149 switch (attachment)
2150 {
2151 case GL_DEPTH_ATTACHMENT:
2152 case GL_STENCIL_ATTACHMENT:
2153 break;
2154 case GL_DEPTH_STENCIL_ATTACHMENT:
2155 if (framebuffer->hasValidDepthStencil())
2156 {
2157 return gl::error(GL_INVALID_OPERATION);
2158 }
2159 break;
2160 default:
2161 return gl::error(GL_INVALID_OPERATION);
2162 }
2163 }
2164 }
2165
2166 GLenum attachmentType = GL_NONE;
2167 GLuint attachmentHandle = 0;
2168 GLuint attachmentLevel = 0;
2169 GLuint attachmentLayer = 0;
2170
2171 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2172
2173 if (attachmentObject)
2174 {
2175 attachmentType = attachmentObject->type();
2176 attachmentHandle = attachmentObject->id();
2177 attachmentLevel = attachmentObject->mipLevel();
2178 attachmentLayer = attachmentObject->layer();
2179 }
2180
2181 GLenum attachmentObjectType; // Type category
2182 if (framebufferHandle == 0)
2183 {
2184 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2185 }
2186 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2187 {
2188 attachmentObjectType = attachmentType;
2189 }
2190 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2191 {
2192 attachmentObjectType = GL_TEXTURE;
2193 }
2194 else
2195 {
2196 UNREACHABLE();
2197 return;
2198 }
2199
2200 if (attachmentObjectType == GL_NONE)
2201 {
2202 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2203 // is NONE, then querying any other pname will generate INVALID_ENUM.
2204
2205 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2206 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2207 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002208
Geoff Lang646559f2013-08-15 11:08:15 -04002209 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002210 {
Geoff Lang646559f2013-08-15 11:08:15 -04002211 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002212 *params = attachmentObjectType;
2213 break;
2214
Geoff Lang646559f2013-08-15 11:08:15 -04002215 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002216 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002217 {
Geoff Lang05b05022014-06-11 15:31:45 -04002218 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002219 }
Geoff Langbfdea662014-07-23 14:16:32 -04002220 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002221 break;
2222
2223 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002224 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002225 {
Geoff Langbfdea662014-07-23 14:16:32 -04002226 return gl::error(GL_INVALID_ENUM);
Geoff Lang646559f2013-08-15 11:08:15 -04002227 }
2228 else
2229 {
Geoff Langbfdea662014-07-23 14:16:32 -04002230 gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002231 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002232 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002233 }
Geoff Langbfdea662014-07-23 14:16:32 -04002234 else
2235 {
2236 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2237 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2238 ASSERT(attachmentObject != NULL);
2239
2240 switch (pname)
2241 {
2242 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2243 *params = attachmentObjectType;
2244 break;
2245
2246 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2247 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2248 {
2249 return gl::error(GL_INVALID_ENUM);
2250 }
2251 *params = attachmentHandle;
2252 break;
2253
2254 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2255 if (attachmentObjectType != GL_TEXTURE)
2256 {
2257 return gl::error(GL_INVALID_ENUM);
2258 }
2259 *params = attachmentLevel;
2260 break;
2261
2262 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2263 if (attachmentObjectType != GL_TEXTURE)
2264 {
2265 return gl::error(GL_INVALID_ENUM);
2266 }
2267 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2268 break;
2269
2270 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2271 *params = attachmentObject->getRedSize();
2272 break;
2273
2274 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2275 *params = attachmentObject->getGreenSize();
2276 break;
2277
2278 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2279 *params = attachmentObject->getBlueSize();
2280 break;
2281
2282 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2283 *params = attachmentObject->getAlphaSize();
2284 break;
2285
2286 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2287 *params = attachmentObject->getDepthSize();
2288 break;
2289
2290 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2291 *params = attachmentObject->getStencilSize();
2292 break;
2293
2294 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2295 if (attachment == GL_DEPTH_STENCIL)
2296 {
2297 gl::error(GL_INVALID_OPERATION);
2298 }
2299 *params = attachmentObject->getComponentType();
2300 break;
2301
2302 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2303 *params = attachmentObject->getColorEncoding();
2304 break;
2305
2306 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2307 if (attachmentObjectType != GL_TEXTURE)
2308 {
2309 return gl::error(GL_INVALID_ENUM);
2310 }
2311 *params = attachmentLayer;
2312 break;
2313
2314 default:
2315 UNREACHABLE();
2316 break;
2317 }
2318 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002319 }
2320}
2321
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002322GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2323{
2324 EVENT("()");
2325
Geoff Langbfdea662014-07-23 14:16:32 -04002326 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002327
Geoff Langbfdea662014-07-23 14:16:32 -04002328 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002329 {
Geoff Langbfdea662014-07-23 14:16:32 -04002330 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002331 }
Geoff Langbfdea662014-07-23 14:16:32 -04002332
2333 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002334}
2335
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002336void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2337{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002338 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002339
Geoff Langbfdea662014-07-23 14:16:32 -04002340 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002341
Geoff Langbfdea662014-07-23 14:16:32 -04002342 if (context)
2343 {
2344 GLenum nativeType;
2345 unsigned int numParams = 0;
2346
2347 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002348 {
Geoff Langbfdea662014-07-23 14:16:32 -04002349 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002350 }
Geoff Langbfdea662014-07-23 14:16:32 -04002351
2352 if (nativeType == GL_INT)
2353 {
2354 context->getIntegerv(pname, params);
2355 }
2356 else
2357 {
2358 CastStateValues(context, nativeType, pname, numParams, params);
2359 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002360 }
2361}
2362
2363void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2364{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002365 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002366
Geoff Langbfdea662014-07-23 14:16:32 -04002367 gl::Context *context = gl::getNonLostContext();
2368
2369 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002370 {
Geoff Langbfdea662014-07-23 14:16:32 -04002371 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002372
Geoff Langbfdea662014-07-23 14:16:32 -04002373 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002374 {
Geoff Langbfdea662014-07-23 14:16:32 -04002375 return gl::error(GL_INVALID_VALUE);
2376 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002377
Geoff Langbfdea662014-07-23 14:16:32 -04002378 if (context->getClientVersion() < 3)
2379 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002380 switch (pname)
2381 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002382 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002383 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002384 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002385 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002386 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002387 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002388 }
2389 }
Geoff Langbfdea662014-07-23 14:16:32 -04002390
2391 switch (pname)
2392 {
2393 case GL_DELETE_STATUS:
2394 *params = programObject->isFlaggedForDeletion();
2395 return;
2396 case GL_LINK_STATUS:
2397 *params = programObject->isLinked();
2398 return;
2399 case GL_VALIDATE_STATUS:
2400 *params = programObject->isValidated();
2401 return;
2402 case GL_INFO_LOG_LENGTH:
2403 *params = programObject->getInfoLogLength();
2404 return;
2405 case GL_ATTACHED_SHADERS:
2406 *params = programObject->getAttachedShadersCount();
2407 return;
2408 case GL_ACTIVE_ATTRIBUTES:
2409 *params = programObject->getActiveAttributeCount();
2410 return;
2411 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2412 *params = programObject->getActiveAttributeMaxLength();
2413 return;
2414 case GL_ACTIVE_UNIFORMS:
2415 *params = programObject->getActiveUniformCount();
2416 return;
2417 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2418 *params = programObject->getActiveUniformMaxLength();
2419 return;
2420 case GL_PROGRAM_BINARY_LENGTH_OES:
2421 *params = programObject->getProgramBinaryLength();
2422 return;
2423 case GL_ACTIVE_UNIFORM_BLOCKS:
2424 *params = programObject->getActiveUniformBlockCount();
2425 return;
2426 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2427 *params = programObject->getActiveUniformBlockMaxLength();
2428 break;
2429 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2430 *params = programObject->getTransformFeedbackBufferMode();
2431 break;
2432 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2433 *params = programObject->getTransformFeedbackVaryingCount();
2434 break;
2435 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2436 *params = programObject->getTransformFeedbackVaryingMaxLength();
2437 break;
2438 default:
2439 return gl::error(GL_INVALID_ENUM);
2440 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441 }
2442}
2443
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002444void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002445{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002446 EVENT("(GLuint program = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002447 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002448
Geoff Langbfdea662014-07-23 14:16:32 -04002449 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002450 {
Geoff Langbfdea662014-07-23 14:16:32 -04002451 return gl::error(GL_INVALID_VALUE);
2452 }
2453
2454 gl::Context *context = gl::getNonLostContext();
2455
2456 if (context)
2457 {
2458 gl::Program *programObject = context->getProgram(program);
2459
2460 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002462 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 }
2464
Geoff Langbfdea662014-07-23 14:16:32 -04002465 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002466 }
2467}
2468
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002469void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2470{
2471 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2472
Geoff Langbfdea662014-07-23 14:16:32 -04002473 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002474
Geoff Langbfdea662014-07-23 14:16:32 -04002475 if (context)
2476 {
2477 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002478 {
Geoff Langbfdea662014-07-23 14:16:32 -04002479 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002480 }
Geoff Langbfdea662014-07-23 14:16:32 -04002481
2482 switch (pname)
2483 {
2484 case GL_CURRENT_QUERY_EXT:
2485 params[0] = context->getState().getActiveQueryId(target);
2486 break;
2487
2488 default:
2489 return gl::error(GL_INVALID_ENUM);
2490 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002491 }
2492}
2493
2494void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2495{
2496 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2497
Geoff Langbfdea662014-07-23 14:16:32 -04002498 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002499
Geoff Langbfdea662014-07-23 14:16:32 -04002500 if (context)
2501 {
2502 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2503
2504 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002505 {
Geoff Langbfdea662014-07-23 14:16:32 -04002506 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002507 }
Geoff Langbfdea662014-07-23 14:16:32 -04002508
2509 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2510 {
2511 return gl::error(GL_INVALID_OPERATION);
2512 }
2513
2514 switch(pname)
2515 {
2516 case GL_QUERY_RESULT_EXT:
2517 params[0] = queryObject->getResult();
2518 break;
2519 case GL_QUERY_RESULT_AVAILABLE_EXT:
2520 params[0] = queryObject->isResultAvailable();
2521 break;
2522 default:
2523 return gl::error(GL_INVALID_ENUM);
2524 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002525 }
2526}
2527
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002528void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2529{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002530 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002531
Geoff Langbfdea662014-07-23 14:16:32 -04002532 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002533
Geoff Langbfdea662014-07-23 14:16:32 -04002534 if (context)
2535 {
2536 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002537 {
Geoff Langbfdea662014-07-23 14:16:32 -04002538 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002539 }
Geoff Langbfdea662014-07-23 14:16:32 -04002540
2541 if (context->getState().getRenderbufferId() == 0)
2542 {
2543 return gl::error(GL_INVALID_OPERATION);
2544 }
2545
2546 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2547
2548 switch (pname)
2549 {
2550 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2551 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2552 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2553 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2554 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2555 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2556 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2557 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2558 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
2559 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2560 if (!context->getExtensions().framebufferMultisample)
2561 {
2562 return gl::error(GL_INVALID_ENUM);
2563 }
2564 *params = renderbuffer->getSamples();
2565 break;
2566 default:
2567 return gl::error(GL_INVALID_ENUM);
2568 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002569 }
2570}
2571
2572void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2573{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002574 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002575
Geoff Langbfdea662014-07-23 14:16:32 -04002576 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002577
Geoff Langbfdea662014-07-23 14:16:32 -04002578 if (context)
2579 {
2580 gl::Shader *shaderObject = context->getShader(shader);
2581
2582 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002583 {
Geoff Langbfdea662014-07-23 14:16:32 -04002584 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002585 }
Geoff Langbfdea662014-07-23 14:16:32 -04002586
2587 switch (pname)
2588 {
2589 case GL_SHADER_TYPE:
2590 *params = shaderObject->getType();
2591 return;
2592 case GL_DELETE_STATUS:
2593 *params = shaderObject->isFlaggedForDeletion();
2594 return;
2595 case GL_COMPILE_STATUS:
2596 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2597 return;
2598 case GL_INFO_LOG_LENGTH:
2599 *params = shaderObject->getInfoLogLength();
2600 return;
2601 case GL_SHADER_SOURCE_LENGTH:
2602 *params = shaderObject->getSourceLength();
2603 return;
2604 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2605 *params = shaderObject->getTranslatedSourceLength();
2606 return;
2607 default:
2608 return gl::error(GL_INVALID_ENUM);
2609 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002610 }
2611}
2612
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002613void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002614{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002615 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002616 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002617
Geoff Langbfdea662014-07-23 14:16:32 -04002618 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002619 {
Geoff Langbfdea662014-07-23 14:16:32 -04002620 return gl::error(GL_INVALID_VALUE);
2621 }
2622
2623 gl::Context *context = gl::getNonLostContext();
2624
2625 if (context)
2626 {
2627 gl::Shader *shaderObject = context->getShader(shader);
2628
2629 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002631 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002632 }
2633
Geoff Langbfdea662014-07-23 14:16:32 -04002634 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002635 }
2636}
2637
2638void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2639{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002640 EVENT("(GLenum shadertype = 0x%X, GLenum precisiontype = 0x%X, GLint* range = 0x%0.8p, GLint* precision = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002641 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002642
Geoff Langbfdea662014-07-23 14:16:32 -04002643 switch (shadertype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002644 {
Geoff Langbfdea662014-07-23 14:16:32 -04002645 case GL_VERTEX_SHADER:
2646 case GL_FRAGMENT_SHADER:
2647 break;
2648 default:
2649 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002650 }
Geoff Langbfdea662014-07-23 14:16:32 -04002651
2652 switch (precisiontype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002653 {
Geoff Langbfdea662014-07-23 14:16:32 -04002654 case GL_LOW_FLOAT:
2655 case GL_MEDIUM_FLOAT:
2656 case GL_HIGH_FLOAT:
2657 // Assume IEEE 754 precision
2658 range[0] = 127;
2659 range[1] = 127;
2660 *precision = 23;
2661 break;
2662 case GL_LOW_INT:
2663 case GL_MEDIUM_INT:
2664 case GL_HIGH_INT:
2665 // Some (most) hardware only supports single-precision floating-point numbers,
2666 // which can accurately represent integers up to +/-16777216
2667 range[0] = 24;
2668 range[1] = 24;
2669 *precision = 0;
2670 break;
2671 default:
2672 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002673 }
2674}
2675
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002676void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002677{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002678 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002679 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002680
Geoff Langbfdea662014-07-23 14:16:32 -04002681 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002682 {
Geoff Langbfdea662014-07-23 14:16:32 -04002683 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002684 }
Geoff Langbfdea662014-07-23 14:16:32 -04002685
2686 gl::Context *context = gl::getNonLostContext();
2687
2688 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002689 {
Geoff Langbfdea662014-07-23 14:16:32 -04002690 gl::Shader *shaderObject = context->getShader(shader);
2691
2692 if (!shaderObject)
2693 {
2694 return gl::error(GL_INVALID_OPERATION);
2695 }
2696
2697 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002698 }
2699}
2700
zmo@google.coma574f782011-10-03 21:45:23 +00002701void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2702{
2703 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2704 shader, bufsize, length, source);
2705
Geoff Langbfdea662014-07-23 14:16:32 -04002706 if (bufsize < 0)
zmo@google.coma574f782011-10-03 21:45:23 +00002707 {
Geoff Langbfdea662014-07-23 14:16:32 -04002708 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00002709 }
Geoff Langbfdea662014-07-23 14:16:32 -04002710
2711 gl::Context *context = gl::getNonLostContext();
2712
2713 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002714 {
Geoff Langbfdea662014-07-23 14:16:32 -04002715 gl::Shader *shaderObject = context->getShader(shader);
2716
2717 if (!shaderObject)
2718 {
2719 return gl::error(GL_INVALID_OPERATION);
2720 }
2721
2722 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002723 }
2724}
2725
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726const GLubyte* __stdcall glGetString(GLenum name)
2727{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002728 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002729
Geoff Langbfdea662014-07-23 14:16:32 -04002730 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002731
Geoff Langbfdea662014-07-23 14:16:32 -04002732 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002733 {
Geoff Langbfdea662014-07-23 14:16:32 -04002734 case GL_VENDOR:
2735 return (GLubyte*)"Google Inc.";
2736 case GL_RENDERER:
2737 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
2738 case GL_VERSION:
2739 if (context->getClientVersion() == 2)
2740 {
2741 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2742 }
2743 else
2744 {
2745 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2746 }
2747 case GL_SHADING_LANGUAGE_VERSION:
2748 if (context->getClientVersion() == 2)
2749 {
2750 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2751 }
2752 else
2753 {
2754 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2755 }
2756 case GL_EXTENSIONS:
2757 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
2758 default:
2759 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002760 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002761}
2762
2763void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2764{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002765 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002766
Geoff Langbfdea662014-07-23 14:16:32 -04002767 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002768
Geoff Langbfdea662014-07-23 14:16:32 -04002769 if (context)
2770 {
2771 gl::Texture *texture = context->getTargetTexture(target);
2772
2773 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002774 {
Geoff Langbfdea662014-07-23 14:16:32 -04002775 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002776 }
Geoff Langbfdea662014-07-23 14:16:32 -04002777
2778 switch (pname)
2779 {
2780 case GL_TEXTURE_MAG_FILTER:
2781 *params = (GLfloat)texture->getSamplerState().magFilter;
2782 break;
2783 case GL_TEXTURE_MIN_FILTER:
2784 *params = (GLfloat)texture->getSamplerState().minFilter;
2785 break;
2786 case GL_TEXTURE_WRAP_S:
2787 *params = (GLfloat)texture->getSamplerState().wrapS;
2788 break;
2789 case GL_TEXTURE_WRAP_T:
2790 *params = (GLfloat)texture->getSamplerState().wrapT;
2791 break;
2792 case GL_TEXTURE_WRAP_R:
2793 if (context->getClientVersion() < 3)
2794 {
2795 return gl::error(GL_INVALID_ENUM);
2796 }
2797 *params = (GLfloat)texture->getSamplerState().wrapR;
2798 break;
2799 case GL_TEXTURE_IMMUTABLE_FORMAT:
2800 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2801 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2802 break;
2803 case GL_TEXTURE_IMMUTABLE_LEVELS:
2804 if (context->getClientVersion() < 3)
2805 {
2806 return gl::error(GL_INVALID_ENUM);
2807 }
2808 *params = (GLfloat)texture->immutableLevelCount();
2809 break;
2810 case GL_TEXTURE_USAGE_ANGLE:
2811 *params = (GLfloat)texture->getUsage();
2812 break;
2813 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2814 if (!context->getExtensions().textureFilterAnisotropic)
2815 {
2816 return gl::error(GL_INVALID_ENUM);
2817 }
2818 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2819 break;
2820 case GL_TEXTURE_SWIZZLE_R:
2821 if (context->getClientVersion() < 3)
2822 {
2823 return gl::error(GL_INVALID_ENUM);
2824 }
2825 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2826 break;
2827 case GL_TEXTURE_SWIZZLE_G:
2828 if (context->getClientVersion() < 3)
2829 {
2830 return gl::error(GL_INVALID_ENUM);
2831 }
2832 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2833 break;
2834 case GL_TEXTURE_SWIZZLE_B:
2835 if (context->getClientVersion() < 3)
2836 {
2837 return gl::error(GL_INVALID_ENUM);
2838 }
2839 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2840 break;
2841 case GL_TEXTURE_SWIZZLE_A:
2842 if (context->getClientVersion() < 3)
2843 {
2844 return gl::error(GL_INVALID_ENUM);
2845 }
2846 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2847 break;
2848 case GL_TEXTURE_BASE_LEVEL:
2849 if (context->getClientVersion() < 3)
2850 {
2851 return gl::error(GL_INVALID_ENUM);
2852 }
2853 *params = (GLfloat)texture->getSamplerState().baseLevel;
2854 break;
2855 case GL_TEXTURE_MAX_LEVEL:
2856 if (context->getClientVersion() < 3)
2857 {
2858 return gl::error(GL_INVALID_ENUM);
2859 }
2860 *params = (GLfloat)texture->getSamplerState().maxLevel;
2861 break;
2862 case GL_TEXTURE_MIN_LOD:
2863 if (context->getClientVersion() < 3)
2864 {
2865 return gl::error(GL_INVALID_ENUM);
2866 }
2867 *params = texture->getSamplerState().minLod;
2868 break;
2869 case GL_TEXTURE_MAX_LOD:
2870 if (context->getClientVersion() < 3)
2871 {
2872 return gl::error(GL_INVALID_ENUM);
2873 }
2874 *params = texture->getSamplerState().maxLod;
2875 break;
2876 default:
2877 return gl::error(GL_INVALID_ENUM);
2878 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002879 }
2880}
2881
2882void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
2883{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002884 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002885
Geoff Langbfdea662014-07-23 14:16:32 -04002886 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002887
Geoff Langbfdea662014-07-23 14:16:32 -04002888 if (context)
2889 {
2890 gl::Texture *texture = context->getTargetTexture(target);
2891
2892 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002893 {
Geoff Langbfdea662014-07-23 14:16:32 -04002894 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002895 }
Geoff Langbfdea662014-07-23 14:16:32 -04002896
2897 switch (pname)
2898 {
2899 case GL_TEXTURE_MAG_FILTER:
2900 *params = texture->getSamplerState().magFilter;
2901 break;
2902 case GL_TEXTURE_MIN_FILTER:
2903 *params = texture->getSamplerState().minFilter;
2904 break;
2905 case GL_TEXTURE_WRAP_S:
2906 *params = texture->getSamplerState().wrapS;
2907 break;
2908 case GL_TEXTURE_WRAP_T:
2909 *params = texture->getSamplerState().wrapT;
2910 break;
2911 case GL_TEXTURE_WRAP_R:
2912 if (context->getClientVersion() < 3)
2913 {
2914 return gl::error(GL_INVALID_ENUM);
2915 }
2916 *params = texture->getSamplerState().wrapR;
2917 break;
2918 case GL_TEXTURE_IMMUTABLE_FORMAT:
2919 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2920 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
2921 break;
2922 case GL_TEXTURE_IMMUTABLE_LEVELS:
2923 if (context->getClientVersion() < 3)
2924 {
2925 return gl::error(GL_INVALID_ENUM);
2926 }
2927 *params = texture->immutableLevelCount();
2928 break;
2929 case GL_TEXTURE_USAGE_ANGLE:
2930 *params = texture->getUsage();
2931 break;
2932 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2933 if (!context->getExtensions().textureFilterAnisotropic)
2934 {
2935 return gl::error(GL_INVALID_ENUM);
2936 }
2937 *params = (GLint)texture->getSamplerState().maxAnisotropy;
2938 break;
2939 case GL_TEXTURE_SWIZZLE_R:
2940 if (context->getClientVersion() < 3)
2941 {
2942 return gl::error(GL_INVALID_ENUM);
2943 }
2944 *params = texture->getSamplerState().swizzleRed;
2945 break;
2946 case GL_TEXTURE_SWIZZLE_G:
2947 if (context->getClientVersion() < 3)
2948 {
2949 return gl::error(GL_INVALID_ENUM);
2950 }
2951 *params = texture->getSamplerState().swizzleGreen;
2952 break;
2953 case GL_TEXTURE_SWIZZLE_B:
2954 if (context->getClientVersion() < 3)
2955 {
2956 return gl::error(GL_INVALID_ENUM);
2957 }
2958 *params = texture->getSamplerState().swizzleBlue;
2959 break;
2960 case GL_TEXTURE_SWIZZLE_A:
2961 if (context->getClientVersion() < 3)
2962 {
2963 return gl::error(GL_INVALID_ENUM);
2964 }
2965 *params = texture->getSamplerState().swizzleAlpha;
2966 break;
2967 case GL_TEXTURE_BASE_LEVEL:
2968 if (context->getClientVersion() < 3)
2969 {
2970 return gl::error(GL_INVALID_ENUM);
2971 }
2972 *params = texture->getSamplerState().baseLevel;
2973 break;
2974 case GL_TEXTURE_MAX_LEVEL:
2975 if (context->getClientVersion() < 3)
2976 {
2977 return gl::error(GL_INVALID_ENUM);
2978 }
2979 *params = texture->getSamplerState().maxLevel;
2980 break;
2981 case GL_TEXTURE_MIN_LOD:
2982 if (context->getClientVersion() < 3)
2983 {
2984 return gl::error(GL_INVALID_ENUM);
2985 }
2986 *params = (GLint)texture->getSamplerState().minLod;
2987 break;
2988 case GL_TEXTURE_MAX_LOD:
2989 if (context->getClientVersion() < 3)
2990 {
2991 return gl::error(GL_INVALID_ENUM);
2992 }
2993 *params = (GLint)texture->getSamplerState().maxLod;
2994 break;
2995 default:
2996 return gl::error(GL_INVALID_ENUM);
2997 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002998 }
2999}
3000
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003001void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3002{
3003 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3004 program, location, bufSize, params);
3005
Geoff Langbfdea662014-07-23 14:16:32 -04003006 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003007 {
Geoff Langbfdea662014-07-23 14:16:32 -04003008 return gl::error(GL_INVALID_VALUE);
3009 }
3010
3011 gl::Context *context = gl::getNonLostContext();
3012
3013 if (context)
3014 {
3015 if (program == 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003016 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003017 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003018 }
3019
Geoff Langbfdea662014-07-23 14:16:32 -04003020 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003021
Geoff Langbfdea662014-07-23 14:16:32 -04003022 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003023 {
Geoff Langbfdea662014-07-23 14:16:32 -04003024 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003025 }
Geoff Langbfdea662014-07-23 14:16:32 -04003026
3027 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3028 if (!programBinary)
3029 {
3030 return gl::error(GL_INVALID_OPERATION);
3031 }
3032
3033 if (!programBinary->getUniformfv(location, &bufSize, params))
3034 {
3035 return gl::error(GL_INVALID_OPERATION);
3036 }
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003037 }
3038}
3039
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003040void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3041{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003042 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003043
Geoff Langbfdea662014-07-23 14:16:32 -04003044 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003045
Geoff Langbfdea662014-07-23 14:16:32 -04003046 if (context)
3047 {
3048 if (program == 0)
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003049 {
Geoff Langbfdea662014-07-23 14:16:32 -04003050 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003051 }
Geoff Langbfdea662014-07-23 14:16:32 -04003052
3053 gl::Program *programObject = context->getProgram(program);
3054
3055 if (!programObject || !programObject->isLinked())
3056 {
3057 return gl::error(GL_INVALID_OPERATION);
3058 }
3059
3060 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3061 if (!programBinary)
3062 {
3063 return gl::error(GL_INVALID_OPERATION);
3064 }
3065
3066 if (!programBinary->getUniformfv(location, NULL, params))
3067 {
3068 return gl::error(GL_INVALID_OPERATION);
3069 }
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003070 }
3071}
3072
3073void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3074{
Geoff Langbfdea662014-07-23 14:16:32 -04003075 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003076 program, location, bufSize, params);
3077
Geoff Langbfdea662014-07-23 14:16:32 -04003078 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003079 {
Geoff Langbfdea662014-07-23 14:16:32 -04003080 return gl::error(GL_INVALID_VALUE);
3081 }
3082
3083 gl::Context *context = gl::getNonLostContext();
3084
3085 if (context)
3086 {
3087 if (program == 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003089 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003090 }
3091
Geoff Langbfdea662014-07-23 14:16:32 -04003092 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003093
Geoff Langbfdea662014-07-23 14:16:32 -04003094 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003095 {
Geoff Langbfdea662014-07-23 14:16:32 -04003096 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003097 }
Geoff Langbfdea662014-07-23 14:16:32 -04003098
3099 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3100 if (!programBinary)
3101 {
3102 return gl::error(GL_INVALID_OPERATION);
3103 }
3104
3105 if (!programBinary->getUniformiv(location, &bufSize, params))
3106 {
3107 return gl::error(GL_INVALID_OPERATION);
3108 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003109 }
3110}
3111
3112void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3113{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003114 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115
Geoff Langbfdea662014-07-23 14:16:32 -04003116 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003117
Geoff Langbfdea662014-07-23 14:16:32 -04003118 if (context)
3119 {
3120 if (program == 0)
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003121 {
Geoff Langbfdea662014-07-23 14:16:32 -04003122 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003123 }
Geoff Langbfdea662014-07-23 14:16:32 -04003124
3125 gl::Program *programObject = context->getProgram(program);
3126
3127 if (!programObject || !programObject->isLinked())
3128 {
3129 return gl::error(GL_INVALID_OPERATION);
3130 }
3131
3132 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3133 if (!programBinary)
3134 {
3135 return gl::error(GL_INVALID_OPERATION);
3136 }
3137
3138 if (!programBinary->getUniformiv(location, NULL, params))
3139 {
3140 return gl::error(GL_INVALID_OPERATION);
3141 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003142 }
3143}
3144
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003145int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003146{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003147 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148
Geoff Langbfdea662014-07-23 14:16:32 -04003149 gl::Context *context = gl::getNonLostContext();
3150
3151 if (strstr(name, "gl_") == name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003152 {
Geoff Langbfdea662014-07-23 14:16:32 -04003153 return -1;
3154 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003155
Geoff Langbfdea662014-07-23 14:16:32 -04003156 if (context)
3157 {
3158 gl::Program *programObject = context->getProgram(program);
3159
3160 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003161 {
Geoff Langbfdea662014-07-23 14:16:32 -04003162 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003164 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003165 }
Geoff Langbfdea662014-07-23 14:16:32 -04003166 else
3167 {
3168 return gl::error(GL_INVALID_VALUE, -1);
3169 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003170 }
Geoff Langbfdea662014-07-23 14:16:32 -04003171
3172 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3173 if (!programObject->isLinked() || !programBinary)
3174 {
3175 return gl::error(GL_INVALID_OPERATION, -1);
3176 }
3177
3178 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003179 }
3180
3181 return -1;
3182}
3183
3184void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3185{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003186 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187
Geoff Langbfdea662014-07-23 14:16:32 -04003188 gl::Context *context = gl::getNonLostContext();
3189
3190 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003191 {
Geoff Langbfdea662014-07-23 14:16:32 -04003192 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003193 {
Geoff Langbfdea662014-07-23 14:16:32 -04003194 return gl::error(GL_INVALID_VALUE);
3195 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003196
Geoff Langbfdea662014-07-23 14:16:32 -04003197 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
3198 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3199 {
3200 return;
3201 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003202
Geoff Langbfdea662014-07-23 14:16:32 -04003203 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3204 {
3205 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3206 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003207 {
Geoff Langbfdea662014-07-23 14:16:32 -04003208 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003209 }
3210 }
Geoff Langbfdea662014-07-23 14:16:32 -04003211 else
3212 {
3213 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3214 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003215 }
3216}
3217
3218void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3219{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003220 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003221
Geoff Langbfdea662014-07-23 14:16:32 -04003222 gl::Context *context = gl::getNonLostContext();
3223
3224 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003225 {
Geoff Langbfdea662014-07-23 14:16:32 -04003226 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003227 {
Geoff Langbfdea662014-07-23 14:16:32 -04003228 return gl::error(GL_INVALID_VALUE);
3229 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003230
Geoff Langbfdea662014-07-23 14:16:32 -04003231 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003232
Geoff Langbfdea662014-07-23 14:16:32 -04003233 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3234 {
3235 return;
3236 }
Jamie Madillaff71502013-07-02 11:57:05 -04003237
Geoff Langbfdea662014-07-23 14:16:32 -04003238 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3239 {
3240 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3241 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003242 {
Geoff Langbfdea662014-07-23 14:16:32 -04003243 float currentValue = currentValueData.FloatValues[i];
3244 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003245 }
3246 }
Geoff Langbfdea662014-07-23 14:16:32 -04003247 else
3248 {
3249 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3250 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003251 }
3252}
3253
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003254void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003255{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003256 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003257
Geoff Langbfdea662014-07-23 14:16:32 -04003258 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003259
Geoff Langbfdea662014-07-23 14:16:32 -04003260 if (context)
3261 {
3262 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003263 {
Geoff Langbfdea662014-07-23 14:16:32 -04003264 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003265 }
Geoff Langbfdea662014-07-23 14:16:32 -04003266
3267 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3268 {
3269 return gl::error(GL_INVALID_ENUM);
3270 }
3271
3272 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003273 }
3274}
3275
3276void __stdcall glHint(GLenum target, GLenum mode)
3277{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003278 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003279
Geoff Langbfdea662014-07-23 14:16:32 -04003280 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003281 {
Geoff Langbfdea662014-07-23 14:16:32 -04003282 case GL_FASTEST:
3283 case GL_NICEST:
3284 case GL_DONT_CARE:
3285 break;
3286 default:
3287 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003288 }
Geoff Langbfdea662014-07-23 14:16:32 -04003289
3290 gl::Context *context = gl::getNonLostContext();
3291 switch (target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003292 {
Geoff Langbfdea662014-07-23 14:16:32 -04003293 case GL_GENERATE_MIPMAP_HINT:
3294 if (context) context->getState().setGenerateMipmapHint(mode);
3295 break;
3296 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3297 if (context) context->getState().setFragmentShaderDerivativeHint(mode);
3298 break;
3299 default:
3300 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003301 }
3302}
3303
3304GLboolean __stdcall glIsBuffer(GLuint buffer)
3305{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003306 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003307
Geoff Langbfdea662014-07-23 14:16:32 -04003308 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003309
Geoff Langbfdea662014-07-23 14:16:32 -04003310 if (context && buffer)
3311 {
3312 gl::Buffer *bufferObject = context->getBuffer(buffer);
3313
3314 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003315 {
Geoff Langbfdea662014-07-23 14:16:32 -04003316 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003317 }
3318 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003319
3320 return GL_FALSE;
3321}
3322
3323GLboolean __stdcall glIsEnabled(GLenum cap)
3324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003325 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003326
Geoff Langbfdea662014-07-23 14:16:32 -04003327 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
Geoff Langbfdea662014-07-23 14:16:32 -04003329 if (context)
3330 {
3331 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003332 {
Geoff Langbfdea662014-07-23 14:16:32 -04003333 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334 }
Geoff Langbfdea662014-07-23 14:16:32 -04003335
3336 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003337 }
3338
3339 return false;
3340}
3341
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003342GLboolean __stdcall glIsFenceNV(GLuint fence)
3343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003344 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003345
Geoff Langbfdea662014-07-23 14:16:32 -04003346 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003347
Geoff Langbfdea662014-07-23 14:16:32 -04003348 if (context)
3349 {
3350 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3351
3352 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003353 {
Geoff Langbfdea662014-07-23 14:16:32 -04003354 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003355 }
Geoff Langbfdea662014-07-23 14:16:32 -04003356
3357 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003358 }
3359
3360 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003361}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003362
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003363GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3364{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003365 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003366
Geoff Langbfdea662014-07-23 14:16:32 -04003367 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003368
Geoff Langbfdea662014-07-23 14:16:32 -04003369 if (context && framebuffer)
3370 {
3371 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3372
3373 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003374 {
Geoff Langbfdea662014-07-23 14:16:32 -04003375 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003376 }
3377 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003378
3379 return GL_FALSE;
3380}
3381
3382GLboolean __stdcall glIsProgram(GLuint program)
3383{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003384 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003385
Geoff Langbfdea662014-07-23 14:16:32 -04003386 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003387
Geoff Langbfdea662014-07-23 14:16:32 -04003388 if (context && program)
3389 {
3390 gl::Program *programObject = context->getProgram(program);
3391
3392 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003393 {
Geoff Langbfdea662014-07-23 14:16:32 -04003394 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003395 }
3396 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397
3398 return GL_FALSE;
3399}
3400
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003401GLboolean __stdcall glIsQueryEXT(GLuint id)
3402{
3403 EVENT("(GLuint id = %d)", id);
3404
Geoff Langbfdea662014-07-23 14:16:32 -04003405 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003406
Geoff Langbfdea662014-07-23 14:16:32 -04003407 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003408 {
Geoff Langbfdea662014-07-23 14:16:32 -04003409 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003410 }
3411
3412 return GL_FALSE;
3413}
3414
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3416{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003417 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418
Geoff Langbfdea662014-07-23 14:16:32 -04003419 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003420
Geoff Langbfdea662014-07-23 14:16:32 -04003421 if (context && renderbuffer)
3422 {
3423 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3424
3425 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003426 {
Geoff Langbfdea662014-07-23 14:16:32 -04003427 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428 }
3429 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003430
3431 return GL_FALSE;
3432}
3433
3434GLboolean __stdcall glIsShader(GLuint shader)
3435{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003436 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003437
Geoff Langbfdea662014-07-23 14:16:32 -04003438 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003439
Geoff Langbfdea662014-07-23 14:16:32 -04003440 if (context && shader)
3441 {
3442 gl::Shader *shaderObject = context->getShader(shader);
3443
3444 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003445 {
Geoff Langbfdea662014-07-23 14:16:32 -04003446 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003447 }
3448 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449
3450 return GL_FALSE;
3451}
3452
3453GLboolean __stdcall glIsTexture(GLuint texture)
3454{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003455 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003456
Geoff Langbfdea662014-07-23 14:16:32 -04003457 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003458
Geoff Langbfdea662014-07-23 14:16:32 -04003459 if (context && texture)
3460 {
3461 gl::Texture *textureObject = context->getTexture(texture);
3462
3463 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003464 {
Geoff Langbfdea662014-07-23 14:16:32 -04003465 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466 }
3467 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468
3469 return GL_FALSE;
3470}
3471
3472void __stdcall glLineWidth(GLfloat width)
3473{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003474 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003475
Geoff Langbfdea662014-07-23 14:16:32 -04003476 if (width <= 0.0f)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003477 {
Geoff Langbfdea662014-07-23 14:16:32 -04003478 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003479 }
Geoff Langbfdea662014-07-23 14:16:32 -04003480
3481 gl::Context *context = gl::getNonLostContext();
3482
3483 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003484 {
Geoff Langbfdea662014-07-23 14:16:32 -04003485 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003486 }
3487}
3488
3489void __stdcall glLinkProgram(GLuint program)
3490{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003491 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003492
Geoff Langbfdea662014-07-23 14:16:32 -04003493 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494
Geoff Langbfdea662014-07-23 14:16:32 -04003495 if (context)
3496 {
3497 gl::Program *programObject = context->getProgram(program);
3498
3499 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003500 {
Geoff Langbfdea662014-07-23 14:16:32 -04003501 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502 {
Geoff Langbfdea662014-07-23 14:16:32 -04003503 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003504 }
Geoff Langbfdea662014-07-23 14:16:32 -04003505 else
3506 {
3507 return gl::error(GL_INVALID_VALUE);
3508 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003509 }
Geoff Langbfdea662014-07-23 14:16:32 -04003510
3511 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003512 }
3513}
3514
3515void __stdcall glPixelStorei(GLenum pname, GLint param)
3516{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003517 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003518
Geoff Langbfdea662014-07-23 14:16:32 -04003519 gl::Context *context = gl::getNonLostContext();
3520
3521 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003522 {
Geoff Langbfdea662014-07-23 14:16:32 -04003523 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003524 {
Geoff Langbfdea662014-07-23 14:16:32 -04003525 case GL_UNPACK_ALIGNMENT:
3526 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003527 {
Geoff Langbfdea662014-07-23 14:16:32 -04003528 return gl::error(GL_INVALID_VALUE);
3529 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003530
Geoff Langbfdea662014-07-23 14:16:32 -04003531 context->getState().setUnpackAlignment(param);
3532 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003533
Geoff Langbfdea662014-07-23 14:16:32 -04003534 case GL_PACK_ALIGNMENT:
3535 if (param != 1 && param != 2 && param != 4 && param != 8)
3536 {
3537 return gl::error(GL_INVALID_VALUE);
3538 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003539
Geoff Langbfdea662014-07-23 14:16:32 -04003540 context->getState().setPackAlignment(param);
3541 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003542
Geoff Langbfdea662014-07-23 14:16:32 -04003543 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3544 context->getState().setPackReverseRowOrder(param != 0);
3545 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003546
Geoff Langbfdea662014-07-23 14:16:32 -04003547 case GL_UNPACK_IMAGE_HEIGHT:
3548 case GL_UNPACK_SKIP_IMAGES:
3549 case GL_UNPACK_ROW_LENGTH:
3550 case GL_UNPACK_SKIP_ROWS:
3551 case GL_UNPACK_SKIP_PIXELS:
3552 case GL_PACK_ROW_LENGTH:
3553 case GL_PACK_SKIP_ROWS:
3554 case GL_PACK_SKIP_PIXELS:
3555 if (context->getClientVersion() < 3)
3556 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003557 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003558 }
Geoff Langbfdea662014-07-23 14:16:32 -04003559 UNIMPLEMENTED();
3560 break;
3561
3562 default:
3563 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003564 }
3565 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003566}
3567
3568void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3569{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003570 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571
Geoff Langbfdea662014-07-23 14:16:32 -04003572 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00003573
Geoff Langbfdea662014-07-23 14:16:32 -04003574 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003575 {
Geoff Langbfdea662014-07-23 14:16:32 -04003576 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003577 }
3578}
3579
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003580void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3581 GLenum format, GLenum type, GLsizei bufSize,
3582 GLvoid *data)
3583{
3584 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3585 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3586 x, y, width, height, format, type, bufSize, data);
3587
Geoff Langbfdea662014-07-23 14:16:32 -04003588 if (width < 0 || height < 0 || bufSize < 0)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003589 {
Geoff Langbfdea662014-07-23 14:16:32 -04003590 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003591 }
Geoff Langbfdea662014-07-23 14:16:32 -04003592
3593 gl::Context *context = gl::getNonLostContext();
3594
3595 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003596 {
Geoff Langbfdea662014-07-23 14:16:32 -04003597 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3598 format, type, &bufSize, data))
3599 {
3600 return;
3601 }
3602
3603 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003604 }
3605}
3606
3607void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3608 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003609{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003610 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003611 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003612 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003613
Geoff Langbfdea662014-07-23 14:16:32 -04003614 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003615 {
Geoff Langbfdea662014-07-23 14:16:32 -04003616 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617 }
Geoff Langbfdea662014-07-23 14:16:32 -04003618
3619 gl::Context *context = gl::getNonLostContext();
3620
3621 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003622 {
Geoff Langbfdea662014-07-23 14:16:32 -04003623 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3624 format, type, NULL, pixels))
3625 {
3626 return;
3627 }
3628
3629 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003630 }
3631}
3632
3633void __stdcall glReleaseShaderCompiler(void)
3634{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003635 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003636
Geoff Langbfdea662014-07-23 14:16:32 -04003637 gl::Shader::releaseCompiler();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003638}
3639
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003640void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003641{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003642 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003643 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003644
Geoff Langbfdea662014-07-23 14:16:32 -04003645 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003646
Geoff Langbfdea662014-07-23 14:16:32 -04003647 if (context)
3648 {
3649 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3650 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003651 {
Geoff Langbfdea662014-07-23 14:16:32 -04003652 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003653 }
Geoff Langbfdea662014-07-23 14:16:32 -04003654
3655 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003656 }
3657}
3658
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003659void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3660{
3661 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3662}
3663
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3665{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003666 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003667
Geoff Langbfdea662014-07-23 14:16:32 -04003668 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003669
Geoff Langbfdea662014-07-23 14:16:32 -04003670 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003671 {
Geoff Langbfdea662014-07-23 14:16:32 -04003672 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003673 }
3674}
3675
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003676void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3677{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003678 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003679
Geoff Langbfdea662014-07-23 14:16:32 -04003680 if (condition != GL_ALL_COMPLETED_NV)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003681 {
Geoff Langbfdea662014-07-23 14:16:32 -04003682 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003683 }
Geoff Langbfdea662014-07-23 14:16:32 -04003684
3685 gl::Context *context = gl::getNonLostContext();
3686
3687 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003688 {
Geoff Langbfdea662014-07-23 14:16:32 -04003689 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3690
3691 if (fenceObject == NULL)
3692 {
3693 return gl::error(GL_INVALID_OPERATION);
3694 }
3695
3696 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003697 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003698}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003699
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003700void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3701{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003702 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003703
Geoff Langbfdea662014-07-23 14:16:32 -04003704 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003705 {
Geoff Langbfdea662014-07-23 14:16:32 -04003706 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003707 }
Geoff Langbfdea662014-07-23 14:16:32 -04003708
3709 gl::Context* context = gl::getNonLostContext();
3710
3711 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003712 {
Geoff Langbfdea662014-07-23 14:16:32 -04003713 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003714 }
3715}
3716
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003717void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003718{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003719 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003720 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003721 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003722
Geoff Lang900013c2014-07-07 11:32:19 -04003723 gl::Context* context = gl::getNonLostContext();
3724 if (context)
3725 {
3726 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3727 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3728 {
3729 return gl::error(GL_INVALID_ENUM);
3730 }
3731
3732 // No binary shader formats are supported.
3733 UNIMPLEMENTED();
3734 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003735}
3736
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003737void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003738{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003739 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 +00003740 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003741
Geoff Langbfdea662014-07-23 14:16:32 -04003742 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743 {
Geoff Langbfdea662014-07-23 14:16:32 -04003744 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003745 }
Geoff Langbfdea662014-07-23 14:16:32 -04003746
3747 gl::Context *context = gl::getNonLostContext();
3748
3749 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003750 {
Geoff Langbfdea662014-07-23 14:16:32 -04003751 gl::Shader *shaderObject = context->getShader(shader);
3752
3753 if (!shaderObject)
3754 {
3755 if (context->getProgram(shader))
3756 {
3757 return gl::error(GL_INVALID_OPERATION);
3758 }
3759 else
3760 {
3761 return gl::error(GL_INVALID_VALUE);
3762 }
3763 }
3764
3765 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003766 }
3767}
3768
3769void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3770{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003771 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003772}
3773
3774void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3775{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003776 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 +00003777
Geoff Langbfdea662014-07-23 14:16:32 -04003778 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003779 {
Geoff Langbfdea662014-07-23 14:16:32 -04003780 case GL_FRONT:
3781 case GL_BACK:
3782 case GL_FRONT_AND_BACK:
3783 break;
3784 default:
3785 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003786 }
Geoff Langbfdea662014-07-23 14:16:32 -04003787
3788 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789 {
Geoff Langbfdea662014-07-23 14:16:32 -04003790 case GL_NEVER:
3791 case GL_ALWAYS:
3792 case GL_LESS:
3793 case GL_LEQUAL:
3794 case GL_EQUAL:
3795 case GL_GEQUAL:
3796 case GL_GREATER:
3797 case GL_NOTEQUAL:
3798 break;
3799 default:
3800 return gl::error(GL_INVALID_ENUM);
3801 }
3802
3803 gl::Context *context = gl::getNonLostContext();
3804
3805 if (context)
3806 {
3807 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3808 {
3809 context->getState().setStencilParams(func, ref, mask);
3810 }
3811
3812 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3813 {
3814 context->getState().setStencilBackParams(func, ref, mask);
3815 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003816 }
3817}
3818
3819void __stdcall glStencilMask(GLuint mask)
3820{
3821 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3822}
3823
3824void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3825{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003826 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003827
Geoff Langbfdea662014-07-23 14:16:32 -04003828 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003829 {
Geoff Langbfdea662014-07-23 14:16:32 -04003830 case GL_FRONT:
3831 case GL_BACK:
3832 case GL_FRONT_AND_BACK:
3833 break;
3834 default:
3835 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003836 }
Geoff Langbfdea662014-07-23 14:16:32 -04003837
3838 gl::Context *context = gl::getNonLostContext();
3839
3840 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003841 {
Geoff Langbfdea662014-07-23 14:16:32 -04003842 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3843 {
3844 context->getState().setStencilWritemask(mask);
3845 }
3846
3847 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3848 {
3849 context->getState().setStencilBackWritemask(mask);
3850 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003851 }
3852}
3853
3854void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3855{
3856 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3857}
3858
3859void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3860{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003861 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 +00003862 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003863
Geoff Langbfdea662014-07-23 14:16:32 -04003864 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003865 {
Geoff Langbfdea662014-07-23 14:16:32 -04003866 case GL_FRONT:
3867 case GL_BACK:
3868 case GL_FRONT_AND_BACK:
3869 break;
3870 default:
3871 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003872 }
Geoff Langbfdea662014-07-23 14:16:32 -04003873
3874 switch (fail)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003875 {
Geoff Langbfdea662014-07-23 14:16:32 -04003876 case GL_ZERO:
3877 case GL_KEEP:
3878 case GL_REPLACE:
3879 case GL_INCR:
3880 case GL_DECR:
3881 case GL_INVERT:
3882 case GL_INCR_WRAP:
3883 case GL_DECR_WRAP:
3884 break;
3885 default:
3886 return gl::error(GL_INVALID_ENUM);
3887 }
3888
3889 switch (zfail)
3890 {
3891 case GL_ZERO:
3892 case GL_KEEP:
3893 case GL_REPLACE:
3894 case GL_INCR:
3895 case GL_DECR:
3896 case GL_INVERT:
3897 case GL_INCR_WRAP:
3898 case GL_DECR_WRAP:
3899 break;
3900 default:
3901 return gl::error(GL_INVALID_ENUM);
3902 }
3903
3904 switch (zpass)
3905 {
3906 case GL_ZERO:
3907 case GL_KEEP:
3908 case GL_REPLACE:
3909 case GL_INCR:
3910 case GL_DECR:
3911 case GL_INVERT:
3912 case GL_INCR_WRAP:
3913 case GL_DECR_WRAP:
3914 break;
3915 default:
3916 return gl::error(GL_INVALID_ENUM);
3917 }
3918
3919 gl::Context *context = gl::getNonLostContext();
3920
3921 if (context)
3922 {
3923 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3924 {
3925 context->getState().setStencilOperations(fail, zfail, zpass);
3926 }
3927
3928 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3929 {
3930 context->getState().setStencilBackOperations(fail, zfail, zpass);
3931 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003932 }
3933}
3934
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003935GLboolean __stdcall glTestFenceNV(GLuint fence)
3936{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003937 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003938
Geoff Langbfdea662014-07-23 14:16:32 -04003939 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003940
Geoff Langbfdea662014-07-23 14:16:32 -04003941 if (context)
3942 {
3943 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3944
3945 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003946 {
Geoff Langbfdea662014-07-23 14:16:32 -04003947 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003948 }
Geoff Langbfdea662014-07-23 14:16:32 -04003949
3950 if (fenceObject->isFence() != GL_TRUE)
3951 {
3952 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
3953 }
3954
3955 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003956 }
Geoff Langbfdea662014-07-23 14:16:32 -04003957
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003958 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003959}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003960
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003961void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
3962 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003963{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003964 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05003965 "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 +00003966 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003967
Geoff Langbfdea662014-07-23 14:16:32 -04003968 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003969
Geoff Langbfdea662014-07-23 14:16:32 -04003970 if (context)
3971 {
3972 if (context->getClientVersion() < 3 &&
3973 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
3974 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003975 {
Geoff Langbfdea662014-07-23 14:16:32 -04003976 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003977 }
Geoff Langbfdea662014-07-23 14:16:32 -04003978
3979 if (context->getClientVersion() >= 3 &&
3980 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
3981 0, 0, 0, width, height, 1, border, format, type, pixels))
3982 {
3983 return;
3984 }
3985
3986 switch (target)
3987 {
3988 case GL_TEXTURE_2D:
3989 {
3990 gl::Texture2D *texture = context->getTexture2D();
3991 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3992 }
3993 break;
3994 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3995 {
3996 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3997 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3998 }
3999 break;
4000 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4001 {
4002 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4003 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4004 }
4005 break;
4006 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4007 {
4008 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4009 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4010 }
4011 break;
4012 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4013 {
4014 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4015 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4016 }
4017 break;
4018 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4019 {
4020 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4021 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4022 }
4023 break;
4024 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4025 {
4026 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4027 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4028 }
4029 break;
4030 default: UNREACHABLE();
4031 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004032 }
4033}
4034
4035void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4036{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004037 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4038
Geoff Langbfdea662014-07-23 14:16:32 -04004039 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004040
Geoff Langbfdea662014-07-23 14:16:32 -04004041 if (context)
4042 {
4043 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004044 {
Geoff Langbfdea662014-07-23 14:16:32 -04004045 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004046 }
Geoff Langbfdea662014-07-23 14:16:32 -04004047
4048 gl::Texture *texture = context->getTargetTexture(target);
4049
4050 if (!texture)
4051 {
4052 return gl::error(GL_INVALID_ENUM);
4053 }
4054
4055 switch (pname)
4056 {
4057 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4058 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4059 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4060 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4061 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4062 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4063 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4064 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4065 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4066 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4067 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4068 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4069 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4070 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4071 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4072 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4073 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4074 default: UNREACHABLE(); break;
4075 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004076 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077}
4078
4079void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4080{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004081 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082}
4083
4084void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4085{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004086 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004087
Geoff Langbfdea662014-07-23 14:16:32 -04004088 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004089
Geoff Langbfdea662014-07-23 14:16:32 -04004090 if (context)
4091 {
4092 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004093 {
Geoff Langbfdea662014-07-23 14:16:32 -04004094 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004095 }
Geoff Langbfdea662014-07-23 14:16:32 -04004096
4097 gl::Texture *texture = context->getTargetTexture(target);
4098
4099 if (!texture)
4100 {
4101 return gl::error(GL_INVALID_ENUM);
4102 }
4103
4104 switch (pname)
4105 {
4106 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4107 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4108 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4109 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4110 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4111 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4112 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4113 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4114 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4115 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4116 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4117 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4118 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4119 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4120 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4121 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4122 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4123 default: UNREACHABLE(); break;
4124 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004125 }
4126}
4127
4128void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4129{
4130 glTexParameteri(target, pname, *params);
4131}
4132
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004133void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4134{
4135 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4136 target, levels, internalformat, width, height);
4137
Geoff Langbfdea662014-07-23 14:16:32 -04004138 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004139
Geoff Langbfdea662014-07-23 14:16:32 -04004140 if (context)
4141 {
4142 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004143 {
Geoff Langbfdea662014-07-23 14:16:32 -04004144 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004145 }
Geoff Langbfdea662014-07-23 14:16:32 -04004146
4147 if (context->getClientVersion() < 3 &&
4148 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4149 {
4150 return;
4151 }
4152
4153 if (context->getClientVersion() >= 3 &&
4154 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4155 {
4156 return;
4157 }
4158
4159 switch (target)
4160 {
4161 case GL_TEXTURE_2D:
4162 {
4163 gl::Texture2D *texture2d = context->getTexture2D();
4164 texture2d->storage(levels, internalformat, width, height);
4165 }
4166 break;
4167
4168 case GL_TEXTURE_CUBE_MAP:
4169 {
4170 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4171 textureCube->storage(levels, internalformat, width);
4172 }
4173 break;
4174
4175 default:
4176 return gl::error(GL_INVALID_ENUM);
4177 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004178 }
4179}
4180
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004181void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4182 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004183{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004184 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004185 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004186 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004187 target, level, xoffset, yoffset, width, height, format, type, pixels);
4188
Geoff Langbfdea662014-07-23 14:16:32 -04004189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004190
Geoff Langbfdea662014-07-23 14:16:32 -04004191 if (context)
4192 {
4193 if (context->getClientVersion() < 3 &&
4194 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4195 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004196 {
Geoff Langbfdea662014-07-23 14:16:32 -04004197 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004198 }
Geoff Langbfdea662014-07-23 14:16:32 -04004199
4200 if (context->getClientVersion() >= 3 &&
4201 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4202 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4203 {
4204 return;
4205 }
4206
4207 // Zero sized uploads are valid but no-ops
4208 if (width == 0 || height == 0)
4209 {
4210 return;
4211 }
4212
4213 switch (target)
4214 {
4215 case GL_TEXTURE_2D:
4216 {
4217 gl::Texture2D *texture = context->getTexture2D();
4218 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4219 }
4220 break;
4221
4222 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4223 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4224 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4225 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4226 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4227 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4228 {
4229 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4230 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4231 }
4232 break;
4233
4234 default:
4235 UNREACHABLE();
4236 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004237 }
4238}
4239
4240void __stdcall glUniform1f(GLint location, GLfloat x)
4241{
4242 glUniform1fv(location, 1, &x);
4243}
4244
4245void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4246{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004247 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004248
Geoff Langbfdea662014-07-23 14:16:32 -04004249 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004250
Geoff Langbfdea662014-07-23 14:16:32 -04004251 if (context)
4252 {
4253 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004254 {
Geoff Langbfdea662014-07-23 14:16:32 -04004255 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004256 }
Geoff Langbfdea662014-07-23 14:16:32 -04004257
4258 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4259 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004260 }
4261}
4262
4263void __stdcall glUniform1i(GLint location, GLint x)
4264{
4265 glUniform1iv(location, 1, &x);
4266}
4267
4268void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4269{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004270 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004271
Geoff Langbfdea662014-07-23 14:16:32 -04004272 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004273
Geoff Langbfdea662014-07-23 14:16:32 -04004274 if (context)
4275 {
4276 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004277 {
Geoff Langbfdea662014-07-23 14:16:32 -04004278 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004279 }
Geoff Langbfdea662014-07-23 14:16:32 -04004280
4281 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4282 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004283 }
4284}
4285
4286void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4287{
4288 GLfloat xy[2] = {x, y};
4289
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004290 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291}
4292
4293void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4294{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004295 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004296
Geoff Langbfdea662014-07-23 14:16:32 -04004297 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004298
Geoff Langbfdea662014-07-23 14:16:32 -04004299 if (context)
4300 {
4301 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004302 {
Geoff Langbfdea662014-07-23 14:16:32 -04004303 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004304 }
Geoff Langbfdea662014-07-23 14:16:32 -04004305
4306 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4307 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004308 }
4309}
4310
4311void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4312{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004313 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004314
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004315 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004316}
4317
4318void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4319{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004320 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004321
Geoff Langbfdea662014-07-23 14:16:32 -04004322 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004323
Geoff Langbfdea662014-07-23 14:16:32 -04004324 if (context)
4325 {
4326 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004327 {
Geoff Langbfdea662014-07-23 14:16:32 -04004328 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004329 }
Geoff Langbfdea662014-07-23 14:16:32 -04004330
4331 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4332 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004333 }
4334}
4335
4336void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4337{
4338 GLfloat xyz[3] = {x, y, z};
4339
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004340 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004341}
4342
4343void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4344{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004345 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004346
Geoff Langbfdea662014-07-23 14:16:32 -04004347 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004348
Geoff Langbfdea662014-07-23 14:16:32 -04004349 if (context)
4350 {
4351 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004352 {
Geoff Langbfdea662014-07-23 14:16:32 -04004353 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004354 }
Geoff Langbfdea662014-07-23 14:16:32 -04004355
4356 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4357 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004358 }
4359}
4360
4361void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4362{
4363 GLint xyz[3] = {x, y, z};
4364
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004365 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004366}
4367
4368void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4369{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004370 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004371
Geoff Langbfdea662014-07-23 14:16:32 -04004372 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004373
Geoff Langbfdea662014-07-23 14:16:32 -04004374 if (context)
4375 {
4376 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004377 {
Geoff Langbfdea662014-07-23 14:16:32 -04004378 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004379 }
Geoff Langbfdea662014-07-23 14:16:32 -04004380
4381 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4382 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004383 }
4384}
4385
4386void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4387{
4388 GLfloat xyzw[4] = {x, y, z, w};
4389
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004390 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004391}
4392
4393void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4394{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004395 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004396
Geoff Langbfdea662014-07-23 14:16:32 -04004397 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004398
Geoff Langbfdea662014-07-23 14:16:32 -04004399 if (context)
4400 {
4401 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004402 {
Geoff Langbfdea662014-07-23 14:16:32 -04004403 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004404 }
Geoff Langbfdea662014-07-23 14:16:32 -04004405
4406 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4407 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004408 }
4409}
4410
4411void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4412{
4413 GLint xyzw[4] = {x, y, z, w};
4414
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004415 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004416}
4417
4418void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4419{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004420 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004421
Geoff Langbfdea662014-07-23 14:16:32 -04004422 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004423
Geoff Langbfdea662014-07-23 14:16:32 -04004424 if (context)
4425 {
4426 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004427 {
Geoff Langbfdea662014-07-23 14:16:32 -04004428 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004429 }
Geoff Langbfdea662014-07-23 14:16:32 -04004430
4431 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4432 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004433 }
4434}
4435
4436void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4437{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004438 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004439 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004440
Geoff Langbfdea662014-07-23 14:16:32 -04004441 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442
Geoff Langbfdea662014-07-23 14:16:32 -04004443 if (context)
4444 {
4445 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004446 {
Geoff Langbfdea662014-07-23 14:16:32 -04004447 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004448 }
Geoff Langbfdea662014-07-23 14:16:32 -04004449
4450 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4451 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452 }
4453}
4454
4455void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4456{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004457 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004458 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004459
Geoff Langbfdea662014-07-23 14:16:32 -04004460 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004461
Geoff Langbfdea662014-07-23 14:16:32 -04004462 if (context)
4463 {
4464 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004465 {
Geoff Langbfdea662014-07-23 14:16:32 -04004466 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004467 }
Geoff Langbfdea662014-07-23 14:16:32 -04004468
4469 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4470 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004471 }
4472}
4473
4474void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4475{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004476 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004477 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004478
Geoff Langbfdea662014-07-23 14:16:32 -04004479 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480
Geoff Langbfdea662014-07-23 14:16:32 -04004481 if (context)
4482 {
4483 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004484 {
Geoff Langbfdea662014-07-23 14:16:32 -04004485 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004486 }
Geoff Langbfdea662014-07-23 14:16:32 -04004487
4488 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4489 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490 }
4491}
4492
4493void __stdcall glUseProgram(GLuint program)
4494{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004495 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004496
Geoff Langbfdea662014-07-23 14:16:32 -04004497 gl::Context *context = gl::getNonLostContext();
4498
4499 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004500 {
Geoff Langbfdea662014-07-23 14:16:32 -04004501 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004502
Geoff Langbfdea662014-07-23 14:16:32 -04004503 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004504 {
Geoff Langbfdea662014-07-23 14:16:32 -04004505 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004507 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508 }
Geoff Langbfdea662014-07-23 14:16:32 -04004509 else
4510 {
4511 return gl::error(GL_INVALID_VALUE);
4512 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004513 }
Geoff Langbfdea662014-07-23 14:16:32 -04004514
4515 if (program != 0 && !programObject->isLinked())
4516 {
4517 return gl::error(GL_INVALID_OPERATION);
4518 }
4519
4520 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004521 }
4522}
4523
4524void __stdcall glValidateProgram(GLuint program)
4525{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004526 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004527
Geoff Langbfdea662014-07-23 14:16:32 -04004528 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004529
Geoff Langbfdea662014-07-23 14:16:32 -04004530 if (context)
4531 {
4532 gl::Program *programObject = context->getProgram(program);
4533
4534 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004535 {
Geoff Langbfdea662014-07-23 14:16:32 -04004536 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004537 {
Geoff Langbfdea662014-07-23 14:16:32 -04004538 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004539 }
Geoff Langbfdea662014-07-23 14:16:32 -04004540 else
4541 {
4542 return gl::error(GL_INVALID_VALUE);
4543 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004544 }
Geoff Langbfdea662014-07-23 14:16:32 -04004545
4546 programObject->validate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004547 }
4548}
4549
4550void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4551{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004552 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004553
Geoff Langbfdea662014-07-23 14:16:32 -04004554 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555 {
Geoff Langbfdea662014-07-23 14:16:32 -04004556 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557 }
Geoff Langbfdea662014-07-23 14:16:32 -04004558
4559 gl::Context *context = gl::getNonLostContext();
4560
4561 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562 {
Geoff Langbfdea662014-07-23 14:16:32 -04004563 GLfloat vals[4] = { x, 0, 0, 1 };
4564 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004565 }
4566}
4567
4568void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4569{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004570 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004571
Geoff Langbfdea662014-07-23 14:16:32 -04004572 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573 {
Geoff Langbfdea662014-07-23 14:16:32 -04004574 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004575 }
Geoff Langbfdea662014-07-23 14:16:32 -04004576
4577 gl::Context *context = gl::getNonLostContext();
4578
4579 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004580 {
Geoff Langbfdea662014-07-23 14:16:32 -04004581 GLfloat vals[4] = { values[0], 0, 0, 1 };
4582 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004583 }
4584}
4585
4586void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4587{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004588 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004589
Geoff Langbfdea662014-07-23 14:16:32 -04004590 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004591 {
Geoff Langbfdea662014-07-23 14:16:32 -04004592 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004593 }
Geoff Langbfdea662014-07-23 14:16:32 -04004594
4595 gl::Context *context = gl::getNonLostContext();
4596
4597 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004598 {
Geoff Langbfdea662014-07-23 14:16:32 -04004599 GLfloat vals[4] = { x, y, 0, 1 };
4600 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004601 }
4602}
4603
4604void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4605{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004606 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004607
Geoff Langbfdea662014-07-23 14:16:32 -04004608 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609 {
Geoff Langbfdea662014-07-23 14:16:32 -04004610 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004611 }
Geoff Langbfdea662014-07-23 14:16:32 -04004612
4613 gl::Context *context = gl::getNonLostContext();
4614
4615 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004616 {
Geoff Langbfdea662014-07-23 14:16:32 -04004617 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4618 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619 }
4620}
4621
4622void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4623{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004624 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 +00004625
Geoff Langbfdea662014-07-23 14:16:32 -04004626 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 {
Geoff Langbfdea662014-07-23 14:16:32 -04004628 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004629 }
Geoff Langbfdea662014-07-23 14:16:32 -04004630
4631 gl::Context *context = gl::getNonLostContext();
4632
4633 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634 {
Geoff Langbfdea662014-07-23 14:16:32 -04004635 GLfloat vals[4] = { x, y, z, 1 };
4636 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004637 }
4638}
4639
4640void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4641{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004642 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004643
Geoff Langbfdea662014-07-23 14:16:32 -04004644 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004645 {
Geoff Langbfdea662014-07-23 14:16:32 -04004646 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004647 }
Geoff Langbfdea662014-07-23 14:16:32 -04004648
4649 gl::Context *context = gl::getNonLostContext();
4650
4651 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004652 {
Geoff Langbfdea662014-07-23 14:16:32 -04004653 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4654 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004655 }
4656}
4657
4658void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4659{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004660 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 +00004661
Geoff Langbfdea662014-07-23 14:16:32 -04004662 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004663 {
Geoff Langbfdea662014-07-23 14:16:32 -04004664 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004665 }
Geoff Langbfdea662014-07-23 14:16:32 -04004666
4667 gl::Context *context = gl::getNonLostContext();
4668
4669 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670 {
Geoff Langbfdea662014-07-23 14:16:32 -04004671 GLfloat vals[4] = { x, y, z, w };
4672 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004673 }
4674}
4675
4676void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4677{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004678 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004679
Geoff Langbfdea662014-07-23 14:16:32 -04004680 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004681 {
Geoff Langbfdea662014-07-23 14:16:32 -04004682 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004683 }
Geoff Langbfdea662014-07-23 14:16:32 -04004684
4685 gl::Context *context = gl::getNonLostContext();
4686
4687 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004688 {
Geoff Langbfdea662014-07-23 14:16:32 -04004689 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004690 }
4691}
4692
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004693void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4694{
4695 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4696
Geoff Langbfdea662014-07-23 14:16:32 -04004697 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004698 {
Geoff Langbfdea662014-07-23 14:16:32 -04004699 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004700 }
Geoff Langbfdea662014-07-23 14:16:32 -04004701
4702 gl::Context *context = gl::getNonLostContext();
4703
4704 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004705 {
Geoff Langbfdea662014-07-23 14:16:32 -04004706 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004707 }
4708}
4709
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004710void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004711{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004712 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004713 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004714 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004715
Geoff Langbfdea662014-07-23 14:16:32 -04004716 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004717 {
Geoff Langbfdea662014-07-23 14:16:32 -04004718 return gl::error(GL_INVALID_VALUE);
4719 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004720
Geoff Langbfdea662014-07-23 14:16:32 -04004721 if (size < 1 || size > 4)
4722 {
4723 return gl::error(GL_INVALID_VALUE);
4724 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004725
Geoff Langbfdea662014-07-23 14:16:32 -04004726 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00004727
Geoff Langbfdea662014-07-23 14:16:32 -04004728 switch (type)
4729 {
4730 case GL_BYTE:
4731 case GL_UNSIGNED_BYTE:
4732 case GL_SHORT:
4733 case GL_UNSIGNED_SHORT:
4734 case GL_FIXED:
4735 case GL_FLOAT:
4736 break;
4737 case GL_HALF_FLOAT:
4738 case GL_INT:
4739 case GL_UNSIGNED_INT:
4740 case GL_INT_2_10_10_10_REV:
4741 case GL_UNSIGNED_INT_2_10_10_10_REV:
4742 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004744 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004745 }
Geoff Langbfdea662014-07-23 14:16:32 -04004746 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004747 {
Geoff Langbfdea662014-07-23 14:16:32 -04004748 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004749 }
Geoff Langbfdea662014-07-23 14:16:32 -04004750 default:
4751 return gl::error(GL_INVALID_ENUM);
4752 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004753
Geoff Langbfdea662014-07-23 14:16:32 -04004754 if (stride < 0)
4755 {
4756 return gl::error(GL_INVALID_VALUE);
4757 }
4758
4759 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4760 {
4761 return gl::error(GL_INVALID_OPERATION);
4762 }
4763
4764 if (context)
4765 {
4766 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4767 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4768 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4769 // and the pointer argument is not NULL.
4770 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004771 {
4772 return gl::error(GL_INVALID_OPERATION);
4773 }
4774
Geoff Langbfdea662014-07-23 14:16:32 -04004775 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4776 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004777 }
4778}
4779
4780void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4781{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004782 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 +00004783
Geoff Langbfdea662014-07-23 14:16:32 -04004784 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004785 {
Geoff Langbfdea662014-07-23 14:16:32 -04004786 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004787 }
Geoff Langbfdea662014-07-23 14:16:32 -04004788
4789 gl::Context *context = gl::getNonLostContext();
4790
4791 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004792 {
Geoff Langbfdea662014-07-23 14:16:32 -04004793 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004794 }
4795}
4796
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004797// OpenGL ES 3.0 functions
4798
4799void __stdcall glReadBuffer(GLenum mode)
4800{
4801 EVENT("(GLenum mode = 0x%X)", mode);
4802
Geoff Langbfdea662014-07-23 14:16:32 -04004803 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004804
Geoff Langbfdea662014-07-23 14:16:32 -04004805 if (context)
4806 {
4807 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004808 {
Geoff Langbfdea662014-07-23 14:16:32 -04004809 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004810 }
Geoff Langbfdea662014-07-23 14:16:32 -04004811
4812 // glReadBuffer
4813 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004814 }
4815}
4816
4817void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4818{
4819 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4820 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4821
Geoff Langbfdea662014-07-23 14:16:32 -04004822 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004823
Geoff Langbfdea662014-07-23 14:16:32 -04004824 if (context)
4825 {
4826 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004827 {
Geoff Langbfdea662014-07-23 14:16:32 -04004828 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004829 }
Geoff Langbfdea662014-07-23 14:16:32 -04004830
4831 // glDrawRangeElements
4832 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004833 }
4834}
4835
4836void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4837{
4838 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4839 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4840 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4841 target, level, internalformat, width, height, depth, border, format, type, pixels);
4842
Geoff Langbfdea662014-07-23 14:16:32 -04004843 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004844
Geoff Langbfdea662014-07-23 14:16:32 -04004845 if (context)
4846 {
4847 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004848 {
Geoff Langbfdea662014-07-23 14:16:32 -04004849 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004850 }
Geoff Langbfdea662014-07-23 14:16:32 -04004851
4852 // validateES3TexImageFormat sets the error code if there is an error
4853 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4854 0, 0, 0, width, height, depth, border, format, type, pixels))
4855 {
4856 return;
4857 }
4858
4859 switch(target)
4860 {
4861 case GL_TEXTURE_3D:
4862 {
4863 gl::Texture3D *texture = context->getTexture3D();
4864 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4865 }
4866 break;
4867
4868 case GL_TEXTURE_2D_ARRAY:
4869 {
4870 gl::Texture2DArray *texture = context->getTexture2DArray();
4871 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4872 }
4873 break;
4874
4875 default:
4876 return gl::error(GL_INVALID_ENUM);
4877 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004878 }
4879}
4880
4881void __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)
4882{
4883 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4884 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4885 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4886 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4887
Geoff Langbfdea662014-07-23 14:16:32 -04004888 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004889
Geoff Langbfdea662014-07-23 14:16:32 -04004890 if (context)
4891 {
4892 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004893 {
Geoff Langbfdea662014-07-23 14:16:32 -04004894 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004895 }
Geoff Langbfdea662014-07-23 14:16:32 -04004896
4897 // validateES3TexImageFormat sets the error code if there is an error
4898 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4899 xoffset, yoffset, zoffset, width, height, depth, 0,
4900 format, type, pixels))
4901 {
4902 return;
4903 }
4904
4905 // Zero sized uploads are valid but no-ops
4906 if (width == 0 || height == 0 || depth == 0)
4907 {
4908 return;
4909 }
4910
4911 switch(target)
4912 {
4913 case GL_TEXTURE_3D:
4914 {
4915 gl::Texture3D *texture = context->getTexture3D();
4916 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4917 }
4918 break;
4919
4920 case GL_TEXTURE_2D_ARRAY:
4921 {
4922 gl::Texture2DArray *texture = context->getTexture2DArray();
4923 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4924 }
4925 break;
4926
4927 default:
4928 return gl::error(GL_INVALID_ENUM);
4929 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004930 }
4931}
4932
4933void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
4934{
4935 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4936 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
4937 target, level, xoffset, yoffset, zoffset, x, y, width, height);
4938
Geoff Langbfdea662014-07-23 14:16:32 -04004939 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004940
Geoff Langbfdea662014-07-23 14:16:32 -04004941 if (context)
4942 {
4943 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004944 {
Geoff Langbfdea662014-07-23 14:16:32 -04004945 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004946 }
Geoff Langbfdea662014-07-23 14:16:32 -04004947
4948 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
4949 x, y, width, height, 0))
4950 {
4951 return;
4952 }
4953
4954 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
4955 gl::Texture *texture = NULL;
4956 switch (target)
4957 {
4958 case GL_TEXTURE_3D:
4959 texture = context->getTexture3D();
4960 break;
4961
4962 case GL_TEXTURE_2D_ARRAY:
4963 texture = context->getTexture2DArray();
4964 break;
4965
4966 default:
4967 return gl::error(GL_INVALID_ENUM);
4968 }
4969
4970 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004971 }
4972}
4973
4974void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
4975{
Geoff Langeef52cc2013-10-16 15:07:39 -04004976 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 +00004977 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
4978 "const GLvoid* data = 0x%0.8p)",
4979 target, level, internalformat, width, height, depth, border, imageSize, data);
4980
Geoff Langbfdea662014-07-23 14:16:32 -04004981 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004982
Geoff Langbfdea662014-07-23 14:16:32 -04004983 if (context)
4984 {
4985 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004986 {
Geoff Langbfdea662014-07-23 14:16:32 -04004987 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004988 }
Geoff Langbfdea662014-07-23 14:16:32 -04004989
Geoff Lang5d601382014-07-22 15:14:06 -04004990 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
4991 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04004992 {
4993 return gl::error(GL_INVALID_VALUE);
4994 }
4995
4996 // validateES3TexImageFormat sets the error code if there is an error
4997 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
4998 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
4999 {
5000 return;
5001 }
5002
5003 switch(target)
5004 {
5005 case GL_TEXTURE_3D:
5006 {
5007 gl::Texture3D *texture = context->getTexture3D();
5008 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5009 }
5010 break;
5011
5012 case GL_TEXTURE_2D_ARRAY:
5013 {
5014 gl::Texture2DArray *texture = context->getTexture2DArray();
5015 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5016 }
5017 break;
5018
5019 default:
5020 return gl::error(GL_INVALID_ENUM);
5021 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005022 }
5023}
5024
5025void __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)
5026{
5027 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5028 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5029 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5030 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5031
Geoff Langbfdea662014-07-23 14:16:32 -04005032 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005033
Geoff Langbfdea662014-07-23 14:16:32 -04005034 if (context)
5035 {
5036 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005037 {
Geoff Langbfdea662014-07-23 14:16:32 -04005038 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005039 }
Geoff Langbfdea662014-07-23 14:16:32 -04005040
Geoff Lang5d601382014-07-22 15:14:06 -04005041 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5042 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005043 {
5044 return gl::error(GL_INVALID_VALUE);
5045 }
5046
5047 if (!data)
5048 {
5049 return gl::error(GL_INVALID_VALUE);
5050 }
5051
5052 // validateES3TexImageFormat sets the error code if there is an error
5053 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5054 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5055 {
5056 return;
5057 }
5058
5059 // Zero sized uploads are valid but no-ops
5060 if (width == 0 || height == 0)
5061 {
5062 return;
5063 }
5064
5065 switch(target)
5066 {
5067 case GL_TEXTURE_3D:
5068 {
5069 gl::Texture3D *texture = context->getTexture3D();
5070 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5071 format, imageSize, data);
5072 }
5073 break;
5074
5075 case GL_TEXTURE_2D_ARRAY:
5076 {
5077 gl::Texture2DArray *texture = context->getTexture2DArray();
5078 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5079 format, imageSize, data);
5080 }
5081 break;
5082
5083 default:
5084 return gl::error(GL_INVALID_ENUM);
5085 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005086 }
5087}
5088
5089void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5090{
5091 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5092
Geoff Langbfdea662014-07-23 14:16:32 -04005093 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005094
Geoff Langbfdea662014-07-23 14:16:32 -04005095 if (context)
5096 {
5097 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005098 {
Geoff Langbfdea662014-07-23 14:16:32 -04005099 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005100 }
Geoff Langbfdea662014-07-23 14:16:32 -04005101
5102 if (n < 0)
5103 {
5104 return gl::error(GL_INVALID_VALUE);
5105 }
5106
5107 for (GLsizei i = 0; i < n; i++)
5108 {
5109 ids[i] = context->createQuery();
5110 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005111 }
5112}
5113
5114void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5115{
5116 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5117
Geoff Langbfdea662014-07-23 14:16:32 -04005118 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005119
Geoff Langbfdea662014-07-23 14:16:32 -04005120 if (context)
5121 {
5122 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005123 {
Geoff Langbfdea662014-07-23 14:16:32 -04005124 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005125 }
Geoff Langbfdea662014-07-23 14:16:32 -04005126
5127 if (n < 0)
5128 {
5129 return gl::error(GL_INVALID_VALUE);
5130 }
5131
5132 for (GLsizei i = 0; i < n; i++)
5133 {
5134 context->deleteQuery(ids[i]);
5135 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005136 }
5137}
5138
5139GLboolean __stdcall glIsQuery(GLuint id)
5140{
5141 EVENT("(GLuint id = %u)", id);
5142
Geoff Langbfdea662014-07-23 14:16:32 -04005143 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005144
Geoff Langbfdea662014-07-23 14:16:32 -04005145 if (context)
5146 {
5147 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005148 {
Geoff Langbfdea662014-07-23 14:16:32 -04005149 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005150 }
Geoff Langbfdea662014-07-23 14:16:32 -04005151
5152 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005153 }
5154
5155 return GL_FALSE;
5156}
5157
5158void __stdcall glBeginQuery(GLenum target, GLuint id)
5159{
5160 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5161
Geoff Langbfdea662014-07-23 14:16:32 -04005162 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005163
Geoff Langbfdea662014-07-23 14:16:32 -04005164 if (context)
5165 {
5166 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005167 {
Geoff Langbfdea662014-07-23 14:16:32 -04005168 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005169 }
Geoff Langbfdea662014-07-23 14:16:32 -04005170
5171 if (!ValidateBeginQuery(context, target, id))
5172 {
5173 return;
5174 }
5175 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005176 }
5177}
5178
5179void __stdcall glEndQuery(GLenum target)
5180{
5181 EVENT("(GLenum target = 0x%X)", target);
5182
Geoff Langbfdea662014-07-23 14:16:32 -04005183 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005184
Geoff Langbfdea662014-07-23 14:16:32 -04005185 if (context)
5186 {
5187 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005188 {
Geoff Langbfdea662014-07-23 14:16:32 -04005189 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005190 }
Geoff Langbfdea662014-07-23 14:16:32 -04005191
5192 if (!ValidateEndQuery(context, target))
5193 {
5194 return;
5195 }
5196
5197 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005198 }
5199}
5200
5201void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5202{
5203 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5204
Geoff Langbfdea662014-07-23 14:16:32 -04005205 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005206
Geoff Langbfdea662014-07-23 14:16:32 -04005207 if (context)
5208 {
5209 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005210 {
Geoff Langbfdea662014-07-23 14:16:32 -04005211 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005212 }
Geoff Langbfdea662014-07-23 14:16:32 -04005213
5214 if (!ValidQueryType(context, target))
5215 {
5216 return gl::error(GL_INVALID_ENUM);
5217 }
5218
5219 switch (pname)
5220 {
5221 case GL_CURRENT_QUERY:
5222 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5223 break;
5224
5225 default:
5226 return gl::error(GL_INVALID_ENUM);
5227 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005228 }
5229}
5230
5231void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5232{
5233 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5234
Geoff Langbfdea662014-07-23 14:16:32 -04005235 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005236
Geoff Langbfdea662014-07-23 14:16:32 -04005237 if (context)
5238 {
5239 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005240 {
Geoff Langbfdea662014-07-23 14:16:32 -04005241 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005242 }
Geoff Langbfdea662014-07-23 14:16:32 -04005243
5244 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5245
5246 if (!queryObject)
5247 {
5248 return gl::error(GL_INVALID_OPERATION);
5249 }
5250
5251 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5252 {
5253 return gl::error(GL_INVALID_OPERATION);
5254 }
5255
5256 switch(pname)
5257 {
5258 case GL_QUERY_RESULT:
5259 params[0] = queryObject->getResult();
5260 break;
5261 case GL_QUERY_RESULT_AVAILABLE:
5262 params[0] = queryObject->isResultAvailable();
5263 break;
5264 default:
5265 return gl::error(GL_INVALID_ENUM);
5266 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005267 }
5268}
5269
5270GLboolean __stdcall glUnmapBuffer(GLenum target)
5271{
5272 EVENT("(GLenum target = 0x%X)", target);
5273
Geoff Langbfdea662014-07-23 14:16:32 -04005274 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005275
Geoff Langbfdea662014-07-23 14:16:32 -04005276 if (context)
5277 {
5278 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005279 {
Geoff Langbfdea662014-07-23 14:16:32 -04005280 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005281 }
Geoff Langbfdea662014-07-23 14:16:32 -04005282
5283 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005284 }
5285
5286 return GL_FALSE;
5287}
5288
5289void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5290{
5291 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
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);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005300 }
Geoff Langbfdea662014-07-23 14:16:32 -04005301
5302 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005303 }
5304}
5305
5306void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5307{
Geoff Langbfdea662014-07-23 14:16:32 -04005308 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005309
Geoff Langbfdea662014-07-23 14:16:32 -04005310 if (context)
5311 {
5312 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005313 {
Geoff Langbfdea662014-07-23 14:16:32 -04005314 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005315 }
Geoff Langbfdea662014-07-23 14:16:32 -04005316
5317 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005318 }
5319}
5320
5321void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5322{
5323 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5324 location, count, transpose, value);
5325
Geoff Langbfdea662014-07-23 14:16:32 -04005326 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005327
Geoff Langbfdea662014-07-23 14:16:32 -04005328 if (context)
5329 {
5330 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005331 {
Geoff Langbfdea662014-07-23 14:16:32 -04005332 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005333 }
Geoff Langbfdea662014-07-23 14:16:32 -04005334
5335 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5336 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005337 }
5338}
5339
5340void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5341{
5342 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5343 location, count, transpose, value);
5344
Geoff Langbfdea662014-07-23 14:16:32 -04005345 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005346
Geoff Langbfdea662014-07-23 14:16:32 -04005347 if (context)
5348 {
5349 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005350 {
Geoff Langbfdea662014-07-23 14:16:32 -04005351 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005352 }
Geoff Langbfdea662014-07-23 14:16:32 -04005353
5354 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5355 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005356 }
5357}
5358
5359void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5360{
5361 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5362 location, count, transpose, value);
5363
Geoff Langbfdea662014-07-23 14:16:32 -04005364 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005365
Geoff Langbfdea662014-07-23 14:16:32 -04005366 if (context)
5367 {
5368 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005369 {
Geoff Langbfdea662014-07-23 14:16:32 -04005370 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005371 }
Geoff Langbfdea662014-07-23 14:16:32 -04005372
5373 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5374 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005375 }
5376}
5377
5378void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5379{
5380 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5381 location, count, transpose, value);
5382
Geoff Langbfdea662014-07-23 14:16:32 -04005383 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005384
Geoff Langbfdea662014-07-23 14:16:32 -04005385 if (context)
5386 {
5387 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005388 {
Geoff Langbfdea662014-07-23 14:16:32 -04005389 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005390 }
Geoff Langbfdea662014-07-23 14:16:32 -04005391
5392 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5393 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005394 }
5395}
5396
5397void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5398{
5399 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5400 location, count, transpose, value);
5401
Geoff Langbfdea662014-07-23 14:16:32 -04005402 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005403
Geoff Langbfdea662014-07-23 14:16:32 -04005404 if (context)
5405 {
5406 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005407 {
Geoff Langbfdea662014-07-23 14:16:32 -04005408 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005409 }
Geoff Langbfdea662014-07-23 14:16:32 -04005410
5411 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5412 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005413 }
5414}
5415
5416void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5417{
5418 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5419 location, count, transpose, value);
5420
Geoff Langbfdea662014-07-23 14:16:32 -04005421 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005422
Geoff Langbfdea662014-07-23 14:16:32 -04005423 if (context)
5424 {
5425 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005426 {
Geoff Langbfdea662014-07-23 14:16:32 -04005427 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005428 }
Geoff Langbfdea662014-07-23 14:16:32 -04005429
5430 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5431 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005432 }
5433}
5434
5435void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5436{
5437 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5438 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5439 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5440
Geoff Langbfdea662014-07-23 14:16:32 -04005441 gl::Context *context = gl::getNonLostContext();
5442 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005443 {
Geoff Langbfdea662014-07-23 14:16:32 -04005444 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005445 {
Geoff Langbfdea662014-07-23 14:16:32 -04005446 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005447 }
Geoff Langbfdea662014-07-23 14:16:32 -04005448
5449 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5450 dstX0, dstY0, dstX1, dstY1, mask, filter,
5451 false))
5452 {
5453 return;
5454 }
5455
5456 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5457 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005458 }
5459}
5460
5461void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5462{
5463 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5464 target, samples, internalformat, width, height);
5465
Geoff Langbfdea662014-07-23 14:16:32 -04005466 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005467
Geoff Langbfdea662014-07-23 14:16:32 -04005468 if (context)
5469 {
5470 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005471 {
Geoff Langbfdea662014-07-23 14:16:32 -04005472 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005473 }
Geoff Langbfdea662014-07-23 14:16:32 -04005474
5475 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5476 width, height, false))
5477 {
5478 return;
5479 }
5480
5481 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005482 }
5483}
5484
5485void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5486{
5487 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5488 target, attachment, texture, level, layer);
5489
Geoff Langbfdea662014-07-23 14:16:32 -04005490 gl::Context *context = gl::getNonLostContext();
5491
5492 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005493 {
Geoff Langbfdea662014-07-23 14:16:32 -04005494 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5495 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005496 {
Geoff Langbfdea662014-07-23 14:16:32 -04005497 return;
5498 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005499
Geoff Langbfdea662014-07-23 14:16:32 -04005500 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5501 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005502
Geoff Langbfdea662014-07-23 14:16:32 -04005503 gl::Texture *textureObject = context->getTexture(texture);
5504 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005505
Geoff Langbfdea662014-07-23 14:16:32 -04005506 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5507 {
5508 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5509 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5510 }
5511 else
5512 {
5513 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005514 {
Geoff Langbfdea662014-07-23 14:16:32 -04005515 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5516 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5517 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005518 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005520 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005521}
5522
5523GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5524{
5525 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5526 target, offset, length, access);
5527
Geoff Langbfdea662014-07-23 14:16:32 -04005528 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005529
Geoff Langbfdea662014-07-23 14:16:32 -04005530 if (context)
5531 {
5532 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005533 {
Geoff Langbfdea662014-07-23 14:16:32 -04005534 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005535 }
Geoff Langbfdea662014-07-23 14:16:32 -04005536
5537 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005538 }
5539
5540 return NULL;
5541}
5542
5543void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5544{
5545 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5546
Geoff Langbfdea662014-07-23 14:16:32 -04005547 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005548
Geoff Langbfdea662014-07-23 14:16:32 -04005549 if (context)
5550 {
5551 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005552 {
Geoff Langbfdea662014-07-23 14:16:32 -04005553 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005554 }
Geoff Langbfdea662014-07-23 14:16:32 -04005555
5556 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005557 }
5558}
5559
5560void __stdcall glBindVertexArray(GLuint array)
5561{
5562 EVENT("(GLuint array = %u)", array);
5563
Geoff Langbfdea662014-07-23 14:16:32 -04005564 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005565
Geoff Langbfdea662014-07-23 14:16:32 -04005566 if (context)
5567 {
5568 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005569 {
Geoff Langbfdea662014-07-23 14:16:32 -04005570 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005571 }
Geoff Langbfdea662014-07-23 14:16:32 -04005572
5573 gl::VertexArray *vao = context->getVertexArray(array);
5574
5575 if (!vao)
5576 {
5577 // The default VAO should always exist
5578 ASSERT(array != 0);
5579 return gl::error(GL_INVALID_OPERATION);
5580 }
5581
5582 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005583 }
5584}
5585
5586void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5587{
5588 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5589
Geoff Langbfdea662014-07-23 14:16:32 -04005590 gl::Context *context = gl::getNonLostContext();
5591
5592 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005593 {
Geoff Langbfdea662014-07-23 14:16:32 -04005594 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005595 {
Geoff Langbfdea662014-07-23 14:16:32 -04005596 return gl::error(GL_INVALID_OPERATION);
5597 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005598
Geoff Langbfdea662014-07-23 14:16:32 -04005599 if (n < 0)
5600 {
5601 return gl::error(GL_INVALID_VALUE);
5602 }
Jamie Madilld1028542013-07-02 11:57:04 -04005603
Geoff Langbfdea662014-07-23 14:16:32 -04005604 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5605 {
5606 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005607 {
Geoff Langbfdea662014-07-23 14:16:32 -04005608 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005609 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005610 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005611 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005612}
5613
5614void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5615{
5616 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5617
Geoff Langbfdea662014-07-23 14:16:32 -04005618 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005619
Geoff Langbfdea662014-07-23 14:16:32 -04005620 if (context)
5621 {
5622 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005623 {
Geoff Langbfdea662014-07-23 14:16:32 -04005624 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005625 }
Geoff Langbfdea662014-07-23 14:16:32 -04005626
5627 if (n < 0)
5628 {
5629 return gl::error(GL_INVALID_VALUE);
5630 }
5631
5632 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5633 {
5634 arrays[arrayIndex] = context->createVertexArray();
5635 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005636 }
5637}
5638
5639GLboolean __stdcall glIsVertexArray(GLuint array)
5640{
5641 EVENT("(GLuint array = %u)", array);
5642
Geoff Langbfdea662014-07-23 14:16:32 -04005643 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005644
Geoff Langbfdea662014-07-23 14:16:32 -04005645 if (context)
5646 {
5647 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005648 {
Geoff Langbfdea662014-07-23 14:16:32 -04005649 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005650 }
Geoff Langbfdea662014-07-23 14:16:32 -04005651
5652 if (array == 0)
5653 {
5654 return GL_FALSE;
5655 }
5656
5657 gl::VertexArray *vao = context->getVertexArray(array);
5658
5659 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005660 }
5661
5662 return GL_FALSE;
5663}
5664
5665void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5666{
5667 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5668 target, index, data);
5669
Geoff Langbfdea662014-07-23 14:16:32 -04005670 gl::Context *context = gl::getNonLostContext();
5671
5672 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005673 {
Geoff Langbfdea662014-07-23 14:16:32 -04005674 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005675 {
Geoff Langbfdea662014-07-23 14:16:32 -04005676 return gl::error(GL_INVALID_OPERATION);
5677 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005678
Geoff Langbfdea662014-07-23 14:16:32 -04005679 switch (target)
5680 {
5681 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5682 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5683 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
5684 if (index >= context->getMaxTransformFeedbackBufferBindings())
5685 return gl::error(GL_INVALID_VALUE);
5686 break;
5687 case GL_UNIFORM_BUFFER_START:
5688 case GL_UNIFORM_BUFFER_SIZE:
5689 case GL_UNIFORM_BUFFER_BINDING:
5690 if (index >= context->getMaximumCombinedUniformBufferBindings())
5691 return gl::error(GL_INVALID_VALUE);
5692 break;
5693 default:
5694 return gl::error(GL_INVALID_ENUM);
5695 }
5696
5697 if (!(context->getIndexedIntegerv(target, index, data)))
5698 {
5699 GLenum nativeType;
5700 unsigned int numParams = 0;
5701 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04005702 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04005703
Geoff Langbfdea662014-07-23 14:16:32 -04005704 if (numParams == 0)
5705 return; // it is known that pname is valid, but there are no parameters to return
5706
5707 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005708 {
Geoff Langbfdea662014-07-23 14:16:32 -04005709 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5710 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5711 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005712
Geoff Langbfdea662014-07-23 14:16:32 -04005713 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005714
Geoff Langbfdea662014-07-23 14:16:32 -04005715 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005716 {
Geoff Langbfdea662014-07-23 14:16:32 -04005717 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5718 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005719 }
Geoff Langbfdea662014-07-23 14:16:32 -04005720
5721 delete [] int64Params;
5722 }
5723 else
5724 {
5725 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005726 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005727 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005728 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005729}
5730
5731void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5732{
5733 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5734
Geoff Langbfdea662014-07-23 14:16:32 -04005735 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005736
Geoff Langbfdea662014-07-23 14:16:32 -04005737 if (context)
5738 {
5739 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005740 {
Geoff Langbfdea662014-07-23 14:16:32 -04005741 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005742 }
Geoff Langbfdea662014-07-23 14:16:32 -04005743
5744 switch (primitiveMode)
5745 {
5746 case GL_TRIANGLES:
5747 case GL_LINES:
5748 case GL_POINTS:
5749 break;
5750 default:
5751 return gl::error(GL_INVALID_ENUM);
5752 }
5753
5754 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5755 ASSERT(transformFeedback != NULL);
5756
5757 if (transformFeedback->isStarted())
5758 {
5759 return gl::error(GL_INVALID_OPERATION);
5760 }
5761
5762 if (transformFeedback->isPaused())
5763 {
5764 transformFeedback->resume();
5765 }
5766 else
5767 {
5768 transformFeedback->start(primitiveMode);
5769 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005770 }
5771}
5772
5773void __stdcall glEndTransformFeedback(void)
5774{
5775 EVENT("(void)");
5776
Geoff Langbfdea662014-07-23 14:16:32 -04005777 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005778
Geoff Langbfdea662014-07-23 14:16:32 -04005779 if (context)
5780 {
5781 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005782 {
Geoff Langbfdea662014-07-23 14:16:32 -04005783 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005784 }
Geoff Langbfdea662014-07-23 14:16:32 -04005785
5786 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5787 ASSERT(transformFeedback != NULL);
5788
5789 if (!transformFeedback->isStarted())
5790 {
5791 return gl::error(GL_INVALID_OPERATION);
5792 }
5793
5794 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005795 }
5796}
5797
5798void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5799{
5800 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5801 target, index, buffer, offset, size);
5802
Geoff Langbfdea662014-07-23 14:16:32 -04005803 gl::Context *context = gl::getNonLostContext();
5804
5805 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005806 {
Geoff Langbfdea662014-07-23 14:16:32 -04005807 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005808 {
Geoff Langbfdea662014-07-23 14:16:32 -04005809 return gl::error(GL_INVALID_OPERATION);
5810 }
5811
5812 switch (target)
5813 {
5814 case GL_TRANSFORM_FEEDBACK_BUFFER:
5815 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005816 {
Geoff Langbfdea662014-07-23 14:16:32 -04005817 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005818 }
Geoff Langbfdea662014-07-23 14:16:32 -04005819 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005820
Geoff Langbfdea662014-07-23 14:16:32 -04005821 case GL_UNIFORM_BUFFER:
5822 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005823 {
Geoff Langbfdea662014-07-23 14:16:32 -04005824 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005825 }
Geoff Langbfdea662014-07-23 14:16:32 -04005826 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005827
Geoff Langbfdea662014-07-23 14:16:32 -04005828 default:
5829 return gl::error(GL_INVALID_ENUM);
5830 }
5831
5832 if (buffer != 0 && size <= 0)
5833 {
5834 return gl::error(GL_INVALID_VALUE);
5835 }
5836
5837 switch (target)
5838 {
5839 case GL_TRANSFORM_FEEDBACK_BUFFER:
5840
5841 // size and offset must be a multiple of 4
5842 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005843 {
5844 return gl::error(GL_INVALID_VALUE);
5845 }
5846
Geoff Langbfdea662014-07-23 14:16:32 -04005847 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5848 context->bindGenericTransformFeedbackBuffer(buffer);
5849 break;
5850
5851 case GL_UNIFORM_BUFFER:
5852
5853 // it is an error to bind an offset not a multiple of the alignment
5854 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005855 {
Geoff Langbfdea662014-07-23 14:16:32 -04005856 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005857 }
Geoff Langbfdea662014-07-23 14:16:32 -04005858
5859 context->bindIndexedUniformBuffer(buffer, index, offset, size);
5860 context->bindGenericUniformBuffer(buffer);
5861 break;
5862
5863 default:
5864 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005865 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005866 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005867}
5868
5869void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
5870{
5871 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
5872 target, index, buffer);
5873
Geoff Langbfdea662014-07-23 14:16:32 -04005874 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005875
Geoff Langbfdea662014-07-23 14:16:32 -04005876 if (context)
5877 {
5878 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005879 {
Geoff Langbfdea662014-07-23 14:16:32 -04005880 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005881 }
Geoff Langbfdea662014-07-23 14:16:32 -04005882
5883 switch (target)
5884 {
5885 case GL_TRANSFORM_FEEDBACK_BUFFER:
5886 if (index >= context->getMaxTransformFeedbackBufferBindings())
5887 {
5888 return gl::error(GL_INVALID_VALUE);
5889 }
5890 break;
5891
5892 case GL_UNIFORM_BUFFER:
5893 if (index >= context->getMaximumCombinedUniformBufferBindings())
5894 {
5895 return gl::error(GL_INVALID_VALUE);
5896 }
5897 break;
5898
5899 default:
5900 return gl::error(GL_INVALID_ENUM);
5901 }
5902
5903 switch (target)
5904 {
5905 case GL_TRANSFORM_FEEDBACK_BUFFER:
5906 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
5907 context->bindGenericTransformFeedbackBuffer(buffer);
5908 break;
5909
5910 case GL_UNIFORM_BUFFER:
5911 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
5912 context->bindGenericUniformBuffer(buffer);
5913 break;
5914
5915 default:
5916 UNREACHABLE();
5917 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005918 }
5919}
5920
5921void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
5922{
5923 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
5924 program, count, varyings, bufferMode);
5925
Geoff Langbfdea662014-07-23 14:16:32 -04005926 gl::Context *context = gl::getNonLostContext();
5927
5928 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005929 {
Geoff Langbfdea662014-07-23 14:16:32 -04005930 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005931 {
Geoff Langbfdea662014-07-23 14:16:32 -04005932 return gl::error(GL_INVALID_OPERATION);
5933 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005934
Geoff Langbfdea662014-07-23 14:16:32 -04005935 if (count < 0)
5936 {
5937 return gl::error(GL_INVALID_VALUE);
5938 }
5939
5940 switch (bufferMode)
5941 {
5942 case GL_INTERLEAVED_ATTRIBS:
5943 break;
5944 case GL_SEPARATE_ATTRIBS:
5945 if (static_cast<GLuint>(count) > context->getMaxTransformFeedbackBufferBindings())
Geoff Lang48dcae72014-02-05 16:28:24 -05005946 {
5947 return gl::error(GL_INVALID_VALUE);
5948 }
Geoff Langbfdea662014-07-23 14:16:32 -04005949 break;
5950 default:
5951 return gl::error(GL_INVALID_ENUM);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005952 }
Geoff Langbfdea662014-07-23 14:16:32 -04005953
5954 if (!gl::ValidProgram(context, program))
5955 {
5956 return;
5957 }
5958
5959 gl::Program *programObject = context->getProgram(program);
5960 ASSERT(programObject);
5961
5962 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005963 }
5964}
5965
5966void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
5967{
5968 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
5969 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
5970 program, index, bufSize, length, size, type, name);
5971
Geoff Langbfdea662014-07-23 14:16:32 -04005972 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005973
Geoff Langbfdea662014-07-23 14:16:32 -04005974 if (context)
5975 {
5976 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005977 {
Geoff Langbfdea662014-07-23 14:16:32 -04005978 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005979 }
Geoff Langbfdea662014-07-23 14:16:32 -04005980
5981 if (bufSize < 0)
5982 {
5983 return gl::error(GL_INVALID_VALUE);
5984 }
5985
5986 if (!gl::ValidProgram(context, program))
5987 {
5988 return;
5989 }
5990
5991 gl::Program *programObject = context->getProgram(program);
5992 ASSERT(programObject);
5993
5994 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
5995 {
5996 return gl::error(GL_INVALID_VALUE);
5997 }
5998
5999 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006000 }
6001}
6002
6003void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6004{
6005 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6006 index, size, type, stride, pointer);
6007
Geoff Langbfdea662014-07-23 14:16:32 -04006008 gl::Context *context = gl::getNonLostContext();
6009
6010 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006011 {
Geoff Langbfdea662014-07-23 14:16:32 -04006012 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006013 {
Geoff Langbfdea662014-07-23 14:16:32 -04006014 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006015 }
Geoff Langbfdea662014-07-23 14:16:32 -04006016 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006017
Geoff Langbfdea662014-07-23 14:16:32 -04006018 if (index >= gl::MAX_VERTEX_ATTRIBS)
6019 {
6020 return gl::error(GL_INVALID_VALUE);
6021 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006022
Geoff Langbfdea662014-07-23 14:16:32 -04006023 if (size < 1 || size > 4)
6024 {
6025 return gl::error(GL_INVALID_VALUE);
6026 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006027
Geoff Langbfdea662014-07-23 14:16:32 -04006028 switch (type)
6029 {
6030 case GL_BYTE:
6031 case GL_UNSIGNED_BYTE:
6032 case GL_SHORT:
6033 case GL_UNSIGNED_SHORT:
6034 case GL_INT:
6035 case GL_UNSIGNED_INT:
6036 case GL_INT_2_10_10_10_REV:
6037 case GL_UNSIGNED_INT_2_10_10_10_REV:
6038 break;
6039 default:
6040 return gl::error(GL_INVALID_ENUM);
6041 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006042
Geoff Langbfdea662014-07-23 14:16:32 -04006043 if (stride < 0)
6044 {
6045 return gl::error(GL_INVALID_VALUE);
6046 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006047
Geoff Langbfdea662014-07-23 14:16:32 -04006048 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6049 {
6050 return gl::error(GL_INVALID_OPERATION);
6051 }
6052
6053 if (context)
6054 {
6055 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6056 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6057 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6058 // and the pointer argument is not NULL.
6059 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006060 {
6061 return gl::error(GL_INVALID_OPERATION);
6062 }
6063
Geoff Langbfdea662014-07-23 14:16:32 -04006064 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6065 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006066 }
6067}
6068
6069void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6070{
6071 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6072 index, pname, params);
6073
Geoff Langbfdea662014-07-23 14:16:32 -04006074 gl::Context *context = gl::getNonLostContext();
6075
6076 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006077 {
Geoff Langbfdea662014-07-23 14:16:32 -04006078 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006079 {
Geoff Langbfdea662014-07-23 14:16:32 -04006080 return gl::error(GL_INVALID_OPERATION);
6081 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006082
Geoff Langbfdea662014-07-23 14:16:32 -04006083 if (index >= gl::MAX_VERTEX_ATTRIBS)
6084 {
6085 return gl::error(GL_INVALID_VALUE);
6086 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006087
Geoff Langbfdea662014-07-23 14:16:32 -04006088 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006089
Geoff Langbfdea662014-07-23 14:16:32 -04006090 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6091 {
6092 return;
6093 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006094
Geoff Langbfdea662014-07-23 14:16:32 -04006095 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6096 {
6097 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6098 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006099 {
Geoff Langbfdea662014-07-23 14:16:32 -04006100 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006101 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006102 }
Geoff Langbfdea662014-07-23 14:16:32 -04006103 else
6104 {
6105 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006107 }
6108}
6109
6110void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6111{
6112 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6113 index, pname, params);
6114
Geoff Langbfdea662014-07-23 14:16:32 -04006115 gl::Context *context = gl::getNonLostContext();
6116
6117 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006118 {
Geoff Langbfdea662014-07-23 14:16:32 -04006119 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006120 {
Geoff Langbfdea662014-07-23 14:16:32 -04006121 return gl::error(GL_INVALID_OPERATION);
6122 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006123
Geoff Langbfdea662014-07-23 14:16:32 -04006124 if (index >= gl::MAX_VERTEX_ATTRIBS)
6125 {
6126 return gl::error(GL_INVALID_VALUE);
6127 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006128
Geoff Langbfdea662014-07-23 14:16:32 -04006129 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006130
Geoff Langbfdea662014-07-23 14:16:32 -04006131 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6132 {
6133 return;
6134 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006135
Geoff Langbfdea662014-07-23 14:16:32 -04006136 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6137 {
6138 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6139 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006140 {
Geoff Langbfdea662014-07-23 14:16:32 -04006141 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006142 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006143 }
Geoff Langbfdea662014-07-23 14:16:32 -04006144 else
6145 {
6146 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6147 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006148 }
6149}
6150
6151void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6152{
6153 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6154 index, x, y, z, w);
6155
Geoff Langbfdea662014-07-23 14:16:32 -04006156 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006157
Geoff Langbfdea662014-07-23 14:16:32 -04006158 if (context)
6159 {
6160 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006161 {
Geoff Langbfdea662014-07-23 14:16:32 -04006162 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006163 }
Geoff Langbfdea662014-07-23 14:16:32 -04006164
6165 if (index >= gl::MAX_VERTEX_ATTRIBS)
6166 {
6167 return gl::error(GL_INVALID_VALUE);
6168 }
6169
6170 GLint vals[4] = { x, y, z, w };
6171 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006172 }
6173}
6174
6175void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6176{
6177 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6178 index, x, y, z, w);
6179
Geoff Langbfdea662014-07-23 14:16:32 -04006180 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006181
Geoff Langbfdea662014-07-23 14:16:32 -04006182 if (context)
6183 {
6184 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006185 {
Geoff Langbfdea662014-07-23 14:16:32 -04006186 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006187 }
Geoff Langbfdea662014-07-23 14:16:32 -04006188
6189 if (index >= gl::MAX_VERTEX_ATTRIBS)
6190 {
6191 return gl::error(GL_INVALID_VALUE);
6192 }
6193
6194 GLuint vals[4] = { x, y, z, w };
6195 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006196 }
6197}
6198
6199void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6200{
6201 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6202
Geoff Langbfdea662014-07-23 14:16:32 -04006203 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006204
Geoff Langbfdea662014-07-23 14:16:32 -04006205 if (context)
6206 {
6207 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006208 {
Geoff Langbfdea662014-07-23 14:16:32 -04006209 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006210 }
Geoff Langbfdea662014-07-23 14:16:32 -04006211
6212 if (index >= gl::MAX_VERTEX_ATTRIBS)
6213 {
6214 return gl::error(GL_INVALID_VALUE);
6215 }
6216
6217 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006218 }
6219}
6220
6221void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6222{
6223 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6224
Geoff Langbfdea662014-07-23 14:16:32 -04006225 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006226
Geoff Langbfdea662014-07-23 14:16:32 -04006227 if (context)
6228 {
6229 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006230 {
Geoff Langbfdea662014-07-23 14:16:32 -04006231 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006232 }
Geoff Langbfdea662014-07-23 14:16:32 -04006233
6234 if (index >= gl::MAX_VERTEX_ATTRIBS)
6235 {
6236 return gl::error(GL_INVALID_VALUE);
6237 }
6238
6239 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006240 }
6241}
6242
6243void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6244{
6245 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6246 program, location, params);
6247
Geoff Langbfdea662014-07-23 14:16:32 -04006248 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006249
Geoff Langbfdea662014-07-23 14:16:32 -04006250 if (context)
6251 {
6252 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006253 {
Geoff Langbfdea662014-07-23 14:16:32 -04006254 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006255 }
Geoff Langbfdea662014-07-23 14:16:32 -04006256
6257 if (program == 0)
6258 {
6259 return gl::error(GL_INVALID_VALUE);
6260 }
6261
6262 gl::Program *programObject = context->getProgram(program);
6263
6264 if (!programObject || !programObject->isLinked())
6265 {
6266 return gl::error(GL_INVALID_OPERATION);
6267 }
6268
6269 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6270 if (!programBinary)
6271 {
6272 return gl::error(GL_INVALID_OPERATION);
6273 }
6274
6275 if (!programBinary->getUniformuiv(location, NULL, params))
6276 {
6277 return gl::error(GL_INVALID_OPERATION);
6278 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006279 }
6280}
6281
6282GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6283{
6284 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6285 program, name);
6286
Geoff Langbfdea662014-07-23 14:16:32 -04006287 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006288
Geoff Langbfdea662014-07-23 14:16:32 -04006289 if (context)
6290 {
6291 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006292 {
Geoff Langbfdea662014-07-23 14:16:32 -04006293 return gl::error(GL_INVALID_OPERATION, -1);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006294 }
Geoff Langbfdea662014-07-23 14:16:32 -04006295
6296 if (program == 0)
6297 {
6298 return gl::error(GL_INVALID_VALUE, -1);
6299 }
6300
6301 gl::Program *programObject = context->getProgram(program);
6302
6303 if (!programObject || !programObject->isLinked())
6304 {
6305 return gl::error(GL_INVALID_OPERATION, -1);
6306 }
6307
6308 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6309 if (!programBinary)
6310 {
6311 return gl::error(GL_INVALID_OPERATION, -1);
6312 }
6313
6314 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006315 }
6316
6317 return 0;
6318}
6319
6320void __stdcall glUniform1ui(GLint location, GLuint v0)
6321{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006322 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006323}
6324
6325void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6326{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006327 const GLuint xy[] = { v0, v1 };
6328 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006329}
6330
6331void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6332{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006333 const GLuint xyz[] = { v0, v1, v2 };
6334 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006335}
6336
6337void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6338{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006339 const GLuint xyzw[] = { v0, v1, v2, v3 };
6340 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006341}
6342
6343void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6344{
6345 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6346 location, count, value);
6347
Geoff Langbfdea662014-07-23 14:16:32 -04006348 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006349
Geoff Langbfdea662014-07-23 14:16:32 -04006350 if (context)
6351 {
6352 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006353 {
Geoff Langbfdea662014-07-23 14:16:32 -04006354 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006355 }
Geoff Langbfdea662014-07-23 14:16:32 -04006356
6357 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6358 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006359 }
6360}
6361
6362void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6363{
6364 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6365 location, count, value);
6366
Geoff Langbfdea662014-07-23 14:16:32 -04006367 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006368
Geoff Langbfdea662014-07-23 14:16:32 -04006369 if (context)
6370 {
6371 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006372 {
Geoff Langbfdea662014-07-23 14:16:32 -04006373 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006374 }
Geoff Langbfdea662014-07-23 14:16:32 -04006375
6376 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6377 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006378 }
6379}
6380
6381void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6382{
6383 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6384 location, count, value);
6385
Geoff Langbfdea662014-07-23 14:16:32 -04006386 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006387
Geoff Langbfdea662014-07-23 14:16:32 -04006388 if (context)
6389 {
6390 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006391 {
Geoff Langbfdea662014-07-23 14:16:32 -04006392 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006393 }
Geoff Langbfdea662014-07-23 14:16:32 -04006394
6395 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6396 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006397 }
6398}
6399
6400void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6401{
6402 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6403 location, count, value);
6404
Geoff Langbfdea662014-07-23 14:16:32 -04006405 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006406
Geoff Langbfdea662014-07-23 14:16:32 -04006407 if (context)
6408 {
6409 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006410 {
Geoff Langbfdea662014-07-23 14:16:32 -04006411 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006412 }
Geoff Langbfdea662014-07-23 14:16:32 -04006413
6414 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6415 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006416 }
6417}
6418
6419void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6420{
6421 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6422 buffer, drawbuffer, value);
6423
Geoff Langbfdea662014-07-23 14:16:32 -04006424 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006425
Geoff Langbfdea662014-07-23 14:16:32 -04006426 if (context)
6427 {
6428 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006429 {
Geoff Langbfdea662014-07-23 14:16:32 -04006430 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006431 }
Geoff Langbfdea662014-07-23 14:16:32 -04006432
6433 switch (buffer)
6434 {
6435 case GL_COLOR:
6436 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6437 {
6438 return gl::error(GL_INVALID_VALUE);
6439 }
6440 break;
6441 case GL_STENCIL:
6442 if (drawbuffer != 0)
6443 {
6444 return gl::error(GL_INVALID_VALUE);
6445 }
6446 break;
6447 default:
6448 return gl::error(GL_INVALID_ENUM);
6449 }
6450
6451 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006452 }
6453}
6454
6455void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6456{
6457 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6458 buffer, drawbuffer, value);
6459
Geoff Langbfdea662014-07-23 14:16:32 -04006460 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006461
Geoff Langbfdea662014-07-23 14:16:32 -04006462 if (context)
6463 {
6464 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006465 {
Geoff Langbfdea662014-07-23 14:16:32 -04006466 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006467 }
Geoff Langbfdea662014-07-23 14:16:32 -04006468
6469 switch (buffer)
6470 {
6471 case GL_COLOR:
6472 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6473 {
6474 return gl::error(GL_INVALID_VALUE);
6475 }
6476 break;
6477 default:
6478 return gl::error(GL_INVALID_ENUM);
6479 }
6480
6481 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006482 }
6483}
6484
6485void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6486{
6487 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6488 buffer, drawbuffer, value);
6489
Geoff Langbfdea662014-07-23 14:16:32 -04006490 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006491
Geoff Langbfdea662014-07-23 14:16:32 -04006492 if (context)
6493 {
6494 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006495 {
Geoff Langbfdea662014-07-23 14:16:32 -04006496 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006497 }
Geoff Langbfdea662014-07-23 14:16:32 -04006498
6499 switch (buffer)
6500 {
6501 case GL_COLOR:
6502 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6503 {
6504 return gl::error(GL_INVALID_VALUE);
6505 }
6506 break;
6507 case GL_DEPTH:
6508 if (drawbuffer != 0)
6509 {
6510 return gl::error(GL_INVALID_VALUE);
6511 }
6512 break;
6513 default:
6514 return gl::error(GL_INVALID_ENUM);
6515 }
6516
6517 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006518 }
6519}
6520
6521void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6522{
6523 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6524 buffer, drawbuffer, depth, stencil);
6525
Geoff Langbfdea662014-07-23 14:16:32 -04006526 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006527
Geoff Langbfdea662014-07-23 14:16:32 -04006528 if (context)
6529 {
6530 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006531 {
Geoff Langbfdea662014-07-23 14:16:32 -04006532 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006533 }
Geoff Langbfdea662014-07-23 14:16:32 -04006534
6535 switch (buffer)
6536 {
6537 case GL_DEPTH_STENCIL:
6538 if (drawbuffer != 0)
6539 {
6540 return gl::error(GL_INVALID_VALUE);
6541 }
6542 break;
6543 default:
6544 return gl::error(GL_INVALID_ENUM);
6545 }
6546
6547 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006548 }
6549}
6550
6551const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6552{
6553 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6554
Geoff Langbfdea662014-07-23 14:16:32 -04006555 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006556
Geoff Langbfdea662014-07-23 14:16:32 -04006557 if (context)
6558 {
6559 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006560 {
Geoff Langbfdea662014-07-23 14:16:32 -04006561 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006562 }
Geoff Langbfdea662014-07-23 14:16:32 -04006563
6564 if (name != GL_EXTENSIONS)
6565 {
6566 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
6567 }
6568
6569 if (index >= context->getExtensionStringCount())
6570 {
6571 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
6572 }
6573
6574 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006575 }
6576
6577 return NULL;
6578}
6579
6580void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6581{
6582 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6583 readTarget, writeTarget, readOffset, writeOffset, size);
6584
Geoff Langbfdea662014-07-23 14:16:32 -04006585 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006586
Geoff Langbfdea662014-07-23 14:16:32 -04006587 if (context)
6588 {
6589 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006590 {
Geoff Langbfdea662014-07-23 14:16:32 -04006591 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006592 }
Geoff Langbfdea662014-07-23 14:16:32 -04006593
6594 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6595 {
6596 return gl::error(GL_INVALID_ENUM);
6597 }
6598
6599 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6600 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6601
6602 if (!readBuffer || !writeBuffer)
6603 {
6604 return gl::error(GL_INVALID_OPERATION);
6605 }
6606
Jamie Madillcfaaf722014-07-31 10:47:54 -04006607 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006608 if (readBuffer->isMapped() || writeBuffer->isMapped())
6609 {
6610 return gl::error(GL_INVALID_OPERATION);
6611 }
6612
6613 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6614 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6615 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6616 {
6617 return gl::error(GL_INVALID_VALUE);
6618 }
6619
6620 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6621 {
6622 return gl::error(GL_INVALID_VALUE);
6623 }
6624
Geoff Langbfdea662014-07-23 14:16:32 -04006625 // if size is zero, the copy is a successful no-op
6626 if (size > 0)
6627 {
6628 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6629 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006630 }
6631}
6632
6633void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6634{
6635 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6636 program, uniformCount, uniformNames, uniformIndices);
6637
Geoff Langbfdea662014-07-23 14:16:32 -04006638 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006639
Geoff Langbfdea662014-07-23 14:16:32 -04006640 if (context)
6641 {
6642 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006643 {
Geoff Langbfdea662014-07-23 14:16:32 -04006644 return gl::error(GL_INVALID_OPERATION);
6645 }
6646
6647 if (uniformCount < 0)
6648 {
6649 return gl::error(GL_INVALID_VALUE);
6650 }
6651
6652 gl::Program *programObject = context->getProgram(program);
6653
6654 if (!programObject)
6655 {
6656 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006657 {
6658 return gl::error(GL_INVALID_OPERATION);
6659 }
Geoff Langbfdea662014-07-23 14:16:32 -04006660 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006661 {
6662 return gl::error(GL_INVALID_VALUE);
6663 }
Geoff Langbfdea662014-07-23 14:16:32 -04006664 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006665
Geoff Langbfdea662014-07-23 14:16:32 -04006666 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6667 if (!programObject->isLinked() || !programBinary)
6668 {
6669 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006670 {
Geoff Langbfdea662014-07-23 14:16:32 -04006671 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006672 }
6673 }
Geoff Langbfdea662014-07-23 14:16:32 -04006674 else
6675 {
6676 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6677 {
6678 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6679 }
6680 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006681 }
6682}
6683
6684void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6685{
6686 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6687 program, uniformCount, uniformIndices, pname, params);
6688
Geoff Langbfdea662014-07-23 14:16:32 -04006689 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006690
Geoff Langbfdea662014-07-23 14:16:32 -04006691 if (context)
6692 {
6693 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006694 {
Geoff Langbfdea662014-07-23 14:16:32 -04006695 return gl::error(GL_INVALID_OPERATION);
6696 }
6697
6698 if (uniformCount < 0)
6699 {
6700 return gl::error(GL_INVALID_VALUE);
6701 }
6702
6703 gl::Program *programObject = context->getProgram(program);
6704
6705 if (!programObject)
6706 {
6707 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006708 {
6709 return gl::error(GL_INVALID_OPERATION);
6710 }
Geoff Langbfdea662014-07-23 14:16:32 -04006711 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006712 {
6713 return gl::error(GL_INVALID_VALUE);
6714 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006715 }
Geoff Langbfdea662014-07-23 14:16:32 -04006716
6717 switch (pname)
6718 {
6719 case GL_UNIFORM_TYPE:
6720 case GL_UNIFORM_SIZE:
6721 case GL_UNIFORM_NAME_LENGTH:
6722 case GL_UNIFORM_BLOCK_INDEX:
6723 case GL_UNIFORM_OFFSET:
6724 case GL_UNIFORM_ARRAY_STRIDE:
6725 case GL_UNIFORM_MATRIX_STRIDE:
6726 case GL_UNIFORM_IS_ROW_MAJOR:
6727 break;
6728 default:
6729 return gl::error(GL_INVALID_ENUM);
6730 }
6731
6732 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6733
6734 if (!programBinary && uniformCount > 0)
6735 {
6736 return gl::error(GL_INVALID_VALUE);
6737 }
6738
6739 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6740 {
6741 const GLuint index = uniformIndices[uniformId];
6742
6743 if (index >= (GLuint)programBinary->getActiveUniformCount())
6744 {
6745 return gl::error(GL_INVALID_VALUE);
6746 }
6747 }
6748
6749 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6750 {
6751 const GLuint index = uniformIndices[uniformId];
6752 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6753 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006754 }
6755}
6756
6757GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6758{
6759 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6760
Geoff Langbfdea662014-07-23 14:16:32 -04006761 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006762
Geoff Langbfdea662014-07-23 14:16:32 -04006763 if (context)
6764 {
6765 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006766 {
Geoff Langbfdea662014-07-23 14:16:32 -04006767 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
6768 }
6769
6770 gl::Program *programObject = context->getProgram(program);
6771
6772 if (!programObject)
6773 {
6774 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006775 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006776 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006777 }
Geoff Langbfdea662014-07-23 14:16:32 -04006778 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006779 {
Geoff Langbfdea662014-07-23 14:16:32 -04006780 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006781 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006782 }
Geoff Langbfdea662014-07-23 14:16:32 -04006783
6784 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6785 if (!programBinary)
6786 {
6787 return GL_INVALID_INDEX;
6788 }
6789
6790 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006791 }
6792
6793 return 0;
6794}
6795
6796void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6797{
6798 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6799 program, uniformBlockIndex, pname, params);
6800
Geoff Langbfdea662014-07-23 14:16:32 -04006801 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006802
Geoff Langbfdea662014-07-23 14:16:32 -04006803 if (context)
6804 {
6805 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006806 {
Geoff Langbfdea662014-07-23 14:16:32 -04006807 return gl::error(GL_INVALID_OPERATION);
6808 }
6809 gl::Program *programObject = context->getProgram(program);
6810
6811 if (!programObject)
6812 {
6813 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006814 {
6815 return gl::error(GL_INVALID_OPERATION);
6816 }
Geoff Langbfdea662014-07-23 14:16:32 -04006817 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006818 {
6819 return gl::error(GL_INVALID_VALUE);
6820 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006821 }
Geoff Langbfdea662014-07-23 14:16:32 -04006822
6823 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6824
6825 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6826 {
6827 return gl::error(GL_INVALID_VALUE);
6828 }
6829
6830 switch (pname)
6831 {
6832 case GL_UNIFORM_BLOCK_BINDING:
6833 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
6834 break;
6835
6836 case GL_UNIFORM_BLOCK_DATA_SIZE:
6837 case GL_UNIFORM_BLOCK_NAME_LENGTH:
6838 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
6839 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
6840 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
6841 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
6842 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
6843 break;
6844
6845 default:
6846 return gl::error(GL_INVALID_ENUM);
6847 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006848 }
6849}
6850
6851void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
6852{
6853 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
6854 program, uniformBlockIndex, bufSize, length, uniformBlockName);
6855
Geoff Langbfdea662014-07-23 14:16:32 -04006856 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006857
Geoff Langbfdea662014-07-23 14:16:32 -04006858 if (context)
6859 {
6860 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006861 {
Geoff Langbfdea662014-07-23 14:16:32 -04006862 return gl::error(GL_INVALID_OPERATION);
6863 }
6864
6865 gl::Program *programObject = context->getProgram(program);
6866
6867 if (!programObject)
6868 {
6869 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006870 {
6871 return gl::error(GL_INVALID_OPERATION);
6872 }
Geoff Langbfdea662014-07-23 14:16:32 -04006873 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006874 {
6875 return gl::error(GL_INVALID_VALUE);
6876 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006877 }
Geoff Langbfdea662014-07-23 14:16:32 -04006878
6879 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6880
6881 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6882 {
6883 return gl::error(GL_INVALID_VALUE);
6884 }
6885
6886 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006887 }
6888}
6889
6890void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
6891{
6892 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
6893 program, uniformBlockIndex, uniformBlockBinding);
6894
Geoff Langbfdea662014-07-23 14:16:32 -04006895 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006896
Geoff Langbfdea662014-07-23 14:16:32 -04006897 if (context)
6898 {
6899 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006900 {
Geoff Langbfdea662014-07-23 14:16:32 -04006901 return gl::error(GL_INVALID_OPERATION);
6902 }
6903
6904 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
6905 {
6906 return gl::error(GL_INVALID_VALUE);
6907 }
6908
6909 gl::Program *programObject = context->getProgram(program);
6910
6911 if (!programObject)
6912 {
6913 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006914 {
6915 return gl::error(GL_INVALID_OPERATION);
6916 }
Geoff Langbfdea662014-07-23 14:16:32 -04006917 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006918 {
6919 return gl::error(GL_INVALID_VALUE);
6920 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006921 }
Geoff Langbfdea662014-07-23 14:16:32 -04006922
6923 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6924
6925 // if never linked, there won't be any uniform blocks
6926 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6927 {
6928 return gl::error(GL_INVALID_VALUE);
6929 }
6930
6931 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006932 }
6933}
6934
6935void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
6936{
6937 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
6938 mode, first, count, instanceCount);
6939
Geoff Langbfdea662014-07-23 14:16:32 -04006940 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006941
Geoff Langbfdea662014-07-23 14:16:32 -04006942 if (context)
6943 {
6944 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006945 {
Geoff Langbfdea662014-07-23 14:16:32 -04006946 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006947 }
Geoff Langbfdea662014-07-23 14:16:32 -04006948
6949 // glDrawArraysInstanced
6950 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006951 }
6952}
6953
6954void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
6955{
6956 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
6957 mode, count, type, indices, instanceCount);
6958
Geoff Langbfdea662014-07-23 14:16:32 -04006959 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006960
Geoff Langbfdea662014-07-23 14:16:32 -04006961 if (context)
6962 {
6963 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006964 {
Geoff Langbfdea662014-07-23 14:16:32 -04006965 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006966 }
Geoff Langbfdea662014-07-23 14:16:32 -04006967
6968 // glDrawElementsInstanced
6969 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006970 }
6971}
6972
6973GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
6974{
6975 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
6976
Geoff Langbfdea662014-07-23 14:16:32 -04006977 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006978
Geoff Langbfdea662014-07-23 14:16:32 -04006979 if (context)
6980 {
6981 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006982 {
Geoff Langbfdea662014-07-23 14:16:32 -04006983 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006984 }
Geoff Langbfdea662014-07-23 14:16:32 -04006985
6986 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
6987 {
6988 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
6989 }
6990
6991 if (flags != 0)
6992 {
6993 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
6994 }
6995
6996 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006997 }
6998
6999 return NULL;
7000}
7001
7002GLboolean __stdcall glIsSync(GLsync sync)
7003{
7004 EVENT("(GLsync sync = 0x%0.8p)", sync);
7005
Geoff Langbfdea662014-07-23 14:16:32 -04007006 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007007
Geoff Langbfdea662014-07-23 14:16:32 -04007008 if (context)
7009 {
7010 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007011 {
Geoff Langbfdea662014-07-23 14:16:32 -04007012 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007013 }
Geoff Langbfdea662014-07-23 14:16:32 -04007014
7015 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007016 }
7017
7018 return GL_FALSE;
7019}
7020
7021void __stdcall glDeleteSync(GLsync sync)
7022{
7023 EVENT("(GLsync sync = 0x%0.8p)", sync);
7024
Geoff Langbfdea662014-07-23 14:16:32 -04007025 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007026
Geoff Langbfdea662014-07-23 14:16:32 -04007027 if (context)
7028 {
7029 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007030 {
Geoff Langbfdea662014-07-23 14:16:32 -04007031 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007032 }
Geoff Langbfdea662014-07-23 14:16:32 -04007033
7034 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7035 {
7036 return gl::error(GL_INVALID_VALUE);
7037 }
7038
7039 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007040 }
7041}
7042
7043GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7044{
7045 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7046 sync, flags, timeout);
7047
Geoff Langbfdea662014-07-23 14:16:32 -04007048 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007049
Geoff Langbfdea662014-07-23 14:16:32 -04007050 if (context)
7051 {
7052 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007053 {
Geoff Langbfdea662014-07-23 14:16:32 -04007054 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007055 }
Geoff Langbfdea662014-07-23 14:16:32 -04007056
7057 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7058 {
7059 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7060 }
7061
7062 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7063
7064 if (!fenceSync)
7065 {
7066 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7067 }
7068
7069 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007070 }
7071
7072 return GL_FALSE;
7073}
7074
7075void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7076{
7077 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7078 sync, flags, timeout);
7079
Geoff Langbfdea662014-07-23 14:16:32 -04007080 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007081
Geoff Langbfdea662014-07-23 14:16:32 -04007082 if (context)
7083 {
7084 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007085 {
Geoff Langbfdea662014-07-23 14:16:32 -04007086 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007087 }
Geoff Langbfdea662014-07-23 14:16:32 -04007088
7089 if (flags != 0)
7090 {
7091 return gl::error(GL_INVALID_VALUE);
7092 }
7093
7094 if (timeout != GL_TIMEOUT_IGNORED)
7095 {
7096 return gl::error(GL_INVALID_VALUE);
7097 }
7098
7099 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7100
7101 if (!fenceSync)
7102 {
7103 return gl::error(GL_INVALID_VALUE);
7104 }
7105
7106 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007107 }
7108}
7109
7110void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7111{
7112 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7113 pname, params);
7114
Geoff Langbfdea662014-07-23 14:16:32 -04007115 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007116
Geoff Langbfdea662014-07-23 14:16:32 -04007117 if (context)
7118 {
7119 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007120 {
Geoff Langbfdea662014-07-23 14:16:32 -04007121 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007122 }
Geoff Langbfdea662014-07-23 14:16:32 -04007123
7124 GLenum nativeType;
7125 unsigned int numParams = 0;
7126 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7127 {
7128 return;
7129 }
7130
7131 if (nativeType == GL_INT_64_ANGLEX)
7132 {
7133 context->getInteger64v(pname, params);
7134 }
7135 else
7136 {
7137 CastStateValues(context, nativeType, pname, numParams, params);
7138 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007139 }
7140}
7141
7142void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7143{
7144 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7145 sync, pname, bufSize, length, values);
7146
Geoff Langbfdea662014-07-23 14:16:32 -04007147 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007148
Geoff Langbfdea662014-07-23 14:16:32 -04007149 if (context)
7150 {
7151 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007152 {
Geoff Langbfdea662014-07-23 14:16:32 -04007153 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007154 }
Geoff Langbfdea662014-07-23 14:16:32 -04007155
7156 if (bufSize < 0)
7157 {
7158 return gl::error(GL_INVALID_VALUE);
7159 }
7160
7161 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7162
7163 if (!fenceSync)
7164 {
7165 return gl::error(GL_INVALID_VALUE);
7166 }
7167
7168 switch (pname)
7169 {
7170 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7171 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7172 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7173 case GL_SYNC_FLAGS: values[0] = 0; break;
7174
7175 default:
7176 return gl::error(GL_INVALID_ENUM);
7177 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007178 }
7179}
7180
7181void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7182{
7183 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7184 target, index, data);
7185
Geoff Langbfdea662014-07-23 14:16:32 -04007186 gl::Context *context = gl::getNonLostContext();
7187
7188 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007189 {
Geoff Langbfdea662014-07-23 14:16:32 -04007190 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007191 {
Geoff Langbfdea662014-07-23 14:16:32 -04007192 return gl::error(GL_INVALID_OPERATION);
7193 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007194
Geoff Langbfdea662014-07-23 14:16:32 -04007195 switch (target)
7196 {
7197 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7198 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7199 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7200 if (index >= context->getMaxTransformFeedbackBufferBindings())
7201 return gl::error(GL_INVALID_VALUE);
7202 break;
7203 case GL_UNIFORM_BUFFER_START:
7204 case GL_UNIFORM_BUFFER_SIZE:
7205 case GL_UNIFORM_BUFFER_BINDING:
7206 if (index >= context->getMaximumCombinedUniformBufferBindings())
7207 return gl::error(GL_INVALID_VALUE);
7208 break;
7209 default:
7210 return gl::error(GL_INVALID_ENUM);
7211 }
7212
7213 if (!(context->getIndexedInteger64v(target, index, data)))
7214 {
7215 GLenum nativeType;
7216 unsigned int numParams = 0;
7217 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04007218 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04007219
Geoff Langbfdea662014-07-23 14:16:32 -04007220 if (numParams == 0)
7221 return; // it is known that pname is valid, but there are no parameters to return
7222
7223 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007224 {
Geoff Langbfdea662014-07-23 14:16:32 -04007225 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007226
Geoff Langbfdea662014-07-23 14:16:32 -04007227 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007228
Geoff Langbfdea662014-07-23 14:16:32 -04007229 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007230 {
Geoff Langbfdea662014-07-23 14:16:32 -04007231 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007232 }
Geoff Langbfdea662014-07-23 14:16:32 -04007233
7234 delete [] intParams;
7235 }
7236 else
7237 {
7238 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007239 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007240 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007241 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007242}
7243
7244void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7245{
7246 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7247 target, pname, params);
7248
Geoff Langbfdea662014-07-23 14:16:32 -04007249 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007250
Geoff Langbfdea662014-07-23 14:16:32 -04007251 if (context)
7252 {
7253 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007254 {
Geoff Langbfdea662014-07-23 14:16:32 -04007255 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007256 }
Geoff Langbfdea662014-07-23 14:16:32 -04007257
7258 if (!gl::ValidBufferTarget(context, target))
7259 {
7260 return gl::error(GL_INVALID_ENUM);
7261 }
7262
7263 if (!gl::ValidBufferParameter(context, pname))
7264 {
7265 return gl::error(GL_INVALID_ENUM);
7266 }
7267
7268 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7269
7270 if (!buffer)
7271 {
7272 // A null buffer means that "0" is bound to the requested buffer target
7273 return gl::error(GL_INVALID_OPERATION);
7274 }
7275
7276 switch (pname)
7277 {
7278 case GL_BUFFER_USAGE:
7279 *params = static_cast<GLint64>(buffer->getUsage());
7280 break;
7281 case GL_BUFFER_SIZE:
7282 *params = buffer->getSize();
7283 break;
7284 case GL_BUFFER_ACCESS_FLAGS:
7285 *params = static_cast<GLint64>(buffer->getAccessFlags());
7286 break;
7287 case GL_BUFFER_MAPPED:
7288 *params = static_cast<GLint64>(buffer->isMapped());
7289 break;
7290 case GL_BUFFER_MAP_OFFSET:
7291 *params = buffer->getMapOffset();
7292 break;
7293 case GL_BUFFER_MAP_LENGTH:
7294 *params = buffer->getMapLength();
7295 break;
7296 default: UNREACHABLE(); break;
7297 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007298 }
7299}
7300
7301void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7302{
7303 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7304
Geoff Langbfdea662014-07-23 14:16:32 -04007305 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007306
Geoff Langbfdea662014-07-23 14:16:32 -04007307 if (context)
7308 {
7309 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007310 {
Geoff Langbfdea662014-07-23 14:16:32 -04007311 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007312 }
Geoff Langbfdea662014-07-23 14:16:32 -04007313
7314 if (count < 0)
7315 {
7316 return gl::error(GL_INVALID_VALUE);
7317 }
7318
7319 for (int i = 0; i < count; i++)
7320 {
7321 samplers[i] = context->createSampler();
7322 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007323 }
7324}
7325
7326void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7327{
7328 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7329
Geoff Langbfdea662014-07-23 14:16:32 -04007330 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007331
Geoff Langbfdea662014-07-23 14:16:32 -04007332 if (context)
7333 {
7334 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007335 {
Geoff Langbfdea662014-07-23 14:16:32 -04007336 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007337 }
Geoff Langbfdea662014-07-23 14:16:32 -04007338
7339 if (count < 0)
7340 {
7341 return gl::error(GL_INVALID_VALUE);
7342 }
7343
7344 for (int i = 0; i < count; i++)
7345 {
7346 context->deleteSampler(samplers[i]);
7347 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007348 }
7349}
7350
7351GLboolean __stdcall glIsSampler(GLuint sampler)
7352{
7353 EVENT("(GLuint sampler = %u)", sampler);
7354
Geoff Langbfdea662014-07-23 14:16:32 -04007355 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007356
Geoff Langbfdea662014-07-23 14:16:32 -04007357 if (context)
7358 {
7359 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007360 {
Geoff Langbfdea662014-07-23 14:16:32 -04007361 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007362 }
Geoff Langbfdea662014-07-23 14:16:32 -04007363
7364 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007365 }
7366
7367 return GL_FALSE;
7368}
7369
7370void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7371{
7372 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7373
Geoff Langbfdea662014-07-23 14:16:32 -04007374 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007375
Geoff Langbfdea662014-07-23 14:16:32 -04007376 if (context)
7377 {
7378 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007379 {
Geoff Langbfdea662014-07-23 14:16:32 -04007380 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007381 }
Geoff Langbfdea662014-07-23 14:16:32 -04007382
7383 if (sampler != 0 && !context->isSampler(sampler))
7384 {
7385 return gl::error(GL_INVALID_OPERATION);
7386 }
7387
7388 if (unit >= context->getMaximumCombinedTextureImageUnits())
7389 {
7390 return gl::error(GL_INVALID_VALUE);
7391 }
7392
7393 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007394 }
7395}
7396
7397void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7398{
7399 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7400
Geoff Langbfdea662014-07-23 14:16:32 -04007401 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007402
Geoff Langbfdea662014-07-23 14:16:32 -04007403 if (context)
7404 {
7405 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007406 {
Geoff Langbfdea662014-07-23 14:16:32 -04007407 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007408 }
Geoff Langbfdea662014-07-23 14:16:32 -04007409
7410 if (!gl::ValidateSamplerObjectParameter(pname))
7411 {
7412 return;
7413 }
7414
7415 if (!gl::ValidateTexParamParameters(context, pname, param))
7416 {
7417 return;
7418 }
7419
7420 if (!context->isSampler(sampler))
7421 {
7422 return gl::error(GL_INVALID_OPERATION);
7423 }
7424
7425 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007426 }
7427}
7428
7429void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7430{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007431 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007432}
7433
7434void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7435{
7436 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7437
Geoff Langbfdea662014-07-23 14:16:32 -04007438 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007439
Geoff Langbfdea662014-07-23 14:16:32 -04007440 if (context)
7441 {
7442 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007443 {
Geoff Langbfdea662014-07-23 14:16:32 -04007444 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007445 }
Geoff Langbfdea662014-07-23 14:16:32 -04007446
7447 if (!gl::ValidateSamplerObjectParameter(pname))
7448 {
7449 return;
7450 }
7451
7452 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7453 {
7454 return;
7455 }
7456
7457 if (!context->isSampler(sampler))
7458 {
7459 return gl::error(GL_INVALID_OPERATION);
7460 }
7461
7462 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007463 }
7464}
7465
7466void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7467{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007468 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007469}
7470
7471void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7472{
7473 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7474
Geoff Langbfdea662014-07-23 14:16:32 -04007475 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007476
Geoff Langbfdea662014-07-23 14:16:32 -04007477 if (context)
7478 {
7479 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007480 {
Geoff Langbfdea662014-07-23 14:16:32 -04007481 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007482 }
Geoff Langbfdea662014-07-23 14:16:32 -04007483
7484 if (!gl::ValidateSamplerObjectParameter(pname))
7485 {
7486 return;
7487 }
7488
7489 if (!context->isSampler(sampler))
7490 {
7491 return gl::error(GL_INVALID_OPERATION);
7492 }
7493
7494 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007495 }
7496}
7497
7498void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7499{
7500 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7501
Geoff Langbfdea662014-07-23 14:16:32 -04007502 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007503
Geoff Langbfdea662014-07-23 14:16:32 -04007504 if (context)
7505 {
7506 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007507 {
Geoff Langbfdea662014-07-23 14:16:32 -04007508 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007509 }
Geoff Langbfdea662014-07-23 14:16:32 -04007510
7511 if (!gl::ValidateSamplerObjectParameter(pname))
7512 {
7513 return;
7514 }
7515
7516 if (!context->isSampler(sampler))
7517 {
7518 return gl::error(GL_INVALID_OPERATION);
7519 }
7520
7521 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007522 }
7523}
7524
7525void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7526{
7527 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7528
Geoff Langbfdea662014-07-23 14:16:32 -04007529 if (index >= gl::MAX_VERTEX_ATTRIBS)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007530 {
Geoff Langbfdea662014-07-23 14:16:32 -04007531 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007532 }
Geoff Langbfdea662014-07-23 14:16:32 -04007533
7534 gl::Context *context = gl::getNonLostContext();
7535
7536 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007537 {
Geoff Langbfdea662014-07-23 14:16:32 -04007538 if (context->getClientVersion() < 3)
7539 {
7540 return gl::error(GL_INVALID_OPERATION);
7541 }
7542
7543 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007544 }
7545}
7546
7547void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7548{
7549 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7550
Geoff Langbfdea662014-07-23 14:16:32 -04007551 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007552
Geoff Langbfdea662014-07-23 14:16:32 -04007553 if (context)
7554 {
7555 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007556 {
Geoff Langbfdea662014-07-23 14:16:32 -04007557 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007558 }
Geoff Langbfdea662014-07-23 14:16:32 -04007559
7560 switch (target)
7561 {
7562 case GL_TRANSFORM_FEEDBACK:
7563 {
7564 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7565 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7566 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7567 {
7568 return gl::error(GL_INVALID_OPERATION);
7569 }
7570
7571 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7572 if (context->getTransformFeedback(id) == NULL)
7573 {
7574 return gl::error(GL_INVALID_OPERATION);
7575 }
7576
7577 context->bindTransformFeedback(id);
7578 }
7579 break;
7580
7581 default:
7582 return gl::error(GL_INVALID_ENUM);
7583 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007584 }
7585}
7586
7587void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7588{
7589 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7590
Geoff Langbfdea662014-07-23 14:16:32 -04007591 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007592
Geoff Langbfdea662014-07-23 14:16:32 -04007593 if (context)
7594 {
7595 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007596 {
Geoff Langbfdea662014-07-23 14:16:32 -04007597 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007598 }
Geoff Langbfdea662014-07-23 14:16:32 -04007599
7600 for (int i = 0; i < n; i++)
7601 {
7602 context->deleteTransformFeedback(ids[i]);
7603 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007604 }
7605}
7606
7607void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7608{
7609 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7610
Geoff Langbfdea662014-07-23 14:16:32 -04007611 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007612
Geoff Langbfdea662014-07-23 14:16:32 -04007613 if (context)
7614 {
7615 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007616 {
Geoff Langbfdea662014-07-23 14:16:32 -04007617 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007618 }
Geoff Langbfdea662014-07-23 14:16:32 -04007619
7620 for (int i = 0; i < n; i++)
7621 {
7622 ids[i] = context->createTransformFeedback();
7623 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007624 }
7625}
7626
7627GLboolean __stdcall glIsTransformFeedback(GLuint id)
7628{
7629 EVENT("(GLuint id = %u)", id);
7630
Geoff Langbfdea662014-07-23 14:16:32 -04007631 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007632
Geoff Langbfdea662014-07-23 14:16:32 -04007633 if (context)
7634 {
7635 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007636 {
Geoff Langbfdea662014-07-23 14:16:32 -04007637 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007638 }
Geoff Langbfdea662014-07-23 14:16:32 -04007639
7640 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007641 }
7642
7643 return GL_FALSE;
7644}
7645
7646void __stdcall glPauseTransformFeedback(void)
7647{
7648 EVENT("(void)");
7649
Geoff Langbfdea662014-07-23 14:16:32 -04007650 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007651
Geoff Langbfdea662014-07-23 14:16:32 -04007652 if (context)
7653 {
7654 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007655 {
Geoff Langbfdea662014-07-23 14:16:32 -04007656 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007657 }
Geoff Langbfdea662014-07-23 14:16:32 -04007658
7659 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7660 ASSERT(transformFeedback != NULL);
7661
7662 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7663 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7664 {
7665 return gl::error(GL_INVALID_OPERATION);
7666 }
7667
7668 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007669 }
7670}
7671
7672void __stdcall glResumeTransformFeedback(void)
7673{
7674 EVENT("(void)");
7675
Geoff Langbfdea662014-07-23 14:16:32 -04007676 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007677
Geoff Langbfdea662014-07-23 14:16:32 -04007678 if (context)
7679 {
7680 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007681 {
Geoff Langbfdea662014-07-23 14:16:32 -04007682 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007683 }
Geoff Langbfdea662014-07-23 14:16:32 -04007684
7685 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7686 ASSERT(transformFeedback != NULL);
7687
7688 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7689 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7690 {
7691 return gl::error(GL_INVALID_OPERATION);
7692 }
7693
7694 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007695 }
7696}
7697
7698void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7699{
7700 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7701 program, bufSize, length, binaryFormat, binary);
7702
Geoff Langbfdea662014-07-23 14:16:32 -04007703 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007704
Geoff Langbfdea662014-07-23 14:16:32 -04007705 if (context)
7706 {
7707 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007708 {
Geoff Langbfdea662014-07-23 14:16:32 -04007709 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007710 }
Geoff Langbfdea662014-07-23 14:16:32 -04007711
7712 // glGetProgramBinary
7713 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007714 }
7715}
7716
7717void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7718{
7719 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7720 program, binaryFormat, binary, length);
7721
Geoff Langbfdea662014-07-23 14:16:32 -04007722 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007723
Geoff Langbfdea662014-07-23 14:16:32 -04007724 if (context)
7725 {
7726 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007727 {
Geoff Langbfdea662014-07-23 14:16:32 -04007728 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007729 }
Geoff Langbfdea662014-07-23 14:16:32 -04007730
7731 // glProgramBinary
7732 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007733 }
7734}
7735
7736void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7737{
7738 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7739 program, pname, value);
7740
Geoff Langbfdea662014-07-23 14:16:32 -04007741 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007742
Geoff Langbfdea662014-07-23 14:16:32 -04007743 if (context)
7744 {
7745 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007746 {
Geoff Langbfdea662014-07-23 14:16:32 -04007747 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007748 }
Geoff Langbfdea662014-07-23 14:16:32 -04007749
7750 // glProgramParameteri
7751 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007752 }
7753}
7754
7755void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7756{
7757 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7758 target, numAttachments, attachments);
7759
Geoff Langbfdea662014-07-23 14:16:32 -04007760 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007761
Geoff Langbfdea662014-07-23 14:16:32 -04007762 if (context)
7763 {
7764 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007765 {
Geoff Langbfdea662014-07-23 14:16:32 -04007766 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007767 }
Geoff Langbfdea662014-07-23 14:16:32 -04007768
7769 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7770 {
7771 return;
7772 }
7773
7774 GLuint maxDimension = context->getCaps().maxRenderbufferSize;
7775 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007776 }
7777}
7778
7779void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
7780{
7781 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
7782 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7783 target, numAttachments, attachments, x, y, width, height);
7784
Geoff Langbfdea662014-07-23 14:16:32 -04007785 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007786
Geoff Langbfdea662014-07-23 14:16:32 -04007787 if (context)
7788 {
7789 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007790 {
Geoff Langbfdea662014-07-23 14:16:32 -04007791 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007792 }
Geoff Langbfdea662014-07-23 14:16:32 -04007793
7794 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7795 {
7796 return;
7797 }
7798
7799 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007800 }
7801}
7802
7803void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7804{
7805 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7806 target, levels, internalformat, width, height);
7807
Geoff Langbfdea662014-07-23 14:16:32 -04007808 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007809
Geoff Langbfdea662014-07-23 14:16:32 -04007810 if (context)
7811 {
7812 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007813 {
Geoff Langbfdea662014-07-23 14:16:32 -04007814 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007815 }
Geoff Langbfdea662014-07-23 14:16:32 -04007816
7817 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
7818 {
7819 return;
7820 }
7821
7822 switch (target)
7823 {
7824 case GL_TEXTURE_2D:
7825 {
7826 gl::Texture2D *texture2d = context->getTexture2D();
7827 texture2d->storage(levels, internalformat, width, height);
7828 }
7829 break;
7830
7831 case GL_TEXTURE_CUBE_MAP:
7832 {
7833 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7834 textureCube->storage(levels, internalformat, width);
7835 }
7836 break;
7837
7838 default:
7839 return gl::error(GL_INVALID_ENUM);
7840 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007841 }
7842}
7843
7844void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
7845{
7846 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
7847 "GLsizei height = %d, GLsizei depth = %d)",
7848 target, levels, internalformat, width, height, depth);
7849
Geoff Langbfdea662014-07-23 14:16:32 -04007850 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007851
Geoff Langbfdea662014-07-23 14:16:32 -04007852 if (context)
7853 {
7854 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007855 {
Geoff Langbfdea662014-07-23 14:16:32 -04007856 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00007857 }
Geoff Langbfdea662014-07-23 14:16:32 -04007858
7859 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
7860 {
7861 return;
7862 }
7863
7864 switch (target)
7865 {
7866 case GL_TEXTURE_3D:
7867 {
7868 gl::Texture3D *texture3d = context->getTexture3D();
7869 texture3d->storage(levels, internalformat, width, height, depth);
7870 }
7871 break;
7872
7873 case GL_TEXTURE_2D_ARRAY:
7874 {
7875 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
7876 texture2darray->storage(levels, internalformat, width, height, depth);
7877 }
7878 break;
7879
7880 default:
7881 UNREACHABLE();
7882 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007883 }
7884}
7885
7886void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
7887{
7888 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
7889 "GLint* params = 0x%0.8p)",
7890 target, internalformat, pname, bufSize, params);
7891
Geoff Langbfdea662014-07-23 14:16:32 -04007892 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007893
Geoff Langbfdea662014-07-23 14:16:32 -04007894 if (context)
7895 {
7896 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007897 {
Geoff Langbfdea662014-07-23 14:16:32 -04007898 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007899 }
Geoff Langbfdea662014-07-23 14:16:32 -04007900
7901 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7902 if (!formatCaps.renderable)
7903 {
7904 return gl::error(GL_INVALID_ENUM);
7905 }
7906
7907 if (target != GL_RENDERBUFFER)
7908 {
7909 return gl::error(GL_INVALID_ENUM);
7910 }
7911
7912 if (bufSize < 0)
7913 {
7914 return gl::error(GL_INVALID_VALUE);
7915 }
7916
7917 switch (pname)
7918 {
7919 case GL_NUM_SAMPLE_COUNTS:
7920 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04007921 {
7922 *params = formatCaps.sampleCounts.size();
7923 }
Geoff Langbfdea662014-07-23 14:16:32 -04007924 break;
7925 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04007926 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04007927 break;
7928 default:
7929 return gl::error(GL_INVALID_ENUM);
7930 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007931 }
7932}
7933
7934// Extension functions
7935
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007936void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
7937 GLbitfield mask, GLenum filter)
7938{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007939 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007940 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
7941 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
7942 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
7943
Geoff Langbfdea662014-07-23 14:16:32 -04007944 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007945
Geoff Langbfdea662014-07-23 14:16:32 -04007946 if (context)
7947 {
7948 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
7949 dstX0, dstY0, dstX1, dstY1, mask, filter,
7950 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007951 {
Geoff Langbfdea662014-07-23 14:16:32 -04007952 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007953 }
Geoff Langbfdea662014-07-23 14:16:32 -04007954
7955 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
7956 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007957 }
7958}
7959
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007960void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
7961 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007962{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007963 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007964 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007965 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007966 target, level, internalformat, width, height, depth, border, format, type, pixels);
7967
Geoff Langbfdea662014-07-23 14:16:32 -04007968 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007969}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00007970
Geoff Langbfdea662014-07-23 14:16:32 -04007971void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007972 GLenum *binaryFormat, void *binary)
7973{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00007974 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 +00007975 program, bufSize, length, binaryFormat, binary);
7976
Geoff Langbfdea662014-07-23 14:16:32 -04007977 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007978
Geoff Langbfdea662014-07-23 14:16:32 -04007979 if (context)
7980 {
7981 gl::Program *programObject = context->getProgram(program);
7982
7983 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007984 {
Geoff Langbfdea662014-07-23 14:16:32 -04007985 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007986 }
Geoff Langbfdea662014-07-23 14:16:32 -04007987
7988 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7989
7990 if (!programBinary)
7991 {
7992 return gl::error(GL_INVALID_OPERATION);
7993 }
7994
Geoff Lang900013c2014-07-07 11:32:19 -04007995 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04007996 {
7997 return gl::error(GL_INVALID_OPERATION);
7998 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007999 }
8000}
8001
8002void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8003 const void *binary, GLint length)
8004{
8005 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8006 program, binaryFormat, binary, length);
8007
Geoff Langbfdea662014-07-23 14:16:32 -04008008 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008009
Geoff Langbfdea662014-07-23 14:16:32 -04008010 if (context)
8011 {
Geoff Lang900013c2014-07-07 11:32:19 -04008012 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8013 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008014 {
Geoff Langbfdea662014-07-23 14:16:32 -04008015 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008016 }
Geoff Langbfdea662014-07-23 14:16:32 -04008017
8018 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008019 if (!programObject)
8020 {
8021 return gl::error(GL_INVALID_OPERATION);
8022 }
8023
Geoff Lang900013c2014-07-07 11:32:19 -04008024 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008025 }
8026}
8027
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008028void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8029{
8030 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8031
Geoff Langbfdea662014-07-23 14:16:32 -04008032 gl::Context *context = gl::getNonLostContext();
8033
8034 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008035 {
Geoff Langbfdea662014-07-23 14:16:32 -04008036 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008037 {
Geoff Langbfdea662014-07-23 14:16:32 -04008038 return gl::error(GL_INVALID_VALUE);
8039 }
8040
8041 if (context->getState().getDrawFramebuffer()->id() == 0)
8042 {
8043 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008044 {
Geoff Langbfdea662014-07-23 14:16:32 -04008045 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008046 }
8047
Geoff Langbfdea662014-07-23 14:16:32 -04008048 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008049 {
Geoff Langbfdea662014-07-23 14:16:32 -04008050 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008051 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008052 }
Geoff Langbfdea662014-07-23 14:16:32 -04008053 else
8054 {
8055 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8056 {
8057 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8058 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8059 {
8060 return gl::error(GL_INVALID_OPERATION);
8061 }
8062 }
8063 }
8064
8065 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8066
8067 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8068 {
8069 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8070 }
8071
8072 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8073 {
8074 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8075 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008076 }
8077}
8078
Shannon Woodsb3801742014-03-27 14:59:19 -04008079void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8080{
8081 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8082
Geoff Langbfdea662014-07-23 14:16:32 -04008083 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008084
Geoff Langbfdea662014-07-23 14:16:32 -04008085 if (context)
8086 {
8087 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008088 {
Geoff Langbfdea662014-07-23 14:16:32 -04008089 return gl::error(GL_INVALID_ENUM);
Shannon Woodsb3801742014-03-27 14:59:19 -04008090 }
Geoff Langbfdea662014-07-23 14:16:32 -04008091
8092 if (pname != GL_BUFFER_MAP_POINTER)
8093 {
8094 return gl::error(GL_INVALID_ENUM);
8095 }
8096
8097 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8098
8099 if (!buffer || !buffer->isMapped())
8100 {
8101 *params = NULL;
8102 }
8103 else
8104 {
8105 *params = buffer->getMapPointer();
8106 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008107 }
8108}
8109
8110void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8111{
8112 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8113
Geoff Langbfdea662014-07-23 14:16:32 -04008114 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008115
Geoff Langbfdea662014-07-23 14:16:32 -04008116 if (context)
8117 {
8118 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008119 {
Geoff Langbfdea662014-07-23 14:16:32 -04008120 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woodsb3801742014-03-27 14:59:19 -04008121 }
Geoff Langbfdea662014-07-23 14:16:32 -04008122
8123 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8124
8125 if (buffer == NULL)
8126 {
8127 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8128 }
8129
8130 if (access != GL_WRITE_ONLY_OES)
8131 {
8132 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
8133 }
8134
8135 if (buffer->isMapped())
8136 {
8137 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8138 }
8139
8140 return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
Shannon Woodsb3801742014-03-27 14:59:19 -04008141 }
8142
8143 return NULL;
8144}
8145
8146GLboolean __stdcall glUnmapBufferOES(GLenum target)
8147{
8148 EVENT("(GLenum target = 0x%X)", target);
8149
Geoff Langbfdea662014-07-23 14:16:32 -04008150 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008151
Geoff Langbfdea662014-07-23 14:16:32 -04008152 if (context)
8153 {
8154 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008155 {
Geoff Langbfdea662014-07-23 14:16:32 -04008156 return gl::error(GL_INVALID_ENUM, GL_FALSE);
Shannon Woodsb3801742014-03-27 14:59:19 -04008157 }
Geoff Langbfdea662014-07-23 14:16:32 -04008158
8159 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8160
8161 if (buffer == NULL || !buffer->isMapped())
8162 {
8163 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8164 }
8165
8166 // TODO: detect if we had corruption. if so, throw an error and return false.
8167
8168 buffer->unmap();
8169
8170 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008171 }
8172
8173 return GL_FALSE;
8174}
8175
Shannon Woods916e7692014-03-27 16:58:22 -04008176void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8177{
8178 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8179 target, offset, length, access);
8180
Geoff Langbfdea662014-07-23 14:16:32 -04008181 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008182
Geoff Langbfdea662014-07-23 14:16:32 -04008183 if (context)
8184 {
8185 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008186 {
Geoff Langbfdea662014-07-23 14:16:32 -04008187 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woods916e7692014-03-27 16:58:22 -04008188 }
Geoff Langbfdea662014-07-23 14:16:32 -04008189
8190 if (offset < 0 || length < 0)
8191 {
8192 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8193 }
8194
8195 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8196
8197 if (buffer == NULL)
8198 {
8199 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8200 }
8201
8202 // Check for buffer overflow
8203 size_t offsetSize = static_cast<size_t>(offset);
8204 size_t lengthSize = static_cast<size_t>(length);
8205
8206 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8207 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8208 {
8209 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8210 }
8211
8212 // Check for invalid bits in the mask
8213 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8214 GL_MAP_WRITE_BIT |
8215 GL_MAP_INVALIDATE_RANGE_BIT |
8216 GL_MAP_INVALIDATE_BUFFER_BIT |
8217 GL_MAP_FLUSH_EXPLICIT_BIT |
8218 GL_MAP_UNSYNCHRONIZED_BIT;
8219
8220 if (access & ~(allAccessBits))
8221 {
8222 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8223 }
8224
8225 if (length == 0 || buffer->isMapped())
8226 {
8227 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8228 }
8229
8230 // Check for invalid bit combinations
8231 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8232 {
8233 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8234 }
8235
8236 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8237 GL_MAP_INVALIDATE_BUFFER_BIT |
8238 GL_MAP_UNSYNCHRONIZED_BIT;
8239
8240 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8241 {
8242 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8243 }
8244
8245 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8246 {
8247 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8248 }
8249
8250 return buffer->mapRange(offset, length, access);
Shannon Woods916e7692014-03-27 16:58:22 -04008251 }
8252
8253 return NULL;
8254}
8255
8256void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8257{
8258 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8259
Geoff Langbfdea662014-07-23 14:16:32 -04008260 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008261
Geoff Langbfdea662014-07-23 14:16:32 -04008262 if (context)
8263 {
8264 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008265 {
Geoff Langbfdea662014-07-23 14:16:32 -04008266 return gl::error(GL_INVALID_VALUE);
Shannon Woods916e7692014-03-27 16:58:22 -04008267 }
Geoff Langbfdea662014-07-23 14:16:32 -04008268
8269 if (!gl::ValidBufferTarget(context, target))
8270 {
8271 return gl::error(GL_INVALID_ENUM);
8272 }
8273
8274 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8275
8276 if (buffer == NULL)
8277 {
8278 return gl::error(GL_INVALID_OPERATION);
8279 }
8280
8281 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8282 {
8283 return gl::error(GL_INVALID_OPERATION);
8284 }
8285
8286 // Check for buffer overflow
8287 size_t offsetSize = static_cast<size_t>(offset);
8288 size_t lengthSize = static_cast<size_t>(length);
8289
8290 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8291 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8292 {
8293 return gl::error(GL_INVALID_VALUE);
8294 }
8295
8296 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008297 }
8298}
8299
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008300__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8301{
8302 struct Extension
8303 {
8304 const char *name;
8305 __eglMustCastToProperFunctionPointerType address;
8306 };
8307
8308 static const Extension glExtensions[] =
8309 {
8310 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008311 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008312 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008313 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8314 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8315 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8316 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8317 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8318 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8319 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008320 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008321 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008322 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8323 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8324 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8325 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008326 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8327 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8328 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8329 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8330 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8331 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8332 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008333 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008334 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8335 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8336 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008337 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008338 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8339 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8340 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008341 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8342 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8343 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008344
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008345 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008346 {
8347 if (strcmp(procname, glExtensions[ext].name) == 0)
8348 {
8349 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8350 }
8351 }
8352
8353 return NULL;
8354}
8355
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008356// Non-public functions used by EGL
8357
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008358bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008359{
8360 EVENT("(egl::Surface* surface = 0x%0.8p)",
8361 surface);
8362
Geoff Langbfdea662014-07-23 14:16:32 -04008363 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008364
Geoff Langbfdea662014-07-23 14:16:32 -04008365 if (context)
8366 {
8367 gl::Texture2D *textureObject = context->getTexture2D();
8368 ASSERT(textureObject != NULL);
8369
8370 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008371 {
Geoff Langbfdea662014-07-23 14:16:32 -04008372 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008373 }
Geoff Langbfdea662014-07-23 14:16:32 -04008374
8375 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008376 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008377
8378 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008379}
8380
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008381}