blob: 5f66f4a7621df36867deb72636585ac0b0756b95 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Geoff Lang48dcae72014-02-05 16:28:24 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
8
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00009#include "common/version.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040010#include "common/utilities.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000013#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000014#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000015#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000016#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000017#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000018#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000019#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000020#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000021#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000022#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040023#include "libGLESv2/VertexArray.h"
Brandon Jones5bf98292014-06-06 17:19:38 -070024#include "libGLESv2/VertexAttribute.h"
Geoff Langc8058452014-02-03 12:04:11 -050025#include "libGLESv2/TransformFeedback.h"
Jamie Madille261b442014-06-25 12:42:21 -040026#include "libGLESv2/FramebufferAttachment.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027
Geoff Lange8ebe7f2013-08-05 15:03:13 -040028#include "libGLESv2/validationES.h"
29#include "libGLESv2/validationES2.h"
30#include "libGLESv2/validationES3.h"
Jamie Madill55856b12014-01-02 13:59:50 -050031#include "libGLESv2/queryconversions.h"
Jamie Madill478fdb22013-07-19 16:36:59 -040032
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033extern "C"
34{
35
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000036// OpenGL ES 2.0 functions
37
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038void __stdcall glActiveTexture(GLenum texture)
39{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000040 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000041
Geoff Langbfdea662014-07-23 14:16:32 -040042 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000043
Geoff Langbfdea662014-07-23 14:16:32 -040044 if (context)
45 {
Geoff Lang3a61c322014-07-10 13:01:54 -040046 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000047 {
Geoff Langbfdea662014-07-23 14:16:32 -040048 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049 }
Geoff Langbfdea662014-07-23 14:16:32 -040050
51 context->getState().setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052 }
53}
54
55void __stdcall glAttachShader(GLuint program, GLuint shader)
56{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000057 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000058
Geoff Langbfdea662014-07-23 14:16:32 -040059 gl::Context *context = gl::getNonLostContext();
60
61 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000062 {
Geoff Langbfdea662014-07-23 14:16:32 -040063 gl::Program *programObject = context->getProgram(program);
64 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000065
Geoff Langbfdea662014-07-23 14:16:32 -040066 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000067 {
Geoff Langbfdea662014-07-23 14:16:32 -040068 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000070 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000071 }
Geoff Langbfdea662014-07-23 14:16:32 -040072 else
73 {
74 return gl::error(GL_INVALID_VALUE);
75 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000076 }
Geoff Langbfdea662014-07-23 14:16:32 -040077
78 if (!shaderObject)
79 {
80 if (context->getProgram(shader))
81 {
82 return gl::error(GL_INVALID_OPERATION);
83 }
84 else
85 {
86 return gl::error(GL_INVALID_VALUE);
87 }
88 }
89
90 if (!programObject->attachShader(shaderObject))
91 {
92 return gl::error(GL_INVALID_OPERATION);
93 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000094 }
95}
96
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000097void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
98{
99 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
100
Geoff Langbfdea662014-07-23 14:16:32 -0400101 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000102
Geoff Langbfdea662014-07-23 14:16:32 -0400103 if (context)
104 {
105 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000106 {
Geoff Langbfdea662014-07-23 14:16:32 -0400107 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000108 }
Geoff Langbfdea662014-07-23 14:16:32 -0400109
110 context->beginQuery(target, id);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000111 }
112}
113
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000114void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000115{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000116 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000117
Geoff Langbfdea662014-07-23 14:16:32 -0400118 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000119 {
Geoff Langbfdea662014-07-23 14:16:32 -0400120 return gl::error(GL_INVALID_VALUE);
121 }
122
123 gl::Context *context = gl::getNonLostContext();
124
125 if (context)
126 {
127 gl::Program *programObject = context->getProgram(program);
128
129 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000130 {
Geoff Langbfdea662014-07-23 14:16:32 -0400131 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000133 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000134 }
Geoff Langbfdea662014-07-23 14:16:32 -0400135 else
136 {
137 return gl::error(GL_INVALID_VALUE);
138 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000139 }
Geoff Langbfdea662014-07-23 14:16:32 -0400140
141 if (strncmp(name, "gl_", 3) == 0)
142 {
143 return gl::error(GL_INVALID_OPERATION);
144 }
145
146 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000147 }
148}
149
150void __stdcall glBindBuffer(GLenum target, GLuint buffer)
151{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000152 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000153
Geoff Langbfdea662014-07-23 14:16:32 -0400154 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000155
Geoff Langbfdea662014-07-23 14:16:32 -0400156 if (context)
157 {
158 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159 {
Geoff Langbfdea662014-07-23 14:16:32 -0400160 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000161 }
Geoff Langbfdea662014-07-23 14:16:32 -0400162
163 switch (target)
164 {
165 case GL_ARRAY_BUFFER:
166 context->bindArrayBuffer(buffer);
167 return;
168 case GL_ELEMENT_ARRAY_BUFFER:
169 context->bindElementArrayBuffer(buffer);
170 return;
171 case GL_COPY_READ_BUFFER:
172 context->bindCopyReadBuffer(buffer);
173 return;
174 case GL_COPY_WRITE_BUFFER:
175 context->bindCopyWriteBuffer(buffer);
176 return;
177 case GL_PIXEL_PACK_BUFFER:
178 context->bindPixelPackBuffer(buffer);
179 return;
180 case GL_PIXEL_UNPACK_BUFFER:
181 context->bindPixelUnpackBuffer(buffer);
182 return;
183 case GL_UNIFORM_BUFFER:
184 context->bindGenericUniformBuffer(buffer);
185 return;
186 case GL_TRANSFORM_FEEDBACK_BUFFER:
187 context->bindGenericTransformFeedbackBuffer(buffer);
188 return;
189 default:
190 return gl::error(GL_INVALID_ENUM);
191 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000192 }
193}
194
195void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
196{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000197 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000198
Geoff Langbfdea662014-07-23 14:16:32 -0400199 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000200 {
Geoff Langbfdea662014-07-23 14:16:32 -0400201 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000202 }
Geoff Langbfdea662014-07-23 14:16:32 -0400203
204 gl::Context *context = gl::getNonLostContext();
205
206 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000207 {
Geoff Langbfdea662014-07-23 14:16:32 -0400208 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
209 {
210 context->bindReadFramebuffer(framebuffer);
211 }
212
213 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
214 {
215 context->bindDrawFramebuffer(framebuffer);
216 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000217 }
218}
219
220void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
221{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000222 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000223
Geoff Langbfdea662014-07-23 14:16:32 -0400224 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000225 {
Geoff Langbfdea662014-07-23 14:16:32 -0400226 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000227 }
Geoff Langbfdea662014-07-23 14:16:32 -0400228
229 gl::Context *context = gl::getNonLostContext();
230
231 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000232 {
Geoff Langbfdea662014-07-23 14:16:32 -0400233 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000234 }
235}
236
237void __stdcall glBindTexture(GLenum target, GLuint texture)
238{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000239 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000240
Geoff Langbfdea662014-07-23 14:16:32 -0400241 gl::Context *context = gl::getNonLostContext();
242
243 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000244 {
Geoff Langbfdea662014-07-23 14:16:32 -0400245 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000246
Geoff Langbfdea662014-07-23 14:16:32 -0400247 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000248 {
Geoff Langbfdea662014-07-23 14:16:32 -0400249 return gl::error(GL_INVALID_OPERATION);
250 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000251
Geoff Langbfdea662014-07-23 14:16:32 -0400252 switch (target)
253 {
254 case GL_TEXTURE_2D:
255 context->bindTexture2D(texture);
256 return;
257 case GL_TEXTURE_CUBE_MAP:
258 context->bindTextureCubeMap(texture);
259 return;
260 case GL_TEXTURE_3D:
261 if (context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000263 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000264 }
Geoff Langbfdea662014-07-23 14:16:32 -0400265 context->bindTexture3D(texture);
266 return;
267 case GL_TEXTURE_2D_ARRAY:
268 if (context->getClientVersion() < 3)
269 {
270 return gl::error(GL_INVALID_ENUM);
271 }
272 context->bindTexture2DArray(texture);
273 return;
274 default:
275 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276 }
277 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000278}
279
280void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
281{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000282 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000283 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000284
Geoff Langbfdea662014-07-23 14:16:32 -0400285 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000286
Geoff Langbfdea662014-07-23 14:16:32 -0400287 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000288 {
Geoff Langbfdea662014-07-23 14:16:32 -0400289 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000290 }
291}
292
293void __stdcall glBlendEquation(GLenum mode)
294{
295 glBlendEquationSeparate(mode, mode);
296}
297
298void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
299{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000300 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000301
Geoff Langbfdea662014-07-23 14:16:32 -0400302 gl::Context *context = gl::getNonLostContext();
303
304 switch (modeRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000305 {
Geoff Langbfdea662014-07-23 14:16:32 -0400306 case GL_FUNC_ADD:
307 case GL_FUNC_SUBTRACT:
308 case GL_FUNC_REVERSE_SUBTRACT:
309 case GL_MIN:
310 case GL_MAX:
311 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000312
Geoff Langbfdea662014-07-23 14:16:32 -0400313 default:
314 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000315 }
Geoff Langbfdea662014-07-23 14:16:32 -0400316
317 switch (modeAlpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000318 {
Geoff Langbfdea662014-07-23 14:16:32 -0400319 case GL_FUNC_ADD:
320 case GL_FUNC_SUBTRACT:
321 case GL_FUNC_REVERSE_SUBTRACT:
322 case GL_MIN:
323 case GL_MAX:
324 break;
325
326 default:
327 return gl::error(GL_INVALID_ENUM);
328 }
329
330 if (context)
331 {
332 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000333 }
334}
335
336void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
337{
338 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
339}
340
341void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
342{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000343 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 +0000344 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000345
Geoff Langbfdea662014-07-23 14:16:32 -0400346 gl::Context *context = gl::getNonLostContext();
347
348 switch (srcRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000349 {
Geoff Langbfdea662014-07-23 14:16:32 -0400350 case GL_ZERO:
351 case GL_ONE:
352 case GL_SRC_COLOR:
353 case GL_ONE_MINUS_SRC_COLOR:
354 case GL_DST_COLOR:
355 case GL_ONE_MINUS_DST_COLOR:
356 case GL_SRC_ALPHA:
357 case GL_ONE_MINUS_SRC_ALPHA:
358 case GL_DST_ALPHA:
359 case GL_ONE_MINUS_DST_ALPHA:
360 case GL_CONSTANT_COLOR:
361 case GL_ONE_MINUS_CONSTANT_COLOR:
362 case GL_CONSTANT_ALPHA:
363 case GL_ONE_MINUS_CONSTANT_ALPHA:
364 case GL_SRC_ALPHA_SATURATE:
365 break;
366 default:
367 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000368 }
Geoff Langbfdea662014-07-23 14:16:32 -0400369
370 switch (dstRGB)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000371 {
Geoff Langbfdea662014-07-23 14:16:32 -0400372 case GL_ZERO:
373 case GL_ONE:
374 case GL_SRC_COLOR:
375 case GL_ONE_MINUS_SRC_COLOR:
376 case GL_DST_COLOR:
377 case GL_ONE_MINUS_DST_COLOR:
378 case GL_SRC_ALPHA:
379 case GL_ONE_MINUS_SRC_ALPHA:
380 case GL_DST_ALPHA:
381 case GL_ONE_MINUS_DST_ALPHA:
382 case GL_CONSTANT_COLOR:
383 case GL_ONE_MINUS_CONSTANT_COLOR:
384 case GL_CONSTANT_ALPHA:
385 case GL_ONE_MINUS_CONSTANT_ALPHA:
386 break;
387
388 case GL_SRC_ALPHA_SATURATE:
389 if (!context || context->getClientVersion() < 3)
390 {
391 return gl::error(GL_INVALID_ENUM);
392 }
393 break;
394
395 default:
396 return gl::error(GL_INVALID_ENUM);
397 }
398
399 switch (srcAlpha)
400 {
401 case GL_ZERO:
402 case GL_ONE:
403 case GL_SRC_COLOR:
404 case GL_ONE_MINUS_SRC_COLOR:
405 case GL_DST_COLOR:
406 case GL_ONE_MINUS_DST_COLOR:
407 case GL_SRC_ALPHA:
408 case GL_ONE_MINUS_SRC_ALPHA:
409 case GL_DST_ALPHA:
410 case GL_ONE_MINUS_DST_ALPHA:
411 case GL_CONSTANT_COLOR:
412 case GL_ONE_MINUS_CONSTANT_COLOR:
413 case GL_CONSTANT_ALPHA:
414 case GL_ONE_MINUS_CONSTANT_ALPHA:
415 case GL_SRC_ALPHA_SATURATE:
416 break;
417 default:
418 return gl::error(GL_INVALID_ENUM);
419 }
420
421 switch (dstAlpha)
422 {
423 case GL_ZERO:
424 case GL_ONE:
425 case GL_SRC_COLOR:
426 case GL_ONE_MINUS_SRC_COLOR:
427 case GL_DST_COLOR:
428 case GL_ONE_MINUS_DST_COLOR:
429 case GL_SRC_ALPHA:
430 case GL_ONE_MINUS_SRC_ALPHA:
431 case GL_DST_ALPHA:
432 case GL_ONE_MINUS_DST_ALPHA:
433 case GL_CONSTANT_COLOR:
434 case GL_ONE_MINUS_CONSTANT_COLOR:
435 case GL_CONSTANT_ALPHA:
436 case GL_ONE_MINUS_CONSTANT_ALPHA:
437 break;
438
439 case GL_SRC_ALPHA_SATURATE:
440 if (!context || context->getClientVersion() < 3)
441 {
442 return gl::error(GL_INVALID_ENUM);
443 }
444 break;
445
446 default:
447 return gl::error(GL_INVALID_ENUM);
448 }
449
450 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
451 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
452
453 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
454 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
455
456 if (constantColorUsed && constantAlphaUsed)
457 {
458 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
459 return gl::error(GL_INVALID_OPERATION);
460 }
461
462 if (context)
463 {
464 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000465 }
466}
467
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000468void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000469{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000470 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 +0000471 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000472
Geoff Langbfdea662014-07-23 14:16:32 -0400473 if (size < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000474 {
Geoff Langbfdea662014-07-23 14:16:32 -0400475 return gl::error(GL_INVALID_VALUE);
476 }
477
478 gl::Context *context = gl::getNonLostContext();
479
480 switch (usage)
481 {
482 case GL_STREAM_DRAW:
483 case GL_STATIC_DRAW:
484 case GL_DYNAMIC_DRAW:
485 break;
486
487 case GL_STREAM_READ:
488 case GL_STREAM_COPY:
489 case GL_STATIC_READ:
490 case GL_STATIC_COPY:
491 case GL_DYNAMIC_READ:
492 case GL_DYNAMIC_COPY:
493 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000494 {
Geoff Langbfdea662014-07-23 14:16:32 -0400495 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000496 }
Geoff Langbfdea662014-07-23 14:16:32 -0400497 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000498
Geoff Langbfdea662014-07-23 14:16:32 -0400499 default:
500 return gl::error(GL_INVALID_ENUM);
501 }
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +0000502
Geoff Langbfdea662014-07-23 14:16:32 -0400503 if (context)
504 {
505 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000507 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000508 }
509
Geoff Langbfdea662014-07-23 14:16:32 -0400510 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
511
512 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000513 {
Geoff Langbfdea662014-07-23 14:16:32 -0400514 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000515 }
Geoff Langbfdea662014-07-23 14:16:32 -0400516
517 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000518 }
519}
520
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000521void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000522{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000523 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 +0000524 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000525
Geoff Langbfdea662014-07-23 14:16:32 -0400526 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000527 {
Geoff Langbfdea662014-07-23 14:16:32 -0400528 return gl::error(GL_INVALID_VALUE);
529 }
530
531 if (data == NULL)
532 {
533 return;
534 }
535
536 gl::Context *context = gl::getNonLostContext();
537
538 if (context)
539 {
540 if (!gl::ValidBufferTarget(context, target))
541 {
542 return gl::error(GL_INVALID_ENUM);
543 }
544
545 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
546
547 if (!buffer)
548 {
549 return gl::error(GL_INVALID_OPERATION);
550 }
551
552 if (buffer->isMapped())
553 {
554 return gl::error(GL_INVALID_OPERATION);
555 }
556
557 // Check for possible overflow of size + offset
558 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
559 {
560 return gl::error(GL_OUT_OF_MEMORY);
561 }
562
563 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000564 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000565 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000566 }
567
Geoff Langbfdea662014-07-23 14:16:32 -0400568 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000569 }
570}
571
572GLenum __stdcall glCheckFramebufferStatus(GLenum target)
573{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000574 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000575
Geoff Langbfdea662014-07-23 14:16:32 -0400576 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000577 {
Geoff Langbfdea662014-07-23 14:16:32 -0400578 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000579 }
Geoff Langbfdea662014-07-23 14:16:32 -0400580
581 gl::Context *context = gl::getNonLostContext();
582
583 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000584 {
Geoff Langbfdea662014-07-23 14:16:32 -0400585 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
586 ASSERT(framebuffer);
587 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000588 }
589
590 return 0;
591}
592
593void __stdcall glClear(GLbitfield mask)
594{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000595 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000596
Geoff Langbfdea662014-07-23 14:16:32 -0400597 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000598
Geoff Langbfdea662014-07-23 14:16:32 -0400599 if (context)
600 {
601 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
602
603 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000604 {
Geoff Langbfdea662014-07-23 14:16:32 -0400605 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000606 }
Geoff Langbfdea662014-07-23 14:16:32 -0400607
608 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
609 {
610 return gl::error(GL_INVALID_VALUE);
611 }
612
613 context->clear(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000614 }
615}
616
617void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
618{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000619 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000620 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000621
Geoff Langbfdea662014-07-23 14:16:32 -0400622 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000623
Geoff Langbfdea662014-07-23 14:16:32 -0400624 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625 {
Geoff Langbfdea662014-07-23 14:16:32 -0400626 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000627 }
628}
629
630void __stdcall glClearDepthf(GLclampf depth)
631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000632 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000633
Geoff Langbfdea662014-07-23 14:16:32 -0400634 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000635
Geoff Langbfdea662014-07-23 14:16:32 -0400636 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000637 {
Geoff Langbfdea662014-07-23 14:16:32 -0400638 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000639 }
640}
641
642void __stdcall glClearStencil(GLint s)
643{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000644 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000645
Geoff Langbfdea662014-07-23 14:16:32 -0400646 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000647
Geoff Langbfdea662014-07-23 14:16:32 -0400648 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000649 {
Geoff Langbfdea662014-07-23 14:16:32 -0400650 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000651 }
652}
653
654void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
655{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000656 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000657 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000658
Geoff Langbfdea662014-07-23 14:16:32 -0400659 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000660
Geoff Langbfdea662014-07-23 14:16:32 -0400661 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000662 {
Geoff Langbfdea662014-07-23 14:16:32 -0400663 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000664 }
665}
666
667void __stdcall glCompileShader(GLuint shader)
668{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000669 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000670
Geoff Langbfdea662014-07-23 14:16:32 -0400671 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000672
Geoff Langbfdea662014-07-23 14:16:32 -0400673 if (context)
674 {
675 gl::Shader *shaderObject = context->getShader(shader);
676
677 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000678 {
Geoff Langbfdea662014-07-23 14:16:32 -0400679 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000680 {
Geoff Langbfdea662014-07-23 14:16:32 -0400681 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000682 }
Geoff Langbfdea662014-07-23 14:16:32 -0400683 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000685 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000686 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000687 }
Geoff Langbfdea662014-07-23 14:16:32 -0400688
689 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000690 }
Geoff Langbfdea662014-07-23 14:16:32 -0400691}
692
693void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
694 GLint border, GLsizei imageSize, const GLvoid* data)
695{
696 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
697 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
698 target, level, internalformat, width, height, border, imageSize, data);
699
700 gl::Context *context = gl::getNonLostContext();
701
702 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000703 {
Geoff Langbfdea662014-07-23 14:16:32 -0400704 if (context->getClientVersion() < 3 &&
705 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
706 0, 0, width, height, border, GL_NONE, GL_NONE, data))
707 {
708 return;
709 }
710
711 if (context->getClientVersion() >= 3 &&
712 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
713 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
714 {
715 return;
716 }
717
Geoff Lang5d601382014-07-22 15:14:06 -0400718 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
719 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400720 {
721 return gl::error(GL_INVALID_VALUE);
722 }
723
724 switch (target)
725 {
726 case GL_TEXTURE_2D:
727 {
728 gl::Texture2D *texture = context->getTexture2D();
729 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
730 }
731 break;
732
733 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
734 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
735 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
736 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
737 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
738 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
739 {
740 gl::TextureCubeMap *texture = context->getTextureCubeMap();
741 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
742 }
743 break;
744
745 default:
746 return gl::error(GL_INVALID_ENUM);
747 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000748 }
749}
750
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000751void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
752 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000754 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000755 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000756 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000757 target, level, xoffset, yoffset, width, height, format, imageSize, data);
758
Geoff Langbfdea662014-07-23 14:16:32 -0400759 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +0000760
Geoff Langbfdea662014-07-23 14:16:32 -0400761 if (context)
762 {
763 if (context->getClientVersion() < 3 &&
764 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
765 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000766 {
Geoff Langbfdea662014-07-23 14:16:32 -0400767 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000768 }
Geoff Langbfdea662014-07-23 14:16:32 -0400769
770 if (context->getClientVersion() >= 3 &&
771 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
772 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
773 {
774 return;
775 }
776
Geoff Lang5d601382014-07-22 15:14:06 -0400777 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
778 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400779 {
780 return gl::error(GL_INVALID_VALUE);
781 }
782
783 switch (target)
784 {
785 case GL_TEXTURE_2D:
786 {
787 gl::Texture2D *texture = context->getTexture2D();
788 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
789 }
790 break;
791
792 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
793 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
794 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
795 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
796 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
797 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
798 {
799 gl::TextureCubeMap *texture = context->getTextureCubeMap();
800 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
801 }
802 break;
803
804 default:
805 return gl::error(GL_INVALID_ENUM);
806 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000807 }
808}
809
810void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
811{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000812 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000813 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000814 target, level, internalformat, x, y, width, height, border);
815
Geoff Langbfdea662014-07-23 14:16:32 -0400816 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000817
Geoff Langbfdea662014-07-23 14:16:32 -0400818 if (context)
819 {
820 if (context->getClientVersion() < 3 &&
821 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
822 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000823 {
Geoff Langbfdea662014-07-23 14:16:32 -0400824 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000825 }
Geoff Langbfdea662014-07-23 14:16:32 -0400826
827 if (context->getClientVersion() >= 3 &&
828 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
829 0, 0, 0, x, y, width, height, border))
830 {
831 return;
832 }
833
834 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
835
836 switch (target)
837 {
838 case GL_TEXTURE_2D:
839 {
840 gl::Texture2D *texture = context->getTexture2D();
841 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
842 }
843 break;
844
845 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
846 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
847 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
848 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
849 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
850 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
851 {
852 gl::TextureCubeMap *texture = context->getTextureCubeMap();
853 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
854 }
855 break;
856
857 default:
858 return gl::error(GL_INVALID_ENUM);
859 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000860 }
861}
862
863void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000865 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000866 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000867 target, level, xoffset, yoffset, x, y, width, height);
868
Geoff Langbfdea662014-07-23 14:16:32 -0400869 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000870
Geoff Langbfdea662014-07-23 14:16:32 -0400871 if (context)
872 {
873 if (context->getClientVersion() < 3 &&
874 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
875 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000876 {
Geoff Langbfdea662014-07-23 14:16:32 -0400877 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000878 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000879
Geoff Langbfdea662014-07-23 14:16:32 -0400880 if (context->getClientVersion() >= 3 &&
881 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
882 xoffset, yoffset, 0, x, y, width, height, 0))
883 {
884 return;
885 }
886
887 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
888
889 switch (target)
890 {
891 case GL_TEXTURE_2D:
892 {
893 gl::Texture2D *texture = context->getTexture2D();
894 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
895 }
896 break;
897
898 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
899 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
900 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
901 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
902 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
903 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
904 {
905 gl::TextureCubeMap *texture = context->getTextureCubeMap();
906 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
907 }
908 break;
909
910 default:
911 return gl::error(GL_INVALID_ENUM);
912 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000913 }
914}
915
916GLuint __stdcall glCreateProgram(void)
917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000918 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000919
Geoff Langbfdea662014-07-23 14:16:32 -0400920 gl::Context *context = gl::getNonLostContext();
921 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000922 {
Geoff Langbfdea662014-07-23 14:16:32 -0400923 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000924 }
925
926 return 0;
927}
928
929GLuint __stdcall glCreateShader(GLenum type)
930{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000931 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000932
Geoff Langbfdea662014-07-23 14:16:32 -0400933 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000934
Geoff Langbfdea662014-07-23 14:16:32 -0400935 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000936 {
Geoff Langbfdea662014-07-23 14:16:32 -0400937 switch (type)
938 {
939 case GL_FRAGMENT_SHADER:
940 case GL_VERTEX_SHADER:
941 return context->createShader(type);
942 default:
943 return gl::error(GL_INVALID_ENUM, 0);
944 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000945 }
946
947 return 0;
948}
949
950void __stdcall glCullFace(GLenum mode)
951{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000952 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000953
Geoff Langbfdea662014-07-23 14:16:32 -0400954 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000955 {
Geoff Langbfdea662014-07-23 14:16:32 -0400956 case GL_FRONT:
957 case GL_BACK:
958 case GL_FRONT_AND_BACK:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000959 {
Geoff Langbfdea662014-07-23 14:16:32 -0400960 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000961
Geoff Langbfdea662014-07-23 14:16:32 -0400962 if (context)
963 {
964 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000965 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000966 }
Geoff Langbfdea662014-07-23 14:16:32 -0400967 break;
968 default:
969 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000970 }
971}
972
973void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
974{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000975 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000976
Geoff Langbfdea662014-07-23 14:16:32 -0400977 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000978 {
Geoff Langbfdea662014-07-23 14:16:32 -0400979 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000980 }
Geoff Langbfdea662014-07-23 14:16:32 -0400981
982 gl::Context *context = gl::getNonLostContext();
983
984 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000985 {
Geoff Langbfdea662014-07-23 14:16:32 -0400986 for (int i = 0; i < n; i++)
987 {
988 context->deleteBuffer(buffers[i]);
989 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000990 }
991}
992
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000993void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000995 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000996
Geoff Langbfdea662014-07-23 14:16:32 -0400997 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000998 {
Geoff Langbfdea662014-07-23 14:16:32 -0400999 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001000 }
Geoff Langbfdea662014-07-23 14:16:32 -04001001
1002 gl::Context *context = gl::getNonLostContext();
1003
1004 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001005 {
Geoff Langbfdea662014-07-23 14:16:32 -04001006 for (int i = 0; i < n; i++)
1007 {
1008 context->deleteFenceNV(fences[i]);
1009 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001010 }
1011}
1012
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001013void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1014{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001015 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001016
Geoff Langbfdea662014-07-23 14:16:32 -04001017 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001018 {
Geoff Langbfdea662014-07-23 14:16:32 -04001019 return gl::error(GL_INVALID_VALUE);
1020 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001021
Geoff Langbfdea662014-07-23 14:16:32 -04001022 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001023
Geoff Langbfdea662014-07-23 14:16:32 -04001024 if (context)
1025 {
1026 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001027 {
Geoff Langbfdea662014-07-23 14:16:32 -04001028 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001029 {
Geoff Langbfdea662014-07-23 14:16:32 -04001030 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001031 }
1032 }
1033 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001034}
1035
1036void __stdcall glDeleteProgram(GLuint program)
1037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001038 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001039
Geoff Langbfdea662014-07-23 14:16:32 -04001040 if (program == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001041 {
Geoff Langbfdea662014-07-23 14:16:32 -04001042 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001043 }
Geoff Langbfdea662014-07-23 14:16:32 -04001044
1045 gl::Context *context = gl::getNonLostContext();
1046
1047 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001048 {
Geoff Langbfdea662014-07-23 14:16:32 -04001049 if (!context->getProgram(program))
1050 {
1051 if(context->getShader(program))
1052 {
1053 return gl::error(GL_INVALID_OPERATION);
1054 }
1055 else
1056 {
1057 return gl::error(GL_INVALID_VALUE);
1058 }
1059 }
1060
1061 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001062 }
1063}
1064
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001065void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1066{
1067 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1068
Geoff Langbfdea662014-07-23 14:16:32 -04001069 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001070 {
Geoff Langbfdea662014-07-23 14:16:32 -04001071 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001072 }
Geoff Langbfdea662014-07-23 14:16:32 -04001073
1074 gl::Context *context = gl::getNonLostContext();
1075
1076 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001077 {
Geoff Langbfdea662014-07-23 14:16:32 -04001078 for (int i = 0; i < n; i++)
1079 {
1080 context->deleteQuery(ids[i]);
1081 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001082 }
1083}
1084
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001085void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1086{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001087 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001088
Geoff Langbfdea662014-07-23 14:16:32 -04001089 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001090 {
Geoff Langbfdea662014-07-23 14:16:32 -04001091 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001092 }
Geoff Langbfdea662014-07-23 14:16:32 -04001093
1094 gl::Context *context = gl::getNonLostContext();
1095
1096 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001097 {
Geoff Langbfdea662014-07-23 14:16:32 -04001098 for (int i = 0; i < n; i++)
1099 {
1100 context->deleteRenderbuffer(renderbuffers[i]);
1101 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001102 }
1103}
1104
1105void __stdcall glDeleteShader(GLuint shader)
1106{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001107 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001108
Geoff Langbfdea662014-07-23 14:16:32 -04001109 if (shader == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001110 {
Geoff Langbfdea662014-07-23 14:16:32 -04001111 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001112 }
Geoff Langbfdea662014-07-23 14:16:32 -04001113
1114 gl::Context *context = gl::getNonLostContext();
1115
1116 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001117 {
Geoff Langbfdea662014-07-23 14:16:32 -04001118 if (!context->getShader(shader))
1119 {
1120 if(context->getProgram(shader))
1121 {
1122 return gl::error(GL_INVALID_OPERATION);
1123 }
1124 else
1125 {
1126 return gl::error(GL_INVALID_VALUE);
1127 }
1128 }
1129
1130 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001131 }
1132}
1133
1134void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1135{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001136 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001137
Geoff Langbfdea662014-07-23 14:16:32 -04001138 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001139 {
Geoff Langbfdea662014-07-23 14:16:32 -04001140 return gl::error(GL_INVALID_VALUE);
1141 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001142
Geoff Langbfdea662014-07-23 14:16:32 -04001143 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001144
Geoff Langbfdea662014-07-23 14:16:32 -04001145 if (context)
1146 {
1147 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001148 {
Geoff Langbfdea662014-07-23 14:16:32 -04001149 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001150 {
Geoff Langbfdea662014-07-23 14:16:32 -04001151 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001152 }
1153 }
1154 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001155}
1156
1157void __stdcall glDepthFunc(GLenum func)
1158{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001159 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001160
Geoff Langbfdea662014-07-23 14:16:32 -04001161 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001162 {
Geoff Langbfdea662014-07-23 14:16:32 -04001163 case GL_NEVER:
1164 case GL_ALWAYS:
1165 case GL_LESS:
1166 case GL_LEQUAL:
1167 case GL_EQUAL:
1168 case GL_GREATER:
1169 case GL_GEQUAL:
1170 case GL_NOTEQUAL:
1171 break;
1172 default:
1173 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001174 }
Geoff Langbfdea662014-07-23 14:16:32 -04001175
1176 gl::Context *context = gl::getNonLostContext();
1177
1178 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001179 {
Geoff Langbfdea662014-07-23 14:16:32 -04001180 context->getState().setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001181 }
1182}
1183
1184void __stdcall glDepthMask(GLboolean flag)
1185{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001186 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001187
Geoff Langbfdea662014-07-23 14:16:32 -04001188 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001189
Geoff Langbfdea662014-07-23 14:16:32 -04001190 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001191 {
Geoff Langbfdea662014-07-23 14:16:32 -04001192 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001193 }
1194}
1195
1196void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1197{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001198 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001199
Geoff Langbfdea662014-07-23 14:16:32 -04001200 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001201
Geoff Langbfdea662014-07-23 14:16:32 -04001202 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001203 {
Geoff Langbfdea662014-07-23 14:16:32 -04001204 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001205 }
1206}
1207
1208void __stdcall glDetachShader(GLuint program, GLuint shader)
1209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001210 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001211
Geoff Langbfdea662014-07-23 14:16:32 -04001212 gl::Context *context = gl::getNonLostContext();
1213
1214 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001215 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001216
Geoff Langbfdea662014-07-23 14:16:32 -04001217 gl::Program *programObject = context->getProgram(program);
1218 gl::Shader *shaderObject = context->getShader(shader);
1219
1220 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001221 {
Geoff Langbfdea662014-07-23 14:16:32 -04001222 gl::Shader *shaderByProgramHandle;
1223 shaderByProgramHandle = context->getShader(program);
1224 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001225 {
Geoff Langbfdea662014-07-23 14:16:32 -04001226 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001227 }
Geoff Langbfdea662014-07-23 14:16:32 -04001228 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001229 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001230 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001231 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001232 }
Geoff Langbfdea662014-07-23 14:16:32 -04001233
1234 if (!shaderObject)
1235 {
1236 gl::Program *programByShaderHandle = context->getProgram(shader);
1237 if (!programByShaderHandle)
1238 {
1239 return gl::error(GL_INVALID_VALUE);
1240 }
1241 else
1242 {
1243 return gl::error(GL_INVALID_OPERATION);
1244 }
1245 }
1246
1247 if (!programObject->detachShader(shaderObject))
1248 {
1249 return gl::error(GL_INVALID_OPERATION);
1250 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001251 }
1252}
1253
1254void __stdcall glDisable(GLenum cap)
1255{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001256 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001257
Geoff Langbfdea662014-07-23 14:16:32 -04001258 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001259
Geoff Langbfdea662014-07-23 14:16:32 -04001260 if (context)
1261 {
1262 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001263 {
Geoff Langbfdea662014-07-23 14:16:32 -04001264 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001265 }
Geoff Langbfdea662014-07-23 14:16:32 -04001266
1267 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001268 }
1269}
1270
1271void __stdcall glDisableVertexAttribArray(GLuint index)
1272{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001273 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001274
Geoff Langbfdea662014-07-23 14:16:32 -04001275 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001276 {
Geoff Langbfdea662014-07-23 14:16:32 -04001277 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001278 }
Geoff Langbfdea662014-07-23 14:16:32 -04001279
1280 gl::Context *context = gl::getNonLostContext();
1281
1282 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001283 {
Geoff Langbfdea662014-07-23 14:16:32 -04001284 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001285 }
1286}
1287
1288void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001290 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001291
Geoff Langbfdea662014-07-23 14:16:32 -04001292 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001293
Geoff Langbfdea662014-07-23 14:16:32 -04001294 if (context)
1295 {
Jamie Madill2b976812014-08-25 15:47:49 -04001296 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001297 {
Geoff Langbfdea662014-07-23 14:16:32 -04001298 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001299 }
Geoff Langbfdea662014-07-23 14:16:32 -04001300
1301 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001302 }
1303}
1304
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001305void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1306{
1307 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1308
Geoff Langbfdea662014-07-23 14:16:32 -04001309 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001310
Geoff Langbfdea662014-07-23 14:16:32 -04001311 if (context)
1312 {
1313 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001314 {
Geoff Langbfdea662014-07-23 14:16:32 -04001315 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001316 }
Geoff Langbfdea662014-07-23 14:16:32 -04001317
1318 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001319 }
1320}
1321
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001322void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001323{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001324 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 +00001325 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001326
Geoff Langbfdea662014-07-23 14:16:32 -04001327 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001328
Geoff Langbfdea662014-07-23 14:16:32 -04001329 if (context)
1330 {
Jamie Madill2b976812014-08-25 15:47:49 -04001331 rx::RangeUI indexRange;
1332 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001333 {
Geoff Langbfdea662014-07-23 14:16:32 -04001334 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001335 }
Geoff Langbfdea662014-07-23 14:16:32 -04001336
Jamie Madill2b976812014-08-25 15:47:49 -04001337 context->drawElements(mode, count, type, indices, 0, indexRange);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001338 }
1339}
1340
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001341void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1342{
1343 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1344 mode, count, type, indices, primcount);
1345
Geoff Langbfdea662014-07-23 14:16:32 -04001346 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001347
Geoff Langbfdea662014-07-23 14:16:32 -04001348 if (context)
1349 {
Jamie Madill2b976812014-08-25 15:47:49 -04001350 rx::RangeUI indexRange;
1351 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001352 {
Geoff Langbfdea662014-07-23 14:16:32 -04001353 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001354 }
Geoff Langbfdea662014-07-23 14:16:32 -04001355
Jamie Madill2b976812014-08-25 15:47:49 -04001356 context->drawElements(mode, count, type, indices, primcount, indexRange);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001357 }
1358}
1359
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001360void __stdcall glEnable(GLenum cap)
1361{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001362 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001363
Geoff Langbfdea662014-07-23 14:16:32 -04001364 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001365
Geoff Langbfdea662014-07-23 14:16:32 -04001366 if (context)
1367 {
1368 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001369 {
Geoff Langbfdea662014-07-23 14:16:32 -04001370 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001371 }
Geoff Langbfdea662014-07-23 14:16:32 -04001372
1373 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001374 }
1375}
1376
1377void __stdcall glEnableVertexAttribArray(GLuint index)
1378{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001379 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001380
Geoff Langbfdea662014-07-23 14:16:32 -04001381 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001382 {
Geoff Langbfdea662014-07-23 14:16:32 -04001383 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001384 }
Geoff Langbfdea662014-07-23 14:16:32 -04001385
1386 gl::Context *context = gl::getNonLostContext();
1387
1388 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001389 {
Geoff Langbfdea662014-07-23 14:16:32 -04001390 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001391 }
1392}
1393
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001394void __stdcall glEndQueryEXT(GLenum target)
1395{
1396 EVENT("GLenum target = 0x%X)", target);
1397
Geoff Langbfdea662014-07-23 14:16:32 -04001398 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001399
Geoff Langbfdea662014-07-23 14:16:32 -04001400 if (context)
1401 {
1402 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001403 {
Geoff Langbfdea662014-07-23 14:16:32 -04001404 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001405 }
Geoff Langbfdea662014-07-23 14:16:32 -04001406
1407 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001408 }
1409}
1410
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001411void __stdcall glFinishFenceNV(GLuint fence)
1412{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001413 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001414
Geoff Langbfdea662014-07-23 14:16:32 -04001415 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001416
Geoff Langbfdea662014-07-23 14:16:32 -04001417 if (context)
1418 {
1419 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1420
1421 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001422 {
Geoff Langbfdea662014-07-23 14:16:32 -04001423 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001424 }
Geoff Langbfdea662014-07-23 14:16:32 -04001425
1426 if (fenceObject->isFence() != GL_TRUE)
1427 {
1428 return gl::error(GL_INVALID_OPERATION);
1429 }
1430
1431 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001432 }
1433}
1434
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001435void __stdcall glFinish(void)
1436{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001437 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001438
Geoff Langbfdea662014-07-23 14:16:32 -04001439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001440
Geoff Langbfdea662014-07-23 14:16:32 -04001441 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001442 {
Geoff Langbfdea662014-07-23 14:16:32 -04001443 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001444 }
1445}
1446
1447void __stdcall glFlush(void)
1448{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001449 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001450
Geoff Langbfdea662014-07-23 14:16:32 -04001451 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001452
Geoff Langbfdea662014-07-23 14:16:32 -04001453 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001454 {
Geoff Langbfdea662014-07-23 14:16:32 -04001455 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001456 }
1457}
1458
1459void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001461 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001462 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001463
Geoff Langbfdea662014-07-23 14:16:32 -04001464 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001465 {
Geoff Langbfdea662014-07-23 14:16:32 -04001466 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001467 }
Geoff Langbfdea662014-07-23 14:16:32 -04001468
1469 gl::Context *context = gl::getNonLostContext();
1470
1471 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001472 {
Geoff Langbfdea662014-07-23 14:16:32 -04001473 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1474 {
1475 return;
1476 }
1477
1478 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1479 ASSERT(framebuffer);
1480
1481 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1482 {
1483 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1484 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1485 }
1486 else
1487 {
1488 switch (attachment)
1489 {
1490 case GL_DEPTH_ATTACHMENT:
1491 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1492 break;
1493 case GL_STENCIL_ATTACHMENT:
1494 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1495 break;
1496 case GL_DEPTH_STENCIL_ATTACHMENT:
1497 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1498 break;
1499 default:
1500 UNREACHABLE();
1501 break;
1502 }
1503 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001504 }
1505}
1506
1507void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1508{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001509 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001510 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001511
Geoff Langbfdea662014-07-23 14:16:32 -04001512 gl::Context *context = gl::getNonLostContext();
1513 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001514 {
Geoff Langbfdea662014-07-23 14:16:32 -04001515 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001516 {
Geoff Langbfdea662014-07-23 14:16:32 -04001517 return;
1518 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001519
Geoff Langbfdea662014-07-23 14:16:32 -04001520 if (texture == 0)
1521 {
1522 textarget = GL_NONE;
1523 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001524
Geoff Langbfdea662014-07-23 14:16:32 -04001525 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001526
Geoff Langbfdea662014-07-23 14:16:32 -04001527 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1528 {
1529 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1530 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1531 }
1532 else
1533 {
1534 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001535 {
Geoff Langbfdea662014-07-23 14:16:32 -04001536 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1537 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1538 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001539 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001540 }
1541 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001542}
1543
1544void __stdcall glFrontFace(GLenum mode)
1545{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001546 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001547
Geoff Langbfdea662014-07-23 14:16:32 -04001548 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001549 {
Geoff Langbfdea662014-07-23 14:16:32 -04001550 case GL_CW:
1551 case GL_CCW:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001552 {
Geoff Langbfdea662014-07-23 14:16:32 -04001553 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001554
Geoff Langbfdea662014-07-23 14:16:32 -04001555 if (context)
1556 {
1557 context->getState().setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001558 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001559 }
Geoff Langbfdea662014-07-23 14:16:32 -04001560 break;
1561 default:
1562 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001563 }
1564}
1565
1566void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1567{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001568 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001569
Geoff Langbfdea662014-07-23 14:16:32 -04001570 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001571 {
Geoff Langbfdea662014-07-23 14:16:32 -04001572 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001573 }
Geoff Langbfdea662014-07-23 14:16:32 -04001574
1575 gl::Context *context = gl::getNonLostContext();
1576
1577 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001578 {
Geoff Langbfdea662014-07-23 14:16:32 -04001579 for (int i = 0; i < n; i++)
1580 {
1581 buffers[i] = context->createBuffer();
1582 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001583 }
1584}
1585
1586void __stdcall glGenerateMipmap(GLenum target)
1587{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001588 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001589
Geoff Langbfdea662014-07-23 14:16:32 -04001590 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001591
Geoff Langbfdea662014-07-23 14:16:32 -04001592 if (context)
1593 {
1594 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001595 {
Geoff Langbfdea662014-07-23 14:16:32 -04001596 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001597 }
Geoff Langbfdea662014-07-23 14:16:32 -04001598
1599 gl::Texture *texture = context->getTargetTexture(target);
1600
1601 if (texture == NULL)
1602 {
1603 return gl::error(GL_INVALID_OPERATION);
1604 }
1605
1606 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1607 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001608 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001609
1610 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1611 // unsized formats or that are color renderable and filterable. Since we do not track if
1612 // the texture was created with sized or unsized format (only sized formats are stored),
1613 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1614 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1615 // textures since they're the only texture format that can be created with unsized formats
1616 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1617 // was the last version to use add them.
1618 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1619 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1620 internalFormat == GL_ALPHA8_EXT;
1621
Geoff Lang5d601382014-07-22 15:14:06 -04001622 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1623 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001624 {
1625 return gl::error(GL_INVALID_OPERATION);
1626 }
1627
1628 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001629 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001630 {
1631 return gl::error(GL_INVALID_OPERATION);
1632 }
1633
1634 // Non-power of 2 ES2 check
1635 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1636 {
1637 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
1638 return gl::error(GL_INVALID_OPERATION);
1639 }
1640
1641 // Cube completeness check
1642 if (target == GL_TEXTURE_CUBE_MAP)
1643 {
1644 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1645 if (!textureCube->isCubeComplete())
1646 {
1647 return gl::error(GL_INVALID_OPERATION);
1648 }
1649 }
1650
1651 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001652 }
1653}
1654
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001655void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1656{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001657 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001658
Geoff Langbfdea662014-07-23 14:16:32 -04001659 if (n < 0)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001660 {
Geoff Langbfdea662014-07-23 14:16:32 -04001661 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001662 }
Geoff Langbfdea662014-07-23 14:16:32 -04001663
1664 gl::Context *context = gl::getNonLostContext();
1665
1666 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001667 {
Geoff Langbfdea662014-07-23 14:16:32 -04001668 for (int i = 0; i < n; i++)
1669 {
1670 fences[i] = context->createFenceNV();
1671 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001672 }
1673}
1674
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001675void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1676{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001677 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001678
Geoff Langbfdea662014-07-23 14:16:32 -04001679 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001680 {
Geoff Langbfdea662014-07-23 14:16:32 -04001681 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001682 }
Geoff Langbfdea662014-07-23 14:16:32 -04001683
1684 gl::Context *context = gl::getNonLostContext();
1685
1686 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001687 {
Geoff Langbfdea662014-07-23 14:16:32 -04001688 for (int i = 0; i < n; i++)
1689 {
1690 framebuffers[i] = context->createFramebuffer();
1691 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001692 }
1693}
1694
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001695void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1696{
1697 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1698
Geoff Langbfdea662014-07-23 14:16:32 -04001699 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001700
Geoff Langbfdea662014-07-23 14:16:32 -04001701 if (context)
1702 {
1703 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001704 {
Geoff Langbfdea662014-07-23 14:16:32 -04001705 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001706 }
Geoff Langbfdea662014-07-23 14:16:32 -04001707
1708 for (GLsizei i = 0; i < n; i++)
1709 {
1710 ids[i] = context->createQuery();
1711 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001712 }
1713}
1714
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001715void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1716{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001717 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001718
Geoff Langbfdea662014-07-23 14:16:32 -04001719 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001720 {
Geoff Langbfdea662014-07-23 14:16:32 -04001721 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001722 }
Geoff Langbfdea662014-07-23 14:16:32 -04001723
1724 gl::Context *context = gl::getNonLostContext();
1725
1726 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001727 {
Geoff Langbfdea662014-07-23 14:16:32 -04001728 for (int i = 0; i < n; i++)
1729 {
1730 renderbuffers[i] = context->createRenderbuffer();
1731 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001732 }
1733}
1734
1735void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1736{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001737 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001738
Geoff Langbfdea662014-07-23 14:16:32 -04001739 if (n < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001740 {
Geoff Langbfdea662014-07-23 14:16:32 -04001741 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001742 }
Geoff Langbfdea662014-07-23 14:16:32 -04001743
1744 gl::Context *context = gl::getNonLostContext();
1745
1746 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001747 {
Geoff Langbfdea662014-07-23 14:16:32 -04001748 for (int i = 0; i < n; i++)
1749 {
1750 textures[i] = context->createTexture();
1751 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001752 }
1753}
1754
daniel@transgaming.com85423182010-04-22 13:35:27 +00001755void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001756{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001757 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001758 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001759 program, index, bufsize, length, size, type, name);
1760
Geoff Langbfdea662014-07-23 14:16:32 -04001761 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001762 {
Geoff Langbfdea662014-07-23 14:16:32 -04001763 return gl::error(GL_INVALID_VALUE);
1764 }
1765
1766 gl::Context *context = gl::getNonLostContext();
1767
1768 if (context)
1769 {
1770 gl::Program *programObject = context->getProgram(program);
1771
1772 if (!programObject)
1773 {
1774 if (context->getShader(program))
1775 {
1776 return gl::error(GL_INVALID_OPERATION);
1777 }
1778 else
1779 {
1780 return gl::error(GL_INVALID_VALUE);
1781 }
1782 }
1783
1784 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001786 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001787 }
1788
Geoff Langbfdea662014-07-23 14:16:32 -04001789 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001790 }
1791}
1792
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001793void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001794{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001795 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001796 "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 +00001797 program, index, bufsize, length, size, type, name);
1798
Geoff Langbfdea662014-07-23 14:16:32 -04001799 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001800 {
Geoff Langbfdea662014-07-23 14:16:32 -04001801 return gl::error(GL_INVALID_VALUE);
1802 }
1803
1804 gl::Context *context = gl::getNonLostContext();
1805
1806 if (context)
1807 {
1808 gl::Program *programObject = context->getProgram(program);
1809
1810 if (!programObject)
1811 {
1812 if (context->getShader(program))
1813 {
1814 return gl::error(GL_INVALID_OPERATION);
1815 }
1816 else
1817 {
1818 return gl::error(GL_INVALID_VALUE);
1819 }
1820 }
1821
1822 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001823 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001824 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001825 }
1826
Geoff Langbfdea662014-07-23 14:16:32 -04001827 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001828 }
1829}
1830
1831void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1832{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001833 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 +00001834 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001835
Geoff Langbfdea662014-07-23 14:16:32 -04001836 if (maxcount < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001837 {
Geoff Langbfdea662014-07-23 14:16:32 -04001838 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001839 }
Geoff Langbfdea662014-07-23 14:16:32 -04001840
1841 gl::Context *context = gl::getNonLostContext();
1842
1843 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001844 {
Geoff Langbfdea662014-07-23 14:16:32 -04001845 gl::Program *programObject = context->getProgram(program);
1846
1847 if (!programObject)
1848 {
1849 if (context->getShader(program))
1850 {
1851 return gl::error(GL_INVALID_OPERATION);
1852 }
1853 else
1854 {
1855 return gl::error(GL_INVALID_VALUE);
1856 }
1857 }
1858
1859 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001860 }
1861}
1862
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001863int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001865 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001866
Geoff Langbfdea662014-07-23 14:16:32 -04001867 gl::Context *context = gl::getNonLostContext();
1868
1869 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001870 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001871
Geoff Langbfdea662014-07-23 14:16:32 -04001872 gl::Program *programObject = context->getProgram(program);
1873
1874 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001875 {
Geoff Langbfdea662014-07-23 14:16:32 -04001876 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001878 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001879 }
Geoff Langbfdea662014-07-23 14:16:32 -04001880 else
1881 {
1882 return gl::error(GL_INVALID_VALUE, -1);
1883 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001884 }
Geoff Langbfdea662014-07-23 14:16:32 -04001885
1886 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1887 if (!programObject->isLinked() || !programBinary)
1888 {
1889 return gl::error(GL_INVALID_OPERATION, -1);
1890 }
1891
1892 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001893 }
1894
1895 return -1;
1896}
1897
1898void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1899{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001900 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001901
Geoff Langbfdea662014-07-23 14:16:32 -04001902 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00001903
Geoff Langbfdea662014-07-23 14:16:32 -04001904 if (context)
1905 {
1906 GLenum nativeType;
1907 unsigned int numParams = 0;
1908 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001909 {
Geoff Langbfdea662014-07-23 14:16:32 -04001910 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001911 }
Geoff Langbfdea662014-07-23 14:16:32 -04001912
1913 if (nativeType == GL_BOOL)
1914 {
1915 context->getBooleanv(pname, params);
1916 }
1917 else
1918 {
1919 CastStateValues(context, nativeType, pname, numParams, params);
1920 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001921 }
1922}
1923
1924void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1925{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001926 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 +00001927
Geoff Langbfdea662014-07-23 14:16:32 -04001928 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001929
Geoff Langbfdea662014-07-23 14:16:32 -04001930 if (context)
1931 {
1932 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001933 {
Geoff Langbfdea662014-07-23 14:16:32 -04001934 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001935 }
Geoff Langbfdea662014-07-23 14:16:32 -04001936
1937 if (!gl::ValidBufferParameter(context, pname))
1938 {
1939 return gl::error(GL_INVALID_ENUM);
1940 }
1941
1942 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
1943
1944 if (!buffer)
1945 {
1946 // A null buffer means that "0" is bound to the requested buffer target
1947 return gl::error(GL_INVALID_OPERATION);
1948 }
1949
1950 switch (pname)
1951 {
1952 case GL_BUFFER_USAGE:
1953 *params = static_cast<GLint>(buffer->getUsage());
1954 break;
1955 case GL_BUFFER_SIZE:
1956 *params = gl::clampCast<GLint>(buffer->getSize());
1957 break;
1958 case GL_BUFFER_ACCESS_FLAGS:
1959 *params = buffer->getAccessFlags();
1960 break;
1961 case GL_BUFFER_MAPPED:
1962 *params = static_cast<GLint>(buffer->isMapped());
1963 break;
1964 case GL_BUFFER_MAP_OFFSET:
1965 *params = gl::clampCast<GLint>(buffer->getMapOffset());
1966 break;
1967 case GL_BUFFER_MAP_LENGTH:
1968 *params = gl::clampCast<GLint>(buffer->getMapLength());
1969 break;
1970 default: UNREACHABLE(); break;
1971 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001972 }
1973}
1974
1975GLenum __stdcall glGetError(void)
1976{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001977 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001978
1979 gl::Context *context = gl::getContext();
1980
1981 if (context)
1982 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00001983 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001984 }
1985
1986 return GL_NO_ERROR;
1987}
1988
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001989void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
1990{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001991 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001992
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001993
Geoff Langbfdea662014-07-23 14:16:32 -04001994 gl::Context *context = gl::getNonLostContext();
1995
1996 if (context)
1997 {
1998 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1999
2000 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002001 {
Geoff Langbfdea662014-07-23 14:16:32 -04002002 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002003 }
Geoff Langbfdea662014-07-23 14:16:32 -04002004
2005 if (fenceObject->isFence() != GL_TRUE)
2006 {
2007 return gl::error(GL_INVALID_OPERATION);
2008 }
2009
2010 switch (pname)
2011 {
2012 case GL_FENCE_STATUS_NV:
2013 case GL_FENCE_CONDITION_NV:
2014 break;
2015
2016 default: return gl::error(GL_INVALID_ENUM);
2017 }
2018
2019 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002020 }
2021}
2022
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002023void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2024{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002025 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002026
Geoff Langbfdea662014-07-23 14:16:32 -04002027 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002028
Geoff Langbfdea662014-07-23 14:16:32 -04002029 if (context)
2030 {
2031 GLenum nativeType;
2032 unsigned int numParams = 0;
2033 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002034 {
Geoff Langbfdea662014-07-23 14:16:32 -04002035 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002036 }
Geoff Langbfdea662014-07-23 14:16:32 -04002037
2038 if (nativeType == GL_FLOAT)
2039 {
2040 context->getFloatv(pname, params);
2041 }
2042 else
2043 {
2044 CastStateValues(context, nativeType, pname, numParams, params);
2045 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002046 }
2047}
2048
2049void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2050{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002051 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 +00002052 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002053
Geoff Langbfdea662014-07-23 14:16:32 -04002054 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002055
Geoff Langbfdea662014-07-23 14:16:32 -04002056 if (context)
2057 {
2058 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002059 {
Geoff Langbfdea662014-07-23 14:16:32 -04002060 return gl::error(GL_INVALID_ENUM);
2061 }
2062
2063 int clientVersion = context->getClientVersion();
2064
2065 switch (pname)
2066 {
2067 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2068 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2069 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2070 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2071 break;
2072 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2073 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002075 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002076 }
Geoff Langbfdea662014-07-23 14:16:32 -04002077 break;
2078 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2079 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2080 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2081 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2082 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2083 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2084 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2085 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2086 if (clientVersion < 3)
2087 {
2088 return gl::error(GL_INVALID_ENUM);
2089 }
2090 break;
2091 default:
2092 return gl::error(GL_INVALID_ENUM);
2093 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002094
Geoff Langbfdea662014-07-23 14:16:32 -04002095 // Determine if the attachment is a valid enum
2096 switch (attachment)
2097 {
2098 case GL_BACK:
2099 case GL_FRONT:
2100 case GL_DEPTH:
2101 case GL_STENCIL:
2102 case GL_DEPTH_STENCIL_ATTACHMENT:
2103 if (clientVersion < 3)
2104 {
2105 return gl::error(GL_INVALID_ENUM);
2106 }
2107 break;
2108
2109 case GL_DEPTH_ATTACHMENT:
2110 case GL_STENCIL_ATTACHMENT:
2111 break;
2112
2113 default:
2114 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2115 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2116 {
2117 return gl::error(GL_INVALID_ENUM);
2118 }
2119 break;
2120 }
2121
2122 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2123 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2124
2125 if (framebufferHandle == 0)
2126 {
2127 if (clientVersion < 3)
2128 {
2129 return gl::error(GL_INVALID_OPERATION);
2130 }
2131
2132 switch (attachment)
2133 {
2134 case GL_BACK:
2135 case GL_DEPTH:
2136 case GL_STENCIL:
2137 break;
2138 default:
2139 return gl::error(GL_INVALID_OPERATION);
2140 }
2141 }
2142 else
2143 {
2144 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2145 {
2146 // Valid attachment query
2147 }
2148 else
2149 {
2150 switch (attachment)
2151 {
2152 case GL_DEPTH_ATTACHMENT:
2153 case GL_STENCIL_ATTACHMENT:
2154 break;
2155 case GL_DEPTH_STENCIL_ATTACHMENT:
2156 if (framebuffer->hasValidDepthStencil())
2157 {
2158 return gl::error(GL_INVALID_OPERATION);
2159 }
2160 break;
2161 default:
2162 return gl::error(GL_INVALID_OPERATION);
2163 }
2164 }
2165 }
2166
2167 GLenum attachmentType = GL_NONE;
2168 GLuint attachmentHandle = 0;
2169 GLuint attachmentLevel = 0;
2170 GLuint attachmentLayer = 0;
2171
2172 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2173
2174 if (attachmentObject)
2175 {
2176 attachmentType = attachmentObject->type();
2177 attachmentHandle = attachmentObject->id();
2178 attachmentLevel = attachmentObject->mipLevel();
2179 attachmentLayer = attachmentObject->layer();
2180 }
2181
2182 GLenum attachmentObjectType; // Type category
2183 if (framebufferHandle == 0)
2184 {
2185 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2186 }
2187 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2188 {
2189 attachmentObjectType = attachmentType;
2190 }
2191 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2192 {
2193 attachmentObjectType = GL_TEXTURE;
2194 }
2195 else
2196 {
2197 UNREACHABLE();
2198 return;
2199 }
2200
2201 if (attachmentObjectType == GL_NONE)
2202 {
2203 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2204 // is NONE, then querying any other pname will generate INVALID_ENUM.
2205
2206 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2207 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2208 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002209
Geoff Lang646559f2013-08-15 11:08:15 -04002210 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002211 {
Geoff Lang646559f2013-08-15 11:08:15 -04002212 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002213 *params = attachmentObjectType;
2214 break;
2215
Geoff Lang646559f2013-08-15 11:08:15 -04002216 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002217 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002218 {
Geoff Lang05b05022014-06-11 15:31:45 -04002219 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002220 }
Geoff Langbfdea662014-07-23 14:16:32 -04002221 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002222 break;
2223
2224 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002225 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002226 {
Geoff Langbfdea662014-07-23 14:16:32 -04002227 return gl::error(GL_INVALID_ENUM);
Geoff Lang646559f2013-08-15 11:08:15 -04002228 }
2229 else
2230 {
Geoff Langbfdea662014-07-23 14:16:32 -04002231 gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002232 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002233 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002234 }
Geoff Langbfdea662014-07-23 14:16:32 -04002235 else
2236 {
2237 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2238 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2239 ASSERT(attachmentObject != NULL);
2240
2241 switch (pname)
2242 {
2243 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2244 *params = attachmentObjectType;
2245 break;
2246
2247 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2248 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2249 {
2250 return gl::error(GL_INVALID_ENUM);
2251 }
2252 *params = attachmentHandle;
2253 break;
2254
2255 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2256 if (attachmentObjectType != GL_TEXTURE)
2257 {
2258 return gl::error(GL_INVALID_ENUM);
2259 }
2260 *params = attachmentLevel;
2261 break;
2262
2263 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2264 if (attachmentObjectType != GL_TEXTURE)
2265 {
2266 return gl::error(GL_INVALID_ENUM);
2267 }
2268 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2269 break;
2270
2271 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2272 *params = attachmentObject->getRedSize();
2273 break;
2274
2275 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2276 *params = attachmentObject->getGreenSize();
2277 break;
2278
2279 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2280 *params = attachmentObject->getBlueSize();
2281 break;
2282
2283 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2284 *params = attachmentObject->getAlphaSize();
2285 break;
2286
2287 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2288 *params = attachmentObject->getDepthSize();
2289 break;
2290
2291 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2292 *params = attachmentObject->getStencilSize();
2293 break;
2294
2295 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2296 if (attachment == GL_DEPTH_STENCIL)
2297 {
2298 gl::error(GL_INVALID_OPERATION);
2299 }
2300 *params = attachmentObject->getComponentType();
2301 break;
2302
2303 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2304 *params = attachmentObject->getColorEncoding();
2305 break;
2306
2307 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2308 if (attachmentObjectType != GL_TEXTURE)
2309 {
2310 return gl::error(GL_INVALID_ENUM);
2311 }
2312 *params = attachmentLayer;
2313 break;
2314
2315 default:
2316 UNREACHABLE();
2317 break;
2318 }
2319 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002320 }
2321}
2322
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002323GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2324{
2325 EVENT("()");
2326
Geoff Langbfdea662014-07-23 14:16:32 -04002327 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002328
Geoff Langbfdea662014-07-23 14:16:32 -04002329 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002330 {
Geoff Langbfdea662014-07-23 14:16:32 -04002331 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002332 }
Geoff Langbfdea662014-07-23 14:16:32 -04002333
2334 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002335}
2336
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002337void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2338{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002339 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002340
Geoff Langbfdea662014-07-23 14:16:32 -04002341 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002342
Geoff Langbfdea662014-07-23 14:16:32 -04002343 if (context)
2344 {
2345 GLenum nativeType;
2346 unsigned int numParams = 0;
2347
2348 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349 {
Geoff Langbfdea662014-07-23 14:16:32 -04002350 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002351 }
Geoff Langbfdea662014-07-23 14:16:32 -04002352
2353 if (nativeType == GL_INT)
2354 {
2355 context->getIntegerv(pname, params);
2356 }
2357 else
2358 {
2359 CastStateValues(context, nativeType, pname, numParams, params);
2360 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002361 }
2362}
2363
2364void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2365{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002366 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002367
Geoff Langbfdea662014-07-23 14:16:32 -04002368 gl::Context *context = gl::getNonLostContext();
2369
2370 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002371 {
Geoff Langbfdea662014-07-23 14:16:32 -04002372 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002373
Geoff Langbfdea662014-07-23 14:16:32 -04002374 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002375 {
Geoff Langbfdea662014-07-23 14:16:32 -04002376 return gl::error(GL_INVALID_VALUE);
2377 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002378
Geoff Langbfdea662014-07-23 14:16:32 -04002379 if (context->getClientVersion() < 3)
2380 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002381 switch (pname)
2382 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002383 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002384 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002385 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002386 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002387 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002388 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002389 }
2390 }
Geoff Langbfdea662014-07-23 14:16:32 -04002391
2392 switch (pname)
2393 {
2394 case GL_DELETE_STATUS:
2395 *params = programObject->isFlaggedForDeletion();
2396 return;
2397 case GL_LINK_STATUS:
2398 *params = programObject->isLinked();
2399 return;
2400 case GL_VALIDATE_STATUS:
2401 *params = programObject->isValidated();
2402 return;
2403 case GL_INFO_LOG_LENGTH:
2404 *params = programObject->getInfoLogLength();
2405 return;
2406 case GL_ATTACHED_SHADERS:
2407 *params = programObject->getAttachedShadersCount();
2408 return;
2409 case GL_ACTIVE_ATTRIBUTES:
2410 *params = programObject->getActiveAttributeCount();
2411 return;
2412 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2413 *params = programObject->getActiveAttributeMaxLength();
2414 return;
2415 case GL_ACTIVE_UNIFORMS:
2416 *params = programObject->getActiveUniformCount();
2417 return;
2418 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2419 *params = programObject->getActiveUniformMaxLength();
2420 return;
2421 case GL_PROGRAM_BINARY_LENGTH_OES:
2422 *params = programObject->getProgramBinaryLength();
2423 return;
2424 case GL_ACTIVE_UNIFORM_BLOCKS:
2425 *params = programObject->getActiveUniformBlockCount();
2426 return;
2427 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2428 *params = programObject->getActiveUniformBlockMaxLength();
2429 break;
2430 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2431 *params = programObject->getTransformFeedbackBufferMode();
2432 break;
2433 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2434 *params = programObject->getTransformFeedbackVaryingCount();
2435 break;
2436 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2437 *params = programObject->getTransformFeedbackVaryingMaxLength();
2438 break;
2439 default:
2440 return gl::error(GL_INVALID_ENUM);
2441 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442 }
2443}
2444
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002445void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002446{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002447 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 +00002448 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449
Geoff Langbfdea662014-07-23 14:16:32 -04002450 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002451 {
Geoff Langbfdea662014-07-23 14:16:32 -04002452 return gl::error(GL_INVALID_VALUE);
2453 }
2454
2455 gl::Context *context = gl::getNonLostContext();
2456
2457 if (context)
2458 {
2459 gl::Program *programObject = context->getProgram(program);
2460
2461 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002463 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002464 }
2465
Geoff Langbfdea662014-07-23 14:16:32 -04002466 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002467 }
2468}
2469
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002470void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2471{
2472 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2473
Geoff Langbfdea662014-07-23 14:16:32 -04002474 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002475
Geoff Langbfdea662014-07-23 14:16:32 -04002476 if (context)
2477 {
2478 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002479 {
Geoff Langbfdea662014-07-23 14:16:32 -04002480 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002481 }
Geoff Langbfdea662014-07-23 14:16:32 -04002482
2483 switch (pname)
2484 {
2485 case GL_CURRENT_QUERY_EXT:
2486 params[0] = context->getState().getActiveQueryId(target);
2487 break;
2488
2489 default:
2490 return gl::error(GL_INVALID_ENUM);
2491 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002492 }
2493}
2494
2495void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2496{
2497 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2498
Geoff Langbfdea662014-07-23 14:16:32 -04002499 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002500
Geoff Langbfdea662014-07-23 14:16:32 -04002501 if (context)
2502 {
2503 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2504
2505 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002506 {
Geoff Langbfdea662014-07-23 14:16:32 -04002507 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002508 }
Geoff Langbfdea662014-07-23 14:16:32 -04002509
2510 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2511 {
2512 return gl::error(GL_INVALID_OPERATION);
2513 }
2514
2515 switch(pname)
2516 {
2517 case GL_QUERY_RESULT_EXT:
2518 params[0] = queryObject->getResult();
2519 break;
2520 case GL_QUERY_RESULT_AVAILABLE_EXT:
2521 params[0] = queryObject->isResultAvailable();
2522 break;
2523 default:
2524 return gl::error(GL_INVALID_ENUM);
2525 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002526 }
2527}
2528
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002529void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2530{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002531 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 +00002532
Geoff Langbfdea662014-07-23 14:16:32 -04002533 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002534
Geoff Langbfdea662014-07-23 14:16:32 -04002535 if (context)
2536 {
2537 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002538 {
Geoff Langbfdea662014-07-23 14:16:32 -04002539 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002540 }
Geoff Langbfdea662014-07-23 14:16:32 -04002541
2542 if (context->getState().getRenderbufferId() == 0)
2543 {
2544 return gl::error(GL_INVALID_OPERATION);
2545 }
2546
2547 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2548
2549 switch (pname)
2550 {
2551 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2552 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2553 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2554 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2555 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2556 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2557 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2558 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2559 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
2560 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2561 if (!context->getExtensions().framebufferMultisample)
2562 {
2563 return gl::error(GL_INVALID_ENUM);
2564 }
2565 *params = renderbuffer->getSamples();
2566 break;
2567 default:
2568 return gl::error(GL_INVALID_ENUM);
2569 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002570 }
2571}
2572
2573void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2574{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002575 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002576
Geoff Langbfdea662014-07-23 14:16:32 -04002577 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002578
Geoff Langbfdea662014-07-23 14:16:32 -04002579 if (context)
2580 {
2581 gl::Shader *shaderObject = context->getShader(shader);
2582
2583 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002584 {
Geoff Langbfdea662014-07-23 14:16:32 -04002585 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002586 }
Geoff Langbfdea662014-07-23 14:16:32 -04002587
2588 switch (pname)
2589 {
2590 case GL_SHADER_TYPE:
2591 *params = shaderObject->getType();
2592 return;
2593 case GL_DELETE_STATUS:
2594 *params = shaderObject->isFlaggedForDeletion();
2595 return;
2596 case GL_COMPILE_STATUS:
2597 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2598 return;
2599 case GL_INFO_LOG_LENGTH:
2600 *params = shaderObject->getInfoLogLength();
2601 return;
2602 case GL_SHADER_SOURCE_LENGTH:
2603 *params = shaderObject->getSourceLength();
2604 return;
2605 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2606 *params = shaderObject->getTranslatedSourceLength();
2607 return;
2608 default:
2609 return gl::error(GL_INVALID_ENUM);
2610 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002611 }
2612}
2613
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002614void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002615{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002616 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 +00002617 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002618
Geoff Langbfdea662014-07-23 14:16:32 -04002619 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002620 {
Geoff Langbfdea662014-07-23 14:16:32 -04002621 return gl::error(GL_INVALID_VALUE);
2622 }
2623
2624 gl::Context *context = gl::getNonLostContext();
2625
2626 if (context)
2627 {
2628 gl::Shader *shaderObject = context->getShader(shader);
2629
2630 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002631 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002632 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002633 }
2634
Geoff Langbfdea662014-07-23 14:16:32 -04002635 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002636 }
2637}
2638
2639void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2640{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002641 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 +00002642 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002643
Geoff Langbfdea662014-07-23 14:16:32 -04002644 switch (shadertype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002645 {
Geoff Langbfdea662014-07-23 14:16:32 -04002646 case GL_VERTEX_SHADER:
2647 case GL_FRAGMENT_SHADER:
2648 break;
2649 default:
2650 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002651 }
Geoff Langbfdea662014-07-23 14:16:32 -04002652
2653 switch (precisiontype)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002654 {
Geoff Langbfdea662014-07-23 14:16:32 -04002655 case GL_LOW_FLOAT:
2656 case GL_MEDIUM_FLOAT:
2657 case GL_HIGH_FLOAT:
2658 // Assume IEEE 754 precision
2659 range[0] = 127;
2660 range[1] = 127;
2661 *precision = 23;
2662 break;
2663 case GL_LOW_INT:
2664 case GL_MEDIUM_INT:
2665 case GL_HIGH_INT:
2666 // Some (most) hardware only supports single-precision floating-point numbers,
2667 // which can accurately represent integers up to +/-16777216
2668 range[0] = 24;
2669 range[1] = 24;
2670 *precision = 0;
2671 break;
2672 default:
2673 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002674 }
2675}
2676
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002677void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002679 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 +00002680 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002681
Geoff Langbfdea662014-07-23 14:16:32 -04002682 if (bufsize < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002683 {
Geoff Langbfdea662014-07-23 14:16:32 -04002684 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002685 }
Geoff Langbfdea662014-07-23 14:16:32 -04002686
2687 gl::Context *context = gl::getNonLostContext();
2688
2689 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002690 {
Geoff Langbfdea662014-07-23 14:16:32 -04002691 gl::Shader *shaderObject = context->getShader(shader);
2692
2693 if (!shaderObject)
2694 {
2695 return gl::error(GL_INVALID_OPERATION);
2696 }
2697
2698 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002699 }
2700}
2701
zmo@google.coma574f782011-10-03 21:45:23 +00002702void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2703{
2704 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2705 shader, bufsize, length, source);
2706
Geoff Langbfdea662014-07-23 14:16:32 -04002707 if (bufsize < 0)
zmo@google.coma574f782011-10-03 21:45:23 +00002708 {
Geoff Langbfdea662014-07-23 14:16:32 -04002709 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00002710 }
Geoff Langbfdea662014-07-23 14:16:32 -04002711
2712 gl::Context *context = gl::getNonLostContext();
2713
2714 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002715 {
Geoff Langbfdea662014-07-23 14:16:32 -04002716 gl::Shader *shaderObject = context->getShader(shader);
2717
2718 if (!shaderObject)
2719 {
2720 return gl::error(GL_INVALID_OPERATION);
2721 }
2722
2723 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002724 }
2725}
2726
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002727const GLubyte* __stdcall glGetString(GLenum name)
2728{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002729 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002730
Geoff Langbfdea662014-07-23 14:16:32 -04002731 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002732
Geoff Langbfdea662014-07-23 14:16:32 -04002733 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002734 {
Geoff Langbfdea662014-07-23 14:16:32 -04002735 case GL_VENDOR:
2736 return (GLubyte*)"Google Inc.";
2737 case GL_RENDERER:
2738 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
2739 case GL_VERSION:
2740 if (context->getClientVersion() == 2)
2741 {
2742 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2743 }
2744 else
2745 {
2746 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2747 }
2748 case GL_SHADING_LANGUAGE_VERSION:
2749 if (context->getClientVersion() == 2)
2750 {
2751 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2752 }
2753 else
2754 {
2755 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2756 }
2757 case GL_EXTENSIONS:
2758 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
2759 default:
2760 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002761 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762}
2763
2764void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2765{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002766 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 +00002767
Geoff Langbfdea662014-07-23 14:16:32 -04002768 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002769
Geoff Langbfdea662014-07-23 14:16:32 -04002770 if (context)
2771 {
2772 gl::Texture *texture = context->getTargetTexture(target);
2773
2774 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002775 {
Geoff Langbfdea662014-07-23 14:16:32 -04002776 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002777 }
Geoff Langbfdea662014-07-23 14:16:32 -04002778
2779 switch (pname)
2780 {
2781 case GL_TEXTURE_MAG_FILTER:
2782 *params = (GLfloat)texture->getSamplerState().magFilter;
2783 break;
2784 case GL_TEXTURE_MIN_FILTER:
2785 *params = (GLfloat)texture->getSamplerState().minFilter;
2786 break;
2787 case GL_TEXTURE_WRAP_S:
2788 *params = (GLfloat)texture->getSamplerState().wrapS;
2789 break;
2790 case GL_TEXTURE_WRAP_T:
2791 *params = (GLfloat)texture->getSamplerState().wrapT;
2792 break;
2793 case GL_TEXTURE_WRAP_R:
2794 if (context->getClientVersion() < 3)
2795 {
2796 return gl::error(GL_INVALID_ENUM);
2797 }
2798 *params = (GLfloat)texture->getSamplerState().wrapR;
2799 break;
2800 case GL_TEXTURE_IMMUTABLE_FORMAT:
2801 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2802 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2803 break;
2804 case GL_TEXTURE_IMMUTABLE_LEVELS:
2805 if (context->getClientVersion() < 3)
2806 {
2807 return gl::error(GL_INVALID_ENUM);
2808 }
2809 *params = (GLfloat)texture->immutableLevelCount();
2810 break;
2811 case GL_TEXTURE_USAGE_ANGLE:
2812 *params = (GLfloat)texture->getUsage();
2813 break;
2814 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2815 if (!context->getExtensions().textureFilterAnisotropic)
2816 {
2817 return gl::error(GL_INVALID_ENUM);
2818 }
2819 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2820 break;
2821 case GL_TEXTURE_SWIZZLE_R:
2822 if (context->getClientVersion() < 3)
2823 {
2824 return gl::error(GL_INVALID_ENUM);
2825 }
2826 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2827 break;
2828 case GL_TEXTURE_SWIZZLE_G:
2829 if (context->getClientVersion() < 3)
2830 {
2831 return gl::error(GL_INVALID_ENUM);
2832 }
2833 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2834 break;
2835 case GL_TEXTURE_SWIZZLE_B:
2836 if (context->getClientVersion() < 3)
2837 {
2838 return gl::error(GL_INVALID_ENUM);
2839 }
2840 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2841 break;
2842 case GL_TEXTURE_SWIZZLE_A:
2843 if (context->getClientVersion() < 3)
2844 {
2845 return gl::error(GL_INVALID_ENUM);
2846 }
2847 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2848 break;
2849 case GL_TEXTURE_BASE_LEVEL:
2850 if (context->getClientVersion() < 3)
2851 {
2852 return gl::error(GL_INVALID_ENUM);
2853 }
2854 *params = (GLfloat)texture->getSamplerState().baseLevel;
2855 break;
2856 case GL_TEXTURE_MAX_LEVEL:
2857 if (context->getClientVersion() < 3)
2858 {
2859 return gl::error(GL_INVALID_ENUM);
2860 }
2861 *params = (GLfloat)texture->getSamplerState().maxLevel;
2862 break;
2863 case GL_TEXTURE_MIN_LOD:
2864 if (context->getClientVersion() < 3)
2865 {
2866 return gl::error(GL_INVALID_ENUM);
2867 }
2868 *params = texture->getSamplerState().minLod;
2869 break;
2870 case GL_TEXTURE_MAX_LOD:
2871 if (context->getClientVersion() < 3)
2872 {
2873 return gl::error(GL_INVALID_ENUM);
2874 }
2875 *params = texture->getSamplerState().maxLod;
2876 break;
2877 default:
2878 return gl::error(GL_INVALID_ENUM);
2879 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002880 }
2881}
2882
2883void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
2884{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002885 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 +00002886
Geoff Langbfdea662014-07-23 14:16:32 -04002887 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002888
Geoff Langbfdea662014-07-23 14:16:32 -04002889 if (context)
2890 {
2891 gl::Texture *texture = context->getTargetTexture(target);
2892
2893 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002894 {
Geoff Langbfdea662014-07-23 14:16:32 -04002895 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002896 }
Geoff Langbfdea662014-07-23 14:16:32 -04002897
2898 switch (pname)
2899 {
2900 case GL_TEXTURE_MAG_FILTER:
2901 *params = texture->getSamplerState().magFilter;
2902 break;
2903 case GL_TEXTURE_MIN_FILTER:
2904 *params = texture->getSamplerState().minFilter;
2905 break;
2906 case GL_TEXTURE_WRAP_S:
2907 *params = texture->getSamplerState().wrapS;
2908 break;
2909 case GL_TEXTURE_WRAP_T:
2910 *params = texture->getSamplerState().wrapT;
2911 break;
2912 case GL_TEXTURE_WRAP_R:
2913 if (context->getClientVersion() < 3)
2914 {
2915 return gl::error(GL_INVALID_ENUM);
2916 }
2917 *params = texture->getSamplerState().wrapR;
2918 break;
2919 case GL_TEXTURE_IMMUTABLE_FORMAT:
2920 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2921 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
2922 break;
2923 case GL_TEXTURE_IMMUTABLE_LEVELS:
2924 if (context->getClientVersion() < 3)
2925 {
2926 return gl::error(GL_INVALID_ENUM);
2927 }
2928 *params = texture->immutableLevelCount();
2929 break;
2930 case GL_TEXTURE_USAGE_ANGLE:
2931 *params = texture->getUsage();
2932 break;
2933 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2934 if (!context->getExtensions().textureFilterAnisotropic)
2935 {
2936 return gl::error(GL_INVALID_ENUM);
2937 }
2938 *params = (GLint)texture->getSamplerState().maxAnisotropy;
2939 break;
2940 case GL_TEXTURE_SWIZZLE_R:
2941 if (context->getClientVersion() < 3)
2942 {
2943 return gl::error(GL_INVALID_ENUM);
2944 }
2945 *params = texture->getSamplerState().swizzleRed;
2946 break;
2947 case GL_TEXTURE_SWIZZLE_G:
2948 if (context->getClientVersion() < 3)
2949 {
2950 return gl::error(GL_INVALID_ENUM);
2951 }
2952 *params = texture->getSamplerState().swizzleGreen;
2953 break;
2954 case GL_TEXTURE_SWIZZLE_B:
2955 if (context->getClientVersion() < 3)
2956 {
2957 return gl::error(GL_INVALID_ENUM);
2958 }
2959 *params = texture->getSamplerState().swizzleBlue;
2960 break;
2961 case GL_TEXTURE_SWIZZLE_A:
2962 if (context->getClientVersion() < 3)
2963 {
2964 return gl::error(GL_INVALID_ENUM);
2965 }
2966 *params = texture->getSamplerState().swizzleAlpha;
2967 break;
2968 case GL_TEXTURE_BASE_LEVEL:
2969 if (context->getClientVersion() < 3)
2970 {
2971 return gl::error(GL_INVALID_ENUM);
2972 }
2973 *params = texture->getSamplerState().baseLevel;
2974 break;
2975 case GL_TEXTURE_MAX_LEVEL:
2976 if (context->getClientVersion() < 3)
2977 {
2978 return gl::error(GL_INVALID_ENUM);
2979 }
2980 *params = texture->getSamplerState().maxLevel;
2981 break;
2982 case GL_TEXTURE_MIN_LOD:
2983 if (context->getClientVersion() < 3)
2984 {
2985 return gl::error(GL_INVALID_ENUM);
2986 }
2987 *params = (GLint)texture->getSamplerState().minLod;
2988 break;
2989 case GL_TEXTURE_MAX_LOD:
2990 if (context->getClientVersion() < 3)
2991 {
2992 return gl::error(GL_INVALID_ENUM);
2993 }
2994 *params = (GLint)texture->getSamplerState().maxLod;
2995 break;
2996 default:
2997 return gl::error(GL_INVALID_ENUM);
2998 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002999 }
3000}
3001
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003002void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3003{
3004 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3005 program, location, bufSize, params);
3006
Geoff Langbfdea662014-07-23 14:16:32 -04003007 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003008 {
Geoff Langbfdea662014-07-23 14:16:32 -04003009 return gl::error(GL_INVALID_VALUE);
3010 }
3011
3012 gl::Context *context = gl::getNonLostContext();
3013
3014 if (context)
3015 {
Jamie Madill0063c512014-08-25 15:47:53 -04003016 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003017 {
Jamie Madill0063c512014-08-25 15:47:53 -04003018 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003019 }
3020
Jamie Madill0063c512014-08-25 15:47:53 -04003021 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3022 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003023
Jamie Madill99a1e982014-08-25 15:47:54 -04003024 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003025 }
3026}
3027
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003028void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3029{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003030 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003031
Geoff Langbfdea662014-07-23 14:16:32 -04003032 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003033
Geoff Langbfdea662014-07-23 14:16:32 -04003034 if (context)
3035 {
Jamie Madill0063c512014-08-25 15:47:53 -04003036 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003037 {
Jamie Madill0063c512014-08-25 15:47:53 -04003038 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003039 }
Geoff Langbfdea662014-07-23 14:16:32 -04003040
Jamie Madill0063c512014-08-25 15:47:53 -04003041 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3042 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003043
Jamie Madill99a1e982014-08-25 15:47:54 -04003044 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003045 }
3046}
3047
3048void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3049{
Geoff Langbfdea662014-07-23 14:16:32 -04003050 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003051 program, location, bufSize, params);
3052
Geoff Langbfdea662014-07-23 14:16:32 -04003053 if (bufSize < 0)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003054 {
Geoff Langbfdea662014-07-23 14:16:32 -04003055 return gl::error(GL_INVALID_VALUE);
3056 }
3057
3058 gl::Context *context = gl::getNonLostContext();
3059
3060 if (context)
3061 {
Jamie Madill0063c512014-08-25 15:47:53 -04003062 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003063 {
Jamie Madill0063c512014-08-25 15:47:53 -04003064 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003065 }
3066
Jamie Madill0063c512014-08-25 15:47:53 -04003067 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3068 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003069
Jamie Madill99a1e982014-08-25 15:47:54 -04003070 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003071 }
3072}
3073
3074void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3075{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003076 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003077
Geoff Langbfdea662014-07-23 14:16:32 -04003078 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003079
Geoff Langbfdea662014-07-23 14:16:32 -04003080 if (context)
3081 {
Jamie Madill0063c512014-08-25 15:47:53 -04003082 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003083 {
Jamie Madill0063c512014-08-25 15:47:53 -04003084 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003085 }
Geoff Langbfdea662014-07-23 14:16:32 -04003086
Jamie Madill0063c512014-08-25 15:47:53 -04003087 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3088 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003089
Jamie Madill99a1e982014-08-25 15:47:54 -04003090 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003091 }
3092}
3093
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003094int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003095{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003096 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003097
Geoff Langbfdea662014-07-23 14:16:32 -04003098 gl::Context *context = gl::getNonLostContext();
3099
3100 if (strstr(name, "gl_") == name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003101 {
Geoff Langbfdea662014-07-23 14:16:32 -04003102 return -1;
3103 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003104
Geoff Langbfdea662014-07-23 14:16:32 -04003105 if (context)
3106 {
3107 gl::Program *programObject = context->getProgram(program);
3108
3109 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003110 {
Geoff Langbfdea662014-07-23 14:16:32 -04003111 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003112 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003113 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003114 }
Geoff Langbfdea662014-07-23 14:16:32 -04003115 else
3116 {
3117 return gl::error(GL_INVALID_VALUE, -1);
3118 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003119 }
Geoff Langbfdea662014-07-23 14:16:32 -04003120
3121 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3122 if (!programObject->isLinked() || !programBinary)
3123 {
3124 return gl::error(GL_INVALID_OPERATION, -1);
3125 }
3126
3127 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003128 }
3129
3130 return -1;
3131}
3132
3133void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3134{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003135 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003136
Geoff Langbfdea662014-07-23 14:16:32 -04003137 gl::Context *context = gl::getNonLostContext();
3138
3139 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003140 {
Geoff Langbfdea662014-07-23 14:16:32 -04003141 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003142 {
Geoff Langbfdea662014-07-23 14:16:32 -04003143 return gl::error(GL_INVALID_VALUE);
3144 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003145
Geoff Langbfdea662014-07-23 14:16:32 -04003146 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
3147 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3148 {
3149 return;
3150 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003151
Geoff Langbfdea662014-07-23 14:16:32 -04003152 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3153 {
3154 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3155 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003156 {
Geoff Langbfdea662014-07-23 14:16:32 -04003157 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003158 }
3159 }
Geoff Langbfdea662014-07-23 14:16:32 -04003160 else
3161 {
3162 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3163 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003164 }
3165}
3166
3167void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3168{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003169 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003170
Geoff Langbfdea662014-07-23 14:16:32 -04003171 gl::Context *context = gl::getNonLostContext();
3172
3173 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003174 {
Geoff Langbfdea662014-07-23 14:16:32 -04003175 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003176 {
Geoff Langbfdea662014-07-23 14:16:32 -04003177 return gl::error(GL_INVALID_VALUE);
3178 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003179
Geoff Langbfdea662014-07-23 14:16:32 -04003180 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003181
Geoff Langbfdea662014-07-23 14:16:32 -04003182 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
3183 {
3184 return;
3185 }
Jamie Madillaff71502013-07-02 11:57:05 -04003186
Geoff Langbfdea662014-07-23 14:16:32 -04003187 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3188 {
3189 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3190 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003191 {
Geoff Langbfdea662014-07-23 14:16:32 -04003192 float currentValue = currentValueData.FloatValues[i];
3193 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003194 }
3195 }
Geoff Langbfdea662014-07-23 14:16:32 -04003196 else
3197 {
3198 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3199 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003200 }
3201}
3202
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003203void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003204{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003205 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003206
Geoff Langbfdea662014-07-23 14:16:32 -04003207 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208
Geoff Langbfdea662014-07-23 14:16:32 -04003209 if (context)
3210 {
3211 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003212 {
Geoff Langbfdea662014-07-23 14:16:32 -04003213 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003214 }
Geoff Langbfdea662014-07-23 14:16:32 -04003215
3216 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3217 {
3218 return gl::error(GL_INVALID_ENUM);
3219 }
3220
3221 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003222 }
3223}
3224
3225void __stdcall glHint(GLenum target, GLenum mode)
3226{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003227 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003228
Geoff Langbfdea662014-07-23 14:16:32 -04003229 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003230 {
Geoff Langbfdea662014-07-23 14:16:32 -04003231 case GL_FASTEST:
3232 case GL_NICEST:
3233 case GL_DONT_CARE:
3234 break;
3235 default:
3236 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003237 }
Geoff Langbfdea662014-07-23 14:16:32 -04003238
3239 gl::Context *context = gl::getNonLostContext();
3240 switch (target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003241 {
Geoff Langbfdea662014-07-23 14:16:32 -04003242 case GL_GENERATE_MIPMAP_HINT:
3243 if (context) context->getState().setGenerateMipmapHint(mode);
3244 break;
3245 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3246 if (context) context->getState().setFragmentShaderDerivativeHint(mode);
3247 break;
3248 default:
3249 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003250 }
3251}
3252
3253GLboolean __stdcall glIsBuffer(GLuint buffer)
3254{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003255 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003256
Geoff Langbfdea662014-07-23 14:16:32 -04003257 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003258
Geoff Langbfdea662014-07-23 14:16:32 -04003259 if (context && buffer)
3260 {
3261 gl::Buffer *bufferObject = context->getBuffer(buffer);
3262
3263 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003264 {
Geoff Langbfdea662014-07-23 14:16:32 -04003265 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003266 }
3267 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268
3269 return GL_FALSE;
3270}
3271
3272GLboolean __stdcall glIsEnabled(GLenum cap)
3273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003274 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003275
Geoff Langbfdea662014-07-23 14:16:32 -04003276 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003277
Geoff Langbfdea662014-07-23 14:16:32 -04003278 if (context)
3279 {
3280 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003281 {
Geoff Langbfdea662014-07-23 14:16:32 -04003282 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003283 }
Geoff Langbfdea662014-07-23 14:16:32 -04003284
3285 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003286 }
3287
3288 return false;
3289}
3290
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003291GLboolean __stdcall glIsFenceNV(GLuint fence)
3292{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003293 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003294
Geoff Langbfdea662014-07-23 14:16:32 -04003295 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003296
Geoff Langbfdea662014-07-23 14:16:32 -04003297 if (context)
3298 {
3299 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3300
3301 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003302 {
Geoff Langbfdea662014-07-23 14:16:32 -04003303 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003304 }
Geoff Langbfdea662014-07-23 14:16:32 -04003305
3306 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003307 }
3308
3309 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003310}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003311
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003312GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3313{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003314 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003315
Geoff Langbfdea662014-07-23 14:16:32 -04003316 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003317
Geoff Langbfdea662014-07-23 14:16:32 -04003318 if (context && framebuffer)
3319 {
3320 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3321
3322 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003323 {
Geoff Langbfdea662014-07-23 14:16:32 -04003324 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325 }
3326 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003327
3328 return GL_FALSE;
3329}
3330
3331GLboolean __stdcall glIsProgram(GLuint program)
3332{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003333 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334
Geoff Langbfdea662014-07-23 14:16:32 -04003335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003336
Geoff Langbfdea662014-07-23 14:16:32 -04003337 if (context && program)
3338 {
3339 gl::Program *programObject = context->getProgram(program);
3340
3341 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003342 {
Geoff Langbfdea662014-07-23 14:16:32 -04003343 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003344 }
3345 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003346
3347 return GL_FALSE;
3348}
3349
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003350GLboolean __stdcall glIsQueryEXT(GLuint id)
3351{
3352 EVENT("(GLuint id = %d)", id);
3353
Geoff Langbfdea662014-07-23 14:16:32 -04003354 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003355
Geoff Langbfdea662014-07-23 14:16:32 -04003356 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003357 {
Geoff Langbfdea662014-07-23 14:16:32 -04003358 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003359 }
3360
3361 return GL_FALSE;
3362}
3363
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3365{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003366 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003367
Geoff Langbfdea662014-07-23 14:16:32 -04003368 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003369
Geoff Langbfdea662014-07-23 14:16:32 -04003370 if (context && renderbuffer)
3371 {
3372 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3373
3374 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003375 {
Geoff Langbfdea662014-07-23 14:16:32 -04003376 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003377 }
3378 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379
3380 return GL_FALSE;
3381}
3382
3383GLboolean __stdcall glIsShader(GLuint shader)
3384{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003385 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003386
Geoff Langbfdea662014-07-23 14:16:32 -04003387 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003388
Geoff Langbfdea662014-07-23 14:16:32 -04003389 if (context && shader)
3390 {
3391 gl::Shader *shaderObject = context->getShader(shader);
3392
3393 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003394 {
Geoff Langbfdea662014-07-23 14:16:32 -04003395 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003396 }
3397 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003398
3399 return GL_FALSE;
3400}
3401
3402GLboolean __stdcall glIsTexture(GLuint texture)
3403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003404 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003405
Geoff Langbfdea662014-07-23 14:16:32 -04003406 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003407
Geoff Langbfdea662014-07-23 14:16:32 -04003408 if (context && texture)
3409 {
3410 gl::Texture *textureObject = context->getTexture(texture);
3411
3412 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003413 {
Geoff Langbfdea662014-07-23 14:16:32 -04003414 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415 }
3416 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003417
3418 return GL_FALSE;
3419}
3420
3421void __stdcall glLineWidth(GLfloat width)
3422{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003423 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003424
Geoff Langbfdea662014-07-23 14:16:32 -04003425 if (width <= 0.0f)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003426 {
Geoff Langbfdea662014-07-23 14:16:32 -04003427 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428 }
Geoff Langbfdea662014-07-23 14:16:32 -04003429
3430 gl::Context *context = gl::getNonLostContext();
3431
3432 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003433 {
Geoff Langbfdea662014-07-23 14:16:32 -04003434 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003435 }
3436}
3437
3438void __stdcall glLinkProgram(GLuint program)
3439{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003440 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003441
Geoff Langbfdea662014-07-23 14:16:32 -04003442 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003443
Geoff Langbfdea662014-07-23 14:16:32 -04003444 if (context)
3445 {
3446 gl::Program *programObject = context->getProgram(program);
3447
3448 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449 {
Geoff Langbfdea662014-07-23 14:16:32 -04003450 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003451 {
Geoff Langbfdea662014-07-23 14:16:32 -04003452 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003453 }
Geoff Langbfdea662014-07-23 14:16:32 -04003454 else
3455 {
3456 return gl::error(GL_INVALID_VALUE);
3457 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003458 }
Geoff Langbfdea662014-07-23 14:16:32 -04003459
3460 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003461 }
3462}
3463
3464void __stdcall glPixelStorei(GLenum pname, GLint param)
3465{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003466 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003467
Geoff Langbfdea662014-07-23 14:16:32 -04003468 gl::Context *context = gl::getNonLostContext();
3469
3470 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003471 {
Geoff Langbfdea662014-07-23 14:16:32 -04003472 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003473 {
Geoff Langbfdea662014-07-23 14:16:32 -04003474 case GL_UNPACK_ALIGNMENT:
3475 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003476 {
Geoff Langbfdea662014-07-23 14:16:32 -04003477 return gl::error(GL_INVALID_VALUE);
3478 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003479
Geoff Langbfdea662014-07-23 14:16:32 -04003480 context->getState().setUnpackAlignment(param);
3481 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003482
Geoff Langbfdea662014-07-23 14:16:32 -04003483 case GL_PACK_ALIGNMENT:
3484 if (param != 1 && param != 2 && param != 4 && param != 8)
3485 {
3486 return gl::error(GL_INVALID_VALUE);
3487 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003488
Geoff Langbfdea662014-07-23 14:16:32 -04003489 context->getState().setPackAlignment(param);
3490 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003491
Geoff Langbfdea662014-07-23 14:16:32 -04003492 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3493 context->getState().setPackReverseRowOrder(param != 0);
3494 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003495
Geoff Langbfdea662014-07-23 14:16:32 -04003496 case GL_UNPACK_IMAGE_HEIGHT:
3497 case GL_UNPACK_SKIP_IMAGES:
3498 case GL_UNPACK_ROW_LENGTH:
3499 case GL_UNPACK_SKIP_ROWS:
3500 case GL_UNPACK_SKIP_PIXELS:
3501 case GL_PACK_ROW_LENGTH:
3502 case GL_PACK_SKIP_ROWS:
3503 case GL_PACK_SKIP_PIXELS:
3504 if (context->getClientVersion() < 3)
3505 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003506 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003507 }
Geoff Langbfdea662014-07-23 14:16:32 -04003508 UNIMPLEMENTED();
3509 break;
3510
3511 default:
3512 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003513 }
3514 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003515}
3516
3517void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3518{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003519 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003520
Geoff Langbfdea662014-07-23 14:16:32 -04003521 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00003522
Geoff Langbfdea662014-07-23 14:16:32 -04003523 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003524 {
Geoff Langbfdea662014-07-23 14:16:32 -04003525 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526 }
3527}
3528
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003529void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3530 GLenum format, GLenum type, GLsizei bufSize,
3531 GLvoid *data)
3532{
3533 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3534 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3535 x, y, width, height, format, type, bufSize, data);
3536
Geoff Langbfdea662014-07-23 14:16:32 -04003537 if (width < 0 || height < 0 || bufSize < 0)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003538 {
Geoff Langbfdea662014-07-23 14:16:32 -04003539 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003540 }
Geoff Langbfdea662014-07-23 14:16:32 -04003541
3542 gl::Context *context = gl::getNonLostContext();
3543
3544 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003545 {
Geoff Langbfdea662014-07-23 14:16:32 -04003546 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3547 format, type, &bufSize, data))
3548 {
3549 return;
3550 }
3551
3552 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003553 }
3554}
3555
3556void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3557 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003558{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003559 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003560 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003561 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003562
Geoff Langbfdea662014-07-23 14:16:32 -04003563 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003564 {
Geoff Langbfdea662014-07-23 14:16:32 -04003565 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003566 }
Geoff Langbfdea662014-07-23 14:16:32 -04003567
3568 gl::Context *context = gl::getNonLostContext();
3569
3570 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571 {
Geoff Langbfdea662014-07-23 14:16:32 -04003572 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3573 format, type, NULL, pixels))
3574 {
3575 return;
3576 }
3577
3578 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003579 }
3580}
3581
3582void __stdcall glReleaseShaderCompiler(void)
3583{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003584 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003585
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003586 gl::Context *context = gl::getNonLostContext();
3587
3588 if (context)
3589 {
3590 context->releaseShaderCompiler();
3591 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003592}
3593
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003594void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003596 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 +00003597 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598
Geoff Langbfdea662014-07-23 14:16:32 -04003599 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003600
Geoff Langbfdea662014-07-23 14:16:32 -04003601 if (context)
3602 {
3603 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3604 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003605 {
Geoff Langbfdea662014-07-23 14:16:32 -04003606 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003607 }
Geoff Langbfdea662014-07-23 14:16:32 -04003608
3609 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003610 }
3611}
3612
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003613void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3614{
3615 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3616}
3617
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3619{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003620 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003621
Geoff Langbfdea662014-07-23 14:16:32 -04003622 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003623
Geoff Langbfdea662014-07-23 14:16:32 -04003624 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003625 {
Geoff Langbfdea662014-07-23 14:16:32 -04003626 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003627 }
3628}
3629
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003630void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003632 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003633
Geoff Langbfdea662014-07-23 14:16:32 -04003634 if (condition != GL_ALL_COMPLETED_NV)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003635 {
Geoff Langbfdea662014-07-23 14:16:32 -04003636 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003637 }
Geoff Langbfdea662014-07-23 14:16:32 -04003638
3639 gl::Context *context = gl::getNonLostContext();
3640
3641 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003642 {
Geoff Langbfdea662014-07-23 14:16:32 -04003643 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3644
3645 if (fenceObject == NULL)
3646 {
3647 return gl::error(GL_INVALID_OPERATION);
3648 }
3649
3650 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003651 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003652}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003653
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003654void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003656 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 +00003657
Geoff Langbfdea662014-07-23 14:16:32 -04003658 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003659 {
Geoff Langbfdea662014-07-23 14:16:32 -04003660 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661 }
Geoff Langbfdea662014-07-23 14:16:32 -04003662
3663 gl::Context* context = gl::getNonLostContext();
3664
3665 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003666 {
Geoff Langbfdea662014-07-23 14:16:32 -04003667 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003668 }
3669}
3670
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003671void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003672{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003673 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003674 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003675 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003676
Geoff Lang900013c2014-07-07 11:32:19 -04003677 gl::Context* context = gl::getNonLostContext();
3678 if (context)
3679 {
3680 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3681 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3682 {
3683 return gl::error(GL_INVALID_ENUM);
3684 }
3685
3686 // No binary shader formats are supported.
3687 UNIMPLEMENTED();
3688 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003689}
3690
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003691void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003692{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003693 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 +00003694 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003695
Geoff Langbfdea662014-07-23 14:16:32 -04003696 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697 {
Geoff Langbfdea662014-07-23 14:16:32 -04003698 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003699 }
Geoff Langbfdea662014-07-23 14:16:32 -04003700
3701 gl::Context *context = gl::getNonLostContext();
3702
3703 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003704 {
Geoff Langbfdea662014-07-23 14:16:32 -04003705 gl::Shader *shaderObject = context->getShader(shader);
3706
3707 if (!shaderObject)
3708 {
3709 if (context->getProgram(shader))
3710 {
3711 return gl::error(GL_INVALID_OPERATION);
3712 }
3713 else
3714 {
3715 return gl::error(GL_INVALID_VALUE);
3716 }
3717 }
3718
3719 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003720 }
3721}
3722
3723void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3724{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003725 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003726}
3727
3728void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003730 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 +00003731
Geoff Langbfdea662014-07-23 14:16:32 -04003732 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733 {
Geoff Langbfdea662014-07-23 14:16:32 -04003734 case GL_FRONT:
3735 case GL_BACK:
3736 case GL_FRONT_AND_BACK:
3737 break;
3738 default:
3739 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003740 }
Geoff Langbfdea662014-07-23 14:16:32 -04003741
3742 switch (func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743 {
Geoff Langbfdea662014-07-23 14:16:32 -04003744 case GL_NEVER:
3745 case GL_ALWAYS:
3746 case GL_LESS:
3747 case GL_LEQUAL:
3748 case GL_EQUAL:
3749 case GL_GEQUAL:
3750 case GL_GREATER:
3751 case GL_NOTEQUAL:
3752 break;
3753 default:
3754 return gl::error(GL_INVALID_ENUM);
3755 }
3756
3757 gl::Context *context = gl::getNonLostContext();
3758
3759 if (context)
3760 {
3761 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3762 {
3763 context->getState().setStencilParams(func, ref, mask);
3764 }
3765
3766 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3767 {
3768 context->getState().setStencilBackParams(func, ref, mask);
3769 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003770 }
3771}
3772
3773void __stdcall glStencilMask(GLuint mask)
3774{
3775 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3776}
3777
3778void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003780 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003781
Geoff Langbfdea662014-07-23 14:16:32 -04003782 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003783 {
Geoff Langbfdea662014-07-23 14:16:32 -04003784 case GL_FRONT:
3785 case GL_BACK:
3786 case GL_FRONT_AND_BACK:
3787 break;
3788 default:
3789 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003790 }
Geoff Langbfdea662014-07-23 14:16:32 -04003791
3792 gl::Context *context = gl::getNonLostContext();
3793
3794 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003795 {
Geoff Langbfdea662014-07-23 14:16:32 -04003796 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3797 {
3798 context->getState().setStencilWritemask(mask);
3799 }
3800
3801 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3802 {
3803 context->getState().setStencilBackWritemask(mask);
3804 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003805 }
3806}
3807
3808void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3809{
3810 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3811}
3812
3813void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3814{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003815 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 +00003816 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003817
Geoff Langbfdea662014-07-23 14:16:32 -04003818 switch (face)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003819 {
Geoff Langbfdea662014-07-23 14:16:32 -04003820 case GL_FRONT:
3821 case GL_BACK:
3822 case GL_FRONT_AND_BACK:
3823 break;
3824 default:
3825 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003826 }
Geoff Langbfdea662014-07-23 14:16:32 -04003827
3828 switch (fail)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003829 {
Geoff Langbfdea662014-07-23 14:16:32 -04003830 case GL_ZERO:
3831 case GL_KEEP:
3832 case GL_REPLACE:
3833 case GL_INCR:
3834 case GL_DECR:
3835 case GL_INVERT:
3836 case GL_INCR_WRAP:
3837 case GL_DECR_WRAP:
3838 break;
3839 default:
3840 return gl::error(GL_INVALID_ENUM);
3841 }
3842
3843 switch (zfail)
3844 {
3845 case GL_ZERO:
3846 case GL_KEEP:
3847 case GL_REPLACE:
3848 case GL_INCR:
3849 case GL_DECR:
3850 case GL_INVERT:
3851 case GL_INCR_WRAP:
3852 case GL_DECR_WRAP:
3853 break;
3854 default:
3855 return gl::error(GL_INVALID_ENUM);
3856 }
3857
3858 switch (zpass)
3859 {
3860 case GL_ZERO:
3861 case GL_KEEP:
3862 case GL_REPLACE:
3863 case GL_INCR:
3864 case GL_DECR:
3865 case GL_INVERT:
3866 case GL_INCR_WRAP:
3867 case GL_DECR_WRAP:
3868 break;
3869 default:
3870 return gl::error(GL_INVALID_ENUM);
3871 }
3872
3873 gl::Context *context = gl::getNonLostContext();
3874
3875 if (context)
3876 {
3877 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3878 {
3879 context->getState().setStencilOperations(fail, zfail, zpass);
3880 }
3881
3882 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3883 {
3884 context->getState().setStencilBackOperations(fail, zfail, zpass);
3885 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003886 }
3887}
3888
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003889GLboolean __stdcall glTestFenceNV(GLuint fence)
3890{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003891 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003892
Geoff Langbfdea662014-07-23 14:16:32 -04003893 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003894
Geoff Langbfdea662014-07-23 14:16:32 -04003895 if (context)
3896 {
3897 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3898
3899 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003900 {
Geoff Langbfdea662014-07-23 14:16:32 -04003901 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003902 }
Geoff Langbfdea662014-07-23 14:16:32 -04003903
3904 if (fenceObject->isFence() != GL_TRUE)
3905 {
3906 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
3907 }
3908
3909 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003910 }
Geoff Langbfdea662014-07-23 14:16:32 -04003911
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003912 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003913}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003914
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003915void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
3916 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003918 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05003919 "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 +00003920 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003921
Geoff Langbfdea662014-07-23 14:16:32 -04003922 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003923
Geoff Langbfdea662014-07-23 14:16:32 -04003924 if (context)
3925 {
3926 if (context->getClientVersion() < 3 &&
3927 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
3928 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003929 {
Geoff Langbfdea662014-07-23 14:16:32 -04003930 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003931 }
Geoff Langbfdea662014-07-23 14:16:32 -04003932
3933 if (context->getClientVersion() >= 3 &&
3934 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
3935 0, 0, 0, width, height, 1, border, format, type, pixels))
3936 {
3937 return;
3938 }
3939
3940 switch (target)
3941 {
3942 case GL_TEXTURE_2D:
3943 {
3944 gl::Texture2D *texture = context->getTexture2D();
3945 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3946 }
3947 break;
3948 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3949 {
3950 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3951 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3952 }
3953 break;
3954 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3955 {
3956 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3957 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3958 }
3959 break;
3960 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3961 {
3962 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3963 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3964 }
3965 break;
3966 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3967 {
3968 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3969 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3970 }
3971 break;
3972 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3973 {
3974 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3975 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3976 }
3977 break;
3978 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
3979 {
3980 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3981 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
3982 }
3983 break;
3984 default: UNREACHABLE();
3985 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003986 }
3987}
3988
3989void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
3990{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003991 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
3992
Geoff Langbfdea662014-07-23 14:16:32 -04003993 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003994
Geoff Langbfdea662014-07-23 14:16:32 -04003995 if (context)
3996 {
3997 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00003998 {
Geoff Langbfdea662014-07-23 14:16:32 -04003999 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004000 }
Geoff Langbfdea662014-07-23 14:16:32 -04004001
4002 gl::Texture *texture = context->getTargetTexture(target);
4003
4004 if (!texture)
4005 {
4006 return gl::error(GL_INVALID_ENUM);
4007 }
4008
4009 switch (pname)
4010 {
4011 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4012 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4013 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4014 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4015 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4016 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4017 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4018 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4019 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4020 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4021 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4022 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4023 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4024 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4025 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4026 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4027 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4028 default: UNREACHABLE(); break;
4029 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004030 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004031}
4032
4033void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4034{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004035 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004036}
4037
4038void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004040 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004041
Geoff Langbfdea662014-07-23 14:16:32 -04004042 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004043
Geoff Langbfdea662014-07-23 14:16:32 -04004044 if (context)
4045 {
4046 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004047 {
Geoff Langbfdea662014-07-23 14:16:32 -04004048 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004049 }
Geoff Langbfdea662014-07-23 14:16:32 -04004050
4051 gl::Texture *texture = context->getTargetTexture(target);
4052
4053 if (!texture)
4054 {
4055 return gl::error(GL_INVALID_ENUM);
4056 }
4057
4058 switch (pname)
4059 {
4060 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4061 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4062 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4063 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4064 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4065 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4066 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4067 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4068 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4069 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4070 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4071 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4072 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4073 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4074 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4075 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4076 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4077 default: UNREACHABLE(); break;
4078 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004079 }
4080}
4081
4082void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4083{
4084 glTexParameteri(target, pname, *params);
4085}
4086
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004087void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4088{
4089 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4090 target, levels, internalformat, width, height);
4091
Geoff Langbfdea662014-07-23 14:16:32 -04004092 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004093
Geoff Langbfdea662014-07-23 14:16:32 -04004094 if (context)
4095 {
4096 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004097 {
Geoff Langbfdea662014-07-23 14:16:32 -04004098 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004099 }
Geoff Langbfdea662014-07-23 14:16:32 -04004100
4101 if (context->getClientVersion() < 3 &&
4102 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4103 {
4104 return;
4105 }
4106
4107 if (context->getClientVersion() >= 3 &&
4108 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4109 {
4110 return;
4111 }
4112
4113 switch (target)
4114 {
4115 case GL_TEXTURE_2D:
4116 {
4117 gl::Texture2D *texture2d = context->getTexture2D();
4118 texture2d->storage(levels, internalformat, width, height);
4119 }
4120 break;
4121
4122 case GL_TEXTURE_CUBE_MAP:
4123 {
4124 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4125 textureCube->storage(levels, internalformat, width);
4126 }
4127 break;
4128
4129 default:
4130 return gl::error(GL_INVALID_ENUM);
4131 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004132 }
4133}
4134
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004135void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4136 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004137{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004138 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004139 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004140 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004141 target, level, xoffset, yoffset, width, height, format, type, pixels);
4142
Geoff Langbfdea662014-07-23 14:16:32 -04004143 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004144
Geoff Langbfdea662014-07-23 14:16:32 -04004145 if (context)
4146 {
4147 if (context->getClientVersion() < 3 &&
4148 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4149 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004150 {
Geoff Langbfdea662014-07-23 14:16:32 -04004151 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004152 }
Geoff Langbfdea662014-07-23 14:16:32 -04004153
4154 if (context->getClientVersion() >= 3 &&
4155 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4156 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4157 {
4158 return;
4159 }
4160
4161 // Zero sized uploads are valid but no-ops
4162 if (width == 0 || height == 0)
4163 {
4164 return;
4165 }
4166
4167 switch (target)
4168 {
4169 case GL_TEXTURE_2D:
4170 {
4171 gl::Texture2D *texture = context->getTexture2D();
4172 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4173 }
4174 break;
4175
4176 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4177 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4178 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4179 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4180 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4181 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4182 {
4183 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4184 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4185 }
4186 break;
4187
4188 default:
4189 UNREACHABLE();
4190 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004191 }
4192}
4193
4194void __stdcall glUniform1f(GLint location, GLfloat x)
4195{
4196 glUniform1fv(location, 1, &x);
4197}
4198
4199void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4200{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004201 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004202
Geoff Langbfdea662014-07-23 14:16:32 -04004203 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004204
Geoff Langbfdea662014-07-23 14:16:32 -04004205 if (context)
4206 {
4207 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004208 {
Geoff Langbfdea662014-07-23 14:16:32 -04004209 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004210 }
Geoff Langbfdea662014-07-23 14:16:32 -04004211
4212 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4213 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004214 }
4215}
4216
4217void __stdcall glUniform1i(GLint location, GLint x)
4218{
4219 glUniform1iv(location, 1, &x);
4220}
4221
4222void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4223{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004224 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004225
Geoff Langbfdea662014-07-23 14:16:32 -04004226 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004227
Geoff Langbfdea662014-07-23 14:16:32 -04004228 if (context)
4229 {
4230 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004231 {
Geoff Langbfdea662014-07-23 14:16:32 -04004232 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004233 }
Geoff Langbfdea662014-07-23 14:16:32 -04004234
4235 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4236 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004237 }
4238}
4239
4240void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4241{
4242 GLfloat xy[2] = {x, y};
4243
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004244 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004245}
4246
4247void __stdcall glUniform2fv(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_VEC2, 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->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004262 }
4263}
4264
4265void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4266{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004267 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004268
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004269 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004270}
4271
4272void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004274 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004275
Geoff Langbfdea662014-07-23 14:16:32 -04004276 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004277
Geoff Langbfdea662014-07-23 14:16:32 -04004278 if (context)
4279 {
4280 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004281 {
Geoff Langbfdea662014-07-23 14:16:32 -04004282 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004283 }
Geoff Langbfdea662014-07-23 14:16:32 -04004284
4285 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4286 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004287 }
4288}
4289
4290void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4291{
4292 GLfloat xyz[3] = {x, y, z};
4293
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004294 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004295}
4296
4297void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004299 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004300
Geoff Langbfdea662014-07-23 14:16:32 -04004301 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004302
Geoff Langbfdea662014-07-23 14:16:32 -04004303 if (context)
4304 {
4305 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004306 {
Geoff Langbfdea662014-07-23 14:16:32 -04004307 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004308 }
Geoff Langbfdea662014-07-23 14:16:32 -04004309
4310 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4311 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004312 }
4313}
4314
4315void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4316{
4317 GLint xyz[3] = {x, y, z};
4318
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004319 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004320}
4321
4322void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4323{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004324 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004325
Geoff Langbfdea662014-07-23 14:16:32 -04004326 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004327
Geoff Langbfdea662014-07-23 14:16:32 -04004328 if (context)
4329 {
4330 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004331 {
Geoff Langbfdea662014-07-23 14:16:32 -04004332 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004333 }
Geoff Langbfdea662014-07-23 14:16:32 -04004334
4335 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4336 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004337 }
4338}
4339
4340void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4341{
4342 GLfloat xyzw[4] = {x, y, z, w};
4343
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004344 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345}
4346
4347void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4348{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004349 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004350
Geoff Langbfdea662014-07-23 14:16:32 -04004351 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004352
Geoff Langbfdea662014-07-23 14:16:32 -04004353 if (context)
4354 {
4355 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004356 {
Geoff Langbfdea662014-07-23 14:16:32 -04004357 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004358 }
Geoff Langbfdea662014-07-23 14:16:32 -04004359
4360 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4361 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004362 }
4363}
4364
4365void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4366{
4367 GLint xyzw[4] = {x, y, z, w};
4368
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004369 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004370}
4371
4372void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4373{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004374 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004375
Geoff Langbfdea662014-07-23 14:16:32 -04004376 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004377
Geoff Langbfdea662014-07-23 14:16:32 -04004378 if (context)
4379 {
4380 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004381 {
Geoff Langbfdea662014-07-23 14:16:32 -04004382 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004383 }
Geoff Langbfdea662014-07-23 14:16:32 -04004384
4385 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4386 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004387 }
4388}
4389
4390void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4391{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004392 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004393 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004394
Geoff Langbfdea662014-07-23 14:16:32 -04004395 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004396
Geoff Langbfdea662014-07-23 14:16:32 -04004397 if (context)
4398 {
4399 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004400 {
Geoff Langbfdea662014-07-23 14:16:32 -04004401 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004402 }
Geoff Langbfdea662014-07-23 14:16:32 -04004403
4404 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4405 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004406 }
4407}
4408
4409void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4410{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004411 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004412 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004413
Geoff Langbfdea662014-07-23 14:16:32 -04004414 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004415
Geoff Langbfdea662014-07-23 14:16:32 -04004416 if (context)
4417 {
4418 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004419 {
Geoff Langbfdea662014-07-23 14:16:32 -04004420 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004421 }
Geoff Langbfdea662014-07-23 14:16:32 -04004422
4423 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4424 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004425 }
4426}
4427
4428void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4429{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004430 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004431 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004432
Geoff Langbfdea662014-07-23 14:16:32 -04004433 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004434
Geoff Langbfdea662014-07-23 14:16:32 -04004435 if (context)
4436 {
4437 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438 {
Geoff Langbfdea662014-07-23 14:16:32 -04004439 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004440 }
Geoff Langbfdea662014-07-23 14:16:32 -04004441
4442 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4443 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004444 }
4445}
4446
4447void __stdcall glUseProgram(GLuint program)
4448{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004449 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450
Geoff Langbfdea662014-07-23 14:16:32 -04004451 gl::Context *context = gl::getNonLostContext();
4452
4453 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454 {
Geoff Langbfdea662014-07-23 14:16:32 -04004455 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004456
Geoff Langbfdea662014-07-23 14:16:32 -04004457 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004458 {
Geoff Langbfdea662014-07-23 14:16:32 -04004459 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004461 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004462 }
Geoff Langbfdea662014-07-23 14:16:32 -04004463 else
4464 {
4465 return gl::error(GL_INVALID_VALUE);
4466 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004467 }
Geoff Langbfdea662014-07-23 14:16:32 -04004468
4469 if (program != 0 && !programObject->isLinked())
4470 {
4471 return gl::error(GL_INVALID_OPERATION);
4472 }
4473
4474 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004475 }
4476}
4477
4478void __stdcall glValidateProgram(GLuint program)
4479{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004480 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004481
Geoff Langbfdea662014-07-23 14:16:32 -04004482 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004483
Geoff Langbfdea662014-07-23 14:16:32 -04004484 if (context)
4485 {
4486 gl::Program *programObject = context->getProgram(program);
4487
4488 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004489 {
Geoff Langbfdea662014-07-23 14:16:32 -04004490 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004491 {
Geoff Langbfdea662014-07-23 14:16:32 -04004492 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004493 }
Geoff Langbfdea662014-07-23 14:16:32 -04004494 else
4495 {
4496 return gl::error(GL_INVALID_VALUE);
4497 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004498 }
Geoff Langbfdea662014-07-23 14:16:32 -04004499
4500 programObject->validate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004501 }
4502}
4503
4504void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004506 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004507
Geoff Langbfdea662014-07-23 14:16:32 -04004508 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004509 {
Geoff Langbfdea662014-07-23 14:16:32 -04004510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004511 }
Geoff Langbfdea662014-07-23 14:16:32 -04004512
4513 gl::Context *context = gl::getNonLostContext();
4514
4515 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004516 {
Geoff Langbfdea662014-07-23 14:16:32 -04004517 GLfloat vals[4] = { x, 0, 0, 1 };
4518 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004519 }
4520}
4521
4522void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004524 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004525
Geoff Langbfdea662014-07-23 14:16:32 -04004526 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004527 {
Geoff Langbfdea662014-07-23 14:16:32 -04004528 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004529 }
Geoff Langbfdea662014-07-23 14:16:32 -04004530
4531 gl::Context *context = gl::getNonLostContext();
4532
4533 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004534 {
Geoff Langbfdea662014-07-23 14:16:32 -04004535 GLfloat vals[4] = { values[0], 0, 0, 1 };
4536 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004537 }
4538}
4539
4540void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4541{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004542 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543
Geoff Langbfdea662014-07-23 14:16:32 -04004544 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004545 {
Geoff Langbfdea662014-07-23 14:16:32 -04004546 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004547 }
Geoff Langbfdea662014-07-23 14:16:32 -04004548
4549 gl::Context *context = gl::getNonLostContext();
4550
4551 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004552 {
Geoff Langbfdea662014-07-23 14:16:32 -04004553 GLfloat vals[4] = { x, y, 0, 1 };
4554 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555 }
4556}
4557
4558void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004560 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004561
Geoff Langbfdea662014-07-23 14:16:32 -04004562 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004563 {
Geoff Langbfdea662014-07-23 14:16:32 -04004564 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004565 }
Geoff Langbfdea662014-07-23 14:16:32 -04004566
4567 gl::Context *context = gl::getNonLostContext();
4568
4569 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570 {
Geoff Langbfdea662014-07-23 14:16:32 -04004571 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4572 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573 }
4574}
4575
4576void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4577{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004578 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 +00004579
Geoff Langbfdea662014-07-23 14:16:32 -04004580 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004581 {
Geoff Langbfdea662014-07-23 14:16:32 -04004582 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004583 }
Geoff Langbfdea662014-07-23 14:16:32 -04004584
4585 gl::Context *context = gl::getNonLostContext();
4586
4587 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004588 {
Geoff Langbfdea662014-07-23 14:16:32 -04004589 GLfloat vals[4] = { x, y, z, 1 };
4590 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004591 }
4592}
4593
4594void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004596 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004597
Geoff Langbfdea662014-07-23 14:16:32 -04004598 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004599 {
Geoff Langbfdea662014-07-23 14:16:32 -04004600 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004601 }
Geoff Langbfdea662014-07-23 14:16:32 -04004602
4603 gl::Context *context = gl::getNonLostContext();
4604
4605 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004606 {
Geoff Langbfdea662014-07-23 14:16:32 -04004607 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4608 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609 }
4610}
4611
4612void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4613{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004614 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 +00004615
Geoff Langbfdea662014-07-23 14:16:32 -04004616 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004617 {
Geoff Langbfdea662014-07-23 14:16:32 -04004618 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619 }
Geoff Langbfdea662014-07-23 14:16:32 -04004620
4621 gl::Context *context = gl::getNonLostContext();
4622
4623 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004624 {
Geoff Langbfdea662014-07-23 14:16:32 -04004625 GLfloat vals[4] = { x, y, z, w };
4626 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 }
4628}
4629
4630void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004632 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004633
Geoff Langbfdea662014-07-23 14:16:32 -04004634 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004635 {
Geoff Langbfdea662014-07-23 14:16:32 -04004636 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004637 }
Geoff Langbfdea662014-07-23 14:16:32 -04004638
4639 gl::Context *context = gl::getNonLostContext();
4640
4641 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642 {
Geoff Langbfdea662014-07-23 14:16:32 -04004643 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004644 }
4645}
4646
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004647void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4648{
4649 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4650
Geoff Langbfdea662014-07-23 14:16:32 -04004651 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004652 {
Geoff Langbfdea662014-07-23 14:16:32 -04004653 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004654 }
Geoff Langbfdea662014-07-23 14:16:32 -04004655
4656 gl::Context *context = gl::getNonLostContext();
4657
4658 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004659 {
Geoff Langbfdea662014-07-23 14:16:32 -04004660 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004661 }
4662}
4663
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004664void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004665{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004666 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004667 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004668 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004669
Geoff Langbfdea662014-07-23 14:16:32 -04004670 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004671 {
Geoff Langbfdea662014-07-23 14:16:32 -04004672 return gl::error(GL_INVALID_VALUE);
4673 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004674
Geoff Langbfdea662014-07-23 14:16:32 -04004675 if (size < 1 || size > 4)
4676 {
4677 return gl::error(GL_INVALID_VALUE);
4678 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004679
Geoff Langbfdea662014-07-23 14:16:32 -04004680 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00004681
Geoff Langbfdea662014-07-23 14:16:32 -04004682 switch (type)
4683 {
4684 case GL_BYTE:
4685 case GL_UNSIGNED_BYTE:
4686 case GL_SHORT:
4687 case GL_UNSIGNED_SHORT:
4688 case GL_FIXED:
4689 case GL_FLOAT:
4690 break;
4691 case GL_HALF_FLOAT:
4692 case GL_INT:
4693 case GL_UNSIGNED_INT:
4694 case GL_INT_2_10_10_10_REV:
4695 case GL_UNSIGNED_INT_2_10_10_10_REV:
4696 if (context && context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004698 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004699 }
Geoff Langbfdea662014-07-23 14:16:32 -04004700 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004701 {
Geoff Langbfdea662014-07-23 14:16:32 -04004702 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004703 }
Geoff Langbfdea662014-07-23 14:16:32 -04004704 default:
4705 return gl::error(GL_INVALID_ENUM);
4706 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004707
Geoff Langbfdea662014-07-23 14:16:32 -04004708 if (stride < 0)
4709 {
4710 return gl::error(GL_INVALID_VALUE);
4711 }
4712
4713 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4714 {
4715 return gl::error(GL_INVALID_OPERATION);
4716 }
4717
4718 if (context)
4719 {
4720 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4721 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4722 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4723 // and the pointer argument is not NULL.
4724 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004725 {
4726 return gl::error(GL_INVALID_OPERATION);
4727 }
4728
Geoff Langbfdea662014-07-23 14:16:32 -04004729 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4730 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004731 }
4732}
4733
4734void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4735{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004736 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 +00004737
Geoff Langbfdea662014-07-23 14:16:32 -04004738 if (width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004739 {
Geoff Langbfdea662014-07-23 14:16:32 -04004740 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004741 }
Geoff Langbfdea662014-07-23 14:16:32 -04004742
4743 gl::Context *context = gl::getNonLostContext();
4744
4745 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004746 {
Geoff Langbfdea662014-07-23 14:16:32 -04004747 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004748 }
4749}
4750
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004751// OpenGL ES 3.0 functions
4752
4753void __stdcall glReadBuffer(GLenum mode)
4754{
4755 EVENT("(GLenum mode = 0x%X)", mode);
4756
Geoff Langbfdea662014-07-23 14:16:32 -04004757 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004758
Geoff Langbfdea662014-07-23 14:16:32 -04004759 if (context)
4760 {
4761 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004762 {
Geoff Langbfdea662014-07-23 14:16:32 -04004763 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004764 }
Geoff Langbfdea662014-07-23 14:16:32 -04004765
4766 // glReadBuffer
4767 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004768 }
4769}
4770
4771void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4772{
4773 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4774 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4775
Geoff Langbfdea662014-07-23 14:16:32 -04004776 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004777
Geoff Langbfdea662014-07-23 14:16:32 -04004778 if (context)
4779 {
4780 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004781 {
Geoff Langbfdea662014-07-23 14:16:32 -04004782 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004783 }
Geoff Langbfdea662014-07-23 14:16:32 -04004784
4785 // glDrawRangeElements
4786 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004787 }
4788}
4789
4790void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4791{
4792 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4793 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4794 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4795 target, level, internalformat, width, height, depth, border, format, type, pixels);
4796
Geoff Langbfdea662014-07-23 14:16:32 -04004797 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004798
Geoff Langbfdea662014-07-23 14:16:32 -04004799 if (context)
4800 {
4801 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004802 {
Geoff Langbfdea662014-07-23 14:16:32 -04004803 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004804 }
Geoff Langbfdea662014-07-23 14:16:32 -04004805
4806 // validateES3TexImageFormat sets the error code if there is an error
4807 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4808 0, 0, 0, width, height, depth, border, format, type, pixels))
4809 {
4810 return;
4811 }
4812
4813 switch(target)
4814 {
4815 case GL_TEXTURE_3D:
4816 {
4817 gl::Texture3D *texture = context->getTexture3D();
4818 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4819 }
4820 break;
4821
4822 case GL_TEXTURE_2D_ARRAY:
4823 {
4824 gl::Texture2DArray *texture = context->getTexture2DArray();
4825 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4826 }
4827 break;
4828
4829 default:
4830 return gl::error(GL_INVALID_ENUM);
4831 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004832 }
4833}
4834
4835void __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)
4836{
4837 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4838 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4839 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4840 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4841
Geoff Langbfdea662014-07-23 14:16:32 -04004842 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004843
Geoff Langbfdea662014-07-23 14:16:32 -04004844 if (context)
4845 {
4846 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004847 {
Geoff Langbfdea662014-07-23 14:16:32 -04004848 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004849 }
Geoff Langbfdea662014-07-23 14:16:32 -04004850
4851 // validateES3TexImageFormat sets the error code if there is an error
4852 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4853 xoffset, yoffset, zoffset, width, height, depth, 0,
4854 format, type, pixels))
4855 {
4856 return;
4857 }
4858
4859 // Zero sized uploads are valid but no-ops
4860 if (width == 0 || height == 0 || depth == 0)
4861 {
4862 return;
4863 }
4864
4865 switch(target)
4866 {
4867 case GL_TEXTURE_3D:
4868 {
4869 gl::Texture3D *texture = context->getTexture3D();
4870 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4871 }
4872 break;
4873
4874 case GL_TEXTURE_2D_ARRAY:
4875 {
4876 gl::Texture2DArray *texture = context->getTexture2DArray();
4877 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
4878 }
4879 break;
4880
4881 default:
4882 return gl::error(GL_INVALID_ENUM);
4883 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004884 }
4885}
4886
4887void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
4888{
4889 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4890 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
4891 target, level, xoffset, yoffset, zoffset, x, y, width, height);
4892
Geoff Langbfdea662014-07-23 14:16:32 -04004893 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004894
Geoff Langbfdea662014-07-23 14:16:32 -04004895 if (context)
4896 {
4897 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004898 {
Geoff Langbfdea662014-07-23 14:16:32 -04004899 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004900 }
Geoff Langbfdea662014-07-23 14:16:32 -04004901
4902 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
4903 x, y, width, height, 0))
4904 {
4905 return;
4906 }
4907
4908 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
4909 gl::Texture *texture = NULL;
4910 switch (target)
4911 {
4912 case GL_TEXTURE_3D:
4913 texture = context->getTexture3D();
4914 break;
4915
4916 case GL_TEXTURE_2D_ARRAY:
4917 texture = context->getTexture2DArray();
4918 break;
4919
4920 default:
4921 return gl::error(GL_INVALID_ENUM);
4922 }
4923
4924 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004925 }
4926}
4927
4928void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
4929{
Geoff Langeef52cc2013-10-16 15:07:39 -04004930 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 +00004931 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
4932 "const GLvoid* data = 0x%0.8p)",
4933 target, level, internalformat, width, height, depth, border, imageSize, data);
4934
Geoff Langbfdea662014-07-23 14:16:32 -04004935 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004936
Geoff Langbfdea662014-07-23 14:16:32 -04004937 if (context)
4938 {
4939 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004940 {
Geoff Langbfdea662014-07-23 14:16:32 -04004941 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004942 }
Geoff Langbfdea662014-07-23 14:16:32 -04004943
Geoff Lang5d601382014-07-22 15:14:06 -04004944 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
4945 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04004946 {
4947 return gl::error(GL_INVALID_VALUE);
4948 }
4949
4950 // validateES3TexImageFormat sets the error code if there is an error
4951 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
4952 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
4953 {
4954 return;
4955 }
4956
4957 switch(target)
4958 {
4959 case GL_TEXTURE_3D:
4960 {
4961 gl::Texture3D *texture = context->getTexture3D();
4962 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
4963 }
4964 break;
4965
4966 case GL_TEXTURE_2D_ARRAY:
4967 {
4968 gl::Texture2DArray *texture = context->getTexture2DArray();
4969 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
4970 }
4971 break;
4972
4973 default:
4974 return gl::error(GL_INVALID_ENUM);
4975 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004976 }
4977}
4978
4979void __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)
4980{
4981 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4982 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4983 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
4984 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
4985
Geoff Langbfdea662014-07-23 14:16:32 -04004986 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004987
Geoff Langbfdea662014-07-23 14:16:32 -04004988 if (context)
4989 {
4990 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004991 {
Geoff Langbfdea662014-07-23 14:16:32 -04004992 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004993 }
Geoff Langbfdea662014-07-23 14:16:32 -04004994
Geoff Lang5d601382014-07-22 15:14:06 -04004995 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
4996 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04004997 {
4998 return gl::error(GL_INVALID_VALUE);
4999 }
5000
5001 if (!data)
5002 {
5003 return gl::error(GL_INVALID_VALUE);
5004 }
5005
5006 // validateES3TexImageFormat sets the error code if there is an error
5007 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5008 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5009 {
5010 return;
5011 }
5012
5013 // Zero sized uploads are valid but no-ops
5014 if (width == 0 || height == 0)
5015 {
5016 return;
5017 }
5018
5019 switch(target)
5020 {
5021 case GL_TEXTURE_3D:
5022 {
5023 gl::Texture3D *texture = context->getTexture3D();
5024 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5025 format, imageSize, data);
5026 }
5027 break;
5028
5029 case GL_TEXTURE_2D_ARRAY:
5030 {
5031 gl::Texture2DArray *texture = context->getTexture2DArray();
5032 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5033 format, imageSize, data);
5034 }
5035 break;
5036
5037 default:
5038 return gl::error(GL_INVALID_ENUM);
5039 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005040 }
5041}
5042
5043void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5044{
5045 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5046
Geoff Langbfdea662014-07-23 14:16:32 -04005047 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005048
Geoff Langbfdea662014-07-23 14:16:32 -04005049 if (context)
5050 {
5051 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005052 {
Geoff Langbfdea662014-07-23 14:16:32 -04005053 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005054 }
Geoff Langbfdea662014-07-23 14:16:32 -04005055
5056 if (n < 0)
5057 {
5058 return gl::error(GL_INVALID_VALUE);
5059 }
5060
5061 for (GLsizei i = 0; i < n; i++)
5062 {
5063 ids[i] = context->createQuery();
5064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005065 }
5066}
5067
5068void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5069{
5070 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5071
Geoff Langbfdea662014-07-23 14:16:32 -04005072 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005073
Geoff Langbfdea662014-07-23 14:16:32 -04005074 if (context)
5075 {
5076 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005077 {
Geoff Langbfdea662014-07-23 14:16:32 -04005078 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005079 }
Geoff Langbfdea662014-07-23 14:16:32 -04005080
5081 if (n < 0)
5082 {
5083 return gl::error(GL_INVALID_VALUE);
5084 }
5085
5086 for (GLsizei i = 0; i < n; i++)
5087 {
5088 context->deleteQuery(ids[i]);
5089 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005090 }
5091}
5092
5093GLboolean __stdcall glIsQuery(GLuint id)
5094{
5095 EVENT("(GLuint id = %u)", id);
5096
Geoff Langbfdea662014-07-23 14:16:32 -04005097 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005098
Geoff Langbfdea662014-07-23 14:16:32 -04005099 if (context)
5100 {
5101 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005102 {
Geoff Langbfdea662014-07-23 14:16:32 -04005103 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005104 }
Geoff Langbfdea662014-07-23 14:16:32 -04005105
5106 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005107 }
5108
5109 return GL_FALSE;
5110}
5111
5112void __stdcall glBeginQuery(GLenum target, GLuint id)
5113{
5114 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5115
Geoff Langbfdea662014-07-23 14:16:32 -04005116 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005117
Geoff Langbfdea662014-07-23 14:16:32 -04005118 if (context)
5119 {
5120 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005121 {
Geoff Langbfdea662014-07-23 14:16:32 -04005122 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005123 }
Geoff Langbfdea662014-07-23 14:16:32 -04005124
5125 if (!ValidateBeginQuery(context, target, id))
5126 {
5127 return;
5128 }
5129 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005130 }
5131}
5132
5133void __stdcall glEndQuery(GLenum target)
5134{
5135 EVENT("(GLenum target = 0x%X)", target);
5136
Geoff Langbfdea662014-07-23 14:16:32 -04005137 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005138
Geoff Langbfdea662014-07-23 14:16:32 -04005139 if (context)
5140 {
5141 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005142 {
Geoff Langbfdea662014-07-23 14:16:32 -04005143 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005144 }
Geoff Langbfdea662014-07-23 14:16:32 -04005145
5146 if (!ValidateEndQuery(context, target))
5147 {
5148 return;
5149 }
5150
5151 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005152 }
5153}
5154
5155void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5156{
5157 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5158
Geoff Langbfdea662014-07-23 14:16:32 -04005159 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005160
Geoff Langbfdea662014-07-23 14:16:32 -04005161 if (context)
5162 {
5163 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005164 {
Geoff Langbfdea662014-07-23 14:16:32 -04005165 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005166 }
Geoff Langbfdea662014-07-23 14:16:32 -04005167
5168 if (!ValidQueryType(context, target))
5169 {
5170 return gl::error(GL_INVALID_ENUM);
5171 }
5172
5173 switch (pname)
5174 {
5175 case GL_CURRENT_QUERY:
5176 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5177 break;
5178
5179 default:
5180 return gl::error(GL_INVALID_ENUM);
5181 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005182 }
5183}
5184
5185void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5186{
5187 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5188
Geoff Langbfdea662014-07-23 14:16:32 -04005189 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005190
Geoff Langbfdea662014-07-23 14:16:32 -04005191 if (context)
5192 {
5193 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005194 {
Geoff Langbfdea662014-07-23 14:16:32 -04005195 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005196 }
Geoff Langbfdea662014-07-23 14:16:32 -04005197
5198 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5199
5200 if (!queryObject)
5201 {
5202 return gl::error(GL_INVALID_OPERATION);
5203 }
5204
5205 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5206 {
5207 return gl::error(GL_INVALID_OPERATION);
5208 }
5209
5210 switch(pname)
5211 {
5212 case GL_QUERY_RESULT:
5213 params[0] = queryObject->getResult();
5214 break;
5215 case GL_QUERY_RESULT_AVAILABLE:
5216 params[0] = queryObject->isResultAvailable();
5217 break;
5218 default:
5219 return gl::error(GL_INVALID_ENUM);
5220 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005221 }
5222}
5223
5224GLboolean __stdcall glUnmapBuffer(GLenum target)
5225{
5226 EVENT("(GLenum target = 0x%X)", target);
5227
Geoff Langbfdea662014-07-23 14:16:32 -04005228 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005229
Geoff Langbfdea662014-07-23 14:16:32 -04005230 if (context)
5231 {
5232 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005233 {
Geoff Langbfdea662014-07-23 14:16:32 -04005234 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005235 }
Geoff Langbfdea662014-07-23 14:16:32 -04005236
5237 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005238 }
5239
5240 return GL_FALSE;
5241}
5242
5243void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5244{
5245 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5246
Geoff Langbfdea662014-07-23 14:16:32 -04005247 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005248
Geoff Langbfdea662014-07-23 14:16:32 -04005249 if (context)
5250 {
5251 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005252 {
Geoff Langbfdea662014-07-23 14:16:32 -04005253 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005254 }
Geoff Langbfdea662014-07-23 14:16:32 -04005255
5256 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005257 }
5258}
5259
5260void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5261{
Geoff Langbfdea662014-07-23 14:16:32 -04005262 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005263
Geoff Langbfdea662014-07-23 14:16:32 -04005264 if (context)
5265 {
5266 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005267 {
Geoff Langbfdea662014-07-23 14:16:32 -04005268 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005269 }
Geoff Langbfdea662014-07-23 14:16:32 -04005270
5271 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005272 }
5273}
5274
5275void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5276{
5277 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5278 location, count, transpose, value);
5279
Geoff Langbfdea662014-07-23 14:16:32 -04005280 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005281
Geoff Langbfdea662014-07-23 14:16:32 -04005282 if (context)
5283 {
5284 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005285 {
Geoff Langbfdea662014-07-23 14:16:32 -04005286 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005287 }
Geoff Langbfdea662014-07-23 14:16:32 -04005288
5289 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5290 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005291 }
5292}
5293
5294void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5295{
5296 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5297 location, count, transpose, value);
5298
Geoff Langbfdea662014-07-23 14:16:32 -04005299 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005300
Geoff Langbfdea662014-07-23 14:16:32 -04005301 if (context)
5302 {
5303 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005304 {
Geoff Langbfdea662014-07-23 14:16:32 -04005305 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005306 }
Geoff Langbfdea662014-07-23 14:16:32 -04005307
5308 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5309 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005310 }
5311}
5312
5313void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5314{
5315 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5316 location, count, transpose, value);
5317
Geoff Langbfdea662014-07-23 14:16:32 -04005318 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005319
Geoff Langbfdea662014-07-23 14:16:32 -04005320 if (context)
5321 {
5322 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005323 {
Geoff Langbfdea662014-07-23 14:16:32 -04005324 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005325 }
Geoff Langbfdea662014-07-23 14:16:32 -04005326
5327 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5328 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005329 }
5330}
5331
5332void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5333{
5334 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5335 location, count, transpose, value);
5336
Geoff Langbfdea662014-07-23 14:16:32 -04005337 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005338
Geoff Langbfdea662014-07-23 14:16:32 -04005339 if (context)
5340 {
5341 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005342 {
Geoff Langbfdea662014-07-23 14:16:32 -04005343 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005344 }
Geoff Langbfdea662014-07-23 14:16:32 -04005345
5346 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5347 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005348 }
5349}
5350
5351void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5352{
5353 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5354 location, count, transpose, value);
5355
Geoff Langbfdea662014-07-23 14:16:32 -04005356 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005357
Geoff Langbfdea662014-07-23 14:16:32 -04005358 if (context)
5359 {
5360 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005361 {
Geoff Langbfdea662014-07-23 14:16:32 -04005362 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005363 }
Geoff Langbfdea662014-07-23 14:16:32 -04005364
5365 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5366 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005367 }
5368}
5369
5370void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5371{
5372 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5373 location, count, transpose, value);
5374
Geoff Langbfdea662014-07-23 14:16:32 -04005375 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005376
Geoff Langbfdea662014-07-23 14:16:32 -04005377 if (context)
5378 {
5379 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005380 {
Geoff Langbfdea662014-07-23 14:16:32 -04005381 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005382 }
Geoff Langbfdea662014-07-23 14:16:32 -04005383
5384 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5385 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005386 }
5387}
5388
5389void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5390{
5391 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5392 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5393 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5394
Geoff Langbfdea662014-07-23 14:16:32 -04005395 gl::Context *context = gl::getNonLostContext();
5396 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005397 {
Geoff Langbfdea662014-07-23 14:16:32 -04005398 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005399 {
Geoff Langbfdea662014-07-23 14:16:32 -04005400 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005401 }
Geoff Langbfdea662014-07-23 14:16:32 -04005402
5403 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5404 dstX0, dstY0, dstX1, dstY1, mask, filter,
5405 false))
5406 {
5407 return;
5408 }
5409
5410 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5411 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005412 }
5413}
5414
5415void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5416{
5417 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5418 target, samples, internalformat, width, height);
5419
Geoff Langbfdea662014-07-23 14:16:32 -04005420 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005421
Geoff Langbfdea662014-07-23 14:16:32 -04005422 if (context)
5423 {
5424 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005425 {
Geoff Langbfdea662014-07-23 14:16:32 -04005426 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005427 }
Geoff Langbfdea662014-07-23 14:16:32 -04005428
5429 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5430 width, height, false))
5431 {
5432 return;
5433 }
5434
5435 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005436 }
5437}
5438
5439void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5440{
5441 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5442 target, attachment, texture, level, layer);
5443
Geoff Langbfdea662014-07-23 14:16:32 -04005444 gl::Context *context = gl::getNonLostContext();
5445
5446 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005447 {
Geoff Langbfdea662014-07-23 14:16:32 -04005448 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5449 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005450 {
Geoff Langbfdea662014-07-23 14:16:32 -04005451 return;
5452 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005453
Geoff Langbfdea662014-07-23 14:16:32 -04005454 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5455 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005456
Geoff Langbfdea662014-07-23 14:16:32 -04005457 gl::Texture *textureObject = context->getTexture(texture);
5458 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005459
Geoff Langbfdea662014-07-23 14:16:32 -04005460 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5461 {
5462 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5463 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5464 }
5465 else
5466 {
5467 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005468 {
Geoff Langbfdea662014-07-23 14:16:32 -04005469 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5470 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5471 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005472 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005473 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005474 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005475}
5476
5477GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5478{
5479 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5480 target, offset, length, access);
5481
Geoff Langbfdea662014-07-23 14:16:32 -04005482 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005483
Geoff Langbfdea662014-07-23 14:16:32 -04005484 if (context)
5485 {
5486 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005487 {
Geoff Langbfdea662014-07-23 14:16:32 -04005488 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005489 }
Geoff Langbfdea662014-07-23 14:16:32 -04005490
5491 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005492 }
5493
5494 return NULL;
5495}
5496
5497void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5498{
5499 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5500
Geoff Langbfdea662014-07-23 14:16:32 -04005501 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005502
Geoff Langbfdea662014-07-23 14:16:32 -04005503 if (context)
5504 {
5505 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005506 {
Geoff Langbfdea662014-07-23 14:16:32 -04005507 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005508 }
Geoff Langbfdea662014-07-23 14:16:32 -04005509
5510 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005511 }
5512}
5513
5514void __stdcall glBindVertexArray(GLuint array)
5515{
5516 EVENT("(GLuint array = %u)", array);
5517
Geoff Langbfdea662014-07-23 14:16:32 -04005518 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005519
Geoff Langbfdea662014-07-23 14:16:32 -04005520 if (context)
5521 {
5522 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005523 {
Geoff Langbfdea662014-07-23 14:16:32 -04005524 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005525 }
Geoff Langbfdea662014-07-23 14:16:32 -04005526
5527 gl::VertexArray *vao = context->getVertexArray(array);
5528
5529 if (!vao)
5530 {
5531 // The default VAO should always exist
5532 ASSERT(array != 0);
5533 return gl::error(GL_INVALID_OPERATION);
5534 }
5535
5536 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005537 }
5538}
5539
5540void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5541{
5542 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5543
Geoff Langbfdea662014-07-23 14:16:32 -04005544 gl::Context *context = gl::getNonLostContext();
5545
5546 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005547 {
Geoff Langbfdea662014-07-23 14:16:32 -04005548 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005549 {
Geoff Langbfdea662014-07-23 14:16:32 -04005550 return gl::error(GL_INVALID_OPERATION);
5551 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005552
Geoff Langbfdea662014-07-23 14:16:32 -04005553 if (n < 0)
5554 {
5555 return gl::error(GL_INVALID_VALUE);
5556 }
Jamie Madilld1028542013-07-02 11:57:04 -04005557
Geoff Langbfdea662014-07-23 14:16:32 -04005558 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5559 {
5560 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005561 {
Geoff Langbfdea662014-07-23 14:16:32 -04005562 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005563 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005564 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005565 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005566}
5567
5568void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5569{
5570 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5571
Geoff Langbfdea662014-07-23 14:16:32 -04005572 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005573
Geoff Langbfdea662014-07-23 14:16:32 -04005574 if (context)
5575 {
5576 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005577 {
Geoff Langbfdea662014-07-23 14:16:32 -04005578 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005579 }
Geoff Langbfdea662014-07-23 14:16:32 -04005580
5581 if (n < 0)
5582 {
5583 return gl::error(GL_INVALID_VALUE);
5584 }
5585
5586 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5587 {
5588 arrays[arrayIndex] = context->createVertexArray();
5589 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005590 }
5591}
5592
5593GLboolean __stdcall glIsVertexArray(GLuint array)
5594{
5595 EVENT("(GLuint array = %u)", array);
5596
Geoff Langbfdea662014-07-23 14:16:32 -04005597 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005598
Geoff Langbfdea662014-07-23 14:16:32 -04005599 if (context)
5600 {
5601 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005602 {
Geoff Langbfdea662014-07-23 14:16:32 -04005603 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005604 }
Geoff Langbfdea662014-07-23 14:16:32 -04005605
5606 if (array == 0)
5607 {
5608 return GL_FALSE;
5609 }
5610
5611 gl::VertexArray *vao = context->getVertexArray(array);
5612
5613 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005614 }
5615
5616 return GL_FALSE;
5617}
5618
5619void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5620{
5621 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5622 target, index, data);
5623
Geoff Langbfdea662014-07-23 14:16:32 -04005624 gl::Context *context = gl::getNonLostContext();
5625
5626 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005627 {
Geoff Langbfdea662014-07-23 14:16:32 -04005628 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005629 {
Geoff Langbfdea662014-07-23 14:16:32 -04005630 return gl::error(GL_INVALID_OPERATION);
5631 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005632
Geoff Lang3a61c322014-07-10 13:01:54 -04005633 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005634 switch (target)
5635 {
5636 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5637 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5638 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
5639 if (index >= context->getMaxTransformFeedbackBufferBindings())
5640 return gl::error(GL_INVALID_VALUE);
5641 break;
5642 case GL_UNIFORM_BUFFER_START:
5643 case GL_UNIFORM_BUFFER_SIZE:
5644 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005645 if (index >= caps.maxCombinedUniformBlocks)
5646 {
Geoff Langbfdea662014-07-23 14:16:32 -04005647 return gl::error(GL_INVALID_VALUE);
Geoff Lang3a61c322014-07-10 13:01:54 -04005648 }
Geoff Langbfdea662014-07-23 14:16:32 -04005649 break;
5650 default:
5651 return gl::error(GL_INVALID_ENUM);
5652 }
5653
5654 if (!(context->getIndexedIntegerv(target, index, data)))
5655 {
5656 GLenum nativeType;
5657 unsigned int numParams = 0;
5658 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04005659 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04005660
Geoff Langbfdea662014-07-23 14:16:32 -04005661 if (numParams == 0)
5662 return; // it is known that pname is valid, but there are no parameters to return
5663
5664 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005665 {
Geoff Langbfdea662014-07-23 14:16:32 -04005666 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5667 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5668 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005669
Geoff Langbfdea662014-07-23 14:16:32 -04005670 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005671
Geoff Langbfdea662014-07-23 14:16:32 -04005672 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005673 {
Geoff Langbfdea662014-07-23 14:16:32 -04005674 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5675 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005676 }
Geoff Langbfdea662014-07-23 14:16:32 -04005677
5678 delete [] int64Params;
5679 }
5680 else
5681 {
5682 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005683 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005684 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005685 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005686}
5687
5688void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5689{
5690 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5691
Geoff Langbfdea662014-07-23 14:16:32 -04005692 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005693
Geoff Langbfdea662014-07-23 14:16:32 -04005694 if (context)
5695 {
5696 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005697 {
Geoff Langbfdea662014-07-23 14:16:32 -04005698 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005699 }
Geoff Langbfdea662014-07-23 14:16:32 -04005700
5701 switch (primitiveMode)
5702 {
5703 case GL_TRIANGLES:
5704 case GL_LINES:
5705 case GL_POINTS:
5706 break;
5707 default:
5708 return gl::error(GL_INVALID_ENUM);
5709 }
5710
5711 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5712 ASSERT(transformFeedback != NULL);
5713
5714 if (transformFeedback->isStarted())
5715 {
5716 return gl::error(GL_INVALID_OPERATION);
5717 }
5718
5719 if (transformFeedback->isPaused())
5720 {
5721 transformFeedback->resume();
5722 }
5723 else
5724 {
5725 transformFeedback->start(primitiveMode);
5726 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005727 }
5728}
5729
5730void __stdcall glEndTransformFeedback(void)
5731{
5732 EVENT("(void)");
5733
Geoff Langbfdea662014-07-23 14:16:32 -04005734 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005735
Geoff Langbfdea662014-07-23 14:16:32 -04005736 if (context)
5737 {
5738 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005739 {
Geoff Langbfdea662014-07-23 14:16:32 -04005740 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005741 }
Geoff Langbfdea662014-07-23 14:16:32 -04005742
5743 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5744 ASSERT(transformFeedback != NULL);
5745
5746 if (!transformFeedback->isStarted())
5747 {
5748 return gl::error(GL_INVALID_OPERATION);
5749 }
5750
5751 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005752 }
5753}
5754
5755void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5756{
5757 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5758 target, index, buffer, offset, size);
5759
Geoff Langbfdea662014-07-23 14:16:32 -04005760 gl::Context *context = gl::getNonLostContext();
5761
5762 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005763 {
Geoff Langbfdea662014-07-23 14:16:32 -04005764 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005765 {
Geoff Langbfdea662014-07-23 14:16:32 -04005766 return gl::error(GL_INVALID_OPERATION);
5767 }
5768
Geoff Lang3a61c322014-07-10 13:01:54 -04005769 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005770 switch (target)
5771 {
5772 case GL_TRANSFORM_FEEDBACK_BUFFER:
5773 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005774 {
Geoff Langbfdea662014-07-23 14:16:32 -04005775 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005776 }
Geoff Langbfdea662014-07-23 14:16:32 -04005777 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005778
Geoff Langbfdea662014-07-23 14:16:32 -04005779 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04005780 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005781 {
Geoff Langbfdea662014-07-23 14:16:32 -04005782 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005783 }
Geoff Langbfdea662014-07-23 14:16:32 -04005784 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005785
Geoff Langbfdea662014-07-23 14:16:32 -04005786 default:
5787 return gl::error(GL_INVALID_ENUM);
5788 }
5789
5790 if (buffer != 0 && size <= 0)
5791 {
5792 return gl::error(GL_INVALID_VALUE);
5793 }
5794
5795 switch (target)
5796 {
5797 case GL_TRANSFORM_FEEDBACK_BUFFER:
5798
5799 // size and offset must be a multiple of 4
5800 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005801 {
5802 return gl::error(GL_INVALID_VALUE);
5803 }
5804
Geoff Langbfdea662014-07-23 14:16:32 -04005805 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5806 context->bindGenericTransformFeedbackBuffer(buffer);
5807 break;
5808
5809 case GL_UNIFORM_BUFFER:
5810
5811 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04005812 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005813 {
Geoff Langbfdea662014-07-23 14:16:32 -04005814 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005815 }
Geoff Langbfdea662014-07-23 14:16:32 -04005816
5817 context->bindIndexedUniformBuffer(buffer, index, offset, size);
5818 context->bindGenericUniformBuffer(buffer);
5819 break;
5820
5821 default:
5822 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005823 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005824 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005825}
5826
5827void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
5828{
5829 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
5830 target, index, buffer);
5831
Geoff Langbfdea662014-07-23 14:16:32 -04005832 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005833
Geoff Langbfdea662014-07-23 14:16:32 -04005834 if (context)
5835 {
5836 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005837 {
Geoff Langbfdea662014-07-23 14:16:32 -04005838 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005839 }
Geoff Langbfdea662014-07-23 14:16:32 -04005840
Geoff Lang3a61c322014-07-10 13:01:54 -04005841 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005842 switch (target)
5843 {
5844 case GL_TRANSFORM_FEEDBACK_BUFFER:
5845 if (index >= context->getMaxTransformFeedbackBufferBindings())
5846 {
5847 return gl::error(GL_INVALID_VALUE);
5848 }
5849 break;
5850
5851 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04005852 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04005853 {
5854 return gl::error(GL_INVALID_VALUE);
5855 }
5856 break;
5857
5858 default:
5859 return gl::error(GL_INVALID_ENUM);
5860 }
5861
5862 switch (target)
5863 {
5864 case GL_TRANSFORM_FEEDBACK_BUFFER:
5865 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
5866 context->bindGenericTransformFeedbackBuffer(buffer);
5867 break;
5868
5869 case GL_UNIFORM_BUFFER:
5870 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
5871 context->bindGenericUniformBuffer(buffer);
5872 break;
5873
5874 default:
5875 UNREACHABLE();
5876 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005877 }
5878}
5879
5880void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
5881{
5882 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
5883 program, count, varyings, bufferMode);
5884
Geoff Langbfdea662014-07-23 14:16:32 -04005885 gl::Context *context = gl::getNonLostContext();
5886
5887 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005888 {
Geoff Langbfdea662014-07-23 14:16:32 -04005889 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005890 {
Geoff Langbfdea662014-07-23 14:16:32 -04005891 return gl::error(GL_INVALID_OPERATION);
5892 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005893
Geoff Langbfdea662014-07-23 14:16:32 -04005894 if (count < 0)
5895 {
5896 return gl::error(GL_INVALID_VALUE);
5897 }
5898
5899 switch (bufferMode)
5900 {
5901 case GL_INTERLEAVED_ATTRIBS:
5902 break;
5903 case GL_SEPARATE_ATTRIBS:
5904 if (static_cast<GLuint>(count) > context->getMaxTransformFeedbackBufferBindings())
Geoff Lang48dcae72014-02-05 16:28:24 -05005905 {
5906 return gl::error(GL_INVALID_VALUE);
5907 }
Geoff Langbfdea662014-07-23 14:16:32 -04005908 break;
5909 default:
5910 return gl::error(GL_INVALID_ENUM);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005911 }
Geoff Langbfdea662014-07-23 14:16:32 -04005912
5913 if (!gl::ValidProgram(context, program))
5914 {
5915 return;
5916 }
5917
5918 gl::Program *programObject = context->getProgram(program);
5919 ASSERT(programObject);
5920
5921 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005922 }
5923}
5924
5925void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
5926{
5927 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
5928 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
5929 program, index, bufSize, length, size, type, name);
5930
Geoff Langbfdea662014-07-23 14:16:32 -04005931 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005932
Geoff Langbfdea662014-07-23 14:16:32 -04005933 if (context)
5934 {
5935 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005936 {
Geoff Langbfdea662014-07-23 14:16:32 -04005937 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005938 }
Geoff Langbfdea662014-07-23 14:16:32 -04005939
5940 if (bufSize < 0)
5941 {
5942 return gl::error(GL_INVALID_VALUE);
5943 }
5944
5945 if (!gl::ValidProgram(context, program))
5946 {
5947 return;
5948 }
5949
5950 gl::Program *programObject = context->getProgram(program);
5951 ASSERT(programObject);
5952
5953 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
5954 {
5955 return gl::error(GL_INVALID_VALUE);
5956 }
5957
5958 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005959 }
5960}
5961
5962void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
5963{
5964 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
5965 index, size, type, stride, pointer);
5966
Geoff Langbfdea662014-07-23 14:16:32 -04005967 gl::Context *context = gl::getNonLostContext();
5968
5969 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005970 {
Geoff Langbfdea662014-07-23 14:16:32 -04005971 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005972 {
Geoff Langbfdea662014-07-23 14:16:32 -04005973 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005974 }
Geoff Langbfdea662014-07-23 14:16:32 -04005975 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005976
Geoff Langbfdea662014-07-23 14:16:32 -04005977 if (index >= gl::MAX_VERTEX_ATTRIBS)
5978 {
5979 return gl::error(GL_INVALID_VALUE);
5980 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005981
Geoff Langbfdea662014-07-23 14:16:32 -04005982 if (size < 1 || size > 4)
5983 {
5984 return gl::error(GL_INVALID_VALUE);
5985 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005986
Geoff Langbfdea662014-07-23 14:16:32 -04005987 switch (type)
5988 {
5989 case GL_BYTE:
5990 case GL_UNSIGNED_BYTE:
5991 case GL_SHORT:
5992 case GL_UNSIGNED_SHORT:
5993 case GL_INT:
5994 case GL_UNSIGNED_INT:
5995 case GL_INT_2_10_10_10_REV:
5996 case GL_UNSIGNED_INT_2_10_10_10_REV:
5997 break;
5998 default:
5999 return gl::error(GL_INVALID_ENUM);
6000 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006001
Geoff Langbfdea662014-07-23 14:16:32 -04006002 if (stride < 0)
6003 {
6004 return gl::error(GL_INVALID_VALUE);
6005 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006006
Geoff Langbfdea662014-07-23 14:16:32 -04006007 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6008 {
6009 return gl::error(GL_INVALID_OPERATION);
6010 }
6011
6012 if (context)
6013 {
6014 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6015 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6016 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6017 // and the pointer argument is not NULL.
6018 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006019 {
6020 return gl::error(GL_INVALID_OPERATION);
6021 }
6022
Geoff Langbfdea662014-07-23 14:16:32 -04006023 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6024 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006025 }
6026}
6027
6028void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6029{
6030 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6031 index, pname, params);
6032
Geoff Langbfdea662014-07-23 14:16:32 -04006033 gl::Context *context = gl::getNonLostContext();
6034
6035 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006036 {
Geoff Langbfdea662014-07-23 14:16:32 -04006037 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006038 {
Geoff Langbfdea662014-07-23 14:16:32 -04006039 return gl::error(GL_INVALID_OPERATION);
6040 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006041
Geoff Langbfdea662014-07-23 14:16:32 -04006042 if (index >= gl::MAX_VERTEX_ATTRIBS)
6043 {
6044 return gl::error(GL_INVALID_VALUE);
6045 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006046
Geoff Langbfdea662014-07-23 14:16:32 -04006047 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006048
Geoff Langbfdea662014-07-23 14:16:32 -04006049 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6050 {
6051 return;
6052 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006053
Geoff Langbfdea662014-07-23 14:16:32 -04006054 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6055 {
6056 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6057 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006058 {
Geoff Langbfdea662014-07-23 14:16:32 -04006059 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006060 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006061 }
Geoff Langbfdea662014-07-23 14:16:32 -04006062 else
6063 {
6064 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6065 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006066 }
6067}
6068
6069void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6070{
6071 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6072 index, pname, params);
6073
Geoff Langbfdea662014-07-23 14:16:32 -04006074 gl::Context *context = gl::getNonLostContext();
6075
6076 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006077 {
Geoff Langbfdea662014-07-23 14:16:32 -04006078 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006079 {
Geoff Langbfdea662014-07-23 14:16:32 -04006080 return gl::error(GL_INVALID_OPERATION);
6081 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006082
Geoff Langbfdea662014-07-23 14:16:32 -04006083 if (index >= gl::MAX_VERTEX_ATTRIBS)
6084 {
6085 return gl::error(GL_INVALID_VALUE);
6086 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006087
Geoff Langbfdea662014-07-23 14:16:32 -04006088 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006089
Geoff Langbfdea662014-07-23 14:16:32 -04006090 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6091 {
6092 return;
6093 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006094
Geoff Langbfdea662014-07-23 14:16:32 -04006095 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6096 {
6097 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6098 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006099 {
Geoff Langbfdea662014-07-23 14:16:32 -04006100 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006101 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006102 }
Geoff Langbfdea662014-07-23 14:16:32 -04006103 else
6104 {
6105 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006107 }
6108}
6109
6110void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6111{
6112 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6113 index, x, y, z, w);
6114
Geoff Langbfdea662014-07-23 14:16:32 -04006115 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006116
Geoff Langbfdea662014-07-23 14:16:32 -04006117 if (context)
6118 {
6119 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006120 {
Geoff Langbfdea662014-07-23 14:16:32 -04006121 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006122 }
Geoff Langbfdea662014-07-23 14:16:32 -04006123
6124 if (index >= gl::MAX_VERTEX_ATTRIBS)
6125 {
6126 return gl::error(GL_INVALID_VALUE);
6127 }
6128
6129 GLint vals[4] = { x, y, z, w };
6130 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006131 }
6132}
6133
6134void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6135{
6136 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6137 index, x, y, z, w);
6138
Geoff Langbfdea662014-07-23 14:16:32 -04006139 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006140
Geoff Langbfdea662014-07-23 14:16:32 -04006141 if (context)
6142 {
6143 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006144 {
Geoff Langbfdea662014-07-23 14:16:32 -04006145 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006146 }
Geoff Langbfdea662014-07-23 14:16:32 -04006147
6148 if (index >= gl::MAX_VERTEX_ATTRIBS)
6149 {
6150 return gl::error(GL_INVALID_VALUE);
6151 }
6152
6153 GLuint vals[4] = { x, y, z, w };
6154 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006155 }
6156}
6157
6158void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6159{
6160 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6161
Geoff Langbfdea662014-07-23 14:16:32 -04006162 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006163
Geoff Langbfdea662014-07-23 14:16:32 -04006164 if (context)
6165 {
6166 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006167 {
Geoff Langbfdea662014-07-23 14:16:32 -04006168 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006169 }
Geoff Langbfdea662014-07-23 14:16:32 -04006170
6171 if (index >= gl::MAX_VERTEX_ATTRIBS)
6172 {
6173 return gl::error(GL_INVALID_VALUE);
6174 }
6175
6176 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006177 }
6178}
6179
6180void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6181{
6182 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6183
Geoff Langbfdea662014-07-23 14:16:32 -04006184 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006185
Geoff Langbfdea662014-07-23 14:16:32 -04006186 if (context)
6187 {
6188 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006189 {
Geoff Langbfdea662014-07-23 14:16:32 -04006190 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006191 }
Geoff Langbfdea662014-07-23 14:16:32 -04006192
6193 if (index >= gl::MAX_VERTEX_ATTRIBS)
6194 {
6195 return gl::error(GL_INVALID_VALUE);
6196 }
6197
6198 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006199 }
6200}
6201
6202void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6203{
6204 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6205 program, location, params);
6206
Geoff Langbfdea662014-07-23 14:16:32 -04006207 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006208
Geoff Langbfdea662014-07-23 14:16:32 -04006209 if (context)
6210 {
Jamie Madill0063c512014-08-25 15:47:53 -04006211 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006212 {
Jamie Madill0063c512014-08-25 15:47:53 -04006213 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006214 }
Geoff Langbfdea662014-07-23 14:16:32 -04006215
Jamie Madill0063c512014-08-25 15:47:53 -04006216 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6217 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006218
Jamie Madill99a1e982014-08-25 15:47:54 -04006219 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006220 }
6221}
6222
6223GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6224{
6225 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6226 program, name);
6227
Geoff Langbfdea662014-07-23 14:16:32 -04006228 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006229
Geoff Langbfdea662014-07-23 14:16:32 -04006230 if (context)
6231 {
6232 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006233 {
Geoff Langbfdea662014-07-23 14:16:32 -04006234 return gl::error(GL_INVALID_OPERATION, -1);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006235 }
Geoff Langbfdea662014-07-23 14:16:32 -04006236
6237 if (program == 0)
6238 {
6239 return gl::error(GL_INVALID_VALUE, -1);
6240 }
6241
6242 gl::Program *programObject = context->getProgram(program);
6243
6244 if (!programObject || !programObject->isLinked())
6245 {
6246 return gl::error(GL_INVALID_OPERATION, -1);
6247 }
6248
6249 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6250 if (!programBinary)
6251 {
6252 return gl::error(GL_INVALID_OPERATION, -1);
6253 }
6254
6255 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006256 }
6257
6258 return 0;
6259}
6260
6261void __stdcall glUniform1ui(GLint location, GLuint v0)
6262{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006263 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006264}
6265
6266void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6267{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006268 const GLuint xy[] = { v0, v1 };
6269 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006270}
6271
6272void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6273{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006274 const GLuint xyz[] = { v0, v1, v2 };
6275 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006276}
6277
6278void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6279{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006280 const GLuint xyzw[] = { v0, v1, v2, v3 };
6281 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006282}
6283
6284void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6285{
6286 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6287 location, count, value);
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 (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006294 {
Geoff Langbfdea662014-07-23 14:16:32 -04006295 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006296 }
Geoff Langbfdea662014-07-23 14:16:32 -04006297
6298 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6299 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006300 }
6301}
6302
6303void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6304{
6305 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6306 location, count, value);
6307
Geoff Langbfdea662014-07-23 14:16:32 -04006308 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006309
Geoff Langbfdea662014-07-23 14:16:32 -04006310 if (context)
6311 {
6312 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006313 {
Geoff Langbfdea662014-07-23 14:16:32 -04006314 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006315 }
Geoff Langbfdea662014-07-23 14:16:32 -04006316
6317 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6318 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006319 }
6320}
6321
6322void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6323{
6324 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6325 location, count, value);
6326
Geoff Langbfdea662014-07-23 14:16:32 -04006327 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006328
Geoff Langbfdea662014-07-23 14:16:32 -04006329 if (context)
6330 {
6331 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006332 {
Geoff Langbfdea662014-07-23 14:16:32 -04006333 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006334 }
Geoff Langbfdea662014-07-23 14:16:32 -04006335
6336 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6337 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006338 }
6339}
6340
6341void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6342{
6343 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6344 location, count, value);
6345
Geoff Langbfdea662014-07-23 14:16:32 -04006346 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006347
Geoff Langbfdea662014-07-23 14:16:32 -04006348 if (context)
6349 {
6350 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006351 {
Geoff Langbfdea662014-07-23 14:16:32 -04006352 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006353 }
Geoff Langbfdea662014-07-23 14:16:32 -04006354
6355 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6356 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006357 }
6358}
6359
6360void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6361{
6362 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6363 buffer, drawbuffer, value);
6364
Geoff Langbfdea662014-07-23 14:16:32 -04006365 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006366
Geoff Langbfdea662014-07-23 14:16:32 -04006367 if (context)
6368 {
6369 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006370 {
Geoff Langbfdea662014-07-23 14:16:32 -04006371 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006372 }
Geoff Langbfdea662014-07-23 14:16:32 -04006373
6374 switch (buffer)
6375 {
6376 case GL_COLOR:
6377 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6378 {
6379 return gl::error(GL_INVALID_VALUE);
6380 }
6381 break;
6382 case GL_STENCIL:
6383 if (drawbuffer != 0)
6384 {
6385 return gl::error(GL_INVALID_VALUE);
6386 }
6387 break;
6388 default:
6389 return gl::error(GL_INVALID_ENUM);
6390 }
6391
6392 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006393 }
6394}
6395
6396void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6397{
6398 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6399 buffer, drawbuffer, value);
6400
Geoff Langbfdea662014-07-23 14:16:32 -04006401 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006402
Geoff Langbfdea662014-07-23 14:16:32 -04006403 if (context)
6404 {
6405 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006406 {
Geoff Langbfdea662014-07-23 14:16:32 -04006407 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006408 }
Geoff Langbfdea662014-07-23 14:16:32 -04006409
6410 switch (buffer)
6411 {
6412 case GL_COLOR:
6413 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6414 {
6415 return gl::error(GL_INVALID_VALUE);
6416 }
6417 break;
6418 default:
6419 return gl::error(GL_INVALID_ENUM);
6420 }
6421
6422 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006423 }
6424}
6425
6426void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6427{
6428 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6429 buffer, drawbuffer, value);
6430
Geoff Langbfdea662014-07-23 14:16:32 -04006431 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006432
Geoff Langbfdea662014-07-23 14:16:32 -04006433 if (context)
6434 {
6435 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006436 {
Geoff Langbfdea662014-07-23 14:16:32 -04006437 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006438 }
Geoff Langbfdea662014-07-23 14:16:32 -04006439
6440 switch (buffer)
6441 {
6442 case GL_COLOR:
6443 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6444 {
6445 return gl::error(GL_INVALID_VALUE);
6446 }
6447 break;
6448 case GL_DEPTH:
6449 if (drawbuffer != 0)
6450 {
6451 return gl::error(GL_INVALID_VALUE);
6452 }
6453 break;
6454 default:
6455 return gl::error(GL_INVALID_ENUM);
6456 }
6457
6458 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006459 }
6460}
6461
6462void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6463{
6464 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6465 buffer, drawbuffer, depth, stencil);
6466
Geoff Langbfdea662014-07-23 14:16:32 -04006467 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006468
Geoff Langbfdea662014-07-23 14:16:32 -04006469 if (context)
6470 {
6471 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006472 {
Geoff Langbfdea662014-07-23 14:16:32 -04006473 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006474 }
Geoff Langbfdea662014-07-23 14:16:32 -04006475
6476 switch (buffer)
6477 {
6478 case GL_DEPTH_STENCIL:
6479 if (drawbuffer != 0)
6480 {
6481 return gl::error(GL_INVALID_VALUE);
6482 }
6483 break;
6484 default:
6485 return gl::error(GL_INVALID_ENUM);
6486 }
6487
6488 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006489 }
6490}
6491
6492const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6493{
6494 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6495
Geoff Langbfdea662014-07-23 14:16:32 -04006496 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006497
Geoff Langbfdea662014-07-23 14:16:32 -04006498 if (context)
6499 {
6500 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006501 {
Geoff Langbfdea662014-07-23 14:16:32 -04006502 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006503 }
Geoff Langbfdea662014-07-23 14:16:32 -04006504
6505 if (name != GL_EXTENSIONS)
6506 {
6507 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
6508 }
6509
6510 if (index >= context->getExtensionStringCount())
6511 {
6512 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
6513 }
6514
6515 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006516 }
6517
6518 return NULL;
6519}
6520
6521void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6522{
6523 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6524 readTarget, writeTarget, readOffset, writeOffset, size);
6525
Geoff Langbfdea662014-07-23 14:16:32 -04006526 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006527
Geoff Langbfdea662014-07-23 14:16:32 -04006528 if (context)
6529 {
6530 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006531 {
Geoff Langbfdea662014-07-23 14:16:32 -04006532 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006533 }
Geoff Langbfdea662014-07-23 14:16:32 -04006534
6535 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6536 {
6537 return gl::error(GL_INVALID_ENUM);
6538 }
6539
6540 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6541 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6542
6543 if (!readBuffer || !writeBuffer)
6544 {
6545 return gl::error(GL_INVALID_OPERATION);
6546 }
6547
Jamie Madillcfaaf722014-07-31 10:47:54 -04006548 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006549 if (readBuffer->isMapped() || writeBuffer->isMapped())
6550 {
6551 return gl::error(GL_INVALID_OPERATION);
6552 }
6553
6554 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6555 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6556 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6557 {
6558 return gl::error(GL_INVALID_VALUE);
6559 }
6560
6561 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6562 {
6563 return gl::error(GL_INVALID_VALUE);
6564 }
6565
Geoff Langbfdea662014-07-23 14:16:32 -04006566 // if size is zero, the copy is a successful no-op
6567 if (size > 0)
6568 {
6569 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6570 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006571 }
6572}
6573
6574void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6575{
6576 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6577 program, uniformCount, uniformNames, uniformIndices);
6578
Geoff Langbfdea662014-07-23 14:16:32 -04006579 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006580
Geoff Langbfdea662014-07-23 14:16:32 -04006581 if (context)
6582 {
6583 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006584 {
Geoff Langbfdea662014-07-23 14:16:32 -04006585 return gl::error(GL_INVALID_OPERATION);
6586 }
6587
6588 if (uniformCount < 0)
6589 {
6590 return gl::error(GL_INVALID_VALUE);
6591 }
6592
6593 gl::Program *programObject = context->getProgram(program);
6594
6595 if (!programObject)
6596 {
6597 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006598 {
6599 return gl::error(GL_INVALID_OPERATION);
6600 }
Geoff Langbfdea662014-07-23 14:16:32 -04006601 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006602 {
6603 return gl::error(GL_INVALID_VALUE);
6604 }
Geoff Langbfdea662014-07-23 14:16:32 -04006605 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006606
Geoff Langbfdea662014-07-23 14:16:32 -04006607 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6608 if (!programObject->isLinked() || !programBinary)
6609 {
6610 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006611 {
Geoff Langbfdea662014-07-23 14:16:32 -04006612 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006613 }
6614 }
Geoff Langbfdea662014-07-23 14:16:32 -04006615 else
6616 {
6617 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6618 {
6619 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6620 }
6621 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006622 }
6623}
6624
6625void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6626{
6627 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6628 program, uniformCount, uniformIndices, pname, params);
6629
Geoff Langbfdea662014-07-23 14:16:32 -04006630 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006631
Geoff Langbfdea662014-07-23 14:16:32 -04006632 if (context)
6633 {
6634 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006635 {
Geoff Langbfdea662014-07-23 14:16:32 -04006636 return gl::error(GL_INVALID_OPERATION);
6637 }
6638
6639 if (uniformCount < 0)
6640 {
6641 return gl::error(GL_INVALID_VALUE);
6642 }
6643
6644 gl::Program *programObject = context->getProgram(program);
6645
6646 if (!programObject)
6647 {
6648 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006649 {
6650 return gl::error(GL_INVALID_OPERATION);
6651 }
Geoff Langbfdea662014-07-23 14:16:32 -04006652 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006653 {
6654 return gl::error(GL_INVALID_VALUE);
6655 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006656 }
Geoff Langbfdea662014-07-23 14:16:32 -04006657
6658 switch (pname)
6659 {
6660 case GL_UNIFORM_TYPE:
6661 case GL_UNIFORM_SIZE:
6662 case GL_UNIFORM_NAME_LENGTH:
6663 case GL_UNIFORM_BLOCK_INDEX:
6664 case GL_UNIFORM_OFFSET:
6665 case GL_UNIFORM_ARRAY_STRIDE:
6666 case GL_UNIFORM_MATRIX_STRIDE:
6667 case GL_UNIFORM_IS_ROW_MAJOR:
6668 break;
6669 default:
6670 return gl::error(GL_INVALID_ENUM);
6671 }
6672
6673 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6674
6675 if (!programBinary && uniformCount > 0)
6676 {
6677 return gl::error(GL_INVALID_VALUE);
6678 }
6679
6680 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6681 {
6682 const GLuint index = uniformIndices[uniformId];
6683
6684 if (index >= (GLuint)programBinary->getActiveUniformCount())
6685 {
6686 return gl::error(GL_INVALID_VALUE);
6687 }
6688 }
6689
6690 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6691 {
6692 const GLuint index = uniformIndices[uniformId];
6693 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6694 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006695 }
6696}
6697
6698GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6699{
6700 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6701
Geoff Langbfdea662014-07-23 14:16:32 -04006702 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006703
Geoff Langbfdea662014-07-23 14:16:32 -04006704 if (context)
6705 {
6706 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006707 {
Geoff Langbfdea662014-07-23 14:16:32 -04006708 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
6709 }
6710
6711 gl::Program *programObject = context->getProgram(program);
6712
6713 if (!programObject)
6714 {
6715 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006716 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006717 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006718 }
Geoff Langbfdea662014-07-23 14:16:32 -04006719 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006720 {
Geoff Langbfdea662014-07-23 14:16:32 -04006721 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006722 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006723 }
Geoff Langbfdea662014-07-23 14:16:32 -04006724
6725 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6726 if (!programBinary)
6727 {
6728 return GL_INVALID_INDEX;
6729 }
6730
6731 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006732 }
6733
6734 return 0;
6735}
6736
6737void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6738{
6739 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6740 program, uniformBlockIndex, pname, params);
6741
Geoff Langbfdea662014-07-23 14:16:32 -04006742 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006743
Geoff Langbfdea662014-07-23 14:16:32 -04006744 if (context)
6745 {
6746 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006747 {
Geoff Langbfdea662014-07-23 14:16:32 -04006748 return gl::error(GL_INVALID_OPERATION);
6749 }
6750 gl::Program *programObject = context->getProgram(program);
6751
6752 if (!programObject)
6753 {
6754 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006755 {
6756 return gl::error(GL_INVALID_OPERATION);
6757 }
Geoff Langbfdea662014-07-23 14:16:32 -04006758 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006759 {
6760 return gl::error(GL_INVALID_VALUE);
6761 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006762 }
Geoff Langbfdea662014-07-23 14:16:32 -04006763
6764 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6765
6766 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6767 {
6768 return gl::error(GL_INVALID_VALUE);
6769 }
6770
6771 switch (pname)
6772 {
6773 case GL_UNIFORM_BLOCK_BINDING:
6774 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
6775 break;
6776
6777 case GL_UNIFORM_BLOCK_DATA_SIZE:
6778 case GL_UNIFORM_BLOCK_NAME_LENGTH:
6779 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
6780 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
6781 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
6782 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
6783 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
6784 break;
6785
6786 default:
6787 return gl::error(GL_INVALID_ENUM);
6788 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006789 }
6790}
6791
6792void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
6793{
6794 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
6795 program, uniformBlockIndex, bufSize, length, uniformBlockName);
6796
Geoff Langbfdea662014-07-23 14:16:32 -04006797 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006798
Geoff Langbfdea662014-07-23 14:16:32 -04006799 if (context)
6800 {
6801 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006802 {
Geoff Langbfdea662014-07-23 14:16:32 -04006803 return gl::error(GL_INVALID_OPERATION);
6804 }
6805
6806 gl::Program *programObject = context->getProgram(program);
6807
6808 if (!programObject)
6809 {
6810 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006811 {
6812 return gl::error(GL_INVALID_OPERATION);
6813 }
Geoff Langbfdea662014-07-23 14:16:32 -04006814 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006815 {
6816 return gl::error(GL_INVALID_VALUE);
6817 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006818 }
Geoff Langbfdea662014-07-23 14:16:32 -04006819
6820 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6821
6822 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6823 {
6824 return gl::error(GL_INVALID_VALUE);
6825 }
6826
6827 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006828 }
6829}
6830
6831void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
6832{
6833 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
6834 program, uniformBlockIndex, uniformBlockBinding);
6835
Geoff Langbfdea662014-07-23 14:16:32 -04006836 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006837
Geoff Langbfdea662014-07-23 14:16:32 -04006838 if (context)
6839 {
6840 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006841 {
Geoff Langbfdea662014-07-23 14:16:32 -04006842 return gl::error(GL_INVALID_OPERATION);
6843 }
6844
Geoff Lang3a61c322014-07-10 13:01:54 -04006845 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006846 {
6847 return gl::error(GL_INVALID_VALUE);
6848 }
6849
6850 gl::Program *programObject = context->getProgram(program);
6851
6852 if (!programObject)
6853 {
6854 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006855 {
6856 return gl::error(GL_INVALID_OPERATION);
6857 }
Geoff Langbfdea662014-07-23 14:16:32 -04006858 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006859 {
6860 return gl::error(GL_INVALID_VALUE);
6861 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006862 }
Geoff Langbfdea662014-07-23 14:16:32 -04006863
6864 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6865
6866 // if never linked, there won't be any uniform blocks
6867 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6868 {
6869 return gl::error(GL_INVALID_VALUE);
6870 }
6871
6872 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006873 }
6874}
6875
6876void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
6877{
6878 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
6879 mode, first, count, instanceCount);
6880
Geoff Langbfdea662014-07-23 14:16:32 -04006881 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006882
Geoff Langbfdea662014-07-23 14:16:32 -04006883 if (context)
6884 {
6885 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006886 {
Geoff Langbfdea662014-07-23 14:16:32 -04006887 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006888 }
Geoff Langbfdea662014-07-23 14:16:32 -04006889
6890 // glDrawArraysInstanced
6891 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006892 }
6893}
6894
6895void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
6896{
6897 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
6898 mode, count, type, indices, instanceCount);
6899
Geoff Langbfdea662014-07-23 14:16:32 -04006900 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006901
Geoff Langbfdea662014-07-23 14:16:32 -04006902 if (context)
6903 {
6904 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006905 {
Geoff Langbfdea662014-07-23 14:16:32 -04006906 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006907 }
Geoff Langbfdea662014-07-23 14:16:32 -04006908
6909 // glDrawElementsInstanced
6910 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006911 }
6912}
6913
6914GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
6915{
6916 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
6917
Geoff Langbfdea662014-07-23 14:16:32 -04006918 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006919
Geoff Langbfdea662014-07-23 14:16:32 -04006920 if (context)
6921 {
6922 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006923 {
Geoff Langbfdea662014-07-23 14:16:32 -04006924 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006925 }
Geoff Langbfdea662014-07-23 14:16:32 -04006926
6927 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
6928 {
6929 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
6930 }
6931
6932 if (flags != 0)
6933 {
6934 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
6935 }
6936
6937 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006938 }
6939
6940 return NULL;
6941}
6942
6943GLboolean __stdcall glIsSync(GLsync sync)
6944{
6945 EVENT("(GLsync sync = 0x%0.8p)", sync);
6946
Geoff Langbfdea662014-07-23 14:16:32 -04006947 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006948
Geoff Langbfdea662014-07-23 14:16:32 -04006949 if (context)
6950 {
6951 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006952 {
Geoff Langbfdea662014-07-23 14:16:32 -04006953 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006954 }
Geoff Langbfdea662014-07-23 14:16:32 -04006955
6956 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006957 }
6958
6959 return GL_FALSE;
6960}
6961
6962void __stdcall glDeleteSync(GLsync sync)
6963{
6964 EVENT("(GLsync sync = 0x%0.8p)", sync);
6965
Geoff Langbfdea662014-07-23 14:16:32 -04006966 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006967
Geoff Langbfdea662014-07-23 14:16:32 -04006968 if (context)
6969 {
6970 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006971 {
Geoff Langbfdea662014-07-23 14:16:32 -04006972 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006973 }
Geoff Langbfdea662014-07-23 14:16:32 -04006974
6975 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
6976 {
6977 return gl::error(GL_INVALID_VALUE);
6978 }
6979
6980 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006981 }
6982}
6983
6984GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6985{
6986 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
6987 sync, flags, timeout);
6988
Geoff Langbfdea662014-07-23 14:16:32 -04006989 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006990
Geoff Langbfdea662014-07-23 14:16:32 -04006991 if (context)
6992 {
6993 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006994 {
Geoff Langbfdea662014-07-23 14:16:32 -04006995 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006996 }
Geoff Langbfdea662014-07-23 14:16:32 -04006997
6998 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
6999 {
7000 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7001 }
7002
7003 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7004
7005 if (!fenceSync)
7006 {
7007 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7008 }
7009
7010 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007011 }
7012
7013 return GL_FALSE;
7014}
7015
7016void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7017{
7018 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7019 sync, flags, timeout);
7020
Geoff Langbfdea662014-07-23 14:16:32 -04007021 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007022
Geoff Langbfdea662014-07-23 14:16:32 -04007023 if (context)
7024 {
7025 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007026 {
Geoff Langbfdea662014-07-23 14:16:32 -04007027 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007028 }
Geoff Langbfdea662014-07-23 14:16:32 -04007029
7030 if (flags != 0)
7031 {
7032 return gl::error(GL_INVALID_VALUE);
7033 }
7034
7035 if (timeout != GL_TIMEOUT_IGNORED)
7036 {
7037 return gl::error(GL_INVALID_VALUE);
7038 }
7039
7040 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7041
7042 if (!fenceSync)
7043 {
7044 return gl::error(GL_INVALID_VALUE);
7045 }
7046
7047 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007048 }
7049}
7050
7051void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7052{
7053 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7054 pname, params);
7055
Geoff Langbfdea662014-07-23 14:16:32 -04007056 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007057
Geoff Langbfdea662014-07-23 14:16:32 -04007058 if (context)
7059 {
7060 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007061 {
Geoff Langbfdea662014-07-23 14:16:32 -04007062 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007063 }
Geoff Langbfdea662014-07-23 14:16:32 -04007064
7065 GLenum nativeType;
7066 unsigned int numParams = 0;
7067 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7068 {
7069 return;
7070 }
7071
7072 if (nativeType == GL_INT_64_ANGLEX)
7073 {
7074 context->getInteger64v(pname, params);
7075 }
7076 else
7077 {
7078 CastStateValues(context, nativeType, pname, numParams, params);
7079 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007080 }
7081}
7082
7083void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7084{
7085 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7086 sync, pname, bufSize, length, values);
7087
Geoff Langbfdea662014-07-23 14:16:32 -04007088 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007089
Geoff Langbfdea662014-07-23 14:16:32 -04007090 if (context)
7091 {
7092 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007093 {
Geoff Langbfdea662014-07-23 14:16:32 -04007094 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007095 }
Geoff Langbfdea662014-07-23 14:16:32 -04007096
7097 if (bufSize < 0)
7098 {
7099 return gl::error(GL_INVALID_VALUE);
7100 }
7101
7102 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7103
7104 if (!fenceSync)
7105 {
7106 return gl::error(GL_INVALID_VALUE);
7107 }
7108
7109 switch (pname)
7110 {
7111 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7112 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7113 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7114 case GL_SYNC_FLAGS: values[0] = 0; break;
7115
7116 default:
7117 return gl::error(GL_INVALID_ENUM);
7118 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007119 }
7120}
7121
7122void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7123{
7124 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7125 target, index, data);
7126
Geoff Langbfdea662014-07-23 14:16:32 -04007127 gl::Context *context = gl::getNonLostContext();
7128
7129 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007130 {
Geoff Langbfdea662014-07-23 14:16:32 -04007131 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007132 {
Geoff Langbfdea662014-07-23 14:16:32 -04007133 return gl::error(GL_INVALID_OPERATION);
7134 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007135
Geoff Lang3a61c322014-07-10 13:01:54 -04007136 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007137 switch (target)
7138 {
7139 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7140 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7141 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7142 if (index >= context->getMaxTransformFeedbackBufferBindings())
7143 return gl::error(GL_INVALID_VALUE);
7144 break;
7145 case GL_UNIFORM_BUFFER_START:
7146 case GL_UNIFORM_BUFFER_SIZE:
7147 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007148 if (index >= caps.maxUniformBufferBindings)
7149 {
Geoff Langbfdea662014-07-23 14:16:32 -04007150 return gl::error(GL_INVALID_VALUE);
Geoff Lang3a61c322014-07-10 13:01:54 -04007151 }
Geoff Langbfdea662014-07-23 14:16:32 -04007152 break;
7153 default:
7154 return gl::error(GL_INVALID_ENUM);
7155 }
7156
7157 if (!(context->getIndexedInteger64v(target, index, data)))
7158 {
7159 GLenum nativeType;
7160 unsigned int numParams = 0;
7161 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04007162 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04007163
Geoff Langbfdea662014-07-23 14:16:32 -04007164 if (numParams == 0)
7165 return; // it is known that pname is valid, but there are no parameters to return
7166
7167 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007168 {
Geoff Langbfdea662014-07-23 14:16:32 -04007169 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007170
Geoff Langbfdea662014-07-23 14:16:32 -04007171 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007172
Geoff Langbfdea662014-07-23 14:16:32 -04007173 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007174 {
Geoff Langbfdea662014-07-23 14:16:32 -04007175 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007176 }
Geoff Langbfdea662014-07-23 14:16:32 -04007177
7178 delete [] intParams;
7179 }
7180 else
7181 {
7182 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007183 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007184 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007185 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007186}
7187
7188void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7189{
7190 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7191 target, pname, params);
7192
Geoff Langbfdea662014-07-23 14:16:32 -04007193 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007194
Geoff Langbfdea662014-07-23 14:16:32 -04007195 if (context)
7196 {
7197 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007198 {
Geoff Langbfdea662014-07-23 14:16:32 -04007199 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007200 }
Geoff Langbfdea662014-07-23 14:16:32 -04007201
7202 if (!gl::ValidBufferTarget(context, target))
7203 {
7204 return gl::error(GL_INVALID_ENUM);
7205 }
7206
7207 if (!gl::ValidBufferParameter(context, pname))
7208 {
7209 return gl::error(GL_INVALID_ENUM);
7210 }
7211
7212 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7213
7214 if (!buffer)
7215 {
7216 // A null buffer means that "0" is bound to the requested buffer target
7217 return gl::error(GL_INVALID_OPERATION);
7218 }
7219
7220 switch (pname)
7221 {
7222 case GL_BUFFER_USAGE:
7223 *params = static_cast<GLint64>(buffer->getUsage());
7224 break;
7225 case GL_BUFFER_SIZE:
7226 *params = buffer->getSize();
7227 break;
7228 case GL_BUFFER_ACCESS_FLAGS:
7229 *params = static_cast<GLint64>(buffer->getAccessFlags());
7230 break;
7231 case GL_BUFFER_MAPPED:
7232 *params = static_cast<GLint64>(buffer->isMapped());
7233 break;
7234 case GL_BUFFER_MAP_OFFSET:
7235 *params = buffer->getMapOffset();
7236 break;
7237 case GL_BUFFER_MAP_LENGTH:
7238 *params = buffer->getMapLength();
7239 break;
7240 default: UNREACHABLE(); break;
7241 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007242 }
7243}
7244
7245void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7246{
7247 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7248
Geoff Langbfdea662014-07-23 14:16:32 -04007249 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007250
Geoff Langbfdea662014-07-23 14:16:32 -04007251 if (context)
7252 {
7253 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007254 {
Geoff Langbfdea662014-07-23 14:16:32 -04007255 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007256 }
Geoff Langbfdea662014-07-23 14:16:32 -04007257
7258 if (count < 0)
7259 {
7260 return gl::error(GL_INVALID_VALUE);
7261 }
7262
7263 for (int i = 0; i < count; i++)
7264 {
7265 samplers[i] = context->createSampler();
7266 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007267 }
7268}
7269
7270void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7271{
7272 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7273
Geoff Langbfdea662014-07-23 14:16:32 -04007274 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007275
Geoff Langbfdea662014-07-23 14:16:32 -04007276 if (context)
7277 {
7278 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007279 {
Geoff Langbfdea662014-07-23 14:16:32 -04007280 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007281 }
Geoff Langbfdea662014-07-23 14:16:32 -04007282
7283 if (count < 0)
7284 {
7285 return gl::error(GL_INVALID_VALUE);
7286 }
7287
7288 for (int i = 0; i < count; i++)
7289 {
7290 context->deleteSampler(samplers[i]);
7291 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007292 }
7293}
7294
7295GLboolean __stdcall glIsSampler(GLuint sampler)
7296{
7297 EVENT("(GLuint sampler = %u)", sampler);
7298
Geoff Langbfdea662014-07-23 14:16:32 -04007299 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007300
Geoff Langbfdea662014-07-23 14:16:32 -04007301 if (context)
7302 {
7303 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007304 {
Geoff Langbfdea662014-07-23 14:16:32 -04007305 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007306 }
Geoff Langbfdea662014-07-23 14:16:32 -04007307
7308 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007309 }
7310
7311 return GL_FALSE;
7312}
7313
7314void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7315{
7316 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7317
Geoff Langbfdea662014-07-23 14:16:32 -04007318 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007319
Geoff Langbfdea662014-07-23 14:16:32 -04007320 if (context)
7321 {
7322 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007323 {
Geoff Langbfdea662014-07-23 14:16:32 -04007324 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007325 }
Geoff Langbfdea662014-07-23 14:16:32 -04007326
7327 if (sampler != 0 && !context->isSampler(sampler))
7328 {
7329 return gl::error(GL_INVALID_OPERATION);
7330 }
7331
Geoff Lang3a61c322014-07-10 13:01:54 -04007332 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007333 {
7334 return gl::error(GL_INVALID_VALUE);
7335 }
7336
7337 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007338 }
7339}
7340
7341void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7342{
7343 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7344
Geoff Langbfdea662014-07-23 14:16:32 -04007345 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007346
Geoff Langbfdea662014-07-23 14:16:32 -04007347 if (context)
7348 {
7349 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007350 {
Geoff Langbfdea662014-07-23 14:16:32 -04007351 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007352 }
Geoff Langbfdea662014-07-23 14:16:32 -04007353
7354 if (!gl::ValidateSamplerObjectParameter(pname))
7355 {
7356 return;
7357 }
7358
7359 if (!gl::ValidateTexParamParameters(context, pname, param))
7360 {
7361 return;
7362 }
7363
7364 if (!context->isSampler(sampler))
7365 {
7366 return gl::error(GL_INVALID_OPERATION);
7367 }
7368
7369 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007370 }
7371}
7372
7373void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7374{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007375 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007376}
7377
7378void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7379{
7380 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7381
Geoff Langbfdea662014-07-23 14:16:32 -04007382 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007383
Geoff Langbfdea662014-07-23 14:16:32 -04007384 if (context)
7385 {
7386 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007387 {
Geoff Langbfdea662014-07-23 14:16:32 -04007388 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007389 }
Geoff Langbfdea662014-07-23 14:16:32 -04007390
7391 if (!gl::ValidateSamplerObjectParameter(pname))
7392 {
7393 return;
7394 }
7395
7396 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7397 {
7398 return;
7399 }
7400
7401 if (!context->isSampler(sampler))
7402 {
7403 return gl::error(GL_INVALID_OPERATION);
7404 }
7405
7406 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007407 }
7408}
7409
7410void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7411{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007412 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007413}
7414
7415void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7416{
7417 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7418
Geoff Langbfdea662014-07-23 14:16:32 -04007419 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007420
Geoff Langbfdea662014-07-23 14:16:32 -04007421 if (context)
7422 {
7423 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007424 {
Geoff Langbfdea662014-07-23 14:16:32 -04007425 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007426 }
Geoff Langbfdea662014-07-23 14:16:32 -04007427
7428 if (!gl::ValidateSamplerObjectParameter(pname))
7429 {
7430 return;
7431 }
7432
7433 if (!context->isSampler(sampler))
7434 {
7435 return gl::error(GL_INVALID_OPERATION);
7436 }
7437
7438 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007439 }
7440}
7441
7442void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7443{
7444 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7445
Geoff Langbfdea662014-07-23 14:16:32 -04007446 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007447
Geoff Langbfdea662014-07-23 14:16:32 -04007448 if (context)
7449 {
7450 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007451 {
Geoff Langbfdea662014-07-23 14:16:32 -04007452 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007453 }
Geoff Langbfdea662014-07-23 14:16:32 -04007454
7455 if (!gl::ValidateSamplerObjectParameter(pname))
7456 {
7457 return;
7458 }
7459
7460 if (!context->isSampler(sampler))
7461 {
7462 return gl::error(GL_INVALID_OPERATION);
7463 }
7464
7465 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007466 }
7467}
7468
7469void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7470{
7471 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7472
Geoff Langbfdea662014-07-23 14:16:32 -04007473 if (index >= gl::MAX_VERTEX_ATTRIBS)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007474 {
Geoff Langbfdea662014-07-23 14:16:32 -04007475 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007476 }
Geoff Langbfdea662014-07-23 14:16:32 -04007477
7478 gl::Context *context = gl::getNonLostContext();
7479
7480 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007481 {
Geoff Langbfdea662014-07-23 14:16:32 -04007482 if (context->getClientVersion() < 3)
7483 {
7484 return gl::error(GL_INVALID_OPERATION);
7485 }
7486
7487 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007488 }
7489}
7490
7491void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7492{
7493 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7494
Geoff Langbfdea662014-07-23 14:16:32 -04007495 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007496
Geoff Langbfdea662014-07-23 14:16:32 -04007497 if (context)
7498 {
7499 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007500 {
Geoff Langbfdea662014-07-23 14:16:32 -04007501 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007502 }
Geoff Langbfdea662014-07-23 14:16:32 -04007503
7504 switch (target)
7505 {
7506 case GL_TRANSFORM_FEEDBACK:
7507 {
7508 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7509 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7510 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7511 {
7512 return gl::error(GL_INVALID_OPERATION);
7513 }
7514
7515 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7516 if (context->getTransformFeedback(id) == NULL)
7517 {
7518 return gl::error(GL_INVALID_OPERATION);
7519 }
7520
7521 context->bindTransformFeedback(id);
7522 }
7523 break;
7524
7525 default:
7526 return gl::error(GL_INVALID_ENUM);
7527 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007528 }
7529}
7530
7531void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7532{
7533 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7534
Geoff Langbfdea662014-07-23 14:16:32 -04007535 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007536
Geoff Langbfdea662014-07-23 14:16:32 -04007537 if (context)
7538 {
7539 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007540 {
Geoff Langbfdea662014-07-23 14:16:32 -04007541 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007542 }
Geoff Langbfdea662014-07-23 14:16:32 -04007543
7544 for (int i = 0; i < n; i++)
7545 {
7546 context->deleteTransformFeedback(ids[i]);
7547 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007548 }
7549}
7550
7551void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7552{
7553 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7554
Geoff Langbfdea662014-07-23 14:16:32 -04007555 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007556
Geoff Langbfdea662014-07-23 14:16:32 -04007557 if (context)
7558 {
7559 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007560 {
Geoff Langbfdea662014-07-23 14:16:32 -04007561 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007562 }
Geoff Langbfdea662014-07-23 14:16:32 -04007563
7564 for (int i = 0; i < n; i++)
7565 {
7566 ids[i] = context->createTransformFeedback();
7567 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007568 }
7569}
7570
7571GLboolean __stdcall glIsTransformFeedback(GLuint id)
7572{
7573 EVENT("(GLuint id = %u)", id);
7574
Geoff Langbfdea662014-07-23 14:16:32 -04007575 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007576
Geoff Langbfdea662014-07-23 14:16:32 -04007577 if (context)
7578 {
7579 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007580 {
Geoff Langbfdea662014-07-23 14:16:32 -04007581 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007582 }
Geoff Langbfdea662014-07-23 14:16:32 -04007583
7584 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007585 }
7586
7587 return GL_FALSE;
7588}
7589
7590void __stdcall glPauseTransformFeedback(void)
7591{
7592 EVENT("(void)");
7593
Geoff Langbfdea662014-07-23 14:16:32 -04007594 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007595
Geoff Langbfdea662014-07-23 14:16:32 -04007596 if (context)
7597 {
7598 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007599 {
Geoff Langbfdea662014-07-23 14:16:32 -04007600 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007601 }
Geoff Langbfdea662014-07-23 14:16:32 -04007602
7603 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7604 ASSERT(transformFeedback != NULL);
7605
7606 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7607 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7608 {
7609 return gl::error(GL_INVALID_OPERATION);
7610 }
7611
7612 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007613 }
7614}
7615
7616void __stdcall glResumeTransformFeedback(void)
7617{
7618 EVENT("(void)");
7619
Geoff Langbfdea662014-07-23 14:16:32 -04007620 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007621
Geoff Langbfdea662014-07-23 14:16:32 -04007622 if (context)
7623 {
7624 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007625 {
Geoff Langbfdea662014-07-23 14:16:32 -04007626 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007627 }
Geoff Langbfdea662014-07-23 14:16:32 -04007628
7629 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7630 ASSERT(transformFeedback != NULL);
7631
7632 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7633 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7634 {
7635 return gl::error(GL_INVALID_OPERATION);
7636 }
7637
7638 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007639 }
7640}
7641
7642void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7643{
7644 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7645 program, bufSize, length, binaryFormat, binary);
7646
Geoff Langbfdea662014-07-23 14:16:32 -04007647 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007648
Geoff Langbfdea662014-07-23 14:16:32 -04007649 if (context)
7650 {
7651 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007652 {
Geoff Langbfdea662014-07-23 14:16:32 -04007653 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007654 }
Geoff Langbfdea662014-07-23 14:16:32 -04007655
7656 // glGetProgramBinary
7657 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007658 }
7659}
7660
7661void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7662{
7663 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7664 program, binaryFormat, binary, length);
7665
Geoff Langbfdea662014-07-23 14:16:32 -04007666 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007667
Geoff Langbfdea662014-07-23 14:16:32 -04007668 if (context)
7669 {
7670 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007671 {
Geoff Langbfdea662014-07-23 14:16:32 -04007672 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007673 }
Geoff Langbfdea662014-07-23 14:16:32 -04007674
7675 // glProgramBinary
7676 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007677 }
7678}
7679
7680void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7681{
7682 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7683 program, pname, value);
7684
Geoff Langbfdea662014-07-23 14:16:32 -04007685 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007686
Geoff Langbfdea662014-07-23 14:16:32 -04007687 if (context)
7688 {
7689 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007690 {
Geoff Langbfdea662014-07-23 14:16:32 -04007691 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007692 }
Geoff Langbfdea662014-07-23 14:16:32 -04007693
7694 // glProgramParameteri
7695 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007696 }
7697}
7698
7699void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7700{
7701 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7702 target, numAttachments, attachments);
7703
Geoff Langbfdea662014-07-23 14:16:32 -04007704 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007705
Geoff Langbfdea662014-07-23 14:16:32 -04007706 if (context)
7707 {
7708 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007709 {
Geoff Langbfdea662014-07-23 14:16:32 -04007710 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007711 }
Geoff Langbfdea662014-07-23 14:16:32 -04007712
7713 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7714 {
7715 return;
7716 }
7717
7718 GLuint maxDimension = context->getCaps().maxRenderbufferSize;
7719 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007720 }
7721}
7722
7723void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
7724{
7725 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
7726 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7727 target, numAttachments, attachments, x, y, width, height);
7728
Geoff Langbfdea662014-07-23 14:16:32 -04007729 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007730
Geoff Langbfdea662014-07-23 14:16:32 -04007731 if (context)
7732 {
7733 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007734 {
Geoff Langbfdea662014-07-23 14:16:32 -04007735 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007736 }
Geoff Langbfdea662014-07-23 14:16:32 -04007737
7738 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7739 {
7740 return;
7741 }
7742
7743 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007744 }
7745}
7746
7747void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7748{
7749 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7750 target, levels, internalformat, width, height);
7751
Geoff Langbfdea662014-07-23 14:16:32 -04007752 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007753
Geoff Langbfdea662014-07-23 14:16:32 -04007754 if (context)
7755 {
7756 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007757 {
Geoff Langbfdea662014-07-23 14:16:32 -04007758 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007759 }
Geoff Langbfdea662014-07-23 14:16:32 -04007760
7761 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
7762 {
7763 return;
7764 }
7765
7766 switch (target)
7767 {
7768 case GL_TEXTURE_2D:
7769 {
7770 gl::Texture2D *texture2d = context->getTexture2D();
7771 texture2d->storage(levels, internalformat, width, height);
7772 }
7773 break;
7774
7775 case GL_TEXTURE_CUBE_MAP:
7776 {
7777 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7778 textureCube->storage(levels, internalformat, width);
7779 }
7780 break;
7781
7782 default:
7783 return gl::error(GL_INVALID_ENUM);
7784 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007785 }
7786}
7787
7788void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
7789{
7790 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
7791 "GLsizei height = %d, GLsizei depth = %d)",
7792 target, levels, internalformat, width, height, depth);
7793
Geoff Langbfdea662014-07-23 14:16:32 -04007794 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007795
Geoff Langbfdea662014-07-23 14:16:32 -04007796 if (context)
7797 {
7798 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007799 {
Geoff Langbfdea662014-07-23 14:16:32 -04007800 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00007801 }
Geoff Langbfdea662014-07-23 14:16:32 -04007802
7803 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
7804 {
7805 return;
7806 }
7807
7808 switch (target)
7809 {
7810 case GL_TEXTURE_3D:
7811 {
7812 gl::Texture3D *texture3d = context->getTexture3D();
7813 texture3d->storage(levels, internalformat, width, height, depth);
7814 }
7815 break;
7816
7817 case GL_TEXTURE_2D_ARRAY:
7818 {
7819 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
7820 texture2darray->storage(levels, internalformat, width, height, depth);
7821 }
7822 break;
7823
7824 default:
7825 UNREACHABLE();
7826 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007827 }
7828}
7829
7830void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
7831{
7832 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
7833 "GLint* params = 0x%0.8p)",
7834 target, internalformat, pname, bufSize, params);
7835
Geoff Langbfdea662014-07-23 14:16:32 -04007836 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007837
Geoff Langbfdea662014-07-23 14:16:32 -04007838 if (context)
7839 {
7840 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007841 {
Geoff Langbfdea662014-07-23 14:16:32 -04007842 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007843 }
Geoff Langbfdea662014-07-23 14:16:32 -04007844
7845 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7846 if (!formatCaps.renderable)
7847 {
7848 return gl::error(GL_INVALID_ENUM);
7849 }
7850
7851 if (target != GL_RENDERBUFFER)
7852 {
7853 return gl::error(GL_INVALID_ENUM);
7854 }
7855
7856 if (bufSize < 0)
7857 {
7858 return gl::error(GL_INVALID_VALUE);
7859 }
7860
7861 switch (pname)
7862 {
7863 case GL_NUM_SAMPLE_COUNTS:
7864 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04007865 {
7866 *params = formatCaps.sampleCounts.size();
7867 }
Geoff Langbfdea662014-07-23 14:16:32 -04007868 break;
7869 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04007870 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04007871 break;
7872 default:
7873 return gl::error(GL_INVALID_ENUM);
7874 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007875 }
7876}
7877
7878// Extension functions
7879
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007880void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
7881 GLbitfield mask, GLenum filter)
7882{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007883 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007884 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
7885 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
7886 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
7887
Geoff Langbfdea662014-07-23 14:16:32 -04007888 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007889
Geoff Langbfdea662014-07-23 14:16:32 -04007890 if (context)
7891 {
7892 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
7893 dstX0, dstY0, dstX1, dstY1, mask, filter,
7894 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007895 {
Geoff Langbfdea662014-07-23 14:16:32 -04007896 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007897 }
Geoff Langbfdea662014-07-23 14:16:32 -04007898
7899 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
7900 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007901 }
7902}
7903
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007904void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
7905 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007906{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007907 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007908 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007909 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007910 target, level, internalformat, width, height, depth, border, format, type, pixels);
7911
Geoff Langbfdea662014-07-23 14:16:32 -04007912 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007913}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00007914
Geoff Langbfdea662014-07-23 14:16:32 -04007915void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007916 GLenum *binaryFormat, void *binary)
7917{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00007918 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 +00007919 program, bufSize, length, binaryFormat, binary);
7920
Geoff Langbfdea662014-07-23 14:16:32 -04007921 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007922
Geoff Langbfdea662014-07-23 14:16:32 -04007923 if (context)
7924 {
7925 gl::Program *programObject = context->getProgram(program);
7926
7927 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007928 {
Geoff Langbfdea662014-07-23 14:16:32 -04007929 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007930 }
Geoff Langbfdea662014-07-23 14:16:32 -04007931
7932 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7933
7934 if (!programBinary)
7935 {
7936 return gl::error(GL_INVALID_OPERATION);
7937 }
7938
Geoff Lang900013c2014-07-07 11:32:19 -04007939 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04007940 {
7941 return gl::error(GL_INVALID_OPERATION);
7942 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007943 }
7944}
7945
7946void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
7947 const void *binary, GLint length)
7948{
7949 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
7950 program, binaryFormat, binary, length);
7951
Geoff Langbfdea662014-07-23 14:16:32 -04007952 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007953
Geoff Langbfdea662014-07-23 14:16:32 -04007954 if (context)
7955 {
Geoff Lang900013c2014-07-07 11:32:19 -04007956 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
7957 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007958 {
Geoff Langbfdea662014-07-23 14:16:32 -04007959 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007960 }
Geoff Langbfdea662014-07-23 14:16:32 -04007961
7962 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04007963 if (!programObject)
7964 {
7965 return gl::error(GL_INVALID_OPERATION);
7966 }
7967
Geoff Lang900013c2014-07-07 11:32:19 -04007968 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007969 }
7970}
7971
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007972void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
7973{
7974 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
7975
Geoff Langbfdea662014-07-23 14:16:32 -04007976 gl::Context *context = gl::getNonLostContext();
7977
7978 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007979 {
Geoff Langbfdea662014-07-23 14:16:32 -04007980 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007981 {
Geoff Langbfdea662014-07-23 14:16:32 -04007982 return gl::error(GL_INVALID_VALUE);
7983 }
7984
7985 if (context->getState().getDrawFramebuffer()->id() == 0)
7986 {
7987 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007988 {
Geoff Langbfdea662014-07-23 14:16:32 -04007989 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007990 }
7991
Geoff Langbfdea662014-07-23 14:16:32 -04007992 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007993 {
Geoff Langbfdea662014-07-23 14:16:32 -04007994 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00007995 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007996 }
Geoff Langbfdea662014-07-23 14:16:32 -04007997 else
7998 {
7999 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8000 {
8001 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8002 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8003 {
8004 return gl::error(GL_INVALID_OPERATION);
8005 }
8006 }
8007 }
8008
8009 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8010
8011 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8012 {
8013 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8014 }
8015
8016 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8017 {
8018 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8019 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008020 }
8021}
8022
Shannon Woodsb3801742014-03-27 14:59:19 -04008023void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8024{
8025 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8026
Geoff Langbfdea662014-07-23 14:16:32 -04008027 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008028
Geoff Langbfdea662014-07-23 14:16:32 -04008029 if (context)
8030 {
8031 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008032 {
Geoff Langbfdea662014-07-23 14:16:32 -04008033 return gl::error(GL_INVALID_ENUM);
Shannon Woodsb3801742014-03-27 14:59:19 -04008034 }
Geoff Langbfdea662014-07-23 14:16:32 -04008035
8036 if (pname != GL_BUFFER_MAP_POINTER)
8037 {
8038 return gl::error(GL_INVALID_ENUM);
8039 }
8040
8041 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8042
8043 if (!buffer || !buffer->isMapped())
8044 {
8045 *params = NULL;
8046 }
8047 else
8048 {
8049 *params = buffer->getMapPointer();
8050 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008051 }
8052}
8053
8054void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8055{
8056 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8057
Geoff Langbfdea662014-07-23 14:16:32 -04008058 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008059
Geoff Langbfdea662014-07-23 14:16:32 -04008060 if (context)
8061 {
8062 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008063 {
Geoff Langbfdea662014-07-23 14:16:32 -04008064 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woodsb3801742014-03-27 14:59:19 -04008065 }
Geoff Langbfdea662014-07-23 14:16:32 -04008066
8067 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8068
8069 if (buffer == NULL)
8070 {
8071 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8072 }
8073
8074 if (access != GL_WRITE_ONLY_OES)
8075 {
8076 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
8077 }
8078
8079 if (buffer->isMapped())
8080 {
8081 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8082 }
8083
8084 return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
Shannon Woodsb3801742014-03-27 14:59:19 -04008085 }
8086
8087 return NULL;
8088}
8089
8090GLboolean __stdcall glUnmapBufferOES(GLenum target)
8091{
8092 EVENT("(GLenum target = 0x%X)", target);
8093
Geoff Langbfdea662014-07-23 14:16:32 -04008094 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008095
Geoff Langbfdea662014-07-23 14:16:32 -04008096 if (context)
8097 {
8098 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008099 {
Geoff Langbfdea662014-07-23 14:16:32 -04008100 return gl::error(GL_INVALID_ENUM, GL_FALSE);
Shannon Woodsb3801742014-03-27 14:59:19 -04008101 }
Geoff Langbfdea662014-07-23 14:16:32 -04008102
8103 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8104
8105 if (buffer == NULL || !buffer->isMapped())
8106 {
8107 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8108 }
8109
8110 // TODO: detect if we had corruption. if so, throw an error and return false.
8111
8112 buffer->unmap();
8113
8114 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008115 }
8116
8117 return GL_FALSE;
8118}
8119
Shannon Woods916e7692014-03-27 16:58:22 -04008120void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8121{
8122 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8123 target, offset, length, access);
8124
Geoff Langbfdea662014-07-23 14:16:32 -04008125 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008126
Geoff Langbfdea662014-07-23 14:16:32 -04008127 if (context)
8128 {
8129 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008130 {
Geoff Langbfdea662014-07-23 14:16:32 -04008131 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woods916e7692014-03-27 16:58:22 -04008132 }
Geoff Langbfdea662014-07-23 14:16:32 -04008133
8134 if (offset < 0 || length < 0)
8135 {
8136 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8137 }
8138
8139 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8140
8141 if (buffer == NULL)
8142 {
8143 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8144 }
8145
8146 // Check for buffer overflow
8147 size_t offsetSize = static_cast<size_t>(offset);
8148 size_t lengthSize = static_cast<size_t>(length);
8149
8150 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8151 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8152 {
8153 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8154 }
8155
8156 // Check for invalid bits in the mask
8157 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8158 GL_MAP_WRITE_BIT |
8159 GL_MAP_INVALIDATE_RANGE_BIT |
8160 GL_MAP_INVALIDATE_BUFFER_BIT |
8161 GL_MAP_FLUSH_EXPLICIT_BIT |
8162 GL_MAP_UNSYNCHRONIZED_BIT;
8163
8164 if (access & ~(allAccessBits))
8165 {
8166 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8167 }
8168
8169 if (length == 0 || buffer->isMapped())
8170 {
8171 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8172 }
8173
8174 // Check for invalid bit combinations
8175 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8176 {
8177 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8178 }
8179
8180 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8181 GL_MAP_INVALIDATE_BUFFER_BIT |
8182 GL_MAP_UNSYNCHRONIZED_BIT;
8183
8184 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8185 {
8186 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8187 }
8188
8189 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8190 {
8191 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8192 }
8193
8194 return buffer->mapRange(offset, length, access);
Shannon Woods916e7692014-03-27 16:58:22 -04008195 }
8196
8197 return NULL;
8198}
8199
8200void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8201{
8202 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8203
Geoff Langbfdea662014-07-23 14:16:32 -04008204 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008205
Geoff Langbfdea662014-07-23 14:16:32 -04008206 if (context)
8207 {
8208 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008209 {
Geoff Langbfdea662014-07-23 14:16:32 -04008210 return gl::error(GL_INVALID_VALUE);
Shannon Woods916e7692014-03-27 16:58:22 -04008211 }
Geoff Langbfdea662014-07-23 14:16:32 -04008212
8213 if (!gl::ValidBufferTarget(context, target))
8214 {
8215 return gl::error(GL_INVALID_ENUM);
8216 }
8217
8218 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8219
8220 if (buffer == NULL)
8221 {
8222 return gl::error(GL_INVALID_OPERATION);
8223 }
8224
8225 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8226 {
8227 return gl::error(GL_INVALID_OPERATION);
8228 }
8229
8230 // Check for buffer overflow
8231 size_t offsetSize = static_cast<size_t>(offset);
8232 size_t lengthSize = static_cast<size_t>(length);
8233
8234 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8235 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8236 {
8237 return gl::error(GL_INVALID_VALUE);
8238 }
8239
8240 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008241 }
8242}
8243
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008244__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8245{
8246 struct Extension
8247 {
8248 const char *name;
8249 __eglMustCastToProperFunctionPointerType address;
8250 };
8251
8252 static const Extension glExtensions[] =
8253 {
8254 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008255 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008256 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008257 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8258 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8259 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8260 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8261 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8262 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8263 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008264 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008265 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008266 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8267 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8268 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8269 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008270 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8271 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8272 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8273 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8274 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8275 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8276 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008277 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008278 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8279 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8280 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008281 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008282 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8283 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8284 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008285 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8286 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8287 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008288
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008289 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008290 {
8291 if (strcmp(procname, glExtensions[ext].name) == 0)
8292 {
8293 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8294 }
8295 }
8296
8297 return NULL;
8298}
8299
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008300// Non-public functions used by EGL
8301
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008302bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008303{
8304 EVENT("(egl::Surface* surface = 0x%0.8p)",
8305 surface);
8306
Geoff Langbfdea662014-07-23 14:16:32 -04008307 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008308
Geoff Langbfdea662014-07-23 14:16:32 -04008309 if (context)
8310 {
8311 gl::Texture2D *textureObject = context->getTexture2D();
8312 ASSERT(textureObject != NULL);
8313
8314 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008315 {
Geoff Langbfdea662014-07-23 14:16:32 -04008316 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008317 }
Geoff Langbfdea662014-07-23 14:16:32 -04008318
8319 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008320 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008321
8322 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008323}
8324
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008325}