blob: d1bfadcb843740c220c011b0f2ce761fc575df1d [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:
Geoff Lang05881a02014-07-10 14:05:30 -04005639 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5640 {
Geoff Langbfdea662014-07-23 14:16:32 -04005641 return gl::error(GL_INVALID_VALUE);
Geoff Lang05881a02014-07-10 14:05:30 -04005642 }
Geoff Langbfdea662014-07-23 14:16:32 -04005643 break;
5644 case GL_UNIFORM_BUFFER_START:
5645 case GL_UNIFORM_BUFFER_SIZE:
5646 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005647 if (index >= caps.maxCombinedUniformBlocks)
5648 {
Geoff Langbfdea662014-07-23 14:16:32 -04005649 return gl::error(GL_INVALID_VALUE);
Geoff Lang3a61c322014-07-10 13:01:54 -04005650 }
Geoff Langbfdea662014-07-23 14:16:32 -04005651 break;
5652 default:
5653 return gl::error(GL_INVALID_ENUM);
5654 }
5655
5656 if (!(context->getIndexedIntegerv(target, index, data)))
5657 {
5658 GLenum nativeType;
5659 unsigned int numParams = 0;
5660 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04005661 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04005662
Geoff Langbfdea662014-07-23 14:16:32 -04005663 if (numParams == 0)
5664 return; // it is known that pname is valid, but there are no parameters to return
5665
5666 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005667 {
Geoff Langbfdea662014-07-23 14:16:32 -04005668 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5669 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5670 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005671
Geoff Langbfdea662014-07-23 14:16:32 -04005672 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005673
Geoff Langbfdea662014-07-23 14:16:32 -04005674 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005675 {
Geoff Langbfdea662014-07-23 14:16:32 -04005676 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5677 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005678 }
Geoff Langbfdea662014-07-23 14:16:32 -04005679
5680 delete [] int64Params;
5681 }
5682 else
5683 {
5684 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005685 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005686 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005687 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005688}
5689
5690void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5691{
5692 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5693
Geoff Langbfdea662014-07-23 14:16:32 -04005694 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005695
Geoff Langbfdea662014-07-23 14:16:32 -04005696 if (context)
5697 {
5698 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005699 {
Geoff Langbfdea662014-07-23 14:16:32 -04005700 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005701 }
Geoff Langbfdea662014-07-23 14:16:32 -04005702
5703 switch (primitiveMode)
5704 {
5705 case GL_TRIANGLES:
5706 case GL_LINES:
5707 case GL_POINTS:
5708 break;
5709 default:
5710 return gl::error(GL_INVALID_ENUM);
5711 }
5712
5713 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5714 ASSERT(transformFeedback != NULL);
5715
5716 if (transformFeedback->isStarted())
5717 {
5718 return gl::error(GL_INVALID_OPERATION);
5719 }
5720
5721 if (transformFeedback->isPaused())
5722 {
5723 transformFeedback->resume();
5724 }
5725 else
5726 {
5727 transformFeedback->start(primitiveMode);
5728 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005729 }
5730}
5731
5732void __stdcall glEndTransformFeedback(void)
5733{
5734 EVENT("(void)");
5735
Geoff Langbfdea662014-07-23 14:16:32 -04005736 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005737
Geoff Langbfdea662014-07-23 14:16:32 -04005738 if (context)
5739 {
5740 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005741 {
Geoff Langbfdea662014-07-23 14:16:32 -04005742 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005743 }
Geoff Langbfdea662014-07-23 14:16:32 -04005744
5745 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5746 ASSERT(transformFeedback != NULL);
5747
5748 if (!transformFeedback->isStarted())
5749 {
5750 return gl::error(GL_INVALID_OPERATION);
5751 }
5752
5753 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005754 }
5755}
5756
5757void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5758{
5759 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5760 target, index, buffer, offset, size);
5761
Geoff Langbfdea662014-07-23 14:16:32 -04005762 gl::Context *context = gl::getNonLostContext();
5763
5764 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005765 {
Geoff Langbfdea662014-07-23 14:16:32 -04005766 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005767 {
Geoff Langbfdea662014-07-23 14:16:32 -04005768 return gl::error(GL_INVALID_OPERATION);
5769 }
5770
Geoff Lang3a61c322014-07-10 13:01:54 -04005771 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005772 switch (target)
5773 {
5774 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04005775 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005776 {
Geoff Langbfdea662014-07-23 14:16:32 -04005777 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005778 }
Geoff Langbfdea662014-07-23 14:16:32 -04005779 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005780
Geoff Langbfdea662014-07-23 14:16:32 -04005781 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04005782 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005783 {
Geoff Langbfdea662014-07-23 14:16:32 -04005784 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005785 }
Geoff Langbfdea662014-07-23 14:16:32 -04005786 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005787
Geoff Langbfdea662014-07-23 14:16:32 -04005788 default:
5789 return gl::error(GL_INVALID_ENUM);
5790 }
5791
5792 if (buffer != 0 && size <= 0)
5793 {
5794 return gl::error(GL_INVALID_VALUE);
5795 }
5796
5797 switch (target)
5798 {
5799 case GL_TRANSFORM_FEEDBACK_BUFFER:
5800
5801 // size and offset must be a multiple of 4
5802 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005803 {
5804 return gl::error(GL_INVALID_VALUE);
5805 }
5806
Geoff Langbfdea662014-07-23 14:16:32 -04005807 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5808 context->bindGenericTransformFeedbackBuffer(buffer);
5809 break;
5810
5811 case GL_UNIFORM_BUFFER:
5812
5813 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04005814 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005815 {
Geoff Langbfdea662014-07-23 14:16:32 -04005816 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005817 }
Geoff Langbfdea662014-07-23 14:16:32 -04005818
5819 context->bindIndexedUniformBuffer(buffer, index, offset, size);
5820 context->bindGenericUniformBuffer(buffer);
5821 break;
5822
5823 default:
5824 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005825 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005826 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005827}
5828
5829void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
5830{
5831 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
5832 target, index, buffer);
5833
Geoff Langbfdea662014-07-23 14:16:32 -04005834 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005835
Geoff Langbfdea662014-07-23 14:16:32 -04005836 if (context)
5837 {
5838 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005839 {
Geoff Langbfdea662014-07-23 14:16:32 -04005840 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005841 }
Geoff Langbfdea662014-07-23 14:16:32 -04005842
Geoff Lang3a61c322014-07-10 13:01:54 -04005843 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005844 switch (target)
5845 {
5846 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04005847 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04005848 {
5849 return gl::error(GL_INVALID_VALUE);
5850 }
5851 break;
5852
5853 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04005854 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04005855 {
5856 return gl::error(GL_INVALID_VALUE);
5857 }
5858 break;
5859
5860 default:
5861 return gl::error(GL_INVALID_ENUM);
5862 }
5863
5864 switch (target)
5865 {
5866 case GL_TRANSFORM_FEEDBACK_BUFFER:
5867 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
5868 context->bindGenericTransformFeedbackBuffer(buffer);
5869 break;
5870
5871 case GL_UNIFORM_BUFFER:
5872 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
5873 context->bindGenericUniformBuffer(buffer);
5874 break;
5875
5876 default:
5877 UNREACHABLE();
5878 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005879 }
5880}
5881
5882void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
5883{
5884 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
5885 program, count, varyings, bufferMode);
5886
Geoff Langbfdea662014-07-23 14:16:32 -04005887 gl::Context *context = gl::getNonLostContext();
5888
5889 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005890 {
Geoff Langbfdea662014-07-23 14:16:32 -04005891 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005892 {
Geoff Langbfdea662014-07-23 14:16:32 -04005893 return gl::error(GL_INVALID_OPERATION);
5894 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005895
Geoff Langbfdea662014-07-23 14:16:32 -04005896 if (count < 0)
5897 {
5898 return gl::error(GL_INVALID_VALUE);
5899 }
5900
Geoff Lang05881a02014-07-10 14:05:30 -04005901 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005902 switch (bufferMode)
5903 {
5904 case GL_INTERLEAVED_ATTRIBS:
5905 break;
5906 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04005907 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05005908 {
5909 return gl::error(GL_INVALID_VALUE);
5910 }
Geoff Langbfdea662014-07-23 14:16:32 -04005911 break;
5912 default:
5913 return gl::error(GL_INVALID_ENUM);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005914 }
Geoff Langbfdea662014-07-23 14:16:32 -04005915
5916 if (!gl::ValidProgram(context, program))
5917 {
5918 return;
5919 }
5920
5921 gl::Program *programObject = context->getProgram(program);
5922 ASSERT(programObject);
5923
5924 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005925 }
5926}
5927
5928void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
5929{
5930 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
5931 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
5932 program, index, bufSize, length, size, type, name);
5933
Geoff Langbfdea662014-07-23 14:16:32 -04005934 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005935
Geoff Langbfdea662014-07-23 14:16:32 -04005936 if (context)
5937 {
5938 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005939 {
Geoff Langbfdea662014-07-23 14:16:32 -04005940 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005941 }
Geoff Langbfdea662014-07-23 14:16:32 -04005942
5943 if (bufSize < 0)
5944 {
5945 return gl::error(GL_INVALID_VALUE);
5946 }
5947
5948 if (!gl::ValidProgram(context, program))
5949 {
5950 return;
5951 }
5952
5953 gl::Program *programObject = context->getProgram(program);
5954 ASSERT(programObject);
5955
5956 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
5957 {
5958 return gl::error(GL_INVALID_VALUE);
5959 }
5960
5961 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005962 }
5963}
5964
5965void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
5966{
5967 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
5968 index, size, type, stride, pointer);
5969
Geoff Langbfdea662014-07-23 14:16:32 -04005970 gl::Context *context = gl::getNonLostContext();
5971
5972 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005973 {
Geoff Langbfdea662014-07-23 14:16:32 -04005974 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005975 {
Geoff Langbfdea662014-07-23 14:16:32 -04005976 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005977 }
Geoff Langbfdea662014-07-23 14:16:32 -04005978 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005979
Geoff Langbfdea662014-07-23 14:16:32 -04005980 if (index >= gl::MAX_VERTEX_ATTRIBS)
5981 {
5982 return gl::error(GL_INVALID_VALUE);
5983 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005984
Geoff Langbfdea662014-07-23 14:16:32 -04005985 if (size < 1 || size > 4)
5986 {
5987 return gl::error(GL_INVALID_VALUE);
5988 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00005989
Geoff Langbfdea662014-07-23 14:16:32 -04005990 switch (type)
5991 {
5992 case GL_BYTE:
5993 case GL_UNSIGNED_BYTE:
5994 case GL_SHORT:
5995 case GL_UNSIGNED_SHORT:
5996 case GL_INT:
5997 case GL_UNSIGNED_INT:
5998 case GL_INT_2_10_10_10_REV:
5999 case GL_UNSIGNED_INT_2_10_10_10_REV:
6000 break;
6001 default:
6002 return gl::error(GL_INVALID_ENUM);
6003 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006004
Geoff Langbfdea662014-07-23 14:16:32 -04006005 if (stride < 0)
6006 {
6007 return gl::error(GL_INVALID_VALUE);
6008 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006009
Geoff Langbfdea662014-07-23 14:16:32 -04006010 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6011 {
6012 return gl::error(GL_INVALID_OPERATION);
6013 }
6014
6015 if (context)
6016 {
6017 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6018 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6019 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6020 // and the pointer argument is not NULL.
6021 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006022 {
6023 return gl::error(GL_INVALID_OPERATION);
6024 }
6025
Geoff Langbfdea662014-07-23 14:16:32 -04006026 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6027 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006028 }
6029}
6030
6031void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6032{
6033 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6034 index, pname, params);
6035
Geoff Langbfdea662014-07-23 14:16:32 -04006036 gl::Context *context = gl::getNonLostContext();
6037
6038 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006039 {
Geoff Langbfdea662014-07-23 14:16:32 -04006040 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006041 {
Geoff Langbfdea662014-07-23 14:16:32 -04006042 return gl::error(GL_INVALID_OPERATION);
6043 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006044
Geoff Langbfdea662014-07-23 14:16:32 -04006045 if (index >= gl::MAX_VERTEX_ATTRIBS)
6046 {
6047 return gl::error(GL_INVALID_VALUE);
6048 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006049
Geoff Langbfdea662014-07-23 14:16:32 -04006050 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006051
Geoff Langbfdea662014-07-23 14:16:32 -04006052 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6053 {
6054 return;
6055 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006056
Geoff Langbfdea662014-07-23 14:16:32 -04006057 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6058 {
6059 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6060 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006061 {
Geoff Langbfdea662014-07-23 14:16:32 -04006062 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006063 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006064 }
Geoff Langbfdea662014-07-23 14:16:32 -04006065 else
6066 {
6067 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006069 }
6070}
6071
6072void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6073{
6074 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6075 index, pname, params);
6076
Geoff Langbfdea662014-07-23 14:16:32 -04006077 gl::Context *context = gl::getNonLostContext();
6078
6079 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006080 {
Geoff Langbfdea662014-07-23 14:16:32 -04006081 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006082 {
Geoff Langbfdea662014-07-23 14:16:32 -04006083 return gl::error(GL_INVALID_OPERATION);
6084 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006085
Geoff Langbfdea662014-07-23 14:16:32 -04006086 if (index >= gl::MAX_VERTEX_ATTRIBS)
6087 {
6088 return gl::error(GL_INVALID_VALUE);
6089 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006090
Geoff Langbfdea662014-07-23 14:16:32 -04006091 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006092
Geoff Langbfdea662014-07-23 14:16:32 -04006093 if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
6094 {
6095 return;
6096 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006097
Geoff Langbfdea662014-07-23 14:16:32 -04006098 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6099 {
6100 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6101 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006102 {
Geoff Langbfdea662014-07-23 14:16:32 -04006103 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006104 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006105 }
Geoff Langbfdea662014-07-23 14:16:32 -04006106 else
6107 {
6108 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6109 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006110 }
6111}
6112
6113void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6114{
6115 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6116 index, x, y, z, w);
6117
Geoff Langbfdea662014-07-23 14:16:32 -04006118 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006119
Geoff Langbfdea662014-07-23 14:16:32 -04006120 if (context)
6121 {
6122 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006123 {
Geoff Langbfdea662014-07-23 14:16:32 -04006124 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006125 }
Geoff Langbfdea662014-07-23 14:16:32 -04006126
6127 if (index >= gl::MAX_VERTEX_ATTRIBS)
6128 {
6129 return gl::error(GL_INVALID_VALUE);
6130 }
6131
6132 GLint vals[4] = { x, y, z, w };
6133 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006134 }
6135}
6136
6137void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6138{
6139 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6140 index, x, y, z, w);
6141
Geoff Langbfdea662014-07-23 14:16:32 -04006142 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006143
Geoff Langbfdea662014-07-23 14:16:32 -04006144 if (context)
6145 {
6146 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006147 {
Geoff Langbfdea662014-07-23 14:16:32 -04006148 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006149 }
Geoff Langbfdea662014-07-23 14:16:32 -04006150
6151 if (index >= gl::MAX_VERTEX_ATTRIBS)
6152 {
6153 return gl::error(GL_INVALID_VALUE);
6154 }
6155
6156 GLuint vals[4] = { x, y, z, w };
6157 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006158 }
6159}
6160
6161void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6162{
6163 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6164
Geoff Langbfdea662014-07-23 14:16:32 -04006165 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006166
Geoff Langbfdea662014-07-23 14:16:32 -04006167 if (context)
6168 {
6169 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006170 {
Geoff Langbfdea662014-07-23 14:16:32 -04006171 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006172 }
Geoff Langbfdea662014-07-23 14:16:32 -04006173
6174 if (index >= gl::MAX_VERTEX_ATTRIBS)
6175 {
6176 return gl::error(GL_INVALID_VALUE);
6177 }
6178
6179 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006180 }
6181}
6182
6183void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6184{
6185 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6186
Geoff Langbfdea662014-07-23 14:16:32 -04006187 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006188
Geoff Langbfdea662014-07-23 14:16:32 -04006189 if (context)
6190 {
6191 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006192 {
Geoff Langbfdea662014-07-23 14:16:32 -04006193 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006194 }
Geoff Langbfdea662014-07-23 14:16:32 -04006195
6196 if (index >= gl::MAX_VERTEX_ATTRIBS)
6197 {
6198 return gl::error(GL_INVALID_VALUE);
6199 }
6200
6201 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006202 }
6203}
6204
6205void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6206{
6207 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6208 program, location, params);
6209
Geoff Langbfdea662014-07-23 14:16:32 -04006210 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006211
Geoff Langbfdea662014-07-23 14:16:32 -04006212 if (context)
6213 {
Jamie Madill0063c512014-08-25 15:47:53 -04006214 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006215 {
Jamie Madill0063c512014-08-25 15:47:53 -04006216 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006217 }
Geoff Langbfdea662014-07-23 14:16:32 -04006218
Jamie Madill0063c512014-08-25 15:47:53 -04006219 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6220 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006221
Jamie Madill99a1e982014-08-25 15:47:54 -04006222 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006223 }
6224}
6225
6226GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6227{
6228 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6229 program, name);
6230
Geoff Langbfdea662014-07-23 14:16:32 -04006231 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006232
Geoff Langbfdea662014-07-23 14:16:32 -04006233 if (context)
6234 {
6235 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006236 {
Geoff Langbfdea662014-07-23 14:16:32 -04006237 return gl::error(GL_INVALID_OPERATION, -1);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006238 }
Geoff Langbfdea662014-07-23 14:16:32 -04006239
6240 if (program == 0)
6241 {
6242 return gl::error(GL_INVALID_VALUE, -1);
6243 }
6244
6245 gl::Program *programObject = context->getProgram(program);
6246
6247 if (!programObject || !programObject->isLinked())
6248 {
6249 return gl::error(GL_INVALID_OPERATION, -1);
6250 }
6251
6252 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6253 if (!programBinary)
6254 {
6255 return gl::error(GL_INVALID_OPERATION, -1);
6256 }
6257
6258 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006259 }
6260
6261 return 0;
6262}
6263
6264void __stdcall glUniform1ui(GLint location, GLuint v0)
6265{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006266 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006267}
6268
6269void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6270{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006271 const GLuint xy[] = { v0, v1 };
6272 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006273}
6274
6275void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6276{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006277 const GLuint xyz[] = { v0, v1, v2 };
6278 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006279}
6280
6281void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6282{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006283 const GLuint xyzw[] = { v0, v1, v2, v3 };
6284 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006285}
6286
6287void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6288{
6289 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6290 location, count, value);
6291
Geoff Langbfdea662014-07-23 14:16:32 -04006292 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006293
Geoff Langbfdea662014-07-23 14:16:32 -04006294 if (context)
6295 {
6296 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006297 {
Geoff Langbfdea662014-07-23 14:16:32 -04006298 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006299 }
Geoff Langbfdea662014-07-23 14:16:32 -04006300
6301 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6302 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006303 }
6304}
6305
6306void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6307{
6308 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6309 location, count, value);
6310
Geoff Langbfdea662014-07-23 14:16:32 -04006311 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006312
Geoff Langbfdea662014-07-23 14:16:32 -04006313 if (context)
6314 {
6315 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006316 {
Geoff Langbfdea662014-07-23 14:16:32 -04006317 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006318 }
Geoff Langbfdea662014-07-23 14:16:32 -04006319
6320 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6321 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006322 }
6323}
6324
6325void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6326{
6327 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6328 location, count, value);
6329
Geoff Langbfdea662014-07-23 14:16:32 -04006330 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006331
Geoff Langbfdea662014-07-23 14:16:32 -04006332 if (context)
6333 {
6334 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006335 {
Geoff Langbfdea662014-07-23 14:16:32 -04006336 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006337 }
Geoff Langbfdea662014-07-23 14:16:32 -04006338
6339 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6340 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006341 }
6342}
6343
6344void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6345{
6346 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6347 location, count, value);
6348
Geoff Langbfdea662014-07-23 14:16:32 -04006349 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006350
Geoff Langbfdea662014-07-23 14:16:32 -04006351 if (context)
6352 {
6353 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006354 {
Geoff Langbfdea662014-07-23 14:16:32 -04006355 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006356 }
Geoff Langbfdea662014-07-23 14:16:32 -04006357
6358 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6359 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006360 }
6361}
6362
6363void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6364{
6365 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6366 buffer, drawbuffer, value);
6367
Geoff Langbfdea662014-07-23 14:16:32 -04006368 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006369
Geoff Langbfdea662014-07-23 14:16:32 -04006370 if (context)
6371 {
6372 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006373 {
Geoff Langbfdea662014-07-23 14:16:32 -04006374 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006375 }
Geoff Langbfdea662014-07-23 14:16:32 -04006376
6377 switch (buffer)
6378 {
6379 case GL_COLOR:
6380 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6381 {
6382 return gl::error(GL_INVALID_VALUE);
6383 }
6384 break;
6385 case GL_STENCIL:
6386 if (drawbuffer != 0)
6387 {
6388 return gl::error(GL_INVALID_VALUE);
6389 }
6390 break;
6391 default:
6392 return gl::error(GL_INVALID_ENUM);
6393 }
6394
6395 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006396 }
6397}
6398
6399void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6400{
6401 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6402 buffer, drawbuffer, value);
6403
Geoff Langbfdea662014-07-23 14:16:32 -04006404 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006405
Geoff Langbfdea662014-07-23 14:16:32 -04006406 if (context)
6407 {
6408 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006409 {
Geoff Langbfdea662014-07-23 14:16:32 -04006410 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006411 }
Geoff Langbfdea662014-07-23 14:16:32 -04006412
6413 switch (buffer)
6414 {
6415 case GL_COLOR:
6416 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6417 {
6418 return gl::error(GL_INVALID_VALUE);
6419 }
6420 break;
6421 default:
6422 return gl::error(GL_INVALID_ENUM);
6423 }
6424
6425 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006426 }
6427}
6428
6429void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6430{
6431 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6432 buffer, drawbuffer, value);
6433
Geoff Langbfdea662014-07-23 14:16:32 -04006434 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006435
Geoff Langbfdea662014-07-23 14:16:32 -04006436 if (context)
6437 {
6438 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006439 {
Geoff Langbfdea662014-07-23 14:16:32 -04006440 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006441 }
Geoff Langbfdea662014-07-23 14:16:32 -04006442
6443 switch (buffer)
6444 {
6445 case GL_COLOR:
6446 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6447 {
6448 return gl::error(GL_INVALID_VALUE);
6449 }
6450 break;
6451 case GL_DEPTH:
6452 if (drawbuffer != 0)
6453 {
6454 return gl::error(GL_INVALID_VALUE);
6455 }
6456 break;
6457 default:
6458 return gl::error(GL_INVALID_ENUM);
6459 }
6460
6461 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006462 }
6463}
6464
6465void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6466{
6467 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6468 buffer, drawbuffer, depth, stencil);
6469
Geoff Langbfdea662014-07-23 14:16:32 -04006470 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006471
Geoff Langbfdea662014-07-23 14:16:32 -04006472 if (context)
6473 {
6474 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006475 {
Geoff Langbfdea662014-07-23 14:16:32 -04006476 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006477 }
Geoff Langbfdea662014-07-23 14:16:32 -04006478
6479 switch (buffer)
6480 {
6481 case GL_DEPTH_STENCIL:
6482 if (drawbuffer != 0)
6483 {
6484 return gl::error(GL_INVALID_VALUE);
6485 }
6486 break;
6487 default:
6488 return gl::error(GL_INVALID_ENUM);
6489 }
6490
6491 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006492 }
6493}
6494
6495const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6496{
6497 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6498
Geoff Langbfdea662014-07-23 14:16:32 -04006499 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006500
Geoff Langbfdea662014-07-23 14:16:32 -04006501 if (context)
6502 {
6503 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006504 {
Geoff Langbfdea662014-07-23 14:16:32 -04006505 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006506 }
Geoff Langbfdea662014-07-23 14:16:32 -04006507
6508 if (name != GL_EXTENSIONS)
6509 {
6510 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
6511 }
6512
6513 if (index >= context->getExtensionStringCount())
6514 {
6515 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
6516 }
6517
6518 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006519 }
6520
6521 return NULL;
6522}
6523
6524void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6525{
6526 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6527 readTarget, writeTarget, readOffset, writeOffset, size);
6528
Geoff Langbfdea662014-07-23 14:16:32 -04006529 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006530
Geoff Langbfdea662014-07-23 14:16:32 -04006531 if (context)
6532 {
6533 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006534 {
Geoff Langbfdea662014-07-23 14:16:32 -04006535 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006536 }
Geoff Langbfdea662014-07-23 14:16:32 -04006537
6538 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6539 {
6540 return gl::error(GL_INVALID_ENUM);
6541 }
6542
6543 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6544 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6545
6546 if (!readBuffer || !writeBuffer)
6547 {
6548 return gl::error(GL_INVALID_OPERATION);
6549 }
6550
Jamie Madillcfaaf722014-07-31 10:47:54 -04006551 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006552 if (readBuffer->isMapped() || writeBuffer->isMapped())
6553 {
6554 return gl::error(GL_INVALID_OPERATION);
6555 }
6556
6557 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6558 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6559 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6560 {
6561 return gl::error(GL_INVALID_VALUE);
6562 }
6563
6564 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6565 {
6566 return gl::error(GL_INVALID_VALUE);
6567 }
6568
Geoff Langbfdea662014-07-23 14:16:32 -04006569 // if size is zero, the copy is a successful no-op
6570 if (size > 0)
6571 {
6572 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6573 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006574 }
6575}
6576
6577void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6578{
6579 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6580 program, uniformCount, uniformNames, uniformIndices);
6581
Geoff Langbfdea662014-07-23 14:16:32 -04006582 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006583
Geoff Langbfdea662014-07-23 14:16:32 -04006584 if (context)
6585 {
6586 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006587 {
Geoff Langbfdea662014-07-23 14:16:32 -04006588 return gl::error(GL_INVALID_OPERATION);
6589 }
6590
6591 if (uniformCount < 0)
6592 {
6593 return gl::error(GL_INVALID_VALUE);
6594 }
6595
6596 gl::Program *programObject = context->getProgram(program);
6597
6598 if (!programObject)
6599 {
6600 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006601 {
6602 return gl::error(GL_INVALID_OPERATION);
6603 }
Geoff Langbfdea662014-07-23 14:16:32 -04006604 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006605 {
6606 return gl::error(GL_INVALID_VALUE);
6607 }
Geoff Langbfdea662014-07-23 14:16:32 -04006608 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006609
Geoff Langbfdea662014-07-23 14:16:32 -04006610 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6611 if (!programObject->isLinked() || !programBinary)
6612 {
6613 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006614 {
Geoff Langbfdea662014-07-23 14:16:32 -04006615 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006616 }
6617 }
Geoff Langbfdea662014-07-23 14:16:32 -04006618 else
6619 {
6620 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6621 {
6622 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6623 }
6624 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006625 }
6626}
6627
6628void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6629{
6630 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6631 program, uniformCount, uniformIndices, pname, params);
6632
Geoff Langbfdea662014-07-23 14:16:32 -04006633 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006634
Geoff Langbfdea662014-07-23 14:16:32 -04006635 if (context)
6636 {
6637 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006638 {
Geoff Langbfdea662014-07-23 14:16:32 -04006639 return gl::error(GL_INVALID_OPERATION);
6640 }
6641
6642 if (uniformCount < 0)
6643 {
6644 return gl::error(GL_INVALID_VALUE);
6645 }
6646
6647 gl::Program *programObject = context->getProgram(program);
6648
6649 if (!programObject)
6650 {
6651 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006652 {
6653 return gl::error(GL_INVALID_OPERATION);
6654 }
Geoff Langbfdea662014-07-23 14:16:32 -04006655 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006656 {
6657 return gl::error(GL_INVALID_VALUE);
6658 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006659 }
Geoff Langbfdea662014-07-23 14:16:32 -04006660
6661 switch (pname)
6662 {
6663 case GL_UNIFORM_TYPE:
6664 case GL_UNIFORM_SIZE:
6665 case GL_UNIFORM_NAME_LENGTH:
6666 case GL_UNIFORM_BLOCK_INDEX:
6667 case GL_UNIFORM_OFFSET:
6668 case GL_UNIFORM_ARRAY_STRIDE:
6669 case GL_UNIFORM_MATRIX_STRIDE:
6670 case GL_UNIFORM_IS_ROW_MAJOR:
6671 break;
6672 default:
6673 return gl::error(GL_INVALID_ENUM);
6674 }
6675
6676 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6677
6678 if (!programBinary && uniformCount > 0)
6679 {
6680 return gl::error(GL_INVALID_VALUE);
6681 }
6682
6683 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6684 {
6685 const GLuint index = uniformIndices[uniformId];
6686
6687 if (index >= (GLuint)programBinary->getActiveUniformCount())
6688 {
6689 return gl::error(GL_INVALID_VALUE);
6690 }
6691 }
6692
6693 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6694 {
6695 const GLuint index = uniformIndices[uniformId];
6696 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6697 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006698 }
6699}
6700
6701GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6702{
6703 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6704
Geoff Langbfdea662014-07-23 14:16:32 -04006705 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006706
Geoff Langbfdea662014-07-23 14:16:32 -04006707 if (context)
6708 {
6709 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006710 {
Geoff Langbfdea662014-07-23 14:16:32 -04006711 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
6712 }
6713
6714 gl::Program *programObject = context->getProgram(program);
6715
6716 if (!programObject)
6717 {
6718 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006719 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006720 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006721 }
Geoff Langbfdea662014-07-23 14:16:32 -04006722 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006723 {
Geoff Langbfdea662014-07-23 14:16:32 -04006724 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006725 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006726 }
Geoff Langbfdea662014-07-23 14:16:32 -04006727
6728 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6729 if (!programBinary)
6730 {
6731 return GL_INVALID_INDEX;
6732 }
6733
6734 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006735 }
6736
6737 return 0;
6738}
6739
6740void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6741{
6742 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6743 program, uniformBlockIndex, pname, params);
6744
Geoff Langbfdea662014-07-23 14:16:32 -04006745 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006746
Geoff Langbfdea662014-07-23 14:16:32 -04006747 if (context)
6748 {
6749 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006750 {
Geoff Langbfdea662014-07-23 14:16:32 -04006751 return gl::error(GL_INVALID_OPERATION);
6752 }
6753 gl::Program *programObject = context->getProgram(program);
6754
6755 if (!programObject)
6756 {
6757 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006758 {
6759 return gl::error(GL_INVALID_OPERATION);
6760 }
Geoff Langbfdea662014-07-23 14:16:32 -04006761 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006762 {
6763 return gl::error(GL_INVALID_VALUE);
6764 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006765 }
Geoff Langbfdea662014-07-23 14:16:32 -04006766
6767 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6768
6769 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6770 {
6771 return gl::error(GL_INVALID_VALUE);
6772 }
6773
6774 switch (pname)
6775 {
6776 case GL_UNIFORM_BLOCK_BINDING:
6777 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
6778 break;
6779
6780 case GL_UNIFORM_BLOCK_DATA_SIZE:
6781 case GL_UNIFORM_BLOCK_NAME_LENGTH:
6782 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
6783 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
6784 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
6785 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
6786 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
6787 break;
6788
6789 default:
6790 return gl::error(GL_INVALID_ENUM);
6791 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006792 }
6793}
6794
6795void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
6796{
6797 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
6798 program, uniformBlockIndex, bufSize, length, uniformBlockName);
6799
Geoff Langbfdea662014-07-23 14:16:32 -04006800 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006801
Geoff Langbfdea662014-07-23 14:16:32 -04006802 if (context)
6803 {
6804 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006805 {
Geoff Langbfdea662014-07-23 14:16:32 -04006806 return gl::error(GL_INVALID_OPERATION);
6807 }
6808
6809 gl::Program *programObject = context->getProgram(program);
6810
6811 if (!programObject)
6812 {
6813 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006814 {
6815 return gl::error(GL_INVALID_OPERATION);
6816 }
Geoff Langbfdea662014-07-23 14:16:32 -04006817 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006818 {
6819 return gl::error(GL_INVALID_VALUE);
6820 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00006821 }
Geoff Langbfdea662014-07-23 14:16:32 -04006822
6823 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6824
6825 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6826 {
6827 return gl::error(GL_INVALID_VALUE);
6828 }
6829
6830 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006831 }
6832}
6833
6834void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
6835{
6836 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
6837 program, uniformBlockIndex, uniformBlockBinding);
6838
Geoff Langbfdea662014-07-23 14:16:32 -04006839 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006840
Geoff Langbfdea662014-07-23 14:16:32 -04006841 if (context)
6842 {
6843 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006844 {
Geoff Langbfdea662014-07-23 14:16:32 -04006845 return gl::error(GL_INVALID_OPERATION);
6846 }
6847
Geoff Lang3a61c322014-07-10 13:01:54 -04006848 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006849 {
6850 return gl::error(GL_INVALID_VALUE);
6851 }
6852
6853 gl::Program *programObject = context->getProgram(program);
6854
6855 if (!programObject)
6856 {
6857 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006858 {
6859 return gl::error(GL_INVALID_OPERATION);
6860 }
Geoff Langbfdea662014-07-23 14:16:32 -04006861 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006862 {
6863 return gl::error(GL_INVALID_VALUE);
6864 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00006865 }
Geoff Langbfdea662014-07-23 14:16:32 -04006866
6867 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6868
6869 // if never linked, there won't be any uniform blocks
6870 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6871 {
6872 return gl::error(GL_INVALID_VALUE);
6873 }
6874
6875 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006876 }
6877}
6878
6879void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
6880{
6881 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
6882 mode, first, count, instanceCount);
6883
Geoff Langbfdea662014-07-23 14:16:32 -04006884 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006885
Geoff Langbfdea662014-07-23 14:16:32 -04006886 if (context)
6887 {
6888 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006889 {
Geoff Langbfdea662014-07-23 14:16:32 -04006890 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006891 }
Geoff Langbfdea662014-07-23 14:16:32 -04006892
6893 // glDrawArraysInstanced
6894 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006895 }
6896}
6897
6898void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
6899{
6900 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
6901 mode, count, type, indices, instanceCount);
6902
Geoff Langbfdea662014-07-23 14:16:32 -04006903 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006904
Geoff Langbfdea662014-07-23 14:16:32 -04006905 if (context)
6906 {
6907 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006908 {
Geoff Langbfdea662014-07-23 14:16:32 -04006909 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006910 }
Geoff Langbfdea662014-07-23 14:16:32 -04006911
6912 // glDrawElementsInstanced
6913 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006914 }
6915}
6916
6917GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
6918{
6919 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
6920
Geoff Langbfdea662014-07-23 14:16:32 -04006921 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006922
Geoff Langbfdea662014-07-23 14:16:32 -04006923 if (context)
6924 {
6925 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006926 {
Geoff Langbfdea662014-07-23 14:16:32 -04006927 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006928 }
Geoff Langbfdea662014-07-23 14:16:32 -04006929
6930 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
6931 {
6932 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
6933 }
6934
6935 if (flags != 0)
6936 {
6937 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
6938 }
6939
6940 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006941 }
6942
6943 return NULL;
6944}
6945
6946GLboolean __stdcall glIsSync(GLsync sync)
6947{
6948 EVENT("(GLsync sync = 0x%0.8p)", sync);
6949
Geoff Langbfdea662014-07-23 14:16:32 -04006950 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006951
Geoff Langbfdea662014-07-23 14:16:32 -04006952 if (context)
6953 {
6954 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006955 {
Geoff Langbfdea662014-07-23 14:16:32 -04006956 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006957 }
Geoff Langbfdea662014-07-23 14:16:32 -04006958
6959 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006960 }
6961
6962 return GL_FALSE;
6963}
6964
6965void __stdcall glDeleteSync(GLsync sync)
6966{
6967 EVENT("(GLsync sync = 0x%0.8p)", sync);
6968
Geoff Langbfdea662014-07-23 14:16:32 -04006969 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006970
Geoff Langbfdea662014-07-23 14:16:32 -04006971 if (context)
6972 {
6973 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006974 {
Geoff Langbfdea662014-07-23 14:16:32 -04006975 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006976 }
Geoff Langbfdea662014-07-23 14:16:32 -04006977
6978 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
6979 {
6980 return gl::error(GL_INVALID_VALUE);
6981 }
6982
6983 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006984 }
6985}
6986
6987GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6988{
6989 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
6990 sync, flags, timeout);
6991
Geoff Langbfdea662014-07-23 14:16:32 -04006992 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006993
Geoff Langbfdea662014-07-23 14:16:32 -04006994 if (context)
6995 {
6996 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006997 {
Geoff Langbfdea662014-07-23 14:16:32 -04006998 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006999 }
Geoff Langbfdea662014-07-23 14:16:32 -04007000
7001 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7002 {
7003 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7004 }
7005
7006 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7007
7008 if (!fenceSync)
7009 {
7010 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
7011 }
7012
7013 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007014 }
7015
7016 return GL_FALSE;
7017}
7018
7019void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7020{
7021 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7022 sync, flags, timeout);
7023
Geoff Langbfdea662014-07-23 14:16:32 -04007024 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007025
Geoff Langbfdea662014-07-23 14:16:32 -04007026 if (context)
7027 {
7028 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007029 {
Geoff Langbfdea662014-07-23 14:16:32 -04007030 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007031 }
Geoff Langbfdea662014-07-23 14:16:32 -04007032
7033 if (flags != 0)
7034 {
7035 return gl::error(GL_INVALID_VALUE);
7036 }
7037
7038 if (timeout != GL_TIMEOUT_IGNORED)
7039 {
7040 return gl::error(GL_INVALID_VALUE);
7041 }
7042
7043 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7044
7045 if (!fenceSync)
7046 {
7047 return gl::error(GL_INVALID_VALUE);
7048 }
7049
7050 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007051 }
7052}
7053
7054void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7055{
7056 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7057 pname, params);
7058
Geoff Langbfdea662014-07-23 14:16:32 -04007059 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007060
Geoff Langbfdea662014-07-23 14:16:32 -04007061 if (context)
7062 {
7063 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007064 {
Geoff Langbfdea662014-07-23 14:16:32 -04007065 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007066 }
Geoff Langbfdea662014-07-23 14:16:32 -04007067
7068 GLenum nativeType;
7069 unsigned int numParams = 0;
7070 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7071 {
7072 return;
7073 }
7074
7075 if (nativeType == GL_INT_64_ANGLEX)
7076 {
7077 context->getInteger64v(pname, params);
7078 }
7079 else
7080 {
7081 CastStateValues(context, nativeType, pname, numParams, params);
7082 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007083 }
7084}
7085
7086void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7087{
7088 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7089 sync, pname, bufSize, length, values);
7090
Geoff Langbfdea662014-07-23 14:16:32 -04007091 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007092
Geoff Langbfdea662014-07-23 14:16:32 -04007093 if (context)
7094 {
7095 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007096 {
Geoff Langbfdea662014-07-23 14:16:32 -04007097 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007098 }
Geoff Langbfdea662014-07-23 14:16:32 -04007099
7100 if (bufSize < 0)
7101 {
7102 return gl::error(GL_INVALID_VALUE);
7103 }
7104
7105 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7106
7107 if (!fenceSync)
7108 {
7109 return gl::error(GL_INVALID_VALUE);
7110 }
7111
7112 switch (pname)
7113 {
7114 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7115 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7116 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7117 case GL_SYNC_FLAGS: values[0] = 0; break;
7118
7119 default:
7120 return gl::error(GL_INVALID_ENUM);
7121 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007122 }
7123}
7124
7125void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7126{
7127 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7128 target, index, data);
7129
Geoff Langbfdea662014-07-23 14:16:32 -04007130 gl::Context *context = gl::getNonLostContext();
7131
7132 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007133 {
Geoff Langbfdea662014-07-23 14:16:32 -04007134 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007135 {
Geoff Langbfdea662014-07-23 14:16:32 -04007136 return gl::error(GL_INVALID_OPERATION);
7137 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007138
Geoff Lang3a61c322014-07-10 13:01:54 -04007139 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007140 switch (target)
7141 {
7142 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7143 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7144 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007145 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7146 {
Geoff Langbfdea662014-07-23 14:16:32 -04007147 return gl::error(GL_INVALID_VALUE);
Geoff Lang05881a02014-07-10 14:05:30 -04007148 }
Geoff Langbfdea662014-07-23 14:16:32 -04007149 break;
7150 case GL_UNIFORM_BUFFER_START:
7151 case GL_UNIFORM_BUFFER_SIZE:
7152 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007153 if (index >= caps.maxUniformBufferBindings)
7154 {
Geoff Langbfdea662014-07-23 14:16:32 -04007155 return gl::error(GL_INVALID_VALUE);
Geoff Lang3a61c322014-07-10 13:01:54 -04007156 }
Geoff Langbfdea662014-07-23 14:16:32 -04007157 break;
7158 default:
7159 return gl::error(GL_INVALID_ENUM);
7160 }
7161
7162 if (!(context->getIndexedInteger64v(target, index, data)))
7163 {
7164 GLenum nativeType;
7165 unsigned int numParams = 0;
7166 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Shannon Woods15934d52013-08-19 14:28:49 -04007167 return gl::error(GL_INVALID_ENUM);
Shannon Woods15934d52013-08-19 14:28:49 -04007168
Geoff Langbfdea662014-07-23 14:16:32 -04007169 if (numParams == 0)
7170 return; // it is known that pname is valid, but there are no parameters to return
7171
7172 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007173 {
Geoff Langbfdea662014-07-23 14:16:32 -04007174 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007175
Geoff Langbfdea662014-07-23 14:16:32 -04007176 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007177
Geoff Langbfdea662014-07-23 14:16:32 -04007178 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007179 {
Geoff Langbfdea662014-07-23 14:16:32 -04007180 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007181 }
Geoff Langbfdea662014-07-23 14:16:32 -04007182
7183 delete [] intParams;
7184 }
7185 else
7186 {
7187 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007188 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007189 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007190 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007191}
7192
7193void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7194{
7195 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7196 target, pname, params);
7197
Geoff Langbfdea662014-07-23 14:16:32 -04007198 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007199
Geoff Langbfdea662014-07-23 14:16:32 -04007200 if (context)
7201 {
7202 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007203 {
Geoff Langbfdea662014-07-23 14:16:32 -04007204 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007205 }
Geoff Langbfdea662014-07-23 14:16:32 -04007206
7207 if (!gl::ValidBufferTarget(context, target))
7208 {
7209 return gl::error(GL_INVALID_ENUM);
7210 }
7211
7212 if (!gl::ValidBufferParameter(context, pname))
7213 {
7214 return gl::error(GL_INVALID_ENUM);
7215 }
7216
7217 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7218
7219 if (!buffer)
7220 {
7221 // A null buffer means that "0" is bound to the requested buffer target
7222 return gl::error(GL_INVALID_OPERATION);
7223 }
7224
7225 switch (pname)
7226 {
7227 case GL_BUFFER_USAGE:
7228 *params = static_cast<GLint64>(buffer->getUsage());
7229 break;
7230 case GL_BUFFER_SIZE:
7231 *params = buffer->getSize();
7232 break;
7233 case GL_BUFFER_ACCESS_FLAGS:
7234 *params = static_cast<GLint64>(buffer->getAccessFlags());
7235 break;
7236 case GL_BUFFER_MAPPED:
7237 *params = static_cast<GLint64>(buffer->isMapped());
7238 break;
7239 case GL_BUFFER_MAP_OFFSET:
7240 *params = buffer->getMapOffset();
7241 break;
7242 case GL_BUFFER_MAP_LENGTH:
7243 *params = buffer->getMapLength();
7244 break;
7245 default: UNREACHABLE(); break;
7246 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007247 }
7248}
7249
7250void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7251{
7252 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7253
Geoff Langbfdea662014-07-23 14:16:32 -04007254 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007255
Geoff Langbfdea662014-07-23 14:16:32 -04007256 if (context)
7257 {
7258 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007259 {
Geoff Langbfdea662014-07-23 14:16:32 -04007260 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007261 }
Geoff Langbfdea662014-07-23 14:16:32 -04007262
7263 if (count < 0)
7264 {
7265 return gl::error(GL_INVALID_VALUE);
7266 }
7267
7268 for (int i = 0; i < count; i++)
7269 {
7270 samplers[i] = context->createSampler();
7271 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007272 }
7273}
7274
7275void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7276{
7277 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7278
Geoff Langbfdea662014-07-23 14:16:32 -04007279 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007280
Geoff Langbfdea662014-07-23 14:16:32 -04007281 if (context)
7282 {
7283 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007284 {
Geoff Langbfdea662014-07-23 14:16:32 -04007285 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007286 }
Geoff Langbfdea662014-07-23 14:16:32 -04007287
7288 if (count < 0)
7289 {
7290 return gl::error(GL_INVALID_VALUE);
7291 }
7292
7293 for (int i = 0; i < count; i++)
7294 {
7295 context->deleteSampler(samplers[i]);
7296 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007297 }
7298}
7299
7300GLboolean __stdcall glIsSampler(GLuint sampler)
7301{
7302 EVENT("(GLuint sampler = %u)", sampler);
7303
Geoff Langbfdea662014-07-23 14:16:32 -04007304 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007305
Geoff Langbfdea662014-07-23 14:16:32 -04007306 if (context)
7307 {
7308 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007309 {
Geoff Langbfdea662014-07-23 14:16:32 -04007310 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007311 }
Geoff Langbfdea662014-07-23 14:16:32 -04007312
7313 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007314 }
7315
7316 return GL_FALSE;
7317}
7318
7319void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7320{
7321 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7322
Geoff Langbfdea662014-07-23 14:16:32 -04007323 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007324
Geoff Langbfdea662014-07-23 14:16:32 -04007325 if (context)
7326 {
7327 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007328 {
Geoff Langbfdea662014-07-23 14:16:32 -04007329 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007330 }
Geoff Langbfdea662014-07-23 14:16:32 -04007331
7332 if (sampler != 0 && !context->isSampler(sampler))
7333 {
7334 return gl::error(GL_INVALID_OPERATION);
7335 }
7336
Geoff Lang3a61c322014-07-10 13:01:54 -04007337 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007338 {
7339 return gl::error(GL_INVALID_VALUE);
7340 }
7341
7342 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007343 }
7344}
7345
7346void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7347{
7348 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7349
Geoff Langbfdea662014-07-23 14:16:32 -04007350 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007351
Geoff Langbfdea662014-07-23 14:16:32 -04007352 if (context)
7353 {
7354 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007355 {
Geoff Langbfdea662014-07-23 14:16:32 -04007356 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007357 }
Geoff Langbfdea662014-07-23 14:16:32 -04007358
7359 if (!gl::ValidateSamplerObjectParameter(pname))
7360 {
7361 return;
7362 }
7363
7364 if (!gl::ValidateTexParamParameters(context, pname, param))
7365 {
7366 return;
7367 }
7368
7369 if (!context->isSampler(sampler))
7370 {
7371 return gl::error(GL_INVALID_OPERATION);
7372 }
7373
7374 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007375 }
7376}
7377
7378void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7379{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007380 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007381}
7382
7383void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7384{
7385 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7386
Geoff Langbfdea662014-07-23 14:16:32 -04007387 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007388
Geoff Langbfdea662014-07-23 14:16:32 -04007389 if (context)
7390 {
7391 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007392 {
Geoff Langbfdea662014-07-23 14:16:32 -04007393 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007394 }
Geoff Langbfdea662014-07-23 14:16:32 -04007395
7396 if (!gl::ValidateSamplerObjectParameter(pname))
7397 {
7398 return;
7399 }
7400
7401 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7402 {
7403 return;
7404 }
7405
7406 if (!context->isSampler(sampler))
7407 {
7408 return gl::error(GL_INVALID_OPERATION);
7409 }
7410
7411 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007412 }
7413}
7414
7415void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7416{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007417 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007418}
7419
7420void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7421{
7422 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7423
Geoff Langbfdea662014-07-23 14:16:32 -04007424 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007425
Geoff Langbfdea662014-07-23 14:16:32 -04007426 if (context)
7427 {
7428 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007429 {
Geoff Langbfdea662014-07-23 14:16:32 -04007430 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007431 }
Geoff Langbfdea662014-07-23 14:16:32 -04007432
7433 if (!gl::ValidateSamplerObjectParameter(pname))
7434 {
7435 return;
7436 }
7437
7438 if (!context->isSampler(sampler))
7439 {
7440 return gl::error(GL_INVALID_OPERATION);
7441 }
7442
7443 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007444 }
7445}
7446
7447void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7448{
7449 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7450
Geoff Langbfdea662014-07-23 14:16:32 -04007451 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007452
Geoff Langbfdea662014-07-23 14:16:32 -04007453 if (context)
7454 {
7455 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007456 {
Geoff Langbfdea662014-07-23 14:16:32 -04007457 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007458 }
Geoff Langbfdea662014-07-23 14:16:32 -04007459
7460 if (!gl::ValidateSamplerObjectParameter(pname))
7461 {
7462 return;
7463 }
7464
7465 if (!context->isSampler(sampler))
7466 {
7467 return gl::error(GL_INVALID_OPERATION);
7468 }
7469
7470 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007471 }
7472}
7473
7474void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7475{
7476 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7477
Geoff Langbfdea662014-07-23 14:16:32 -04007478 if (index >= gl::MAX_VERTEX_ATTRIBS)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007479 {
Geoff Langbfdea662014-07-23 14:16:32 -04007480 return gl::error(GL_INVALID_VALUE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007481 }
Geoff Langbfdea662014-07-23 14:16:32 -04007482
7483 gl::Context *context = gl::getNonLostContext();
7484
7485 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007486 {
Geoff Langbfdea662014-07-23 14:16:32 -04007487 if (context->getClientVersion() < 3)
7488 {
7489 return gl::error(GL_INVALID_OPERATION);
7490 }
7491
7492 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007493 }
7494}
7495
7496void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7497{
7498 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7499
Geoff Langbfdea662014-07-23 14:16:32 -04007500 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007501
Geoff Langbfdea662014-07-23 14:16:32 -04007502 if (context)
7503 {
7504 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007505 {
Geoff Langbfdea662014-07-23 14:16:32 -04007506 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007507 }
Geoff Langbfdea662014-07-23 14:16:32 -04007508
7509 switch (target)
7510 {
7511 case GL_TRANSFORM_FEEDBACK:
7512 {
7513 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7514 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7515 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7516 {
7517 return gl::error(GL_INVALID_OPERATION);
7518 }
7519
7520 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7521 if (context->getTransformFeedback(id) == NULL)
7522 {
7523 return gl::error(GL_INVALID_OPERATION);
7524 }
7525
7526 context->bindTransformFeedback(id);
7527 }
7528 break;
7529
7530 default:
7531 return gl::error(GL_INVALID_ENUM);
7532 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007533 }
7534}
7535
7536void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7537{
7538 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7539
Geoff Langbfdea662014-07-23 14:16:32 -04007540 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007541
Geoff Langbfdea662014-07-23 14:16:32 -04007542 if (context)
7543 {
7544 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007545 {
Geoff Langbfdea662014-07-23 14:16:32 -04007546 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007547 }
Geoff Langbfdea662014-07-23 14:16:32 -04007548
7549 for (int i = 0; i < n; i++)
7550 {
7551 context->deleteTransformFeedback(ids[i]);
7552 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007553 }
7554}
7555
7556void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7557{
7558 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7559
Geoff Langbfdea662014-07-23 14:16:32 -04007560 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007561
Geoff Langbfdea662014-07-23 14:16:32 -04007562 if (context)
7563 {
7564 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007565 {
Geoff Langbfdea662014-07-23 14:16:32 -04007566 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007567 }
Geoff Langbfdea662014-07-23 14:16:32 -04007568
7569 for (int i = 0; i < n; i++)
7570 {
7571 ids[i] = context->createTransformFeedback();
7572 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007573 }
7574}
7575
7576GLboolean __stdcall glIsTransformFeedback(GLuint id)
7577{
7578 EVENT("(GLuint id = %u)", id);
7579
Geoff Langbfdea662014-07-23 14:16:32 -04007580 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007581
Geoff Langbfdea662014-07-23 14:16:32 -04007582 if (context)
7583 {
7584 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007585 {
Geoff Langbfdea662014-07-23 14:16:32 -04007586 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007587 }
Geoff Langbfdea662014-07-23 14:16:32 -04007588
7589 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007590 }
7591
7592 return GL_FALSE;
7593}
7594
7595void __stdcall glPauseTransformFeedback(void)
7596{
7597 EVENT("(void)");
7598
Geoff Langbfdea662014-07-23 14:16:32 -04007599 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007600
Geoff Langbfdea662014-07-23 14:16:32 -04007601 if (context)
7602 {
7603 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007604 {
Geoff Langbfdea662014-07-23 14:16:32 -04007605 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007606 }
Geoff Langbfdea662014-07-23 14:16:32 -04007607
7608 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7609 ASSERT(transformFeedback != NULL);
7610
7611 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7612 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7613 {
7614 return gl::error(GL_INVALID_OPERATION);
7615 }
7616
7617 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007618 }
7619}
7620
7621void __stdcall glResumeTransformFeedback(void)
7622{
7623 EVENT("(void)");
7624
Geoff Langbfdea662014-07-23 14:16:32 -04007625 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007626
Geoff Langbfdea662014-07-23 14:16:32 -04007627 if (context)
7628 {
7629 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007630 {
Geoff Langbfdea662014-07-23 14:16:32 -04007631 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007632 }
Geoff Langbfdea662014-07-23 14:16:32 -04007633
7634 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7635 ASSERT(transformFeedback != NULL);
7636
7637 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7638 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7639 {
7640 return gl::error(GL_INVALID_OPERATION);
7641 }
7642
7643 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007644 }
7645}
7646
7647void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7648{
7649 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7650 program, bufSize, length, binaryFormat, binary);
7651
Geoff Langbfdea662014-07-23 14:16:32 -04007652 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007653
Geoff Langbfdea662014-07-23 14:16:32 -04007654 if (context)
7655 {
7656 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007657 {
Geoff Langbfdea662014-07-23 14:16:32 -04007658 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007659 }
Geoff Langbfdea662014-07-23 14:16:32 -04007660
7661 // glGetProgramBinary
7662 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007663 }
7664}
7665
7666void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7667{
7668 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7669 program, binaryFormat, binary, length);
7670
Geoff Langbfdea662014-07-23 14:16:32 -04007671 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007672
Geoff Langbfdea662014-07-23 14:16:32 -04007673 if (context)
7674 {
7675 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007676 {
Geoff Langbfdea662014-07-23 14:16:32 -04007677 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007678 }
Geoff Langbfdea662014-07-23 14:16:32 -04007679
7680 // glProgramBinary
7681 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007682 }
7683}
7684
7685void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7686{
7687 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7688 program, pname, value);
7689
Geoff Langbfdea662014-07-23 14:16:32 -04007690 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007691
Geoff Langbfdea662014-07-23 14:16:32 -04007692 if (context)
7693 {
7694 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007695 {
Geoff Langbfdea662014-07-23 14:16:32 -04007696 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007697 }
Geoff Langbfdea662014-07-23 14:16:32 -04007698
7699 // glProgramParameteri
7700 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007701 }
7702}
7703
7704void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7705{
7706 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7707 target, numAttachments, attachments);
7708
Geoff Langbfdea662014-07-23 14:16:32 -04007709 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007710
Geoff Langbfdea662014-07-23 14:16:32 -04007711 if (context)
7712 {
7713 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007714 {
Geoff Langbfdea662014-07-23 14:16:32 -04007715 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007716 }
Geoff Langbfdea662014-07-23 14:16:32 -04007717
7718 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7719 {
7720 return;
7721 }
7722
7723 GLuint maxDimension = context->getCaps().maxRenderbufferSize;
7724 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007725 }
7726}
7727
7728void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
7729{
7730 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
7731 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7732 target, numAttachments, attachments, x, y, width, height);
7733
Geoff Langbfdea662014-07-23 14:16:32 -04007734 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007735
Geoff Langbfdea662014-07-23 14:16:32 -04007736 if (context)
7737 {
7738 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007739 {
Geoff Langbfdea662014-07-23 14:16:32 -04007740 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007741 }
Geoff Langbfdea662014-07-23 14:16:32 -04007742
7743 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7744 {
7745 return;
7746 }
7747
7748 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007749 }
7750}
7751
7752void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7753{
7754 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7755 target, levels, internalformat, width, height);
7756
Geoff Langbfdea662014-07-23 14:16:32 -04007757 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007758
Geoff Langbfdea662014-07-23 14:16:32 -04007759 if (context)
7760 {
7761 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007762 {
Geoff Langbfdea662014-07-23 14:16:32 -04007763 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007764 }
Geoff Langbfdea662014-07-23 14:16:32 -04007765
7766 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
7767 {
7768 return;
7769 }
7770
7771 switch (target)
7772 {
7773 case GL_TEXTURE_2D:
7774 {
7775 gl::Texture2D *texture2d = context->getTexture2D();
7776 texture2d->storage(levels, internalformat, width, height);
7777 }
7778 break;
7779
7780 case GL_TEXTURE_CUBE_MAP:
7781 {
7782 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7783 textureCube->storage(levels, internalformat, width);
7784 }
7785 break;
7786
7787 default:
7788 return gl::error(GL_INVALID_ENUM);
7789 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007790 }
7791}
7792
7793void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
7794{
7795 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
7796 "GLsizei height = %d, GLsizei depth = %d)",
7797 target, levels, internalformat, width, height, depth);
7798
Geoff Langbfdea662014-07-23 14:16:32 -04007799 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007800
Geoff Langbfdea662014-07-23 14:16:32 -04007801 if (context)
7802 {
7803 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007804 {
Geoff Langbfdea662014-07-23 14:16:32 -04007805 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00007806 }
Geoff Langbfdea662014-07-23 14:16:32 -04007807
7808 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
7809 {
7810 return;
7811 }
7812
7813 switch (target)
7814 {
7815 case GL_TEXTURE_3D:
7816 {
7817 gl::Texture3D *texture3d = context->getTexture3D();
7818 texture3d->storage(levels, internalformat, width, height, depth);
7819 }
7820 break;
7821
7822 case GL_TEXTURE_2D_ARRAY:
7823 {
7824 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
7825 texture2darray->storage(levels, internalformat, width, height, depth);
7826 }
7827 break;
7828
7829 default:
7830 UNREACHABLE();
7831 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007832 }
7833}
7834
7835void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
7836{
7837 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
7838 "GLint* params = 0x%0.8p)",
7839 target, internalformat, pname, bufSize, params);
7840
Geoff Langbfdea662014-07-23 14:16:32 -04007841 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007842
Geoff Langbfdea662014-07-23 14:16:32 -04007843 if (context)
7844 {
7845 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007846 {
Geoff Langbfdea662014-07-23 14:16:32 -04007847 return gl::error(GL_INVALID_OPERATION);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007848 }
Geoff Langbfdea662014-07-23 14:16:32 -04007849
7850 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7851 if (!formatCaps.renderable)
7852 {
7853 return gl::error(GL_INVALID_ENUM);
7854 }
7855
7856 if (target != GL_RENDERBUFFER)
7857 {
7858 return gl::error(GL_INVALID_ENUM);
7859 }
7860
7861 if (bufSize < 0)
7862 {
7863 return gl::error(GL_INVALID_VALUE);
7864 }
7865
7866 switch (pname)
7867 {
7868 case GL_NUM_SAMPLE_COUNTS:
7869 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04007870 {
7871 *params = formatCaps.sampleCounts.size();
7872 }
Geoff Langbfdea662014-07-23 14:16:32 -04007873 break;
7874 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04007875 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04007876 break;
7877 default:
7878 return gl::error(GL_INVALID_ENUM);
7879 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007880 }
7881}
7882
7883// Extension functions
7884
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007885void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
7886 GLbitfield mask, GLenum filter)
7887{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007888 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007889 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
7890 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
7891 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
7892
Geoff Langbfdea662014-07-23 14:16:32 -04007893 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007894
Geoff Langbfdea662014-07-23 14:16:32 -04007895 if (context)
7896 {
7897 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
7898 dstX0, dstY0, dstX1, dstY1, mask, filter,
7899 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007900 {
Geoff Langbfdea662014-07-23 14:16:32 -04007901 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007902 }
Geoff Langbfdea662014-07-23 14:16:32 -04007903
7904 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
7905 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00007906 }
7907}
7908
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007909void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
7910 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007911{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007912 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007913 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007914 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007915 target, level, internalformat, width, height, depth, border, format, type, pixels);
7916
Geoff Langbfdea662014-07-23 14:16:32 -04007917 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007918}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00007919
Geoff Langbfdea662014-07-23 14:16:32 -04007920void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007921 GLenum *binaryFormat, void *binary)
7922{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00007923 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 +00007924 program, bufSize, length, binaryFormat, binary);
7925
Geoff Langbfdea662014-07-23 14:16:32 -04007926 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007927
Geoff Langbfdea662014-07-23 14:16:32 -04007928 if (context)
7929 {
7930 gl::Program *programObject = context->getProgram(program);
7931
7932 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007933 {
Geoff Langbfdea662014-07-23 14:16:32 -04007934 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007935 }
Geoff Langbfdea662014-07-23 14:16:32 -04007936
7937 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7938
7939 if (!programBinary)
7940 {
7941 return gl::error(GL_INVALID_OPERATION);
7942 }
7943
Geoff Lang900013c2014-07-07 11:32:19 -04007944 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04007945 {
7946 return gl::error(GL_INVALID_OPERATION);
7947 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007948 }
7949}
7950
7951void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
7952 const void *binary, GLint length)
7953{
7954 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
7955 program, binaryFormat, binary, length);
7956
Geoff Langbfdea662014-07-23 14:16:32 -04007957 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007958
Geoff Langbfdea662014-07-23 14:16:32 -04007959 if (context)
7960 {
Geoff Lang900013c2014-07-07 11:32:19 -04007961 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
7962 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007963 {
Geoff Langbfdea662014-07-23 14:16:32 -04007964 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007965 }
Geoff Langbfdea662014-07-23 14:16:32 -04007966
7967 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04007968 if (!programObject)
7969 {
7970 return gl::error(GL_INVALID_OPERATION);
7971 }
7972
Geoff Lang900013c2014-07-07 11:32:19 -04007973 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00007974 }
7975}
7976
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007977void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
7978{
7979 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
7980
Geoff Langbfdea662014-07-23 14:16:32 -04007981 gl::Context *context = gl::getNonLostContext();
7982
7983 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007984 {
Geoff Langbfdea662014-07-23 14:16:32 -04007985 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007986 {
Geoff Langbfdea662014-07-23 14:16:32 -04007987 return gl::error(GL_INVALID_VALUE);
7988 }
7989
7990 if (context->getState().getDrawFramebuffer()->id() == 0)
7991 {
7992 if (n != 1)
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.com4059a382013-04-13 03:31:16 +00007995 }
7996
Geoff Langbfdea662014-07-23 14:16:32 -04007997 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00007998 {
Geoff Langbfdea662014-07-23 14:16:32 -04007999 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008000 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008001 }
Geoff Langbfdea662014-07-23 14:16:32 -04008002 else
8003 {
8004 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8005 {
8006 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8007 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8008 {
8009 return gl::error(GL_INVALID_OPERATION);
8010 }
8011 }
8012 }
8013
8014 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8015
8016 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8017 {
8018 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8019 }
8020
8021 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8022 {
8023 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8024 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008025 }
8026}
8027
Shannon Woodsb3801742014-03-27 14:59:19 -04008028void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8029{
8030 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8031
Geoff Langbfdea662014-07-23 14:16:32 -04008032 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008033
Geoff Langbfdea662014-07-23 14:16:32 -04008034 if (context)
8035 {
8036 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008037 {
Geoff Langbfdea662014-07-23 14:16:32 -04008038 return gl::error(GL_INVALID_ENUM);
Shannon Woodsb3801742014-03-27 14:59:19 -04008039 }
Geoff Langbfdea662014-07-23 14:16:32 -04008040
8041 if (pname != GL_BUFFER_MAP_POINTER)
8042 {
8043 return gl::error(GL_INVALID_ENUM);
8044 }
8045
8046 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8047
8048 if (!buffer || !buffer->isMapped())
8049 {
8050 *params = NULL;
8051 }
8052 else
8053 {
8054 *params = buffer->getMapPointer();
8055 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008056 }
8057}
8058
8059void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8060{
8061 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8062
Geoff Langbfdea662014-07-23 14:16:32 -04008063 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008064
Geoff Langbfdea662014-07-23 14:16:32 -04008065 if (context)
8066 {
8067 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008068 {
Geoff Langbfdea662014-07-23 14:16:32 -04008069 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woodsb3801742014-03-27 14:59:19 -04008070 }
Geoff Langbfdea662014-07-23 14:16:32 -04008071
8072 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8073
8074 if (buffer == NULL)
8075 {
8076 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8077 }
8078
8079 if (access != GL_WRITE_ONLY_OES)
8080 {
8081 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
8082 }
8083
8084 if (buffer->isMapped())
8085 {
8086 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8087 }
8088
8089 return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
Shannon Woodsb3801742014-03-27 14:59:19 -04008090 }
8091
8092 return NULL;
8093}
8094
8095GLboolean __stdcall glUnmapBufferOES(GLenum target)
8096{
8097 EVENT("(GLenum target = 0x%X)", target);
8098
Geoff Langbfdea662014-07-23 14:16:32 -04008099 gl::Context *context = gl::getNonLostContext();
Shannon Woodsb3801742014-03-27 14:59:19 -04008100
Geoff Langbfdea662014-07-23 14:16:32 -04008101 if (context)
8102 {
8103 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008104 {
Geoff Langbfdea662014-07-23 14:16:32 -04008105 return gl::error(GL_INVALID_ENUM, GL_FALSE);
Shannon Woodsb3801742014-03-27 14:59:19 -04008106 }
Geoff Langbfdea662014-07-23 14:16:32 -04008107
8108 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8109
8110 if (buffer == NULL || !buffer->isMapped())
8111 {
8112 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8113 }
8114
8115 // TODO: detect if we had corruption. if so, throw an error and return false.
8116
8117 buffer->unmap();
8118
8119 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008120 }
8121
8122 return GL_FALSE;
8123}
8124
Shannon Woods916e7692014-03-27 16:58:22 -04008125void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8126{
8127 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8128 target, offset, length, access);
8129
Geoff Langbfdea662014-07-23 14:16:32 -04008130 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008131
Geoff Langbfdea662014-07-23 14:16:32 -04008132 if (context)
8133 {
8134 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008135 {
Geoff Langbfdea662014-07-23 14:16:32 -04008136 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
Shannon Woods916e7692014-03-27 16:58:22 -04008137 }
Geoff Langbfdea662014-07-23 14:16:32 -04008138
8139 if (offset < 0 || length < 0)
8140 {
8141 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8142 }
8143
8144 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8145
8146 if (buffer == NULL)
8147 {
8148 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8149 }
8150
8151 // Check for buffer overflow
8152 size_t offsetSize = static_cast<size_t>(offset);
8153 size_t lengthSize = static_cast<size_t>(length);
8154
8155 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8156 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8157 {
8158 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8159 }
8160
8161 // Check for invalid bits in the mask
8162 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8163 GL_MAP_WRITE_BIT |
8164 GL_MAP_INVALIDATE_RANGE_BIT |
8165 GL_MAP_INVALIDATE_BUFFER_BIT |
8166 GL_MAP_FLUSH_EXPLICIT_BIT |
8167 GL_MAP_UNSYNCHRONIZED_BIT;
8168
8169 if (access & ~(allAccessBits))
8170 {
8171 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
8172 }
8173
8174 if (length == 0 || buffer->isMapped())
8175 {
8176 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8177 }
8178
8179 // Check for invalid bit combinations
8180 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8181 {
8182 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8183 }
8184
8185 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8186 GL_MAP_INVALIDATE_BUFFER_BIT |
8187 GL_MAP_UNSYNCHRONIZED_BIT;
8188
8189 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8190 {
8191 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8192 }
8193
8194 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8195 {
8196 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8197 }
8198
8199 return buffer->mapRange(offset, length, access);
Shannon Woods916e7692014-03-27 16:58:22 -04008200 }
8201
8202 return NULL;
8203}
8204
8205void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8206{
8207 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8208
Geoff Langbfdea662014-07-23 14:16:32 -04008209 gl::Context *context = gl::getNonLostContext();
Shannon Woods916e7692014-03-27 16:58:22 -04008210
Geoff Langbfdea662014-07-23 14:16:32 -04008211 if (context)
8212 {
8213 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008214 {
Geoff Langbfdea662014-07-23 14:16:32 -04008215 return gl::error(GL_INVALID_VALUE);
Shannon Woods916e7692014-03-27 16:58:22 -04008216 }
Geoff Langbfdea662014-07-23 14:16:32 -04008217
8218 if (!gl::ValidBufferTarget(context, target))
8219 {
8220 return gl::error(GL_INVALID_ENUM);
8221 }
8222
8223 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8224
8225 if (buffer == NULL)
8226 {
8227 return gl::error(GL_INVALID_OPERATION);
8228 }
8229
8230 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8231 {
8232 return gl::error(GL_INVALID_OPERATION);
8233 }
8234
8235 // Check for buffer overflow
8236 size_t offsetSize = static_cast<size_t>(offset);
8237 size_t lengthSize = static_cast<size_t>(length);
8238
8239 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8240 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8241 {
8242 return gl::error(GL_INVALID_VALUE);
8243 }
8244
8245 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008246 }
8247}
8248
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008249__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8250{
8251 struct Extension
8252 {
8253 const char *name;
8254 __eglMustCastToProperFunctionPointerType address;
8255 };
8256
8257 static const Extension glExtensions[] =
8258 {
8259 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008260 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008261 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008262 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8263 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8264 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8265 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8266 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8267 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8268 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008269 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008270 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008271 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8272 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8273 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8274 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008275 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8276 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8277 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8278 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8279 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8280 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8281 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008282 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008283 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8284 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8285 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008286 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008287 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8288 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8289 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008290 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8291 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8292 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008293
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008294 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008295 {
8296 if (strcmp(procname, glExtensions[ext].name) == 0)
8297 {
8298 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8299 }
8300 }
8301
8302 return NULL;
8303}
8304
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008305// Non-public functions used by EGL
8306
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008307bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008308{
8309 EVENT("(egl::Surface* surface = 0x%0.8p)",
8310 surface);
8311
Geoff Langbfdea662014-07-23 14:16:32 -04008312 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008313
Geoff Langbfdea662014-07-23 14:16:32 -04008314 if (context)
8315 {
8316 gl::Texture2D *textureObject = context->getTexture2D();
8317 ASSERT(textureObject != NULL);
8318
8319 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008320 {
Geoff Langbfdea662014-07-23 14:16:32 -04008321 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008322 }
Geoff Langbfdea662014-07-23 14:16:32 -04008323
8324 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008325 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008326
8327 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008328}
8329
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008330}