blob: 25eb3bd774e91dba8d84a06a3ee1d183222cf001 [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();
Geoff Langbfdea662014-07-23 14:16:32 -040043 if (context)
44 {
Geoff Lang3a61c322014-07-10 13:01:54 -040045 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000046 {
Geoff Langb1196682014-07-23 13:47:29 -040047 context->recordError(gl::Error(GL_INVALID_ENUM));
48 return;
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();
Geoff Langbfdea662014-07-23 14:16:32 -040060 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000061 {
Geoff Langbfdea662014-07-23 14:16:32 -040062 gl::Program *programObject = context->getProgram(program);
63 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064
Geoff Langbfdea662014-07-23 14:16:32 -040065 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066 {
Geoff Langbfdea662014-07-23 14:16:32 -040067 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000068 {
Geoff Langb1196682014-07-23 13:47:29 -040069 context->recordError(gl::Error(GL_INVALID_OPERATION));
70 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000071 }
Geoff Langbfdea662014-07-23 14:16:32 -040072 else
73 {
Geoff Langb1196682014-07-23 13:47:29 -040074 context->recordError(gl::Error(GL_INVALID_VALUE));
75 return;
Geoff Langbfdea662014-07-23 14:16:32 -040076 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000077 }
Geoff Langbfdea662014-07-23 14:16:32 -040078
79 if (!shaderObject)
80 {
81 if (context->getProgram(shader))
82 {
Geoff Langb1196682014-07-23 13:47:29 -040083 context->recordError(gl::Error(GL_INVALID_OPERATION));
84 return;
Geoff Langbfdea662014-07-23 14:16:32 -040085 }
86 else
87 {
Geoff Langb1196682014-07-23 13:47:29 -040088 context->recordError(gl::Error(GL_INVALID_VALUE));
89 return;
Geoff Langbfdea662014-07-23 14:16:32 -040090 }
91 }
92
93 if (!programObject->attachShader(shaderObject))
94 {
Geoff Langb1196682014-07-23 13:47:29 -040095 context->recordError(gl::Error(GL_INVALID_OPERATION));
96 return;
Geoff Langbfdea662014-07-23 14:16:32 -040097 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098 }
99}
100
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000101void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
102{
103 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
104
Geoff Langbfdea662014-07-23 14:16:32 -0400105 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400106 if (context)
107 {
108 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000109 {
Geoff Langbfdea662014-07-23 14:16:32 -0400110 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000111 }
Geoff Langbfdea662014-07-23 14:16:32 -0400112
Geoff Lang5aad9672014-09-08 11:10:42 -0400113 gl::Error error = context->beginQuery(target, id);
114 if (error.isError())
115 {
116 context->recordError(error);
117 return;
118 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000119 }
120}
121
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000122void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000124 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
Geoff Langbfdea662014-07-23 14:16:32 -0400126 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400127 if (context)
128 {
Geoff Langb1196682014-07-23 13:47:29 -0400129 if (index >= gl::MAX_VERTEX_ATTRIBS)
130 {
131 context->recordError(gl::Error(GL_INVALID_VALUE));
132 return;
133 }
134
Geoff Langbfdea662014-07-23 14:16:32 -0400135 gl::Program *programObject = context->getProgram(program);
136
137 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000138 {
Geoff Langbfdea662014-07-23 14:16:32 -0400139 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000140 {
Geoff Langb1196682014-07-23 13:47:29 -0400141 context->recordError(gl::Error(GL_INVALID_OPERATION));
142 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000143 }
Geoff Langbfdea662014-07-23 14:16:32 -0400144 else
145 {
Geoff Langb1196682014-07-23 13:47:29 -0400146 context->recordError(gl::Error(GL_INVALID_VALUE));
147 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400148 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000149 }
Geoff Langbfdea662014-07-23 14:16:32 -0400150
151 if (strncmp(name, "gl_", 3) == 0)
152 {
Geoff Langb1196682014-07-23 13:47:29 -0400153 context->recordError(gl::Error(GL_INVALID_OPERATION));
154 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400155 }
156
157 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000158 }
159}
160
161void __stdcall glBindBuffer(GLenum target, GLuint buffer)
162{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000163 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000164
Geoff Langbfdea662014-07-23 14:16:32 -0400165 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400166 if (context)
167 {
168 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000169 {
Geoff Langb1196682014-07-23 13:47:29 -0400170 context->recordError(gl::Error(GL_INVALID_ENUM));
171 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000172 }
Geoff Langbfdea662014-07-23 14:16:32 -0400173
174 switch (target)
175 {
176 case GL_ARRAY_BUFFER:
177 context->bindArrayBuffer(buffer);
178 return;
179 case GL_ELEMENT_ARRAY_BUFFER:
180 context->bindElementArrayBuffer(buffer);
181 return;
182 case GL_COPY_READ_BUFFER:
183 context->bindCopyReadBuffer(buffer);
184 return;
185 case GL_COPY_WRITE_BUFFER:
186 context->bindCopyWriteBuffer(buffer);
187 return;
188 case GL_PIXEL_PACK_BUFFER:
189 context->bindPixelPackBuffer(buffer);
190 return;
191 case GL_PIXEL_UNPACK_BUFFER:
192 context->bindPixelUnpackBuffer(buffer);
193 return;
194 case GL_UNIFORM_BUFFER:
195 context->bindGenericUniformBuffer(buffer);
196 return;
197 case GL_TRANSFORM_FEEDBACK_BUFFER:
198 context->bindGenericTransformFeedbackBuffer(buffer);
199 return;
Geoff Langb1196682014-07-23 13:47:29 -0400200
Geoff Langbfdea662014-07-23 14:16:32 -0400201 default:
Geoff Langb1196682014-07-23 13:47:29 -0400202 context->recordError(gl::Error(GL_INVALID_ENUM));
203 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400204 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000205 }
206}
207
208void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000210 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000211
Geoff Langbfdea662014-07-23 14:16:32 -0400212 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400213 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000214 {
Geoff Langb1196682014-07-23 13:47:29 -0400215 if (!gl::ValidFramebufferTarget(target))
216 {
217 context->recordError(gl::Error(GL_INVALID_ENUM));
218 return;
219 }
220
Geoff Langbfdea662014-07-23 14:16:32 -0400221 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
222 {
223 context->bindReadFramebuffer(framebuffer);
224 }
225
226 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
227 {
228 context->bindDrawFramebuffer(framebuffer);
229 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000230 }
231}
232
233void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
234{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000235 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000236
Geoff Langbfdea662014-07-23 14:16:32 -0400237 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400238 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000239 {
Geoff Langb1196682014-07-23 13:47:29 -0400240 if (target != GL_RENDERBUFFER)
241 {
242 context->recordError(gl::Error(GL_INVALID_ENUM));
243 return;
244 }
245
Geoff Langbfdea662014-07-23 14:16:32 -0400246 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000247 }
248}
249
250void __stdcall glBindTexture(GLenum target, GLuint texture)
251{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000252 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000253
Geoff Langbfdea662014-07-23 14:16:32 -0400254 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400255 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000256 {
Geoff Langbfdea662014-07-23 14:16:32 -0400257 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000258
Geoff Langbfdea662014-07-23 14:16:32 -0400259 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000260 {
Geoff Langb1196682014-07-23 13:47:29 -0400261 context->recordError(gl::Error(GL_INVALID_OPERATION));
262 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400263 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000264
Geoff Langbfdea662014-07-23 14:16:32 -0400265 switch (target)
266 {
267 case GL_TEXTURE_2D:
Geoff Langbfdea662014-07-23 14:16:32 -0400268 case GL_TEXTURE_CUBE_MAP:
Geoff Lang76b10c92014-09-05 16:28:14 -0400269 break;
Geoff Langb1196682014-07-23 13:47:29 -0400270
Geoff Langbfdea662014-07-23 14:16:32 -0400271 case GL_TEXTURE_3D:
Geoff Langbfdea662014-07-23 14:16:32 -0400272 case GL_TEXTURE_2D_ARRAY:
273 if (context->getClientVersion() < 3)
274 {
Geoff Langb1196682014-07-23 13:47:29 -0400275 context->recordError(gl::Error(GL_INVALID_ENUM));
276 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400277 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400278 break;
Geoff Langb1196682014-07-23 13:47:29 -0400279
Geoff Langbfdea662014-07-23 14:16:32 -0400280 default:
Geoff Langb1196682014-07-23 13:47:29 -0400281 context->recordError(gl::Error(GL_INVALID_ENUM));
282 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000283 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400284
285 context->bindTexture(target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000286 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287}
288
289void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000291 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000292 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000293
Geoff Langbfdea662014-07-23 14:16:32 -0400294 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000295
Geoff Langbfdea662014-07-23 14:16:32 -0400296 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000297 {
Geoff Langbfdea662014-07-23 14:16:32 -0400298 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000299 }
300}
301
302void __stdcall glBlendEquation(GLenum mode)
303{
304 glBlendEquationSeparate(mode, mode);
305}
306
307void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
308{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000309 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000310
Geoff Langbfdea662014-07-23 14:16:32 -0400311 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400312 if (context)
313 {
Geoff Langb1196682014-07-23 13:47:29 -0400314 switch (modeRGB)
315 {
316 case GL_FUNC_ADD:
317 case GL_FUNC_SUBTRACT:
318 case GL_FUNC_REVERSE_SUBTRACT:
319 case GL_MIN:
320 case GL_MAX:
321 break;
322
323 default:
324 context->recordError(gl::Error(GL_INVALID_ENUM));
325 return;
326 }
327
328 switch (modeAlpha)
329 {
330 case GL_FUNC_ADD:
331 case GL_FUNC_SUBTRACT:
332 case GL_FUNC_REVERSE_SUBTRACT:
333 case GL_MIN:
334 case GL_MAX:
335 break;
336
337 default:
338 context->recordError(gl::Error(GL_INVALID_ENUM));
339 return;
340 }
341
Geoff Langbfdea662014-07-23 14:16:32 -0400342 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000343 }
344}
345
346void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
347{
348 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
349}
350
351void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
352{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000353 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 +0000354 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000355
Geoff Langbfdea662014-07-23 14:16:32 -0400356 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400357 if (context)
358 {
Geoff Langb1196682014-07-23 13:47:29 -0400359 switch (srcRGB)
360 {
361 case GL_ZERO:
362 case GL_ONE:
363 case GL_SRC_COLOR:
364 case GL_ONE_MINUS_SRC_COLOR:
365 case GL_DST_COLOR:
366 case GL_ONE_MINUS_DST_COLOR:
367 case GL_SRC_ALPHA:
368 case GL_ONE_MINUS_SRC_ALPHA:
369 case GL_DST_ALPHA:
370 case GL_ONE_MINUS_DST_ALPHA:
371 case GL_CONSTANT_COLOR:
372 case GL_ONE_MINUS_CONSTANT_COLOR:
373 case GL_CONSTANT_ALPHA:
374 case GL_ONE_MINUS_CONSTANT_ALPHA:
375 case GL_SRC_ALPHA_SATURATE:
376 break;
377
378 default:
379 context->recordError(gl::Error(GL_INVALID_ENUM));
380 return;
381 }
382
383 switch (dstRGB)
384 {
385 case GL_ZERO:
386 case GL_ONE:
387 case GL_SRC_COLOR:
388 case GL_ONE_MINUS_SRC_COLOR:
389 case GL_DST_COLOR:
390 case GL_ONE_MINUS_DST_COLOR:
391 case GL_SRC_ALPHA:
392 case GL_ONE_MINUS_SRC_ALPHA:
393 case GL_DST_ALPHA:
394 case GL_ONE_MINUS_DST_ALPHA:
395 case GL_CONSTANT_COLOR:
396 case GL_ONE_MINUS_CONSTANT_COLOR:
397 case GL_CONSTANT_ALPHA:
398 case GL_ONE_MINUS_CONSTANT_ALPHA:
399 break;
400
401 case GL_SRC_ALPHA_SATURATE:
402 if (context->getClientVersion() < 3)
403 {
404 context->recordError(gl::Error(GL_INVALID_ENUM));
405 return;
406 }
407 break;
408
409 default:
410 context->recordError(gl::Error(GL_INVALID_ENUM));
411 return;
412 }
413
414 switch (srcAlpha)
415 {
416 case GL_ZERO:
417 case GL_ONE:
418 case GL_SRC_COLOR:
419 case GL_ONE_MINUS_SRC_COLOR:
420 case GL_DST_COLOR:
421 case GL_ONE_MINUS_DST_COLOR:
422 case GL_SRC_ALPHA:
423 case GL_ONE_MINUS_SRC_ALPHA:
424 case GL_DST_ALPHA:
425 case GL_ONE_MINUS_DST_ALPHA:
426 case GL_CONSTANT_COLOR:
427 case GL_ONE_MINUS_CONSTANT_COLOR:
428 case GL_CONSTANT_ALPHA:
429 case GL_ONE_MINUS_CONSTANT_ALPHA:
430 case GL_SRC_ALPHA_SATURATE:
431 break;
432
433 default:
434 context->recordError(gl::Error(GL_INVALID_ENUM));
435 return;
436 }
437
438 switch (dstAlpha)
439 {
440 case GL_ZERO:
441 case GL_ONE:
442 case GL_SRC_COLOR:
443 case GL_ONE_MINUS_SRC_COLOR:
444 case GL_DST_COLOR:
445 case GL_ONE_MINUS_DST_COLOR:
446 case GL_SRC_ALPHA:
447 case GL_ONE_MINUS_SRC_ALPHA:
448 case GL_DST_ALPHA:
449 case GL_ONE_MINUS_DST_ALPHA:
450 case GL_CONSTANT_COLOR:
451 case GL_ONE_MINUS_CONSTANT_COLOR:
452 case GL_CONSTANT_ALPHA:
453 case GL_ONE_MINUS_CONSTANT_ALPHA:
454 break;
455
456 case GL_SRC_ALPHA_SATURATE:
457 if (context->getClientVersion() < 3)
458 {
459 context->recordError(gl::Error(GL_INVALID_ENUM));
460 return;
461 }
462 break;
463
464 default:
465 context->recordError(gl::Error(GL_INVALID_ENUM));
466 return;
467 }
468
469 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
470 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
471
472 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
473 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
474
475 if (constantColorUsed && constantAlphaUsed)
476 {
477 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
478 context->recordError(gl::Error(GL_INVALID_OPERATION));
479 return;
480 }
481
Geoff Langbfdea662014-07-23 14:16:32 -0400482 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000483 }
484}
485
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000486void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000487{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000488 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 +0000489 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000490
Geoff Langbfdea662014-07-23 14:16:32 -0400491 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400492 if (context)
493 {
Geoff Langb1196682014-07-23 13:47:29 -0400494 if (size < 0)
495 {
496 context->recordError(gl::Error(GL_INVALID_VALUE));
497 return;
498 }
499
500 switch (usage)
501 {
502 case GL_STREAM_DRAW:
503 case GL_STATIC_DRAW:
504 case GL_DYNAMIC_DRAW:
505 break;
506
507 case GL_STREAM_READ:
508 case GL_STREAM_COPY:
509 case GL_STATIC_READ:
510 case GL_STATIC_COPY:
511 case GL_DYNAMIC_READ:
512 case GL_DYNAMIC_COPY:
513 if (context->getClientVersion() < 3)
514 {
515 context->recordError(gl::Error(GL_INVALID_ENUM));
516 return;
517 }
518 break;
519
520 default:
521 context->recordError(gl::Error(GL_INVALID_ENUM));
522 return;
523 }
524
Geoff Langbfdea662014-07-23 14:16:32 -0400525 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000526 {
Geoff Langb1196682014-07-23 13:47:29 -0400527 context->recordError(gl::Error(GL_INVALID_ENUM));
528 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000529 }
530
Geoff Langbfdea662014-07-23 14:16:32 -0400531 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
532
533 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000534 {
Geoff Langb1196682014-07-23 13:47:29 -0400535 context->recordError(gl::Error(GL_INVALID_OPERATION));
536 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000537 }
Geoff Langbfdea662014-07-23 14:16:32 -0400538
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400539 gl::Error error = buffer->bufferData(data, size, usage);
540 if (error.isError())
541 {
542 context->recordError(error);
543 return;
544 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000545 }
546}
547
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000548void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000549{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000550 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 +0000551 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000552
Geoff Langbfdea662014-07-23 14:16:32 -0400553 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400554 if (context)
555 {
Geoff Langb1196682014-07-23 13:47:29 -0400556 if (size < 0 || offset < 0)
557 {
558 context->recordError(gl::Error(GL_INVALID_VALUE));
559 return;
560 }
561
562 if (data == NULL)
563 {
564 return;
565 }
566
Geoff Langbfdea662014-07-23 14:16:32 -0400567 if (!gl::ValidBufferTarget(context, target))
568 {
Geoff Langb1196682014-07-23 13:47:29 -0400569 context->recordError(gl::Error(GL_INVALID_ENUM));
570 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400571 }
572
573 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
574
575 if (!buffer)
576 {
Geoff Langb1196682014-07-23 13:47:29 -0400577 context->recordError(gl::Error(GL_INVALID_OPERATION));
578 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400579 }
580
581 if (buffer->isMapped())
582 {
Geoff Langb1196682014-07-23 13:47:29 -0400583 context->recordError(gl::Error(GL_INVALID_OPERATION));
584 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400585 }
586
587 // Check for possible overflow of size + offset
588 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
589 {
Geoff Langb1196682014-07-23 13:47:29 -0400590 context->recordError(gl::Error(GL_OUT_OF_MEMORY));
591 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400592 }
593
594 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000595 {
Geoff Langb1196682014-07-23 13:47:29 -0400596 context->recordError(gl::Error(GL_INVALID_VALUE));
597 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000598 }
599
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400600 gl::Error error = buffer->bufferSubData(data, size, offset);
601 if (error.isError())
602 {
603 context->recordError(error);
604 return;
605 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000606 }
607}
608
609GLenum __stdcall glCheckFramebufferStatus(GLenum target)
610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000611 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000612
Geoff Langbfdea662014-07-23 14:16:32 -0400613 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400614 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000615 {
Geoff Langb1196682014-07-23 13:47:29 -0400616 if (!gl::ValidFramebufferTarget(target))
617 {
618 context->recordError(gl::Error(GL_INVALID_ENUM));
619 return 0;
620 }
621
Geoff Langbfdea662014-07-23 14:16:32 -0400622 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
623 ASSERT(framebuffer);
624 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625 }
626
627 return 0;
628}
629
630void __stdcall glClear(GLbitfield mask)
631{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000632 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000633
Geoff Langbfdea662014-07-23 14:16:32 -0400634 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400635 if (context)
636 {
637 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
638
639 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000640 {
Geoff Langb1196682014-07-23 13:47:29 -0400641 context->recordError(gl::Error(GL_INVALID_FRAMEBUFFER_OPERATION));
642 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000643 }
Geoff Langbfdea662014-07-23 14:16:32 -0400644
645 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
646 {
Geoff Langb1196682014-07-23 13:47:29 -0400647 context->recordError(gl::Error(GL_INVALID_VALUE));
648 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400649 }
650
Geoff Langcc79b8c2014-07-25 13:48:02 -0400651 gl::Error error = context->clear(mask);
652 if (error.isError())
653 {
654 context->recordError(error);
655 return;
656 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000657 }
658}
659
660void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000662 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000663 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000664
Geoff Langbfdea662014-07-23 14:16:32 -0400665 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400666 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000667 {
Geoff Langbfdea662014-07-23 14:16:32 -0400668 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000669 }
670}
671
672void __stdcall glClearDepthf(GLclampf depth)
673{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000674 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000675
Geoff Langbfdea662014-07-23 14:16:32 -0400676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400677 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000678 {
Geoff Langbfdea662014-07-23 14:16:32 -0400679 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000680 }
681}
682
683void __stdcall glClearStencil(GLint s)
684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000685 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000686
Geoff Langbfdea662014-07-23 14:16:32 -0400687 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400688 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000689 {
Geoff Langbfdea662014-07-23 14:16:32 -0400690 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000691 }
692}
693
694void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
695{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000696 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000697 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000698
Geoff Langbfdea662014-07-23 14:16:32 -0400699 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400700 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000701 {
Geoff Langbfdea662014-07-23 14:16:32 -0400702 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000703 }
704}
705
706void __stdcall glCompileShader(GLuint shader)
707{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000708 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000709
Geoff Langbfdea662014-07-23 14:16:32 -0400710 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400711 if (context)
712 {
713 gl::Shader *shaderObject = context->getShader(shader);
714
715 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000716 {
Geoff Langbfdea662014-07-23 14:16:32 -0400717 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000718 {
Geoff Langb1196682014-07-23 13:47:29 -0400719 context->recordError(gl::Error(GL_INVALID_OPERATION));
720 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000721 }
Geoff Langbfdea662014-07-23 14:16:32 -0400722 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000723 {
Geoff Langb1196682014-07-23 13:47:29 -0400724 context->recordError(gl::Error(GL_INVALID_VALUE));
725 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000726 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000727 }
Geoff Langbfdea662014-07-23 14:16:32 -0400728
729 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000730 }
Geoff Langbfdea662014-07-23 14:16:32 -0400731}
732
733void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
734 GLint border, GLsizei imageSize, const GLvoid* data)
735{
736 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
737 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
738 target, level, internalformat, width, height, border, imageSize, data);
739
740 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400741 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000742 {
Geoff Langbfdea662014-07-23 14:16:32 -0400743 if (context->getClientVersion() < 3 &&
744 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
745 0, 0, width, height, border, GL_NONE, GL_NONE, data))
746 {
747 return;
748 }
749
750 if (context->getClientVersion() >= 3 &&
751 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
752 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
753 {
754 return;
755 }
756
Geoff Lang5d601382014-07-22 15:14:06 -0400757 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
758 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400759 {
Geoff Langb1196682014-07-23 13:47:29 -0400760 context->recordError(gl::Error(GL_INVALID_VALUE));
761 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400762 }
763
764 switch (target)
765 {
766 case GL_TEXTURE_2D:
767 {
768 gl::Texture2D *texture = context->getTexture2D();
769 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
770 }
771 break;
772
773 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
774 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
775 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
776 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
777 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
778 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
779 {
780 gl::TextureCubeMap *texture = context->getTextureCubeMap();
781 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
782 }
783 break;
784
785 default:
Geoff Langb1196682014-07-23 13:47:29 -0400786 context->recordError(gl::Error(GL_INVALID_ENUM));
787 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400788 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000789 }
790}
791
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000792void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
793 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000794{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000795 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000796 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000797 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000798 target, level, xoffset, yoffset, width, height, format, imageSize, data);
799
Geoff Langbfdea662014-07-23 14:16:32 -0400800 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400801 if (context)
802 {
803 if (context->getClientVersion() < 3 &&
804 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
805 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000806 {
Geoff Langbfdea662014-07-23 14:16:32 -0400807 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000808 }
Geoff Langbfdea662014-07-23 14:16:32 -0400809
810 if (context->getClientVersion() >= 3 &&
811 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
812 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
813 {
814 return;
815 }
816
Geoff Lang5d601382014-07-22 15:14:06 -0400817 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
818 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400819 {
Geoff Langb1196682014-07-23 13:47:29 -0400820 context->recordError(gl::Error(GL_INVALID_VALUE));
821 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400822 }
823
824 switch (target)
825 {
826 case GL_TEXTURE_2D:
827 {
828 gl::Texture2D *texture = context->getTexture2D();
829 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
830 }
831 break;
832
833 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
834 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
835 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
836 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
837 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
838 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
839 {
840 gl::TextureCubeMap *texture = context->getTextureCubeMap();
841 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
842 }
843 break;
844
845 default:
Geoff Langb1196682014-07-23 13:47:29 -0400846 context->recordError(gl::Error(GL_INVALID_ENUM));
847 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400848 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000849 }
850}
851
852void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
853{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000854 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000855 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000856 target, level, internalformat, x, y, width, height, border);
857
Geoff Langbfdea662014-07-23 14:16:32 -0400858 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400859 if (context)
860 {
861 if (context->getClientVersion() < 3 &&
862 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
863 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000864 {
Geoff Langbfdea662014-07-23 14:16:32 -0400865 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000866 }
Geoff Langbfdea662014-07-23 14:16:32 -0400867
868 if (context->getClientVersion() >= 3 &&
869 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
870 0, 0, 0, x, y, width, height, border))
871 {
872 return;
873 }
874
875 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
876
877 switch (target)
878 {
879 case GL_TEXTURE_2D:
880 {
881 gl::Texture2D *texture = context->getTexture2D();
882 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
883 }
884 break;
885
886 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
887 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
888 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
889 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
890 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
891 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
892 {
893 gl::TextureCubeMap *texture = context->getTextureCubeMap();
894 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
895 }
896 break;
897
Geoff Langb1196682014-07-23 13:47:29 -0400898 default:
899 context->recordError(gl::Error(GL_INVALID_ENUM));
900 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400901 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000902 }
903}
904
905void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
906{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000907 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000908 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000909 target, level, xoffset, yoffset, x, y, width, height);
910
Geoff Langbfdea662014-07-23 14:16:32 -0400911 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400912 if (context)
913 {
914 if (context->getClientVersion() < 3 &&
915 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
916 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000917 {
Geoff Langbfdea662014-07-23 14:16:32 -0400918 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000919 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000920
Geoff Langbfdea662014-07-23 14:16:32 -0400921 if (context->getClientVersion() >= 3 &&
922 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
923 xoffset, yoffset, 0, x, y, width, height, 0))
924 {
925 return;
926 }
927
928 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
929
930 switch (target)
931 {
932 case GL_TEXTURE_2D:
933 {
934 gl::Texture2D *texture = context->getTexture2D();
935 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
936 }
937 break;
938
939 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
940 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
941 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
942 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
943 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
944 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
945 {
946 gl::TextureCubeMap *texture = context->getTextureCubeMap();
947 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
948 }
949 break;
950
951 default:
Geoff Langb1196682014-07-23 13:47:29 -0400952 context->recordError(gl::Error(GL_INVALID_ENUM));
953 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400954 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000955 }
956}
957
958GLuint __stdcall glCreateProgram(void)
959{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000960 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000961
Geoff Langbfdea662014-07-23 14:16:32 -0400962 gl::Context *context = gl::getNonLostContext();
963 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000964 {
Geoff Langbfdea662014-07-23 14:16:32 -0400965 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000966 }
967
968 return 0;
969}
970
971GLuint __stdcall glCreateShader(GLenum type)
972{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000973 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000974
Geoff Langbfdea662014-07-23 14:16:32 -0400975 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400976 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000977 {
Geoff Langbfdea662014-07-23 14:16:32 -0400978 switch (type)
979 {
980 case GL_FRAGMENT_SHADER:
981 case GL_VERTEX_SHADER:
982 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -0400983
Geoff Langbfdea662014-07-23 14:16:32 -0400984 default:
Geoff Langb1196682014-07-23 13:47:29 -0400985 context->recordError(gl::Error(GL_INVALID_ENUM));
986 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -0400987 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000988 }
989
990 return 0;
991}
992
993void __stdcall glCullFace(GLenum mode)
994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000995 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000996
Geoff Langb1196682014-07-23 13:47:29 -0400997 gl::Context *context = gl::getNonLostContext();
998 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000999 {
Geoff Langb1196682014-07-23 13:47:29 -04001000 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001001 {
Geoff Langb1196682014-07-23 13:47:29 -04001002 case GL_FRONT:
1003 case GL_BACK:
1004 case GL_FRONT_AND_BACK:
1005 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001006
Geoff Langb1196682014-07-23 13:47:29 -04001007 default:
1008 context->recordError(gl::Error(GL_INVALID_ENUM));
1009 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001010 }
Geoff Langb1196682014-07-23 13:47:29 -04001011
1012 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001013 }
1014}
1015
1016void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
1017{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001018 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001019
Geoff Langbfdea662014-07-23 14:16:32 -04001020 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001021 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001022 {
Geoff Langb1196682014-07-23 13:47:29 -04001023 if (n < 0)
1024 {
1025 context->recordError(gl::Error(GL_INVALID_VALUE));
1026 return;
1027 }
1028
Geoff Langbfdea662014-07-23 14:16:32 -04001029 for (int i = 0; i < n; i++)
1030 {
1031 context->deleteBuffer(buffers[i]);
1032 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001033 }
1034}
1035
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001036void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
1037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001038 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001039
Geoff Langbfdea662014-07-23 14:16:32 -04001040 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001041 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001042 {
Geoff Langb1196682014-07-23 13:47:29 -04001043 if (n < 0)
1044 {
1045 context->recordError(gl::Error(GL_INVALID_VALUE));
1046 return;
1047 }
1048
Geoff Langbfdea662014-07-23 14:16:32 -04001049 for (int i = 0; i < n; i++)
1050 {
1051 context->deleteFenceNV(fences[i]);
1052 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001053 }
1054}
1055
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001056void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1057{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001058 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001059
Geoff Langbfdea662014-07-23 14:16:32 -04001060 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001061 if (context)
1062 {
Geoff Langb1196682014-07-23 13:47:29 -04001063 if (n < 0)
1064 {
1065 context->recordError(gl::Error(GL_INVALID_VALUE));
1066 return;
1067 }
1068
Geoff Langbfdea662014-07-23 14:16:32 -04001069 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001070 {
Geoff Langbfdea662014-07-23 14:16:32 -04001071 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001072 {
Geoff Langbfdea662014-07-23 14:16:32 -04001073 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001074 }
1075 }
1076 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001077}
1078
1079void __stdcall glDeleteProgram(GLuint program)
1080{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001081 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001082
Geoff Langbfdea662014-07-23 14:16:32 -04001083 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001084 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001085 {
Geoff Langb1196682014-07-23 13:47:29 -04001086 if (program == 0)
1087 {
1088 return;
1089 }
1090
Geoff Langbfdea662014-07-23 14:16:32 -04001091 if (!context->getProgram(program))
1092 {
1093 if(context->getShader(program))
1094 {
Geoff Langb1196682014-07-23 13:47:29 -04001095 context->recordError(gl::Error(GL_INVALID_OPERATION));
1096 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001097 }
1098 else
1099 {
Geoff Langb1196682014-07-23 13:47:29 -04001100 context->recordError(gl::Error(GL_INVALID_VALUE));
1101 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001102 }
1103 }
1104
1105 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001106 }
1107}
1108
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001109void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1110{
1111 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1112
Geoff Langbfdea662014-07-23 14:16:32 -04001113 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001114 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001115 {
Geoff Langb1196682014-07-23 13:47:29 -04001116 if (n < 0)
1117 {
1118 context->recordError(gl::Error(GL_INVALID_VALUE));
1119 return;
1120 }
1121
Geoff Langbfdea662014-07-23 14:16:32 -04001122 for (int i = 0; i < n; i++)
1123 {
1124 context->deleteQuery(ids[i]);
1125 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001126 }
1127}
1128
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001129void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1130{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001131 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001132
Geoff Langbfdea662014-07-23 14:16:32 -04001133 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001134 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001135 {
Geoff Langb1196682014-07-23 13:47:29 -04001136 if (n < 0)
1137 {
1138 context->recordError(gl::Error(GL_INVALID_VALUE));
1139 return;
1140 }
1141
Geoff Langbfdea662014-07-23 14:16:32 -04001142 for (int i = 0; i < n; i++)
1143 {
1144 context->deleteRenderbuffer(renderbuffers[i]);
1145 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001146 }
1147}
1148
1149void __stdcall glDeleteShader(GLuint shader)
1150{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001151 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001152
Geoff Langbfdea662014-07-23 14:16:32 -04001153 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001154 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001155 {
Geoff Langb1196682014-07-23 13:47:29 -04001156 if (shader == 0)
1157 {
1158 return;
1159 }
1160
Geoff Langbfdea662014-07-23 14:16:32 -04001161 if (!context->getShader(shader))
1162 {
1163 if(context->getProgram(shader))
1164 {
Geoff Langb1196682014-07-23 13:47:29 -04001165 context->recordError(gl::Error(GL_INVALID_OPERATION));
1166 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001167 }
1168 else
1169 {
Geoff Langb1196682014-07-23 13:47:29 -04001170 context->recordError(gl::Error(GL_INVALID_VALUE));
1171 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001172 }
1173 }
1174
1175 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001176 }
1177}
1178
1179void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1180{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001181 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001182
Geoff Langbfdea662014-07-23 14:16:32 -04001183 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001184 if (context)
1185 {
Geoff Langb1196682014-07-23 13:47:29 -04001186 if (n < 0)
1187 {
1188 context->recordError(gl::Error(GL_INVALID_VALUE));
1189 return;
1190 }
1191
Geoff Langbfdea662014-07-23 14:16:32 -04001192 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001193 {
Geoff Langbfdea662014-07-23 14:16:32 -04001194 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001195 {
Geoff Langbfdea662014-07-23 14:16:32 -04001196 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001197 }
1198 }
1199 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001200}
1201
1202void __stdcall glDepthFunc(GLenum func)
1203{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001204 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001205
Geoff Langbfdea662014-07-23 14:16:32 -04001206 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001207 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001208 {
Geoff Langb1196682014-07-23 13:47:29 -04001209 switch (func)
1210 {
1211 case GL_NEVER:
1212 case GL_ALWAYS:
1213 case GL_LESS:
1214 case GL_LEQUAL:
1215 case GL_EQUAL:
1216 case GL_GREATER:
1217 case GL_GEQUAL:
1218 case GL_NOTEQUAL:
1219 context->getState().setDepthFunc(func);
1220 break;
1221
1222 default:
1223 context->recordError(gl::Error(GL_INVALID_ENUM));
1224 return;
1225 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001226 }
1227}
1228
1229void __stdcall glDepthMask(GLboolean flag)
1230{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001231 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001232
Geoff Langbfdea662014-07-23 14:16:32 -04001233 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001234 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001235 {
Geoff Langbfdea662014-07-23 14:16:32 -04001236 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001237 }
1238}
1239
1240void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1241{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001242 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001243
Geoff Langbfdea662014-07-23 14:16:32 -04001244 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001245 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001246 {
Geoff Langbfdea662014-07-23 14:16:32 -04001247 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001248 }
1249}
1250
1251void __stdcall glDetachShader(GLuint program, GLuint shader)
1252{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001253 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001254
Geoff Langbfdea662014-07-23 14:16:32 -04001255 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001256 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001257 {
Geoff Langbfdea662014-07-23 14:16:32 -04001258 gl::Program *programObject = context->getProgram(program);
1259 gl::Shader *shaderObject = context->getShader(shader);
1260
1261 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001262 {
Geoff Langbfdea662014-07-23 14:16:32 -04001263 gl::Shader *shaderByProgramHandle;
1264 shaderByProgramHandle = context->getShader(program);
1265 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266 {
Geoff Langb1196682014-07-23 13:47:29 -04001267 context->recordError(gl::Error(GL_INVALID_VALUE));
1268 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001269 }
Geoff Langbfdea662014-07-23 14:16:32 -04001270 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001271 {
Geoff Langb1196682014-07-23 13:47:29 -04001272 context->recordError(gl::Error(GL_INVALID_OPERATION));
1273 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001274 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001275 }
Geoff Langbfdea662014-07-23 14:16:32 -04001276
1277 if (!shaderObject)
1278 {
1279 gl::Program *programByShaderHandle = context->getProgram(shader);
1280 if (!programByShaderHandle)
1281 {
Geoff Langb1196682014-07-23 13:47:29 -04001282 context->recordError(gl::Error(GL_INVALID_VALUE));
1283 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001284 }
1285 else
1286 {
Geoff Langb1196682014-07-23 13:47:29 -04001287 context->recordError(gl::Error(GL_INVALID_OPERATION));
1288 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001289 }
1290 }
1291
1292 if (!programObject->detachShader(shaderObject))
1293 {
Geoff Langb1196682014-07-23 13:47:29 -04001294 context->recordError(gl::Error(GL_INVALID_OPERATION));
1295 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001296 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001297 }
1298}
1299
1300void __stdcall glDisable(GLenum cap)
1301{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001302 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001303
Geoff Langbfdea662014-07-23 14:16:32 -04001304 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001305 if (context)
1306 {
1307 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001308 {
Geoff Langb1196682014-07-23 13:47:29 -04001309 context->recordError(gl::Error(GL_INVALID_ENUM));
1310 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001311 }
Geoff Langbfdea662014-07-23 14:16:32 -04001312
1313 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001314 }
1315}
1316
1317void __stdcall glDisableVertexAttribArray(GLuint index)
1318{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001319 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001320
Geoff Langbfdea662014-07-23 14:16:32 -04001321 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001322 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001323 {
Geoff Langb1196682014-07-23 13:47:29 -04001324 if (index >= gl::MAX_VERTEX_ATTRIBS)
1325 {
1326 context->recordError(gl::Error(GL_INVALID_VALUE));
1327 return;
1328 }
1329
Geoff Langbfdea662014-07-23 14:16:32 -04001330 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001331 }
1332}
1333
1334void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1335{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001336 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001337
Geoff Langbfdea662014-07-23 14:16:32 -04001338 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001339 if (context)
1340 {
Jamie Madill2b976812014-08-25 15:47:49 -04001341 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001342 {
Geoff Langbfdea662014-07-23 14:16:32 -04001343 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001344 }
Geoff Langbfdea662014-07-23 14:16:32 -04001345
Geoff Langc77e8c32014-09-08 16:28:24 -04001346 gl::Error error = context->drawArrays(mode, first, count, 0);
1347 if (error.isError())
1348 {
1349 context->recordError(error);
1350 return;
1351 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001352 }
1353}
1354
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001355void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1356{
1357 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1358
Geoff Langbfdea662014-07-23 14:16:32 -04001359 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001360 if (context)
1361 {
Geoff Lang87a93302014-09-16 13:29:43 -04001362 if (!ValidateDrawArraysInstancedANGLE(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001363 {
Geoff Langbfdea662014-07-23 14:16:32 -04001364 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001365 }
Geoff Langbfdea662014-07-23 14:16:32 -04001366
Geoff Langc77e8c32014-09-08 16:28:24 -04001367 gl::Error error = context->drawArrays(mode, first, count, primcount);
1368 if (error.isError())
1369 {
1370 context->recordError(error);
1371 return;
1372 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001373 }
1374}
1375
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001376void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001377{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001378 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 +00001379 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001380
Geoff Langbfdea662014-07-23 14:16:32 -04001381 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001382 if (context)
1383 {
Jamie Madill2b976812014-08-25 15:47:49 -04001384 rx::RangeUI indexRange;
1385 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001386 {
Geoff Langbfdea662014-07-23 14:16:32 -04001387 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001388 }
Geoff Langbfdea662014-07-23 14:16:32 -04001389
Geoff Langc77e8c32014-09-08 16:28:24 -04001390 gl::Error error = context->drawElements(mode, count, type, indices, 0, indexRange);
1391 if (error.isError())
1392 {
1393 context->recordError(error);
1394 return;
1395 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001396 }
1397}
1398
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001399void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1400{
1401 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1402 mode, count, type, indices, primcount);
1403
Geoff Langbfdea662014-07-23 14:16:32 -04001404 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001405 if (context)
1406 {
Jamie Madill2b976812014-08-25 15:47:49 -04001407 rx::RangeUI indexRange;
Geoff Lang87a93302014-09-16 13:29:43 -04001408 if (!ValidateDrawElementsInstancedANGLE(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001409 {
Geoff Langbfdea662014-07-23 14:16:32 -04001410 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001411 }
Geoff Langbfdea662014-07-23 14:16:32 -04001412
Geoff Langc77e8c32014-09-08 16:28:24 -04001413 gl::Error error = context->drawElements(mode, count, type, indices, primcount, indexRange);
1414 if (error.isError())
1415 {
1416 context->recordError(error);
1417 return;
1418 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001419 }
1420}
1421
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001422void __stdcall glEnable(GLenum cap)
1423{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001424 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001425
Geoff Langbfdea662014-07-23 14:16:32 -04001426 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001427 if (context)
1428 {
1429 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001430 {
Geoff Langb1196682014-07-23 13:47:29 -04001431 context->recordError(gl::Error(GL_INVALID_ENUM));
1432 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001433 }
Geoff Langbfdea662014-07-23 14:16:32 -04001434
1435 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001436 }
1437}
1438
1439void __stdcall glEnableVertexAttribArray(GLuint index)
1440{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001441 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001442
Geoff Langbfdea662014-07-23 14:16:32 -04001443 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001444 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001445 {
Geoff Langb1196682014-07-23 13:47:29 -04001446 if (index >= gl::MAX_VERTEX_ATTRIBS)
1447 {
1448 context->recordError(gl::Error(GL_INVALID_VALUE));
1449 return;
1450 }
1451
Geoff Langbfdea662014-07-23 14:16:32 -04001452 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453 }
1454}
1455
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001456void __stdcall glEndQueryEXT(GLenum target)
1457{
1458 EVENT("GLenum target = 0x%X)", target);
1459
Geoff Langbfdea662014-07-23 14:16:32 -04001460 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001461 if (context)
1462 {
1463 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001464 {
Geoff Langbfdea662014-07-23 14:16:32 -04001465 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001466 }
Geoff Langbfdea662014-07-23 14:16:32 -04001467
Geoff Lang5aad9672014-09-08 11:10:42 -04001468 gl::Error error = context->endQuery(target);
1469 if (error.isError())
1470 {
1471 context->recordError(error);
1472 return;
1473 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001474 }
1475}
1476
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001477void __stdcall glFinishFenceNV(GLuint fence)
1478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001479 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001480
Geoff Langbfdea662014-07-23 14:16:32 -04001481 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001482 if (context)
1483 {
1484 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1485
1486 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001487 {
Geoff Langb1196682014-07-23 13:47:29 -04001488 context->recordError(gl::Error(GL_INVALID_OPERATION));
1489 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001490 }
Geoff Langbfdea662014-07-23 14:16:32 -04001491
1492 if (fenceObject->isFence() != GL_TRUE)
1493 {
Geoff Langb1196682014-07-23 13:47:29 -04001494 context->recordError(gl::Error(GL_INVALID_OPERATION));
1495 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001496 }
1497
1498 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001499 }
1500}
1501
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001502void __stdcall glFinish(void)
1503{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001504 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001505
Geoff Langbfdea662014-07-23 14:16:32 -04001506 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001507 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001508 {
Geoff Langbfdea662014-07-23 14:16:32 -04001509 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001510 }
1511}
1512
1513void __stdcall glFlush(void)
1514{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001515 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001516
Geoff Langbfdea662014-07-23 14:16:32 -04001517 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001518 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001519 {
Geoff Langbfdea662014-07-23 14:16:32 -04001520 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001521 }
1522}
1523
1524void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1525{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001526 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001527 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001528
Geoff Langbfdea662014-07-23 14:16:32 -04001529 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001530 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001531 {
Geoff Langb1196682014-07-23 13:47:29 -04001532 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1533 {
1534 context->recordError(gl::Error(GL_INVALID_ENUM));
1535 return;
1536 }
1537
Geoff Langbfdea662014-07-23 14:16:32 -04001538 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1539 {
1540 return;
1541 }
1542
1543 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1544 ASSERT(framebuffer);
1545
1546 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1547 {
1548 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1549 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1550 }
1551 else
1552 {
1553 switch (attachment)
1554 {
1555 case GL_DEPTH_ATTACHMENT:
1556 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1557 break;
1558 case GL_STENCIL_ATTACHMENT:
1559 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1560 break;
1561 case GL_DEPTH_STENCIL_ATTACHMENT:
1562 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1563 break;
1564 default:
1565 UNREACHABLE();
1566 break;
1567 }
1568 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001569 }
1570}
1571
1572void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1573{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001574 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001575 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001576
Geoff Langbfdea662014-07-23 14:16:32 -04001577 gl::Context *context = gl::getNonLostContext();
1578 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001579 {
Geoff Langbfdea662014-07-23 14:16:32 -04001580 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001581 {
Geoff Langbfdea662014-07-23 14:16:32 -04001582 return;
1583 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001584
Geoff Langbfdea662014-07-23 14:16:32 -04001585 if (texture == 0)
1586 {
1587 textarget = GL_NONE;
1588 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001589
Geoff Langbfdea662014-07-23 14:16:32 -04001590 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001591
Geoff Langbfdea662014-07-23 14:16:32 -04001592 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1593 {
1594 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1595 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1596 }
1597 else
1598 {
1599 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001600 {
Geoff Langbfdea662014-07-23 14:16:32 -04001601 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1602 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1603 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001604 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001605 }
1606 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001607}
1608
1609void __stdcall glFrontFace(GLenum mode)
1610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001611 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001612
Geoff Langb1196682014-07-23 13:47:29 -04001613 gl::Context *context = gl::getNonLostContext();
1614 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001615 {
Geoff Langb1196682014-07-23 13:47:29 -04001616 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001617 {
Geoff Langb1196682014-07-23 13:47:29 -04001618 case GL_CW:
1619 case GL_CCW:
1620 context->getState().setFrontFace(mode);
1621 break;
1622 default:
1623 context->recordError(gl::Error(GL_INVALID_ENUM));
1624 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001625 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001626 }
1627}
1628
1629void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1630{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001631 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001632
Geoff Langbfdea662014-07-23 14:16:32 -04001633 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001634 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001635 {
Geoff Langb1196682014-07-23 13:47:29 -04001636 if (n < 0)
1637 {
1638 context->recordError(gl::Error(GL_INVALID_VALUE));
1639 return;
1640 }
1641
Geoff Langbfdea662014-07-23 14:16:32 -04001642 for (int i = 0; i < n; i++)
1643 {
1644 buffers[i] = context->createBuffer();
1645 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001646 }
1647}
1648
1649void __stdcall glGenerateMipmap(GLenum target)
1650{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001651 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001652
Geoff Langbfdea662014-07-23 14:16:32 -04001653 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001654 if (context)
1655 {
1656 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001657 {
Geoff Langb1196682014-07-23 13:47:29 -04001658 context->recordError(gl::Error(GL_INVALID_ENUM));
1659 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001660 }
Geoff Langbfdea662014-07-23 14:16:32 -04001661
1662 gl::Texture *texture = context->getTargetTexture(target);
1663
1664 if (texture == NULL)
1665 {
Geoff Langb1196682014-07-23 13:47:29 -04001666 context->recordError(gl::Error(GL_INVALID_OPERATION));
1667 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001668 }
1669
1670 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1671 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001672 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001673
1674 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1675 // unsized formats or that are color renderable and filterable. Since we do not track if
1676 // the texture was created with sized or unsized format (only sized formats are stored),
1677 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1678 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1679 // textures since they're the only texture format that can be created with unsized formats
1680 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1681 // was the last version to use add them.
1682 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1683 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1684 internalFormat == GL_ALPHA8_EXT;
1685
Geoff Lang5d601382014-07-22 15:14:06 -04001686 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1687 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001688 {
Geoff Langb1196682014-07-23 13:47:29 -04001689 context->recordError(gl::Error(GL_INVALID_OPERATION));
1690 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001691 }
1692
1693 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001694 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001695 {
Geoff Langb1196682014-07-23 13:47:29 -04001696 context->recordError(gl::Error(GL_INVALID_OPERATION));
1697 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001698 }
1699
1700 // Non-power of 2 ES2 check
1701 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1702 {
1703 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001704 context->recordError(gl::Error(GL_INVALID_OPERATION));
1705 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001706 }
1707
1708 // Cube completeness check
1709 if (target == GL_TEXTURE_CUBE_MAP)
1710 {
1711 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1712 if (!textureCube->isCubeComplete())
1713 {
Geoff Langb1196682014-07-23 13:47:29 -04001714 context->recordError(gl::Error(GL_INVALID_OPERATION));
1715 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001716 }
1717 }
1718
1719 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001720 }
1721}
1722
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001723void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1724{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001725 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001726
Geoff Langbfdea662014-07-23 14:16:32 -04001727 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001728 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001729 {
Geoff Langb1196682014-07-23 13:47:29 -04001730 if (n < 0)
1731 {
1732 context->recordError(gl::Error(GL_INVALID_VALUE));
1733 return;
1734 }
1735
Geoff Langbfdea662014-07-23 14:16:32 -04001736 for (int i = 0; i < n; i++)
1737 {
1738 fences[i] = context->createFenceNV();
1739 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001740 }
1741}
1742
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001743void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1744{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001745 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001746
Geoff Langbfdea662014-07-23 14:16:32 -04001747 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001748 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001749 {
Geoff Langb1196682014-07-23 13:47:29 -04001750 if (n < 0)
1751 {
1752 context->recordError(gl::Error(GL_INVALID_VALUE));
1753 return;
1754 }
1755
Geoff Langbfdea662014-07-23 14:16:32 -04001756 for (int i = 0; i < n; i++)
1757 {
1758 framebuffers[i] = context->createFramebuffer();
1759 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001760 }
1761}
1762
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001763void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1764{
1765 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1766
Geoff Langbfdea662014-07-23 14:16:32 -04001767 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001768 if (context)
1769 {
1770 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001771 {
Geoff Langb1196682014-07-23 13:47:29 -04001772 context->recordError(gl::Error(GL_INVALID_VALUE));
1773 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001774 }
Geoff Langbfdea662014-07-23 14:16:32 -04001775
1776 for (GLsizei i = 0; i < n; i++)
1777 {
1778 ids[i] = context->createQuery();
1779 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001780 }
1781}
1782
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001783void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1784{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001785 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001786
Geoff Langbfdea662014-07-23 14:16:32 -04001787 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001788 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001789 {
Geoff Langb1196682014-07-23 13:47:29 -04001790 if (n < 0)
1791 {
1792 context->recordError(gl::Error(GL_INVALID_VALUE));
1793 return;
1794 }
1795
Geoff Langbfdea662014-07-23 14:16:32 -04001796 for (int i = 0; i < n; i++)
1797 {
1798 renderbuffers[i] = context->createRenderbuffer();
1799 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001800 }
1801}
1802
1803void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1804{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001805 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001806
Geoff Langbfdea662014-07-23 14:16:32 -04001807 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001808 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001809 {
Geoff Langb1196682014-07-23 13:47:29 -04001810 if (n < 0)
1811 {
1812 context->recordError(gl::Error(GL_INVALID_VALUE));
1813 return;
1814 }
1815
Geoff Langbfdea662014-07-23 14:16:32 -04001816 for (int i = 0; i < n; i++)
1817 {
1818 textures[i] = context->createTexture();
1819 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001820 }
1821}
1822
daniel@transgaming.com85423182010-04-22 13:35:27 +00001823void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001824{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001825 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001826 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001827 program, index, bufsize, length, size, type, name);
1828
Geoff Langbfdea662014-07-23 14:16:32 -04001829 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001830 if (context)
1831 {
Geoff Langb1196682014-07-23 13:47:29 -04001832 if (bufsize < 0)
1833 {
1834 context->recordError(gl::Error(GL_INVALID_VALUE));
1835 return;
1836 }
1837
Geoff Langbfdea662014-07-23 14:16:32 -04001838 gl::Program *programObject = context->getProgram(program);
1839
1840 if (!programObject)
1841 {
1842 if (context->getShader(program))
1843 {
Geoff Langb1196682014-07-23 13:47:29 -04001844 context->recordError(gl::Error(GL_INVALID_OPERATION));
1845 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001846 }
1847 else
1848 {
Geoff Langb1196682014-07-23 13:47:29 -04001849 context->recordError(gl::Error(GL_INVALID_VALUE));
1850 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001851 }
1852 }
1853
1854 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001855 {
Geoff Langb1196682014-07-23 13:47:29 -04001856 context->recordError(gl::Error(GL_INVALID_VALUE));
1857 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001858 }
1859
Geoff Langbfdea662014-07-23 14:16:32 -04001860 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001861 }
1862}
1863
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001864void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001865{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001866 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001867 "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 +00001868 program, index, bufsize, length, size, type, name);
1869
Geoff Langbfdea662014-07-23 14:16:32 -04001870
1871 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001872 if (context)
1873 {
Geoff Langb1196682014-07-23 13:47:29 -04001874 if (bufsize < 0)
1875 {
1876 context->recordError(gl::Error(GL_INVALID_VALUE));
1877 return;
1878 }
1879
Geoff Langbfdea662014-07-23 14:16:32 -04001880 gl::Program *programObject = context->getProgram(program);
1881
1882 if (!programObject)
1883 {
1884 if (context->getShader(program))
1885 {
Geoff Langb1196682014-07-23 13:47:29 -04001886 context->recordError(gl::Error(GL_INVALID_OPERATION));
1887 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001888 }
1889 else
1890 {
Geoff Langb1196682014-07-23 13:47:29 -04001891 context->recordError(gl::Error(GL_INVALID_VALUE));
1892 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001893 }
1894 }
1895
1896 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001897 {
Geoff Langb1196682014-07-23 13:47:29 -04001898 context->recordError(gl::Error(GL_INVALID_VALUE));
1899 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001900 }
1901
Geoff Langbfdea662014-07-23 14:16:32 -04001902 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001903 }
1904}
1905
1906void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1907{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001908 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 +00001909 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001910
Geoff Langbfdea662014-07-23 14:16:32 -04001911 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001912 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001913 {
Geoff Langb1196682014-07-23 13:47:29 -04001914 if (maxcount < 0)
1915 {
1916 context->recordError(gl::Error(GL_INVALID_VALUE));
1917 return;
1918 }
1919
Geoff Langbfdea662014-07-23 14:16:32 -04001920 gl::Program *programObject = context->getProgram(program);
1921
1922 if (!programObject)
1923 {
1924 if (context->getShader(program))
1925 {
Geoff Langb1196682014-07-23 13:47:29 -04001926 context->recordError(gl::Error(GL_INVALID_OPERATION));
1927 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001928 }
1929 else
1930 {
Geoff Langb1196682014-07-23 13:47:29 -04001931 context->recordError(gl::Error(GL_INVALID_VALUE));
1932 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001933 }
1934 }
1935
1936 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001937 }
1938}
1939
Geoff Langb1196682014-07-23 13:47:29 -04001940GLint __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001941{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001942 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001943
Geoff Langbfdea662014-07-23 14:16:32 -04001944 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001945 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001946 {
Geoff Langbfdea662014-07-23 14:16:32 -04001947 gl::Program *programObject = context->getProgram(program);
1948
1949 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001950 {
Geoff Langbfdea662014-07-23 14:16:32 -04001951 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001952 {
Geoff Langb1196682014-07-23 13:47:29 -04001953 context->recordError(gl::Error(GL_INVALID_OPERATION));
1954 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001955 }
Geoff Langbfdea662014-07-23 14:16:32 -04001956 else
1957 {
Geoff Langb1196682014-07-23 13:47:29 -04001958 context->recordError(gl::Error(GL_INVALID_VALUE));
1959 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001960 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001961 }
Geoff Langbfdea662014-07-23 14:16:32 -04001962
1963 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1964 if (!programObject->isLinked() || !programBinary)
1965 {
Geoff Langb1196682014-07-23 13:47:29 -04001966 context->recordError(gl::Error(GL_INVALID_OPERATION));
1967 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001968 }
1969
1970 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001971 }
1972
1973 return -1;
1974}
1975
1976void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1977{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001978 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979
Geoff Langbfdea662014-07-23 14:16:32 -04001980 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001981 if (context)
1982 {
1983 GLenum nativeType;
1984 unsigned int numParams = 0;
1985 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001986 {
Geoff Langbfdea662014-07-23 14:16:32 -04001987 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001988 }
Geoff Langbfdea662014-07-23 14:16:32 -04001989
1990 if (nativeType == GL_BOOL)
1991 {
1992 context->getBooleanv(pname, params);
1993 }
1994 else
1995 {
1996 CastStateValues(context, nativeType, pname, numParams, params);
1997 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001998 }
1999}
2000
2001void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
2002{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002003 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 +00002004
Geoff Langbfdea662014-07-23 14:16:32 -04002005 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002006 if (context)
2007 {
2008 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002009 {
Geoff Langb1196682014-07-23 13:47:29 -04002010 context->recordError(gl::Error(GL_INVALID_ENUM));
2011 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002012 }
Geoff Langbfdea662014-07-23 14:16:32 -04002013
2014 if (!gl::ValidBufferParameter(context, pname))
2015 {
Geoff Langb1196682014-07-23 13:47:29 -04002016 context->recordError(gl::Error(GL_INVALID_ENUM));
2017 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002018 }
2019
2020 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
2021
2022 if (!buffer)
2023 {
2024 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04002025 context->recordError(gl::Error(GL_INVALID_OPERATION));
2026 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002027 }
2028
2029 switch (pname)
2030 {
2031 case GL_BUFFER_USAGE:
2032 *params = static_cast<GLint>(buffer->getUsage());
2033 break;
2034 case GL_BUFFER_SIZE:
2035 *params = gl::clampCast<GLint>(buffer->getSize());
2036 break;
2037 case GL_BUFFER_ACCESS_FLAGS:
2038 *params = buffer->getAccessFlags();
2039 break;
2040 case GL_BUFFER_MAPPED:
2041 *params = static_cast<GLint>(buffer->isMapped());
2042 break;
2043 case GL_BUFFER_MAP_OFFSET:
2044 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2045 break;
2046 case GL_BUFFER_MAP_LENGTH:
2047 *params = gl::clampCast<GLint>(buffer->getMapLength());
2048 break;
2049 default: UNREACHABLE(); break;
2050 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002051 }
2052}
2053
2054GLenum __stdcall glGetError(void)
2055{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002056 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002057
2058 gl::Context *context = gl::getContext();
2059
2060 if (context)
2061 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002062 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002063 }
2064
2065 return GL_NO_ERROR;
2066}
2067
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002068void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
2069{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002070 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002071
Geoff Langbfdea662014-07-23 14:16:32 -04002072 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002073 if (context)
2074 {
2075 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2076
2077 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002078 {
Geoff Langb1196682014-07-23 13:47:29 -04002079 context->recordError(gl::Error(GL_INVALID_OPERATION));
2080 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002081 }
Geoff Langbfdea662014-07-23 14:16:32 -04002082
2083 if (fenceObject->isFence() != GL_TRUE)
2084 {
Geoff Langb1196682014-07-23 13:47:29 -04002085 context->recordError(gl::Error(GL_INVALID_OPERATION));
2086 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002087 }
2088
2089 switch (pname)
2090 {
2091 case GL_FENCE_STATUS_NV:
2092 case GL_FENCE_CONDITION_NV:
2093 break;
2094
Geoff Langb1196682014-07-23 13:47:29 -04002095 default:
2096 context->recordError(gl::Error(GL_INVALID_ENUM));
2097 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002098 }
2099
2100 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002101 }
2102}
2103
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002104void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2105{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002106 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002107
Geoff Langbfdea662014-07-23 14:16:32 -04002108 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002109 if (context)
2110 {
2111 GLenum nativeType;
2112 unsigned int numParams = 0;
2113 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002114 {
Geoff Langbfdea662014-07-23 14:16:32 -04002115 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002116 }
Geoff Langbfdea662014-07-23 14:16:32 -04002117
2118 if (nativeType == GL_FLOAT)
2119 {
2120 context->getFloatv(pname, params);
2121 }
2122 else
2123 {
2124 CastStateValues(context, nativeType, pname, numParams, params);
2125 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002126 }
2127}
2128
2129void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2130{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002131 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 +00002132 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002133
Geoff Langbfdea662014-07-23 14:16:32 -04002134 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002135 if (context)
2136 {
2137 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002138 {
Geoff Langb1196682014-07-23 13:47:29 -04002139 context->recordError(gl::Error(GL_INVALID_ENUM));
2140 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002141 }
2142
2143 int clientVersion = context->getClientVersion();
2144
2145 switch (pname)
2146 {
2147 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2148 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2149 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2150 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2151 break;
Geoff Langb1196682014-07-23 13:47:29 -04002152
Geoff Langbfdea662014-07-23 14:16:32 -04002153 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2154 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002155 {
Geoff Langb1196682014-07-23 13:47:29 -04002156 context->recordError(gl::Error(GL_INVALID_ENUM));
2157 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002158 }
Geoff Langbfdea662014-07-23 14:16:32 -04002159 break;
Geoff Langb1196682014-07-23 13:47:29 -04002160
Geoff Langbfdea662014-07-23 14:16:32 -04002161 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2162 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2163 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2164 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2165 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2166 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2167 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2168 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2169 if (clientVersion < 3)
2170 {
Geoff Langb1196682014-07-23 13:47:29 -04002171 context->recordError(gl::Error(GL_INVALID_ENUM));
2172 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002173 }
2174 break;
Geoff Langb1196682014-07-23 13:47:29 -04002175
Geoff Langbfdea662014-07-23 14:16:32 -04002176 default:
Geoff Langb1196682014-07-23 13:47:29 -04002177 context->recordError(gl::Error(GL_INVALID_ENUM));
2178 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002179 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002180
Geoff Langbfdea662014-07-23 14:16:32 -04002181 // Determine if the attachment is a valid enum
2182 switch (attachment)
2183 {
2184 case GL_BACK:
2185 case GL_FRONT:
2186 case GL_DEPTH:
2187 case GL_STENCIL:
2188 case GL_DEPTH_STENCIL_ATTACHMENT:
2189 if (clientVersion < 3)
2190 {
Geoff Langb1196682014-07-23 13:47:29 -04002191 context->recordError(gl::Error(GL_INVALID_ENUM));
2192 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002193 }
2194 break;
2195
2196 case GL_DEPTH_ATTACHMENT:
2197 case GL_STENCIL_ATTACHMENT:
2198 break;
2199
2200 default:
2201 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2202 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2203 {
Geoff Langb1196682014-07-23 13:47:29 -04002204 context->recordError(gl::Error(GL_INVALID_ENUM));
2205 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002206 }
2207 break;
2208 }
2209
2210 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2211 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2212
2213 if (framebufferHandle == 0)
2214 {
2215 if (clientVersion < 3)
2216 {
Geoff Langb1196682014-07-23 13:47:29 -04002217 context->recordError(gl::Error(GL_INVALID_OPERATION));
2218 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002219 }
2220
2221 switch (attachment)
2222 {
2223 case GL_BACK:
2224 case GL_DEPTH:
2225 case GL_STENCIL:
2226 break;
Geoff Langb1196682014-07-23 13:47:29 -04002227
Geoff Langbfdea662014-07-23 14:16:32 -04002228 default:
Geoff Langb1196682014-07-23 13:47:29 -04002229 context->recordError(gl::Error(GL_INVALID_OPERATION));
2230 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002231 }
2232 }
2233 else
2234 {
2235 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2236 {
2237 // Valid attachment query
2238 }
2239 else
2240 {
2241 switch (attachment)
2242 {
2243 case GL_DEPTH_ATTACHMENT:
2244 case GL_STENCIL_ATTACHMENT:
2245 break;
Geoff Langb1196682014-07-23 13:47:29 -04002246
Geoff Langbfdea662014-07-23 14:16:32 -04002247 case GL_DEPTH_STENCIL_ATTACHMENT:
2248 if (framebuffer->hasValidDepthStencil())
2249 {
Geoff Langb1196682014-07-23 13:47:29 -04002250 context->recordError(gl::Error(GL_INVALID_OPERATION));
2251 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002252 }
2253 break;
Geoff Langb1196682014-07-23 13:47:29 -04002254
Geoff Langbfdea662014-07-23 14:16:32 -04002255 default:
Geoff Langb1196682014-07-23 13:47:29 -04002256 context->recordError(gl::Error(GL_INVALID_OPERATION));
2257 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002258 }
2259 }
2260 }
2261
2262 GLenum attachmentType = GL_NONE;
2263 GLuint attachmentHandle = 0;
2264 GLuint attachmentLevel = 0;
2265 GLuint attachmentLayer = 0;
2266
2267 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2268
2269 if (attachmentObject)
2270 {
2271 attachmentType = attachmentObject->type();
2272 attachmentHandle = attachmentObject->id();
2273 attachmentLevel = attachmentObject->mipLevel();
2274 attachmentLayer = attachmentObject->layer();
2275 }
2276
2277 GLenum attachmentObjectType; // Type category
2278 if (framebufferHandle == 0)
2279 {
2280 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2281 }
2282 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2283 {
2284 attachmentObjectType = attachmentType;
2285 }
2286 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2287 {
2288 attachmentObjectType = GL_TEXTURE;
2289 }
2290 else
2291 {
2292 UNREACHABLE();
2293 return;
2294 }
2295
2296 if (attachmentObjectType == GL_NONE)
2297 {
2298 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2299 // is NONE, then querying any other pname will generate INVALID_ENUM.
2300
2301 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2302 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2303 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002304
Geoff Lang646559f2013-08-15 11:08:15 -04002305 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002306 {
Geoff Lang646559f2013-08-15 11:08:15 -04002307 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002308 *params = attachmentObjectType;
2309 break;
2310
Geoff Lang646559f2013-08-15 11:08:15 -04002311 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002312 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002313 {
Geoff Langb1196682014-07-23 13:47:29 -04002314 context->recordError(gl::Error(GL_INVALID_ENUM));
2315 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002316 }
Geoff Langbfdea662014-07-23 14:16:32 -04002317 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002318 break;
2319
2320 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002321 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002322 {
Geoff Langb1196682014-07-23 13:47:29 -04002323 context->recordError(gl::Error(GL_INVALID_ENUM));
2324 return;
Geoff Lang646559f2013-08-15 11:08:15 -04002325 }
2326 else
2327 {
Geoff Langb1196682014-07-23 13:47:29 -04002328 context->recordError(gl::Error(GL_INVALID_OPERATION));
2329 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002330 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002331 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002332 }
Geoff Langbfdea662014-07-23 14:16:32 -04002333 else
2334 {
2335 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2336 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2337 ASSERT(attachmentObject != NULL);
2338
2339 switch (pname)
2340 {
2341 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2342 *params = attachmentObjectType;
2343 break;
2344
2345 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2346 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2347 {
Geoff Langb1196682014-07-23 13:47:29 -04002348 context->recordError(gl::Error(GL_INVALID_ENUM));
2349 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002350 }
2351 *params = attachmentHandle;
2352 break;
2353
2354 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2355 if (attachmentObjectType != GL_TEXTURE)
2356 {
Geoff Langb1196682014-07-23 13:47:29 -04002357 context->recordError(gl::Error(GL_INVALID_ENUM));
2358 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002359 }
2360 *params = attachmentLevel;
2361 break;
2362
2363 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2364 if (attachmentObjectType != GL_TEXTURE)
2365 {
Geoff Langb1196682014-07-23 13:47:29 -04002366 context->recordError(gl::Error(GL_INVALID_ENUM));
2367 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002368 }
2369 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2370 break;
2371
2372 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2373 *params = attachmentObject->getRedSize();
2374 break;
2375
2376 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2377 *params = attachmentObject->getGreenSize();
2378 break;
2379
2380 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2381 *params = attachmentObject->getBlueSize();
2382 break;
2383
2384 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2385 *params = attachmentObject->getAlphaSize();
2386 break;
2387
2388 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2389 *params = attachmentObject->getDepthSize();
2390 break;
2391
2392 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2393 *params = attachmentObject->getStencilSize();
2394 break;
2395
2396 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
Jamie Madillee85d1b2014-09-17 10:35:23 -04002397 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT)
Geoff Langbfdea662014-07-23 14:16:32 -04002398 {
Geoff Langb1196682014-07-23 13:47:29 -04002399 context->recordError(gl::Error(GL_INVALID_OPERATION));
2400 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002401 }
2402 *params = attachmentObject->getComponentType();
2403 break;
2404
2405 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2406 *params = attachmentObject->getColorEncoding();
2407 break;
2408
2409 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2410 if (attachmentObjectType != GL_TEXTURE)
2411 {
Geoff Langb1196682014-07-23 13:47:29 -04002412 context->recordError(gl::Error(GL_INVALID_ENUM));
2413 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002414 }
2415 *params = attachmentLayer;
2416 break;
2417
2418 default:
2419 UNREACHABLE();
2420 break;
2421 }
2422 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002423 }
2424}
2425
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002426GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2427{
2428 EVENT("()");
2429
Geoff Langbfdea662014-07-23 14:16:32 -04002430 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002431
Geoff Langbfdea662014-07-23 14:16:32 -04002432 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002433 {
Geoff Langbfdea662014-07-23 14:16:32 -04002434 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002435 }
Geoff Langbfdea662014-07-23 14:16:32 -04002436
2437 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002438}
2439
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002440void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2441{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002442 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002443
Geoff Langbfdea662014-07-23 14:16:32 -04002444 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002445 if (context)
2446 {
2447 GLenum nativeType;
2448 unsigned int numParams = 0;
2449
2450 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002451 {
Geoff Langbfdea662014-07-23 14:16:32 -04002452 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002453 }
Geoff Langbfdea662014-07-23 14:16:32 -04002454
2455 if (nativeType == GL_INT)
2456 {
2457 context->getIntegerv(pname, params);
2458 }
2459 else
2460 {
2461 CastStateValues(context, nativeType, pname, numParams, params);
2462 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 }
2464}
2465
2466void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2467{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002468 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469
Geoff Langbfdea662014-07-23 14:16:32 -04002470 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002471 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002472 {
Geoff Langbfdea662014-07-23 14:16:32 -04002473 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002474
Geoff Langbfdea662014-07-23 14:16:32 -04002475 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002476 {
Geoff Langb1196682014-07-23 13:47:29 -04002477 context->recordError(gl::Error(GL_INVALID_VALUE));
2478 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002479 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480
Geoff Langbfdea662014-07-23 14:16:32 -04002481 if (context->getClientVersion() < 3)
2482 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002483 switch (pname)
2484 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002485 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002486 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002487 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002488 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002489 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002490 context->recordError(gl::Error(GL_INVALID_ENUM));
2491 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002492 }
2493 }
Geoff Langbfdea662014-07-23 14:16:32 -04002494
2495 switch (pname)
2496 {
2497 case GL_DELETE_STATUS:
2498 *params = programObject->isFlaggedForDeletion();
2499 return;
2500 case GL_LINK_STATUS:
2501 *params = programObject->isLinked();
2502 return;
2503 case GL_VALIDATE_STATUS:
2504 *params = programObject->isValidated();
2505 return;
2506 case GL_INFO_LOG_LENGTH:
2507 *params = programObject->getInfoLogLength();
2508 return;
2509 case GL_ATTACHED_SHADERS:
2510 *params = programObject->getAttachedShadersCount();
2511 return;
2512 case GL_ACTIVE_ATTRIBUTES:
2513 *params = programObject->getActiveAttributeCount();
2514 return;
2515 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2516 *params = programObject->getActiveAttributeMaxLength();
2517 return;
2518 case GL_ACTIVE_UNIFORMS:
2519 *params = programObject->getActiveUniformCount();
2520 return;
2521 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2522 *params = programObject->getActiveUniformMaxLength();
2523 return;
2524 case GL_PROGRAM_BINARY_LENGTH_OES:
2525 *params = programObject->getProgramBinaryLength();
2526 return;
2527 case GL_ACTIVE_UNIFORM_BLOCKS:
2528 *params = programObject->getActiveUniformBlockCount();
2529 return;
2530 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2531 *params = programObject->getActiveUniformBlockMaxLength();
2532 break;
2533 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2534 *params = programObject->getTransformFeedbackBufferMode();
2535 break;
2536 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2537 *params = programObject->getTransformFeedbackVaryingCount();
2538 break;
2539 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2540 *params = programObject->getTransformFeedbackVaryingMaxLength();
2541 break;
Geoff Langb1196682014-07-23 13:47:29 -04002542
Geoff Langbfdea662014-07-23 14:16:32 -04002543 default:
Geoff Langb1196682014-07-23 13:47:29 -04002544 context->recordError(gl::Error(GL_INVALID_ENUM));
2545 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002546 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002547 }
2548}
2549
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002550void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002551{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002552 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 +00002553 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002554
Geoff Langbfdea662014-07-23 14:16:32 -04002555 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002556 if (context)
2557 {
Geoff Langb1196682014-07-23 13:47:29 -04002558 if (bufsize < 0)
2559 {
2560 context->recordError(gl::Error(GL_INVALID_VALUE));
2561 return;
2562 }
2563
Geoff Langbfdea662014-07-23 14:16:32 -04002564 gl::Program *programObject = context->getProgram(program);
2565
2566 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002567 {
Geoff Langb1196682014-07-23 13:47:29 -04002568 context->recordError(gl::Error(GL_INVALID_VALUE));
2569 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002570 }
2571
Geoff Langbfdea662014-07-23 14:16:32 -04002572 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002573 }
2574}
2575
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002576void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2577{
2578 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2579
Geoff Langbfdea662014-07-23 14:16:32 -04002580 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002581 if (context)
2582 {
2583 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002584 {
Geoff Langb1196682014-07-23 13:47:29 -04002585 context->recordError(gl::Error(GL_INVALID_ENUM));
2586 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002587 }
Geoff Langbfdea662014-07-23 14:16:32 -04002588
2589 switch (pname)
2590 {
2591 case GL_CURRENT_QUERY_EXT:
2592 params[0] = context->getState().getActiveQueryId(target);
2593 break;
2594
2595 default:
Geoff Langb1196682014-07-23 13:47:29 -04002596 context->recordError(gl::Error(GL_INVALID_ENUM));
2597 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002598 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002599 }
2600}
2601
2602void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2603{
2604 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2605
Geoff Langbfdea662014-07-23 14:16:32 -04002606 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002607 if (context)
2608 {
2609 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2610
2611 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002612 {
Geoff Langb1196682014-07-23 13:47:29 -04002613 context->recordError(gl::Error(GL_INVALID_OPERATION));
2614 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002615 }
Geoff Langbfdea662014-07-23 14:16:32 -04002616
2617 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2618 {
Geoff Langb1196682014-07-23 13:47:29 -04002619 context->recordError(gl::Error(GL_INVALID_OPERATION));
2620 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002621 }
2622
2623 switch(pname)
2624 {
2625 case GL_QUERY_RESULT_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002626 {
2627 gl::Error error = queryObject->getResult(params);
2628 if (error.isError())
2629 {
2630 context->recordError(error);
2631 return;
2632 }
2633 }
Geoff Langbfdea662014-07-23 14:16:32 -04002634 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002635
Geoff Langbfdea662014-07-23 14:16:32 -04002636 case GL_QUERY_RESULT_AVAILABLE_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002637 {
2638 gl::Error error = queryObject->isResultAvailable(params);
2639 if (error.isError())
2640 {
2641 context->recordError(error);
2642 return;
2643 }
2644 }
Geoff Langbfdea662014-07-23 14:16:32 -04002645 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002646
Geoff Langbfdea662014-07-23 14:16:32 -04002647 default:
Geoff Langb1196682014-07-23 13:47:29 -04002648 context->recordError(gl::Error(GL_INVALID_ENUM));
2649 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002650 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002651 }
2652}
2653
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002654void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002656 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 +00002657
Geoff Langbfdea662014-07-23 14:16:32 -04002658 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002659 if (context)
2660 {
2661 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002662 {
Geoff Langb1196682014-07-23 13:47:29 -04002663 context->recordError(gl::Error(GL_INVALID_ENUM));
2664 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002665 }
Geoff Langbfdea662014-07-23 14:16:32 -04002666
2667 if (context->getState().getRenderbufferId() == 0)
2668 {
Geoff Langb1196682014-07-23 13:47:29 -04002669 context->recordError(gl::Error(GL_INVALID_OPERATION));
2670 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002671 }
2672
2673 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2674
2675 switch (pname)
2676 {
2677 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2678 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2679 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2680 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2681 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2682 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2683 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2684 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2685 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002686
Geoff Langbfdea662014-07-23 14:16:32 -04002687 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2688 if (!context->getExtensions().framebufferMultisample)
2689 {
Geoff Langb1196682014-07-23 13:47:29 -04002690 context->recordError(gl::Error(GL_INVALID_ENUM));
2691 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002692 }
2693 *params = renderbuffer->getSamples();
2694 break;
Geoff Langb1196682014-07-23 13:47:29 -04002695
Geoff Langbfdea662014-07-23 14:16:32 -04002696 default:
Geoff Langb1196682014-07-23 13:47:29 -04002697 context->recordError(gl::Error(GL_INVALID_ENUM));
2698 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002699 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002700 }
2701}
2702
2703void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2704{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002705 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002706
Geoff Langbfdea662014-07-23 14:16:32 -04002707 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002708 if (context)
2709 {
2710 gl::Shader *shaderObject = context->getShader(shader);
2711
2712 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002713 {
Geoff Langb1196682014-07-23 13:47:29 -04002714 context->recordError(gl::Error(GL_INVALID_VALUE));
2715 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002716 }
Geoff Langbfdea662014-07-23 14:16:32 -04002717
2718 switch (pname)
2719 {
2720 case GL_SHADER_TYPE:
2721 *params = shaderObject->getType();
2722 return;
2723 case GL_DELETE_STATUS:
2724 *params = shaderObject->isFlaggedForDeletion();
2725 return;
2726 case GL_COMPILE_STATUS:
2727 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2728 return;
2729 case GL_INFO_LOG_LENGTH:
2730 *params = shaderObject->getInfoLogLength();
2731 return;
2732 case GL_SHADER_SOURCE_LENGTH:
2733 *params = shaderObject->getSourceLength();
2734 return;
2735 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2736 *params = shaderObject->getTranslatedSourceLength();
2737 return;
Geoff Langb1196682014-07-23 13:47:29 -04002738
Geoff Langbfdea662014-07-23 14:16:32 -04002739 default:
Geoff Langb1196682014-07-23 13:47:29 -04002740 context->recordError(gl::Error(GL_INVALID_ENUM));
2741 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002742 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002743 }
2744}
2745
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002746void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002747{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002748 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 +00002749 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002750
Geoff Langbfdea662014-07-23 14:16:32 -04002751 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002752 if (context)
2753 {
Geoff Langb1196682014-07-23 13:47:29 -04002754 if (bufsize < 0)
2755 {
2756 context->recordError(gl::Error(GL_INVALID_VALUE));
2757 return;
2758 }
2759
Geoff Langbfdea662014-07-23 14:16:32 -04002760 gl::Shader *shaderObject = context->getShader(shader);
2761
2762 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002763 {
Geoff Langb1196682014-07-23 13:47:29 -04002764 context->recordError(gl::Error(GL_INVALID_VALUE));
2765 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002766 }
2767
Geoff Langbfdea662014-07-23 14:16:32 -04002768 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002769 }
2770}
2771
2772void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2773{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002774 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 +00002775 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002776
Geoff Langb1196682014-07-23 13:47:29 -04002777 gl::Context *context = gl::getNonLostContext();
2778 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002779 {
Geoff Langb1196682014-07-23 13:47:29 -04002780 switch (shadertype)
2781 {
2782 case GL_VERTEX_SHADER:
2783 case GL_FRAGMENT_SHADER:
2784 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002785
Geoff Langb1196682014-07-23 13:47:29 -04002786 default:
2787 context->recordError(gl::Error(GL_INVALID_ENUM));
2788 return;
2789 }
2790
2791 switch (precisiontype)
2792 {
2793 case GL_LOW_FLOAT:
2794 case GL_MEDIUM_FLOAT:
2795 case GL_HIGH_FLOAT:
2796 // Assume IEEE 754 precision
2797 range[0] = 127;
2798 range[1] = 127;
2799 *precision = 23;
2800 break;
2801
2802 case GL_LOW_INT:
2803 case GL_MEDIUM_INT:
2804 case GL_HIGH_INT:
2805 // Some (most) hardware only supports single-precision floating-point numbers,
2806 // which can accurately represent integers up to +/-16777216
2807 range[0] = 24;
2808 range[1] = 24;
2809 *precision = 0;
2810 break;
2811
2812 default:
2813 context->recordError(gl::Error(GL_INVALID_ENUM));
2814 return;
2815 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002816 }
2817}
2818
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002819void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002820{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002821 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 +00002822 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002823
Geoff Langbfdea662014-07-23 14:16:32 -04002824 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002825 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002826 {
Geoff Langb1196682014-07-23 13:47:29 -04002827 if (bufsize < 0)
2828 {
2829 context->recordError(gl::Error(GL_INVALID_VALUE));
2830 return;
2831 }
2832
Geoff Langbfdea662014-07-23 14:16:32 -04002833 gl::Shader *shaderObject = context->getShader(shader);
2834
2835 if (!shaderObject)
2836 {
Geoff Langb1196682014-07-23 13:47:29 -04002837 context->recordError(gl::Error(GL_INVALID_OPERATION));
2838 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002839 }
2840
2841 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002842 }
2843}
2844
zmo@google.coma574f782011-10-03 21:45:23 +00002845void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2846{
2847 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2848 shader, bufsize, length, source);
2849
Geoff Langbfdea662014-07-23 14:16:32 -04002850 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002851 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002852 {
Geoff Langb1196682014-07-23 13:47:29 -04002853 if (bufsize < 0)
2854 {
2855 context->recordError(gl::Error(GL_INVALID_VALUE));
2856 return;
2857 }
2858
Geoff Langbfdea662014-07-23 14:16:32 -04002859 gl::Shader *shaderObject = context->getShader(shader);
2860
2861 if (!shaderObject)
2862 {
Geoff Langb1196682014-07-23 13:47:29 -04002863 context->recordError(gl::Error(GL_INVALID_OPERATION));
2864 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002865 }
2866
2867 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002868 }
2869}
2870
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002871const GLubyte* __stdcall glGetString(GLenum name)
2872{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002873 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002874
Geoff Langbfdea662014-07-23 14:16:32 -04002875 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002876
Geoff Langbfdea662014-07-23 14:16:32 -04002877 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002878 {
Geoff Langbfdea662014-07-23 14:16:32 -04002879 case GL_VENDOR:
2880 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002881
Geoff Langbfdea662014-07-23 14:16:32 -04002882 case GL_RENDERER:
2883 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002884
Geoff Langbfdea662014-07-23 14:16:32 -04002885 case GL_VERSION:
2886 if (context->getClientVersion() == 2)
2887 {
2888 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2889 }
2890 else
2891 {
2892 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2893 }
Geoff Langb1196682014-07-23 13:47:29 -04002894
Geoff Langbfdea662014-07-23 14:16:32 -04002895 case GL_SHADING_LANGUAGE_VERSION:
2896 if (context->getClientVersion() == 2)
2897 {
2898 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2899 }
2900 else
2901 {
2902 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2903 }
Geoff Langb1196682014-07-23 13:47:29 -04002904
Geoff Langbfdea662014-07-23 14:16:32 -04002905 case GL_EXTENSIONS:
2906 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002907
Geoff Langbfdea662014-07-23 14:16:32 -04002908 default:
Geoff Langb1196682014-07-23 13:47:29 -04002909 if (context)
2910 {
2911 context->recordError(gl::Error(GL_INVALID_ENUM));
2912 }
2913 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002914 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002915}
2916
2917void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2918{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002919 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 +00002920
Geoff Langbfdea662014-07-23 14:16:32 -04002921 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002922 if (context)
2923 {
2924 gl::Texture *texture = context->getTargetTexture(target);
2925
2926 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002927 {
Geoff Langb1196682014-07-23 13:47:29 -04002928 context->recordError(gl::Error(GL_INVALID_ENUM));
2929 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002930 }
Geoff Langbfdea662014-07-23 14:16:32 -04002931
2932 switch (pname)
2933 {
2934 case GL_TEXTURE_MAG_FILTER:
2935 *params = (GLfloat)texture->getSamplerState().magFilter;
2936 break;
2937 case GL_TEXTURE_MIN_FILTER:
2938 *params = (GLfloat)texture->getSamplerState().minFilter;
2939 break;
2940 case GL_TEXTURE_WRAP_S:
2941 *params = (GLfloat)texture->getSamplerState().wrapS;
2942 break;
2943 case GL_TEXTURE_WRAP_T:
2944 *params = (GLfloat)texture->getSamplerState().wrapT;
2945 break;
2946 case GL_TEXTURE_WRAP_R:
2947 if (context->getClientVersion() < 3)
2948 {
Geoff Langb1196682014-07-23 13:47:29 -04002949 context->recordError(gl::Error(GL_INVALID_ENUM));
2950 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002951 }
2952 *params = (GLfloat)texture->getSamplerState().wrapR;
2953 break;
2954 case GL_TEXTURE_IMMUTABLE_FORMAT:
2955 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2956 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2957 break;
2958 case GL_TEXTURE_IMMUTABLE_LEVELS:
2959 if (context->getClientVersion() < 3)
2960 {
Geoff Langb1196682014-07-23 13:47:29 -04002961 context->recordError(gl::Error(GL_INVALID_ENUM));
2962 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002963 }
2964 *params = (GLfloat)texture->immutableLevelCount();
2965 break;
2966 case GL_TEXTURE_USAGE_ANGLE:
2967 *params = (GLfloat)texture->getUsage();
2968 break;
2969 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2970 if (!context->getExtensions().textureFilterAnisotropic)
2971 {
Geoff Langb1196682014-07-23 13:47:29 -04002972 context->recordError(gl::Error(GL_INVALID_ENUM));
2973 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002974 }
2975 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2976 break;
2977 case GL_TEXTURE_SWIZZLE_R:
2978 if (context->getClientVersion() < 3)
2979 {
Geoff Langb1196682014-07-23 13:47:29 -04002980 context->recordError(gl::Error(GL_INVALID_ENUM));
2981 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002982 }
2983 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2984 break;
2985 case GL_TEXTURE_SWIZZLE_G:
2986 if (context->getClientVersion() < 3)
2987 {
Geoff Langb1196682014-07-23 13:47:29 -04002988 context->recordError(gl::Error(GL_INVALID_ENUM));
2989 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002990 }
2991 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2992 break;
2993 case GL_TEXTURE_SWIZZLE_B:
2994 if (context->getClientVersion() < 3)
2995 {
Geoff Langb1196682014-07-23 13:47:29 -04002996 context->recordError(gl::Error(GL_INVALID_ENUM));
2997 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002998 }
2999 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
3000 break;
3001 case GL_TEXTURE_SWIZZLE_A:
3002 if (context->getClientVersion() < 3)
3003 {
Geoff Langb1196682014-07-23 13:47:29 -04003004 context->recordError(gl::Error(GL_INVALID_ENUM));
3005 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003006 }
3007 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
3008 break;
3009 case GL_TEXTURE_BASE_LEVEL:
3010 if (context->getClientVersion() < 3)
3011 {
Geoff Langb1196682014-07-23 13:47:29 -04003012 context->recordError(gl::Error(GL_INVALID_ENUM));
3013 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003014 }
3015 *params = (GLfloat)texture->getSamplerState().baseLevel;
3016 break;
3017 case GL_TEXTURE_MAX_LEVEL:
3018 if (context->getClientVersion() < 3)
3019 {
Geoff Langb1196682014-07-23 13:47:29 -04003020 context->recordError(gl::Error(GL_INVALID_ENUM));
3021 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003022 }
3023 *params = (GLfloat)texture->getSamplerState().maxLevel;
3024 break;
3025 case GL_TEXTURE_MIN_LOD:
3026 if (context->getClientVersion() < 3)
3027 {
Geoff Langb1196682014-07-23 13:47:29 -04003028 context->recordError(gl::Error(GL_INVALID_ENUM));
3029 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003030 }
3031 *params = texture->getSamplerState().minLod;
3032 break;
3033 case GL_TEXTURE_MAX_LOD:
3034 if (context->getClientVersion() < 3)
3035 {
Geoff Langb1196682014-07-23 13:47:29 -04003036 context->recordError(gl::Error(GL_INVALID_ENUM));
3037 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003038 }
3039 *params = texture->getSamplerState().maxLod;
3040 break;
Geoff Langb1196682014-07-23 13:47:29 -04003041
Geoff Langbfdea662014-07-23 14:16:32 -04003042 default:
Geoff Langb1196682014-07-23 13:47:29 -04003043 context->recordError(gl::Error(GL_INVALID_ENUM));
3044 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003045 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003046 }
3047}
3048
3049void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
3050{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003051 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 +00003052
Geoff Langbfdea662014-07-23 14:16:32 -04003053 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003054 if (context)
3055 {
3056 gl::Texture *texture = context->getTargetTexture(target);
3057
3058 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003059 {
Geoff Langb1196682014-07-23 13:47:29 -04003060 context->recordError(gl::Error(GL_INVALID_ENUM));
3061 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003062 }
Geoff Langbfdea662014-07-23 14:16:32 -04003063
3064 switch (pname)
3065 {
3066 case GL_TEXTURE_MAG_FILTER:
3067 *params = texture->getSamplerState().magFilter;
3068 break;
3069 case GL_TEXTURE_MIN_FILTER:
3070 *params = texture->getSamplerState().minFilter;
3071 break;
3072 case GL_TEXTURE_WRAP_S:
3073 *params = texture->getSamplerState().wrapS;
3074 break;
3075 case GL_TEXTURE_WRAP_T:
3076 *params = texture->getSamplerState().wrapT;
3077 break;
3078 case GL_TEXTURE_WRAP_R:
3079 if (context->getClientVersion() < 3)
3080 {
Geoff Langb1196682014-07-23 13:47:29 -04003081 context->recordError(gl::Error(GL_INVALID_ENUM));
3082 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003083 }
3084 *params = texture->getSamplerState().wrapR;
3085 break;
3086 case GL_TEXTURE_IMMUTABLE_FORMAT:
3087 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3088 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3089 break;
3090 case GL_TEXTURE_IMMUTABLE_LEVELS:
3091 if (context->getClientVersion() < 3)
3092 {
Geoff Langb1196682014-07-23 13:47:29 -04003093 context->recordError(gl::Error(GL_INVALID_ENUM));
3094 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003095 }
3096 *params = texture->immutableLevelCount();
3097 break;
3098 case GL_TEXTURE_USAGE_ANGLE:
3099 *params = texture->getUsage();
3100 break;
3101 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3102 if (!context->getExtensions().textureFilterAnisotropic)
3103 {
Geoff Langb1196682014-07-23 13:47:29 -04003104 context->recordError(gl::Error(GL_INVALID_ENUM));
3105 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003106 }
3107 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3108 break;
3109 case GL_TEXTURE_SWIZZLE_R:
3110 if (context->getClientVersion() < 3)
3111 {
Geoff Langb1196682014-07-23 13:47:29 -04003112 context->recordError(gl::Error(GL_INVALID_ENUM));
3113 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003114 }
3115 *params = texture->getSamplerState().swizzleRed;
3116 break;
3117 case GL_TEXTURE_SWIZZLE_G:
3118 if (context->getClientVersion() < 3)
3119 {
Geoff Langb1196682014-07-23 13:47:29 -04003120 context->recordError(gl::Error(GL_INVALID_ENUM));
3121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003122 }
3123 *params = texture->getSamplerState().swizzleGreen;
3124 break;
3125 case GL_TEXTURE_SWIZZLE_B:
3126 if (context->getClientVersion() < 3)
3127 {
Geoff Langb1196682014-07-23 13:47:29 -04003128 context->recordError(gl::Error(GL_INVALID_ENUM));
3129 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003130 }
3131 *params = texture->getSamplerState().swizzleBlue;
3132 break;
3133 case GL_TEXTURE_SWIZZLE_A:
3134 if (context->getClientVersion() < 3)
3135 {
Geoff Langb1196682014-07-23 13:47:29 -04003136 context->recordError(gl::Error(GL_INVALID_ENUM));
3137 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003138 }
3139 *params = texture->getSamplerState().swizzleAlpha;
3140 break;
3141 case GL_TEXTURE_BASE_LEVEL:
3142 if (context->getClientVersion() < 3)
3143 {
Geoff Langb1196682014-07-23 13:47:29 -04003144 context->recordError(gl::Error(GL_INVALID_ENUM));
3145 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003146 }
3147 *params = texture->getSamplerState().baseLevel;
3148 break;
3149 case GL_TEXTURE_MAX_LEVEL:
3150 if (context->getClientVersion() < 3)
3151 {
Geoff Langb1196682014-07-23 13:47:29 -04003152 context->recordError(gl::Error(GL_INVALID_ENUM));
3153 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003154 }
3155 *params = texture->getSamplerState().maxLevel;
3156 break;
3157 case GL_TEXTURE_MIN_LOD:
3158 if (context->getClientVersion() < 3)
3159 {
Geoff Langb1196682014-07-23 13:47:29 -04003160 context->recordError(gl::Error(GL_INVALID_ENUM));
3161 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003162 }
3163 *params = (GLint)texture->getSamplerState().minLod;
3164 break;
3165 case GL_TEXTURE_MAX_LOD:
3166 if (context->getClientVersion() < 3)
3167 {
Geoff Langb1196682014-07-23 13:47:29 -04003168 context->recordError(gl::Error(GL_INVALID_ENUM));
3169 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003170 }
3171 *params = (GLint)texture->getSamplerState().maxLod;
3172 break;
Geoff Langb1196682014-07-23 13:47:29 -04003173
Geoff Langbfdea662014-07-23 14:16:32 -04003174 default:
Geoff Langb1196682014-07-23 13:47:29 -04003175 context->recordError(gl::Error(GL_INVALID_ENUM));
3176 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003177 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003178 }
3179}
3180
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003181void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3182{
3183 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3184 program, location, bufSize, params);
3185
Geoff Langbfdea662014-07-23 14:16:32 -04003186 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003187 if (context)
3188 {
Jamie Madill0063c512014-08-25 15:47:53 -04003189 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003190 {
Jamie Madill0063c512014-08-25 15:47:53 -04003191 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003192 }
3193
Jamie Madilla502c742014-08-28 17:19:13 -04003194 gl::Program *programObject = context->getProgram(program);
3195 ASSERT(programObject);
3196 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003197 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003198
Jamie Madill99a1e982014-08-25 15:47:54 -04003199 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003200 }
3201}
3202
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003203void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3204{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003205 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003206
Geoff Langbfdea662014-07-23 14:16:32 -04003207 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003208 if (context)
3209 {
Jamie Madill0063c512014-08-25 15:47:53 -04003210 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003211 {
Jamie Madill0063c512014-08-25 15:47:53 -04003212 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003213 }
Geoff Langbfdea662014-07-23 14:16:32 -04003214
Jamie Madilla502c742014-08-28 17:19:13 -04003215 gl::Program *programObject = context->getProgram(program);
3216 ASSERT(programObject);
3217 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003218 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003219
Jamie Madill99a1e982014-08-25 15:47:54 -04003220 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003221 }
3222}
3223
3224void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3225{
Geoff Langbfdea662014-07-23 14:16:32 -04003226 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003227 program, location, bufSize, params);
3228
Geoff Langbfdea662014-07-23 14:16:32 -04003229 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003230 if (context)
3231 {
Jamie Madill0063c512014-08-25 15:47:53 -04003232 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003233 {
Jamie Madill0063c512014-08-25 15:47:53 -04003234 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003235 }
3236
Jamie Madilla502c742014-08-28 17:19:13 -04003237 gl::Program *programObject = context->getProgram(program);
3238 ASSERT(programObject);
3239 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003240 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003241
Jamie Madill99a1e982014-08-25 15:47:54 -04003242 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003243 }
3244}
3245
3246void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3247{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003248 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003249
Geoff Langbfdea662014-07-23 14:16:32 -04003250 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003251 if (context)
3252 {
Jamie Madill0063c512014-08-25 15:47:53 -04003253 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003254 {
Jamie Madill0063c512014-08-25 15:47:53 -04003255 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003256 }
Geoff Langbfdea662014-07-23 14:16:32 -04003257
Jamie Madilla502c742014-08-28 17:19:13 -04003258 gl::Program *programObject = context->getProgram(program);
3259 ASSERT(programObject);
3260 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003261 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003262
Jamie Madill99a1e982014-08-25 15:47:54 -04003263 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003264 }
3265}
3266
Geoff Langb1196682014-07-23 13:47:29 -04003267GLint __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003269 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003270
Geoff Langbfdea662014-07-23 14:16:32 -04003271 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003272 if (context)
3273 {
Geoff Langb1196682014-07-23 13:47:29 -04003274 if (strstr(name, "gl_") == name)
3275 {
3276 return -1;
3277 }
3278
Geoff Langbfdea662014-07-23 14:16:32 -04003279 gl::Program *programObject = context->getProgram(program);
3280
3281 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003282 {
Geoff Langbfdea662014-07-23 14:16:32 -04003283 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003284 {
Geoff Langb1196682014-07-23 13:47:29 -04003285 context->recordError(gl::Error(GL_INVALID_OPERATION));
3286 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003287 }
Geoff Langbfdea662014-07-23 14:16:32 -04003288 else
3289 {
Geoff Langb1196682014-07-23 13:47:29 -04003290 context->recordError(gl::Error(GL_INVALID_VALUE));
3291 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003292 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003293 }
Geoff Langbfdea662014-07-23 14:16:32 -04003294
3295 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3296 if (!programObject->isLinked() || !programBinary)
3297 {
Geoff Langb1196682014-07-23 13:47:29 -04003298 context->recordError(gl::Error(GL_INVALID_OPERATION));
3299 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003300 }
3301
3302 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003303 }
3304
3305 return -1;
3306}
3307
3308void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3309{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003310 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003311
Geoff Langbfdea662014-07-23 14:16:32 -04003312 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003313 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003314 {
Geoff Langbfdea662014-07-23 14:16:32 -04003315 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003316 {
Geoff Langb1196682014-07-23 13:47:29 -04003317 context->recordError(gl::Error(GL_INVALID_VALUE));
3318 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003319 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003320
Geoff Langbfdea662014-07-23 14:16:32 -04003321 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003322 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003323 {
3324 return;
3325 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003326
Geoff Langbfdea662014-07-23 14:16:32 -04003327 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3328 {
3329 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3330 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003331 {
Geoff Langbfdea662014-07-23 14:16:32 -04003332 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003333 }
3334 }
Geoff Langbfdea662014-07-23 14:16:32 -04003335 else
3336 {
3337 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3338 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003339 }
3340}
3341
3342void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003344 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003345
Geoff Langbfdea662014-07-23 14:16:32 -04003346 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003347 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003348 {
Geoff Langbfdea662014-07-23 14:16:32 -04003349 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003350 {
Geoff Langb1196682014-07-23 13:47:29 -04003351 context->recordError(gl::Error(GL_INVALID_VALUE));
3352 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003353 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003354
Geoff Langbfdea662014-07-23 14:16:32 -04003355 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003356
Geoff Langb1196682014-07-23 13:47:29 -04003357 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003358 {
3359 return;
3360 }
Jamie Madillaff71502013-07-02 11:57:05 -04003361
Geoff Langbfdea662014-07-23 14:16:32 -04003362 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3363 {
3364 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3365 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003366 {
Geoff Langbfdea662014-07-23 14:16:32 -04003367 float currentValue = currentValueData.FloatValues[i];
3368 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003369 }
3370 }
Geoff Langbfdea662014-07-23 14:16:32 -04003371 else
3372 {
3373 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3374 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003375 }
3376}
3377
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003378void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003380 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003381
Geoff Langbfdea662014-07-23 14:16:32 -04003382 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003383 if (context)
3384 {
3385 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003386 {
Geoff Langb1196682014-07-23 13:47:29 -04003387 context->recordError(gl::Error(GL_INVALID_VALUE));
3388 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003389 }
Geoff Langbfdea662014-07-23 14:16:32 -04003390
3391 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3392 {
Geoff Langb1196682014-07-23 13:47:29 -04003393 context->recordError(gl::Error(GL_INVALID_ENUM));
3394 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003395 }
3396
3397 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003398 }
3399}
3400
3401void __stdcall glHint(GLenum target, GLenum mode)
3402{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003403 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003404
Geoff Langbfdea662014-07-23 14:16:32 -04003405 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003406 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003407 {
Geoff Langb1196682014-07-23 13:47:29 -04003408 switch (mode)
3409 {
3410 case GL_FASTEST:
3411 case GL_NICEST:
3412 case GL_DONT_CARE:
3413 break;
3414
3415 default:
3416 context->recordError(gl::Error(GL_INVALID_ENUM));
3417 return;
3418 }
3419
3420 switch (target)
3421 {
3422 case GL_GENERATE_MIPMAP_HINT:
3423 context->getState().setGenerateMipmapHint(mode);
3424 break;
3425
3426 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3427 context->getState().setFragmentShaderDerivativeHint(mode);
3428 break;
3429
3430 default:
3431 context->recordError(gl::Error(GL_INVALID_ENUM));
3432 return;
3433 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003434 }
3435}
3436
3437GLboolean __stdcall glIsBuffer(GLuint buffer)
3438{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003439 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003440
Geoff Langbfdea662014-07-23 14:16:32 -04003441 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003442 if (context && buffer)
3443 {
3444 gl::Buffer *bufferObject = context->getBuffer(buffer);
3445
3446 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003447 {
Geoff Langbfdea662014-07-23 14:16:32 -04003448 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449 }
3450 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003451
3452 return GL_FALSE;
3453}
3454
3455GLboolean __stdcall glIsEnabled(GLenum cap)
3456{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003457 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003458
Geoff Langbfdea662014-07-23 14:16:32 -04003459 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003460 if (context)
3461 {
3462 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003463 {
Geoff Langb1196682014-07-23 13:47:29 -04003464 context->recordError(gl::Error(GL_INVALID_ENUM));
3465 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466 }
Geoff Langbfdea662014-07-23 14:16:32 -04003467
3468 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003469 }
3470
3471 return false;
3472}
3473
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003474GLboolean __stdcall glIsFenceNV(GLuint fence)
3475{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003476 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003477
Geoff Langbfdea662014-07-23 14:16:32 -04003478 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003479 if (context)
3480 {
3481 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3482
3483 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003484 {
Geoff Langbfdea662014-07-23 14:16:32 -04003485 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003486 }
Geoff Langbfdea662014-07-23 14:16:32 -04003487
3488 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003489 }
3490
3491 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003492}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003493
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3495{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003496 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003497
Geoff Langbfdea662014-07-23 14:16:32 -04003498 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003499 if (context && framebuffer)
3500 {
3501 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3502
3503 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003504 {
Geoff Langbfdea662014-07-23 14:16:32 -04003505 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003506 }
3507 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003508
3509 return GL_FALSE;
3510}
3511
3512GLboolean __stdcall glIsProgram(GLuint program)
3513{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003514 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003515
Geoff Langbfdea662014-07-23 14:16:32 -04003516 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003517 if (context && program)
3518 {
3519 gl::Program *programObject = context->getProgram(program);
3520
3521 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003522 {
Geoff Langbfdea662014-07-23 14:16:32 -04003523 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003524 }
3525 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526
3527 return GL_FALSE;
3528}
3529
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003530GLboolean __stdcall glIsQueryEXT(GLuint id)
3531{
3532 EVENT("(GLuint id = %d)", id);
3533
Geoff Langbfdea662014-07-23 14:16:32 -04003534 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003535 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003536 {
Geoff Langbfdea662014-07-23 14:16:32 -04003537 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003538 }
3539
3540 return GL_FALSE;
3541}
3542
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003543GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003545 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003546
Geoff Langbfdea662014-07-23 14:16:32 -04003547 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003548 if (context && renderbuffer)
3549 {
3550 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3551
3552 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003553 {
Geoff Langbfdea662014-07-23 14:16:32 -04003554 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003555 }
3556 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003557
3558 return GL_FALSE;
3559}
3560
3561GLboolean __stdcall glIsShader(GLuint shader)
3562{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003563 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003564
Geoff Langbfdea662014-07-23 14:16:32 -04003565 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003566 if (context && shader)
3567 {
3568 gl::Shader *shaderObject = context->getShader(shader);
3569
3570 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571 {
Geoff Langbfdea662014-07-23 14:16:32 -04003572 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003573 }
3574 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003575
3576 return GL_FALSE;
3577}
3578
3579GLboolean __stdcall glIsTexture(GLuint texture)
3580{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003581 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582
Geoff Langbfdea662014-07-23 14:16:32 -04003583 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003584 if (context && texture)
3585 {
3586 gl::Texture *textureObject = context->getTexture(texture);
3587
3588 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003589 {
Geoff Langbfdea662014-07-23 14:16:32 -04003590 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003591 }
3592 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003593
3594 return GL_FALSE;
3595}
3596
3597void __stdcall glLineWidth(GLfloat width)
3598{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003599 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003600
Geoff Langbfdea662014-07-23 14:16:32 -04003601 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003602 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003603 {
Geoff Langb1196682014-07-23 13:47:29 -04003604 if (width <= 0.0f)
3605 {
3606 context->recordError(gl::Error(GL_INVALID_VALUE));
3607 return;
3608 }
3609
Geoff Langbfdea662014-07-23 14:16:32 -04003610 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003611 }
3612}
3613
3614void __stdcall glLinkProgram(GLuint program)
3615{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003616 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617
Geoff Langbfdea662014-07-23 14:16:32 -04003618 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003619 if (context)
3620 {
3621 gl::Program *programObject = context->getProgram(program);
3622
3623 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003624 {
Geoff Langbfdea662014-07-23 14:16:32 -04003625 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003626 {
Geoff Langb1196682014-07-23 13:47:29 -04003627 context->recordError(gl::Error(GL_INVALID_OPERATION));
3628 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003629 }
Geoff Langbfdea662014-07-23 14:16:32 -04003630 else
3631 {
Geoff Langb1196682014-07-23 13:47:29 -04003632 context->recordError(gl::Error(GL_INVALID_VALUE));
3633 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003634 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003635 }
Geoff Langbfdea662014-07-23 14:16:32 -04003636
3637 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003638 }
3639}
3640
3641void __stdcall glPixelStorei(GLenum pname, GLint param)
3642{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003643 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003644
Geoff Langbfdea662014-07-23 14:16:32 -04003645 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003646 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003647 {
Geoff Langbfdea662014-07-23 14:16:32 -04003648 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003649 {
Geoff Langbfdea662014-07-23 14:16:32 -04003650 case GL_UNPACK_ALIGNMENT:
3651 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003652 {
Geoff Langb1196682014-07-23 13:47:29 -04003653 context->recordError(gl::Error(GL_INVALID_VALUE));
3654 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003655 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003656
Geoff Langbfdea662014-07-23 14:16:32 -04003657 context->getState().setUnpackAlignment(param);
3658 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003659
Geoff Langbfdea662014-07-23 14:16:32 -04003660 case GL_PACK_ALIGNMENT:
3661 if (param != 1 && param != 2 && param != 4 && param != 8)
3662 {
Geoff Langb1196682014-07-23 13:47:29 -04003663 context->recordError(gl::Error(GL_INVALID_VALUE));
3664 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003665 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003666
Geoff Langbfdea662014-07-23 14:16:32 -04003667 context->getState().setPackAlignment(param);
3668 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003669
Geoff Langbfdea662014-07-23 14:16:32 -04003670 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3671 context->getState().setPackReverseRowOrder(param != 0);
3672 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003673
Geoff Langbfdea662014-07-23 14:16:32 -04003674 case GL_UNPACK_IMAGE_HEIGHT:
3675 case GL_UNPACK_SKIP_IMAGES:
3676 case GL_UNPACK_ROW_LENGTH:
3677 case GL_UNPACK_SKIP_ROWS:
3678 case GL_UNPACK_SKIP_PIXELS:
3679 case GL_PACK_ROW_LENGTH:
3680 case GL_PACK_SKIP_ROWS:
3681 case GL_PACK_SKIP_PIXELS:
3682 if (context->getClientVersion() < 3)
3683 {
Geoff Langb1196682014-07-23 13:47:29 -04003684 context->recordError(gl::Error(GL_INVALID_ENUM));
3685 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003686 }
Geoff Langbfdea662014-07-23 14:16:32 -04003687 UNIMPLEMENTED();
3688 break;
3689
3690 default:
Geoff Langb1196682014-07-23 13:47:29 -04003691 context->recordError(gl::Error(GL_INVALID_ENUM));
3692 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003693 }
3694 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003695}
3696
3697void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3698{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003699 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003700
Geoff Langbfdea662014-07-23 14:16:32 -04003701 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003702 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003703 {
Geoff Langbfdea662014-07-23 14:16:32 -04003704 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003705 }
3706}
3707
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003708void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3709 GLenum format, GLenum type, GLsizei bufSize,
3710 GLvoid *data)
3711{
3712 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3713 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3714 x, y, width, height, format, type, bufSize, data);
3715
Geoff Langbfdea662014-07-23 14:16:32 -04003716 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003717 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003718 {
Geoff Langb1196682014-07-23 13:47:29 -04003719 if (width < 0 || height < 0 || bufSize < 0)
3720 {
3721 context->recordError(gl::Error(GL_INVALID_VALUE));
3722 return;
3723 }
3724
Geoff Langbfdea662014-07-23 14:16:32 -04003725 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3726 format, type, &bufSize, data))
3727 {
3728 return;
3729 }
3730
Geoff Lang63d2fc72014-07-25 14:51:41 -04003731 gl::Error error = context->readPixels(x, y, width, height, format, type, &bufSize, data);
3732 if (error.isError())
3733 {
3734 context->recordError(error);
3735 return;
3736 }
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003737 }
3738}
3739
3740void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3741 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003742{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003743 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003744 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003745 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003746
Geoff Langbfdea662014-07-23 14:16:32 -04003747 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003748 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003749 {
Geoff Langb1196682014-07-23 13:47:29 -04003750 if (width < 0 || height < 0)
3751 {
3752 context->recordError(gl::Error(GL_INVALID_VALUE));
3753 return;
3754 }
3755
Geoff Langbfdea662014-07-23 14:16:32 -04003756 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3757 format, type, NULL, pixels))
3758 {
3759 return;
3760 }
3761
Geoff Lang63d2fc72014-07-25 14:51:41 -04003762 gl::Error error = context->readPixels(x, y, width, height, format, type, NULL, pixels);
3763 if (error.isError())
3764 {
3765 context->recordError(error);
3766 return;
3767 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003768 }
3769}
3770
3771void __stdcall glReleaseShaderCompiler(void)
3772{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003773 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003774
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003775 gl::Context *context = gl::getNonLostContext();
3776
3777 if (context)
3778 {
3779 context->releaseShaderCompiler();
3780 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003781}
3782
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003783void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003784{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003785 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 +00003786 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003787
Geoff Langbfdea662014-07-23 14:16:32 -04003788 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003789 if (context)
3790 {
3791 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3792 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003793 {
Geoff Langbfdea662014-07-23 14:16:32 -04003794 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003795 }
Geoff Langbfdea662014-07-23 14:16:32 -04003796
3797 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003798 }
3799}
3800
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003801void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3802{
3803 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3804}
3805
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003806void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3807{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003808 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003809
Geoff Langbfdea662014-07-23 14:16:32 -04003810 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003811
Geoff Langbfdea662014-07-23 14:16:32 -04003812 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003813 {
Geoff Langbfdea662014-07-23 14:16:32 -04003814 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003815 }
3816}
3817
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003818void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3819{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003820 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003821
Geoff Langbfdea662014-07-23 14:16:32 -04003822 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003823 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003824 {
Geoff Langb1196682014-07-23 13:47:29 -04003825 if (condition != GL_ALL_COMPLETED_NV)
3826 {
3827 context->recordError(gl::Error(GL_INVALID_ENUM));
3828 return;
3829 }
3830
Geoff Langbfdea662014-07-23 14:16:32 -04003831 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3832
3833 if (fenceObject == NULL)
3834 {
Geoff Langb1196682014-07-23 13:47:29 -04003835 context->recordError(gl::Error(GL_INVALID_OPERATION));
3836 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003837 }
3838
3839 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003840 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003841}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003842
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003843void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003845 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 +00003846
Geoff Langbfdea662014-07-23 14:16:32 -04003847 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003848 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003849 {
Geoff Langb1196682014-07-23 13:47:29 -04003850 if (width < 0 || height < 0)
3851 {
3852 context->recordError(gl::Error(GL_INVALID_VALUE));
3853 return;
3854 }
3855
Geoff Langbfdea662014-07-23 14:16:32 -04003856 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003857 }
3858}
3859
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003860void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003861{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003862 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003863 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003864 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003865
Geoff Lang900013c2014-07-07 11:32:19 -04003866 gl::Context* context = gl::getNonLostContext();
3867 if (context)
3868 {
3869 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3870 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3871 {
Geoff Langb1196682014-07-23 13:47:29 -04003872 context->recordError(gl::Error(GL_INVALID_ENUM));
3873 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003874 }
3875
3876 // No binary shader formats are supported.
3877 UNIMPLEMENTED();
3878 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003879}
3880
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003881void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003882{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003883 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 +00003884 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003885
Geoff Langbfdea662014-07-23 14:16:32 -04003886 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003887 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003888 {
Geoff Langb1196682014-07-23 13:47:29 -04003889 if (count < 0)
3890 {
3891 context->recordError(gl::Error(GL_INVALID_VALUE));
3892 return;
3893 }
3894
Geoff Langbfdea662014-07-23 14:16:32 -04003895 gl::Shader *shaderObject = context->getShader(shader);
3896
3897 if (!shaderObject)
3898 {
3899 if (context->getProgram(shader))
3900 {
Geoff Langb1196682014-07-23 13:47:29 -04003901 context->recordError(gl::Error(GL_INVALID_OPERATION));
3902 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003903 }
3904 else
3905 {
Geoff Langb1196682014-07-23 13:47:29 -04003906 context->recordError(gl::Error(GL_INVALID_VALUE));
3907 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003908 }
3909 }
3910
3911 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003912 }
3913}
3914
3915void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3916{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003917 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003918}
3919
3920void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3921{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003922 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 +00003923
Geoff Langbfdea662014-07-23 14:16:32 -04003924 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003925 if (context)
3926 {
Geoff Langb1196682014-07-23 13:47:29 -04003927 switch (face)
3928 {
3929 case GL_FRONT:
3930 case GL_BACK:
3931 case GL_FRONT_AND_BACK:
3932 break;
3933
3934 default:
3935 context->recordError(gl::Error(GL_INVALID_ENUM));
3936 return;
3937 }
3938
3939 switch (func)
3940 {
3941 case GL_NEVER:
3942 case GL_ALWAYS:
3943 case GL_LESS:
3944 case GL_LEQUAL:
3945 case GL_EQUAL:
3946 case GL_GEQUAL:
3947 case GL_GREATER:
3948 case GL_NOTEQUAL:
3949 break;
3950
3951 default:
3952 context->recordError(gl::Error(GL_INVALID_ENUM));
3953 return;
3954 }
3955
Geoff Langbfdea662014-07-23 14:16:32 -04003956 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3957 {
3958 context->getState().setStencilParams(func, ref, mask);
3959 }
3960
3961 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3962 {
3963 context->getState().setStencilBackParams(func, ref, mask);
3964 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003965 }
3966}
3967
3968void __stdcall glStencilMask(GLuint mask)
3969{
3970 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3971}
3972
3973void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3974{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003975 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003976
Geoff Langbfdea662014-07-23 14:16:32 -04003977 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003978 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003979 {
Geoff Langb1196682014-07-23 13:47:29 -04003980 switch (face)
3981 {
3982 case GL_FRONT:
3983 case GL_BACK:
3984 case GL_FRONT_AND_BACK:
3985 break;
3986
3987 default:
3988 context->recordError(gl::Error(GL_INVALID_ENUM));
3989 return;
3990 }
3991
Geoff Langbfdea662014-07-23 14:16:32 -04003992 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3993 {
3994 context->getState().setStencilWritemask(mask);
3995 }
3996
3997 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3998 {
3999 context->getState().setStencilBackWritemask(mask);
4000 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004001 }
4002}
4003
4004void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4005{
4006 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4007}
4008
4009void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4010{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004011 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 +00004012 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004013
Geoff Langbfdea662014-07-23 14:16:32 -04004014 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004015 if (context)
4016 {
Geoff Langb1196682014-07-23 13:47:29 -04004017 switch (face)
4018 {
4019 case GL_FRONT:
4020 case GL_BACK:
4021 case GL_FRONT_AND_BACK:
4022 break;
4023
4024 default:
4025 context->recordError(gl::Error(GL_INVALID_ENUM));
4026 return;
4027 }
4028
4029 switch (fail)
4030 {
4031 case GL_ZERO:
4032 case GL_KEEP:
4033 case GL_REPLACE:
4034 case GL_INCR:
4035 case GL_DECR:
4036 case GL_INVERT:
4037 case GL_INCR_WRAP:
4038 case GL_DECR_WRAP:
4039 break;
4040
4041 default:
4042 context->recordError(gl::Error(GL_INVALID_ENUM));
4043 return;
4044 }
4045
4046 switch (zfail)
4047 {
4048 case GL_ZERO:
4049 case GL_KEEP:
4050 case GL_REPLACE:
4051 case GL_INCR:
4052 case GL_DECR:
4053 case GL_INVERT:
4054 case GL_INCR_WRAP:
4055 case GL_DECR_WRAP:
4056 break;
4057
4058 default:
4059 context->recordError(gl::Error(GL_INVALID_ENUM));
4060 return;
4061 }
4062
4063 switch (zpass)
4064 {
4065 case GL_ZERO:
4066 case GL_KEEP:
4067 case GL_REPLACE:
4068 case GL_INCR:
4069 case GL_DECR:
4070 case GL_INVERT:
4071 case GL_INCR_WRAP:
4072 case GL_DECR_WRAP:
4073 break;
4074
4075 default:
4076 context->recordError(gl::Error(GL_INVALID_ENUM));
4077 return;
4078 }
4079
Geoff Langbfdea662014-07-23 14:16:32 -04004080 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4081 {
4082 context->getState().setStencilOperations(fail, zfail, zpass);
4083 }
4084
4085 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4086 {
4087 context->getState().setStencilBackOperations(fail, zfail, zpass);
4088 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004089 }
4090}
4091
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004092GLboolean __stdcall glTestFenceNV(GLuint fence)
4093{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004094 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004095
Geoff Langbfdea662014-07-23 14:16:32 -04004096 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004097 if (context)
4098 {
4099 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4100
4101 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004102 {
Geoff Langb1196682014-07-23 13:47:29 -04004103 context->recordError(gl::Error(GL_INVALID_OPERATION));
4104 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004105 }
Geoff Langbfdea662014-07-23 14:16:32 -04004106
4107 if (fenceObject->isFence() != GL_TRUE)
4108 {
Geoff Langb1196682014-07-23 13:47:29 -04004109 context->recordError(gl::Error(GL_INVALID_OPERATION));
4110 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004111 }
4112
4113 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004114 }
Geoff Langbfdea662014-07-23 14:16:32 -04004115
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004116 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004117}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004118
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004119void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4120 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004122 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004123 "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 +00004124 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004125
Geoff Langbfdea662014-07-23 14:16:32 -04004126 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004127 if (context)
4128 {
4129 if (context->getClientVersion() < 3 &&
4130 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4131 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004132 {
Geoff Langbfdea662014-07-23 14:16:32 -04004133 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004134 }
Geoff Langbfdea662014-07-23 14:16:32 -04004135
4136 if (context->getClientVersion() >= 3 &&
4137 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4138 0, 0, 0, width, height, 1, border, format, type, pixels))
4139 {
4140 return;
4141 }
4142
4143 switch (target)
4144 {
4145 case GL_TEXTURE_2D:
4146 {
4147 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004148 gl::Error error = texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4149 if (error.isError())
4150 {
4151 context->recordError(error);
4152 return;
4153 }
Geoff Langbfdea662014-07-23 14:16:32 -04004154 }
4155 break;
4156 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4157 {
4158 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004159 gl::Error error = texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4160 if (error.isError())
4161 {
4162 context->recordError(error);
4163 return;
4164 }
Geoff Langbfdea662014-07-23 14:16:32 -04004165 }
4166 break;
4167 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4168 {
4169 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004170 gl::Error error = texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4171 if (error.isError())
4172 {
4173 context->recordError(error);
4174 return;
4175 }
Geoff Langbfdea662014-07-23 14:16:32 -04004176 }
4177 break;
4178 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4179 {
4180 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004181 gl::Error error = texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4182 if (error.isError())
4183 {
4184 context->recordError(error);
4185 return;
4186 }
Geoff Langbfdea662014-07-23 14:16:32 -04004187 }
4188 break;
4189 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4190 {
4191 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004192 gl::Error error = texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4193 if (error.isError())
4194 {
4195 context->recordError(error);
4196 return;
4197 }
Geoff Langbfdea662014-07-23 14:16:32 -04004198 }
4199 break;
4200 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4201 {
4202 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004203 gl::Error error = texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4204 if (error.isError())
4205 {
4206 context->recordError(error);
4207 return;
4208 }
Geoff Langbfdea662014-07-23 14:16:32 -04004209 }
4210 break;
4211 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4212 {
4213 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004214 gl::Error error = texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4215 if (error.isError())
4216 {
4217 context->recordError(error);
4218 return;
4219 }
Geoff Langbfdea662014-07-23 14:16:32 -04004220 }
4221 break;
4222 default: UNREACHABLE();
4223 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004224 }
4225}
4226
4227void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4228{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004229 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4230
Geoff Langbfdea662014-07-23 14:16:32 -04004231 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004232 if (context)
4233 {
4234 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004235 {
Geoff Langbfdea662014-07-23 14:16:32 -04004236 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004237 }
Geoff Langbfdea662014-07-23 14:16:32 -04004238
4239 gl::Texture *texture = context->getTargetTexture(target);
4240
4241 if (!texture)
4242 {
Geoff Langb1196682014-07-23 13:47:29 -04004243 context->recordError(gl::Error(GL_INVALID_ENUM));
4244 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004245 }
4246
4247 switch (pname)
4248 {
4249 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4250 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4251 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4252 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4253 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4254 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4255 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4256 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4257 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4258 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4259 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4260 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4261 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4262 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4263 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4264 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4265 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4266 default: UNREACHABLE(); break;
4267 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004268 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004269}
4270
4271void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4272{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004273 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004274}
4275
4276void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4277{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004278 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004279
Geoff Langbfdea662014-07-23 14:16:32 -04004280 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004281 if (context)
4282 {
4283 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004284 {
Geoff Langbfdea662014-07-23 14:16:32 -04004285 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004286 }
Geoff Langbfdea662014-07-23 14:16:32 -04004287
4288 gl::Texture *texture = context->getTargetTexture(target);
4289
4290 if (!texture)
4291 {
Geoff Langb1196682014-07-23 13:47:29 -04004292 context->recordError(gl::Error(GL_INVALID_ENUM));
4293 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004294 }
4295
4296 switch (pname)
4297 {
4298 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4299 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4300 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4301 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4302 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4303 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4304 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4305 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4306 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4307 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4308 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4309 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4310 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4311 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4312 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4313 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4314 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4315 default: UNREACHABLE(); break;
4316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004317 }
4318}
4319
4320void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4321{
4322 glTexParameteri(target, pname, *params);
4323}
4324
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004325void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4326{
4327 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4328 target, levels, internalformat, width, height);
4329
Geoff Langbfdea662014-07-23 14:16:32 -04004330 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004331 if (context)
4332 {
4333 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004334 {
Geoff Langb1196682014-07-23 13:47:29 -04004335 context->recordError(gl::Error(GL_INVALID_OPERATION));
4336 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004337 }
Geoff Langbfdea662014-07-23 14:16:32 -04004338
4339 if (context->getClientVersion() < 3 &&
4340 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4341 {
4342 return;
4343 }
4344
4345 if (context->getClientVersion() >= 3 &&
4346 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4347 {
4348 return;
4349 }
4350
4351 switch (target)
4352 {
4353 case GL_TEXTURE_2D:
4354 {
4355 gl::Texture2D *texture2d = context->getTexture2D();
4356 texture2d->storage(levels, internalformat, width, height);
4357 }
4358 break;
4359
4360 case GL_TEXTURE_CUBE_MAP:
4361 {
4362 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4363 textureCube->storage(levels, internalformat, width);
4364 }
4365 break;
4366
4367 default:
Geoff Langb1196682014-07-23 13:47:29 -04004368 context->recordError(gl::Error(GL_INVALID_ENUM));
4369 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004370 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004371 }
4372}
4373
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004374void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4375 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004376{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004377 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004378 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004379 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004380 target, level, xoffset, yoffset, width, height, format, type, pixels);
4381
Geoff Langbfdea662014-07-23 14:16:32 -04004382 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004383 if (context)
4384 {
4385 if (context->getClientVersion() < 3 &&
4386 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4387 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004388 {
Geoff Langbfdea662014-07-23 14:16:32 -04004389 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004390 }
Geoff Langbfdea662014-07-23 14:16:32 -04004391
4392 if (context->getClientVersion() >= 3 &&
4393 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4394 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4395 {
4396 return;
4397 }
4398
4399 // Zero sized uploads are valid but no-ops
4400 if (width == 0 || height == 0)
4401 {
4402 return;
4403 }
4404
4405 switch (target)
4406 {
4407 case GL_TEXTURE_2D:
4408 {
4409 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004410 gl::Error error = texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4411 if (error.isError())
4412 {
4413 context->recordError(error);
4414 return;
4415 }
Geoff Langbfdea662014-07-23 14:16:32 -04004416 }
4417 break;
4418
4419 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4420 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4421 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4422 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4423 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4424 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4425 {
4426 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004427 gl::Error error = texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4428 if (error.isError())
4429 {
4430 context->recordError(error);
4431 return;
4432 }
Geoff Langbfdea662014-07-23 14:16:32 -04004433 }
4434 break;
4435
4436 default:
4437 UNREACHABLE();
4438 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004439 }
4440}
4441
4442void __stdcall glUniform1f(GLint location, GLfloat x)
4443{
4444 glUniform1fv(location, 1, &x);
4445}
4446
4447void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4448{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004449 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450
Geoff Langbfdea662014-07-23 14:16:32 -04004451 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004452 if (context)
4453 {
4454 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004455 {
Geoff Langbfdea662014-07-23 14:16:32 -04004456 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004457 }
Geoff Langbfdea662014-07-23 14:16:32 -04004458
4459 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4460 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004461 }
4462}
4463
4464void __stdcall glUniform1i(GLint location, GLint x)
4465{
4466 glUniform1iv(location, 1, &x);
4467}
4468
4469void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4470{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004471 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004472
Geoff Langbfdea662014-07-23 14:16:32 -04004473 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004474 if (context)
4475 {
4476 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004477 {
Geoff Langbfdea662014-07-23 14:16:32 -04004478 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479 }
Geoff Langbfdea662014-07-23 14:16:32 -04004480
4481 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4482 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004483 }
4484}
4485
4486void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4487{
4488 GLfloat xy[2] = {x, y};
4489
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004490 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004491}
4492
4493void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4494{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004495 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004496
Geoff Langbfdea662014-07-23 14:16:32 -04004497 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004498 if (context)
4499 {
4500 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004501 {
Geoff Langbfdea662014-07-23 14:16:32 -04004502 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004503 }
Geoff Langbfdea662014-07-23 14:16:32 -04004504
4505 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4506 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004507 }
4508}
4509
4510void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4511{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004512 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004513
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004514 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004515}
4516
4517void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4518{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004519 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004520
Geoff Langbfdea662014-07-23 14:16:32 -04004521 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004522 if (context)
4523 {
4524 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004525 {
Geoff Langbfdea662014-07-23 14:16:32 -04004526 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004527 }
Geoff Langbfdea662014-07-23 14:16:32 -04004528
4529 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4530 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004531 }
4532}
4533
4534void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4535{
4536 GLfloat xyz[3] = {x, y, z};
4537
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004538 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004539}
4540
4541void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4542{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004543 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004544
Geoff Langbfdea662014-07-23 14:16:32 -04004545 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004546 if (context)
4547 {
4548 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004549 {
Geoff Langbfdea662014-07-23 14:16:32 -04004550 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004551 }
Geoff Langbfdea662014-07-23 14:16:32 -04004552
4553 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4554 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555 }
4556}
4557
4558void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4559{
4560 GLint xyz[3] = {x, y, z};
4561
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004562 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004563}
4564
4565void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4566{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004567 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004568
Geoff Langbfdea662014-07-23 14:16:32 -04004569 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004570 if (context)
4571 {
4572 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004573 {
Geoff Langbfdea662014-07-23 14:16:32 -04004574 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004575 }
Geoff Langbfdea662014-07-23 14:16:32 -04004576
4577 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4578 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004579 }
4580}
4581
4582void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4583{
4584 GLfloat xyzw[4] = {x, y, z, w};
4585
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004586 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004587}
4588
4589void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4590{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004591 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004592
Geoff Langbfdea662014-07-23 14:16:32 -04004593 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004594 if (context)
4595 {
4596 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004597 {
Geoff Langbfdea662014-07-23 14:16:32 -04004598 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004599 }
Geoff Langbfdea662014-07-23 14:16:32 -04004600
4601 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4602 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004603 }
4604}
4605
4606void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4607{
4608 GLint xyzw[4] = {x, y, z, w};
4609
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004610 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004611}
4612
4613void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4614{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004615 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004616
Geoff Langbfdea662014-07-23 14:16:32 -04004617 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004618 if (context)
4619 {
4620 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004621 {
Geoff Langbfdea662014-07-23 14:16:32 -04004622 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004623 }
Geoff Langbfdea662014-07-23 14:16:32 -04004624
4625 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4626 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 }
4628}
4629
4630void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4631{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004632 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004633 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634
Geoff Langbfdea662014-07-23 14:16:32 -04004635 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004636 if (context)
4637 {
4638 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004639 {
Geoff Langbfdea662014-07-23 14:16:32 -04004640 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004641 }
Geoff Langbfdea662014-07-23 14:16:32 -04004642
4643 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4644 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004645 }
4646}
4647
4648void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4649{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004650 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004651 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004652
Geoff Langbfdea662014-07-23 14:16:32 -04004653 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004654 if (context)
4655 {
4656 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004657 {
Geoff Langbfdea662014-07-23 14:16:32 -04004658 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004659 }
Geoff Langbfdea662014-07-23 14:16:32 -04004660
4661 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4662 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004663 }
4664}
4665
4666void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4667{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004668 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004669 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670
Geoff Langbfdea662014-07-23 14:16:32 -04004671 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004672 if (context)
4673 {
4674 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004675 {
Geoff Langbfdea662014-07-23 14:16:32 -04004676 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004677 }
Geoff Langbfdea662014-07-23 14:16:32 -04004678
4679 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4680 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004681 }
4682}
4683
4684void __stdcall glUseProgram(GLuint program)
4685{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004686 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004687
Geoff Langbfdea662014-07-23 14:16:32 -04004688 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004689 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004690 {
Geoff Langbfdea662014-07-23 14:16:32 -04004691 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004692
Geoff Langbfdea662014-07-23 14:16:32 -04004693 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004694 {
Geoff Langbfdea662014-07-23 14:16:32 -04004695 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004696 {
Geoff Langb1196682014-07-23 13:47:29 -04004697 context->recordError(gl::Error(GL_INVALID_OPERATION));
4698 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004699 }
Geoff Langbfdea662014-07-23 14:16:32 -04004700 else
4701 {
Geoff Langb1196682014-07-23 13:47:29 -04004702 context->recordError(gl::Error(GL_INVALID_VALUE));
4703 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004704 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004705 }
Geoff Langbfdea662014-07-23 14:16:32 -04004706
4707 if (program != 0 && !programObject->isLinked())
4708 {
Geoff Langb1196682014-07-23 13:47:29 -04004709 context->recordError(gl::Error(GL_INVALID_OPERATION));
4710 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004711 }
4712
4713 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004714 }
4715}
4716
4717void __stdcall glValidateProgram(GLuint program)
4718{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004719 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004720
Geoff Langbfdea662014-07-23 14:16:32 -04004721 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004722 if (context)
4723 {
4724 gl::Program *programObject = context->getProgram(program);
4725
4726 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004727 {
Geoff Langbfdea662014-07-23 14:16:32 -04004728 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004729 {
Geoff Langb1196682014-07-23 13:47:29 -04004730 context->recordError(gl::Error(GL_INVALID_OPERATION));
4731 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004732 }
Geoff Langbfdea662014-07-23 14:16:32 -04004733 else
4734 {
Geoff Langb1196682014-07-23 13:47:29 -04004735 context->recordError(gl::Error(GL_INVALID_VALUE));
4736 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004737 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004738 }
Geoff Langbfdea662014-07-23 14:16:32 -04004739
Brandon Jones43a53e22014-08-28 16:23:22 -07004740 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004741 }
4742}
4743
4744void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4745{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004746 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004747
Geoff Langbfdea662014-07-23 14:16:32 -04004748 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004749 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004750 {
Geoff Langb1196682014-07-23 13:47:29 -04004751 if (index >= gl::MAX_VERTEX_ATTRIBS)
4752 {
4753 context->recordError(gl::Error(GL_INVALID_VALUE));
4754 return;
4755 }
4756
Geoff Langbfdea662014-07-23 14:16:32 -04004757 GLfloat vals[4] = { x, 0, 0, 1 };
4758 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004759 }
4760}
4761
4762void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4763{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004764 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004765
Geoff Langbfdea662014-07-23 14:16:32 -04004766 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004767 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004768 {
Geoff Langb1196682014-07-23 13:47:29 -04004769 if (index >= gl::MAX_VERTEX_ATTRIBS)
4770 {
4771 context->recordError(gl::Error(GL_INVALID_VALUE));
4772 return;
4773 }
4774
Geoff Langbfdea662014-07-23 14:16:32 -04004775 GLfloat vals[4] = { values[0], 0, 0, 1 };
4776 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004777 }
4778}
4779
4780void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4781{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004782 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004783
Geoff Langbfdea662014-07-23 14:16:32 -04004784 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004785 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004786 {
Geoff Langb1196682014-07-23 13:47:29 -04004787 if (index >= gl::MAX_VERTEX_ATTRIBS)
4788 {
4789 context->recordError(gl::Error(GL_INVALID_VALUE));
4790 return;
4791 }
4792
Geoff Langbfdea662014-07-23 14:16:32 -04004793 GLfloat vals[4] = { x, y, 0, 1 };
4794 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004795 }
4796}
4797
4798void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4799{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004800 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004801
Geoff Langbfdea662014-07-23 14:16:32 -04004802 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004803 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004804 {
Geoff Langb1196682014-07-23 13:47:29 -04004805 if (index >= gl::MAX_VERTEX_ATTRIBS)
4806 {
4807 context->recordError(gl::Error(GL_INVALID_VALUE));
4808 return;
4809 }
4810
Geoff Langbfdea662014-07-23 14:16:32 -04004811 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4812 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004813 }
4814}
4815
4816void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4817{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004818 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 +00004819
Geoff Langbfdea662014-07-23 14:16:32 -04004820 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004821 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004822 {
Geoff Langb1196682014-07-23 13:47:29 -04004823 if (index >= gl::MAX_VERTEX_ATTRIBS)
4824 {
4825 context->recordError(gl::Error(GL_INVALID_VALUE));
4826 return;
4827 }
4828
Geoff Langbfdea662014-07-23 14:16:32 -04004829 GLfloat vals[4] = { x, y, z, 1 };
4830 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004831 }
4832}
4833
4834void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4835{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004836 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004837
Geoff Langbfdea662014-07-23 14:16:32 -04004838 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004839 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004840 {
Geoff Langb1196682014-07-23 13:47:29 -04004841 if (index >= gl::MAX_VERTEX_ATTRIBS)
4842 {
4843 context->recordError(gl::Error(GL_INVALID_VALUE));
4844 return;
4845 }
4846
Geoff Langbfdea662014-07-23 14:16:32 -04004847 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4848 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004849 }
4850}
4851
4852void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4853{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004854 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 +00004855
Geoff Langbfdea662014-07-23 14:16:32 -04004856 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004857 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004858 {
Geoff Langb1196682014-07-23 13:47:29 -04004859 if (index >= gl::MAX_VERTEX_ATTRIBS)
4860 {
4861 context->recordError(gl::Error(GL_INVALID_VALUE));
4862 return;
4863 }
4864
Geoff Langbfdea662014-07-23 14:16:32 -04004865 GLfloat vals[4] = { x, y, z, w };
4866 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004867 }
4868}
4869
4870void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4871{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004872 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004873
Geoff Langbfdea662014-07-23 14:16:32 -04004874 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004875 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004876 {
Geoff Langb1196682014-07-23 13:47:29 -04004877 if (index >= gl::MAX_VERTEX_ATTRIBS)
4878 {
4879 context->recordError(gl::Error(GL_INVALID_VALUE));
4880 return;
4881 }
4882
Geoff Langbfdea662014-07-23 14:16:32 -04004883 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004884 }
4885}
4886
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004887void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4888{
4889 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4890
Geoff Langbfdea662014-07-23 14:16:32 -04004891 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004892 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004893 {
Geoff Langb1196682014-07-23 13:47:29 -04004894 if (index >= gl::MAX_VERTEX_ATTRIBS)
4895 {
4896 context->recordError(gl::Error(GL_INVALID_VALUE));
4897 return;
4898 }
4899
Geoff Langbfdea662014-07-23 14:16:32 -04004900 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004901 }
4902}
4903
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004904void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004905{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004906 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004907 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004908 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004909
Geoff Langbfdea662014-07-23 14:16:32 -04004910 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004911 if (context)
4912 {
Geoff Langb1196682014-07-23 13:47:29 -04004913 if (index >= gl::MAX_VERTEX_ATTRIBS)
4914 {
4915 context->recordError(gl::Error(GL_INVALID_VALUE));
4916 return;
4917 }
4918
4919 if (size < 1 || size > 4)
4920 {
4921 context->recordError(gl::Error(GL_INVALID_VALUE));
4922 return;
4923 }
4924
4925 switch (type)
4926 {
4927 case GL_BYTE:
4928 case GL_UNSIGNED_BYTE:
4929 case GL_SHORT:
4930 case GL_UNSIGNED_SHORT:
4931 case GL_FIXED:
4932 case GL_FLOAT:
4933 break;
4934
4935 case GL_HALF_FLOAT:
4936 case GL_INT:
4937 case GL_UNSIGNED_INT:
4938 case GL_INT_2_10_10_10_REV:
4939 case GL_UNSIGNED_INT_2_10_10_10_REV:
4940 if (context->getClientVersion() < 3)
4941 {
4942 context->recordError(gl::Error(GL_INVALID_ENUM));
4943 return;
4944 }
4945 break;
4946
4947 default:
4948 context->recordError(gl::Error(GL_INVALID_ENUM));
4949 return;
4950 }
4951
4952 if (stride < 0)
4953 {
4954 context->recordError(gl::Error(GL_INVALID_VALUE));
4955 return;
4956 }
4957
4958 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4959 {
4960 context->recordError(gl::Error(GL_INVALID_OPERATION));
4961 return;
4962 }
4963
Geoff Langbfdea662014-07-23 14:16:32 -04004964 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4965 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4966 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4967 // and the pointer argument is not NULL.
4968 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004969 {
Geoff Langb1196682014-07-23 13:47:29 -04004970 context->recordError(gl::Error(GL_INVALID_OPERATION));
4971 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004972 }
4973
Geoff Langbfdea662014-07-23 14:16:32 -04004974 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4975 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004976 }
4977}
4978
4979void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4980{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004981 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 +00004982
Geoff Langbfdea662014-07-23 14:16:32 -04004983 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004984 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004985 {
Geoff Langb1196682014-07-23 13:47:29 -04004986 if (width < 0 || height < 0)
4987 {
4988 context->recordError(gl::Error(GL_INVALID_VALUE));
4989 return;
4990 }
4991
Geoff Langbfdea662014-07-23 14:16:32 -04004992 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004993 }
4994}
4995
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004996// OpenGL ES 3.0 functions
4997
4998void __stdcall glReadBuffer(GLenum mode)
4999{
5000 EVENT("(GLenum mode = 0x%X)", mode);
5001
Geoff Langbfdea662014-07-23 14:16:32 -04005002 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005003 if (context)
5004 {
5005 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005006 {
Geoff Langb1196682014-07-23 13:47:29 -04005007 context->recordError(gl::Error(GL_INVALID_OPERATION));
5008 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005009 }
Geoff Langbfdea662014-07-23 14:16:32 -04005010
5011 // glReadBuffer
5012 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005013 }
5014}
5015
5016void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
5017{
5018 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
5019 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
5020
Geoff Langbfdea662014-07-23 14:16:32 -04005021 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005022 if (context)
5023 {
5024 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005025 {
Geoff Langb1196682014-07-23 13:47:29 -04005026 context->recordError(gl::Error(GL_INVALID_OPERATION));
5027 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005028 }
Geoff Langbfdea662014-07-23 14:16:32 -04005029
5030 // glDrawRangeElements
5031 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005032 }
5033}
5034
5035void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
5036{
5037 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
5038 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
5039 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5040 target, level, internalformat, width, height, depth, border, format, type, pixels);
5041
Geoff Langbfdea662014-07-23 14:16:32 -04005042 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005043 if (context)
5044 {
5045 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005046 {
Geoff Langb1196682014-07-23 13:47:29 -04005047 context->recordError(gl::Error(GL_INVALID_OPERATION));
5048 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005049 }
Geoff Langbfdea662014-07-23 14:16:32 -04005050
5051 // validateES3TexImageFormat sets the error code if there is an error
5052 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
5053 0, 0, 0, width, height, depth, border, format, type, pixels))
5054 {
5055 return;
5056 }
5057
5058 switch(target)
5059 {
5060 case GL_TEXTURE_3D:
5061 {
5062 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005063 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5064 if (error.isError())
5065 {
5066 context->recordError(error);
5067 return;
5068 }
Geoff Langbfdea662014-07-23 14:16:32 -04005069 }
5070 break;
5071
5072 case GL_TEXTURE_2D_ARRAY:
5073 {
5074 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005075 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5076 if (error.isError())
5077 {
5078 context->recordError(error);
5079 return;
5080 }
Geoff Langbfdea662014-07-23 14:16:32 -04005081 }
5082 break;
5083
5084 default:
Geoff Langb1196682014-07-23 13:47:29 -04005085 context->recordError(gl::Error(GL_INVALID_ENUM));
5086 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005087 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005088 }
5089}
5090
5091void __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)
5092{
5093 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5094 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5095 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5096 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
5097
Geoff Langbfdea662014-07-23 14:16:32 -04005098 gl::Context *context = gl::getNonLostContext();
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 Langb1196682014-07-23 13:47:29 -04005103 context->recordError(gl::Error(GL_INVALID_OPERATION));
5104 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005105 }
Geoff Langbfdea662014-07-23 14:16:32 -04005106
5107 // validateES3TexImageFormat sets the error code if there is an error
5108 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5109 xoffset, yoffset, zoffset, width, height, depth, 0,
5110 format, type, pixels))
5111 {
5112 return;
5113 }
5114
5115 // Zero sized uploads are valid but no-ops
5116 if (width == 0 || height == 0 || depth == 0)
5117 {
5118 return;
5119 }
5120
5121 switch(target)
5122 {
5123 case GL_TEXTURE_3D:
5124 {
5125 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005126 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5127 if (error.isError())
5128 {
5129 context->recordError(error);
5130 return;
5131 }
Geoff Langbfdea662014-07-23 14:16:32 -04005132 }
5133 break;
5134
5135 case GL_TEXTURE_2D_ARRAY:
5136 {
5137 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005138 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5139 if (error.isError())
5140 {
5141 context->recordError(error);
5142 return;
5143 }
Geoff Langbfdea662014-07-23 14:16:32 -04005144 }
5145 break;
5146
5147 default:
Geoff Langb1196682014-07-23 13:47:29 -04005148 context->recordError(gl::Error(GL_INVALID_ENUM));
5149 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005150 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005151 }
5152}
5153
5154void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5155{
5156 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5157 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5158 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5159
Geoff Langbfdea662014-07-23 14:16:32 -04005160 gl::Context *context = gl::getNonLostContext();
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 Langb1196682014-07-23 13:47:29 -04005165 context->recordError(gl::Error(GL_INVALID_OPERATION));
5166 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005167 }
Geoff Langbfdea662014-07-23 14:16:32 -04005168
5169 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5170 x, y, width, height, 0))
5171 {
5172 return;
5173 }
5174
5175 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5176 gl::Texture *texture = NULL;
5177 switch (target)
5178 {
5179 case GL_TEXTURE_3D:
5180 texture = context->getTexture3D();
5181 break;
5182
5183 case GL_TEXTURE_2D_ARRAY:
5184 texture = context->getTexture2DArray();
5185 break;
5186
5187 default:
Geoff Langb1196682014-07-23 13:47:29 -04005188 context->recordError(gl::Error(GL_INVALID_ENUM));
5189 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005190 }
5191
5192 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005193 }
5194}
5195
5196void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5197{
Geoff Langeef52cc2013-10-16 15:07:39 -04005198 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 +00005199 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5200 "const GLvoid* data = 0x%0.8p)",
5201 target, level, internalformat, width, height, depth, border, imageSize, data);
5202
Geoff Langbfdea662014-07-23 14:16:32 -04005203 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005204 if (context)
5205 {
5206 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005207 {
Geoff Langb1196682014-07-23 13:47:29 -04005208 context->recordError(gl::Error(GL_INVALID_OPERATION));
5209 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005210 }
Geoff Langbfdea662014-07-23 14:16:32 -04005211
Geoff Lang5d601382014-07-22 15:14:06 -04005212 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5213 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005214 {
Geoff Langb1196682014-07-23 13:47:29 -04005215 context->recordError(gl::Error(GL_INVALID_VALUE));
5216 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005217 }
5218
5219 // validateES3TexImageFormat sets the error code if there is an error
5220 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5221 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5222 {
5223 return;
5224 }
5225
5226 switch(target)
5227 {
5228 case GL_TEXTURE_3D:
5229 {
5230 gl::Texture3D *texture = context->getTexture3D();
5231 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5232 }
5233 break;
5234
5235 case GL_TEXTURE_2D_ARRAY:
5236 {
5237 gl::Texture2DArray *texture = context->getTexture2DArray();
5238 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5239 }
5240 break;
5241
5242 default:
Geoff Langb1196682014-07-23 13:47:29 -04005243 context->recordError(gl::Error(GL_INVALID_ENUM));
5244 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005245 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005246 }
5247}
5248
5249void __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)
5250{
5251 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5252 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5253 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5254 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5255
Geoff Langbfdea662014-07-23 14:16:32 -04005256 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005257 if (context)
5258 {
5259 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005260 {
Geoff Langb1196682014-07-23 13:47:29 -04005261 context->recordError(gl::Error(GL_INVALID_OPERATION));
5262 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005263 }
Geoff Langbfdea662014-07-23 14:16:32 -04005264
Geoff Lang5d601382014-07-22 15:14:06 -04005265 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5266 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005267 {
Geoff Langb1196682014-07-23 13:47:29 -04005268 context->recordError(gl::Error(GL_INVALID_VALUE));
5269 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005270 }
5271
5272 if (!data)
5273 {
Geoff Langb1196682014-07-23 13:47:29 -04005274 context->recordError(gl::Error(GL_INVALID_VALUE));
5275 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005276 }
5277
5278 // validateES3TexImageFormat sets the error code if there is an error
5279 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5280 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5281 {
5282 return;
5283 }
5284
5285 // Zero sized uploads are valid but no-ops
5286 if (width == 0 || height == 0)
5287 {
5288 return;
5289 }
5290
5291 switch(target)
5292 {
5293 case GL_TEXTURE_3D:
5294 {
5295 gl::Texture3D *texture = context->getTexture3D();
5296 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5297 format, imageSize, data);
5298 }
5299 break;
5300
5301 case GL_TEXTURE_2D_ARRAY:
5302 {
5303 gl::Texture2DArray *texture = context->getTexture2DArray();
5304 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5305 format, imageSize, data);
5306 }
5307 break;
5308
Geoff Langb1196682014-07-23 13:47:29 -04005309 default:
5310 context->recordError(gl::Error(GL_INVALID_ENUM));
5311 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005312 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005313 }
5314}
5315
5316void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5317{
5318 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5319
Geoff Langbfdea662014-07-23 14:16:32 -04005320 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005321 if (context)
5322 {
5323 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005324 {
Geoff Langb1196682014-07-23 13:47:29 -04005325 context->recordError(gl::Error(GL_INVALID_OPERATION));
5326 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005327 }
Geoff Langbfdea662014-07-23 14:16:32 -04005328
5329 if (n < 0)
5330 {
Geoff Langb1196682014-07-23 13:47:29 -04005331 context->recordError(gl::Error(GL_INVALID_VALUE));
5332 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005333 }
5334
5335 for (GLsizei i = 0; i < n; i++)
5336 {
5337 ids[i] = context->createQuery();
5338 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005339 }
5340}
5341
5342void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5343{
5344 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5345
Geoff Langbfdea662014-07-23 14:16:32 -04005346 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005347 if (context)
5348 {
5349 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005350 {
Geoff Langb1196682014-07-23 13:47:29 -04005351 context->recordError(gl::Error(GL_INVALID_OPERATION));
5352 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005353 }
Geoff Langbfdea662014-07-23 14:16:32 -04005354
5355 if (n < 0)
5356 {
Geoff Langb1196682014-07-23 13:47:29 -04005357 context->recordError(gl::Error(GL_INVALID_VALUE));
5358 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005359 }
5360
5361 for (GLsizei i = 0; i < n; i++)
5362 {
5363 context->deleteQuery(ids[i]);
5364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005365 }
5366}
5367
5368GLboolean __stdcall glIsQuery(GLuint id)
5369{
5370 EVENT("(GLuint id = %u)", id);
5371
Geoff Langbfdea662014-07-23 14:16:32 -04005372 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005373 if (context)
5374 {
5375 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005376 {
Geoff Langb1196682014-07-23 13:47:29 -04005377 context->recordError(gl::Error(GL_INVALID_OPERATION));
5378 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005379 }
Geoff Langbfdea662014-07-23 14:16:32 -04005380
5381 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005382 }
5383
5384 return GL_FALSE;
5385}
5386
5387void __stdcall glBeginQuery(GLenum target, GLuint id)
5388{
5389 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5390
Geoff Langbfdea662014-07-23 14:16:32 -04005391 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005392 if (context)
5393 {
5394 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005395 {
Geoff Langb1196682014-07-23 13:47:29 -04005396 context->recordError(gl::Error(GL_INVALID_OPERATION));
5397 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005398 }
Geoff Langbfdea662014-07-23 14:16:32 -04005399
5400 if (!ValidateBeginQuery(context, target, id))
5401 {
5402 return;
5403 }
Geoff Lang5aad9672014-09-08 11:10:42 -04005404
5405 gl::Error error = context->beginQuery(target, id);
5406 if (error.isError())
5407 {
5408 context->recordError(error);
5409 return;
5410 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005411 }
5412}
5413
5414void __stdcall glEndQuery(GLenum target)
5415{
5416 EVENT("(GLenum target = 0x%X)", target);
5417
Geoff Langbfdea662014-07-23 14:16:32 -04005418 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005419 if (context)
5420 {
5421 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005422 {
Geoff Langb1196682014-07-23 13:47:29 -04005423 context->recordError(gl::Error(GL_INVALID_OPERATION));
5424 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005425 }
Geoff Langbfdea662014-07-23 14:16:32 -04005426
5427 if (!ValidateEndQuery(context, target))
5428 {
5429 return;
5430 }
5431
Geoff Lang5aad9672014-09-08 11:10:42 -04005432 gl::Error error = context->endQuery(target);
5433 if (error.isError())
5434 {
5435 context->recordError(error);
5436 return;
5437 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005438 }
5439}
5440
5441void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5442{
5443 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5444
Geoff Langbfdea662014-07-23 14:16:32 -04005445 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005446 if (context)
5447 {
5448 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005449 {
Geoff Langb1196682014-07-23 13:47:29 -04005450 context->recordError(gl::Error(GL_INVALID_OPERATION));
5451 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005452 }
Geoff Langbfdea662014-07-23 14:16:32 -04005453
5454 if (!ValidQueryType(context, target))
5455 {
Geoff Langb1196682014-07-23 13:47:29 -04005456 context->recordError(gl::Error(GL_INVALID_ENUM));
5457 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005458 }
5459
5460 switch (pname)
5461 {
5462 case GL_CURRENT_QUERY:
5463 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5464 break;
5465
5466 default:
Geoff Langb1196682014-07-23 13:47:29 -04005467 context->recordError(gl::Error(GL_INVALID_ENUM));
5468 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005469 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005470 }
5471}
5472
5473void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5474{
5475 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5476
Geoff Langbfdea662014-07-23 14:16:32 -04005477 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005478 if (context)
5479 {
5480 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005481 {
Geoff Langb1196682014-07-23 13:47:29 -04005482 context->recordError(gl::Error(GL_INVALID_OPERATION));
5483 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005484 }
Geoff Langbfdea662014-07-23 14:16:32 -04005485
5486 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5487
5488 if (!queryObject)
5489 {
Geoff Langb1196682014-07-23 13:47:29 -04005490 context->recordError(gl::Error(GL_INVALID_OPERATION));
5491 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005492 }
5493
5494 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5495 {
Geoff Langb1196682014-07-23 13:47:29 -04005496 context->recordError(gl::Error(GL_INVALID_OPERATION));
5497 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005498 }
5499
5500 switch(pname)
5501 {
Geoff Lang5aad9672014-09-08 11:10:42 -04005502 case GL_QUERY_RESULT_EXT:
5503 {
5504 gl::Error error = queryObject->getResult(params);
5505 if (error.isError())
5506 {
5507 context->recordError(error);
5508 return;
5509 }
5510 }
Geoff Langbfdea662014-07-23 14:16:32 -04005511 break;
Geoff Langb1196682014-07-23 13:47:29 -04005512
Geoff Lang5aad9672014-09-08 11:10:42 -04005513 case GL_QUERY_RESULT_AVAILABLE_EXT:
5514 {
5515 gl::Error error = queryObject->isResultAvailable(params);
5516 if (error.isError())
5517 {
5518 context->recordError(error);
5519 return;
5520 }
5521 }
Geoff Langbfdea662014-07-23 14:16:32 -04005522 break;
Geoff Langb1196682014-07-23 13:47:29 -04005523
Geoff Langbfdea662014-07-23 14:16:32 -04005524 default:
Geoff Langb1196682014-07-23 13:47:29 -04005525 context->recordError(gl::Error(GL_INVALID_ENUM));
5526 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005527 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005528 }
5529}
5530
5531GLboolean __stdcall glUnmapBuffer(GLenum target)
5532{
5533 EVENT("(GLenum target = 0x%X)", target);
5534
Geoff Langbfdea662014-07-23 14:16:32 -04005535 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005536 if (context)
5537 {
5538 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005539 {
Geoff Langb1196682014-07-23 13:47:29 -04005540 context->recordError(gl::Error(GL_INVALID_OPERATION));
5541 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005542 }
Geoff Langbfdea662014-07-23 14:16:32 -04005543
5544 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005545 }
5546
5547 return GL_FALSE;
5548}
5549
5550void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5551{
5552 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5553
Geoff Langbfdea662014-07-23 14:16:32 -04005554 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005555 if (context)
5556 {
5557 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005558 {
Geoff Langb1196682014-07-23 13:47:29 -04005559 context->recordError(gl::Error(GL_INVALID_OPERATION));
5560 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005561 }
Geoff Langbfdea662014-07-23 14:16:32 -04005562
5563 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005564 }
5565}
5566
5567void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5568{
Geoff Langbfdea662014-07-23 14:16:32 -04005569 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005570 if (context)
5571 {
5572 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005573 {
Geoff Langb1196682014-07-23 13:47:29 -04005574 context->recordError(gl::Error(GL_INVALID_OPERATION));
5575 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005576 }
Geoff Langbfdea662014-07-23 14:16:32 -04005577
5578 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005579 }
5580}
5581
5582void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5583{
5584 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5585 location, count, transpose, value);
5586
Geoff Langbfdea662014-07-23 14:16:32 -04005587 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005588 if (context)
5589 {
5590 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005591 {
Geoff Langbfdea662014-07-23 14:16:32 -04005592 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005593 }
Geoff Langbfdea662014-07-23 14:16:32 -04005594
5595 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5596 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005597 }
5598}
5599
5600void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5601{
5602 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5603 location, count, transpose, value);
5604
Geoff Langbfdea662014-07-23 14:16:32 -04005605 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005606 if (context)
5607 {
5608 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005609 {
Geoff Langbfdea662014-07-23 14:16:32 -04005610 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005611 }
Geoff Langbfdea662014-07-23 14:16:32 -04005612
5613 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5614 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005615 }
5616}
5617
5618void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5619{
5620 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5621 location, count, transpose, value);
5622
Geoff Langbfdea662014-07-23 14:16:32 -04005623 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005624 if (context)
5625 {
5626 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005627 {
Geoff Langbfdea662014-07-23 14:16:32 -04005628 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005629 }
Geoff Langbfdea662014-07-23 14:16:32 -04005630
5631 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5632 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005633 }
5634}
5635
5636void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5637{
5638 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5639 location, count, transpose, value);
5640
Geoff Langbfdea662014-07-23 14:16:32 -04005641 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005642 if (context)
5643 {
5644 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005645 {
Geoff Langbfdea662014-07-23 14:16:32 -04005646 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005647 }
Geoff Langbfdea662014-07-23 14:16:32 -04005648
5649 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5650 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005651 }
5652}
5653
5654void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5655{
5656 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5657 location, count, transpose, value);
5658
Geoff Langbfdea662014-07-23 14:16:32 -04005659 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005660 if (context)
5661 {
5662 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005663 {
Geoff Langbfdea662014-07-23 14:16:32 -04005664 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005665 }
Geoff Langbfdea662014-07-23 14:16:32 -04005666
5667 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5668 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005669 }
5670}
5671
5672void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5673{
5674 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5675 location, count, transpose, value);
5676
Geoff Langbfdea662014-07-23 14:16:32 -04005677 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005678 if (context)
5679 {
5680 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005681 {
Geoff Langbfdea662014-07-23 14:16:32 -04005682 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005683 }
Geoff Langbfdea662014-07-23 14:16:32 -04005684
5685 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5686 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005687 }
5688}
5689
5690void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5691{
5692 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5693 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5694 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5695
Geoff Langbfdea662014-07-23 14:16:32 -04005696 gl::Context *context = gl::getNonLostContext();
5697 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005698 {
Geoff Langbfdea662014-07-23 14:16:32 -04005699 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005700 {
Geoff Langb1196682014-07-23 13:47:29 -04005701 context->recordError(gl::Error(GL_INVALID_OPERATION));
5702 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005703 }
Geoff Langbfdea662014-07-23 14:16:32 -04005704
5705 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5706 dstX0, dstY0, dstX1, dstY1, mask, filter,
5707 false))
5708 {
5709 return;
5710 }
5711
Geoff Lang64839152014-08-26 16:23:25 -04005712 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5713 mask, filter);
5714 if (error.isError())
5715 {
5716 context->recordError(error);
5717 return;
5718 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005719 }
5720}
5721
5722void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5723{
5724 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5725 target, samples, internalformat, width, height);
5726
Geoff Langbfdea662014-07-23 14:16:32 -04005727 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005728 if (context)
5729 {
5730 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005731 {
Geoff Langb1196682014-07-23 13:47:29 -04005732 context->recordError(gl::Error(GL_INVALID_OPERATION));
5733 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005734 }
Geoff Langbfdea662014-07-23 14:16:32 -04005735
5736 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5737 width, height, false))
5738 {
5739 return;
5740 }
5741
5742 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005743 }
5744}
5745
5746void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5747{
5748 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5749 target, attachment, texture, level, layer);
5750
Geoff Langbfdea662014-07-23 14:16:32 -04005751 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005752 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005753 {
Geoff Langbfdea662014-07-23 14:16:32 -04005754 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5755 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005756 {
Geoff Langbfdea662014-07-23 14:16:32 -04005757 return;
5758 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005759
Geoff Langbfdea662014-07-23 14:16:32 -04005760 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5761 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005762
Geoff Langbfdea662014-07-23 14:16:32 -04005763 gl::Texture *textureObject = context->getTexture(texture);
5764 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005765
Geoff Langbfdea662014-07-23 14:16:32 -04005766 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5767 {
5768 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5769 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5770 }
5771 else
5772 {
5773 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005774 {
Geoff Langbfdea662014-07-23 14:16:32 -04005775 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5776 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5777 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005778 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005779 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005780 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005781}
5782
5783GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5784{
5785 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5786 target, offset, length, access);
5787
Geoff Langbfdea662014-07-23 14:16:32 -04005788 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005789 if (context)
5790 {
5791 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005792 {
Geoff Langb1196682014-07-23 13:47:29 -04005793 context->recordError(gl::Error(GL_INVALID_OPERATION));
5794 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005795 }
Geoff Langbfdea662014-07-23 14:16:32 -04005796
5797 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005798 }
5799
5800 return NULL;
5801}
5802
5803void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5804{
5805 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5806
Geoff Langbfdea662014-07-23 14:16:32 -04005807 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005808 if (context)
5809 {
5810 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005811 {
Geoff Langb1196682014-07-23 13:47:29 -04005812 context->recordError(gl::Error(GL_INVALID_OPERATION));
5813 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005814 }
Geoff Langbfdea662014-07-23 14:16:32 -04005815
5816 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005817 }
5818}
5819
5820void __stdcall glBindVertexArray(GLuint array)
5821{
5822 EVENT("(GLuint array = %u)", array);
5823
Geoff Langbfdea662014-07-23 14:16:32 -04005824 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005825 if (context)
5826 {
5827 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005828 {
Geoff Langb1196682014-07-23 13:47:29 -04005829 context->recordError(gl::Error(GL_INVALID_OPERATION));
5830 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005831 }
Geoff Langbfdea662014-07-23 14:16:32 -04005832
5833 gl::VertexArray *vao = context->getVertexArray(array);
5834
5835 if (!vao)
5836 {
5837 // The default VAO should always exist
5838 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005839 context->recordError(gl::Error(GL_INVALID_OPERATION));
5840 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005841 }
5842
5843 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005844 }
5845}
5846
5847void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5848{
5849 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5850
Geoff Langbfdea662014-07-23 14:16:32 -04005851 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005852 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005853 {
Geoff Langbfdea662014-07-23 14:16:32 -04005854 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005855 {
Geoff Langb1196682014-07-23 13:47:29 -04005856 context->recordError(gl::Error(GL_INVALID_OPERATION));
5857 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005858 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005859
Geoff Langbfdea662014-07-23 14:16:32 -04005860 if (n < 0)
5861 {
Geoff Langb1196682014-07-23 13:47:29 -04005862 context->recordError(gl::Error(GL_INVALID_VALUE));
5863 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005864 }
Jamie Madilld1028542013-07-02 11:57:04 -04005865
Geoff Langbfdea662014-07-23 14:16:32 -04005866 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5867 {
5868 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005869 {
Geoff Langbfdea662014-07-23 14:16:32 -04005870 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005871 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005872 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005873 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005874}
5875
5876void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5877{
5878 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5879
Geoff Langbfdea662014-07-23 14:16:32 -04005880 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005881 if (context)
5882 {
5883 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005884 {
Geoff Langb1196682014-07-23 13:47:29 -04005885 context->recordError(gl::Error(GL_INVALID_OPERATION));
5886 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005887 }
Geoff Langbfdea662014-07-23 14:16:32 -04005888
5889 if (n < 0)
5890 {
Geoff Langb1196682014-07-23 13:47:29 -04005891 context->recordError(gl::Error(GL_INVALID_VALUE));
5892 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005893 }
5894
5895 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5896 {
5897 arrays[arrayIndex] = context->createVertexArray();
5898 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005899 }
5900}
5901
5902GLboolean __stdcall glIsVertexArray(GLuint array)
5903{
5904 EVENT("(GLuint array = %u)", array);
5905
Geoff Langbfdea662014-07-23 14:16:32 -04005906 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005907 if (context)
5908 {
5909 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005910 {
Geoff Langb1196682014-07-23 13:47:29 -04005911 context->recordError(gl::Error(GL_INVALID_OPERATION));
5912 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005913 }
Geoff Langbfdea662014-07-23 14:16:32 -04005914
5915 if (array == 0)
5916 {
5917 return GL_FALSE;
5918 }
5919
5920 gl::VertexArray *vao = context->getVertexArray(array);
5921
5922 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005923 }
5924
5925 return GL_FALSE;
5926}
5927
5928void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5929{
5930 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5931 target, index, data);
5932
Geoff Langbfdea662014-07-23 14:16:32 -04005933 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005934 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005935 {
Geoff Langbfdea662014-07-23 14:16:32 -04005936 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005937 {
Geoff Langb1196682014-07-23 13:47:29 -04005938 context->recordError(gl::Error(GL_INVALID_OPERATION));
5939 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005940 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005941
Geoff Lang3a61c322014-07-10 13:01:54 -04005942 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005943 switch (target)
5944 {
5945 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5946 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5947 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005948 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5949 {
Geoff Langb1196682014-07-23 13:47:29 -04005950 context->recordError(gl::Error(GL_INVALID_VALUE));
5951 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005952 }
Geoff Langbfdea662014-07-23 14:16:32 -04005953 break;
Geoff Langb1196682014-07-23 13:47:29 -04005954
Geoff Langbfdea662014-07-23 14:16:32 -04005955 case GL_UNIFORM_BUFFER_START:
5956 case GL_UNIFORM_BUFFER_SIZE:
5957 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005958 if (index >= caps.maxCombinedUniformBlocks)
5959 {
Geoff Langb1196682014-07-23 13:47:29 -04005960 context->recordError(gl::Error(GL_INVALID_VALUE));
5961 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005962 }
Geoff Langbfdea662014-07-23 14:16:32 -04005963 break;
Geoff Langb1196682014-07-23 13:47:29 -04005964
Geoff Langbfdea662014-07-23 14:16:32 -04005965 default:
Geoff Langb1196682014-07-23 13:47:29 -04005966 context->recordError(gl::Error(GL_INVALID_ENUM));
5967 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005968 }
5969
5970 if (!(context->getIndexedIntegerv(target, index, data)))
5971 {
5972 GLenum nativeType;
5973 unsigned int numParams = 0;
5974 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005975 {
5976 context->recordError(gl::Error(GL_INVALID_ENUM));
5977 return;
5978 }
Shannon Woods15934d52013-08-19 14:28:49 -04005979
Geoff Langbfdea662014-07-23 14:16:32 -04005980 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005981 {
Geoff Langbfdea662014-07-23 14:16:32 -04005982 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005983 }
Geoff Langbfdea662014-07-23 14:16:32 -04005984
5985 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005986 {
Geoff Langbfdea662014-07-23 14:16:32 -04005987 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5988 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5989 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005990
Geoff Langbfdea662014-07-23 14:16:32 -04005991 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005992
Geoff Langbfdea662014-07-23 14:16:32 -04005993 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005994 {
Geoff Langbfdea662014-07-23 14:16:32 -04005995 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5996 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005997 }
Geoff Langbfdea662014-07-23 14:16:32 -04005998
5999 delete [] int64Params;
6000 }
6001 else
6002 {
6003 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04006004 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006005 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006006 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006007}
6008
6009void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
6010{
6011 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
6012
Geoff Langbfdea662014-07-23 14:16:32 -04006013 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006014 if (context)
6015 {
6016 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006017 {
Geoff Langb1196682014-07-23 13:47:29 -04006018 context->recordError(gl::Error(GL_INVALID_OPERATION));
6019 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006020 }
Geoff Langbfdea662014-07-23 14:16:32 -04006021
6022 switch (primitiveMode)
6023 {
6024 case GL_TRIANGLES:
6025 case GL_LINES:
6026 case GL_POINTS:
6027 break;
Geoff Langb1196682014-07-23 13:47:29 -04006028
Geoff Langbfdea662014-07-23 14:16:32 -04006029 default:
Geoff Langb1196682014-07-23 13:47:29 -04006030 context->recordError(gl::Error(GL_INVALID_ENUM));
6031 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006032 }
6033
6034 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6035 ASSERT(transformFeedback != NULL);
6036
6037 if (transformFeedback->isStarted())
6038 {
Geoff Langb1196682014-07-23 13:47:29 -04006039 context->recordError(gl::Error(GL_INVALID_OPERATION));
6040 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006041 }
6042
6043 if (transformFeedback->isPaused())
6044 {
6045 transformFeedback->resume();
6046 }
6047 else
6048 {
6049 transformFeedback->start(primitiveMode);
6050 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006051 }
6052}
6053
6054void __stdcall glEndTransformFeedback(void)
6055{
6056 EVENT("(void)");
6057
Geoff Langbfdea662014-07-23 14:16:32 -04006058 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006059 if (context)
6060 {
6061 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006062 {
Geoff Langb1196682014-07-23 13:47:29 -04006063 context->recordError(gl::Error(GL_INVALID_OPERATION));
6064 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006065 }
Geoff Langbfdea662014-07-23 14:16:32 -04006066
6067 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6068 ASSERT(transformFeedback != NULL);
6069
6070 if (!transformFeedback->isStarted())
6071 {
Geoff Langb1196682014-07-23 13:47:29 -04006072 context->recordError(gl::Error(GL_INVALID_OPERATION));
6073 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006074 }
6075
6076 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006077 }
6078}
6079
6080void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
6081{
6082 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
6083 target, index, buffer, offset, size);
6084
Geoff Langbfdea662014-07-23 14:16:32 -04006085 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006086 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006087 {
Geoff Langbfdea662014-07-23 14:16:32 -04006088 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006089 {
Geoff Langb1196682014-07-23 13:47:29 -04006090 context->recordError(gl::Error(GL_INVALID_OPERATION));
6091 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006092 }
6093
Geoff Lang3a61c322014-07-10 13:01:54 -04006094 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006095 switch (target)
6096 {
6097 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006098 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006099 {
Geoff Langb1196682014-07-23 13:47:29 -04006100 context->recordError(gl::Error(GL_INVALID_VALUE));
6101 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006102 }
Geoff Langbfdea662014-07-23 14:16:32 -04006103 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006104
Geoff Langbfdea662014-07-23 14:16:32 -04006105 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006106 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006107 {
Geoff Langb1196682014-07-23 13:47:29 -04006108 context->recordError(gl::Error(GL_INVALID_VALUE));
6109 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006110 }
Geoff Langbfdea662014-07-23 14:16:32 -04006111 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006112
Geoff Langbfdea662014-07-23 14:16:32 -04006113 default:
Geoff Langb1196682014-07-23 13:47:29 -04006114 context->recordError(gl::Error(GL_INVALID_ENUM));
6115 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006116 }
6117
6118 if (buffer != 0 && size <= 0)
6119 {
Geoff Langb1196682014-07-23 13:47:29 -04006120 context->recordError(gl::Error(GL_INVALID_VALUE));
6121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006122 }
6123
6124 switch (target)
6125 {
6126 case GL_TRANSFORM_FEEDBACK_BUFFER:
6127
6128 // size and offset must be a multiple of 4
6129 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006130 {
Geoff Langb1196682014-07-23 13:47:29 -04006131 context->recordError(gl::Error(GL_INVALID_VALUE));
6132 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006133 }
6134
Geoff Langbfdea662014-07-23 14:16:32 -04006135 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
6136 context->bindGenericTransformFeedbackBuffer(buffer);
6137 break;
6138
6139 case GL_UNIFORM_BUFFER:
6140
6141 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006142 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006143 {
Geoff Langb1196682014-07-23 13:47:29 -04006144 context->recordError(gl::Error(GL_INVALID_VALUE));
6145 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006146 }
Geoff Langbfdea662014-07-23 14:16:32 -04006147
6148 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6149 context->bindGenericUniformBuffer(buffer);
6150 break;
6151
6152 default:
6153 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006154 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006155 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006156}
6157
6158void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
6159{
6160 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6161 target, index, buffer);
6162
Geoff Langbfdea662014-07-23 14:16:32 -04006163 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006164 if (context)
6165 {
6166 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006167 {
Geoff Langb1196682014-07-23 13:47:29 -04006168 context->recordError(gl::Error(GL_INVALID_OPERATION));
6169 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006170 }
Geoff Langbfdea662014-07-23 14:16:32 -04006171
Geoff Lang3a61c322014-07-10 13:01:54 -04006172 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006173 switch (target)
6174 {
6175 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006176 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006177 {
Geoff Langb1196682014-07-23 13:47:29 -04006178 context->recordError(gl::Error(GL_INVALID_VALUE));
6179 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006180 }
6181 break;
6182
6183 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006184 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006185 {
Geoff Langb1196682014-07-23 13:47:29 -04006186 context->recordError(gl::Error(GL_INVALID_VALUE));
6187 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006188 }
6189 break;
6190
6191 default:
Geoff Langb1196682014-07-23 13:47:29 -04006192 context->recordError(gl::Error(GL_INVALID_ENUM));
6193 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006194 }
6195
6196 switch (target)
6197 {
6198 case GL_TRANSFORM_FEEDBACK_BUFFER:
6199 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6200 context->bindGenericTransformFeedbackBuffer(buffer);
6201 break;
6202
6203 case GL_UNIFORM_BUFFER:
6204 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6205 context->bindGenericUniformBuffer(buffer);
6206 break;
6207
6208 default:
6209 UNREACHABLE();
6210 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006211 }
6212}
6213
6214void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6215{
6216 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6217 program, count, varyings, bufferMode);
6218
Geoff Langbfdea662014-07-23 14:16:32 -04006219 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006220 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006221 {
Geoff Langbfdea662014-07-23 14:16:32 -04006222 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006223 {
Geoff Langb1196682014-07-23 13:47:29 -04006224 context->recordError(gl::Error(GL_INVALID_OPERATION));
6225 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006226 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006227
Geoff Langbfdea662014-07-23 14:16:32 -04006228 if (count < 0)
6229 {
Geoff Langb1196682014-07-23 13:47:29 -04006230 context->recordError(gl::Error(GL_INVALID_VALUE));
6231 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006232 }
6233
Geoff Lang05881a02014-07-10 14:05:30 -04006234 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006235 switch (bufferMode)
6236 {
6237 case GL_INTERLEAVED_ATTRIBS:
6238 break;
6239 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006240 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006241 {
Geoff Langb1196682014-07-23 13:47:29 -04006242 context->recordError(gl::Error(GL_INVALID_VALUE));
6243 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006244 }
Geoff Langbfdea662014-07-23 14:16:32 -04006245 break;
6246 default:
Geoff Langb1196682014-07-23 13:47:29 -04006247 context->recordError(gl::Error(GL_INVALID_ENUM));
6248 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006249 }
Geoff Langbfdea662014-07-23 14:16:32 -04006250
6251 if (!gl::ValidProgram(context, program))
6252 {
6253 return;
6254 }
6255
6256 gl::Program *programObject = context->getProgram(program);
6257 ASSERT(programObject);
6258
6259 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006260 }
6261}
6262
6263void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6264{
6265 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6266 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6267 program, index, bufSize, length, size, type, name);
6268
Geoff Langbfdea662014-07-23 14:16:32 -04006269 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006270 if (context)
6271 {
6272 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006273 {
Geoff Langb1196682014-07-23 13:47:29 -04006274 context->recordError(gl::Error(GL_INVALID_OPERATION));
6275 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006276 }
Geoff Langbfdea662014-07-23 14:16:32 -04006277
6278 if (bufSize < 0)
6279 {
Geoff Langb1196682014-07-23 13:47:29 -04006280 context->recordError(gl::Error(GL_INVALID_VALUE));
6281 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006282 }
6283
6284 if (!gl::ValidProgram(context, program))
6285 {
6286 return;
6287 }
6288
6289 gl::Program *programObject = context->getProgram(program);
6290 ASSERT(programObject);
6291
6292 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6293 {
Geoff Langb1196682014-07-23 13:47:29 -04006294 context->recordError(gl::Error(GL_INVALID_VALUE));
6295 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006296 }
6297
6298 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006299 }
6300}
6301
6302void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6303{
6304 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6305 index, size, type, stride, pointer);
6306
Geoff Langbfdea662014-07-23 14:16:32 -04006307 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006308 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006309 {
Geoff Langbfdea662014-07-23 14:16:32 -04006310 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006311 {
Geoff Langb1196682014-07-23 13:47:29 -04006312 context->recordError(gl::Error(GL_INVALID_OPERATION));
6313 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006314 }
6315
Geoff Langb1196682014-07-23 13:47:29 -04006316 if (index >= gl::MAX_VERTEX_ATTRIBS)
6317 {
6318 context->recordError(gl::Error(GL_INVALID_VALUE));
6319 return;
6320 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006321
Geoff Langb1196682014-07-23 13:47:29 -04006322 if (size < 1 || size > 4)
6323 {
6324 context->recordError(gl::Error(GL_INVALID_VALUE));
6325 return;
6326 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006327
Geoff Langb1196682014-07-23 13:47:29 -04006328 switch (type)
6329 {
6330 case GL_BYTE:
6331 case GL_UNSIGNED_BYTE:
6332 case GL_SHORT:
6333 case GL_UNSIGNED_SHORT:
6334 case GL_INT:
6335 case GL_UNSIGNED_INT:
6336 case GL_INT_2_10_10_10_REV:
6337 case GL_UNSIGNED_INT_2_10_10_10_REV:
6338 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006339
Geoff Langb1196682014-07-23 13:47:29 -04006340 default:
6341 context->recordError(gl::Error(GL_INVALID_ENUM));
6342 return;
6343 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006344
Geoff Langb1196682014-07-23 13:47:29 -04006345 if (stride < 0)
6346 {
6347 context->recordError(gl::Error(GL_INVALID_VALUE));
6348 return;
6349 }
Geoff Langbfdea662014-07-23 14:16:32 -04006350
Geoff Langb1196682014-07-23 13:47:29 -04006351 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6352 {
6353 context->recordError(gl::Error(GL_INVALID_OPERATION));
6354 return;
6355 }
6356
Geoff Langbfdea662014-07-23 14:16:32 -04006357 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6358 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6359 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6360 // and the pointer argument is not NULL.
6361 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006362 {
Geoff Langb1196682014-07-23 13:47:29 -04006363 context->recordError(gl::Error(GL_INVALID_OPERATION));
6364 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006365 }
6366
Geoff Langbfdea662014-07-23 14:16:32 -04006367 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6368 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006369 }
6370}
6371
6372void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6373{
6374 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6375 index, pname, params);
6376
Geoff Langbfdea662014-07-23 14:16:32 -04006377 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006378 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006379 {
Geoff Langbfdea662014-07-23 14:16:32 -04006380 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006381 {
Geoff Langb1196682014-07-23 13:47:29 -04006382 context->recordError(gl::Error(GL_INVALID_OPERATION));
6383 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006384 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006385
Geoff Langbfdea662014-07-23 14:16:32 -04006386 if (index >= gl::MAX_VERTEX_ATTRIBS)
6387 {
Geoff Langb1196682014-07-23 13:47:29 -04006388 context->recordError(gl::Error(GL_INVALID_VALUE));
6389 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006390 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006391
Geoff Langbfdea662014-07-23 14:16:32 -04006392 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006393
Geoff Langb1196682014-07-23 13:47:29 -04006394 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006395 {
6396 return;
6397 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006398
Geoff Langbfdea662014-07-23 14:16:32 -04006399 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6400 {
6401 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6402 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006403 {
Geoff Langbfdea662014-07-23 14:16:32 -04006404 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006405 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006406 }
Geoff Langbfdea662014-07-23 14:16:32 -04006407 else
6408 {
6409 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6410 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006411 }
6412}
6413
6414void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6415{
6416 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6417 index, pname, params);
6418
Geoff Langbfdea662014-07-23 14:16:32 -04006419 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006420 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006421 {
Geoff Langbfdea662014-07-23 14:16:32 -04006422 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006423 {
Geoff Langb1196682014-07-23 13:47:29 -04006424 context->recordError(gl::Error(GL_INVALID_OPERATION));
6425 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006426 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006427
Geoff Langbfdea662014-07-23 14:16:32 -04006428 if (index >= gl::MAX_VERTEX_ATTRIBS)
6429 {
Geoff Langb1196682014-07-23 13:47:29 -04006430 context->recordError(gl::Error(GL_INVALID_VALUE));
6431 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006432 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006433
Geoff Langbfdea662014-07-23 14:16:32 -04006434 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006435
Geoff Langb1196682014-07-23 13:47:29 -04006436 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006437 {
6438 return;
6439 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006440
Geoff Langbfdea662014-07-23 14:16:32 -04006441 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6442 {
6443 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6444 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006445 {
Geoff Langbfdea662014-07-23 14:16:32 -04006446 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006447 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006448 }
Geoff Langbfdea662014-07-23 14:16:32 -04006449 else
6450 {
6451 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6452 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006453 }
6454}
6455
6456void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6457{
6458 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6459 index, x, y, z, w);
6460
Geoff Langbfdea662014-07-23 14:16:32 -04006461 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006462 if (context)
6463 {
6464 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006465 {
Geoff Langb1196682014-07-23 13:47:29 -04006466 context->recordError(gl::Error(GL_INVALID_OPERATION));
6467 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006468 }
Geoff Langbfdea662014-07-23 14:16:32 -04006469
6470 if (index >= gl::MAX_VERTEX_ATTRIBS)
6471 {
Geoff Langb1196682014-07-23 13:47:29 -04006472 context->recordError(gl::Error(GL_INVALID_VALUE));
6473 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006474 }
6475
6476 GLint vals[4] = { x, y, z, w };
6477 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006478 }
6479}
6480
6481void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6482{
6483 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6484 index, x, y, z, w);
6485
Geoff Langbfdea662014-07-23 14:16:32 -04006486 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006487 if (context)
6488 {
6489 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006490 {
Geoff Langb1196682014-07-23 13:47:29 -04006491 context->recordError(gl::Error(GL_INVALID_OPERATION));
6492 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006493 }
Geoff Langbfdea662014-07-23 14:16:32 -04006494
6495 if (index >= gl::MAX_VERTEX_ATTRIBS)
6496 {
Geoff Langb1196682014-07-23 13:47:29 -04006497 context->recordError(gl::Error(GL_INVALID_VALUE));
6498 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006499 }
6500
6501 GLuint vals[4] = { x, y, z, w };
6502 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006503 }
6504}
6505
6506void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6507{
6508 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6509
Geoff Langbfdea662014-07-23 14:16:32 -04006510 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006511 if (context)
6512 {
6513 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006514 {
Geoff Langb1196682014-07-23 13:47:29 -04006515 context->recordError(gl::Error(GL_INVALID_OPERATION));
6516 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006517 }
Geoff Langbfdea662014-07-23 14:16:32 -04006518
6519 if (index >= gl::MAX_VERTEX_ATTRIBS)
6520 {
Geoff Langb1196682014-07-23 13:47:29 -04006521 context->recordError(gl::Error(GL_INVALID_VALUE));
6522 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006523 }
6524
6525 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006526 }
6527}
6528
6529void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6530{
6531 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6532
Geoff Langbfdea662014-07-23 14:16:32 -04006533 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006534 if (context)
6535 {
6536 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006537 {
Geoff Langb1196682014-07-23 13:47:29 -04006538 context->recordError(gl::Error(GL_INVALID_OPERATION));
6539 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006540 }
Geoff Langbfdea662014-07-23 14:16:32 -04006541
6542 if (index >= gl::MAX_VERTEX_ATTRIBS)
6543 {
Geoff Langb1196682014-07-23 13:47:29 -04006544 context->recordError(gl::Error(GL_INVALID_VALUE));
6545 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006546 }
6547
6548 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006549 }
6550}
6551
6552void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6553{
6554 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6555 program, location, params);
6556
Geoff Langbfdea662014-07-23 14:16:32 -04006557 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006558 if (context)
6559 {
Jamie Madill0063c512014-08-25 15:47:53 -04006560 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006561 {
Jamie Madill0063c512014-08-25 15:47:53 -04006562 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006563 }
Geoff Langbfdea662014-07-23 14:16:32 -04006564
Jamie Madilla502c742014-08-28 17:19:13 -04006565 gl::Program *programObject = context->getProgram(program);
6566 ASSERT(programObject);
6567 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006568 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006569
Jamie Madill99a1e982014-08-25 15:47:54 -04006570 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006571 }
6572}
6573
6574GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6575{
6576 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6577 program, name);
6578
Geoff Langbfdea662014-07-23 14:16:32 -04006579 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006580 if (context)
6581 {
6582 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006583 {
Geoff Langb1196682014-07-23 13:47:29 -04006584 context->recordError(gl::Error(GL_INVALID_OPERATION));
6585 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006586 }
Geoff Langbfdea662014-07-23 14:16:32 -04006587
6588 if (program == 0)
6589 {
Geoff Langb1196682014-07-23 13:47:29 -04006590 context->recordError(gl::Error(GL_INVALID_VALUE));
6591 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006592 }
6593
6594 gl::Program *programObject = context->getProgram(program);
6595
6596 if (!programObject || !programObject->isLinked())
6597 {
Geoff Langb1196682014-07-23 13:47:29 -04006598 context->recordError(gl::Error(GL_INVALID_OPERATION));
6599 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006600 }
6601
6602 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6603 if (!programBinary)
6604 {
Geoff Langb1196682014-07-23 13:47:29 -04006605 context->recordError(gl::Error(GL_INVALID_OPERATION));
6606 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006607 }
6608
6609 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006610 }
6611
6612 return 0;
6613}
6614
6615void __stdcall glUniform1ui(GLint location, GLuint v0)
6616{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006617 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006618}
6619
6620void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6621{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006622 const GLuint xy[] = { v0, v1 };
6623 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006624}
6625
6626void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6627{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006628 const GLuint xyz[] = { v0, v1, v2 };
6629 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006630}
6631
6632void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6633{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006634 const GLuint xyzw[] = { v0, v1, v2, v3 };
6635 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006636}
6637
6638void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6639{
6640 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6641 location, count, value);
6642
Geoff Langbfdea662014-07-23 14:16:32 -04006643 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006644 if (context)
6645 {
6646 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006647 {
Geoff Langbfdea662014-07-23 14:16:32 -04006648 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006649 }
Geoff Langbfdea662014-07-23 14:16:32 -04006650
6651 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6652 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006653 }
6654}
6655
6656void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6657{
6658 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6659 location, count, value);
6660
Geoff Langbfdea662014-07-23 14:16:32 -04006661 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006662 if (context)
6663 {
6664 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006665 {
Geoff Langbfdea662014-07-23 14:16:32 -04006666 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006667 }
Geoff Langbfdea662014-07-23 14:16:32 -04006668
6669 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6670 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006671 }
6672}
6673
6674void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6675{
6676 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6677 location, count, value);
6678
Geoff Langbfdea662014-07-23 14:16:32 -04006679 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006680 if (context)
6681 {
6682 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006683 {
Geoff Langbfdea662014-07-23 14:16:32 -04006684 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006685 }
Geoff Langbfdea662014-07-23 14:16:32 -04006686
6687 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6688 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006689 }
6690}
6691
6692void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6693{
6694 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6695 location, count, value);
6696
Geoff Langbfdea662014-07-23 14:16:32 -04006697 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006698 if (context)
6699 {
6700 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006701 {
Geoff Langbfdea662014-07-23 14:16:32 -04006702 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006703 }
Geoff Langbfdea662014-07-23 14:16:32 -04006704
6705 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6706 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006707 }
6708}
6709
6710void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6711{
6712 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6713 buffer, drawbuffer, value);
6714
Geoff Langbfdea662014-07-23 14:16:32 -04006715 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006716 if (context)
6717 {
6718 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006719 {
Geoff Langbfdea662014-07-23 14:16:32 -04006720 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006721 }
Geoff Langbfdea662014-07-23 14:16:32 -04006722
6723 switch (buffer)
6724 {
6725 case GL_COLOR:
6726 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6727 {
Geoff Langb1196682014-07-23 13:47:29 -04006728 context->recordError(gl::Error(GL_INVALID_VALUE));
6729 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006730 }
6731 break;
Geoff Langb1196682014-07-23 13:47:29 -04006732
Geoff Langbfdea662014-07-23 14:16:32 -04006733 case GL_STENCIL:
6734 if (drawbuffer != 0)
6735 {
Geoff Langb1196682014-07-23 13:47:29 -04006736 context->recordError(gl::Error(GL_INVALID_VALUE));
6737 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006738 }
6739 break;
Geoff Langb1196682014-07-23 13:47:29 -04006740
Geoff Langbfdea662014-07-23 14:16:32 -04006741 default:
Geoff Langb1196682014-07-23 13:47:29 -04006742 context->recordError(gl::Error(GL_INVALID_ENUM));
6743 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006744 }
6745
Geoff Langcc79b8c2014-07-25 13:48:02 -04006746 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6747 if (error.isError())
6748 {
6749 context->recordError(error);
6750 return;
6751 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006752 }
6753}
6754
6755void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6756{
6757 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6758 buffer, drawbuffer, value);
6759
Geoff Langbfdea662014-07-23 14:16:32 -04006760 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006761 if (context)
6762 {
6763 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006764 {
Geoff Langbfdea662014-07-23 14:16:32 -04006765 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006766 }
Geoff Langbfdea662014-07-23 14:16:32 -04006767
6768 switch (buffer)
6769 {
6770 case GL_COLOR:
6771 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6772 {
Geoff Langb1196682014-07-23 13:47:29 -04006773 context->recordError(gl::Error(GL_INVALID_VALUE));
6774 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006775 }
6776 break;
Geoff Langb1196682014-07-23 13:47:29 -04006777
Geoff Langbfdea662014-07-23 14:16:32 -04006778 default:
Geoff Langb1196682014-07-23 13:47:29 -04006779 context->recordError(gl::Error(GL_INVALID_ENUM));
6780 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006781 }
6782
Geoff Langcc79b8c2014-07-25 13:48:02 -04006783 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6784 if (error.isError())
6785 {
6786 context->recordError(error);
6787 return;
6788 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006789 }
6790}
6791
6792void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6793{
6794 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6795 buffer, drawbuffer, value);
6796
Geoff Langbfdea662014-07-23 14:16:32 -04006797 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006798 if (context)
6799 {
6800 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006801 {
Geoff Langbfdea662014-07-23 14:16:32 -04006802 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006803 }
Geoff Langbfdea662014-07-23 14:16:32 -04006804
6805 switch (buffer)
6806 {
6807 case GL_COLOR:
6808 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6809 {
Geoff Langb1196682014-07-23 13:47:29 -04006810 context->recordError(gl::Error(GL_INVALID_VALUE));
6811 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006812 }
6813 break;
Geoff Langb1196682014-07-23 13:47:29 -04006814
Geoff Langbfdea662014-07-23 14:16:32 -04006815 case GL_DEPTH:
6816 if (drawbuffer != 0)
6817 {
Geoff Langb1196682014-07-23 13:47:29 -04006818 context->recordError(gl::Error(GL_INVALID_VALUE));
6819 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006820 }
6821 break;
Geoff Langb1196682014-07-23 13:47:29 -04006822
Geoff Langbfdea662014-07-23 14:16:32 -04006823 default:
Geoff Langb1196682014-07-23 13:47:29 -04006824 context->recordError(gl::Error(GL_INVALID_ENUM));
6825 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006826 }
6827
Geoff Langcc79b8c2014-07-25 13:48:02 -04006828 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6829 if (error.isError())
6830 {
6831 context->recordError(error);
6832 return;
6833 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006834 }
6835}
6836
6837void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6838{
6839 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6840 buffer, drawbuffer, depth, stencil);
6841
Geoff Langbfdea662014-07-23 14:16:32 -04006842 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006843 if (context)
6844 {
6845 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006846 {
Geoff Langbfdea662014-07-23 14:16:32 -04006847 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006848 }
Geoff Langbfdea662014-07-23 14:16:32 -04006849
6850 switch (buffer)
6851 {
6852 case GL_DEPTH_STENCIL:
6853 if (drawbuffer != 0)
6854 {
Geoff Langb1196682014-07-23 13:47:29 -04006855 context->recordError(gl::Error(GL_INVALID_VALUE));
6856 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006857 }
6858 break;
Geoff Langb1196682014-07-23 13:47:29 -04006859
Geoff Langbfdea662014-07-23 14:16:32 -04006860 default:
Geoff Langb1196682014-07-23 13:47:29 -04006861 context->recordError(gl::Error(GL_INVALID_ENUM));
6862 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006863 }
6864
Geoff Langcc79b8c2014-07-25 13:48:02 -04006865 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6866 if (error.isError())
6867 {
6868 context->recordError(error);
6869 return;
6870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006871 }
6872}
6873
6874const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6875{
6876 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6877
Geoff Langbfdea662014-07-23 14:16:32 -04006878 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006879 if (context)
6880 {
6881 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006882 {
Geoff Langb1196682014-07-23 13:47:29 -04006883 context->recordError(gl::Error(GL_INVALID_OPERATION));
6884 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006885 }
Geoff Langbfdea662014-07-23 14:16:32 -04006886
6887 if (name != GL_EXTENSIONS)
6888 {
Geoff Langb1196682014-07-23 13:47:29 -04006889 context->recordError(gl::Error(GL_INVALID_ENUM));
6890 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006891 }
6892
6893 if (index >= context->getExtensionStringCount())
6894 {
Geoff Langb1196682014-07-23 13:47:29 -04006895 context->recordError(gl::Error(GL_INVALID_VALUE));
6896 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006897 }
6898
6899 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006900 }
6901
6902 return NULL;
6903}
6904
6905void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6906{
6907 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6908 readTarget, writeTarget, readOffset, writeOffset, size);
6909
Geoff Langbfdea662014-07-23 14:16:32 -04006910 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006911 if (context)
6912 {
6913 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006914 {
Geoff Langb1196682014-07-23 13:47:29 -04006915 context->recordError(gl::Error(GL_INVALID_OPERATION));
6916 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006917 }
Geoff Langbfdea662014-07-23 14:16:32 -04006918
6919 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6920 {
Geoff Langb1196682014-07-23 13:47:29 -04006921 context->recordError(gl::Error(GL_INVALID_ENUM));
6922 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006923 }
6924
6925 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6926 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6927
6928 if (!readBuffer || !writeBuffer)
6929 {
Geoff Langb1196682014-07-23 13:47:29 -04006930 context->recordError(gl::Error(GL_INVALID_OPERATION));
6931 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006932 }
6933
Jamie Madillcfaaf722014-07-31 10:47:54 -04006934 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006935 if (readBuffer->isMapped() || writeBuffer->isMapped())
6936 {
Geoff Langb1196682014-07-23 13:47:29 -04006937 context->recordError(gl::Error(GL_INVALID_OPERATION));
6938 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006939 }
6940
6941 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6942 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6943 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6944 {
Geoff Langb1196682014-07-23 13:47:29 -04006945 context->recordError(gl::Error(GL_INVALID_VALUE));
6946 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006947 }
6948
6949 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6950 {
Geoff Langb1196682014-07-23 13:47:29 -04006951 context->recordError(gl::Error(GL_INVALID_VALUE));
6952 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006953 }
6954
Geoff Langbfdea662014-07-23 14:16:32 -04006955 // if size is zero, the copy is a successful no-op
6956 if (size > 0)
6957 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006958 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6959 if (error.isError())
6960 {
6961 context->recordError(error);
6962 return;
6963 }
Geoff Langbfdea662014-07-23 14:16:32 -04006964 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006965 }
6966}
6967
6968void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6969{
6970 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6971 program, uniformCount, uniformNames, uniformIndices);
6972
Geoff Langbfdea662014-07-23 14:16:32 -04006973 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006974 if (context)
6975 {
6976 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006977 {
Geoff Langb1196682014-07-23 13:47:29 -04006978 context->recordError(gl::Error(GL_INVALID_OPERATION));
6979 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006980 }
6981
6982 if (uniformCount < 0)
6983 {
Geoff Langb1196682014-07-23 13:47:29 -04006984 context->recordError(gl::Error(GL_INVALID_VALUE));
6985 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006986 }
6987
6988 gl::Program *programObject = context->getProgram(program);
6989
6990 if (!programObject)
6991 {
6992 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006993 {
Geoff Langb1196682014-07-23 13:47:29 -04006994 context->recordError(gl::Error(GL_INVALID_OPERATION));
6995 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006996 }
Geoff Langbfdea662014-07-23 14:16:32 -04006997 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006998 {
Geoff Langb1196682014-07-23 13:47:29 -04006999 context->recordError(gl::Error(GL_INVALID_VALUE));
7000 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007001 }
Geoff Langbfdea662014-07-23 14:16:32 -04007002 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007003
Geoff Langbfdea662014-07-23 14:16:32 -04007004 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7005 if (!programObject->isLinked() || !programBinary)
7006 {
7007 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007008 {
Geoff Langbfdea662014-07-23 14:16:32 -04007009 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007010 }
7011 }
Geoff Langbfdea662014-07-23 14:16:32 -04007012 else
7013 {
7014 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7015 {
7016 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
7017 }
7018 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007019 }
7020}
7021
7022void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
7023{
7024 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7025 program, uniformCount, uniformIndices, pname, params);
7026
Geoff Langbfdea662014-07-23 14:16:32 -04007027 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007028 if (context)
7029 {
7030 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007031 {
Geoff Langb1196682014-07-23 13:47:29 -04007032 context->recordError(gl::Error(GL_INVALID_OPERATION));
7033 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007034 }
7035
7036 if (uniformCount < 0)
7037 {
Geoff Langb1196682014-07-23 13:47:29 -04007038 context->recordError(gl::Error(GL_INVALID_VALUE));
7039 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007040 }
7041
7042 gl::Program *programObject = context->getProgram(program);
7043
7044 if (!programObject)
7045 {
7046 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007047 {
Geoff Langb1196682014-07-23 13:47:29 -04007048 context->recordError(gl::Error(GL_INVALID_OPERATION));
7049 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007050 }
Geoff Langbfdea662014-07-23 14:16:32 -04007051 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007052 {
Geoff Langb1196682014-07-23 13:47:29 -04007053 context->recordError(gl::Error(GL_INVALID_VALUE));
7054 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007055 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007056 }
Geoff Langbfdea662014-07-23 14:16:32 -04007057
7058 switch (pname)
7059 {
7060 case GL_UNIFORM_TYPE:
7061 case GL_UNIFORM_SIZE:
7062 case GL_UNIFORM_NAME_LENGTH:
7063 case GL_UNIFORM_BLOCK_INDEX:
7064 case GL_UNIFORM_OFFSET:
7065 case GL_UNIFORM_ARRAY_STRIDE:
7066 case GL_UNIFORM_MATRIX_STRIDE:
7067 case GL_UNIFORM_IS_ROW_MAJOR:
7068 break;
Geoff Langb1196682014-07-23 13:47:29 -04007069
Geoff Langbfdea662014-07-23 14:16:32 -04007070 default:
Geoff Langb1196682014-07-23 13:47:29 -04007071 context->recordError(gl::Error(GL_INVALID_ENUM));
7072 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007073 }
7074
7075 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7076
7077 if (!programBinary && uniformCount > 0)
7078 {
Geoff Langb1196682014-07-23 13:47:29 -04007079 context->recordError(gl::Error(GL_INVALID_VALUE));
7080 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007081 }
7082
7083 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7084 {
7085 const GLuint index = uniformIndices[uniformId];
7086
7087 if (index >= (GLuint)programBinary->getActiveUniformCount())
7088 {
Geoff Langb1196682014-07-23 13:47:29 -04007089 context->recordError(gl::Error(GL_INVALID_VALUE));
7090 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007091 }
7092 }
7093
7094 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7095 {
7096 const GLuint index = uniformIndices[uniformId];
7097 params[uniformId] = programBinary->getActiveUniformi(index, pname);
7098 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007099 }
7100}
7101
7102GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
7103{
7104 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
7105
Geoff Langbfdea662014-07-23 14:16:32 -04007106 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007107 if (context)
7108 {
7109 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007110 {
Geoff Langb1196682014-07-23 13:47:29 -04007111 context->recordError(gl::Error(GL_INVALID_OPERATION));
7112 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04007113 }
7114
7115 gl::Program *programObject = context->getProgram(program);
7116
7117 if (!programObject)
7118 {
7119 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007120 {
Geoff Langb1196682014-07-23 13:47:29 -04007121 context->recordError(gl::Error(GL_INVALID_OPERATION));
7122 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007123 }
Geoff Langbfdea662014-07-23 14:16:32 -04007124 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007125 {
Geoff Langb1196682014-07-23 13:47:29 -04007126 context->recordError(gl::Error(GL_INVALID_VALUE));
7127 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007128 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007129 }
Geoff Langbfdea662014-07-23 14:16:32 -04007130
7131 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7132 if (!programBinary)
7133 {
7134 return GL_INVALID_INDEX;
7135 }
7136
7137 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007138 }
7139
7140 return 0;
7141}
7142
7143void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
7144{
7145 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7146 program, uniformBlockIndex, pname, params);
7147
Geoff Langbfdea662014-07-23 14:16:32 -04007148 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007149 if (context)
7150 {
7151 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007152 {
Geoff Langb1196682014-07-23 13:47:29 -04007153 context->recordError(gl::Error(GL_INVALID_OPERATION));
7154 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007155 }
7156 gl::Program *programObject = context->getProgram(program);
7157
7158 if (!programObject)
7159 {
7160 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007161 {
Geoff Langb1196682014-07-23 13:47:29 -04007162 context->recordError(gl::Error(GL_INVALID_OPERATION));
7163 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007164 }
Geoff Langbfdea662014-07-23 14:16:32 -04007165 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007166 {
Geoff Langb1196682014-07-23 13:47:29 -04007167 context->recordError(gl::Error(GL_INVALID_VALUE));
7168 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007169 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007170 }
Geoff Langbfdea662014-07-23 14:16:32 -04007171
7172 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7173
7174 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7175 {
Geoff Langb1196682014-07-23 13:47:29 -04007176 context->recordError(gl::Error(GL_INVALID_VALUE));
7177 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007178 }
7179
7180 switch (pname)
7181 {
7182 case GL_UNIFORM_BLOCK_BINDING:
7183 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7184 break;
7185
7186 case GL_UNIFORM_BLOCK_DATA_SIZE:
7187 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7188 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7189 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7190 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7191 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7192 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7193 break;
7194
7195 default:
Geoff Langb1196682014-07-23 13:47:29 -04007196 context->recordError(gl::Error(GL_INVALID_ENUM));
7197 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007198 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007199 }
7200}
7201
7202void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7203{
7204 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7205 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7206
Geoff Langbfdea662014-07-23 14:16:32 -04007207 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007208 if (context)
7209 {
7210 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007211 {
Geoff Langb1196682014-07-23 13:47:29 -04007212 context->recordError(gl::Error(GL_INVALID_OPERATION));
7213 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007214 }
7215
7216 gl::Program *programObject = context->getProgram(program);
7217
7218 if (!programObject)
7219 {
7220 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007221 {
Geoff Langb1196682014-07-23 13:47:29 -04007222 context->recordError(gl::Error(GL_INVALID_OPERATION));
7223 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007224 }
Geoff Langbfdea662014-07-23 14:16:32 -04007225 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007226 {
Geoff Langb1196682014-07-23 13:47:29 -04007227 context->recordError(gl::Error(GL_INVALID_VALUE));
7228 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007229 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007230 }
Geoff Langbfdea662014-07-23 14:16:32 -04007231
7232 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7233
7234 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7235 {
Geoff Langb1196682014-07-23 13:47:29 -04007236 context->recordError(gl::Error(GL_INVALID_VALUE));
7237 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007238 }
7239
7240 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007241 }
7242}
7243
7244void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7245{
7246 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7247 program, uniformBlockIndex, uniformBlockBinding);
7248
Geoff Langbfdea662014-07-23 14:16:32 -04007249 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007250 if (context)
7251 {
7252 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007253 {
Geoff Langb1196682014-07-23 13:47:29 -04007254 context->recordError(gl::Error(GL_INVALID_OPERATION));
7255 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007256 }
7257
Geoff Lang3a61c322014-07-10 13:01:54 -04007258 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007259 {
Geoff Langb1196682014-07-23 13:47:29 -04007260 context->recordError(gl::Error(GL_INVALID_VALUE));
7261 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007262 }
7263
7264 gl::Program *programObject = context->getProgram(program);
7265
7266 if (!programObject)
7267 {
7268 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007269 {
Geoff Langb1196682014-07-23 13:47:29 -04007270 context->recordError(gl::Error(GL_INVALID_OPERATION));
7271 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007272 }
Geoff Langbfdea662014-07-23 14:16:32 -04007273 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007274 {
Geoff Langb1196682014-07-23 13:47:29 -04007275 context->recordError(gl::Error(GL_INVALID_VALUE));
7276 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007277 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007278 }
Geoff Langbfdea662014-07-23 14:16:32 -04007279
7280 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7281
7282 // if never linked, there won't be any uniform blocks
7283 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7284 {
Geoff Langb1196682014-07-23 13:47:29 -04007285 context->recordError(gl::Error(GL_INVALID_VALUE));
7286 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007287 }
7288
7289 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007290 }
7291}
7292
7293void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7294{
7295 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7296 mode, first, count, instanceCount);
7297
Geoff Langbfdea662014-07-23 14:16:32 -04007298 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007299 if (context)
7300 {
7301 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007302 {
Geoff Langb1196682014-07-23 13:47:29 -04007303 context->recordError(gl::Error(GL_INVALID_OPERATION));
7304 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007305 }
Geoff Langbfdea662014-07-23 14:16:32 -04007306
7307 // glDrawArraysInstanced
7308 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007309 }
7310}
7311
7312void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7313{
7314 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7315 mode, count, type, indices, instanceCount);
7316
Geoff Langbfdea662014-07-23 14:16:32 -04007317 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007318 if (context)
7319 {
7320 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007321 {
Geoff Langb1196682014-07-23 13:47:29 -04007322 context->recordError(gl::Error(GL_INVALID_OPERATION));
7323 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007324 }
Geoff Langbfdea662014-07-23 14:16:32 -04007325
7326 // glDrawElementsInstanced
7327 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007328 }
7329}
7330
7331GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7332{
7333 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7334
Geoff Langbfdea662014-07-23 14:16:32 -04007335 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007336 if (context)
7337 {
7338 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007339 {
Geoff Langb1196682014-07-23 13:47:29 -04007340 context->recordError(gl::Error(GL_INVALID_OPERATION));
7341 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007342 }
Geoff Langbfdea662014-07-23 14:16:32 -04007343
7344 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7345 {
Geoff Langb1196682014-07-23 13:47:29 -04007346 context->recordError(gl::Error(GL_INVALID_ENUM));
7347 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007348 }
7349
7350 if (flags != 0)
7351 {
Geoff Langb1196682014-07-23 13:47:29 -04007352 context->recordError(gl::Error(GL_INVALID_VALUE));
7353 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007354 }
7355
7356 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007357 }
7358
7359 return NULL;
7360}
7361
7362GLboolean __stdcall glIsSync(GLsync sync)
7363{
7364 EVENT("(GLsync sync = 0x%0.8p)", sync);
7365
Geoff Langbfdea662014-07-23 14:16:32 -04007366 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007367 if (context)
7368 {
7369 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007370 {
Geoff Langb1196682014-07-23 13:47:29 -04007371 context->recordError(gl::Error(GL_INVALID_OPERATION));
7372 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007373 }
Geoff Langbfdea662014-07-23 14:16:32 -04007374
7375 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007376 }
7377
7378 return GL_FALSE;
7379}
7380
7381void __stdcall glDeleteSync(GLsync sync)
7382{
7383 EVENT("(GLsync sync = 0x%0.8p)", sync);
7384
Geoff Langbfdea662014-07-23 14:16:32 -04007385 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007386 if (context)
7387 {
7388 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007389 {
Geoff Langb1196682014-07-23 13:47:29 -04007390 context->recordError(gl::Error(GL_INVALID_OPERATION));
7391 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007392 }
Geoff Langbfdea662014-07-23 14:16:32 -04007393
7394 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7395 {
Geoff Langb1196682014-07-23 13:47:29 -04007396 context->recordError(gl::Error(GL_INVALID_VALUE));
7397 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007398 }
7399
7400 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007401 }
7402}
7403
7404GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7405{
7406 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7407 sync, flags, timeout);
7408
Geoff Langbfdea662014-07-23 14:16:32 -04007409 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007410 if (context)
7411 {
7412 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007413 {
Geoff Langb1196682014-07-23 13:47:29 -04007414 context->recordError(gl::Error(GL_INVALID_OPERATION));
7415 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007416 }
Geoff Langbfdea662014-07-23 14:16:32 -04007417
7418 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7419 {
Geoff Langb1196682014-07-23 13:47:29 -04007420 context->recordError(gl::Error(GL_INVALID_VALUE));
7421 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007422 }
7423
7424 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7425
7426 if (!fenceSync)
7427 {
Geoff Langb1196682014-07-23 13:47:29 -04007428 context->recordError(gl::Error(GL_INVALID_VALUE));
7429 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007430 }
7431
7432 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007433 }
7434
7435 return GL_FALSE;
7436}
7437
7438void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7439{
7440 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7441 sync, flags, timeout);
7442
Geoff Langbfdea662014-07-23 14:16:32 -04007443 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007444 if (context)
7445 {
7446 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007447 {
Geoff Langb1196682014-07-23 13:47:29 -04007448 context->recordError(gl::Error(GL_INVALID_OPERATION));
7449 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007450 }
Geoff Langbfdea662014-07-23 14:16:32 -04007451
7452 if (flags != 0)
7453 {
Geoff Langb1196682014-07-23 13:47:29 -04007454 context->recordError(gl::Error(GL_INVALID_VALUE));
7455 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007456 }
7457
7458 if (timeout != GL_TIMEOUT_IGNORED)
7459 {
Geoff Langb1196682014-07-23 13:47:29 -04007460 context->recordError(gl::Error(GL_INVALID_VALUE));
7461 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007462 }
7463
7464 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7465
7466 if (!fenceSync)
7467 {
Geoff Langb1196682014-07-23 13:47:29 -04007468 context->recordError(gl::Error(GL_INVALID_VALUE));
7469 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007470 }
7471
7472 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007473 }
7474}
7475
7476void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7477{
7478 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7479 pname, params);
7480
Geoff Langbfdea662014-07-23 14:16:32 -04007481 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007482 if (context)
7483 {
7484 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007485 {
Geoff Langb1196682014-07-23 13:47:29 -04007486 context->recordError(gl::Error(GL_INVALID_OPERATION));
7487 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007488 }
Geoff Langbfdea662014-07-23 14:16:32 -04007489
7490 GLenum nativeType;
7491 unsigned int numParams = 0;
7492 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7493 {
7494 return;
7495 }
7496
7497 if (nativeType == GL_INT_64_ANGLEX)
7498 {
7499 context->getInteger64v(pname, params);
7500 }
7501 else
7502 {
7503 CastStateValues(context, nativeType, pname, numParams, params);
7504 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007505 }
7506}
7507
7508void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7509{
7510 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7511 sync, pname, bufSize, length, values);
7512
Geoff Langbfdea662014-07-23 14:16:32 -04007513 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007514 if (context)
7515 {
7516 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007517 {
Geoff Langb1196682014-07-23 13:47:29 -04007518 context->recordError(gl::Error(GL_INVALID_OPERATION));
7519 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007520 }
Geoff Langbfdea662014-07-23 14:16:32 -04007521
7522 if (bufSize < 0)
7523 {
Geoff Langb1196682014-07-23 13:47:29 -04007524 context->recordError(gl::Error(GL_INVALID_VALUE));
7525 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007526 }
7527
7528 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7529
7530 if (!fenceSync)
7531 {
Geoff Langb1196682014-07-23 13:47:29 -04007532 context->recordError(gl::Error(GL_INVALID_VALUE));
7533 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007534 }
7535
7536 switch (pname)
7537 {
7538 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7539 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7540 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7541 case GL_SYNC_FLAGS: values[0] = 0; break;
7542
7543 default:
Geoff Langb1196682014-07-23 13:47:29 -04007544 context->recordError(gl::Error(GL_INVALID_ENUM));
7545 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007546 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007547 }
7548}
7549
7550void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7551{
7552 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7553 target, index, data);
7554
Geoff Langbfdea662014-07-23 14:16:32 -04007555 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007556 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007557 {
Geoff Langbfdea662014-07-23 14:16:32 -04007558 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007559 {
Geoff Langb1196682014-07-23 13:47:29 -04007560 context->recordError(gl::Error(GL_INVALID_OPERATION));
7561 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007562 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007563
Geoff Lang3a61c322014-07-10 13:01:54 -04007564 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007565 switch (target)
7566 {
7567 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7568 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7569 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007570 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7571 {
Geoff Langb1196682014-07-23 13:47:29 -04007572 context->recordError(gl::Error(GL_INVALID_VALUE));
7573 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007574 }
Geoff Langbfdea662014-07-23 14:16:32 -04007575 break;
Geoff Langb1196682014-07-23 13:47:29 -04007576
Geoff Langbfdea662014-07-23 14:16:32 -04007577 case GL_UNIFORM_BUFFER_START:
7578 case GL_UNIFORM_BUFFER_SIZE:
7579 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007580 if (index >= caps.maxUniformBufferBindings)
7581 {
Geoff Langb1196682014-07-23 13:47:29 -04007582 context->recordError(gl::Error(GL_INVALID_VALUE));
7583 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007584 }
Geoff Langbfdea662014-07-23 14:16:32 -04007585 break;
Geoff Langb1196682014-07-23 13:47:29 -04007586
Geoff Langbfdea662014-07-23 14:16:32 -04007587 default:
Geoff Langb1196682014-07-23 13:47:29 -04007588 context->recordError(gl::Error(GL_INVALID_ENUM));
7589 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007590 }
7591
7592 if (!(context->getIndexedInteger64v(target, index, data)))
7593 {
7594 GLenum nativeType;
7595 unsigned int numParams = 0;
7596 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007597 {
7598 context->recordError(gl::Error(GL_INVALID_ENUM));
7599 return;
7600 }
Shannon Woods15934d52013-08-19 14:28:49 -04007601
Geoff Langbfdea662014-07-23 14:16:32 -04007602 if (numParams == 0)
7603 return; // it is known that pname is valid, but there are no parameters to return
7604
7605 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007606 {
Geoff Langbfdea662014-07-23 14:16:32 -04007607 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007608
Geoff Langbfdea662014-07-23 14:16:32 -04007609 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007610
Geoff Langbfdea662014-07-23 14:16:32 -04007611 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007612 {
Geoff Langbfdea662014-07-23 14:16:32 -04007613 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007614 }
Geoff Langbfdea662014-07-23 14:16:32 -04007615
7616 delete [] intParams;
7617 }
7618 else
7619 {
7620 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007621 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007622 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007623 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007624}
7625
7626void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7627{
7628 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7629 target, pname, params);
7630
Geoff Langbfdea662014-07-23 14:16:32 -04007631 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007632 if (context)
7633 {
7634 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007635 {
Geoff Langb1196682014-07-23 13:47:29 -04007636 context->recordError(gl::Error(GL_INVALID_OPERATION));
7637 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007638 }
Geoff Langbfdea662014-07-23 14:16:32 -04007639
7640 if (!gl::ValidBufferTarget(context, target))
7641 {
Geoff Langb1196682014-07-23 13:47:29 -04007642 context->recordError(gl::Error(GL_INVALID_ENUM));
7643 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007644 }
7645
7646 if (!gl::ValidBufferParameter(context, pname))
7647 {
Geoff Langb1196682014-07-23 13:47:29 -04007648 context->recordError(gl::Error(GL_INVALID_ENUM));
7649 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007650 }
7651
7652 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7653
7654 if (!buffer)
7655 {
7656 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007657 context->recordError(gl::Error(GL_INVALID_OPERATION));
7658 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007659 }
7660
7661 switch (pname)
7662 {
7663 case GL_BUFFER_USAGE:
7664 *params = static_cast<GLint64>(buffer->getUsage());
7665 break;
7666 case GL_BUFFER_SIZE:
7667 *params = buffer->getSize();
7668 break;
7669 case GL_BUFFER_ACCESS_FLAGS:
7670 *params = static_cast<GLint64>(buffer->getAccessFlags());
7671 break;
7672 case GL_BUFFER_MAPPED:
7673 *params = static_cast<GLint64>(buffer->isMapped());
7674 break;
7675 case GL_BUFFER_MAP_OFFSET:
7676 *params = buffer->getMapOffset();
7677 break;
7678 case GL_BUFFER_MAP_LENGTH:
7679 *params = buffer->getMapLength();
7680 break;
7681 default: UNREACHABLE(); break;
7682 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007683 }
7684}
7685
7686void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7687{
7688 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7689
Geoff Langbfdea662014-07-23 14:16:32 -04007690 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007691 if (context)
7692 {
7693 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007694 {
Geoff Langb1196682014-07-23 13:47:29 -04007695 context->recordError(gl::Error(GL_INVALID_OPERATION));
7696 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007697 }
Geoff Langbfdea662014-07-23 14:16:32 -04007698
7699 if (count < 0)
7700 {
Geoff Langb1196682014-07-23 13:47:29 -04007701 context->recordError(gl::Error(GL_INVALID_VALUE));
7702 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007703 }
7704
7705 for (int i = 0; i < count; i++)
7706 {
7707 samplers[i] = context->createSampler();
7708 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007709 }
7710}
7711
7712void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7713{
7714 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7715
Geoff Langbfdea662014-07-23 14:16:32 -04007716 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007717 if (context)
7718 {
7719 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007720 {
Geoff Langb1196682014-07-23 13:47:29 -04007721 context->recordError(gl::Error(GL_INVALID_OPERATION));
7722 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007723 }
Geoff Langbfdea662014-07-23 14:16:32 -04007724
7725 if (count < 0)
7726 {
Geoff Langb1196682014-07-23 13:47:29 -04007727 context->recordError(gl::Error(GL_INVALID_VALUE));
7728 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007729 }
7730
7731 for (int i = 0; i < count; i++)
7732 {
7733 context->deleteSampler(samplers[i]);
7734 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007735 }
7736}
7737
7738GLboolean __stdcall glIsSampler(GLuint sampler)
7739{
7740 EVENT("(GLuint sampler = %u)", sampler);
7741
Geoff Langbfdea662014-07-23 14:16:32 -04007742 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007743 if (context)
7744 {
7745 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007746 {
Geoff Langb1196682014-07-23 13:47:29 -04007747 context->recordError(gl::Error(GL_INVALID_OPERATION));
7748 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007749 }
Geoff Langbfdea662014-07-23 14:16:32 -04007750
7751 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007752 }
7753
7754 return GL_FALSE;
7755}
7756
7757void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7758{
7759 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7760
Geoff Langbfdea662014-07-23 14:16:32 -04007761 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007762 if (context)
7763 {
7764 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007765 {
Geoff Langb1196682014-07-23 13:47:29 -04007766 context->recordError(gl::Error(GL_INVALID_OPERATION));
7767 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007768 }
Geoff Langbfdea662014-07-23 14:16:32 -04007769
7770 if (sampler != 0 && !context->isSampler(sampler))
7771 {
Geoff Langb1196682014-07-23 13:47:29 -04007772 context->recordError(gl::Error(GL_INVALID_OPERATION));
7773 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007774 }
7775
Geoff Lang3a61c322014-07-10 13:01:54 -04007776 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007777 {
Geoff Langb1196682014-07-23 13:47:29 -04007778 context->recordError(gl::Error(GL_INVALID_VALUE));
7779 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007780 }
7781
7782 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007783 }
7784}
7785
7786void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7787{
7788 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7789
Geoff Langbfdea662014-07-23 14:16:32 -04007790 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007791 if (context)
7792 {
7793 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007794 {
Geoff Langb1196682014-07-23 13:47:29 -04007795 context->recordError(gl::Error(GL_INVALID_OPERATION));
7796 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007797 }
Geoff Langbfdea662014-07-23 14:16:32 -04007798
Geoff Langb1196682014-07-23 13:47:29 -04007799 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007800 {
7801 return;
7802 }
7803
7804 if (!gl::ValidateTexParamParameters(context, pname, param))
7805 {
7806 return;
7807 }
7808
7809 if (!context->isSampler(sampler))
7810 {
Geoff Langb1196682014-07-23 13:47:29 -04007811 context->recordError(gl::Error(GL_INVALID_OPERATION));
7812 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007813 }
7814
7815 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007816 }
7817}
7818
7819void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7820{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007821 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007822}
7823
7824void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7825{
7826 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7827
Geoff Langbfdea662014-07-23 14:16:32 -04007828 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007829 if (context)
7830 {
7831 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007832 {
Geoff Langb1196682014-07-23 13:47:29 -04007833 context->recordError(gl::Error(GL_INVALID_OPERATION));
7834 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007835 }
Geoff Langbfdea662014-07-23 14:16:32 -04007836
Geoff Langb1196682014-07-23 13:47:29 -04007837 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007838 {
7839 return;
7840 }
7841
7842 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7843 {
7844 return;
7845 }
7846
7847 if (!context->isSampler(sampler))
7848 {
Geoff Langb1196682014-07-23 13:47:29 -04007849 context->recordError(gl::Error(GL_INVALID_OPERATION));
7850 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007851 }
7852
7853 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007854 }
7855}
7856
7857void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7858{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007859 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007860}
7861
7862void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7863{
7864 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7865
Geoff Langbfdea662014-07-23 14:16:32 -04007866 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007867 if (context)
7868 {
7869 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007870 {
Geoff Langb1196682014-07-23 13:47:29 -04007871 context->recordError(gl::Error(GL_INVALID_OPERATION));
7872 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007873 }
Geoff Langbfdea662014-07-23 14:16:32 -04007874
Geoff Langb1196682014-07-23 13:47:29 -04007875 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007876 {
7877 return;
7878 }
7879
7880 if (!context->isSampler(sampler))
7881 {
Geoff Langb1196682014-07-23 13:47:29 -04007882 context->recordError(gl::Error(GL_INVALID_OPERATION));
7883 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007884 }
7885
7886 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007887 }
7888}
7889
7890void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7891{
7892 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7893
Geoff Langbfdea662014-07-23 14:16:32 -04007894 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007895 if (context)
7896 {
7897 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007898 {
Geoff Langb1196682014-07-23 13:47:29 -04007899 context->recordError(gl::Error(GL_INVALID_OPERATION));
7900 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007901 }
Geoff Langbfdea662014-07-23 14:16:32 -04007902
Geoff Langb1196682014-07-23 13:47:29 -04007903 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007904 {
7905 return;
7906 }
7907
7908 if (!context->isSampler(sampler))
7909 {
Geoff Langb1196682014-07-23 13:47:29 -04007910 context->recordError(gl::Error(GL_INVALID_OPERATION));
7911 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007912 }
7913
7914 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007915 }
7916}
7917
7918void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7919{
7920 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7921
Geoff Langbfdea662014-07-23 14:16:32 -04007922 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007923 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007924 {
Geoff Langbfdea662014-07-23 14:16:32 -04007925 if (context->getClientVersion() < 3)
7926 {
Geoff Langb1196682014-07-23 13:47:29 -04007927 context->recordError(gl::Error(GL_INVALID_OPERATION));
7928 return;
7929 }
7930
7931 if (index >= gl::MAX_VERTEX_ATTRIBS)
7932 {
7933 context->recordError(gl::Error(GL_INVALID_VALUE));
7934 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007935 }
7936
7937 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007938 }
7939}
7940
7941void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7942{
7943 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7944
Geoff Langbfdea662014-07-23 14:16:32 -04007945 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007946 if (context)
7947 {
7948 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007949 {
Geoff Langb1196682014-07-23 13:47:29 -04007950 context->recordError(gl::Error(GL_INVALID_OPERATION));
7951 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007952 }
Geoff Langbfdea662014-07-23 14:16:32 -04007953
7954 switch (target)
7955 {
7956 case GL_TRANSFORM_FEEDBACK:
7957 {
7958 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7959 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7960 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7961 {
Geoff Langb1196682014-07-23 13:47:29 -04007962 context->recordError(gl::Error(GL_INVALID_OPERATION));
7963 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007964 }
7965
7966 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7967 if (context->getTransformFeedback(id) == NULL)
7968 {
Geoff Langb1196682014-07-23 13:47:29 -04007969 context->recordError(gl::Error(GL_INVALID_OPERATION));
7970 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007971 }
7972
7973 context->bindTransformFeedback(id);
7974 }
7975 break;
7976
7977 default:
Geoff Langb1196682014-07-23 13:47:29 -04007978 context->recordError(gl::Error(GL_INVALID_ENUM));
7979 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007980 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007981 }
7982}
7983
7984void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7985{
7986 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7987
Geoff Langbfdea662014-07-23 14:16:32 -04007988 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007989 if (context)
7990 {
7991 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007992 {
Geoff Langb1196682014-07-23 13:47:29 -04007993 context->recordError(gl::Error(GL_INVALID_OPERATION));
7994 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007995 }
Geoff Langbfdea662014-07-23 14:16:32 -04007996
7997 for (int i = 0; i < n; i++)
7998 {
7999 context->deleteTransformFeedback(ids[i]);
8000 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008001 }
8002}
8003
8004void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
8005{
8006 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8007
Geoff Langbfdea662014-07-23 14:16:32 -04008008 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008009 if (context)
8010 {
8011 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008012 {
Geoff Langb1196682014-07-23 13:47:29 -04008013 context->recordError(gl::Error(GL_INVALID_OPERATION));
8014 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008015 }
Geoff Langbfdea662014-07-23 14:16:32 -04008016
8017 for (int i = 0; i < n; i++)
8018 {
8019 ids[i] = context->createTransformFeedback();
8020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008021 }
8022}
8023
8024GLboolean __stdcall glIsTransformFeedback(GLuint id)
8025{
8026 EVENT("(GLuint id = %u)", id);
8027
Geoff Langbfdea662014-07-23 14:16:32 -04008028 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008029 if (context)
8030 {
8031 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008032 {
Geoff Langb1196682014-07-23 13:47:29 -04008033 context->recordError(gl::Error(GL_INVALID_OPERATION));
8034 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008035 }
Geoff Langbfdea662014-07-23 14:16:32 -04008036
8037 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008038 }
8039
8040 return GL_FALSE;
8041}
8042
8043void __stdcall glPauseTransformFeedback(void)
8044{
8045 EVENT("(void)");
8046
Geoff Langbfdea662014-07-23 14:16:32 -04008047 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008048 if (context)
8049 {
8050 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008051 {
Geoff Langb1196682014-07-23 13:47:29 -04008052 context->recordError(gl::Error(GL_INVALID_OPERATION));
8053 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008054 }
Geoff Langbfdea662014-07-23 14:16:32 -04008055
8056 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8057 ASSERT(transformFeedback != NULL);
8058
8059 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
8060 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
8061 {
Geoff Langb1196682014-07-23 13:47:29 -04008062 context->recordError(gl::Error(GL_INVALID_OPERATION));
8063 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008064 }
8065
8066 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008067 }
8068}
8069
8070void __stdcall glResumeTransformFeedback(void)
8071{
8072 EVENT("(void)");
8073
Geoff Langbfdea662014-07-23 14:16:32 -04008074 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008075 if (context)
8076 {
8077 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008078 {
Geoff Langb1196682014-07-23 13:47:29 -04008079 context->recordError(gl::Error(GL_INVALID_OPERATION));
8080 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008081 }
Geoff Langbfdea662014-07-23 14:16:32 -04008082
8083 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8084 ASSERT(transformFeedback != NULL);
8085
8086 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
8087 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
8088 {
Geoff Langb1196682014-07-23 13:47:29 -04008089 context->recordError(gl::Error(GL_INVALID_OPERATION));
8090 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008091 }
8092
8093 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008094 }
8095}
8096
8097void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
8098{
8099 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
8100 program, bufSize, length, binaryFormat, binary);
8101
Geoff Langbfdea662014-07-23 14:16:32 -04008102 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008103 if (context)
8104 {
8105 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008106 {
Geoff Langb1196682014-07-23 13:47:29 -04008107 context->recordError(gl::Error(GL_INVALID_OPERATION));
8108 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008109 }
Geoff Langbfdea662014-07-23 14:16:32 -04008110
8111 // glGetProgramBinary
8112 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008113 }
8114}
8115
8116void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
8117{
8118 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
8119 program, binaryFormat, binary, length);
8120
Geoff Langbfdea662014-07-23 14:16:32 -04008121 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008122 if (context)
8123 {
8124 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008125 {
Geoff Langb1196682014-07-23 13:47:29 -04008126 context->recordError(gl::Error(GL_INVALID_OPERATION));
8127 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008128 }
Geoff Langbfdea662014-07-23 14:16:32 -04008129
8130 // glProgramBinary
8131 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008132 }
8133}
8134
8135void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
8136{
8137 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
8138 program, pname, value);
8139
Geoff Langbfdea662014-07-23 14:16:32 -04008140 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008141 if (context)
8142 {
8143 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008144 {
Geoff Langb1196682014-07-23 13:47:29 -04008145 context->recordError(gl::Error(GL_INVALID_OPERATION));
8146 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008147 }
Geoff Langbfdea662014-07-23 14:16:32 -04008148
8149 // glProgramParameteri
8150 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008151 }
8152}
8153
8154void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
8155{
8156 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8157 target, numAttachments, attachments);
8158
Geoff Langbfdea662014-07-23 14:16:32 -04008159 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008160 if (context)
8161 {
8162 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008163 {
Geoff Langb1196682014-07-23 13:47:29 -04008164 context->recordError(gl::Error(GL_INVALID_OPERATION));
8165 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008166 }
Geoff Langbfdea662014-07-23 14:16:32 -04008167
8168 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8169 {
8170 return;
8171 }
8172
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008173 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8174 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8175 {
8176 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8177 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008178 }
8179}
8180
8181void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
8182{
8183 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8184 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8185 target, numAttachments, attachments, x, y, width, height);
8186
Geoff Langbfdea662014-07-23 14:16:32 -04008187 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008188 if (context)
8189 {
8190 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008191 {
Geoff Langb1196682014-07-23 13:47:29 -04008192 context->recordError(gl::Error(GL_INVALID_OPERATION));
8193 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008194 }
Geoff Langbfdea662014-07-23 14:16:32 -04008195
8196 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8197 {
8198 return;
8199 }
8200
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008201 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8202 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8203 {
8204 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8205 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008206 }
8207}
8208
8209void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8210{
8211 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8212 target, levels, internalformat, width, height);
8213
Geoff Langbfdea662014-07-23 14:16:32 -04008214 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008215 if (context)
8216 {
8217 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008218 {
Geoff Langb1196682014-07-23 13:47:29 -04008219 context->recordError(gl::Error(GL_INVALID_OPERATION));
8220 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008221 }
Geoff Langbfdea662014-07-23 14:16:32 -04008222
8223 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8224 {
8225 return;
8226 }
8227
8228 switch (target)
8229 {
8230 case GL_TEXTURE_2D:
8231 {
8232 gl::Texture2D *texture2d = context->getTexture2D();
8233 texture2d->storage(levels, internalformat, width, height);
8234 }
8235 break;
8236
8237 case GL_TEXTURE_CUBE_MAP:
8238 {
8239 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8240 textureCube->storage(levels, internalformat, width);
8241 }
8242 break;
8243
8244 default:
Geoff Langb1196682014-07-23 13:47:29 -04008245 context->recordError(gl::Error(GL_INVALID_ENUM));
8246 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008247 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008248 }
8249}
8250
8251void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8252{
8253 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8254 "GLsizei height = %d, GLsizei depth = %d)",
8255 target, levels, internalformat, width, height, depth);
8256
Geoff Langbfdea662014-07-23 14:16:32 -04008257 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008258 if (context)
8259 {
8260 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008261 {
Geoff Langb1196682014-07-23 13:47:29 -04008262 context->recordError(gl::Error(GL_INVALID_OPERATION));
8263 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008264 }
Geoff Langbfdea662014-07-23 14:16:32 -04008265
8266 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8267 {
8268 return;
8269 }
8270
8271 switch (target)
8272 {
8273 case GL_TEXTURE_3D:
8274 {
8275 gl::Texture3D *texture3d = context->getTexture3D();
8276 texture3d->storage(levels, internalformat, width, height, depth);
8277 }
8278 break;
8279
8280 case GL_TEXTURE_2D_ARRAY:
8281 {
8282 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8283 texture2darray->storage(levels, internalformat, width, height, depth);
8284 }
8285 break;
8286
8287 default:
8288 UNREACHABLE();
8289 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008290 }
8291}
8292
8293void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8294{
8295 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8296 "GLint* params = 0x%0.8p)",
8297 target, internalformat, pname, bufSize, params);
8298
Geoff Langbfdea662014-07-23 14:16:32 -04008299 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008300 if (context)
8301 {
8302 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008303 {
Geoff Langb1196682014-07-23 13:47:29 -04008304 context->recordError(gl::Error(GL_INVALID_OPERATION));
8305 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008306 }
Geoff Langbfdea662014-07-23 14:16:32 -04008307
8308 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8309 if (!formatCaps.renderable)
8310 {
Geoff Langb1196682014-07-23 13:47:29 -04008311 context->recordError(gl::Error(GL_INVALID_ENUM));
8312 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008313 }
8314
8315 if (target != GL_RENDERBUFFER)
8316 {
Geoff Langb1196682014-07-23 13:47:29 -04008317 context->recordError(gl::Error(GL_INVALID_ENUM));
8318 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008319 }
8320
8321 if (bufSize < 0)
8322 {
Geoff Langb1196682014-07-23 13:47:29 -04008323 context->recordError(gl::Error(GL_INVALID_VALUE));
8324 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008325 }
8326
8327 switch (pname)
8328 {
8329 case GL_NUM_SAMPLE_COUNTS:
8330 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008331 {
8332 *params = formatCaps.sampleCounts.size();
8333 }
Geoff Langbfdea662014-07-23 14:16:32 -04008334 break;
Geoff Langb1196682014-07-23 13:47:29 -04008335
Geoff Langbfdea662014-07-23 14:16:32 -04008336 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008337 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008338 break;
Geoff Langb1196682014-07-23 13:47:29 -04008339
Geoff Langbfdea662014-07-23 14:16:32 -04008340 default:
Geoff Langb1196682014-07-23 13:47:29 -04008341 context->recordError(gl::Error(GL_INVALID_ENUM));
8342 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008343 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008344 }
8345}
8346
8347// Extension functions
8348
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008349void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8350 GLbitfield mask, GLenum filter)
8351{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008352 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008353 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8354 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8355 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8356
Geoff Langbfdea662014-07-23 14:16:32 -04008357 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008358 if (context)
8359 {
8360 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8361 dstX0, dstY0, dstX1, dstY1, mask, filter,
8362 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008363 {
Geoff Langbfdea662014-07-23 14:16:32 -04008364 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008365 }
Geoff Langbfdea662014-07-23 14:16:32 -04008366
Geoff Lang64839152014-08-26 16:23:25 -04008367 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8368 mask, filter);
8369 if (error.isError())
8370 {
8371 context->recordError(error);
8372 return;
8373 }
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008374 }
8375}
8376
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008377void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8378 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008379{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008380 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008381 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008382 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008383 target, level, internalformat, width, height, depth, border, format, type, pixels);
8384
Geoff Langbfdea662014-07-23 14:16:32 -04008385 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008386}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008387
Geoff Langbfdea662014-07-23 14:16:32 -04008388void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008389 GLenum *binaryFormat, void *binary)
8390{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008391 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 +00008392 program, bufSize, length, binaryFormat, binary);
8393
Geoff Langbfdea662014-07-23 14:16:32 -04008394 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008395 if (context)
8396 {
8397 gl::Program *programObject = context->getProgram(program);
8398
8399 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008400 {
Geoff Langb1196682014-07-23 13:47:29 -04008401 context->recordError(gl::Error(GL_INVALID_OPERATION));
8402 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008403 }
Geoff Langbfdea662014-07-23 14:16:32 -04008404
8405 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8406
8407 if (!programBinary)
8408 {
Geoff Langb1196682014-07-23 13:47:29 -04008409 context->recordError(gl::Error(GL_INVALID_OPERATION));
8410 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008411 }
8412
Geoff Lang900013c2014-07-07 11:32:19 -04008413 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04008414 {
Geoff Langb1196682014-07-23 13:47:29 -04008415 context->recordError(gl::Error(GL_INVALID_OPERATION));
8416 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008417 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008418 }
8419}
8420
8421void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8422 const void *binary, GLint length)
8423{
8424 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8425 program, binaryFormat, binary, length);
8426
Geoff Langbfdea662014-07-23 14:16:32 -04008427 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008428 if (context)
8429 {
Geoff Lang900013c2014-07-07 11:32:19 -04008430 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8431 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008432 {
Geoff Langb1196682014-07-23 13:47:29 -04008433 context->recordError(gl::Error(GL_INVALID_ENUM));
8434 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008435 }
Geoff Langbfdea662014-07-23 14:16:32 -04008436
8437 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008438 if (!programObject)
8439 {
Geoff Langb1196682014-07-23 13:47:29 -04008440 context->recordError(gl::Error(GL_INVALID_OPERATION));
8441 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008442 }
8443
Geoff Lang900013c2014-07-07 11:32:19 -04008444 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008445 }
8446}
8447
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008448void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8449{
8450 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8451
Geoff Langbfdea662014-07-23 14:16:32 -04008452 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008453 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008454 {
Geoff Langbfdea662014-07-23 14:16:32 -04008455 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008456 {
Geoff Langb1196682014-07-23 13:47:29 -04008457 context->recordError(gl::Error(GL_INVALID_VALUE));
8458 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008459 }
8460
8461 if (context->getState().getDrawFramebuffer()->id() == 0)
8462 {
8463 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008464 {
Geoff Langb1196682014-07-23 13:47:29 -04008465 context->recordError(gl::Error(GL_INVALID_OPERATION));
8466 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008467 }
8468
Geoff Langbfdea662014-07-23 14:16:32 -04008469 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008470 {
Geoff Langb1196682014-07-23 13:47:29 -04008471 context->recordError(gl::Error(GL_INVALID_OPERATION));
8472 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008473 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008474 }
Geoff Langbfdea662014-07-23 14:16:32 -04008475 else
8476 {
8477 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8478 {
8479 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8480 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8481 {
Geoff Langb1196682014-07-23 13:47:29 -04008482 context->recordError(gl::Error(GL_INVALID_OPERATION));
8483 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008484 }
8485 }
8486 }
8487
8488 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8489
8490 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8491 {
8492 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8493 }
8494
8495 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8496 {
8497 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8498 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008499 }
8500}
8501
Shannon Woodsb3801742014-03-27 14:59:19 -04008502void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8503{
8504 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8505
Geoff Langbfdea662014-07-23 14:16:32 -04008506 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008507 if (context)
8508 {
8509 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008510 {
Geoff Langb1196682014-07-23 13:47:29 -04008511 context->recordError(gl::Error(GL_INVALID_ENUM));
8512 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008513 }
Geoff Langbfdea662014-07-23 14:16:32 -04008514
8515 if (pname != GL_BUFFER_MAP_POINTER)
8516 {
Geoff Langb1196682014-07-23 13:47:29 -04008517 context->recordError(gl::Error(GL_INVALID_ENUM));
8518 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008519 }
8520
8521 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8522
8523 if (!buffer || !buffer->isMapped())
8524 {
8525 *params = NULL;
8526 }
8527 else
8528 {
8529 *params = buffer->getMapPointer();
8530 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008531 }
8532}
8533
8534void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8535{
8536 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8537
Geoff Langbfdea662014-07-23 14:16:32 -04008538 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008539 if (context)
8540 {
8541 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008542 {
Geoff Langb1196682014-07-23 13:47:29 -04008543 context->recordError(gl::Error(GL_INVALID_ENUM));
8544 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008545 }
Geoff Langbfdea662014-07-23 14:16:32 -04008546
8547 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8548
8549 if (buffer == NULL)
8550 {
Geoff Langb1196682014-07-23 13:47:29 -04008551 context->recordError(gl::Error(GL_INVALID_OPERATION));
8552 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008553 }
8554
8555 if (access != GL_WRITE_ONLY_OES)
8556 {
Geoff Langb1196682014-07-23 13:47:29 -04008557 context->recordError(gl::Error(GL_INVALID_ENUM));
8558 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008559 }
8560
8561 if (buffer->isMapped())
8562 {
Geoff Langb1196682014-07-23 13:47:29 -04008563 context->recordError(gl::Error(GL_INVALID_OPERATION));
8564 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008565 }
8566
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008567 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8568 if (error.isError())
8569 {
8570 context->recordError(error);
8571 return NULL;
8572 }
8573
8574 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008575 }
8576
8577 return NULL;
8578}
8579
8580GLboolean __stdcall glUnmapBufferOES(GLenum target)
8581{
8582 EVENT("(GLenum target = 0x%X)", target);
8583
Geoff Langbfdea662014-07-23 14:16:32 -04008584 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008585 if (context)
8586 {
8587 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008588 {
Geoff Langb1196682014-07-23 13:47:29 -04008589 context->recordError(gl::Error(GL_INVALID_ENUM));
8590 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008591 }
Geoff Langbfdea662014-07-23 14:16:32 -04008592
8593 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8594
8595 if (buffer == NULL || !buffer->isMapped())
8596 {
Geoff Langb1196682014-07-23 13:47:29 -04008597 context->recordError(gl::Error(GL_INVALID_OPERATION));
8598 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008599 }
8600
8601 // TODO: detect if we had corruption. if so, throw an error and return false.
8602
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008603 gl::Error error = buffer->unmap();
8604 if (error.isError())
8605 {
8606 context->recordError(error);
8607 return GL_FALSE;
8608 }
Geoff Langbfdea662014-07-23 14:16:32 -04008609
8610 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008611 }
8612
8613 return GL_FALSE;
8614}
8615
Shannon Woods916e7692014-03-27 16:58:22 -04008616void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8617{
8618 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8619 target, offset, length, access);
8620
Geoff Langbfdea662014-07-23 14:16:32 -04008621 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008622 if (context)
8623 {
8624 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008625 {
Geoff Langb1196682014-07-23 13:47:29 -04008626 context->recordError(gl::Error(GL_INVALID_ENUM));
8627 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008628 }
Geoff Langbfdea662014-07-23 14:16:32 -04008629
8630 if (offset < 0 || length < 0)
8631 {
Geoff Langb1196682014-07-23 13:47:29 -04008632 context->recordError(gl::Error(GL_INVALID_VALUE));
8633 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008634 }
8635
8636 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8637
8638 if (buffer == NULL)
8639 {
Geoff Langb1196682014-07-23 13:47:29 -04008640 context->recordError(gl::Error(GL_INVALID_OPERATION));
8641 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008642 }
8643
8644 // Check for buffer overflow
8645 size_t offsetSize = static_cast<size_t>(offset);
8646 size_t lengthSize = static_cast<size_t>(length);
8647
8648 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8649 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8650 {
Geoff Langb1196682014-07-23 13:47:29 -04008651 context->recordError(gl::Error(GL_INVALID_VALUE));
8652 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008653 }
8654
8655 // Check for invalid bits in the mask
8656 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8657 GL_MAP_WRITE_BIT |
8658 GL_MAP_INVALIDATE_RANGE_BIT |
8659 GL_MAP_INVALIDATE_BUFFER_BIT |
8660 GL_MAP_FLUSH_EXPLICIT_BIT |
8661 GL_MAP_UNSYNCHRONIZED_BIT;
8662
8663 if (access & ~(allAccessBits))
8664 {
Geoff Langb1196682014-07-23 13:47:29 -04008665 context->recordError(gl::Error(GL_INVALID_VALUE));
8666 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008667 }
8668
8669 if (length == 0 || buffer->isMapped())
8670 {
Geoff Langb1196682014-07-23 13:47:29 -04008671 context->recordError(gl::Error(GL_INVALID_OPERATION));
8672 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008673 }
8674
8675 // Check for invalid bit combinations
8676 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8677 {
Geoff Langb1196682014-07-23 13:47:29 -04008678 context->recordError(gl::Error(GL_INVALID_OPERATION));
8679 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008680 }
8681
8682 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8683 GL_MAP_INVALIDATE_BUFFER_BIT |
8684 GL_MAP_UNSYNCHRONIZED_BIT;
8685
8686 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8687 {
Geoff Langb1196682014-07-23 13:47:29 -04008688 context->recordError(gl::Error(GL_INVALID_OPERATION));
8689 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008690 }
8691
8692 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8693 {
Geoff Langb1196682014-07-23 13:47:29 -04008694 context->recordError(gl::Error(GL_INVALID_OPERATION));
8695 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008696 }
8697
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008698 gl::Error error = buffer->mapRange(offset, length, access);
8699 if (error.isError())
8700 {
8701 context->recordError(error);
8702 return NULL;
8703 }
8704
8705 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008706 }
8707
8708 return NULL;
8709}
8710
8711void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8712{
8713 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8714
Geoff Langbfdea662014-07-23 14:16:32 -04008715 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008716 if (context)
8717 {
8718 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008719 {
Geoff Langb1196682014-07-23 13:47:29 -04008720 context->recordError(gl::Error(GL_INVALID_VALUE));
8721 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008722 }
Geoff Langbfdea662014-07-23 14:16:32 -04008723
8724 if (!gl::ValidBufferTarget(context, target))
8725 {
Geoff Langb1196682014-07-23 13:47:29 -04008726 context->recordError(gl::Error(GL_INVALID_ENUM));
8727 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008728 }
8729
8730 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8731
8732 if (buffer == NULL)
8733 {
Geoff Langb1196682014-07-23 13:47:29 -04008734 context->recordError(gl::Error(GL_INVALID_OPERATION));
8735 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008736 }
8737
8738 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8739 {
Geoff Langb1196682014-07-23 13:47:29 -04008740 context->recordError(gl::Error(GL_INVALID_OPERATION));
8741 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008742 }
8743
8744 // Check for buffer overflow
8745 size_t offsetSize = static_cast<size_t>(offset);
8746 size_t lengthSize = static_cast<size_t>(length);
8747
8748 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8749 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8750 {
Geoff Langb1196682014-07-23 13:47:29 -04008751 context->recordError(gl::Error(GL_INVALID_VALUE));
8752 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008753 }
8754
8755 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008756 }
8757}
8758
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008759__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8760{
8761 struct Extension
8762 {
8763 const char *name;
8764 __eglMustCastToProperFunctionPointerType address;
8765 };
8766
8767 static const Extension glExtensions[] =
8768 {
8769 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008770 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008771 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008772 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8773 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8774 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8775 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8776 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8777 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8778 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008779 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008780 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008781 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8782 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8783 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8784 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008785 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8786 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8787 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8788 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8789 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8790 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8791 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008792 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008793 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8794 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8795 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008796 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008797 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8798 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8799 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008800 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8801 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8802 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008803
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008804 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008805 {
8806 if (strcmp(procname, glExtensions[ext].name) == 0)
8807 {
8808 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8809 }
8810 }
8811
8812 return NULL;
8813}
8814
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008815// Non-public functions used by EGL
8816
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008817bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008818{
8819 EVENT("(egl::Surface* surface = 0x%0.8p)",
8820 surface);
8821
Geoff Langbfdea662014-07-23 14:16:32 -04008822 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008823 if (context)
8824 {
8825 gl::Texture2D *textureObject = context->getTexture2D();
8826 ASSERT(textureObject != NULL);
8827
8828 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008829 {
Geoff Langbfdea662014-07-23 14:16:32 -04008830 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008831 }
Geoff Langbfdea662014-07-23 14:16:32 -04008832
8833 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008834 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008835
8836 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008837}
8838
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008839}