blob: 103d4ff605c26fd4b3d67cfcfa83e23d127465e7 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
Geoff Lang48dcae72014-02-05 16:28:24 -05003// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040024#include "libGLESv2/VertexArray.h"
Brandon Jones5bf98292014-06-06 17:19:38 -070025#include "libGLESv2/VertexAttribute.h"
Geoff Langc8058452014-02-03 12:04:11 -050026#include "libGLESv2/TransformFeedback.h"
Jamie Madille261b442014-06-25 12:42:21 -040027#include "libGLESv2/FramebufferAttachment.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000028
Geoff Lange8ebe7f2013-08-05 15:03:13 -040029#include "libGLESv2/validationES.h"
30#include "libGLESv2/validationES2.h"
31#include "libGLESv2/validationES3.h"
Jamie Madill55856b12014-01-02 13:59:50 -050032#include "libGLESv2/queryconversions.h"
Jamie Madill478fdb22013-07-19 16:36:59 -040033
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034extern "C"
35{
36
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000037// OpenGL ES 2.0 functions
38
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039void __stdcall glActiveTexture(GLenum texture)
40{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000041 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000042
Geoff Langbfdea662014-07-23 14:16:32 -040043 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000044
Geoff Langbfdea662014-07-23 14:16:32 -040045 if (context)
46 {
47 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000048 {
Geoff Langbfdea662014-07-23 14:16:32 -040049 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000050 }
Geoff Langbfdea662014-07-23 14:16:32 -040051
52 context->getState().setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000053 }
54}
55
56void __stdcall glAttachShader(GLuint program, GLuint shader)
57{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000058 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000059
Geoff Langbfdea662014-07-23 14:16:32 -040060 gl::Context *context = gl::getNonLostContext();
61
62 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000063 {
Geoff Langbfdea662014-07-23 14:16:32 -040064 gl::Program *programObject = context->getProgram(program);
65 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066
Geoff Langbfdea662014-07-23 14:16:32 -040067 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000068 {
Geoff Langbfdea662014-07-23 14:16:32 -040069 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000071 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072 }
Geoff Langbfdea662014-07-23 14:16:32 -040073 else
74 {
75 return gl::error(GL_INVALID_VALUE);
76 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000077 }
Geoff Langbfdea662014-07-23 14:16:32 -040078
79 if (!shaderObject)
80 {
81 if (context->getProgram(shader))
82 {
83 return gl::error(GL_INVALID_OPERATION);
84 }
85 else
86 {
87 return gl::error(GL_INVALID_VALUE);
88 }
89 }
90
91 if (!programObject->attachShader(shaderObject))
92 {
93 return gl::error(GL_INVALID_OPERATION);
94 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095 }
96}
97
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000098void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
99{
100 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
101
Geoff Langbfdea662014-07-23 14:16:32 -0400102 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000103
Geoff Langbfdea662014-07-23 14:16:32 -0400104 if (context)
105 {
106 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000107 {
Geoff Langbfdea662014-07-23 14:16:32 -0400108 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000109 }
Geoff Langbfdea662014-07-23 14:16:32 -0400110
111 context->beginQuery(target, id);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000112 }
113}
114
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000115void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000116{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000117 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000118
Geoff Langbfdea662014-07-23 14:16:32 -0400119 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120 {
Geoff Langbfdea662014-07-23 14:16:32 -0400121 return gl::error(GL_INVALID_VALUE);
122 }
123
124 gl::Context *context = gl::getNonLostContext();
125
126 if (context)
127 {
128 gl::Program *programObject = context->getProgram(program);
129
130 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000131 {
Geoff Langbfdea662014-07-23 14:16:32 -0400132 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000134 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135 }
Geoff Langbfdea662014-07-23 14:16:32 -0400136 else
137 {
138 return gl::error(GL_INVALID_VALUE);
139 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000140 }
Geoff Langbfdea662014-07-23 14:16:32 -0400141
142 if (strncmp(name, "gl_", 3) == 0)
143 {
144 return gl::error(GL_INVALID_OPERATION);
145 }
146
147 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000148 }
149}
150
151void __stdcall glBindBuffer(GLenum target, GLuint buffer)
152{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000153 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000154
Geoff Langbfdea662014-07-23 14:16:32 -0400155 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000156
Geoff Langbfdea662014-07-23 14:16:32 -0400157 if (context)
158 {
159 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000160 {
Geoff Langbfdea662014-07-23 14:16:32 -0400161 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000162 }
Geoff Langbfdea662014-07-23 14:16:32 -0400163
164 switch (target)
165 {
166 case GL_ARRAY_BUFFER:
167 context->bindArrayBuffer(buffer);
168 return;
169 case GL_ELEMENT_ARRAY_BUFFER:
170 context->bindElementArrayBuffer(buffer);
171 return;
172 case GL_COPY_READ_BUFFER:
173 context->bindCopyReadBuffer(buffer);
174 return;
175 case GL_COPY_WRITE_BUFFER:
176 context->bindCopyWriteBuffer(buffer);
177 return;
178 case GL_PIXEL_PACK_BUFFER:
179 context->bindPixelPackBuffer(buffer);
180 return;
181 case GL_PIXEL_UNPACK_BUFFER:
182 context->bindPixelUnpackBuffer(buffer);
183 return;
184 case GL_UNIFORM_BUFFER:
185 context->bindGenericUniformBuffer(buffer);
186 return;
187 case GL_TRANSFORM_FEEDBACK_BUFFER:
188 context->bindGenericTransformFeedbackBuffer(buffer);
189 return;
190 default:
191 return gl::error(GL_INVALID_ENUM);
192 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000193 }
194}
195
196void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
197{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000198 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000199
Geoff Langbfdea662014-07-23 14:16:32 -0400200 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000201 {
Geoff Langbfdea662014-07-23 14:16:32 -0400202 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000203 }
Geoff Langbfdea662014-07-23 14:16:32 -0400204
205 gl::Context *context = gl::getNonLostContext();
206
207 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000208 {
Geoff Langbfdea662014-07-23 14:16:32 -0400209 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
210 {
211 context->bindReadFramebuffer(framebuffer);
212 }
213
214 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
215 {
216 context->bindDrawFramebuffer(framebuffer);
217 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000218 }
219}
220
221void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
222{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000223 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000224
Geoff Langbfdea662014-07-23 14:16:32 -0400225 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000226 {
Geoff Langbfdea662014-07-23 14:16:32 -0400227 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000228 }
Geoff Langbfdea662014-07-23 14:16:32 -0400229
230 gl::Context *context = gl::getNonLostContext();
231
232 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000233 {
Geoff Langbfdea662014-07-23 14:16:32 -0400234 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000235 }
236}
237
238void __stdcall glBindTexture(GLenum target, GLuint texture)
239{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000240 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000241
Geoff Langbfdea662014-07-23 14:16:32 -0400242 gl::Context *context = gl::getNonLostContext();
243
244 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000245 {
Geoff Langbfdea662014-07-23 14:16:32 -0400246 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000247
Geoff Langbfdea662014-07-23 14:16:32 -0400248 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000249 {
Geoff Langbfdea662014-07-23 14:16:32 -0400250 return gl::error(GL_INVALID_OPERATION);
251 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000252
Geoff Langbfdea662014-07-23 14:16:32 -0400253 switch (target)
254 {
255 case GL_TEXTURE_2D:
256 context->bindTexture2D(texture);
257 return;
258 case GL_TEXTURE_CUBE_MAP:
259 context->bindTextureCubeMap(texture);
260 return;
261 case GL_TEXTURE_3D:
262 if (context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000263 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000264 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000265 }
Geoff Langbfdea662014-07-23 14:16:32 -0400266 context->bindTexture3D(texture);
267 return;
268 case GL_TEXTURE_2D_ARRAY:
269 if (context->getClientVersion() < 3)
270 {
271 return gl::error(GL_INVALID_ENUM);
272 }
273 context->bindTexture2DArray(texture);
274 return;
275 default:
276 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000277 }
278 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000279}
280
281void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
282{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000283 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000284 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000285
Geoff Langbfdea662014-07-23 14:16:32 -0400286 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287
Geoff Langbfdea662014-07-23 14:16:32 -0400288 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000289 {
Geoff Langbfdea662014-07-23 14:16:32 -0400290 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000291 }
292}
293
294void __stdcall glBlendEquation(GLenum mode)
295{
296 glBlendEquationSeparate(mode, mode);
297}
298
299void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
300{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000301 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000302
Geoff Langbfdea662014-07-23 14:16:32 -0400303 gl::Context *context = gl::getNonLostContext();
304
305 switch (modeRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000306 {
Geoff Langbfdea662014-07-23 14:16:32 -0400307 case GL_FUNC_ADD:
308 case GL_FUNC_SUBTRACT:
309 case GL_FUNC_REVERSE_SUBTRACT:
310 case GL_MIN:
311 case GL_MAX:
312 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000313
Geoff Langbfdea662014-07-23 14:16:32 -0400314 default:
315 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000316 }
Geoff Langbfdea662014-07-23 14:16:32 -0400317
318 switch (modeAlpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000319 {
Geoff Langbfdea662014-07-23 14:16:32 -0400320 case GL_FUNC_ADD:
321 case GL_FUNC_SUBTRACT:
322 case GL_FUNC_REVERSE_SUBTRACT:
323 case GL_MIN:
324 case GL_MAX:
325 break;
326
327 default:
328 return gl::error(GL_INVALID_ENUM);
329 }
330
331 if (context)
332 {
333 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000334 }
335}
336
337void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
338{
339 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
340}
341
342void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000344 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000345 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000346
Geoff Langbfdea662014-07-23 14:16:32 -0400347 gl::Context *context = gl::getNonLostContext();
348
349 switch (srcRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000350 {
Geoff Langbfdea662014-07-23 14:16:32 -0400351 case GL_ZERO:
352 case GL_ONE:
353 case GL_SRC_COLOR:
354 case GL_ONE_MINUS_SRC_COLOR:
355 case GL_DST_COLOR:
356 case GL_ONE_MINUS_DST_COLOR:
357 case GL_SRC_ALPHA:
358 case GL_ONE_MINUS_SRC_ALPHA:
359 case GL_DST_ALPHA:
360 case GL_ONE_MINUS_DST_ALPHA:
361 case GL_CONSTANT_COLOR:
362 case GL_ONE_MINUS_CONSTANT_COLOR:
363 case GL_CONSTANT_ALPHA:
364 case GL_ONE_MINUS_CONSTANT_ALPHA:
365 case GL_SRC_ALPHA_SATURATE:
366 break;
367 default:
368 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000369 }
Geoff Langbfdea662014-07-23 14:16:32 -0400370
371 switch (dstRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000372 {
Geoff Langbfdea662014-07-23 14:16:32 -0400373 case GL_ZERO:
374 case GL_ONE:
375 case GL_SRC_COLOR:
376 case GL_ONE_MINUS_SRC_COLOR:
377 case GL_DST_COLOR:
378 case GL_ONE_MINUS_DST_COLOR:
379 case GL_SRC_ALPHA:
380 case GL_ONE_MINUS_SRC_ALPHA:
381 case GL_DST_ALPHA:
382 case GL_ONE_MINUS_DST_ALPHA:
383 case GL_CONSTANT_COLOR:
384 case GL_ONE_MINUS_CONSTANT_COLOR:
385 case GL_CONSTANT_ALPHA:
386 case GL_ONE_MINUS_CONSTANT_ALPHA:
387 break;
388
389 case GL_SRC_ALPHA_SATURATE:
390 if (!context || context->getClientVersion() < 3)
391 {
392 return gl::error(GL_INVALID_ENUM);
393 }
394 break;
395
396 default:
397 return gl::error(GL_INVALID_ENUM);
398 }
399
400 switch (srcAlpha)
401 {
402 case GL_ZERO:
403 case GL_ONE:
404 case GL_SRC_COLOR:
405 case GL_ONE_MINUS_SRC_COLOR:
406 case GL_DST_COLOR:
407 case GL_ONE_MINUS_DST_COLOR:
408 case GL_SRC_ALPHA:
409 case GL_ONE_MINUS_SRC_ALPHA:
410 case GL_DST_ALPHA:
411 case GL_ONE_MINUS_DST_ALPHA:
412 case GL_CONSTANT_COLOR:
413 case GL_ONE_MINUS_CONSTANT_COLOR:
414 case GL_CONSTANT_ALPHA:
415 case GL_ONE_MINUS_CONSTANT_ALPHA:
416 case GL_SRC_ALPHA_SATURATE:
417 break;
418 default:
419 return gl::error(GL_INVALID_ENUM);
420 }
421
422 switch (dstAlpha)
423 {
424 case GL_ZERO:
425 case GL_ONE:
426 case GL_SRC_COLOR:
427 case GL_ONE_MINUS_SRC_COLOR:
428 case GL_DST_COLOR:
429 case GL_ONE_MINUS_DST_COLOR:
430 case GL_SRC_ALPHA:
431 case GL_ONE_MINUS_SRC_ALPHA:
432 case GL_DST_ALPHA:
433 case GL_ONE_MINUS_DST_ALPHA:
434 case GL_CONSTANT_COLOR:
435 case GL_ONE_MINUS_CONSTANT_COLOR:
436 case GL_CONSTANT_ALPHA:
437 case GL_ONE_MINUS_CONSTANT_ALPHA:
438 break;
439
440 case GL_SRC_ALPHA_SATURATE:
441 if (!context || context->getClientVersion() < 3)
442 {
443 return gl::error(GL_INVALID_ENUM);
444 }
445 break;
446
447 default:
448 return gl::error(GL_INVALID_ENUM);
449 }
450
451 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
452 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
453
454 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
455 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
456
457 if (constantColorUsed && constantAlphaUsed)
458 {
459 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
460 return gl::error(GL_INVALID_OPERATION);
461 }
462
463 if (context)
464 {
465 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000466 }
467}
468
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000469void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000470{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000471 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000472 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000473
Geoff Langbfdea662014-07-23 14:16:32 -0400474 if (size < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000475 {
Geoff Langbfdea662014-07-23 14:16:32 -0400476 return gl::error(GL_INVALID_VALUE);
477 }
478
479 gl::Context *context = gl::getNonLostContext();
480
481 switch (usage)
482 {
483 case GL_STREAM_DRAW:
484 case GL_STATIC_DRAW:
485 case GL_DYNAMIC_DRAW:
486 break;
487
488 case GL_STREAM_READ:
489 case GL_STREAM_COPY:
490 case GL_STATIC_READ:
491 case GL_STATIC_COPY:
492 case GL_DYNAMIC_READ:
493 case GL_DYNAMIC_COPY:
494 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000495 {
Geoff Langbfdea662014-07-23 14:16:32 -0400496 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000497 }
Geoff Langbfdea662014-07-23 14:16:32 -0400498 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000499
Geoff Langbfdea662014-07-23 14:16:32 -0400500 default:
501 return gl::error(GL_INVALID_ENUM);
502 }
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +0000503
Geoff Langbfdea662014-07-23 14:16:32 -0400504 if (context)
505 {
506 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000508 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000509 }
510
Geoff Langbfdea662014-07-23 14:16:32 -0400511 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
512
513 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000514 {
Geoff Langbfdea662014-07-23 14:16:32 -0400515 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000516 }
Geoff Langbfdea662014-07-23 14:16:32 -0400517
518 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000519 }
520}
521
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000522void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000524 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000525 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000526
Geoff Langbfdea662014-07-23 14:16:32 -0400527 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000528 {
Geoff Langbfdea662014-07-23 14:16:32 -0400529 return gl::error(GL_INVALID_VALUE);
530 }
531
532 if (data == NULL)
533 {
534 return;
535 }
536
537 gl::Context *context = gl::getNonLostContext();
538
539 if (context)
540 {
541 if (!gl::ValidBufferTarget(context, target))
542 {
543 return gl::error(GL_INVALID_ENUM);
544 }
545
546 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
547
548 if (!buffer)
549 {
550 return gl::error(GL_INVALID_OPERATION);
551 }
552
553 if (buffer->isMapped())
554 {
555 return gl::error(GL_INVALID_OPERATION);
556 }
557
558 // Check for possible overflow of size + offset
559 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
560 {
561 return gl::error(GL_OUT_OF_MEMORY);
562 }
563
564 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000566 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000567 }
568
Geoff Langbfdea662014-07-23 14:16:32 -0400569 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000570 }
571}
572
573GLenum __stdcall glCheckFramebufferStatus(GLenum target)
574{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000575 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000576
Geoff Langbfdea662014-07-23 14:16:32 -0400577 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000578 {
Geoff Langbfdea662014-07-23 14:16:32 -0400579 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000580 }
Geoff Langbfdea662014-07-23 14:16:32 -0400581
582 gl::Context *context = gl::getNonLostContext();
583
584 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000585 {
Geoff Langbfdea662014-07-23 14:16:32 -0400586 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
587 ASSERT(framebuffer);
588 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000589 }
590
591 return 0;
592}
593
594void __stdcall glClear(GLbitfield mask)
595{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000596 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000597
Geoff Langbfdea662014-07-23 14:16:32 -0400598 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000599
Geoff Langbfdea662014-07-23 14:16:32 -0400600 if (context)
601 {
602 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
603
604 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000605 {
Geoff Langbfdea662014-07-23 14:16:32 -0400606 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000607 }
Geoff Langbfdea662014-07-23 14:16:32 -0400608
609 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
610 {
611 return gl::error(GL_INVALID_VALUE);
612 }
613
614 context->clear(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000615 }
616}
617
618void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
619{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000620 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000621 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000622
Geoff Langbfdea662014-07-23 14:16:32 -0400623 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000624
Geoff Langbfdea662014-07-23 14:16:32 -0400625 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000626 {
Geoff Langbfdea662014-07-23 14:16:32 -0400627 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000628 }
629}
630
631void __stdcall glClearDepthf(GLclampf depth)
632{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000633 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000634
Geoff Langbfdea662014-07-23 14:16:32 -0400635 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000636
Geoff Langbfdea662014-07-23 14:16:32 -0400637 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000638 {
Geoff Langbfdea662014-07-23 14:16:32 -0400639 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000640 }
641}
642
643void __stdcall glClearStencil(GLint s)
644{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000645 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000646
Geoff Langbfdea662014-07-23 14:16:32 -0400647 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000648
Geoff Langbfdea662014-07-23 14:16:32 -0400649 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000650 {
Geoff Langbfdea662014-07-23 14:16:32 -0400651 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000652 }
653}
654
655void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
656{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000657 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000658 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000659
Geoff Langbfdea662014-07-23 14:16:32 -0400660 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000661
Geoff Langbfdea662014-07-23 14:16:32 -0400662 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000663 {
Geoff Langbfdea662014-07-23 14:16:32 -0400664 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000665 }
666}
667
668void __stdcall glCompileShader(GLuint shader)
669{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000670 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000671
Geoff Langbfdea662014-07-23 14:16:32 -0400672 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000673
Geoff Langbfdea662014-07-23 14:16:32 -0400674 if (context)
675 {
676 gl::Shader *shaderObject = context->getShader(shader);
677
678 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000679 {
Geoff Langbfdea662014-07-23 14:16:32 -0400680 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000681 {
Geoff Langbfdea662014-07-23 14:16:32 -0400682 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000683 }
Geoff Langbfdea662014-07-23 14:16:32 -0400684 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000686 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000687 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000688 }
Geoff Langbfdea662014-07-23 14:16:32 -0400689
690 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000691 }
Geoff Langbfdea662014-07-23 14:16:32 -0400692}
693
694void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
695 GLint border, GLsizei imageSize, const GLvoid* data)
696{
697 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
698 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
699 target, level, internalformat, width, height, border, imageSize, data);
700
701 gl::Context *context = gl::getNonLostContext();
702
703 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000704 {
Geoff Langbfdea662014-07-23 14:16:32 -0400705 if (context->getClientVersion() < 3 &&
706 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
707 0, 0, width, height, border, GL_NONE, GL_NONE, data))
708 {
709 return;
710 }
711
712 if (context->getClientVersion() >= 3 &&
713 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
714 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
715 {
716 return;
717 }
718
Geoff Lang5d601382014-07-22 15:14:06 -0400719 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
720 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400721 {
722 return gl::error(GL_INVALID_VALUE);
723 }
724
725 switch (target)
726 {
727 case GL_TEXTURE_2D:
728 {
729 gl::Texture2D *texture = context->getTexture2D();
730 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
731 }
732 break;
733
734 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
735 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
736 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
737 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
738 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
739 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
740 {
741 gl::TextureCubeMap *texture = context->getTextureCubeMap();
742 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
743 }
744 break;
745
746 default:
747 return gl::error(GL_INVALID_ENUM);
748 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000749 }
750}
751
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000752void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
753 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000754{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000755 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000756 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000757 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000758 target, level, xoffset, yoffset, width, height, format, imageSize, data);
759
Geoff Langbfdea662014-07-23 14:16:32 -0400760 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +0000761
Geoff Langbfdea662014-07-23 14:16:32 -0400762 if (context)
763 {
764 if (context->getClientVersion() < 3 &&
765 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
766 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000767 {
Geoff Langbfdea662014-07-23 14:16:32 -0400768 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000769 }
Geoff Langbfdea662014-07-23 14:16:32 -0400770
771 if (context->getClientVersion() >= 3 &&
772 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
773 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
774 {
775 return;
776 }
777
Geoff Lang5d601382014-07-22 15:14:06 -0400778 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
779 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400780 {
781 return gl::error(GL_INVALID_VALUE);
782 }
783
784 switch (target)
785 {
786 case GL_TEXTURE_2D:
787 {
788 gl::Texture2D *texture = context->getTexture2D();
789 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
790 }
791 break;
792
793 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
794 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
795 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
797 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
798 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
799 {
800 gl::TextureCubeMap *texture = context->getTextureCubeMap();
801 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
802 }
803 break;
804
805 default:
806 return gl::error(GL_INVALID_ENUM);
807 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000808 }
809}
810
811void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
812{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000813 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000814 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000815 target, level, internalformat, x, y, width, height, border);
816
Geoff Langbfdea662014-07-23 14:16:32 -0400817 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000818
Geoff Langbfdea662014-07-23 14:16:32 -0400819 if (context)
820 {
821 if (context->getClientVersion() < 3 &&
822 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
823 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000824 {
Geoff Langbfdea662014-07-23 14:16:32 -0400825 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000826 }
Geoff Langbfdea662014-07-23 14:16:32 -0400827
828 if (context->getClientVersion() >= 3 &&
829 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
830 0, 0, 0, x, y, width, height, border))
831 {
832 return;
833 }
834
835 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
836
837 switch (target)
838 {
839 case GL_TEXTURE_2D:
840 {
841 gl::Texture2D *texture = context->getTexture2D();
842 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
843 }
844 break;
845
846 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
847 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
848 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
852 {
853 gl::TextureCubeMap *texture = context->getTextureCubeMap();
854 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
855 }
856 break;
857
858 default:
859 return gl::error(GL_INVALID_ENUM);
860 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000861 }
862}
863
864void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
865{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000866 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000867 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000868 target, level, xoffset, yoffset, x, y, width, height);
869
Geoff Langbfdea662014-07-23 14:16:32 -0400870 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000871
Geoff Langbfdea662014-07-23 14:16:32 -0400872 if (context)
873 {
874 if (context->getClientVersion() < 3 &&
875 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
876 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000877 {
Geoff Langbfdea662014-07-23 14:16:32 -0400878 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000879 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000880
Geoff Langbfdea662014-07-23 14:16:32 -0400881 if (context->getClientVersion() >= 3 &&
882 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
883 xoffset, yoffset, 0, x, y, width, height, 0))
884 {
885 return;
886 }
887
888 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
889
890 switch (target)
891 {
892 case GL_TEXTURE_2D:
893 {
894 gl::Texture2D *texture = context->getTexture2D();
895 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
896 }
897 break;
898
899 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
900 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
901 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
902 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
903 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
904 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
905 {
906 gl::TextureCubeMap *texture = context->getTextureCubeMap();
907 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
908 }
909 break;
910
911 default:
912 return gl::error(GL_INVALID_ENUM);
913 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000914 }
915}
916
917GLuint __stdcall glCreateProgram(void)
918{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000919 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000920
Geoff Langbfdea662014-07-23 14:16:32 -0400921 gl::Context *context = gl::getNonLostContext();
922 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000923 {
Geoff Langbfdea662014-07-23 14:16:32 -0400924 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000925 }
926
927 return 0;
928}
929
930GLuint __stdcall glCreateShader(GLenum type)
931{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000932 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000933
Geoff Langbfdea662014-07-23 14:16:32 -0400934 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000935
Geoff Langbfdea662014-07-23 14:16:32 -0400936 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000937 {
Geoff Langbfdea662014-07-23 14:16:32 -0400938 switch (type)
939 {
940 case GL_FRAGMENT_SHADER:
941 case GL_VERTEX_SHADER:
942 return context->createShader(type);
943 default:
944 return gl::error(GL_INVALID_ENUM, 0);
945 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000946 }
947
948 return 0;
949}
950
951void __stdcall glCullFace(GLenum mode)
952{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000953 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000954
Geoff Langbfdea662014-07-23 14:16:32 -0400955 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000956 {
Geoff Langbfdea662014-07-23 14:16:32 -0400957 case GL_FRONT:
958 case GL_BACK:
959 case GL_FRONT_AND_BACK:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000960 {
Geoff Langbfdea662014-07-23 14:16:32 -0400961 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000962
Geoff Langbfdea662014-07-23 14:16:32 -0400963 if (context)
964 {
965 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000966 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000967 }
Geoff Langbfdea662014-07-23 14:16:32 -0400968 break;
969 default:
970 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000971 }
972}
973
974void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000976 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000977
Geoff Langbfdea662014-07-23 14:16:32 -0400978 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000979 {
Geoff Langbfdea662014-07-23 14:16:32 -0400980 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000981 }
Geoff Langbfdea662014-07-23 14:16:32 -0400982
983 gl::Context *context = gl::getNonLostContext();
984
985 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000986 {
Geoff Langbfdea662014-07-23 14:16:32 -0400987 for (int i = 0; i < n; i++)
988 {
989 context->deleteBuffer(buffers[i]);
990 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000991 }
992}
993
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000994void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
995{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000996 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000997
Geoff Langbfdea662014-07-23 14:16:32 -0400998 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000999 {
Geoff Langbfdea662014-07-23 14:16:32 -04001000 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001001 }
Geoff Langbfdea662014-07-23 14:16:32 -04001002
1003 gl::Context *context = gl::getNonLostContext();
1004
1005 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001006 {
Geoff Langbfdea662014-07-23 14:16:32 -04001007 for (int i = 0; i < n; i++)
1008 {
1009 context->deleteFenceNV(fences[i]);
1010 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001011 }
1012}
1013
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001014void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1015{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001016 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001017
Geoff Langbfdea662014-07-23 14:16:32 -04001018 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001019 {
Geoff Langbfdea662014-07-23 14:16:32 -04001020 return gl::error(GL_INVALID_VALUE);
1021 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001022
Geoff Langbfdea662014-07-23 14:16:32 -04001023 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001024
Geoff Langbfdea662014-07-23 14:16:32 -04001025 if (context)
1026 {
1027 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001028 {
Geoff Langbfdea662014-07-23 14:16:32 -04001029 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001030 {
Geoff Langbfdea662014-07-23 14:16:32 -04001031 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001032 }
1033 }
1034 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001035}
1036
1037void __stdcall glDeleteProgram(GLuint program)
1038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001039 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001040
Geoff Langbfdea662014-07-23 14:16:32 -04001041 if (program == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001042 {
Geoff Langbfdea662014-07-23 14:16:32 -04001043 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001044 }
Geoff Langbfdea662014-07-23 14:16:32 -04001045
1046 gl::Context *context = gl::getNonLostContext();
1047
1048 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001049 {
Geoff Langbfdea662014-07-23 14:16:32 -04001050 if (!context->getProgram(program))
1051 {
1052 if(context->getShader(program))
1053 {
1054 return gl::error(GL_INVALID_OPERATION);
1055 }
1056 else
1057 {
1058 return gl::error(GL_INVALID_VALUE);
1059 }
1060 }
1061
1062 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001063 }
1064}
1065
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001066void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1067{
1068 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1069
Geoff Langbfdea662014-07-23 14:16:32 -04001070 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001071 {
Geoff Langbfdea662014-07-23 14:16:32 -04001072 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001073 }
Geoff Langbfdea662014-07-23 14:16:32 -04001074
1075 gl::Context *context = gl::getNonLostContext();
1076
1077 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001078 {
Geoff Langbfdea662014-07-23 14:16:32 -04001079 for (int i = 0; i < n; i++)
1080 {
1081 context->deleteQuery(ids[i]);
1082 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001083 }
1084}
1085
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001086void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1087{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001088 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001089
Geoff Langbfdea662014-07-23 14:16:32 -04001090 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001091 {
Geoff Langbfdea662014-07-23 14:16:32 -04001092 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001093 }
Geoff Langbfdea662014-07-23 14:16:32 -04001094
1095 gl::Context *context = gl::getNonLostContext();
1096
1097 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001098 {
Geoff Langbfdea662014-07-23 14:16:32 -04001099 for (int i = 0; i < n; i++)
1100 {
1101 context->deleteRenderbuffer(renderbuffers[i]);
1102 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001103 }
1104}
1105
1106void __stdcall glDeleteShader(GLuint shader)
1107{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001108 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001109
Geoff Langbfdea662014-07-23 14:16:32 -04001110 if (shader == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001111 {
Geoff Langbfdea662014-07-23 14:16:32 -04001112 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001113 }
Geoff Langbfdea662014-07-23 14:16:32 -04001114
1115 gl::Context *context = gl::getNonLostContext();
1116
1117 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001118 {
Geoff Langbfdea662014-07-23 14:16:32 -04001119 if (!context->getShader(shader))
1120 {
1121 if(context->getProgram(shader))
1122 {
1123 return gl::error(GL_INVALID_OPERATION);
1124 }
1125 else
1126 {
1127 return gl::error(GL_INVALID_VALUE);
1128 }
1129 }
1130
1131 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001132 }
1133}
1134
1135void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001137 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001138
Geoff Langbfdea662014-07-23 14:16:32 -04001139 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001140 {
Geoff Langbfdea662014-07-23 14:16:32 -04001141 return gl::error(GL_INVALID_VALUE);
1142 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001143
Geoff Langbfdea662014-07-23 14:16:32 -04001144 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001145
Geoff Langbfdea662014-07-23 14:16:32 -04001146 if (context)
1147 {
1148 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001149 {
Geoff Langbfdea662014-07-23 14:16:32 -04001150 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001151 {
Geoff Langbfdea662014-07-23 14:16:32 -04001152 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001153 }
1154 }
1155 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001156}
1157
1158void __stdcall glDepthFunc(GLenum func)
1159{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001160 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001161
Geoff Langbfdea662014-07-23 14:16:32 -04001162 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001163 {
Geoff Langbfdea662014-07-23 14:16:32 -04001164 case GL_NEVER:
1165 case GL_ALWAYS:
1166 case GL_LESS:
1167 case GL_LEQUAL:
1168 case GL_EQUAL:
1169 case GL_GREATER:
1170 case GL_GEQUAL:
1171 case GL_NOTEQUAL:
1172 break;
1173 default:
1174 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001175 }
Geoff Langbfdea662014-07-23 14:16:32 -04001176
1177 gl::Context *context = gl::getNonLostContext();
1178
1179 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001180 {
Geoff Langbfdea662014-07-23 14:16:32 -04001181 context->getState().setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001182 }
1183}
1184
1185void __stdcall glDepthMask(GLboolean flag)
1186{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001187 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001188
Geoff Langbfdea662014-07-23 14:16:32 -04001189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001190
Geoff Langbfdea662014-07-23 14:16:32 -04001191 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001192 {
Geoff Langbfdea662014-07-23 14:16:32 -04001193 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001194 }
1195}
1196
1197void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1198{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001199 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001200
Geoff Langbfdea662014-07-23 14:16:32 -04001201 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001202
Geoff Langbfdea662014-07-23 14:16:32 -04001203 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001204 {
Geoff Langbfdea662014-07-23 14:16:32 -04001205 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001206 }
1207}
1208
1209void __stdcall glDetachShader(GLuint program, GLuint shader)
1210{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001211 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001212
Geoff Langbfdea662014-07-23 14:16:32 -04001213 gl::Context *context = gl::getNonLostContext();
1214
1215 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001216 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001217
Geoff Langbfdea662014-07-23 14:16:32 -04001218 gl::Program *programObject = context->getProgram(program);
1219 gl::Shader *shaderObject = context->getShader(shader);
1220
1221 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001222 {
Geoff Langbfdea662014-07-23 14:16:32 -04001223 gl::Shader *shaderByProgramHandle;
1224 shaderByProgramHandle = context->getShader(program);
1225 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001226 {
Geoff Langbfdea662014-07-23 14:16:32 -04001227 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001228 }
Geoff Langbfdea662014-07-23 14:16:32 -04001229 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001231 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001232 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001233 }
Geoff Langbfdea662014-07-23 14:16:32 -04001234
1235 if (!shaderObject)
1236 {
1237 gl::Program *programByShaderHandle = context->getProgram(shader);
1238 if (!programByShaderHandle)
1239 {
1240 return gl::error(GL_INVALID_VALUE);
1241 }
1242 else
1243 {
1244 return gl::error(GL_INVALID_OPERATION);
1245 }
1246 }
1247
1248 if (!programObject->detachShader(shaderObject))
1249 {
1250 return gl::error(GL_INVALID_OPERATION);
1251 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001252 }
1253}
1254
1255void __stdcall glDisable(GLenum cap)
1256{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001257 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001258
Geoff Langbfdea662014-07-23 14:16:32 -04001259 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001260
Geoff Langbfdea662014-07-23 14:16:32 -04001261 if (context)
1262 {
1263 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001264 {
Geoff Langbfdea662014-07-23 14:16:32 -04001265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266 }
Geoff Langbfdea662014-07-23 14:16:32 -04001267
1268 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001269 }
1270}
1271
1272void __stdcall glDisableVertexAttribArray(GLuint index)
1273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001274 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001275
Geoff Langbfdea662014-07-23 14:16:32 -04001276 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277 {
Geoff Langbfdea662014-07-23 14:16:32 -04001278 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001279 }
Geoff Langbfdea662014-07-23 14:16:32 -04001280
1281 gl::Context *context = gl::getNonLostContext();
1282
1283 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001284 {
Geoff Langbfdea662014-07-23 14:16:32 -04001285 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001286 }
1287}
1288
1289void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001291 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001292
Geoff Langbfdea662014-07-23 14:16:32 -04001293 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001294
Geoff Langbfdea662014-07-23 14:16:32 -04001295 if (context)
1296 {
Jamie Madill2b976812014-08-25 15:47:49 -04001297 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001298 {
Geoff Langbfdea662014-07-23 14:16:32 -04001299 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001300 }
Geoff Langbfdea662014-07-23 14:16:32 -04001301
1302 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001303 }
1304}
1305
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001306void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1307{
1308 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1309
Geoff Langbfdea662014-07-23 14:16:32 -04001310 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001311
Geoff Langbfdea662014-07-23 14:16:32 -04001312 if (context)
1313 {
1314 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001315 {
Geoff Langbfdea662014-07-23 14:16:32 -04001316 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001317 }
Geoff Langbfdea662014-07-23 14:16:32 -04001318
1319 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001320 }
1321}
1322
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001323void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001325 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001326 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001327
Geoff Langbfdea662014-07-23 14:16:32 -04001328 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001329
Geoff Langbfdea662014-07-23 14:16:32 -04001330 if (context)
1331 {
Jamie Madill2b976812014-08-25 15:47:49 -04001332 rx::RangeUI indexRange;
1333 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001334 {
Geoff Langbfdea662014-07-23 14:16:32 -04001335 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001336 }
Geoff Langbfdea662014-07-23 14:16:32 -04001337
Jamie Madill2b976812014-08-25 15:47:49 -04001338 context->drawElements(mode, count, type, indices, 0, indexRange);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001339 }
1340}
1341
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001342void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1343{
1344 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1345 mode, count, type, indices, primcount);
1346
Geoff Langbfdea662014-07-23 14:16:32 -04001347 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001348
Geoff Langbfdea662014-07-23 14:16:32 -04001349 if (context)
1350 {
Jamie Madill2b976812014-08-25 15:47:49 -04001351 rx::RangeUI indexRange;
1352 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001353 {
Geoff Langbfdea662014-07-23 14:16:32 -04001354 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001355 }
Geoff Langbfdea662014-07-23 14:16:32 -04001356
Jamie Madill2b976812014-08-25 15:47:49 -04001357 context->drawElements(mode, count, type, indices, primcount, indexRange);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001358 }
1359}
1360
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001361void __stdcall glEnable(GLenum cap)
1362{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001363 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001364
Geoff Langbfdea662014-07-23 14:16:32 -04001365 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001366
Geoff Langbfdea662014-07-23 14:16:32 -04001367 if (context)
1368 {
1369 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001370 {
Geoff Langbfdea662014-07-23 14:16:32 -04001371 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001372 }
Geoff Langbfdea662014-07-23 14:16:32 -04001373
1374 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001375 }
1376}
1377
1378void __stdcall glEnableVertexAttribArray(GLuint index)
1379{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001380 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001381
Geoff Langbfdea662014-07-23 14:16:32 -04001382 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001383 {
Geoff Langbfdea662014-07-23 14:16:32 -04001384 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001385 }
Geoff Langbfdea662014-07-23 14:16:32 -04001386
1387 gl::Context *context = gl::getNonLostContext();
1388
1389 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001390 {
Geoff Langbfdea662014-07-23 14:16:32 -04001391 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001392 }
1393}
1394
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001395void __stdcall glEndQueryEXT(GLenum target)
1396{
1397 EVENT("GLenum target = 0x%X)", target);
1398
Geoff Langbfdea662014-07-23 14:16:32 -04001399 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001400
Geoff Langbfdea662014-07-23 14:16:32 -04001401 if (context)
1402 {
1403 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001404 {
Geoff Langbfdea662014-07-23 14:16:32 -04001405 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001406 }
Geoff Langbfdea662014-07-23 14:16:32 -04001407
1408 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001409 }
1410}
1411
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001412void __stdcall glFinishFenceNV(GLuint fence)
1413{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001414 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001415
Geoff Langbfdea662014-07-23 14:16:32 -04001416 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001417
Geoff Langbfdea662014-07-23 14:16:32 -04001418 if (context)
1419 {
1420 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1421
1422 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001423 {
Geoff Langbfdea662014-07-23 14:16:32 -04001424 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001425 }
Geoff Langbfdea662014-07-23 14:16:32 -04001426
1427 if (fenceObject->isFence() != GL_TRUE)
1428 {
1429 return gl::error(GL_INVALID_OPERATION);
1430 }
1431
1432 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001433 }
1434}
1435
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001436void __stdcall glFinish(void)
1437{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001438 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001439
Geoff Langbfdea662014-07-23 14:16:32 -04001440 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001441
Geoff Langbfdea662014-07-23 14:16:32 -04001442 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001443 {
Geoff Langbfdea662014-07-23 14:16:32 -04001444 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001445 }
1446}
1447
1448void __stdcall glFlush(void)
1449{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001450 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001451
Geoff Langbfdea662014-07-23 14:16:32 -04001452 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453
Geoff Langbfdea662014-07-23 14:16:32 -04001454 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001455 {
Geoff Langbfdea662014-07-23 14:16:32 -04001456 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001457 }
1458}
1459
1460void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1461{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001462 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001463 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001464
Geoff Langbfdea662014-07-23 14:16:32 -04001465 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001466 {
Geoff Langbfdea662014-07-23 14:16:32 -04001467 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001468 }
Geoff Langbfdea662014-07-23 14:16:32 -04001469
1470 gl::Context *context = gl::getNonLostContext();
1471
1472 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001473 {
Geoff Langbfdea662014-07-23 14:16:32 -04001474 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1475 {
1476 return;
1477 }
1478
1479 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1480 ASSERT(framebuffer);
1481
1482 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1483 {
1484 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1485 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1486 }
1487 else
1488 {
1489 switch (attachment)
1490 {
1491 case GL_DEPTH_ATTACHMENT:
1492 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1493 break;
1494 case GL_STENCIL_ATTACHMENT:
1495 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1496 break;
1497 case GL_DEPTH_STENCIL_ATTACHMENT:
1498 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1499 break;
1500 default:
1501 UNREACHABLE();
1502 break;
1503 }
1504 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001505 }
1506}
1507
1508void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1509{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001510 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001511 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001512
Geoff Langbfdea662014-07-23 14:16:32 -04001513 gl::Context *context = gl::getNonLostContext();
1514 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001515 {
Geoff Langbfdea662014-07-23 14:16:32 -04001516 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001517 {
Geoff Langbfdea662014-07-23 14:16:32 -04001518 return;
1519 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001520
Geoff Langbfdea662014-07-23 14:16:32 -04001521 if (texture == 0)
1522 {
1523 textarget = GL_NONE;
1524 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001525
Geoff Langbfdea662014-07-23 14:16:32 -04001526 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001527
Geoff Langbfdea662014-07-23 14:16:32 -04001528 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1529 {
1530 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1531 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1532 }
1533 else
1534 {
1535 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001536 {
Geoff Langbfdea662014-07-23 14:16:32 -04001537 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1538 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1539 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001540 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001541 }
1542 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001543}
1544
1545void __stdcall glFrontFace(GLenum mode)
1546{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001547 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001548
Geoff Langbfdea662014-07-23 14:16:32 -04001549 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001550 {
Geoff Langbfdea662014-07-23 14:16:32 -04001551 case GL_CW:
1552 case GL_CCW:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001553 {
Geoff Langbfdea662014-07-23 14:16:32 -04001554 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001555
Geoff Langbfdea662014-07-23 14:16:32 -04001556 if (context)
1557 {
1558 context->getState().setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001559 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001560 }
Geoff Langbfdea662014-07-23 14:16:32 -04001561 break;
1562 default:
1563 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001564 }
1565}
1566
1567void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1568{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001569 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001570
Geoff Langbfdea662014-07-23 14:16:32 -04001571 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001572 {
Geoff Langbfdea662014-07-23 14:16:32 -04001573 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001574 }
Geoff Langbfdea662014-07-23 14:16:32 -04001575
1576 gl::Context *context = gl::getNonLostContext();
1577
1578 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001579 {
Geoff Langbfdea662014-07-23 14:16:32 -04001580 for (int i = 0; i < n; i++)
1581 {
1582 buffers[i] = context->createBuffer();
1583 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001584 }
1585}
1586
1587void __stdcall glGenerateMipmap(GLenum target)
1588{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001589 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001590
Geoff Langbfdea662014-07-23 14:16:32 -04001591 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001592
Geoff Langbfdea662014-07-23 14:16:32 -04001593 if (context)
1594 {
1595 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001596 {
Geoff Langbfdea662014-07-23 14:16:32 -04001597 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001598 }
Geoff Langbfdea662014-07-23 14:16:32 -04001599
1600 gl::Texture *texture = context->getTargetTexture(target);
1601
1602 if (texture == NULL)
1603 {
1604 return gl::error(GL_INVALID_OPERATION);
1605 }
1606
1607 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1608 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001609 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001610
1611 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1612 // unsized formats or that are color renderable and filterable. Since we do not track if
1613 // the texture was created with sized or unsized format (only sized formats are stored),
1614 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1615 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1616 // textures since they're the only texture format that can be created with unsized formats
1617 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1618 // was the last version to use add them.
1619 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1620 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1621 internalFormat == GL_ALPHA8_EXT;
1622
Geoff Lang5d601382014-07-22 15:14:06 -04001623 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1624 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001625 {
1626 return gl::error(GL_INVALID_OPERATION);
1627 }
1628
1629 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001630 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001631 {
1632 return gl::error(GL_INVALID_OPERATION);
1633 }
1634
1635 // Non-power of 2 ES2 check
1636 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1637 {
1638 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
1639 return gl::error(GL_INVALID_OPERATION);
1640 }
1641
1642 // Cube completeness check
1643 if (target == GL_TEXTURE_CUBE_MAP)
1644 {
1645 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1646 if (!textureCube->isCubeComplete())
1647 {
1648 return gl::error(GL_INVALID_OPERATION);
1649 }
1650 }
1651
1652 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001653 }
1654}
1655
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001656void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1657{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001658 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001659
Geoff Langbfdea662014-07-23 14:16:32 -04001660 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001661 {
Geoff Langbfdea662014-07-23 14:16:32 -04001662 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001663 }
Geoff Langbfdea662014-07-23 14:16:32 -04001664
1665 gl::Context *context = gl::getNonLostContext();
1666
1667 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001668 {
Geoff Langbfdea662014-07-23 14:16:32 -04001669 for (int i = 0; i < n; i++)
1670 {
1671 fences[i] = context->createFenceNV();
1672 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001673 }
1674}
1675
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001676void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1677{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001678 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001679
Geoff Langbfdea662014-07-23 14:16:32 -04001680 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001681 {
Geoff Langbfdea662014-07-23 14:16:32 -04001682 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001683 }
Geoff Langbfdea662014-07-23 14:16:32 -04001684
1685 gl::Context *context = gl::getNonLostContext();
1686
1687 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001688 {
Geoff Langbfdea662014-07-23 14:16:32 -04001689 for (int i = 0; i < n; i++)
1690 {
1691 framebuffers[i] = context->createFramebuffer();
1692 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001693 }
1694}
1695
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001696void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1697{
1698 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1699
Geoff Langbfdea662014-07-23 14:16:32 -04001700 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001701
Geoff Langbfdea662014-07-23 14:16:32 -04001702 if (context)
1703 {
1704 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001705 {
Geoff Langbfdea662014-07-23 14:16:32 -04001706 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001707 }
Geoff Langbfdea662014-07-23 14:16:32 -04001708
1709 for (GLsizei i = 0; i < n; i++)
1710 {
1711 ids[i] = context->createQuery();
1712 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001713 }
1714}
1715
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001716void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1717{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001718 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001719
Geoff Langbfdea662014-07-23 14:16:32 -04001720 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001721 {
Geoff Langbfdea662014-07-23 14:16:32 -04001722 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001723 }
Geoff Langbfdea662014-07-23 14:16:32 -04001724
1725 gl::Context *context = gl::getNonLostContext();
1726
1727 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001728 {
Geoff Langbfdea662014-07-23 14:16:32 -04001729 for (int i = 0; i < n; i++)
1730 {
1731 renderbuffers[i] = context->createRenderbuffer();
1732 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001733 }
1734}
1735
1736void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1737{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001738 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001739
Geoff Langbfdea662014-07-23 14:16:32 -04001740 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001741 {
Geoff Langbfdea662014-07-23 14:16:32 -04001742 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001743 }
Geoff Langbfdea662014-07-23 14:16:32 -04001744
1745 gl::Context *context = gl::getNonLostContext();
1746
1747 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001748 {
Geoff Langbfdea662014-07-23 14:16:32 -04001749 for (int i = 0; i < n; i++)
1750 {
1751 textures[i] = context->createTexture();
1752 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001753 }
1754}
1755
daniel@transgaming.com85423182010-04-22 13:35:27 +00001756void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001757{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001758 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001759 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001760 program, index, bufsize, length, size, type, name);
1761
Geoff Langbfdea662014-07-23 14:16:32 -04001762 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001763 {
Geoff Langbfdea662014-07-23 14:16:32 -04001764 return gl::error(GL_INVALID_VALUE);
1765 }
1766
1767 gl::Context *context = gl::getNonLostContext();
1768
1769 if (context)
1770 {
1771 gl::Program *programObject = context->getProgram(program);
1772
1773 if (!programObject)
1774 {
1775 if (context->getShader(program))
1776 {
1777 return gl::error(GL_INVALID_OPERATION);
1778 }
1779 else
1780 {
1781 return gl::error(GL_INVALID_VALUE);
1782 }
1783 }
1784
1785 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001787 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001788 }
1789
Geoff Langbfdea662014-07-23 14:16:32 -04001790 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001791 }
1792}
1793
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001794void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001795{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001796 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001797 "GLsizei* length = 0x%0.8p, GLint* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001798 program, index, bufsize, length, size, type, name);
1799
Geoff Langbfdea662014-07-23 14:16:32 -04001800 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001801 {
Geoff Langbfdea662014-07-23 14:16:32 -04001802 return gl::error(GL_INVALID_VALUE);
1803 }
1804
1805 gl::Context *context = gl::getNonLostContext();
1806
1807 if (context)
1808 {
1809 gl::Program *programObject = context->getProgram(program);
1810
1811 if (!programObject)
1812 {
1813 if (context->getShader(program))
1814 {
1815 return gl::error(GL_INVALID_OPERATION);
1816 }
1817 else
1818 {
1819 return gl::error(GL_INVALID_VALUE);
1820 }
1821 }
1822
1823 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001824 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001825 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001826 }
1827
Geoff Langbfdea662014-07-23 14:16:32 -04001828 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001829 }
1830}
1831
1832void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1833{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001834 EVENT("(GLuint program = %d, GLsizei maxcount = %d, GLsizei* count = 0x%0.8p, GLuint* shaders = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001835 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001836
Geoff Langbfdea662014-07-23 14:16:32 -04001837 if (maxcount < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001838 {
Geoff Langbfdea662014-07-23 14:16:32 -04001839 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001840 }
Geoff Langbfdea662014-07-23 14:16:32 -04001841
1842 gl::Context *context = gl::getNonLostContext();
1843
1844 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001845 {
Geoff Langbfdea662014-07-23 14:16:32 -04001846 gl::Program *programObject = context->getProgram(program);
1847
1848 if (!programObject)
1849 {
1850 if (context->getShader(program))
1851 {
1852 return gl::error(GL_INVALID_OPERATION);
1853 }
1854 else
1855 {
1856 return gl::error(GL_INVALID_VALUE);
1857 }
1858 }
1859
1860 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001861 }
1862}
1863
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001864int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001865{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001866 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001867
Geoff Langbfdea662014-07-23 14:16:32 -04001868 gl::Context *context = gl::getNonLostContext();
1869
1870 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001871 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001872
Geoff Langbfdea662014-07-23 14:16:32 -04001873 gl::Program *programObject = context->getProgram(program);
1874
1875 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001876 {
Geoff Langbfdea662014-07-23 14:16:32 -04001877 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001878 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001879 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001880 }
Geoff Langbfdea662014-07-23 14:16:32 -04001881 else
1882 {
1883 return gl::error(GL_INVALID_VALUE, -1);
1884 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001885 }
Geoff Langbfdea662014-07-23 14:16:32 -04001886
1887 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1888 if (!programObject->isLinked() || !programBinary)
1889 {
1890 return gl::error(GL_INVALID_OPERATION, -1);
1891 }
1892
1893 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001894 }
1895
1896 return -1;
1897}
1898
1899void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1900{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001901 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001902
Geoff Langbfdea662014-07-23 14:16:32 -04001903 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00001904
Geoff Langbfdea662014-07-23 14:16:32 -04001905 if (context)
1906 {
1907 GLenum nativeType;
1908 unsigned int numParams = 0;
1909 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001910 {
Geoff Langbfdea662014-07-23 14:16:32 -04001911 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001912 }
Geoff Langbfdea662014-07-23 14:16:32 -04001913
1914 if (nativeType == GL_BOOL)
1915 {
1916 context->getBooleanv(pname, params);
1917 }
1918 else
1919 {
1920 CastStateValues(context, nativeType, pname, numParams, params);
1921 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001922 }
1923}
1924
1925void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1926{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001927 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001928
Geoff Langbfdea662014-07-23 14:16:32 -04001929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001930
Geoff Langbfdea662014-07-23 14:16:32 -04001931 if (context)
1932 {
1933 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001934 {
Geoff Langbfdea662014-07-23 14:16:32 -04001935 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001936 }
Geoff Langbfdea662014-07-23 14:16:32 -04001937
1938 if (!gl::ValidBufferParameter(context, pname))
1939 {
1940 return gl::error(GL_INVALID_ENUM);
1941 }
1942
1943 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
1944
1945 if (!buffer)
1946 {
1947 // A null buffer means that "0" is bound to the requested buffer target
1948 return gl::error(GL_INVALID_OPERATION);
1949 }
1950
1951 switch (pname)
1952 {
1953 case GL_BUFFER_USAGE:
1954 *params = static_cast<GLint>(buffer->getUsage());
1955 break;
1956 case GL_BUFFER_SIZE:
1957 *params = gl::clampCast<GLint>(buffer->getSize());
1958 break;
1959 case GL_BUFFER_ACCESS_FLAGS:
1960 *params = buffer->getAccessFlags();
1961 break;
1962 case GL_BUFFER_MAPPED:
1963 *params = static_cast<GLint>(buffer->isMapped());
1964 break;
1965 case GL_BUFFER_MAP_OFFSET:
1966 *params = gl::clampCast<GLint>(buffer->getMapOffset());
1967 break;
1968 case GL_BUFFER_MAP_LENGTH:
1969 *params = gl::clampCast<GLint>(buffer->getMapLength());
1970 break;
1971 default: UNREACHABLE(); break;
1972 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001973 }
1974}
1975
1976GLenum __stdcall glGetError(void)
1977{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001978 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979
1980 gl::Context *context = gl::getContext();
1981
1982 if (context)
1983 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00001984 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001985 }
1986
1987 return GL_NO_ERROR;
1988}
1989
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001990void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
1991{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001992 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001993
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001994
Geoff Langbfdea662014-07-23 14:16:32 -04001995 gl::Context *context = gl::getNonLostContext();
1996
1997 if (context)
1998 {
1999 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2000
2001 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002002 {
Geoff Langbfdea662014-07-23 14:16:32 -04002003 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002004 }
Geoff Langbfdea662014-07-23 14:16:32 -04002005
2006 if (fenceObject->isFence() != GL_TRUE)
2007 {
2008 return gl::error(GL_INVALID_OPERATION);
2009 }
2010
2011 switch (pname)
2012 {
2013 case GL_FENCE_STATUS_NV:
2014 case GL_FENCE_CONDITION_NV:
2015 break;
2016
2017 default: return gl::error(GL_INVALID_ENUM);
2018 }
2019
2020 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002021 }
2022}
2023
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002024void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2025{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002026 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002027
Geoff Langbfdea662014-07-23 14:16:32 -04002028 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002029
Geoff Langbfdea662014-07-23 14:16:32 -04002030 if (context)
2031 {
2032 GLenum nativeType;
2033 unsigned int numParams = 0;
2034 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002035 {
Geoff Langbfdea662014-07-23 14:16:32 -04002036 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002037 }
Geoff Langbfdea662014-07-23 14:16:32 -04002038
2039 if (nativeType == GL_FLOAT)
2040 {
2041 context->getFloatv(pname, params);
2042 }
2043 else
2044 {
2045 CastStateValues(context, nativeType, pname, numParams, params);
2046 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002047 }
2048}
2049
2050void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2051{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002052 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002053 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002054
Geoff Langbfdea662014-07-23 14:16:32 -04002055 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002056
Geoff Langbfdea662014-07-23 14:16:32 -04002057 if (context)
2058 {
2059 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002060 {
Geoff Langbfdea662014-07-23 14:16:32 -04002061 return gl::error(GL_INVALID_ENUM);
2062 }
2063
2064 int clientVersion = context->getClientVersion();
2065
2066 switch (pname)
2067 {
2068 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2069 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2070 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2071 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2072 break;
2073 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2074 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002076 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002077 }
Geoff Langbfdea662014-07-23 14:16:32 -04002078 break;
2079 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2080 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2081 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2082 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2083 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2084 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2085 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2086 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2087 if (clientVersion < 3)
2088 {
2089 return gl::error(GL_INVALID_ENUM);
2090 }
2091 break;
2092 default:
2093 return gl::error(GL_INVALID_ENUM);
2094 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002095
Geoff Langbfdea662014-07-23 14:16:32 -04002096 // Determine if the attachment is a valid enum
2097 switch (attachment)
2098 {
2099 case GL_BACK:
2100 case GL_FRONT:
2101 case GL_DEPTH:
2102 case GL_STENCIL:
2103 case GL_DEPTH_STENCIL_ATTACHMENT:
2104 if (clientVersion < 3)
2105 {
2106 return gl::error(GL_INVALID_ENUM);
2107 }
2108 break;
2109
2110 case GL_DEPTH_ATTACHMENT:
2111 case GL_STENCIL_ATTACHMENT:
2112 break;
2113
2114 default:
2115 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2116 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2117 {
2118 return gl::error(GL_INVALID_ENUM);
2119 }
2120 break;
2121 }
2122
2123 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2124 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2125
2126 if (framebufferHandle == 0)
2127 {
2128 if (clientVersion < 3)
2129 {
2130 return gl::error(GL_INVALID_OPERATION);
2131 }
2132
2133 switch (attachment)
2134 {
2135 case GL_BACK:
2136 case GL_DEPTH:
2137 case GL_STENCIL:
2138 break;
2139 default:
2140 return gl::error(GL_INVALID_OPERATION);
2141 }
2142 }
2143 else
2144 {
2145 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2146 {
2147 // Valid attachment query
2148 }
2149 else
2150 {
2151 switch (attachment)
2152 {
2153 case GL_DEPTH_ATTACHMENT:
2154 case GL_STENCIL_ATTACHMENT:
2155 break;
2156 case GL_DEPTH_STENCIL_ATTACHMENT:
2157 if (framebuffer->hasValidDepthStencil())
2158 {
2159 return gl::error(GL_INVALID_OPERATION);
2160 }
2161 break;
2162 default:
2163 return gl::error(GL_INVALID_OPERATION);
2164 }
2165 }
2166 }
2167
2168 GLenum attachmentType = GL_NONE;
2169 GLuint attachmentHandle = 0;
2170 GLuint attachmentLevel = 0;
2171 GLuint attachmentLayer = 0;
2172
2173 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2174
2175 if (attachmentObject)
2176 {
2177 attachmentType = attachmentObject->type();
2178 attachmentHandle = attachmentObject->id();
2179 attachmentLevel = attachmentObject->mipLevel();
2180 attachmentLayer = attachmentObject->layer();
2181 }
2182
2183 GLenum attachmentObjectType; // Type category
2184 if (framebufferHandle == 0)
2185 {
2186 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2187 }
2188 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2189 {
2190 attachmentObjectType = attachmentType;
2191 }
2192 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2193 {
2194 attachmentObjectType = GL_TEXTURE;
2195 }
2196 else
2197 {
2198 UNREACHABLE();
2199 return;
2200 }
2201
2202 if (attachmentObjectType == GL_NONE)
2203 {
2204 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2205 // is NONE, then querying any other pname will generate INVALID_ENUM.
2206
2207 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2208 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2209 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002210
Geoff Lang646559f2013-08-15 11:08:15 -04002211 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002212 {
Geoff Lang646559f2013-08-15 11:08:15 -04002213 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002214 *params = attachmentObjectType;
2215 break;
2216
Geoff Lang646559f2013-08-15 11:08:15 -04002217 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002218 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002219 {
Geoff Lang05b05022014-06-11 15:31:45 -04002220 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002221 }
Geoff Langbfdea662014-07-23 14:16:32 -04002222 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002223 break;
2224
2225 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002226 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002227 {
Geoff Langbfdea662014-07-23 14:16:32 -04002228 return gl::error(GL_INVALID_ENUM);
Geoff Lang646559f2013-08-15 11:08:15 -04002229 }
2230 else
2231 {
Geoff Langbfdea662014-07-23 14:16:32 -04002232 gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002233 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002234 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002235 }
Geoff Langbfdea662014-07-23 14:16:32 -04002236 else
2237 {
2238 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2239 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2240 ASSERT(attachmentObject != NULL);
2241
2242 switch (pname)
2243 {
2244 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2245 *params = attachmentObjectType;
2246 break;
2247
2248 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2249 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2250 {
2251 return gl::error(GL_INVALID_ENUM);
2252 }
2253 *params = attachmentHandle;
2254 break;
2255
2256 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2257 if (attachmentObjectType != GL_TEXTURE)
2258 {
2259 return gl::error(GL_INVALID_ENUM);
2260 }
2261 *params = attachmentLevel;
2262 break;
2263
2264 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2265 if (attachmentObjectType != GL_TEXTURE)
2266 {
2267 return gl::error(GL_INVALID_ENUM);
2268 }
2269 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2270 break;
2271
2272 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2273 *params = attachmentObject->getRedSize();
2274 break;
2275
2276 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2277 *params = attachmentObject->getGreenSize();
2278 break;
2279
2280 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2281 *params = attachmentObject->getBlueSize();
2282 break;
2283
2284 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2285 *params = attachmentObject->getAlphaSize();
2286 break;
2287
2288 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2289 *params = attachmentObject->getDepthSize();
2290 break;
2291
2292 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2293 *params = attachmentObject->getStencilSize();
2294 break;
2295
2296 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2297 if (attachment == GL_DEPTH_STENCIL)
2298 {
2299 gl::error(GL_INVALID_OPERATION);
2300 }
2301 *params = attachmentObject->getComponentType();
2302 break;
2303
2304 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2305 *params = attachmentObject->getColorEncoding();
2306 break;
2307
2308 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2309 if (attachmentObjectType != GL_TEXTURE)
2310 {
2311 return gl::error(GL_INVALID_ENUM);
2312 }
2313 *params = attachmentLayer;
2314 break;
2315
2316 default:
2317 UNREACHABLE();
2318 break;
2319 }
2320 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002321 }
2322}
2323
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002324GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2325{
2326 EVENT("()");
2327
Geoff Langbfdea662014-07-23 14:16:32 -04002328 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002329
Geoff Langbfdea662014-07-23 14:16:32 -04002330 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002331 {
Geoff Langbfdea662014-07-23 14:16:32 -04002332 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002333 }
Geoff Langbfdea662014-07-23 14:16:32 -04002334
2335 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002336}
2337
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002338void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2339{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002340 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002341
Geoff Langbfdea662014-07-23 14:16:32 -04002342 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002343
Geoff Langbfdea662014-07-23 14:16:32 -04002344 if (context)
2345 {
2346 GLenum nativeType;
2347 unsigned int numParams = 0;
2348
2349 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002350 {
Geoff Langbfdea662014-07-23 14:16:32 -04002351 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002352 }
Geoff Langbfdea662014-07-23 14:16:32 -04002353
2354 if (nativeType == GL_INT)
2355 {
2356 context->getIntegerv(pname, params);
2357 }
2358 else
2359 {
2360 CastStateValues(context, nativeType, pname, numParams, params);
2361 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002362 }
2363}
2364
2365void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2366{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002367 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002368
Geoff Langbfdea662014-07-23 14:16:32 -04002369 gl::Context *context = gl::getNonLostContext();
2370
2371 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002372 {
Geoff Langbfdea662014-07-23 14:16:32 -04002373 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002374
Geoff Langbfdea662014-07-23 14:16:32 -04002375 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002376 {
Geoff Langbfdea662014-07-23 14:16:32 -04002377 return gl::error(GL_INVALID_VALUE);
2378 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002379
Geoff Langbfdea662014-07-23 14:16:32 -04002380 if (context->getClientVersion() < 3)
2381 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002382 switch (pname)
2383 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002384 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002385 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002386 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002387 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002388 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002389 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002390 }
2391 }
Geoff Langbfdea662014-07-23 14:16:32 -04002392
2393 switch (pname)
2394 {
2395 case GL_DELETE_STATUS:
2396 *params = programObject->isFlaggedForDeletion();
2397 return;
2398 case GL_LINK_STATUS:
2399 *params = programObject->isLinked();
2400 return;
2401 case GL_VALIDATE_STATUS:
2402 *params = programObject->isValidated();
2403 return;
2404 case GL_INFO_LOG_LENGTH:
2405 *params = programObject->getInfoLogLength();
2406 return;
2407 case GL_ATTACHED_SHADERS:
2408 *params = programObject->getAttachedShadersCount();
2409 return;
2410 case GL_ACTIVE_ATTRIBUTES:
2411 *params = programObject->getActiveAttributeCount();
2412 return;
2413 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2414 *params = programObject->getActiveAttributeMaxLength();
2415 return;
2416 case GL_ACTIVE_UNIFORMS:
2417 *params = programObject->getActiveUniformCount();
2418 return;
2419 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2420 *params = programObject->getActiveUniformMaxLength();
2421 return;
2422 case GL_PROGRAM_BINARY_LENGTH_OES:
2423 *params = programObject->getProgramBinaryLength();
2424 return;
2425 case GL_ACTIVE_UNIFORM_BLOCKS:
2426 *params = programObject->getActiveUniformBlockCount();
2427 return;
2428 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2429 *params = programObject->getActiveUniformBlockMaxLength();
2430 break;
2431 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2432 *params = programObject->getTransformFeedbackBufferMode();
2433 break;
2434 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2435 *params = programObject->getTransformFeedbackVaryingCount();
2436 break;
2437 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2438 *params = programObject->getTransformFeedbackVaryingMaxLength();
2439 break;
2440 default:
2441 return gl::error(GL_INVALID_ENUM);
2442 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002443 }
2444}
2445
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002446void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002448 EVENT("(GLuint program = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002449 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002450
Geoff Langbfdea662014-07-23 14:16:32 -04002451 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002452 {
Geoff Langbfdea662014-07-23 14:16:32 -04002453 return gl::error(GL_INVALID_VALUE);
2454 }
2455
2456 gl::Context *context = gl::getNonLostContext();
2457
2458 if (context)
2459 {
2460 gl::Program *programObject = context->getProgram(program);
2461
2462 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002464 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002465 }
2466
Geoff Langbfdea662014-07-23 14:16:32 -04002467 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002468 }
2469}
2470
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002471void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2472{
2473 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2474
Geoff Langbfdea662014-07-23 14:16:32 -04002475 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002476
Geoff Langbfdea662014-07-23 14:16:32 -04002477 if (context)
2478 {
2479 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002480 {
Geoff Langbfdea662014-07-23 14:16:32 -04002481 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002482 }
Geoff Langbfdea662014-07-23 14:16:32 -04002483
2484 switch (pname)
2485 {
2486 case GL_CURRENT_QUERY_EXT:
2487 params[0] = context->getState().getActiveQueryId(target);
2488 break;
2489
2490 default:
2491 return gl::error(GL_INVALID_ENUM);
2492 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002493 }
2494}
2495
2496void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2497{
2498 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2499
Geoff Langbfdea662014-07-23 14:16:32 -04002500 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002501
Geoff Langbfdea662014-07-23 14:16:32 -04002502 if (context)
2503 {
2504 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2505
2506 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002507 {
Geoff Langbfdea662014-07-23 14:16:32 -04002508 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002509 }
Geoff Langbfdea662014-07-23 14:16:32 -04002510
2511 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2512 {
2513 return gl::error(GL_INVALID_OPERATION);
2514 }
2515
2516 switch(pname)
2517 {
2518 case GL_QUERY_RESULT_EXT:
2519 params[0] = queryObject->getResult();
2520 break;
2521 case GL_QUERY_RESULT_AVAILABLE_EXT:
2522 params[0] = queryObject->isResultAvailable();
2523 break;
2524 default:
2525 return gl::error(GL_INVALID_ENUM);
2526 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002527 }
2528}
2529
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002530void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2531{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002532 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002533
Geoff Langbfdea662014-07-23 14:16:32 -04002534 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002535
Geoff Langbfdea662014-07-23 14:16:32 -04002536 if (context)
2537 {
2538 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002539 {
Geoff Langbfdea662014-07-23 14:16:32 -04002540 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002541 }
Geoff Langbfdea662014-07-23 14:16:32 -04002542
2543 if (context->getState().getRenderbufferId() == 0)
2544 {
2545 return gl::error(GL_INVALID_OPERATION);
2546 }
2547
2548 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2549
2550 switch (pname)
2551 {
2552 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2553 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2554 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2555 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2556 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2557 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2558 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2559 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2560 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
2561 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2562 if (!context->getExtensions().framebufferMultisample)
2563 {
2564 return gl::error(GL_INVALID_ENUM);
2565 }
2566 *params = renderbuffer->getSamples();
2567 break;
2568 default:
2569 return gl::error(GL_INVALID_ENUM);
2570 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002571 }
2572}
2573
2574void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2575{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002576 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002577
Geoff Langbfdea662014-07-23 14:16:32 -04002578 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002579
Geoff Langbfdea662014-07-23 14:16:32 -04002580 if (context)
2581 {
2582 gl::Shader *shaderObject = context->getShader(shader);
2583
2584 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002585 {
Geoff Langbfdea662014-07-23 14:16:32 -04002586 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002587 }
Geoff Langbfdea662014-07-23 14:16:32 -04002588
2589 switch (pname)
2590 {
2591 case GL_SHADER_TYPE:
2592 *params = shaderObject->getType();
2593 return;
2594 case GL_DELETE_STATUS:
2595 *params = shaderObject->isFlaggedForDeletion();
2596 return;
2597 case GL_COMPILE_STATUS:
2598 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2599 return;
2600 case GL_INFO_LOG_LENGTH:
2601 *params = shaderObject->getInfoLogLength();
2602 return;
2603 case GL_SHADER_SOURCE_LENGTH:
2604 *params = shaderObject->getSourceLength();
2605 return;
2606 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2607 *params = shaderObject->getTranslatedSourceLength();
2608 return;
2609 default:
2610 return gl::error(GL_INVALID_ENUM);
2611 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002612 }
2613}
2614
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002615void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002616{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002617 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002618 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002619
Geoff Langbfdea662014-07-23 14:16:32 -04002620 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002621 {
Geoff Langbfdea662014-07-23 14:16:32 -04002622 return gl::error(GL_INVALID_VALUE);
2623 }
2624
2625 gl::Context *context = gl::getNonLostContext();
2626
2627 if (context)
2628 {
2629 gl::Shader *shaderObject = context->getShader(shader);
2630
2631 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002633 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002634 }
2635
Geoff Langbfdea662014-07-23 14:16:32 -04002636 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002637 }
2638}
2639
2640void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2641{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002642 EVENT("(GLenum shadertype = 0x%X, GLenum precisiontype = 0x%X, GLint* range = 0x%0.8p, GLint* precision = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002643 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002644
Geoff Langbfdea662014-07-23 14:16:32 -04002645 switch (shadertype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002646 {
Geoff Langbfdea662014-07-23 14:16:32 -04002647 case GL_VERTEX_SHADER:
2648 case GL_FRAGMENT_SHADER:
2649 break;
2650 default:
2651 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002652 }
Geoff Langbfdea662014-07-23 14:16:32 -04002653
2654 switch (precisiontype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002655 {
Geoff Langbfdea662014-07-23 14:16:32 -04002656 case GL_LOW_FLOAT:
2657 case GL_MEDIUM_FLOAT:
2658 case GL_HIGH_FLOAT:
2659 // Assume IEEE 754 precision
2660 range[0] = 127;
2661 range[1] = 127;
2662 *precision = 23;
2663 break;
2664 case GL_LOW_INT:
2665 case GL_MEDIUM_INT:
2666 case GL_HIGH_INT:
2667 // Some (most) hardware only supports single-precision floating-point numbers,
2668 // which can accurately represent integers up to +/-16777216
2669 range[0] = 24;
2670 range[1] = 24;
2671 *precision = 0;
2672 break;
2673 default:
2674 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002675 }
2676}
2677
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002678void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002680 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002681 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002682
Geoff Langbfdea662014-07-23 14:16:32 -04002683 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002684 {
Geoff Langbfdea662014-07-23 14:16:32 -04002685 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002686 }
Geoff Langbfdea662014-07-23 14:16:32 -04002687
2688 gl::Context *context = gl::getNonLostContext();
2689
2690 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002691 {
Geoff Langbfdea662014-07-23 14:16:32 -04002692 gl::Shader *shaderObject = context->getShader(shader);
2693
2694 if (!shaderObject)
2695 {
2696 return gl::error(GL_INVALID_OPERATION);
2697 }
2698
2699 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002700 }
2701}
2702
zmo@google.coma574f782011-10-03 21:45:23 +00002703void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2704{
2705 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2706 shader, bufsize, length, source);
2707
Geoff Langbfdea662014-07-23 14:16:32 -04002708 if (bufsize < 0)
zmo@google.coma574f782011-10-03 21:45:23 +00002709 {
Geoff Langbfdea662014-07-23 14:16:32 -04002710 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00002711 }
Geoff Langbfdea662014-07-23 14:16:32 -04002712
2713 gl::Context *context = gl::getNonLostContext();
2714
2715 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002716 {
Geoff Langbfdea662014-07-23 14:16:32 -04002717 gl::Shader *shaderObject = context->getShader(shader);
2718
2719 if (!shaderObject)
2720 {
2721 return gl::error(GL_INVALID_OPERATION);
2722 }
2723
2724 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002725 }
2726}
2727
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002728const GLubyte* __stdcall glGetString(GLenum name)
2729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002730 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002731
Geoff Langbfdea662014-07-23 14:16:32 -04002732 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002733
Geoff Langbfdea662014-07-23 14:16:32 -04002734 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735 {
Geoff Langbfdea662014-07-23 14:16:32 -04002736 case GL_VENDOR:
2737 return (GLubyte*)"Google Inc.";
2738 case GL_RENDERER:
2739 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
2740 case GL_VERSION:
2741 if (context->getClientVersion() == 2)
2742 {
2743 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2744 }
2745 else
2746 {
2747 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2748 }
2749 case GL_SHADING_LANGUAGE_VERSION:
2750 if (context->getClientVersion() == 2)
2751 {
2752 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2753 }
2754 else
2755 {
2756 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2757 }
2758 case GL_EXTENSIONS:
2759 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
2760 default:
2761 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002763}
2764
2765void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2766{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002767 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002768
Geoff Langbfdea662014-07-23 14:16:32 -04002769 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002770
Geoff Langbfdea662014-07-23 14:16:32 -04002771 if (context)
2772 {
2773 gl::Texture *texture = context->getTargetTexture(target);
2774
2775 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002776 {
Geoff Langbfdea662014-07-23 14:16:32 -04002777 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002778 }
Geoff Langbfdea662014-07-23 14:16:32 -04002779
2780 switch (pname)
2781 {
2782 case GL_TEXTURE_MAG_FILTER:
2783 *params = (GLfloat)texture->getSamplerState().magFilter;
2784 break;
2785 case GL_TEXTURE_MIN_FILTER:
2786 *params = (GLfloat)texture->getSamplerState().minFilter;
2787 break;
2788 case GL_TEXTURE_WRAP_S:
2789 *params = (GLfloat)texture->getSamplerState().wrapS;
2790 break;
2791 case GL_TEXTURE_WRAP_T:
2792 *params = (GLfloat)texture->getSamplerState().wrapT;
2793 break;
2794 case GL_TEXTURE_WRAP_R:
2795 if (context->getClientVersion() < 3)
2796 {
2797 return gl::error(GL_INVALID_ENUM);
2798 }
2799 *params = (GLfloat)texture->getSamplerState().wrapR;
2800 break;
2801 case GL_TEXTURE_IMMUTABLE_FORMAT:
2802 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2803 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2804 break;
2805 case GL_TEXTURE_IMMUTABLE_LEVELS:
2806 if (context->getClientVersion() < 3)
2807 {
2808 return gl::error(GL_INVALID_ENUM);
2809 }
2810 *params = (GLfloat)texture->immutableLevelCount();
2811 break;
2812 case GL_TEXTURE_USAGE_ANGLE:
2813 *params = (GLfloat)texture->getUsage();
2814 break;
2815 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2816 if (!context->getExtensions().textureFilterAnisotropic)
2817 {
2818 return gl::error(GL_INVALID_ENUM);
2819 }
2820 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2821 break;
2822 case GL_TEXTURE_SWIZZLE_R:
2823 if (context->getClientVersion() < 3)
2824 {
2825 return gl::error(GL_INVALID_ENUM);
2826 }
2827 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2828 break;
2829 case GL_TEXTURE_SWIZZLE_G:
2830 if (context->getClientVersion() < 3)
2831 {
2832 return gl::error(GL_INVALID_ENUM);
2833 }
2834 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2835 break;
2836 case GL_TEXTURE_SWIZZLE_B:
2837 if (context->getClientVersion() < 3)
2838 {
2839 return gl::error(GL_INVALID_ENUM);
2840 }
2841 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2842 break;
2843 case GL_TEXTURE_SWIZZLE_A:
2844 if (context->getClientVersion() < 3)
2845 {
2846 return gl::error(GL_INVALID_ENUM);
2847 }
2848 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2849 break;
2850 case GL_TEXTURE_BASE_LEVEL:
2851 if (context->getClientVersion() < 3)
2852 {
2853 return gl::error(GL_INVALID_ENUM);
2854 }
2855 *params = (GLfloat)texture->getSamplerState().baseLevel;
2856 break;
2857 case GL_TEXTURE_MAX_LEVEL:
2858 if (context->getClientVersion() < 3)
2859 {
2860 return gl::error(GL_INVALID_ENUM);
2861 }
2862 *params = (GLfloat)texture->getSamplerState().maxLevel;
2863 break;
2864 case GL_TEXTURE_MIN_LOD:
2865 if (context->getClientVersion() < 3)
2866 {
2867 return gl::error(GL_INVALID_ENUM);
2868 }
2869 *params = texture->getSamplerState().minLod;
2870 break;
2871 case GL_TEXTURE_MAX_LOD:
2872 if (context->getClientVersion() < 3)
2873 {
2874 return gl::error(GL_INVALID_ENUM);
2875 }
2876 *params = texture->getSamplerState().maxLod;
2877 break;
2878 default:
2879 return gl::error(GL_INVALID_ENUM);
2880 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002881 }
2882}
2883
2884void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
2885{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002886 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002887
Geoff Langbfdea662014-07-23 14:16:32 -04002888 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002889
Geoff Langbfdea662014-07-23 14:16:32 -04002890 if (context)
2891 {
2892 gl::Texture *texture = context->getTargetTexture(target);
2893
2894 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002895 {
Geoff Langbfdea662014-07-23 14:16:32 -04002896 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002897 }
Geoff Langbfdea662014-07-23 14:16:32 -04002898
2899 switch (pname)
2900 {
2901 case GL_TEXTURE_MAG_FILTER:
2902 *params = texture->getSamplerState().magFilter;
2903 break;
2904 case GL_TEXTURE_MIN_FILTER:
2905 *params = texture->getSamplerState().minFilter;
2906 break;
2907 case GL_TEXTURE_WRAP_S:
2908 *params = texture->getSamplerState().wrapS;
2909 break;
2910 case GL_TEXTURE_WRAP_T:
2911 *params = texture->getSamplerState().wrapT;
2912 break;
2913 case GL_TEXTURE_WRAP_R:
2914 if (context->getClientVersion() < 3)
2915 {
2916 return gl::error(GL_INVALID_ENUM);
2917 }
2918 *params = texture->getSamplerState().wrapR;
2919 break;
2920 case GL_TEXTURE_IMMUTABLE_FORMAT:
2921 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2922 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
2923 break;
2924 case GL_TEXTURE_IMMUTABLE_LEVELS:
2925 if (context->getClientVersion() < 3)
2926 {
2927 return gl::error(GL_INVALID_ENUM);
2928 }
2929 *params = texture->immutableLevelCount();
2930 break;
2931 case GL_TEXTURE_USAGE_ANGLE:
2932 *params = texture->getUsage();
2933 break;
2934 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2935 if (!context->getExtensions().textureFilterAnisotropic)
2936 {
2937 return gl::error(GL_INVALID_ENUM);
2938 }
2939 *params = (GLint)texture->getSamplerState().maxAnisotropy;
2940 break;
2941 case GL_TEXTURE_SWIZZLE_R:
2942 if (context->getClientVersion() < 3)
2943 {
2944 return gl::error(GL_INVALID_ENUM);
2945 }
2946 *params = texture->getSamplerState().swizzleRed;
2947 break;
2948 case GL_TEXTURE_SWIZZLE_G:
2949 if (context->getClientVersion() < 3)
2950 {
2951 return gl::error(GL_INVALID_ENUM);
2952 }
2953 *params = texture->getSamplerState().swizzleGreen;
2954 break;
2955 case GL_TEXTURE_SWIZZLE_B:
2956 if (context->getClientVersion() < 3)
2957 {
2958 return gl::error(GL_INVALID_ENUM);
2959 }
2960 *params = texture->getSamplerState().swizzleBlue;
2961 break;
2962 case GL_TEXTURE_SWIZZLE_A:
2963 if (context->getClientVersion() < 3)
2964 {
2965 return gl::error(GL_INVALID_ENUM);
2966 }
2967 *params = texture->getSamplerState().swizzleAlpha;
2968 break;
2969 case GL_TEXTURE_BASE_LEVEL:
2970 if (context->getClientVersion() < 3)
2971 {
2972 return gl::error(GL_INVALID_ENUM);
2973 }
2974 *params = texture->getSamplerState().baseLevel;
2975 break;
2976 case GL_TEXTURE_MAX_LEVEL:
2977 if (context->getClientVersion() < 3)
2978 {
2979 return gl::error(GL_INVALID_ENUM);
2980 }
2981 *params = texture->getSamplerState().maxLevel;
2982 break;
2983 case GL_TEXTURE_MIN_LOD:
2984 if (context->getClientVersion() < 3)
2985 {
2986 return gl::error(GL_INVALID_ENUM);
2987 }
2988 *params = (GLint)texture->getSamplerState().minLod;
2989 break;
2990 case GL_TEXTURE_MAX_LOD:
2991 if (context->getClientVersion() < 3)
2992 {
2993 return gl::error(GL_INVALID_ENUM);
2994 }
2995 *params = (GLint)texture->getSamplerState().maxLod;
2996 break;
2997 default:
2998 return gl::error(GL_INVALID_ENUM);
2999 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003000 }
3001}
3002
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003003void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3004{
3005 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3006 program, location, bufSize, params);
3007
Geoff Langbfdea662014-07-23 14:16:32 -04003008 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003009 {
Geoff Langbfdea662014-07-23 14:16:32 -04003010 return gl::error(GL_INVALID_VALUE);
3011 }
3012
3013 gl::Context *context = gl::getNonLostContext();
3014
3015 if (context)
3016 {
3017 if (program == 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003019 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003020 }
3021
Geoff Langbfdea662014-07-23 14:16:32 -04003022 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003023
Geoff Langbfdea662014-07-23 14:16:32 -04003024 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003025 {
Geoff Langbfdea662014-07-23 14:16:32 -04003026 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003027 }
Geoff Langbfdea662014-07-23 14:16:32 -04003028
3029 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3030 if (!programBinary)
3031 {
3032 return gl::error(GL_INVALID_OPERATION);
3033 }
3034
3035 if (!programBinary->getUniformfv(location, &bufSize, params))
3036 {
3037 return gl::error(GL_INVALID_OPERATION);
3038 }
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003039 }
3040}
3041
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003042void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3043{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003044 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003045
Geoff Langbfdea662014-07-23 14:16:32 -04003046 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003047
Geoff Langbfdea662014-07-23 14:16:32 -04003048 if (context)
3049 {
3050 if (program == 0)
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003051 {
Geoff Langbfdea662014-07-23 14:16:32 -04003052 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003053 }
Geoff Langbfdea662014-07-23 14:16:32 -04003054
3055 gl::Program *programObject = context->getProgram(program);
3056
3057 if (!programObject || !programObject->isLinked())
3058 {
3059 return gl::error(GL_INVALID_OPERATION);
3060 }
3061
3062 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3063 if (!programBinary)
3064 {
3065 return gl::error(GL_INVALID_OPERATION);
3066 }
3067
3068 if (!programBinary->getUniformfv(location, NULL, params))
3069 {
3070 return gl::error(GL_INVALID_OPERATION);
3071 }
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003072 }
3073}
3074
3075void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3076{
Geoff Langbfdea662014-07-23 14:16:32 -04003077 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003078 program, location, bufSize, params);
3079
Geoff Langbfdea662014-07-23 14:16:32 -04003080 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003081 {
Geoff Langbfdea662014-07-23 14:16:32 -04003082 return gl::error(GL_INVALID_VALUE);
3083 }
3084
3085 gl::Context *context = gl::getNonLostContext();
3086
3087 if (context)
3088 {
3089 if (program == 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003090 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003091 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003092 }
3093
Geoff Langbfdea662014-07-23 14:16:32 -04003094 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003095
Geoff Langbfdea662014-07-23 14:16:32 -04003096 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003097 {
Geoff Langbfdea662014-07-23 14:16:32 -04003098 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003099 }
Geoff Langbfdea662014-07-23 14:16:32 -04003100
3101 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3102 if (!programBinary)
3103 {
3104 return gl::error(GL_INVALID_OPERATION);
3105 }
3106
3107 if (!programBinary->getUniformiv(location, &bufSize, params))
3108 {
3109 return gl::error(GL_INVALID_OPERATION);
3110 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003111 }
3112}
3113
3114void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3115{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003116 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003117
Geoff Langbfdea662014-07-23 14:16:32 -04003118 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003119
Geoff Langbfdea662014-07-23 14:16:32 -04003120 if (context)
3121 {
3122 if (program == 0)
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003123 {
Geoff Langbfdea662014-07-23 14:16:32 -04003124 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003125 }
Geoff Langbfdea662014-07-23 14:16:32 -04003126
3127 gl::Program *programObject = context->getProgram(program);
3128
3129 if (!programObject || !programObject->isLinked())
3130 {
3131 return gl::error(GL_INVALID_OPERATION);
3132 }
3133
3134 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3135 if (!programBinary)
3136 {
3137 return gl::error(GL_INVALID_OPERATION);
3138 }
3139
3140 if (!programBinary->getUniformiv(location, NULL, params))
3141 {
3142 return gl::error(GL_INVALID_OPERATION);
3143 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003144 }
3145}
3146
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003147int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003149 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003150
Geoff Langbfdea662014-07-23 14:16:32 -04003151 gl::Context *context = gl::getNonLostContext();
3152
3153 if (strstr(name, "gl_") == name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003154 {
Geoff Langbfdea662014-07-23 14:16:32 -04003155 return -1;
3156 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003157
Geoff Langbfdea662014-07-23 14:16:32 -04003158 if (context)
3159 {
3160 gl::Program *programObject = context->getProgram(program);
3161
3162 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003163 {
Geoff Langbfdea662014-07-23 14:16:32 -04003164 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003166 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003167 }
Geoff Langbfdea662014-07-23 14:16:32 -04003168 else
3169 {
3170 return gl::error(GL_INVALID_VALUE, -1);
3171 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003172 }
Geoff Langbfdea662014-07-23 14:16:32 -04003173
3174 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3175 if (!programObject->isLinked() || !programBinary)
3176 {
3177 return gl::error(GL_INVALID_OPERATION, -1);
3178 }
3179
3180 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003181 }
3182
3183 return -1;
3184}
3185
3186void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3187{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003188 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003189
Geoff Langbfdea662014-07-23 14:16:32 -04003190 gl::Context *context = gl::getNonLostContext();
3191
3192 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003193 {
Geoff Langbfdea662014-07-23 14:16:32 -04003194 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003195 {
Geoff Langbfdea662014-07-23 14:16:32 -04003196 return gl::error(GL_INVALID_VALUE);
3197 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003198
Geoff Langbfdea662014-07-23 14:16:32 -04003199 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
3200 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3201 {
3202 return;
3203 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003204
Geoff Langbfdea662014-07-23 14:16:32 -04003205 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3206 {
3207 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3208 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003209 {
Geoff Langbfdea662014-07-23 14:16:32 -04003210 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003211 }
3212 }
Geoff Langbfdea662014-07-23 14:16:32 -04003213 else
3214 {
3215 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3216 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003217 }
3218}
3219
3220void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3221{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003222 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003223
Geoff Langbfdea662014-07-23 14:16:32 -04003224 gl::Context *context = gl::getNonLostContext();
3225
3226 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003227 {
Geoff Langbfdea662014-07-23 14:16:32 -04003228 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003229 {
Geoff Langbfdea662014-07-23 14:16:32 -04003230 return gl::error(GL_INVALID_VALUE);
3231 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003232
Geoff Langbfdea662014-07-23 14:16:32 -04003233 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003234
Geoff Langbfdea662014-07-23 14:16:32 -04003235 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3236 {
3237 return;
3238 }
Jamie Madillaff71502013-07-02 11:57:05 -04003239
Geoff Langbfdea662014-07-23 14:16:32 -04003240 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3241 {
3242 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3243 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003244 {
Geoff Langbfdea662014-07-23 14:16:32 -04003245 float currentValue = currentValueData.FloatValues[i];
3246 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003247 }
3248 }
Geoff Langbfdea662014-07-23 14:16:32 -04003249 else
3250 {
3251 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3252 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003253 }
3254}
3255
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003256void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003257{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003258 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003259
Geoff Langbfdea662014-07-23 14:16:32 -04003260 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003261
Geoff Langbfdea662014-07-23 14:16:32 -04003262 if (context)
3263 {
3264 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003265 {
Geoff Langbfdea662014-07-23 14:16:32 -04003266 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003267 }
Geoff Langbfdea662014-07-23 14:16:32 -04003268
3269 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3270 {
3271 return gl::error(GL_INVALID_ENUM);
3272 }
3273
3274 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003275 }
3276}
3277
3278void __stdcall glHint(GLenum target, GLenum mode)
3279{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003280 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003281
Geoff Langbfdea662014-07-23 14:16:32 -04003282 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003283 {
Geoff Langbfdea662014-07-23 14:16:32 -04003284 case GL_FASTEST:
3285 case GL_NICEST:
3286 case GL_DONT_CARE:
3287 break;
3288 default:
3289 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003290 }
Geoff Langbfdea662014-07-23 14:16:32 -04003291
3292 gl::Context *context = gl::getNonLostContext();
3293 switch (target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003294 {
Geoff Langbfdea662014-07-23 14:16:32 -04003295 case GL_GENERATE_MIPMAP_HINT:
3296 if (context) context->getState().setGenerateMipmapHint(mode);
3297 break;
3298 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3299 if (context) context->getState().setFragmentShaderDerivativeHint(mode);
3300 break;
3301 default:
3302 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003303 }
3304}
3305
3306GLboolean __stdcall glIsBuffer(GLuint buffer)
3307{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003308 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003309
Geoff Langbfdea662014-07-23 14:16:32 -04003310 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003311
Geoff Langbfdea662014-07-23 14:16:32 -04003312 if (context && buffer)
3313 {
3314 gl::Buffer *bufferObject = context->getBuffer(buffer);
3315
3316 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003317 {
Geoff Langbfdea662014-07-23 14:16:32 -04003318 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003319 }
3320 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003321
3322 return GL_FALSE;
3323}
3324
3325GLboolean __stdcall glIsEnabled(GLenum cap)
3326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003327 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
Geoff Langbfdea662014-07-23 14:16:32 -04003329 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003330
Geoff Langbfdea662014-07-23 14:16:32 -04003331 if (context)
3332 {
3333 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334 {
Geoff Langbfdea662014-07-23 14:16:32 -04003335 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003336 }
Geoff Langbfdea662014-07-23 14:16:32 -04003337
3338 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003339 }
3340
3341 return false;
3342}
3343
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003344GLboolean __stdcall glIsFenceNV(GLuint fence)
3345{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003346 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003347
Geoff Langbfdea662014-07-23 14:16:32 -04003348 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003349
Geoff Langbfdea662014-07-23 14:16:32 -04003350 if (context)
3351 {
3352 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3353
3354 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003355 {
Geoff Langbfdea662014-07-23 14:16:32 -04003356 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003357 }
Geoff Langbfdea662014-07-23 14:16:32 -04003358
3359 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003360 }
3361
3362 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003363}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003364
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003365GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3366{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003367 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003368
Geoff Langbfdea662014-07-23 14:16:32 -04003369 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003370
Geoff Langbfdea662014-07-23 14:16:32 -04003371 if (context && framebuffer)
3372 {
3373 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3374
3375 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003376 {
Geoff Langbfdea662014-07-23 14:16:32 -04003377 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003378 }
3379 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003380
3381 return GL_FALSE;
3382}
3383
3384GLboolean __stdcall glIsProgram(GLuint program)
3385{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003386 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003387
Geoff Langbfdea662014-07-23 14:16:32 -04003388 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003389
Geoff Langbfdea662014-07-23 14:16:32 -04003390 if (context && program)
3391 {
3392 gl::Program *programObject = context->getProgram(program);
3393
3394 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003395 {
Geoff Langbfdea662014-07-23 14:16:32 -04003396 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397 }
3398 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003399
3400 return GL_FALSE;
3401}
3402
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003403GLboolean __stdcall glIsQueryEXT(GLuint id)
3404{
3405 EVENT("(GLuint id = %d)", id);
3406
Geoff Langbfdea662014-07-23 14:16:32 -04003407 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003408
Geoff Langbfdea662014-07-23 14:16:32 -04003409 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003410 {
Geoff Langbfdea662014-07-23 14:16:32 -04003411 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003412 }
3413
3414 return GL_FALSE;
3415}
3416
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003417GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3418{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003419 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003420
Geoff Langbfdea662014-07-23 14:16:32 -04003421 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003422
Geoff Langbfdea662014-07-23 14:16:32 -04003423 if (context && renderbuffer)
3424 {
3425 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3426
3427 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428 {
Geoff Langbfdea662014-07-23 14:16:32 -04003429 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003430 }
3431 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003432
3433 return GL_FALSE;
3434}
3435
3436GLboolean __stdcall glIsShader(GLuint shader)
3437{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003438 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003439
Geoff Langbfdea662014-07-23 14:16:32 -04003440 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003441
Geoff Langbfdea662014-07-23 14:16:32 -04003442 if (context && shader)
3443 {
3444 gl::Shader *shaderObject = context->getShader(shader);
3445
3446 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003447 {
Geoff Langbfdea662014-07-23 14:16:32 -04003448 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449 }
3450 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003451
3452 return GL_FALSE;
3453}
3454
3455GLboolean __stdcall glIsTexture(GLuint texture)
3456{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003457 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003458
Geoff Langbfdea662014-07-23 14:16:32 -04003459 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003460
Geoff Langbfdea662014-07-23 14:16:32 -04003461 if (context && texture)
3462 {
3463 gl::Texture *textureObject = context->getTexture(texture);
3464
3465 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466 {
Geoff Langbfdea662014-07-23 14:16:32 -04003467 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468 }
3469 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003470
3471 return GL_FALSE;
3472}
3473
3474void __stdcall glLineWidth(GLfloat width)
3475{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003476 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003477
Geoff Langbfdea662014-07-23 14:16:32 -04003478 if (width <= 0.0f)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003479 {
Geoff Langbfdea662014-07-23 14:16:32 -04003480 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003481 }
Geoff Langbfdea662014-07-23 14:16:32 -04003482
3483 gl::Context *context = gl::getNonLostContext();
3484
3485 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003486 {
Geoff Langbfdea662014-07-23 14:16:32 -04003487 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003488 }
3489}
3490
3491void __stdcall glLinkProgram(GLuint program)
3492{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003493 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494
Geoff Langbfdea662014-07-23 14:16:32 -04003495 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003496
Geoff Langbfdea662014-07-23 14:16:32 -04003497 if (context)
3498 {
3499 gl::Program *programObject = context->getProgram(program);
3500
3501 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502 {
Geoff Langbfdea662014-07-23 14:16:32 -04003503 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003504 {
Geoff Langbfdea662014-07-23 14:16:32 -04003505 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003506 }
Geoff Langbfdea662014-07-23 14:16:32 -04003507 else
3508 {
3509 return gl::error(GL_INVALID_VALUE);
3510 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003511 }
Geoff Langbfdea662014-07-23 14:16:32 -04003512
3513 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003514 }
3515}
3516
3517void __stdcall glPixelStorei(GLenum pname, GLint param)
3518{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003519 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003520
Geoff Langbfdea662014-07-23 14:16:32 -04003521 gl::Context *context = gl::getNonLostContext();
3522
3523 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003524 {
Geoff Langbfdea662014-07-23 14:16:32 -04003525 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526 {
Geoff Langbfdea662014-07-23 14:16:32 -04003527 case GL_UNPACK_ALIGNMENT:
3528 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003529 {
Geoff Langbfdea662014-07-23 14:16:32 -04003530 return gl::error(GL_INVALID_VALUE);
3531 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003532
Geoff Langbfdea662014-07-23 14:16:32 -04003533 context->getState().setUnpackAlignment(param);
3534 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003535
Geoff Langbfdea662014-07-23 14:16:32 -04003536 case GL_PACK_ALIGNMENT:
3537 if (param != 1 && param != 2 && param != 4 && param != 8)
3538 {
3539 return gl::error(GL_INVALID_VALUE);
3540 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003541
Geoff Langbfdea662014-07-23 14:16:32 -04003542 context->getState().setPackAlignment(param);
3543 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003544
Geoff Langbfdea662014-07-23 14:16:32 -04003545 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3546 context->getState().setPackReverseRowOrder(param != 0);
3547 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003548
Geoff Langbfdea662014-07-23 14:16:32 -04003549 case GL_UNPACK_IMAGE_HEIGHT:
3550 case GL_UNPACK_SKIP_IMAGES:
3551 case GL_UNPACK_ROW_LENGTH:
3552 case GL_UNPACK_SKIP_ROWS:
3553 case GL_UNPACK_SKIP_PIXELS:
3554 case GL_PACK_ROW_LENGTH:
3555 case GL_PACK_SKIP_ROWS:
3556 case GL_PACK_SKIP_PIXELS:
3557 if (context->getClientVersion() < 3)
3558 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003559 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003560 }
Geoff Langbfdea662014-07-23 14:16:32 -04003561 UNIMPLEMENTED();
3562 break;
3563
3564 default:
3565 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003566 }
3567 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568}
3569
3570void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003572 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003573
Geoff Langbfdea662014-07-23 14:16:32 -04003574 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00003575
Geoff Langbfdea662014-07-23 14:16:32 -04003576 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003577 {
Geoff Langbfdea662014-07-23 14:16:32 -04003578 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003579 }
3580}
3581
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003582void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3583 GLenum format, GLenum type, GLsizei bufSize,
3584 GLvoid *data)
3585{
3586 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3587 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3588 x, y, width, height, format, type, bufSize, data);
3589
Geoff Langbfdea662014-07-23 14:16:32 -04003590 if (width < 0 || height < 0 || bufSize < 0)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003591 {
Geoff Langbfdea662014-07-23 14:16:32 -04003592 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003593 }
Geoff Langbfdea662014-07-23 14:16:32 -04003594
3595 gl::Context *context = gl::getNonLostContext();
3596
3597 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003598 {
Geoff Langbfdea662014-07-23 14:16:32 -04003599 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3600 format, type, &bufSize, data))
3601 {
3602 return;
3603 }
3604
3605 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003606 }
3607}
3608
3609void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3610 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003611{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003612 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003613 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003614 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003615
Geoff Langbfdea662014-07-23 14:16:32 -04003616 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617 {
Geoff Langbfdea662014-07-23 14:16:32 -04003618 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003619 }
Geoff Langbfdea662014-07-23 14:16:32 -04003620
3621 gl::Context *context = gl::getNonLostContext();
3622
3623 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003624 {
Geoff Langbfdea662014-07-23 14:16:32 -04003625 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3626 format, type, NULL, pixels))
3627 {
3628 return;
3629 }
3630
3631 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003632 }
3633}
3634
3635void __stdcall glReleaseShaderCompiler(void)
3636{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003637 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003638
Geoff Langbfdea662014-07-23 14:16:32 -04003639 gl::Shader::releaseCompiler();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640}
3641
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003642void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003643{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003644 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 +00003645 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003646
Geoff Langbfdea662014-07-23 14:16:32 -04003647 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003648
Geoff Langbfdea662014-07-23 14:16:32 -04003649 if (context)
3650 {
3651 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3652 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003653 {
Geoff Langbfdea662014-07-23 14:16:32 -04003654 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003655 }
Geoff Langbfdea662014-07-23 14:16:32 -04003656
3657 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003658 }
3659}
3660
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003661void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3662{
3663 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3664}
3665
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003666void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3667{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003668 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003669
Geoff Langbfdea662014-07-23 14:16:32 -04003670 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003671
Geoff Langbfdea662014-07-23 14:16:32 -04003672 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003673 {
Geoff Langbfdea662014-07-23 14:16:32 -04003674 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003675 }
3676}
3677
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003678void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003680 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003681
Geoff Langbfdea662014-07-23 14:16:32 -04003682 if (condition != GL_ALL_COMPLETED_NV)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003683 {
Geoff Langbfdea662014-07-23 14:16:32 -04003684 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003685 }
Geoff Langbfdea662014-07-23 14:16:32 -04003686
3687 gl::Context *context = gl::getNonLostContext();
3688
3689 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003690 {
Geoff Langbfdea662014-07-23 14:16:32 -04003691 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3692
3693 if (fenceObject == NULL)
3694 {
3695 return gl::error(GL_INVALID_OPERATION);
3696 }
3697
3698 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003699 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003700}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003701
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003702void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3703{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003704 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 +00003705
Geoff Langbfdea662014-07-23 14:16:32 -04003706 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003707 {
Geoff Langbfdea662014-07-23 14:16:32 -04003708 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003709 }
Geoff Langbfdea662014-07-23 14:16:32 -04003710
3711 gl::Context* context = gl::getNonLostContext();
3712
3713 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003714 {
Geoff Langbfdea662014-07-23 14:16:32 -04003715 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003716 }
3717}
3718
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003719void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003720{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003721 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003722 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003723 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003724
Geoff Lang900013c2014-07-07 11:32:19 -04003725 gl::Context* context = gl::getNonLostContext();
3726 if (context)
3727 {
3728 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3729 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3730 {
3731 return gl::error(GL_INVALID_ENUM);
3732 }
3733
3734 // No binary shader formats are supported.
3735 UNIMPLEMENTED();
3736 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003737}
3738
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003739void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003740{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003741 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 +00003742 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743
Geoff Langbfdea662014-07-23 14:16:32 -04003744 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003745 {
Geoff Langbfdea662014-07-23 14:16:32 -04003746 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003747 }
Geoff Langbfdea662014-07-23 14:16:32 -04003748
3749 gl::Context *context = gl::getNonLostContext();
3750
3751 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003752 {
Geoff Langbfdea662014-07-23 14:16:32 -04003753 gl::Shader *shaderObject = context->getShader(shader);
3754
3755 if (!shaderObject)
3756 {
3757 if (context->getProgram(shader))
3758 {
3759 return gl::error(GL_INVALID_OPERATION);
3760 }
3761 else
3762 {
3763 return gl::error(GL_INVALID_VALUE);
3764 }
3765 }
3766
3767 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003768 }
3769}
3770
3771void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3772{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003773 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003774}
3775
3776void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3777{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003778 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 +00003779
Geoff Langbfdea662014-07-23 14:16:32 -04003780 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003781 {
Geoff Langbfdea662014-07-23 14:16:32 -04003782 case GL_FRONT:
3783 case GL_BACK:
3784 case GL_FRONT_AND_BACK:
3785 break;
3786 default:
3787 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003788 }
Geoff Langbfdea662014-07-23 14:16:32 -04003789
3790 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003791 {
Geoff Langbfdea662014-07-23 14:16:32 -04003792 case GL_NEVER:
3793 case GL_ALWAYS:
3794 case GL_LESS:
3795 case GL_LEQUAL:
3796 case GL_EQUAL:
3797 case GL_GEQUAL:
3798 case GL_GREATER:
3799 case GL_NOTEQUAL:
3800 break;
3801 default:
3802 return gl::error(GL_INVALID_ENUM);
3803 }
3804
3805 gl::Context *context = gl::getNonLostContext();
3806
3807 if (context)
3808 {
3809 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3810 {
3811 context->getState().setStencilParams(func, ref, mask);
3812 }
3813
3814 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3815 {
3816 context->getState().setStencilBackParams(func, ref, mask);
3817 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003818 }
3819}
3820
3821void __stdcall glStencilMask(GLuint mask)
3822{
3823 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3824}
3825
3826void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3827{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003828 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003829
Geoff Langbfdea662014-07-23 14:16:32 -04003830 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003831 {
Geoff Langbfdea662014-07-23 14:16:32 -04003832 case GL_FRONT:
3833 case GL_BACK:
3834 case GL_FRONT_AND_BACK:
3835 break;
3836 default:
3837 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838 }
Geoff Langbfdea662014-07-23 14:16:32 -04003839
3840 gl::Context *context = gl::getNonLostContext();
3841
3842 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003843 {
Geoff Langbfdea662014-07-23 14:16:32 -04003844 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3845 {
3846 context->getState().setStencilWritemask(mask);
3847 }
3848
3849 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3850 {
3851 context->getState().setStencilBackWritemask(mask);
3852 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003853 }
3854}
3855
3856void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3857{
3858 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3859}
3860
3861void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3862{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003863 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 +00003864 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003865
Geoff Langbfdea662014-07-23 14:16:32 -04003866 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003867 {
Geoff Langbfdea662014-07-23 14:16:32 -04003868 case GL_FRONT:
3869 case GL_BACK:
3870 case GL_FRONT_AND_BACK:
3871 break;
3872 default:
3873 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003874 }
Geoff Langbfdea662014-07-23 14:16:32 -04003875
3876 switch (fail)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003877 {
Geoff Langbfdea662014-07-23 14:16:32 -04003878 case GL_ZERO:
3879 case GL_KEEP:
3880 case GL_REPLACE:
3881 case GL_INCR:
3882 case GL_DECR:
3883 case GL_INVERT:
3884 case GL_INCR_WRAP:
3885 case GL_DECR_WRAP:
3886 break;
3887 default:
3888 return gl::error(GL_INVALID_ENUM);
3889 }
3890
3891 switch (zfail)
3892 {
3893 case GL_ZERO:
3894 case GL_KEEP:
3895 case GL_REPLACE:
3896 case GL_INCR:
3897 case GL_DECR:
3898 case GL_INVERT:
3899 case GL_INCR_WRAP:
3900 case GL_DECR_WRAP:
3901 break;
3902 default:
3903 return gl::error(GL_INVALID_ENUM);
3904 }
3905
3906 switch (zpass)
3907 {
3908 case GL_ZERO:
3909 case GL_KEEP:
3910 case GL_REPLACE:
3911 case GL_INCR:
3912 case GL_DECR:
3913 case GL_INVERT:
3914 case GL_INCR_WRAP:
3915 case GL_DECR_WRAP:
3916 break;
3917 default:
3918 return gl::error(GL_INVALID_ENUM);
3919 }
3920
3921 gl::Context *context = gl::getNonLostContext();
3922
3923 if (context)
3924 {
3925 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3926 {
3927 context->getState().setStencilOperations(fail, zfail, zpass);
3928 }
3929
3930 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3931 {
3932 context->getState().setStencilBackOperations(fail, zfail, zpass);
3933 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003934 }
3935}
3936
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003937GLboolean __stdcall glTestFenceNV(GLuint fence)
3938{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003939 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003940
Geoff Langbfdea662014-07-23 14:16:32 -04003941 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003942
Geoff Langbfdea662014-07-23 14:16:32 -04003943 if (context)
3944 {
3945 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3946
3947 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003948 {
Geoff Langbfdea662014-07-23 14:16:32 -04003949 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003950 }
Geoff Langbfdea662014-07-23 14:16:32 -04003951
3952 if (fenceObject->isFence() != GL_TRUE)
3953 {
3954 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
3955 }
3956
3957 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003958 }
Geoff Langbfdea662014-07-23 14:16:32 -04003959
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003960 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003961}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003962
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003963void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
3964 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003965{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003966 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05003967 "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 +00003968 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003969
Geoff Langbfdea662014-07-23 14:16:32 -04003970 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003971
Geoff Langbfdea662014-07-23 14:16:32 -04003972 if (context)
3973 {
3974 if (context->getClientVersion() < 3 &&
3975 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
3976 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003977 {
Geoff Langbfdea662014-07-23 14:16:32 -04003978 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003979 }
Geoff Langbfdea662014-07-23 14:16:32 -04003980
3981 if (context->getClientVersion() >= 3 &&
3982 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
3983 0, 0, 0, width, height, 1, border, format, type, pixels))
3984 {
3985 return;
3986 }
3987
3988 switch (target)
3989 {
3990 case GL_TEXTURE_2D:
3991 {
3992 gl::Texture2D *texture = context->getTexture2D();
3993 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3994 }
3995 break;
3996 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3997 {
3998 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3999 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4000 }
4001 break;
4002 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4003 {
4004 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4005 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4006 }
4007 break;
4008 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4009 {
4010 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4011 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4012 }
4013 break;
4014 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4015 {
4016 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4017 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4018 }
4019 break;
4020 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4021 {
4022 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4023 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4024 }
4025 break;
4026 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4027 {
4028 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4029 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4030 }
4031 break;
4032 default: UNREACHABLE();
4033 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004034 }
4035}
4036
4037void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4038{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004039 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4040
Geoff Langbfdea662014-07-23 14:16:32 -04004041 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004042
Geoff Langbfdea662014-07-23 14:16:32 -04004043 if (context)
4044 {
4045 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004046 {
Geoff Langbfdea662014-07-23 14:16:32 -04004047 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004048 }
Geoff Langbfdea662014-07-23 14:16:32 -04004049
4050 gl::Texture *texture = context->getTargetTexture(target);
4051
4052 if (!texture)
4053 {
4054 return gl::error(GL_INVALID_ENUM);
4055 }
4056
4057 switch (pname)
4058 {
4059 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4060 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4061 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4062 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4063 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4064 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4065 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4066 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4067 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4068 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4069 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4070 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4071 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4072 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4073 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4074 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4075 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4076 default: UNREACHABLE(); break;
4077 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004078 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004079}
4080
4081void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4082{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004083 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004084}
4085
4086void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4087{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004088 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004089
Geoff Langbfdea662014-07-23 14:16:32 -04004090 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004091
Geoff Langbfdea662014-07-23 14:16:32 -04004092 if (context)
4093 {
4094 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004095 {
Geoff Langbfdea662014-07-23 14:16:32 -04004096 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004097 }
Geoff Langbfdea662014-07-23 14:16:32 -04004098
4099 gl::Texture *texture = context->getTargetTexture(target);
4100
4101 if (!texture)
4102 {
4103 return gl::error(GL_INVALID_ENUM);
4104 }
4105
4106 switch (pname)
4107 {
4108 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4109 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4110 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4111 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4112 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4113 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4114 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4115 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4116 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4117 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4118 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4119 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4120 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4121 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4122 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4123 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4124 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4125 default: UNREACHABLE(); break;
4126 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004127 }
4128}
4129
4130void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4131{
4132 glTexParameteri(target, pname, *params);
4133}
4134
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004135void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4136{
4137 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4138 target, levels, internalformat, width, height);
4139
Geoff Langbfdea662014-07-23 14:16:32 -04004140 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004141
Geoff Langbfdea662014-07-23 14:16:32 -04004142 if (context)
4143 {
4144 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004145 {
Geoff Langbfdea662014-07-23 14:16:32 -04004146 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004147 }
Geoff Langbfdea662014-07-23 14:16:32 -04004148
4149 if (context->getClientVersion() < 3 &&
4150 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4151 {
4152 return;
4153 }
4154
4155 if (context->getClientVersion() >= 3 &&
4156 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4157 {
4158 return;
4159 }
4160
4161 switch (target)
4162 {
4163 case GL_TEXTURE_2D:
4164 {
4165 gl::Texture2D *texture2d = context->getTexture2D();
4166 texture2d->storage(levels, internalformat, width, height);
4167 }
4168 break;
4169
4170 case GL_TEXTURE_CUBE_MAP:
4171 {
4172 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4173 textureCube->storage(levels, internalformat, width);
4174 }
4175 break;
4176
4177 default:
4178 return gl::error(GL_INVALID_ENUM);
4179 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004180 }
4181}
4182
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004183void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4184 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004185{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004186 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004187 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004188 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004189 target, level, xoffset, yoffset, width, height, format, type, pixels);
4190
Geoff Langbfdea662014-07-23 14:16:32 -04004191 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004192
Geoff Langbfdea662014-07-23 14:16:32 -04004193 if (context)
4194 {
4195 if (context->getClientVersion() < 3 &&
4196 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4197 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004198 {
Geoff Langbfdea662014-07-23 14:16:32 -04004199 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004200 }
Geoff Langbfdea662014-07-23 14:16:32 -04004201
4202 if (context->getClientVersion() >= 3 &&
4203 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4204 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4205 {
4206 return;
4207 }
4208
4209 // Zero sized uploads are valid but no-ops
4210 if (width == 0 || height == 0)
4211 {
4212 return;
4213 }
4214
4215 switch (target)
4216 {
4217 case GL_TEXTURE_2D:
4218 {
4219 gl::Texture2D *texture = context->getTexture2D();
4220 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4221 }
4222 break;
4223
4224 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4225 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4226 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4227 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4228 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4229 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4230 {
4231 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4232 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4233 }
4234 break;
4235
4236 default:
4237 UNREACHABLE();
4238 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004239 }
4240}
4241
4242void __stdcall glUniform1f(GLint location, GLfloat x)
4243{
4244 glUniform1fv(location, 1, &x);
4245}
4246
4247void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4248{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004249 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004250
Geoff Langbfdea662014-07-23 14:16:32 -04004251 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004252
Geoff Langbfdea662014-07-23 14:16:32 -04004253 if (context)
4254 {
4255 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004256 {
Geoff Langbfdea662014-07-23 14:16:32 -04004257 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
Geoff Langbfdea662014-07-23 14:16:32 -04004259
4260 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4261 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004262 }
4263}
4264
4265void __stdcall glUniform1i(GLint location, GLint x)
4266{
4267 glUniform1iv(location, 1, &x);
4268}
4269
4270void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4271{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004272 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004273
Geoff Langbfdea662014-07-23 14:16:32 -04004274 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004275
Geoff Langbfdea662014-07-23 14:16:32 -04004276 if (context)
4277 {
4278 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004279 {
Geoff Langbfdea662014-07-23 14:16:32 -04004280 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004281 }
Geoff Langbfdea662014-07-23 14:16:32 -04004282
4283 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4284 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004285 }
4286}
4287
4288void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4289{
4290 GLfloat xy[2] = {x, y};
4291
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004292 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004293}
4294
4295void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4296{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004297 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004298
Geoff Langbfdea662014-07-23 14:16:32 -04004299 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004300
Geoff Langbfdea662014-07-23 14:16:32 -04004301 if (context)
4302 {
4303 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004304 {
Geoff Langbfdea662014-07-23 14:16:32 -04004305 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004306 }
Geoff Langbfdea662014-07-23 14:16:32 -04004307
4308 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4309 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004310 }
4311}
4312
4313void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4314{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004315 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004316
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004317 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004318}
4319
4320void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4321{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004322 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004323
Geoff Langbfdea662014-07-23 14:16:32 -04004324 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004325
Geoff Langbfdea662014-07-23 14:16:32 -04004326 if (context)
4327 {
4328 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004329 {
Geoff Langbfdea662014-07-23 14:16:32 -04004330 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004331 }
Geoff Langbfdea662014-07-23 14:16:32 -04004332
4333 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4334 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004335 }
4336}
4337
4338void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4339{
4340 GLfloat xyz[3] = {x, y, z};
4341
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004342 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004343}
4344
4345void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4346{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004347 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004348
Geoff Langbfdea662014-07-23 14:16:32 -04004349 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004350
Geoff Langbfdea662014-07-23 14:16:32 -04004351 if (context)
4352 {
4353 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004354 {
Geoff Langbfdea662014-07-23 14:16:32 -04004355 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004356 }
Geoff Langbfdea662014-07-23 14:16:32 -04004357
4358 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4359 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004360 }
4361}
4362
4363void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4364{
4365 GLint xyz[3] = {x, y, z};
4366
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004367 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004368}
4369
4370void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4371{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004372 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004373
Geoff Langbfdea662014-07-23 14:16:32 -04004374 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004375
Geoff Langbfdea662014-07-23 14:16:32 -04004376 if (context)
4377 {
4378 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004379 {
Geoff Langbfdea662014-07-23 14:16:32 -04004380 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004381 }
Geoff Langbfdea662014-07-23 14:16:32 -04004382
4383 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4384 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004385 }
4386}
4387
4388void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4389{
4390 GLfloat xyzw[4] = {x, y, z, w};
4391
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004392 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004393}
4394
4395void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4396{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004397 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004398
Geoff Langbfdea662014-07-23 14:16:32 -04004399 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004400
Geoff Langbfdea662014-07-23 14:16:32 -04004401 if (context)
4402 {
4403 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004404 {
Geoff Langbfdea662014-07-23 14:16:32 -04004405 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004406 }
Geoff Langbfdea662014-07-23 14:16:32 -04004407
4408 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4409 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004410 }
4411}
4412
4413void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4414{
4415 GLint xyzw[4] = {x, y, z, w};
4416
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004417 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004418}
4419
4420void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4421{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004422 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004423
Geoff Langbfdea662014-07-23 14:16:32 -04004424 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004425
Geoff Langbfdea662014-07-23 14:16:32 -04004426 if (context)
4427 {
4428 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004429 {
Geoff Langbfdea662014-07-23 14:16:32 -04004430 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004431 }
Geoff Langbfdea662014-07-23 14:16:32 -04004432
4433 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4434 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004435 }
4436}
4437
4438void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4439{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004440 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004441 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442
Geoff Langbfdea662014-07-23 14:16:32 -04004443 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004444
Geoff Langbfdea662014-07-23 14:16:32 -04004445 if (context)
4446 {
4447 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004448 {
Geoff Langbfdea662014-07-23 14:16:32 -04004449 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450 }
Geoff Langbfdea662014-07-23 14:16:32 -04004451
4452 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4453 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454 }
4455}
4456
4457void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4458{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004459 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004460 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004461
Geoff Langbfdea662014-07-23 14:16:32 -04004462 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004463
Geoff Langbfdea662014-07-23 14:16:32 -04004464 if (context)
4465 {
4466 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004467 {
Geoff Langbfdea662014-07-23 14:16:32 -04004468 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004469 }
Geoff Langbfdea662014-07-23 14:16:32 -04004470
4471 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4472 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004473 }
4474}
4475
4476void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4477{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004478 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004479 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480
Geoff Langbfdea662014-07-23 14:16:32 -04004481 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004482
Geoff Langbfdea662014-07-23 14:16:32 -04004483 if (context)
4484 {
4485 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004486 {
Geoff Langbfdea662014-07-23 14:16:32 -04004487 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004488 }
Geoff Langbfdea662014-07-23 14:16:32 -04004489
4490 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4491 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004492 }
4493}
4494
4495void __stdcall glUseProgram(GLuint program)
4496{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004497 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004498
Geoff Langbfdea662014-07-23 14:16:32 -04004499 gl::Context *context = gl::getNonLostContext();
4500
4501 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004502 {
Geoff Langbfdea662014-07-23 14:16:32 -04004503 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004504
Geoff Langbfdea662014-07-23 14:16:32 -04004505 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004506 {
Geoff Langbfdea662014-07-23 14:16:32 -04004507 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004509 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004510 }
Geoff Langbfdea662014-07-23 14:16:32 -04004511 else
4512 {
4513 return gl::error(GL_INVALID_VALUE);
4514 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004515 }
Geoff Langbfdea662014-07-23 14:16:32 -04004516
4517 if (program != 0 && !programObject->isLinked())
4518 {
4519 return gl::error(GL_INVALID_OPERATION);
4520 }
4521
4522 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004523 }
4524}
4525
4526void __stdcall glValidateProgram(GLuint program)
4527{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004528 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004529
Geoff Langbfdea662014-07-23 14:16:32 -04004530 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004531
Geoff Langbfdea662014-07-23 14:16:32 -04004532 if (context)
4533 {
4534 gl::Program *programObject = context->getProgram(program);
4535
4536 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004537 {
Geoff Langbfdea662014-07-23 14:16:32 -04004538 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004539 {
Geoff Langbfdea662014-07-23 14:16:32 -04004540 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004541 }
Geoff Langbfdea662014-07-23 14:16:32 -04004542 else
4543 {
4544 return gl::error(GL_INVALID_VALUE);
4545 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004546 }
Geoff Langbfdea662014-07-23 14:16:32 -04004547
4548 programObject->validate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004549 }
4550}
4551
4552void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4553{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004554 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555
Geoff Langbfdea662014-07-23 14:16:32 -04004556 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557 {
Geoff Langbfdea662014-07-23 14:16:32 -04004558 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004559 }
Geoff Langbfdea662014-07-23 14:16:32 -04004560
4561 gl::Context *context = gl::getNonLostContext();
4562
4563 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004564 {
Geoff Langbfdea662014-07-23 14:16:32 -04004565 GLfloat vals[4] = { x, 0, 0, 1 };
4566 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004567 }
4568}
4569
4570void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004572 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573
Geoff Langbfdea662014-07-23 14:16:32 -04004574 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004575 {
Geoff Langbfdea662014-07-23 14:16:32 -04004576 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004577 }
Geoff Langbfdea662014-07-23 14:16:32 -04004578
4579 gl::Context *context = gl::getNonLostContext();
4580
4581 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004582 {
Geoff Langbfdea662014-07-23 14:16:32 -04004583 GLfloat vals[4] = { values[0], 0, 0, 1 };
4584 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004585 }
4586}
4587
4588void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4589{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004590 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004591
Geoff Langbfdea662014-07-23 14:16:32 -04004592 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004593 {
Geoff Langbfdea662014-07-23 14:16:32 -04004594 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004595 }
Geoff Langbfdea662014-07-23 14:16:32 -04004596
4597 gl::Context *context = gl::getNonLostContext();
4598
4599 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004600 {
Geoff Langbfdea662014-07-23 14:16:32 -04004601 GLfloat vals[4] = { x, y, 0, 1 };
4602 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004603 }
4604}
4605
4606void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4607{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004608 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609
Geoff Langbfdea662014-07-23 14:16:32 -04004610 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004611 {
Geoff Langbfdea662014-07-23 14:16:32 -04004612 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004613 }
Geoff Langbfdea662014-07-23 14:16:32 -04004614
4615 gl::Context *context = gl::getNonLostContext();
4616
4617 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004618 {
Geoff Langbfdea662014-07-23 14:16:32 -04004619 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4620 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004621 }
4622}
4623
4624void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4625{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004626 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 +00004627
Geoff Langbfdea662014-07-23 14:16:32 -04004628 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004629 {
Geoff Langbfdea662014-07-23 14:16:32 -04004630 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004631 }
Geoff Langbfdea662014-07-23 14:16:32 -04004632
4633 gl::Context *context = gl::getNonLostContext();
4634
4635 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004636 {
Geoff Langbfdea662014-07-23 14:16:32 -04004637 GLfloat vals[4] = { x, y, z, 1 };
4638 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004639 }
4640}
4641
4642void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4643{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004644 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004645
Geoff Langbfdea662014-07-23 14:16:32 -04004646 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004647 {
Geoff Langbfdea662014-07-23 14:16:32 -04004648 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004649 }
Geoff Langbfdea662014-07-23 14:16:32 -04004650
4651 gl::Context *context = gl::getNonLostContext();
4652
4653 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004654 {
Geoff Langbfdea662014-07-23 14:16:32 -04004655 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4656 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004657 }
4658}
4659
4660void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004662 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 +00004663
Geoff Langbfdea662014-07-23 14:16:32 -04004664 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004665 {
Geoff Langbfdea662014-07-23 14:16:32 -04004666 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004667 }
Geoff Langbfdea662014-07-23 14:16:32 -04004668
4669 gl::Context *context = gl::getNonLostContext();
4670
4671 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004672 {
Geoff Langbfdea662014-07-23 14:16:32 -04004673 GLfloat vals[4] = { x, y, z, w };
4674 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004675 }
4676}
4677
4678void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004680 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004681
Geoff Langbfdea662014-07-23 14:16:32 -04004682 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004683 {
Geoff Langbfdea662014-07-23 14:16:32 -04004684 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004685 }
Geoff Langbfdea662014-07-23 14:16:32 -04004686
4687 gl::Context *context = gl::getNonLostContext();
4688
4689 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004690 {
Geoff Langbfdea662014-07-23 14:16:32 -04004691 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004692 }
4693}
4694
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004695void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4696{
4697 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4698
Geoff Langbfdea662014-07-23 14:16:32 -04004699 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004700 {
Geoff Langbfdea662014-07-23 14:16:32 -04004701 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004702 }
Geoff Langbfdea662014-07-23 14:16:32 -04004703
4704 gl::Context *context = gl::getNonLostContext();
4705
4706 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004707 {
Geoff Langbfdea662014-07-23 14:16:32 -04004708 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004709 }
4710}
4711
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004712void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004713{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004714 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004715 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004716 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004717
Geoff Langbfdea662014-07-23 14:16:32 -04004718 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004719 {
Geoff Langbfdea662014-07-23 14:16:32 -04004720 return gl::error(GL_INVALID_VALUE);
4721 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004722
Geoff Langbfdea662014-07-23 14:16:32 -04004723 if (size < 1 || size > 4)
4724 {
4725 return gl::error(GL_INVALID_VALUE);
4726 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004727
Geoff Langbfdea662014-07-23 14:16:32 -04004728 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00004729
Geoff Langbfdea662014-07-23 14:16:32 -04004730 switch (type)
4731 {
4732 case GL_BYTE:
4733 case GL_UNSIGNED_BYTE:
4734 case GL_SHORT:
4735 case GL_UNSIGNED_SHORT:
4736 case GL_FIXED:
4737 case GL_FLOAT:
4738 break;
4739 case GL_HALF_FLOAT:
4740 case GL_INT:
4741 case GL_UNSIGNED_INT:
4742 case GL_INT_2_10_10_10_REV:
4743 case GL_UNSIGNED_INT_2_10_10_10_REV:
4744 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004746 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004747 }
Geoff Langbfdea662014-07-23 14:16:32 -04004748 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004749 {
Geoff Langbfdea662014-07-23 14:16:32 -04004750 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004751 }
Geoff Langbfdea662014-07-23 14:16:32 -04004752 default:
4753 return gl::error(GL_INVALID_ENUM);
4754 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004755
Geoff Langbfdea662014-07-23 14:16:32 -04004756 if (stride < 0)
4757 {
4758 return gl::error(GL_INVALID_VALUE);
4759 }
4760
4761 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4762 {
4763 return gl::error(GL_INVALID_OPERATION);
4764 }
4765
4766 if (context)
4767 {
4768 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4769 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4770 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4771 // and the pointer argument is not NULL.
4772 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004773 {
4774 return gl::error(GL_INVALID_OPERATION);
4775 }
4776
Geoff Langbfdea662014-07-23 14:16:32 -04004777 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4778 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004779 }
4780}
4781
4782void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4783{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004784 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 +00004785
Geoff Langbfdea662014-07-23 14:16:32 -04004786 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004787 {
Geoff Langbfdea662014-07-23 14:16:32 -04004788 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004789 }
Geoff Langbfdea662014-07-23 14:16:32 -04004790
4791 gl::Context *context = gl::getNonLostContext();
4792
4793 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004794 {
Geoff Langbfdea662014-07-23 14:16:32 -04004795 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004796 }
4797}
4798
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004799// OpenGL ES 3.0 functions
4800
4801void __stdcall glReadBuffer(GLenum mode)
4802{
4803 EVENT("(GLenum mode = 0x%X)", mode);
4804
Geoff Langbfdea662014-07-23 14:16:32 -04004805 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004806
Geoff Langbfdea662014-07-23 14:16:32 -04004807 if (context)
4808 {
4809 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004810 {
Geoff Langbfdea662014-07-23 14:16:32 -04004811 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004812 }
Geoff Langbfdea662014-07-23 14:16:32 -04004813
4814 // glReadBuffer
4815 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004816 }
4817}
4818
4819void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4820{
4821 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4822 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4823
Geoff Langbfdea662014-07-23 14:16:32 -04004824 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004825
Geoff Langbfdea662014-07-23 14:16:32 -04004826 if (context)
4827 {
4828 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004829 {
Geoff Langbfdea662014-07-23 14:16:32 -04004830 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004831 }
Geoff Langbfdea662014-07-23 14:16:32 -04004832
4833 // glDrawRangeElements
4834 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004835 }
4836}
4837
4838void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4839{
4840 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4841 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4842 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4843 target, level, internalformat, width, height, depth, border, format, type, pixels);
4844
Geoff Langbfdea662014-07-23 14:16:32 -04004845 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004846
Geoff Langbfdea662014-07-23 14:16:32 -04004847 if (context)
4848 {
4849 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004850 {
Geoff Langbfdea662014-07-23 14:16:32 -04004851 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004852 }
Geoff Langbfdea662014-07-23 14:16:32 -04004853
4854 // validateES3TexImageFormat sets the error code if there is an error
4855 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4856 0, 0, 0, width, height, depth, border, format, type, pixels))
4857 {
4858 return;
4859 }
4860
4861 switch(target)
4862 {
4863 case GL_TEXTURE_3D:
4864 {
4865 gl::Texture3D *texture = context->getTexture3D();
4866 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4867 }
4868 break;
4869
4870 case GL_TEXTURE_2D_ARRAY:
4871 {
4872 gl::Texture2DArray *texture = context->getTexture2DArray();
4873 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4874 }
4875 break;
4876
4877 default:
4878 return gl::error(GL_INVALID_ENUM);
4879 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004880 }
4881}
4882
4883void __stdcall glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels)
4884{
4885 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4886 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4887 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4888 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4889
Geoff Langbfdea662014-07-23 14:16:32 -04004890 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004891
Geoff Langbfdea662014-07-23 14:16:32 -04004892 if (context)
4893 {
4894 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004895 {
Geoff Langbfdea662014-07-23 14:16:32 -04004896 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004897 }
Geoff Langbfdea662014-07-23 14:16:32 -04004898
4899 // validateES3TexImageFormat sets the error code if there is an error
4900 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4901 xoffset, yoffset, zoffset, width, height, depth, 0,
4902 format, type, pixels))
4903 {
4904 return;
4905 }
4906
4907 // Zero sized uploads are valid but no-ops
4908 if (width == 0 || height == 0 || depth == 0)
4909 {
4910 return;
4911 }
4912
4913 switch(target)
4914 {
4915 case GL_TEXTURE_3D:
4916 {
4917 gl::Texture3D *texture = context->getTexture3D();
4918 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4919 }
4920 break;
4921
4922 case GL_TEXTURE_2D_ARRAY:
4923 {
4924 gl::Texture2DArray *texture = context->getTexture2DArray();
4925 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4926 }
4927 break;
4928
4929 default:
4930 return gl::error(GL_INVALID_ENUM);
4931 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004932 }
4933}
4934
4935void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
4936{
4937 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4938 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
4939 target, level, xoffset, yoffset, zoffset, x, y, width, height);
4940
Geoff Langbfdea662014-07-23 14:16:32 -04004941 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004942
Geoff Langbfdea662014-07-23 14:16:32 -04004943 if (context)
4944 {
4945 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004946 {
Geoff Langbfdea662014-07-23 14:16:32 -04004947 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004948 }
Geoff Langbfdea662014-07-23 14:16:32 -04004949
4950 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
4951 x, y, width, height, 0))
4952 {
4953 return;
4954 }
4955
4956 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
4957 gl::Texture *texture = NULL;
4958 switch (target)
4959 {
4960 case GL_TEXTURE_3D:
4961 texture = context->getTexture3D();
4962 break;
4963
4964 case GL_TEXTURE_2D_ARRAY:
4965 texture = context->getTexture2DArray();
4966 break;
4967
4968 default:
4969 return gl::error(GL_INVALID_ENUM);
4970 }
4971
4972 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004973 }
4974}
4975
4976void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
4977{
Geoff Langeef52cc2013-10-16 15:07:39 -04004978 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 +00004979 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
4980 "const GLvoid* data = 0x%0.8p)",
4981 target, level, internalformat, width, height, depth, border, imageSize, data);
4982
Geoff Langbfdea662014-07-23 14:16:32 -04004983 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004984
Geoff Langbfdea662014-07-23 14:16:32 -04004985 if (context)
4986 {
4987 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004988 {
Geoff Langbfdea662014-07-23 14:16:32 -04004989 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004990 }
Geoff Langbfdea662014-07-23 14:16:32 -04004991
Geoff Lang5d601382014-07-22 15:14:06 -04004992 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
4993 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04004994 {
4995 return gl::error(GL_INVALID_VALUE);
4996 }
4997
4998 // validateES3TexImageFormat sets the error code if there is an error
4999 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5000 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5001 {
5002 return;
5003 }
5004
5005 switch(target)
5006 {
5007 case GL_TEXTURE_3D:
5008 {
5009 gl::Texture3D *texture = context->getTexture3D();
5010 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5011 }
5012 break;
5013
5014 case GL_TEXTURE_2D_ARRAY:
5015 {
5016 gl::Texture2DArray *texture = context->getTexture2DArray();
5017 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5018 }
5019 break;
5020
5021 default:
5022 return gl::error(GL_INVALID_ENUM);
5023 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005024 }
5025}
5026
5027void __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)
5028{
5029 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5030 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5031 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5032 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5033
Geoff Langbfdea662014-07-23 14:16:32 -04005034 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005035
Geoff Langbfdea662014-07-23 14:16:32 -04005036 if (context)
5037 {
5038 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005039 {
Geoff Langbfdea662014-07-23 14:16:32 -04005040 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005041 }
Geoff Langbfdea662014-07-23 14:16:32 -04005042
Geoff Lang5d601382014-07-22 15:14:06 -04005043 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5044 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005045 {
5046 return gl::error(GL_INVALID_VALUE);
5047 }
5048
5049 if (!data)
5050 {
5051 return gl::error(GL_INVALID_VALUE);
5052 }
5053
5054 // validateES3TexImageFormat sets the error code if there is an error
5055 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5056 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5057 {
5058 return;
5059 }
5060
5061 // Zero sized uploads are valid but no-ops
5062 if (width == 0 || height == 0)
5063 {
5064 return;
5065 }
5066
5067 switch(target)
5068 {
5069 case GL_TEXTURE_3D:
5070 {
5071 gl::Texture3D *texture = context->getTexture3D();
5072 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5073 format, imageSize, data);
5074 }
5075 break;
5076
5077 case GL_TEXTURE_2D_ARRAY:
5078 {
5079 gl::Texture2DArray *texture = context->getTexture2DArray();
5080 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5081 format, imageSize, data);
5082 }
5083 break;
5084
5085 default:
5086 return gl::error(GL_INVALID_ENUM);
5087 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005088 }
5089}
5090
5091void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5092{
5093 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5094
Geoff Langbfdea662014-07-23 14:16:32 -04005095 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005096
Geoff Langbfdea662014-07-23 14:16:32 -04005097 if (context)
5098 {
5099 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005100 {
Geoff Langbfdea662014-07-23 14:16:32 -04005101 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005102 }
Geoff Langbfdea662014-07-23 14:16:32 -04005103
5104 if (n < 0)
5105 {
5106 return gl::error(GL_INVALID_VALUE);
5107 }
5108
5109 for (GLsizei i = 0; i < n; i++)
5110 {
5111 ids[i] = context->createQuery();
5112 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005113 }
5114}
5115
5116void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5117{
5118 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5119
Geoff Langbfdea662014-07-23 14:16:32 -04005120 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005121
Geoff Langbfdea662014-07-23 14:16:32 -04005122 if (context)
5123 {
5124 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005125 {
Geoff Langbfdea662014-07-23 14:16:32 -04005126 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005127 }
Geoff Langbfdea662014-07-23 14:16:32 -04005128
5129 if (n < 0)
5130 {
5131 return gl::error(GL_INVALID_VALUE);
5132 }
5133
5134 for (GLsizei i = 0; i < n; i++)
5135 {
5136 context->deleteQuery(ids[i]);
5137 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005138 }
5139}
5140
5141GLboolean __stdcall glIsQuery(GLuint id)
5142{
5143 EVENT("(GLuint id = %u)", id);
5144
Geoff Langbfdea662014-07-23 14:16:32 -04005145 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005146
Geoff Langbfdea662014-07-23 14:16:32 -04005147 if (context)
5148 {
5149 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005150 {
Geoff Langbfdea662014-07-23 14:16:32 -04005151 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005152 }
Geoff Langbfdea662014-07-23 14:16:32 -04005153
5154 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005155 }
5156
5157 return GL_FALSE;
5158}
5159
5160void __stdcall glBeginQuery(GLenum target, GLuint id)
5161{
5162 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5163
Geoff Langbfdea662014-07-23 14:16:32 -04005164 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005165
Geoff Langbfdea662014-07-23 14:16:32 -04005166 if (context)
5167 {
5168 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005169 {
Geoff Langbfdea662014-07-23 14:16:32 -04005170 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005171 }
Geoff Langbfdea662014-07-23 14:16:32 -04005172
5173 if (!ValidateBeginQuery(context, target, id))
5174 {
5175 return;
5176 }
5177 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005178 }
5179}
5180
5181void __stdcall glEndQuery(GLenum target)
5182{
5183 EVENT("(GLenum target = 0x%X)", target);
5184
Geoff Langbfdea662014-07-23 14:16:32 -04005185 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005186
Geoff Langbfdea662014-07-23 14:16:32 -04005187 if (context)
5188 {
5189 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005190 {
Geoff Langbfdea662014-07-23 14:16:32 -04005191 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005192 }
Geoff Langbfdea662014-07-23 14:16:32 -04005193
5194 if (!ValidateEndQuery(context, target))
5195 {
5196 return;
5197 }
5198
5199 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005200 }
5201}
5202
5203void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5204{
5205 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5206
Geoff Langbfdea662014-07-23 14:16:32 -04005207 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005208
Geoff Langbfdea662014-07-23 14:16:32 -04005209 if (context)
5210 {
5211 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005212 {
Geoff Langbfdea662014-07-23 14:16:32 -04005213 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005214 }
Geoff Langbfdea662014-07-23 14:16:32 -04005215
5216 if (!ValidQueryType(context, target))
5217 {
5218 return gl::error(GL_INVALID_ENUM);
5219 }
5220
5221 switch (pname)
5222 {
5223 case GL_CURRENT_QUERY:
5224 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5225 break;
5226
5227 default:
5228 return gl::error(GL_INVALID_ENUM);
5229 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005230 }
5231}
5232
5233void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5234{
5235 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5236
Geoff Langbfdea662014-07-23 14:16:32 -04005237 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005238
Geoff Langbfdea662014-07-23 14:16:32 -04005239 if (context)
5240 {
5241 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005242 {
Geoff Langbfdea662014-07-23 14:16:32 -04005243 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005244 }
Geoff Langbfdea662014-07-23 14:16:32 -04005245
5246 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5247
5248 if (!queryObject)
5249 {
5250 return gl::error(GL_INVALID_OPERATION);
5251 }
5252
5253 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5254 {
5255 return gl::error(GL_INVALID_OPERATION);
5256 }
5257
5258 switch(pname)
5259 {
5260 case GL_QUERY_RESULT:
5261 params[0] = queryObject->getResult();
5262 break;
5263 case GL_QUERY_RESULT_AVAILABLE:
5264 params[0] = queryObject->isResultAvailable();
5265 break;
5266 default:
5267 return gl::error(GL_INVALID_ENUM);
5268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005269 }
5270}
5271
5272GLboolean __stdcall glUnmapBuffer(GLenum target)
5273{
5274 EVENT("(GLenum target = 0x%X)", target);
5275
Geoff Langbfdea662014-07-23 14:16:32 -04005276 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005277
Geoff Langbfdea662014-07-23 14:16:32 -04005278 if (context)
5279 {
5280 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005281 {
Geoff Langbfdea662014-07-23 14:16:32 -04005282 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005283 }
Geoff Langbfdea662014-07-23 14:16:32 -04005284
5285 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005286 }
5287
5288 return GL_FALSE;
5289}
5290
5291void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5292{
5293 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5294
Geoff Langbfdea662014-07-23 14:16:32 -04005295 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005296
Geoff Langbfdea662014-07-23 14:16:32 -04005297 if (context)
5298 {
5299 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005300 {
Geoff Langbfdea662014-07-23 14:16:32 -04005301 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005302 }
Geoff Langbfdea662014-07-23 14:16:32 -04005303
5304 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005305 }
5306}
5307
5308void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5309{
Geoff Langbfdea662014-07-23 14:16:32 -04005310 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005311
Geoff Langbfdea662014-07-23 14:16:32 -04005312 if (context)
5313 {
5314 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005315 {
Geoff Langbfdea662014-07-23 14:16:32 -04005316 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005317 }
Geoff Langbfdea662014-07-23 14:16:32 -04005318
5319 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005320 }
5321}
5322
5323void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5324{
5325 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5326 location, count, transpose, value);
5327
Geoff Langbfdea662014-07-23 14:16:32 -04005328 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005329
Geoff Langbfdea662014-07-23 14:16:32 -04005330 if (context)
5331 {
5332 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005333 {
Geoff Langbfdea662014-07-23 14:16:32 -04005334 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005335 }
Geoff Langbfdea662014-07-23 14:16:32 -04005336
5337 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5338 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005339 }
5340}
5341
5342void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5343{
5344 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5345 location, count, transpose, value);
5346
Geoff Langbfdea662014-07-23 14:16:32 -04005347 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005348
Geoff Langbfdea662014-07-23 14:16:32 -04005349 if (context)
5350 {
5351 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005352 {
Geoff Langbfdea662014-07-23 14:16:32 -04005353 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005354 }
Geoff Langbfdea662014-07-23 14:16:32 -04005355
5356 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5357 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005358 }
5359}
5360
5361void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5362{
5363 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5364 location, count, transpose, value);
5365
Geoff Langbfdea662014-07-23 14:16:32 -04005366 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005367
Geoff Langbfdea662014-07-23 14:16:32 -04005368 if (context)
5369 {
5370 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005371 {
Geoff Langbfdea662014-07-23 14:16:32 -04005372 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005373 }
Geoff Langbfdea662014-07-23 14:16:32 -04005374
5375 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5376 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005377 }
5378}
5379
5380void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5381{
5382 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5383 location, count, transpose, value);
5384
Geoff Langbfdea662014-07-23 14:16:32 -04005385 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005386
Geoff Langbfdea662014-07-23 14:16:32 -04005387 if (context)
5388 {
5389 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005390 {
Geoff Langbfdea662014-07-23 14:16:32 -04005391 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005392 }
Geoff Langbfdea662014-07-23 14:16:32 -04005393
5394 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5395 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005396 }
5397}
5398
5399void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5400{
5401 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5402 location, count, transpose, value);
5403
Geoff Langbfdea662014-07-23 14:16:32 -04005404 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005405
Geoff Langbfdea662014-07-23 14:16:32 -04005406 if (context)
5407 {
5408 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005409 {
Geoff Langbfdea662014-07-23 14:16:32 -04005410 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005411 }
Geoff Langbfdea662014-07-23 14:16:32 -04005412
5413 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5414 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005415 }
5416}
5417
5418void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5419{
5420 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5421 location, count, transpose, value);
5422
Geoff Langbfdea662014-07-23 14:16:32 -04005423 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005424
Geoff Langbfdea662014-07-23 14:16:32 -04005425 if (context)
5426 {
5427 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005428 {
Geoff Langbfdea662014-07-23 14:16:32 -04005429 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005430 }
Geoff Langbfdea662014-07-23 14:16:32 -04005431
5432 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5433 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005434 }
5435}
5436
5437void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5438{
5439 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5440 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5441 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5442
Geoff Langbfdea662014-07-23 14:16:32 -04005443 gl::Context *context = gl::getNonLostContext();
5444 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005445 {
Geoff Langbfdea662014-07-23 14:16:32 -04005446 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005447 {
Geoff Langbfdea662014-07-23 14:16:32 -04005448 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005449 }
Geoff Langbfdea662014-07-23 14:16:32 -04005450
5451 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5452 dstX0, dstY0, dstX1, dstY1, mask, filter,
5453 false))
5454 {
5455 return;
5456 }
5457
5458 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5459 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005460 }
5461}
5462
5463void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5464{
5465 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5466 target, samples, internalformat, width, height);
5467
Geoff Langbfdea662014-07-23 14:16:32 -04005468 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005469
Geoff Langbfdea662014-07-23 14:16:32 -04005470 if (context)
5471 {
5472 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005473 {
Geoff Langbfdea662014-07-23 14:16:32 -04005474 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005475 }
Geoff Langbfdea662014-07-23 14:16:32 -04005476
5477 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5478 width, height, false))
5479 {
5480 return;
5481 }
5482
5483 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005484 }
5485}
5486
5487void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5488{
5489 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5490 target, attachment, texture, level, layer);
5491
Geoff Langbfdea662014-07-23 14:16:32 -04005492 gl::Context *context = gl::getNonLostContext();
5493
5494 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005495 {
Geoff Langbfdea662014-07-23 14:16:32 -04005496 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5497 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005498 {
Geoff Langbfdea662014-07-23 14:16:32 -04005499 return;
5500 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005501
Geoff Langbfdea662014-07-23 14:16:32 -04005502 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5503 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005504
Geoff Langbfdea662014-07-23 14:16:32 -04005505 gl::Texture *textureObject = context->getTexture(texture);
5506 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005507
Geoff Langbfdea662014-07-23 14:16:32 -04005508 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5509 {
5510 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5511 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5512 }
5513 else
5514 {
5515 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005516 {
Geoff Langbfdea662014-07-23 14:16:32 -04005517 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5518 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5519 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005520 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005521 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005522 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005523}
5524
5525GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5526{
5527 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5528 target, offset, length, access);
5529
Geoff Langbfdea662014-07-23 14:16:32 -04005530 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005531
Geoff Langbfdea662014-07-23 14:16:32 -04005532 if (context)
5533 {
5534 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005535 {
Geoff Langbfdea662014-07-23 14:16:32 -04005536 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005537 }
Geoff Langbfdea662014-07-23 14:16:32 -04005538
5539 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005540 }
5541
5542 return NULL;
5543}
5544
5545void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5546{
5547 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5548
Geoff Langbfdea662014-07-23 14:16:32 -04005549 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005550
Geoff Langbfdea662014-07-23 14:16:32 -04005551 if (context)
5552 {
5553 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005554 {
Geoff Langbfdea662014-07-23 14:16:32 -04005555 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005556 }
Geoff Langbfdea662014-07-23 14:16:32 -04005557
5558 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005559 }
5560}
5561
5562void __stdcall glBindVertexArray(GLuint array)
5563{
5564 EVENT("(GLuint array = %u)", array);
5565
Geoff Langbfdea662014-07-23 14:16:32 -04005566 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005567
Geoff Langbfdea662014-07-23 14:16:32 -04005568 if (context)
5569 {
5570 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005571 {
Geoff Langbfdea662014-07-23 14:16:32 -04005572 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005573 }
Geoff Langbfdea662014-07-23 14:16:32 -04005574
5575 gl::VertexArray *vao = context->getVertexArray(array);
5576
5577 if (!vao)
5578 {
5579 // The default VAO should always exist
5580 ASSERT(array != 0);
5581 return gl::error(GL_INVALID_OPERATION);
5582 }
5583
5584 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005585 }
5586}
5587
5588void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5589{
5590 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5591
Geoff Langbfdea662014-07-23 14:16:32 -04005592 gl::Context *context = gl::getNonLostContext();
5593
5594 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005595 {
Geoff Langbfdea662014-07-23 14:16:32 -04005596 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005597 {
Geoff Langbfdea662014-07-23 14:16:32 -04005598 return gl::error(GL_INVALID_OPERATION);
5599 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005600
Geoff Langbfdea662014-07-23 14:16:32 -04005601 if (n < 0)
5602 {
5603 return gl::error(GL_INVALID_VALUE);
5604 }
Jamie Madilld1028542013-07-02 11:57:04 -04005605
Geoff Langbfdea662014-07-23 14:16:32 -04005606 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5607 {
5608 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005609 {
Geoff Langbfdea662014-07-23 14:16:32 -04005610 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005611 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005612 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005613 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005614}
5615
5616void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5617{
5618 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5619
Geoff Langbfdea662014-07-23 14:16:32 -04005620 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005621
Geoff Langbfdea662014-07-23 14:16:32 -04005622 if (context)
5623 {
5624 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005625 {
Geoff Langbfdea662014-07-23 14:16:32 -04005626 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005627 }
Geoff Langbfdea662014-07-23 14:16:32 -04005628
5629 if (n < 0)
5630 {
5631 return gl::error(GL_INVALID_VALUE);
5632 }
5633
5634 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5635 {
5636 arrays[arrayIndex] = context->createVertexArray();
5637 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005638 }
5639}
5640
5641GLboolean __stdcall glIsVertexArray(GLuint array)
5642{
5643 EVENT("(GLuint array = %u)", array);
5644
Geoff Langbfdea662014-07-23 14:16:32 -04005645 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005646
Geoff Langbfdea662014-07-23 14:16:32 -04005647 if (context)
5648 {
5649 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005650 {
Geoff Langbfdea662014-07-23 14:16:32 -04005651 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005652 }
Geoff Langbfdea662014-07-23 14:16:32 -04005653
5654 if (array == 0)
5655 {
5656 return GL_FALSE;
5657 }
5658
5659 gl::VertexArray *vao = context->getVertexArray(array);
5660
5661 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005662 }
5663
5664 return GL_FALSE;
5665}
5666
5667void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5668{
5669 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5670 target, index, data);
5671
Geoff Langbfdea662014-07-23 14:16:32 -04005672 gl::Context *context = gl::getNonLostContext();
5673
5674 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005675 {
Geoff Langbfdea662014-07-23 14:16:32 -04005676 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005677 {
Geoff Langbfdea662014-07-23 14:16:32 -04005678 return gl::error(GL_INVALID_OPERATION);
5679 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005680
Geoff Langbfdea662014-07-23 14:16:32 -04005681 switch (target)
5682 {
5683 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5684 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5685 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
5686 if (index >= context->getMaxTransformFeedbackBufferBindings())
5687 return gl::error(GL_INVALID_VALUE);
5688 break;
5689 case GL_UNIFORM_BUFFER_START:
5690 case GL_UNIFORM_BUFFER_SIZE:
5691 case GL_UNIFORM_BUFFER_BINDING:
5692 if (index >= context->getMaximumCombinedUniformBufferBindings())
5693 return gl::error(GL_INVALID_VALUE);
5694 break;
5695 default:
5696 return gl::error(GL_INVALID_ENUM);
5697 }
5698
5699 if (!(context->getIndexedIntegerv(target, index, data)))
5700 {
5701 GLenum nativeType;
5702 unsigned int numParams = 0;
5703 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04005704 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04005705
Geoff Langbfdea662014-07-23 14:16:32 -04005706 if (numParams == 0)
5707 return; // it is known that pname is valid, but there are no parameters to return
5708
5709 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005710 {
Geoff Langbfdea662014-07-23 14:16:32 -04005711 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5712 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5713 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005714
Geoff Langbfdea662014-07-23 14:16:32 -04005715 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005716
Geoff Langbfdea662014-07-23 14:16:32 -04005717 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005718 {
Geoff Langbfdea662014-07-23 14:16:32 -04005719 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5720 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005721 }
Geoff Langbfdea662014-07-23 14:16:32 -04005722
5723 delete [] int64Params;
5724 }
5725 else
5726 {
5727 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005728 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005729 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005731}
5732
5733void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5734{
5735 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5736
Geoff Langbfdea662014-07-23 14:16:32 -04005737 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005738
Geoff Langbfdea662014-07-23 14:16:32 -04005739 if (context)
5740 {
5741 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005742 {
Geoff Langbfdea662014-07-23 14:16:32 -04005743 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005744 }
Geoff Langbfdea662014-07-23 14:16:32 -04005745
5746 switch (primitiveMode)
5747 {
5748 case GL_TRIANGLES:
5749 case GL_LINES:
5750 case GL_POINTS:
5751 break;
5752 default:
5753 return gl::error(GL_INVALID_ENUM);
5754 }
5755
5756 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5757 ASSERT(transformFeedback != NULL);
5758
5759 if (transformFeedback->isStarted())
5760 {
5761 return gl::error(GL_INVALID_OPERATION);
5762 }
5763
5764 if (transformFeedback->isPaused())
5765 {
5766 transformFeedback->resume();
5767 }
5768 else
5769 {
5770 transformFeedback->start(primitiveMode);
5771 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005772 }
5773}
5774
5775void __stdcall glEndTransformFeedback(void)
5776{
5777 EVENT("(void)");
5778
Geoff Langbfdea662014-07-23 14:16:32 -04005779 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005780
Geoff Langbfdea662014-07-23 14:16:32 -04005781 if (context)
5782 {
5783 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005784 {
Geoff Langbfdea662014-07-23 14:16:32 -04005785 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005786 }
Geoff Langbfdea662014-07-23 14:16:32 -04005787
5788 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5789 ASSERT(transformFeedback != NULL);
5790
5791 if (!transformFeedback->isStarted())
5792 {
5793 return gl::error(GL_INVALID_OPERATION);
5794 }
5795
5796 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005797 }
5798}
5799
5800void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5801{
5802 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5803 target, index, buffer, offset, size);
5804
Geoff Langbfdea662014-07-23 14:16:32 -04005805 gl::Context *context = gl::getNonLostContext();
5806
5807 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005808 {
Geoff Langbfdea662014-07-23 14:16:32 -04005809 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005810 {
Geoff Langbfdea662014-07-23 14:16:32 -04005811 return gl::error(GL_INVALID_OPERATION);
5812 }
5813
5814 switch (target)
5815 {
5816 case GL_TRANSFORM_FEEDBACK_BUFFER:
5817 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005818 {
Geoff Langbfdea662014-07-23 14:16:32 -04005819 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005820 }
Geoff Langbfdea662014-07-23 14:16:32 -04005821 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005822
Geoff Langbfdea662014-07-23 14:16:32 -04005823 case GL_UNIFORM_BUFFER:
5824 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005825 {
Geoff Langbfdea662014-07-23 14:16:32 -04005826 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005827 }
Geoff Langbfdea662014-07-23 14:16:32 -04005828 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005829
Geoff Langbfdea662014-07-23 14:16:32 -04005830 default:
5831 return gl::error(GL_INVALID_ENUM);
5832 }
5833
5834 if (buffer != 0 && size <= 0)
5835 {
5836 return gl::error(GL_INVALID_VALUE);
5837 }
5838
5839 switch (target)
5840 {
5841 case GL_TRANSFORM_FEEDBACK_BUFFER:
5842
5843 // size and offset must be a multiple of 4
5844 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005845 {
5846 return gl::error(GL_INVALID_VALUE);
5847 }
5848
Geoff Langbfdea662014-07-23 14:16:32 -04005849 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5850 context->bindGenericTransformFeedbackBuffer(buffer);
5851 break;
5852
5853 case GL_UNIFORM_BUFFER:
5854
5855 // it is an error to bind an offset not a multiple of the alignment
5856 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005857 {
Geoff Langbfdea662014-07-23 14:16:32 -04005858 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005859 }
Geoff Langbfdea662014-07-23 14:16:32 -04005860
5861 context->bindIndexedUniformBuffer(buffer, index, offset, size);
5862 context->bindGenericUniformBuffer(buffer);
5863 break;
5864
5865 default:
5866 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005867 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005868 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005869}
5870
5871void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
5872{
5873 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
5874 target, index, buffer);
5875
Geoff Langbfdea662014-07-23 14:16:32 -04005876 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005877
Geoff Langbfdea662014-07-23 14:16:32 -04005878 if (context)
5879 {
5880 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005881 {
Geoff Langbfdea662014-07-23 14:16:32 -04005882 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005883 }
Geoff Langbfdea662014-07-23 14:16:32 -04005884
5885 switch (target)
5886 {
5887 case GL_TRANSFORM_FEEDBACK_BUFFER:
5888 if (index >= context->getMaxTransformFeedbackBufferBindings())
5889 {
5890 return gl::error(GL_INVALID_VALUE);
5891 }
5892 break;
5893
5894 case GL_UNIFORM_BUFFER:
5895 if (index >= context->getMaximumCombinedUniformBufferBindings())
5896 {
5897 return gl::error(GL_INVALID_VALUE);
5898 }
5899 break;
5900
5901 default:
5902 return gl::error(GL_INVALID_ENUM);
5903 }
5904
5905 switch (target)
5906 {
5907 case GL_TRANSFORM_FEEDBACK_BUFFER:
5908 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
5909 context->bindGenericTransformFeedbackBuffer(buffer);
5910 break;
5911
5912 case GL_UNIFORM_BUFFER:
5913 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
5914 context->bindGenericUniformBuffer(buffer);
5915 break;
5916
5917 default:
5918 UNREACHABLE();
5919 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005920 }
5921}
5922
5923void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
5924{
5925 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
5926 program, count, varyings, bufferMode);
5927
Geoff Langbfdea662014-07-23 14:16:32 -04005928 gl::Context *context = gl::getNonLostContext();
5929
5930 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005931 {
Geoff Langbfdea662014-07-23 14:16:32 -04005932 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005933 {
Geoff Langbfdea662014-07-23 14:16:32 -04005934 return gl::error(GL_INVALID_OPERATION);
5935 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005936
Geoff Langbfdea662014-07-23 14:16:32 -04005937 if (count < 0)
5938 {
5939 return gl::error(GL_INVALID_VALUE);
5940 }
5941
5942 switch (bufferMode)
5943 {
5944 case GL_INTERLEAVED_ATTRIBS:
5945 break;
5946 case GL_SEPARATE_ATTRIBS:
5947 if (static_cast<GLuint>(count) > context->getMaxTransformFeedbackBufferBindings())
Geoff Lang48dcae72014-02-05 16:28:24 -05005948 {
5949 return gl::error(GL_INVALID_VALUE);
5950 }
Geoff Langbfdea662014-07-23 14:16:32 -04005951 break;
5952 default:
5953 return gl::error(GL_INVALID_ENUM);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005954 }
Geoff Langbfdea662014-07-23 14:16:32 -04005955
5956 if (!gl::ValidProgram(context, program))
5957 {
5958 return;
5959 }
5960
5961 gl::Program *programObject = context->getProgram(program);
5962 ASSERT(programObject);
5963
5964 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005965 }
5966}
5967
5968void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
5969{
5970 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
5971 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
5972 program, index, bufSize, length, size, type, name);
5973
Geoff Langbfdea662014-07-23 14:16:32 -04005974 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005975
Geoff Langbfdea662014-07-23 14:16:32 -04005976 if (context)
5977 {
5978 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005979 {
Geoff Langbfdea662014-07-23 14:16:32 -04005980 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005981 }
Geoff Langbfdea662014-07-23 14:16:32 -04005982
5983 if (bufSize < 0)
5984 {
5985 return gl::error(GL_INVALID_VALUE);
5986 }
5987
5988 if (!gl::ValidProgram(context, program))
5989 {
5990 return;
5991 }
5992
5993 gl::Program *programObject = context->getProgram(program);
5994 ASSERT(programObject);
5995
5996 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
5997 {
5998 return gl::error(GL_INVALID_VALUE);
5999 }
6000
6001 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006002 }
6003}
6004
6005void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6006{
6007 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6008 index, size, type, stride, pointer);
6009
Geoff Langbfdea662014-07-23 14:16:32 -04006010 gl::Context *context = gl::getNonLostContext();
6011
6012 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006013 {
Geoff Langbfdea662014-07-23 14:16:32 -04006014 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006015 {
Geoff Langbfdea662014-07-23 14:16:32 -04006016 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006017 }
Geoff Langbfdea662014-07-23 14:16:32 -04006018 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006019
Geoff Langbfdea662014-07-23 14:16:32 -04006020 if (index >= gl::MAX_VERTEX_ATTRIBS)
6021 {
6022 return gl::error(GL_INVALID_VALUE);
6023 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006024
Geoff Langbfdea662014-07-23 14:16:32 -04006025 if (size < 1 || size > 4)
6026 {
6027 return gl::error(GL_INVALID_VALUE);
6028 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006029
Geoff Langbfdea662014-07-23 14:16:32 -04006030 switch (type)
6031 {
6032 case GL_BYTE:
6033 case GL_UNSIGNED_BYTE:
6034 case GL_SHORT:
6035 case GL_UNSIGNED_SHORT:
6036 case GL_INT:
6037 case GL_UNSIGNED_INT:
6038 case GL_INT_2_10_10_10_REV:
6039 case GL_UNSIGNED_INT_2_10_10_10_REV:
6040 break;
6041 default:
6042 return gl::error(GL_INVALID_ENUM);
6043 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006044
Geoff Langbfdea662014-07-23 14:16:32 -04006045 if (stride < 0)
6046 {
6047 return gl::error(GL_INVALID_VALUE);
6048 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006049
Geoff Langbfdea662014-07-23 14:16:32 -04006050 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6051 {
6052 return gl::error(GL_INVALID_OPERATION);
6053 }
6054
6055 if (context)
6056 {
6057 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6058 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6059 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6060 // and the pointer argument is not NULL.
6061 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006062 {
6063 return gl::error(GL_INVALID_OPERATION);
6064 }
6065
Geoff Langbfdea662014-07-23 14:16:32 -04006066 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6067 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006068 }
6069}
6070
6071void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6072{
6073 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6074 index, pname, params);
6075
Geoff Langbfdea662014-07-23 14:16:32 -04006076 gl::Context *context = gl::getNonLostContext();
6077
6078 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006079 {
Geoff Langbfdea662014-07-23 14:16:32 -04006080 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006081 {
Geoff Langbfdea662014-07-23 14:16:32 -04006082 return gl::error(GL_INVALID_OPERATION);
6083 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006084
Geoff Langbfdea662014-07-23 14:16:32 -04006085 if (index >= gl::MAX_VERTEX_ATTRIBS)
6086 {
6087 return gl::error(GL_INVALID_VALUE);
6088 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006089
Geoff Langbfdea662014-07-23 14:16:32 -04006090 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006091
Geoff Langbfdea662014-07-23 14:16:32 -04006092 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6093 {
6094 return;
6095 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006096
Geoff Langbfdea662014-07-23 14:16:32 -04006097 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6098 {
6099 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6100 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006101 {
Geoff Langbfdea662014-07-23 14:16:32 -04006102 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006103 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006104 }
Geoff Langbfdea662014-07-23 14:16:32 -04006105 else
6106 {
6107 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6108 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006109 }
6110}
6111
6112void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6113{
6114 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6115 index, pname, params);
6116
Geoff Langbfdea662014-07-23 14:16:32 -04006117 gl::Context *context = gl::getNonLostContext();
6118
6119 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006120 {
Geoff Langbfdea662014-07-23 14:16:32 -04006121 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006122 {
Geoff Langbfdea662014-07-23 14:16:32 -04006123 return gl::error(GL_INVALID_OPERATION);
6124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006125
Geoff Langbfdea662014-07-23 14:16:32 -04006126 if (index >= gl::MAX_VERTEX_ATTRIBS)
6127 {
6128 return gl::error(GL_INVALID_VALUE);
6129 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006130
Geoff Langbfdea662014-07-23 14:16:32 -04006131 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006132
Geoff Langbfdea662014-07-23 14:16:32 -04006133 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6134 {
6135 return;
6136 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006137
Geoff Langbfdea662014-07-23 14:16:32 -04006138 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6139 {
6140 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6141 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006142 {
Geoff Langbfdea662014-07-23 14:16:32 -04006143 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006144 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006145 }
Geoff Langbfdea662014-07-23 14:16:32 -04006146 else
6147 {
6148 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6149 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006150 }
6151}
6152
6153void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6154{
6155 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6156 index, x, y, z, w);
6157
Geoff Langbfdea662014-07-23 14:16:32 -04006158 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006159
Geoff Langbfdea662014-07-23 14:16:32 -04006160 if (context)
6161 {
6162 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006163 {
Geoff Langbfdea662014-07-23 14:16:32 -04006164 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006165 }
Geoff Langbfdea662014-07-23 14:16:32 -04006166
6167 if (index >= gl::MAX_VERTEX_ATTRIBS)
6168 {
6169 return gl::error(GL_INVALID_VALUE);
6170 }
6171
6172 GLint vals[4] = { x, y, z, w };
6173 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006174 }
6175}
6176
6177void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6178{
6179 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6180 index, x, y, z, w);
6181
Geoff Langbfdea662014-07-23 14:16:32 -04006182 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006183
Geoff Langbfdea662014-07-23 14:16:32 -04006184 if (context)
6185 {
6186 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006187 {
Geoff Langbfdea662014-07-23 14:16:32 -04006188 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006189 }
Geoff Langbfdea662014-07-23 14:16:32 -04006190
6191 if (index >= gl::MAX_VERTEX_ATTRIBS)
6192 {
6193 return gl::error(GL_INVALID_VALUE);
6194 }
6195
6196 GLuint vals[4] = { x, y, z, w };
6197 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006198 }
6199}
6200
6201void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6202{
6203 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6204
Geoff Langbfdea662014-07-23 14:16:32 -04006205 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006206
Geoff Langbfdea662014-07-23 14:16:32 -04006207 if (context)
6208 {
6209 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006210 {
Geoff Langbfdea662014-07-23 14:16:32 -04006211 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006212 }
Geoff Langbfdea662014-07-23 14:16:32 -04006213
6214 if (index >= gl::MAX_VERTEX_ATTRIBS)
6215 {
6216 return gl::error(GL_INVALID_VALUE);
6217 }
6218
6219 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006220 }
6221}
6222
6223void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6224{
6225 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6226
Geoff Langbfdea662014-07-23 14:16:32 -04006227 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006228
Geoff Langbfdea662014-07-23 14:16:32 -04006229 if (context)
6230 {
6231 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006232 {
Geoff Langbfdea662014-07-23 14:16:32 -04006233 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006234 }
Geoff Langbfdea662014-07-23 14:16:32 -04006235
6236 if (index >= gl::MAX_VERTEX_ATTRIBS)
6237 {
6238 return gl::error(GL_INVALID_VALUE);
6239 }
6240
6241 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006242 }
6243}
6244
6245void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6246{
6247 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6248 program, location, params);
6249
Geoff Langbfdea662014-07-23 14:16:32 -04006250 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006251
Geoff Langbfdea662014-07-23 14:16:32 -04006252 if (context)
6253 {
6254 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006255 {
Geoff Langbfdea662014-07-23 14:16:32 -04006256 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006257 }
Geoff Langbfdea662014-07-23 14:16:32 -04006258
6259 if (program == 0)
6260 {
6261 return gl::error(GL_INVALID_VALUE);
6262 }
6263
6264 gl::Program *programObject = context->getProgram(program);
6265
6266 if (!programObject || !programObject->isLinked())
6267 {
6268 return gl::error(GL_INVALID_OPERATION);
6269 }
6270
6271 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6272 if (!programBinary)
6273 {
6274 return gl::error(GL_INVALID_OPERATION);
6275 }
6276
6277 if (!programBinary->getUniformuiv(location, NULL, params))
6278 {
6279 return gl::error(GL_INVALID_OPERATION);
6280 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006281 }
6282}
6283
6284GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6285{
6286 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6287 program, name);
6288
Geoff Langbfdea662014-07-23 14:16:32 -04006289 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006290
Geoff Langbfdea662014-07-23 14:16:32 -04006291 if (context)
6292 {
6293 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006294 {
Geoff Langbfdea662014-07-23 14:16:32 -04006295 return gl::error(GL_INVALID_OPERATION, -1);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006296 }
Geoff Langbfdea662014-07-23 14:16:32 -04006297
6298 if (program == 0)
6299 {
6300 return gl::error(GL_INVALID_VALUE, -1);
6301 }
6302
6303 gl::Program *programObject = context->getProgram(program);
6304
6305 if (!programObject || !programObject->isLinked())
6306 {
6307 return gl::error(GL_INVALID_OPERATION, -1);
6308 }
6309
6310 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6311 if (!programBinary)
6312 {
6313 return gl::error(GL_INVALID_OPERATION, -1);
6314 }
6315
6316 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006317 }
6318
6319 return 0;
6320}
6321
6322void __stdcall glUniform1ui(GLint location, GLuint v0)
6323{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006324 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006325}
6326
6327void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6328{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006329 const GLuint xy[] = { v0, v1 };
6330 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006331}
6332
6333void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6334{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006335 const GLuint xyz[] = { v0, v1, v2 };
6336 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006337}
6338
6339void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6340{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006341 const GLuint xyzw[] = { v0, v1, v2, v3 };
6342 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006343}
6344
6345void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6346{
6347 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6348 location, count, value);
6349
Geoff Langbfdea662014-07-23 14:16:32 -04006350 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006351
Geoff Langbfdea662014-07-23 14:16:32 -04006352 if (context)
6353 {
6354 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006355 {
Geoff Langbfdea662014-07-23 14:16:32 -04006356 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006357 }
Geoff Langbfdea662014-07-23 14:16:32 -04006358
6359 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6360 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006361 }
6362}
6363
6364void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6365{
6366 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6367 location, count, value);
6368
Geoff Langbfdea662014-07-23 14:16:32 -04006369 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006370
Geoff Langbfdea662014-07-23 14:16:32 -04006371 if (context)
6372 {
6373 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006374 {
Geoff Langbfdea662014-07-23 14:16:32 -04006375 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006376 }
Geoff Langbfdea662014-07-23 14:16:32 -04006377
6378 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6379 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006380 }
6381}
6382
6383void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6384{
6385 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6386 location, count, value);
6387
Geoff Langbfdea662014-07-23 14:16:32 -04006388 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006389
Geoff Langbfdea662014-07-23 14:16:32 -04006390 if (context)
6391 {
6392 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006393 {
Geoff Langbfdea662014-07-23 14:16:32 -04006394 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006395 }
Geoff Langbfdea662014-07-23 14:16:32 -04006396
6397 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6398 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006399 }
6400}
6401
6402void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6403{
6404 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6405 location, count, value);
6406
Geoff Langbfdea662014-07-23 14:16:32 -04006407 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006408
Geoff Langbfdea662014-07-23 14:16:32 -04006409 if (context)
6410 {
6411 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006412 {
Geoff Langbfdea662014-07-23 14:16:32 -04006413 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006414 }
Geoff Langbfdea662014-07-23 14:16:32 -04006415
6416 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6417 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006418 }
6419}
6420
6421void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6422{
6423 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6424 buffer, drawbuffer, value);
6425
Geoff Langbfdea662014-07-23 14:16:32 -04006426 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006427
Geoff Langbfdea662014-07-23 14:16:32 -04006428 if (context)
6429 {
6430 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006431 {
Geoff Langbfdea662014-07-23 14:16:32 -04006432 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006433 }
Geoff Langbfdea662014-07-23 14:16:32 -04006434
6435 switch (buffer)
6436 {
6437 case GL_COLOR:
6438 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6439 {
6440 return gl::error(GL_INVALID_VALUE);
6441 }
6442 break;
6443 case GL_STENCIL:
6444 if (drawbuffer != 0)
6445 {
6446 return gl::error(GL_INVALID_VALUE);
6447 }
6448 break;
6449 default:
6450 return gl::error(GL_INVALID_ENUM);
6451 }
6452
6453 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006454 }
6455}
6456
6457void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6458{
6459 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6460 buffer, drawbuffer, value);
6461
Geoff Langbfdea662014-07-23 14:16:32 -04006462 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006463
Geoff Langbfdea662014-07-23 14:16:32 -04006464 if (context)
6465 {
6466 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006467 {
Geoff Langbfdea662014-07-23 14:16:32 -04006468 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006469 }
Geoff Langbfdea662014-07-23 14:16:32 -04006470
6471 switch (buffer)
6472 {
6473 case GL_COLOR:
6474 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6475 {
6476 return gl::error(GL_INVALID_VALUE);
6477 }
6478 break;
6479 default:
6480 return gl::error(GL_INVALID_ENUM);
6481 }
6482
6483 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006484 }
6485}
6486
6487void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6488{
6489 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6490 buffer, drawbuffer, value);
6491
Geoff Langbfdea662014-07-23 14:16:32 -04006492 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006493
Geoff Langbfdea662014-07-23 14:16:32 -04006494 if (context)
6495 {
6496 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006497 {
Geoff Langbfdea662014-07-23 14:16:32 -04006498 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006499 }
Geoff Langbfdea662014-07-23 14:16:32 -04006500
6501 switch (buffer)
6502 {
6503 case GL_COLOR:
6504 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6505 {
6506 return gl::error(GL_INVALID_VALUE);
6507 }
6508 break;
6509 case GL_DEPTH:
6510 if (drawbuffer != 0)
6511 {
6512 return gl::error(GL_INVALID_VALUE);
6513 }
6514 break;
6515 default:
6516 return gl::error(GL_INVALID_ENUM);
6517 }
6518
6519 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006520 }
6521}
6522
6523void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6524{
6525 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6526 buffer, drawbuffer, depth, stencil);
6527
Geoff Langbfdea662014-07-23 14:16:32 -04006528 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006529
Geoff Langbfdea662014-07-23 14:16:32 -04006530 if (context)
6531 {
6532 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006533 {
Geoff Langbfdea662014-07-23 14:16:32 -04006534 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006535 }
Geoff Langbfdea662014-07-23 14:16:32 -04006536
6537 switch (buffer)
6538 {
6539 case GL_DEPTH_STENCIL:
6540 if (drawbuffer != 0)
6541 {
6542 return gl::error(GL_INVALID_VALUE);
6543 }
6544 break;
6545 default:
6546 return gl::error(GL_INVALID_ENUM);
6547 }
6548
6549 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006550 }
6551}
6552
6553const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6554{
6555 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6556
Geoff Langbfdea662014-07-23 14:16:32 -04006557 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006558
Geoff Langbfdea662014-07-23 14:16:32 -04006559 if (context)
6560 {
6561 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006562 {
Geoff Langbfdea662014-07-23 14:16:32 -04006563 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006564 }
Geoff Langbfdea662014-07-23 14:16:32 -04006565
6566 if (name != GL_EXTENSIONS)
6567 {
6568 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
6569 }
6570
6571 if (index >= context->getExtensionStringCount())
6572 {
6573 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
6574 }
6575
6576 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006577 }
6578
6579 return NULL;
6580}
6581
6582void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6583{
6584 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6585 readTarget, writeTarget, readOffset, writeOffset, size);
6586
Geoff Langbfdea662014-07-23 14:16:32 -04006587 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006588
Geoff Langbfdea662014-07-23 14:16:32 -04006589 if (context)
6590 {
6591 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006592 {
Geoff Langbfdea662014-07-23 14:16:32 -04006593 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006594 }
Geoff Langbfdea662014-07-23 14:16:32 -04006595
6596 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6597 {
6598 return gl::error(GL_INVALID_ENUM);
6599 }
6600
6601 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6602 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6603
6604 if (!readBuffer || !writeBuffer)
6605 {
6606 return gl::error(GL_INVALID_OPERATION);
6607 }
6608
Jamie Madillcfaaf722014-07-31 10:47:54 -04006609 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006610 if (readBuffer->isMapped() || writeBuffer->isMapped())
6611 {
6612 return gl::error(GL_INVALID_OPERATION);
6613 }
6614
6615 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6616 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6617 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6618 {
6619 return gl::error(GL_INVALID_VALUE);
6620 }
6621
6622 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6623 {
6624 return gl::error(GL_INVALID_VALUE);
6625 }
6626
Geoff Langbfdea662014-07-23 14:16:32 -04006627 // if size is zero, the copy is a successful no-op
6628 if (size > 0)
6629 {
6630 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6631 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006632 }
6633}
6634
6635void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6636{
6637 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6638 program, uniformCount, uniformNames, uniformIndices);
6639
Geoff Langbfdea662014-07-23 14:16:32 -04006640 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006641
Geoff Langbfdea662014-07-23 14:16:32 -04006642 if (context)
6643 {
6644 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006645 {
Geoff Langbfdea662014-07-23 14:16:32 -04006646 return gl::error(GL_INVALID_OPERATION);
6647 }
6648
6649 if (uniformCount < 0)
6650 {
6651 return gl::error(GL_INVALID_VALUE);
6652 }
6653
6654 gl::Program *programObject = context->getProgram(program);
6655
6656 if (!programObject)
6657 {
6658 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006659 {
6660 return gl::error(GL_INVALID_OPERATION);
6661 }
Geoff Langbfdea662014-07-23 14:16:32 -04006662 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006663 {
6664 return gl::error(GL_INVALID_VALUE);
6665 }
Geoff Langbfdea662014-07-23 14:16:32 -04006666 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006667
Geoff Langbfdea662014-07-23 14:16:32 -04006668 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6669 if (!programObject->isLinked() || !programBinary)
6670 {
6671 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006672 {
Geoff Langbfdea662014-07-23 14:16:32 -04006673 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006674 }
6675 }
Geoff Langbfdea662014-07-23 14:16:32 -04006676 else
6677 {
6678 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6679 {
6680 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6681 }
6682 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006683 }
6684}
6685
6686void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6687{
6688 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6689 program, uniformCount, uniformIndices, pname, params);
6690
Geoff Langbfdea662014-07-23 14:16:32 -04006691 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006692
Geoff Langbfdea662014-07-23 14:16:32 -04006693 if (context)
6694 {
6695 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006696 {
Geoff Langbfdea662014-07-23 14:16:32 -04006697 return gl::error(GL_INVALID_OPERATION);
6698 }
6699
6700 if (uniformCount < 0)
6701 {
6702 return gl::error(GL_INVALID_VALUE);
6703 }
6704
6705 gl::Program *programObject = context->getProgram(program);
6706
6707 if (!programObject)
6708 {
6709 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006710 {
6711 return gl::error(GL_INVALID_OPERATION);
6712 }
Geoff Langbfdea662014-07-23 14:16:32 -04006713 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006714 {
6715 return gl::error(GL_INVALID_VALUE);
6716 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006717 }
Geoff Langbfdea662014-07-23 14:16:32 -04006718
6719 switch (pname)
6720 {
6721 case GL_UNIFORM_TYPE:
6722 case GL_UNIFORM_SIZE:
6723 case GL_UNIFORM_NAME_LENGTH:
6724 case GL_UNIFORM_BLOCK_INDEX:
6725 case GL_UNIFORM_OFFSET:
6726 case GL_UNIFORM_ARRAY_STRIDE:
6727 case GL_UNIFORM_MATRIX_STRIDE:
6728 case GL_UNIFORM_IS_ROW_MAJOR:
6729 break;
6730 default:
6731 return gl::error(GL_INVALID_ENUM);
6732 }
6733
6734 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6735
6736 if (!programBinary && uniformCount > 0)
6737 {
6738 return gl::error(GL_INVALID_VALUE);
6739 }
6740
6741 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6742 {
6743 const GLuint index = uniformIndices[uniformId];
6744
6745 if (index >= (GLuint)programBinary->getActiveUniformCount())
6746 {
6747 return gl::error(GL_INVALID_VALUE);
6748 }
6749 }
6750
6751 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6752 {
6753 const GLuint index = uniformIndices[uniformId];
6754 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6755 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006756 }
6757}
6758
6759GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6760{
6761 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6762
Geoff Langbfdea662014-07-23 14:16:32 -04006763 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006764
Geoff Langbfdea662014-07-23 14:16:32 -04006765 if (context)
6766 {
6767 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006768 {
Geoff Langbfdea662014-07-23 14:16:32 -04006769 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
6770 }
6771
6772 gl::Program *programObject = context->getProgram(program);
6773
6774 if (!programObject)
6775 {
6776 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006777 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006778 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006779 }
Geoff Langbfdea662014-07-23 14:16:32 -04006780 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006781 {
Geoff Langbfdea662014-07-23 14:16:32 -04006782 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006783 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006784 }
Geoff Langbfdea662014-07-23 14:16:32 -04006785
6786 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6787 if (!programBinary)
6788 {
6789 return GL_INVALID_INDEX;
6790 }
6791
6792 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006793 }
6794
6795 return 0;
6796}
6797
6798void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6799{
6800 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6801 program, uniformBlockIndex, pname, params);
6802
Geoff Langbfdea662014-07-23 14:16:32 -04006803 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006804
Geoff Langbfdea662014-07-23 14:16:32 -04006805 if (context)
6806 {
6807 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006808 {
Geoff Langbfdea662014-07-23 14:16:32 -04006809 return gl::error(GL_INVALID_OPERATION);
6810 }
6811 gl::Program *programObject = context->getProgram(program);
6812
6813 if (!programObject)
6814 {
6815 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006816 {
6817 return gl::error(GL_INVALID_OPERATION);
6818 }
Geoff Langbfdea662014-07-23 14:16:32 -04006819 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006820 {
6821 return gl::error(GL_INVALID_VALUE);
6822 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006823 }
Geoff Langbfdea662014-07-23 14:16:32 -04006824
6825 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6826
6827 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6828 {
6829 return gl::error(GL_INVALID_VALUE);
6830 }
6831
6832 switch (pname)
6833 {
6834 case GL_UNIFORM_BLOCK_BINDING:
6835 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
6836 break;
6837
6838 case GL_UNIFORM_BLOCK_DATA_SIZE:
6839 case GL_UNIFORM_BLOCK_NAME_LENGTH:
6840 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
6841 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
6842 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
6843 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
6844 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
6845 break;
6846
6847 default:
6848 return gl::error(GL_INVALID_ENUM);
6849 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006850 }
6851}
6852
6853void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
6854{
6855 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
6856 program, uniformBlockIndex, bufSize, length, uniformBlockName);
6857
Geoff Langbfdea662014-07-23 14:16:32 -04006858 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006859
Geoff Langbfdea662014-07-23 14:16:32 -04006860 if (context)
6861 {
6862 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006863 {
Geoff Langbfdea662014-07-23 14:16:32 -04006864 return gl::error(GL_INVALID_OPERATION);
6865 }
6866
6867 gl::Program *programObject = context->getProgram(program);
6868
6869 if (!programObject)
6870 {
6871 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006872 {
6873 return gl::error(GL_INVALID_OPERATION);
6874 }
Geoff Langbfdea662014-07-23 14:16:32 -04006875 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006876 {
6877 return gl::error(GL_INVALID_VALUE);
6878 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006879 }
Geoff Langbfdea662014-07-23 14:16:32 -04006880
6881 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6882
6883 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6884 {
6885 return gl::error(GL_INVALID_VALUE);
6886 }
6887
6888 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006889 }
6890}
6891
6892void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
6893{
6894 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
6895 program, uniformBlockIndex, uniformBlockBinding);
6896
Geoff Langbfdea662014-07-23 14:16:32 -04006897 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006898
Geoff Langbfdea662014-07-23 14:16:32 -04006899 if (context)
6900 {
6901 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006902 {
Geoff Langbfdea662014-07-23 14:16:32 -04006903 return gl::error(GL_INVALID_OPERATION);
6904 }
6905
6906 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
6907 {
6908 return gl::error(GL_INVALID_VALUE);
6909 }
6910
6911 gl::Program *programObject = context->getProgram(program);
6912
6913 if (!programObject)
6914 {
6915 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006916 {
6917 return gl::error(GL_INVALID_OPERATION);
6918 }
Geoff Langbfdea662014-07-23 14:16:32 -04006919 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006920 {
6921 return gl::error(GL_INVALID_VALUE);
6922 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006923 }
Geoff Langbfdea662014-07-23 14:16:32 -04006924
6925 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6926
6927 // if never linked, there won't be any uniform blocks
6928 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6929 {
6930 return gl::error(GL_INVALID_VALUE);
6931 }
6932
6933 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006934 }
6935}
6936
6937void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
6938{
6939 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
6940 mode, first, count, instanceCount);
6941
Geoff Langbfdea662014-07-23 14:16:32 -04006942 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006943
Geoff Langbfdea662014-07-23 14:16:32 -04006944 if (context)
6945 {
6946 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006947 {
Geoff Langbfdea662014-07-23 14:16:32 -04006948 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006949 }
Geoff Langbfdea662014-07-23 14:16:32 -04006950
6951 // glDrawArraysInstanced
6952 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006953 }
6954}
6955
6956void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
6957{
6958 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
6959 mode, count, type, indices, instanceCount);
6960
Geoff Langbfdea662014-07-23 14:16:32 -04006961 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006962
Geoff Langbfdea662014-07-23 14:16:32 -04006963 if (context)
6964 {
6965 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006966 {
Geoff Langbfdea662014-07-23 14:16:32 -04006967 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006968 }
Geoff Langbfdea662014-07-23 14:16:32 -04006969
6970 // glDrawElementsInstanced
6971 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006972 }
6973}
6974
6975GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
6976{
6977 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
6978
Geoff Langbfdea662014-07-23 14:16:32 -04006979 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006980
Geoff Langbfdea662014-07-23 14:16:32 -04006981 if (context)
6982 {
6983 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006984 {
Geoff Langbfdea662014-07-23 14:16:32 -04006985 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006986 }
Geoff Langbfdea662014-07-23 14:16:32 -04006987
6988 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
6989 {
6990 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
6991 }
6992
6993 if (flags != 0)
6994 {
6995 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
6996 }
6997
6998 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006999 }
7000
7001 return NULL;
7002}
7003
7004GLboolean __stdcall glIsSync(GLsync sync)
7005{
7006 EVENT("(GLsync sync = 0x%0.8p)", sync);
7007
Geoff Langbfdea662014-07-23 14:16:32 -04007008 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007009
Geoff Langbfdea662014-07-23 14:16:32 -04007010 if (context)
7011 {
7012 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007013 {
Geoff Langbfdea662014-07-23 14:16:32 -04007014 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007015 }
Geoff Langbfdea662014-07-23 14:16:32 -04007016
7017 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007018 }
7019
7020 return GL_FALSE;
7021}
7022
7023void __stdcall glDeleteSync(GLsync sync)
7024{
7025 EVENT("(GLsync sync = 0x%0.8p)", sync);
7026
Geoff Langbfdea662014-07-23 14:16:32 -04007027 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007028
Geoff Langbfdea662014-07-23 14:16:32 -04007029 if (context)
7030 {
7031 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007032 {
Geoff Langbfdea662014-07-23 14:16:32 -04007033 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007034 }
Geoff Langbfdea662014-07-23 14:16:32 -04007035
7036 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7037 {
7038 return gl::error(GL_INVALID_VALUE);
7039 }
7040
7041 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007042 }
7043}
7044
7045GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7046{
7047 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7048 sync, flags, timeout);
7049
Geoff Langbfdea662014-07-23 14:16:32 -04007050 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007051
Geoff Langbfdea662014-07-23 14:16:32 -04007052 if (context)
7053 {
7054 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007055 {
Geoff Langbfdea662014-07-23 14:16:32 -04007056 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007057 }
Geoff Langbfdea662014-07-23 14:16:32 -04007058
7059 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7060 {
7061 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7062 }
7063
7064 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7065
7066 if (!fenceSync)
7067 {
7068 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7069 }
7070
7071 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007072 }
7073
7074 return GL_FALSE;
7075}
7076
7077void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7078{
7079 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7080 sync, flags, timeout);
7081
Geoff Langbfdea662014-07-23 14:16:32 -04007082 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007083
Geoff Langbfdea662014-07-23 14:16:32 -04007084 if (context)
7085 {
7086 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007087 {
Geoff Langbfdea662014-07-23 14:16:32 -04007088 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007089 }
Geoff Langbfdea662014-07-23 14:16:32 -04007090
7091 if (flags != 0)
7092 {
7093 return gl::error(GL_INVALID_VALUE);
7094 }
7095
7096 if (timeout != GL_TIMEOUT_IGNORED)
7097 {
7098 return gl::error(GL_INVALID_VALUE);
7099 }
7100
7101 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7102
7103 if (!fenceSync)
7104 {
7105 return gl::error(GL_INVALID_VALUE);
7106 }
7107
7108 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007109 }
7110}
7111
7112void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7113{
7114 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7115 pname, params);
7116
Geoff Langbfdea662014-07-23 14:16:32 -04007117 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007118
Geoff Langbfdea662014-07-23 14:16:32 -04007119 if (context)
7120 {
7121 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007122 {
Geoff Langbfdea662014-07-23 14:16:32 -04007123 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007124 }
Geoff Langbfdea662014-07-23 14:16:32 -04007125
7126 GLenum nativeType;
7127 unsigned int numParams = 0;
7128 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7129 {
7130 return;
7131 }
7132
7133 if (nativeType == GL_INT_64_ANGLEX)
7134 {
7135 context->getInteger64v(pname, params);
7136 }
7137 else
7138 {
7139 CastStateValues(context, nativeType, pname, numParams, params);
7140 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007141 }
7142}
7143
7144void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7145{
7146 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7147 sync, pname, bufSize, length, values);
7148
Geoff Langbfdea662014-07-23 14:16:32 -04007149 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007150
Geoff Langbfdea662014-07-23 14:16:32 -04007151 if (context)
7152 {
7153 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007154 {
Geoff Langbfdea662014-07-23 14:16:32 -04007155 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007156 }
Geoff Langbfdea662014-07-23 14:16:32 -04007157
7158 if (bufSize < 0)
7159 {
7160 return gl::error(GL_INVALID_VALUE);
7161 }
7162
7163 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7164
7165 if (!fenceSync)
7166 {
7167 return gl::error(GL_INVALID_VALUE);
7168 }
7169
7170 switch (pname)
7171 {
7172 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7173 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7174 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7175 case GL_SYNC_FLAGS: values[0] = 0; break;
7176
7177 default:
7178 return gl::error(GL_INVALID_ENUM);
7179 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007180 }
7181}
7182
7183void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7184{
7185 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7186 target, index, data);
7187
Geoff Langbfdea662014-07-23 14:16:32 -04007188 gl::Context *context = gl::getNonLostContext();
7189
7190 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007191 {
Geoff Langbfdea662014-07-23 14:16:32 -04007192 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007193 {
Geoff Langbfdea662014-07-23 14:16:32 -04007194 return gl::error(GL_INVALID_OPERATION);
7195 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007196
Geoff Langbfdea662014-07-23 14:16:32 -04007197 switch (target)
7198 {
7199 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7200 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7201 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7202 if (index >= context->getMaxTransformFeedbackBufferBindings())
7203 return gl::error(GL_INVALID_VALUE);
7204 break;
7205 case GL_UNIFORM_BUFFER_START:
7206 case GL_UNIFORM_BUFFER_SIZE:
7207 case GL_UNIFORM_BUFFER_BINDING:
7208 if (index >= context->getMaximumCombinedUniformBufferBindings())
7209 return gl::error(GL_INVALID_VALUE);
7210 break;
7211 default:
7212 return gl::error(GL_INVALID_ENUM);
7213 }
7214
7215 if (!(context->getIndexedInteger64v(target, index, data)))
7216 {
7217 GLenum nativeType;
7218 unsigned int numParams = 0;
7219 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04007220 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04007221
Geoff Langbfdea662014-07-23 14:16:32 -04007222 if (numParams == 0)
7223 return; // it is known that pname is valid, but there are no parameters to return
7224
7225 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007226 {
Geoff Langbfdea662014-07-23 14:16:32 -04007227 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007228
Geoff Langbfdea662014-07-23 14:16:32 -04007229 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007230
Geoff Langbfdea662014-07-23 14:16:32 -04007231 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007232 {
Geoff Langbfdea662014-07-23 14:16:32 -04007233 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007234 }
Geoff Langbfdea662014-07-23 14:16:32 -04007235
7236 delete [] intParams;
7237 }
7238 else
7239 {
7240 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007241 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007242 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007243 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007244}
7245
7246void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7247{
7248 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7249 target, pname, params);
7250
Geoff Langbfdea662014-07-23 14:16:32 -04007251 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007252
Geoff Langbfdea662014-07-23 14:16:32 -04007253 if (context)
7254 {
7255 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007256 {
Geoff Langbfdea662014-07-23 14:16:32 -04007257 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007258 }
Geoff Langbfdea662014-07-23 14:16:32 -04007259
7260 if (!gl::ValidBufferTarget(context, target))
7261 {
7262 return gl::error(GL_INVALID_ENUM);
7263 }
7264
7265 if (!gl::ValidBufferParameter(context, pname))
7266 {
7267 return gl::error(GL_INVALID_ENUM);
7268 }
7269
7270 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7271
7272 if (!buffer)
7273 {
7274 // A null buffer means that "0" is bound to the requested buffer target
7275 return gl::error(GL_INVALID_OPERATION);
7276 }
7277
7278 switch (pname)
7279 {
7280 case GL_BUFFER_USAGE:
7281 *params = static_cast<GLint64>(buffer->getUsage());
7282 break;
7283 case GL_BUFFER_SIZE:
7284 *params = buffer->getSize();
7285 break;
7286 case GL_BUFFER_ACCESS_FLAGS:
7287 *params = static_cast<GLint64>(buffer->getAccessFlags());
7288 break;
7289 case GL_BUFFER_MAPPED:
7290 *params = static_cast<GLint64>(buffer->isMapped());
7291 break;
7292 case GL_BUFFER_MAP_OFFSET:
7293 *params = buffer->getMapOffset();
7294 break;
7295 case GL_BUFFER_MAP_LENGTH:
7296 *params = buffer->getMapLength();
7297 break;
7298 default: UNREACHABLE(); break;
7299 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007300 }
7301}
7302
7303void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7304{
7305 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7306
Geoff Langbfdea662014-07-23 14:16:32 -04007307 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007308
Geoff Langbfdea662014-07-23 14:16:32 -04007309 if (context)
7310 {
7311 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007312 {
Geoff Langbfdea662014-07-23 14:16:32 -04007313 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007314 }
Geoff Langbfdea662014-07-23 14:16:32 -04007315
7316 if (count < 0)
7317 {
7318 return gl::error(GL_INVALID_VALUE);
7319 }
7320
7321 for (int i = 0; i < count; i++)
7322 {
7323 samplers[i] = context->createSampler();
7324 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007325 }
7326}
7327
7328void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7329{
7330 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7331
Geoff Langbfdea662014-07-23 14:16:32 -04007332 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007333
Geoff Langbfdea662014-07-23 14:16:32 -04007334 if (context)
7335 {
7336 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007337 {
Geoff Langbfdea662014-07-23 14:16:32 -04007338 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007339 }
Geoff Langbfdea662014-07-23 14:16:32 -04007340
7341 if (count < 0)
7342 {
7343 return gl::error(GL_INVALID_VALUE);
7344 }
7345
7346 for (int i = 0; i < count; i++)
7347 {
7348 context->deleteSampler(samplers[i]);
7349 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007350 }
7351}
7352
7353GLboolean __stdcall glIsSampler(GLuint sampler)
7354{
7355 EVENT("(GLuint sampler = %u)", sampler);
7356
Geoff Langbfdea662014-07-23 14:16:32 -04007357 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007358
Geoff Langbfdea662014-07-23 14:16:32 -04007359 if (context)
7360 {
7361 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007362 {
Geoff Langbfdea662014-07-23 14:16:32 -04007363 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007364 }
Geoff Langbfdea662014-07-23 14:16:32 -04007365
7366 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007367 }
7368
7369 return GL_FALSE;
7370}
7371
7372void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7373{
7374 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7375
Geoff Langbfdea662014-07-23 14:16:32 -04007376 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007377
Geoff Langbfdea662014-07-23 14:16:32 -04007378 if (context)
7379 {
7380 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007381 {
Geoff Langbfdea662014-07-23 14:16:32 -04007382 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007383 }
Geoff Langbfdea662014-07-23 14:16:32 -04007384
7385 if (sampler != 0 && !context->isSampler(sampler))
7386 {
7387 return gl::error(GL_INVALID_OPERATION);
7388 }
7389
7390 if (unit >= context->getMaximumCombinedTextureImageUnits())
7391 {
7392 return gl::error(GL_INVALID_VALUE);
7393 }
7394
7395 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007396 }
7397}
7398
7399void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7400{
7401 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7402
Geoff Langbfdea662014-07-23 14:16:32 -04007403 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007404
Geoff Langbfdea662014-07-23 14:16:32 -04007405 if (context)
7406 {
7407 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007408 {
Geoff Langbfdea662014-07-23 14:16:32 -04007409 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007410 }
Geoff Langbfdea662014-07-23 14:16:32 -04007411
7412 if (!gl::ValidateSamplerObjectParameter(pname))
7413 {
7414 return;
7415 }
7416
7417 if (!gl::ValidateTexParamParameters(context, pname, param))
7418 {
7419 return;
7420 }
7421
7422 if (!context->isSampler(sampler))
7423 {
7424 return gl::error(GL_INVALID_OPERATION);
7425 }
7426
7427 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007428 }
7429}
7430
7431void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7432{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007433 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007434}
7435
7436void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7437{
7438 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7439
Geoff Langbfdea662014-07-23 14:16:32 -04007440 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007441
Geoff Langbfdea662014-07-23 14:16:32 -04007442 if (context)
7443 {
7444 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007445 {
Geoff Langbfdea662014-07-23 14:16:32 -04007446 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007447 }
Geoff Langbfdea662014-07-23 14:16:32 -04007448
7449 if (!gl::ValidateSamplerObjectParameter(pname))
7450 {
7451 return;
7452 }
7453
7454 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7455 {
7456 return;
7457 }
7458
7459 if (!context->isSampler(sampler))
7460 {
7461 return gl::error(GL_INVALID_OPERATION);
7462 }
7463
7464 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007465 }
7466}
7467
7468void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7469{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007470 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007471}
7472
7473void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7474{
7475 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7476
Geoff Langbfdea662014-07-23 14:16:32 -04007477 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007478
Geoff Langbfdea662014-07-23 14:16:32 -04007479 if (context)
7480 {
7481 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007482 {
Geoff Langbfdea662014-07-23 14:16:32 -04007483 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007484 }
Geoff Langbfdea662014-07-23 14:16:32 -04007485
7486 if (!gl::ValidateSamplerObjectParameter(pname))
7487 {
7488 return;
7489 }
7490
7491 if (!context->isSampler(sampler))
7492 {
7493 return gl::error(GL_INVALID_OPERATION);
7494 }
7495
7496 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007497 }
7498}
7499
7500void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7501{
7502 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7503
Geoff Langbfdea662014-07-23 14:16:32 -04007504 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007505
Geoff Langbfdea662014-07-23 14:16:32 -04007506 if (context)
7507 {
7508 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007509 {
Geoff Langbfdea662014-07-23 14:16:32 -04007510 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007511 }
Geoff Langbfdea662014-07-23 14:16:32 -04007512
7513 if (!gl::ValidateSamplerObjectParameter(pname))
7514 {
7515 return;
7516 }
7517
7518 if (!context->isSampler(sampler))
7519 {
7520 return gl::error(GL_INVALID_OPERATION);
7521 }
7522
7523 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007524 }
7525}
7526
7527void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7528{
7529 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7530
Geoff Langbfdea662014-07-23 14:16:32 -04007531 if (index >= gl::MAX_VERTEX_ATTRIBS)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007532 {
Geoff Langbfdea662014-07-23 14:16:32 -04007533 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007534 }
Geoff Langbfdea662014-07-23 14:16:32 -04007535
7536 gl::Context *context = gl::getNonLostContext();
7537
7538 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007539 {
Geoff Langbfdea662014-07-23 14:16:32 -04007540 if (context->getClientVersion() < 3)
7541 {
7542 return gl::error(GL_INVALID_OPERATION);
7543 }
7544
7545 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007546 }
7547}
7548
7549void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7550{
7551 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7552
Geoff Langbfdea662014-07-23 14:16:32 -04007553 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007554
Geoff Langbfdea662014-07-23 14:16:32 -04007555 if (context)
7556 {
7557 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007558 {
Geoff Langbfdea662014-07-23 14:16:32 -04007559 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007560 }
Geoff Langbfdea662014-07-23 14:16:32 -04007561
7562 switch (target)
7563 {
7564 case GL_TRANSFORM_FEEDBACK:
7565 {
7566 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7567 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7568 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7569 {
7570 return gl::error(GL_INVALID_OPERATION);
7571 }
7572
7573 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7574 if (context->getTransformFeedback(id) == NULL)
7575 {
7576 return gl::error(GL_INVALID_OPERATION);
7577 }
7578
7579 context->bindTransformFeedback(id);
7580 }
7581 break;
7582
7583 default:
7584 return gl::error(GL_INVALID_ENUM);
7585 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007586 }
7587}
7588
7589void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7590{
7591 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7592
Geoff Langbfdea662014-07-23 14:16:32 -04007593 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007594
Geoff Langbfdea662014-07-23 14:16:32 -04007595 if (context)
7596 {
7597 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007598 {
Geoff Langbfdea662014-07-23 14:16:32 -04007599 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007600 }
Geoff Langbfdea662014-07-23 14:16:32 -04007601
7602 for (int i = 0; i < n; i++)
7603 {
7604 context->deleteTransformFeedback(ids[i]);
7605 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007606 }
7607}
7608
7609void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7610{
7611 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7612
Geoff Langbfdea662014-07-23 14:16:32 -04007613 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007614
Geoff Langbfdea662014-07-23 14:16:32 -04007615 if (context)
7616 {
7617 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007618 {
Geoff Langbfdea662014-07-23 14:16:32 -04007619 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007620 }
Geoff Langbfdea662014-07-23 14:16:32 -04007621
7622 for (int i = 0; i < n; i++)
7623 {
7624 ids[i] = context->createTransformFeedback();
7625 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007626 }
7627}
7628
7629GLboolean __stdcall glIsTransformFeedback(GLuint id)
7630{
7631 EVENT("(GLuint id = %u)", id);
7632
Geoff Langbfdea662014-07-23 14:16:32 -04007633 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007634
Geoff Langbfdea662014-07-23 14:16:32 -04007635 if (context)
7636 {
7637 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007638 {
Geoff Langbfdea662014-07-23 14:16:32 -04007639 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007640 }
Geoff Langbfdea662014-07-23 14:16:32 -04007641
7642 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007643 }
7644
7645 return GL_FALSE;
7646}
7647
7648void __stdcall glPauseTransformFeedback(void)
7649{
7650 EVENT("(void)");
7651
Geoff Langbfdea662014-07-23 14:16:32 -04007652 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007653
Geoff Langbfdea662014-07-23 14:16:32 -04007654 if (context)
7655 {
7656 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007657 {
Geoff Langbfdea662014-07-23 14:16:32 -04007658 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007659 }
Geoff Langbfdea662014-07-23 14:16:32 -04007660
7661 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7662 ASSERT(transformFeedback != NULL);
7663
7664 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7665 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7666 {
7667 return gl::error(GL_INVALID_OPERATION);
7668 }
7669
7670 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007671 }
7672}
7673
7674void __stdcall glResumeTransformFeedback(void)
7675{
7676 EVENT("(void)");
7677
Geoff Langbfdea662014-07-23 14:16:32 -04007678 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007679
Geoff Langbfdea662014-07-23 14:16:32 -04007680 if (context)
7681 {
7682 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007683 {
Geoff Langbfdea662014-07-23 14:16:32 -04007684 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007685 }
Geoff Langbfdea662014-07-23 14:16:32 -04007686
7687 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7688 ASSERT(transformFeedback != NULL);
7689
7690 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7691 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7692 {
7693 return gl::error(GL_INVALID_OPERATION);
7694 }
7695
7696 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007697 }
7698}
7699
7700void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7701{
7702 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7703 program, bufSize, length, binaryFormat, binary);
7704
Geoff Langbfdea662014-07-23 14:16:32 -04007705 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007706
Geoff Langbfdea662014-07-23 14:16:32 -04007707 if (context)
7708 {
7709 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007710 {
Geoff Langbfdea662014-07-23 14:16:32 -04007711 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007712 }
Geoff Langbfdea662014-07-23 14:16:32 -04007713
7714 // glGetProgramBinary
7715 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007716 }
7717}
7718
7719void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7720{
7721 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7722 program, binaryFormat, binary, length);
7723
Geoff Langbfdea662014-07-23 14:16:32 -04007724 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007725
Geoff Langbfdea662014-07-23 14:16:32 -04007726 if (context)
7727 {
7728 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007729 {
Geoff Langbfdea662014-07-23 14:16:32 -04007730 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007731 }
Geoff Langbfdea662014-07-23 14:16:32 -04007732
7733 // glProgramBinary
7734 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007735 }
7736}
7737
7738void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7739{
7740 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7741 program, pname, value);
7742
Geoff Langbfdea662014-07-23 14:16:32 -04007743 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007744
Geoff Langbfdea662014-07-23 14:16:32 -04007745 if (context)
7746 {
7747 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007748 {
Geoff Langbfdea662014-07-23 14:16:32 -04007749 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007750 }
Geoff Langbfdea662014-07-23 14:16:32 -04007751
7752 // glProgramParameteri
7753 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007754 }
7755}
7756
7757void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7758{
7759 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7760 target, numAttachments, attachments);
7761
Geoff Langbfdea662014-07-23 14:16:32 -04007762 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007763
Geoff Langbfdea662014-07-23 14:16:32 -04007764 if (context)
7765 {
7766 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007767 {
Geoff Langbfdea662014-07-23 14:16:32 -04007768 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007769 }
Geoff Langbfdea662014-07-23 14:16:32 -04007770
7771 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7772 {
7773 return;
7774 }
7775
7776 GLuint maxDimension = context->getCaps().maxRenderbufferSize;
7777 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007778 }
7779}
7780
7781void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
7782{
7783 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
7784 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7785 target, numAttachments, attachments, x, y, width, height);
7786
Geoff Langbfdea662014-07-23 14:16:32 -04007787 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007788
Geoff Langbfdea662014-07-23 14:16:32 -04007789 if (context)
7790 {
7791 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007792 {
Geoff Langbfdea662014-07-23 14:16:32 -04007793 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007794 }
Geoff Langbfdea662014-07-23 14:16:32 -04007795
7796 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7797 {
7798 return;
7799 }
7800
7801 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007802 }
7803}
7804
7805void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7806{
7807 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7808 target, levels, internalformat, width, height);
7809
Geoff Langbfdea662014-07-23 14:16:32 -04007810 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007811
Geoff Langbfdea662014-07-23 14:16:32 -04007812 if (context)
7813 {
7814 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007815 {
Geoff Langbfdea662014-07-23 14:16:32 -04007816 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007817 }
Geoff Langbfdea662014-07-23 14:16:32 -04007818
7819 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
7820 {
7821 return;
7822 }
7823
7824 switch (target)
7825 {
7826 case GL_TEXTURE_2D:
7827 {
7828 gl::Texture2D *texture2d = context->getTexture2D();
7829 texture2d->storage(levels, internalformat, width, height);
7830 }
7831 break;
7832
7833 case GL_TEXTURE_CUBE_MAP:
7834 {
7835 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7836 textureCube->storage(levels, internalformat, width);
7837 }
7838 break;
7839
7840 default:
7841 return gl::error(GL_INVALID_ENUM);
7842 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007843 }
7844}
7845
7846void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
7847{
7848 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
7849 "GLsizei height = %d, GLsizei depth = %d)",
7850 target, levels, internalformat, width, height, depth);
7851
Geoff Langbfdea662014-07-23 14:16:32 -04007852 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007853
Geoff Langbfdea662014-07-23 14:16:32 -04007854 if (context)
7855 {
7856 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007857 {
Geoff Langbfdea662014-07-23 14:16:32 -04007858 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00007859 }
Geoff Langbfdea662014-07-23 14:16:32 -04007860
7861 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
7862 {
7863 return;
7864 }
7865
7866 switch (target)
7867 {
7868 case GL_TEXTURE_3D:
7869 {
7870 gl::Texture3D *texture3d = context->getTexture3D();
7871 texture3d->storage(levels, internalformat, width, height, depth);
7872 }
7873 break;
7874
7875 case GL_TEXTURE_2D_ARRAY:
7876 {
7877 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
7878 texture2darray->storage(levels, internalformat, width, height, depth);
7879 }
7880 break;
7881
7882 default:
7883 UNREACHABLE();
7884 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007885 }
7886}
7887
7888void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
7889{
7890 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
7891 "GLint* params = 0x%0.8p)",
7892 target, internalformat, pname, bufSize, params);
7893
Geoff Langbfdea662014-07-23 14:16:32 -04007894 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007895
Geoff Langbfdea662014-07-23 14:16:32 -04007896 if (context)
7897 {
7898 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007899 {
Geoff Langbfdea662014-07-23 14:16:32 -04007900 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007901 }
Geoff Langbfdea662014-07-23 14:16:32 -04007902
7903 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7904 if (!formatCaps.renderable)
7905 {
7906 return gl::error(GL_INVALID_ENUM);
7907 }
7908
7909 if (target != GL_RENDERBUFFER)
7910 {
7911 return gl::error(GL_INVALID_ENUM);
7912 }
7913
7914 if (bufSize < 0)
7915 {
7916 return gl::error(GL_INVALID_VALUE);
7917 }
7918
7919 switch (pname)
7920 {
7921 case GL_NUM_SAMPLE_COUNTS:
7922 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04007923 {
7924 *params = formatCaps.sampleCounts.size();
7925 }
Geoff Langbfdea662014-07-23 14:16:32 -04007926 break;
7927 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04007928 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04007929 break;
7930 default:
7931 return gl::error(GL_INVALID_ENUM);
7932 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007933 }
7934}
7935
7936// Extension functions
7937
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007938void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
7939 GLbitfield mask, GLenum filter)
7940{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007941 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007942 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
7943 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
7944 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
7945
Geoff Langbfdea662014-07-23 14:16:32 -04007946 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007947
Geoff Langbfdea662014-07-23 14:16:32 -04007948 if (context)
7949 {
7950 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
7951 dstX0, dstY0, dstX1, dstY1, mask, filter,
7952 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007953 {
Geoff Langbfdea662014-07-23 14:16:32 -04007954 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007955 }
Geoff Langbfdea662014-07-23 14:16:32 -04007956
7957 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
7958 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007959 }
7960}
7961
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007962void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
7963 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007964{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007965 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007966 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007967 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007968 target, level, internalformat, width, height, depth, border, format, type, pixels);
7969
Geoff Langbfdea662014-07-23 14:16:32 -04007970 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007971}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00007972
Geoff Langbfdea662014-07-23 14:16:32 -04007973void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007974 GLenum *binaryFormat, void *binary)
7975{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00007976 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 +00007977 program, bufSize, length, binaryFormat, binary);
7978
Geoff Langbfdea662014-07-23 14:16:32 -04007979 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007980
Geoff Langbfdea662014-07-23 14:16:32 -04007981 if (context)
7982 {
7983 gl::Program *programObject = context->getProgram(program);
7984
7985 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007986 {
Geoff Langbfdea662014-07-23 14:16:32 -04007987 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007988 }
Geoff Langbfdea662014-07-23 14:16:32 -04007989
7990 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7991
7992 if (!programBinary)
7993 {
7994 return gl::error(GL_INVALID_OPERATION);
7995 }
7996
Geoff Lang900013c2014-07-07 11:32:19 -04007997 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04007998 {
7999 return gl::error(GL_INVALID_OPERATION);
8000 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008001 }
8002}
8003
8004void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8005 const void *binary, GLint length)
8006{
8007 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8008 program, binaryFormat, binary, length);
8009
Geoff Langbfdea662014-07-23 14:16:32 -04008010 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008011
Geoff Langbfdea662014-07-23 14:16:32 -04008012 if (context)
8013 {
Geoff Lang900013c2014-07-07 11:32:19 -04008014 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8015 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008016 {
Geoff Langbfdea662014-07-23 14:16:32 -04008017 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008018 }
Geoff Langbfdea662014-07-23 14:16:32 -04008019
8020 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008021 if (!programObject)
8022 {
8023 return gl::error(GL_INVALID_OPERATION);
8024 }
8025
Geoff Lang900013c2014-07-07 11:32:19 -04008026 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008027 }
8028}
8029
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008030void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8031{
8032 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8033
Geoff Langbfdea662014-07-23 14:16:32 -04008034 gl::Context *context = gl::getNonLostContext();
8035
8036 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008037 {
Geoff Langbfdea662014-07-23 14:16:32 -04008038 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008039 {
Geoff Langbfdea662014-07-23 14:16:32 -04008040 return gl::error(GL_INVALID_VALUE);
8041 }
8042
8043 if (context->getState().getDrawFramebuffer()->id() == 0)
8044 {
8045 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008046 {
Geoff Langbfdea662014-07-23 14:16:32 -04008047 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008048 }
8049
Geoff Langbfdea662014-07-23 14:16:32 -04008050 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008051 {
Geoff Langbfdea662014-07-23 14:16:32 -04008052 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008053 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008054 }
Geoff Langbfdea662014-07-23 14:16:32 -04008055 else
8056 {
8057 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8058 {
8059 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8060 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8061 {
8062 return gl::error(GL_INVALID_OPERATION);
8063 }
8064 }
8065 }
8066
8067 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8068
8069 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8070 {
8071 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8072 }
8073
8074 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8075 {
8076 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8077 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008078 }
8079}
8080
Shannon Woodsb3801742014-03-27 14:59:19 -04008081void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8082{
8083 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8084
Geoff Langbfdea662014-07-23 14:16:32 -04008085 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008086
Geoff Langbfdea662014-07-23 14:16:32 -04008087 if (context)
8088 {
8089 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008090 {
Geoff Langbfdea662014-07-23 14:16:32 -04008091 return gl::error(GL_INVALID_ENUM);
Shannon Woodsb3801742014-03-27 14:59:19 -04008092 }
Geoff Langbfdea662014-07-23 14:16:32 -04008093
8094 if (pname != GL_BUFFER_MAP_POINTER)
8095 {
8096 return gl::error(GL_INVALID_ENUM);
8097 }
8098
8099 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8100
8101 if (!buffer || !buffer->isMapped())
8102 {
8103 *params = NULL;
8104 }
8105 else
8106 {
8107 *params = buffer->getMapPointer();
8108 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008109 }
8110}
8111
8112void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8113{
8114 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8115
Geoff Langbfdea662014-07-23 14:16:32 -04008116 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008117
Geoff Langbfdea662014-07-23 14:16:32 -04008118 if (context)
8119 {
8120 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008121 {
Geoff Langbfdea662014-07-23 14:16:32 -04008122 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woodsb3801742014-03-27 14:59:19 -04008123 }
Geoff Langbfdea662014-07-23 14:16:32 -04008124
8125 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8126
8127 if (buffer == NULL)
8128 {
8129 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8130 }
8131
8132 if (access != GL_WRITE_ONLY_OES)
8133 {
8134 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
8135 }
8136
8137 if (buffer->isMapped())
8138 {
8139 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8140 }
8141
8142 return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
Shannon Woodsb3801742014-03-27 14:59:19 -04008143 }
8144
8145 return NULL;
8146}
8147
8148GLboolean __stdcall glUnmapBufferOES(GLenum target)
8149{
8150 EVENT("(GLenum target = 0x%X)", target);
8151
Geoff Langbfdea662014-07-23 14:16:32 -04008152 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008153
Geoff Langbfdea662014-07-23 14:16:32 -04008154 if (context)
8155 {
8156 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008157 {
Geoff Langbfdea662014-07-23 14:16:32 -04008158 return gl::error(GL_INVALID_ENUM, GL_FALSE);
Shannon Woodsb3801742014-03-27 14:59:19 -04008159 }
Geoff Langbfdea662014-07-23 14:16:32 -04008160
8161 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8162
8163 if (buffer == NULL || !buffer->isMapped())
8164 {
8165 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8166 }
8167
8168 // TODO: detect if we had corruption. if so, throw an error and return false.
8169
8170 buffer->unmap();
8171
8172 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008173 }
8174
8175 return GL_FALSE;
8176}
8177
Shannon Woods916e7692014-03-27 16:58:22 -04008178void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8179{
8180 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8181 target, offset, length, access);
8182
Geoff Langbfdea662014-07-23 14:16:32 -04008183 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008184
Geoff Langbfdea662014-07-23 14:16:32 -04008185 if (context)
8186 {
8187 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008188 {
Geoff Langbfdea662014-07-23 14:16:32 -04008189 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woods916e7692014-03-27 16:58:22 -04008190 }
Geoff Langbfdea662014-07-23 14:16:32 -04008191
8192 if (offset < 0 || length < 0)
8193 {
8194 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8195 }
8196
8197 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8198
8199 if (buffer == NULL)
8200 {
8201 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8202 }
8203
8204 // Check for buffer overflow
8205 size_t offsetSize = static_cast<size_t>(offset);
8206 size_t lengthSize = static_cast<size_t>(length);
8207
8208 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8209 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8210 {
8211 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8212 }
8213
8214 // Check for invalid bits in the mask
8215 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8216 GL_MAP_WRITE_BIT |
8217 GL_MAP_INVALIDATE_RANGE_BIT |
8218 GL_MAP_INVALIDATE_BUFFER_BIT |
8219 GL_MAP_FLUSH_EXPLICIT_BIT |
8220 GL_MAP_UNSYNCHRONIZED_BIT;
8221
8222 if (access & ~(allAccessBits))
8223 {
8224 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8225 }
8226
8227 if (length == 0 || buffer->isMapped())
8228 {
8229 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8230 }
8231
8232 // Check for invalid bit combinations
8233 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8234 {
8235 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8236 }
8237
8238 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8239 GL_MAP_INVALIDATE_BUFFER_BIT |
8240 GL_MAP_UNSYNCHRONIZED_BIT;
8241
8242 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8243 {
8244 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8245 }
8246
8247 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8248 {
8249 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8250 }
8251
8252 return buffer->mapRange(offset, length, access);
Shannon Woods916e7692014-03-27 16:58:22 -04008253 }
8254
8255 return NULL;
8256}
8257
8258void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8259{
8260 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8261
Geoff Langbfdea662014-07-23 14:16:32 -04008262 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008263
Geoff Langbfdea662014-07-23 14:16:32 -04008264 if (context)
8265 {
8266 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008267 {
Geoff Langbfdea662014-07-23 14:16:32 -04008268 return gl::error(GL_INVALID_VALUE);
Shannon Woods916e7692014-03-27 16:58:22 -04008269 }
Geoff Langbfdea662014-07-23 14:16:32 -04008270
8271 if (!gl::ValidBufferTarget(context, target))
8272 {
8273 return gl::error(GL_INVALID_ENUM);
8274 }
8275
8276 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8277
8278 if (buffer == NULL)
8279 {
8280 return gl::error(GL_INVALID_OPERATION);
8281 }
8282
8283 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8284 {
8285 return gl::error(GL_INVALID_OPERATION);
8286 }
8287
8288 // Check for buffer overflow
8289 size_t offsetSize = static_cast<size_t>(offset);
8290 size_t lengthSize = static_cast<size_t>(length);
8291
8292 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8293 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8294 {
8295 return gl::error(GL_INVALID_VALUE);
8296 }
8297
8298 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008299 }
8300}
8301
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008302__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8303{
8304 struct Extension
8305 {
8306 const char *name;
8307 __eglMustCastToProperFunctionPointerType address;
8308 };
8309
8310 static const Extension glExtensions[] =
8311 {
8312 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008313 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008314 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008315 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8316 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8317 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8318 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8319 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8320 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8321 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008322 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008323 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008324 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8325 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8326 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8327 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008328 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8329 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8330 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8331 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8332 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8333 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8334 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008335 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008336 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8337 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8338 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008339 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008340 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8341 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8342 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008343 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8344 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8345 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008346
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008347 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008348 {
8349 if (strcmp(procname, glExtensions[ext].name) == 0)
8350 {
8351 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8352 }
8353 }
8354
8355 return NULL;
8356}
8357
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008358// Non-public functions used by EGL
8359
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008360bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008361{
8362 EVENT("(egl::Surface* surface = 0x%0.8p)",
8363 surface);
8364
Geoff Langbfdea662014-07-23 14:16:32 -04008365 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008366
Geoff Langbfdea662014-07-23 14:16:32 -04008367 if (context)
8368 {
8369 gl::Texture2D *textureObject = context->getTexture2D();
8370 ASSERT(textureObject != NULL);
8371
8372 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008373 {
Geoff Langbfdea662014-07-23 14:16:32 -04008374 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008375 }
Geoff Langbfdea662014-07-23 14:16:32 -04008376
8377 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008378 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008379
8380 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008381}
8382
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008383}