blob: 575d25023355ca783602aa5ca0e3db2b03453430 [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();
Geoff Langb5348332014-09-02 13:16:34 -0400769 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
770 if (error.isError())
771 {
772 context->recordError(error);
773 return;
774 }
Geoff Langbfdea662014-07-23 14:16:32 -0400775 }
776 break;
777
778 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
779 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
780 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
781 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
782 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
783 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
784 {
785 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Langb5348332014-09-02 13:16:34 -0400786 gl::Error error = texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
787 if (error.isError())
788 {
789 context->recordError(error);
790 return;
791 }
Geoff Langbfdea662014-07-23 14:16:32 -0400792 }
793 break;
794
795 default:
Geoff Langb1196682014-07-23 13:47:29 -0400796 context->recordError(gl::Error(GL_INVALID_ENUM));
797 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400798 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000799 }
800}
801
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000802void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
803 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000804{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000805 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000806 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000807 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000808 target, level, xoffset, yoffset, width, height, format, imageSize, data);
809
Geoff Langbfdea662014-07-23 14:16:32 -0400810 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400811 if (context)
812 {
813 if (context->getClientVersion() < 3 &&
814 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
815 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000816 {
Geoff Langbfdea662014-07-23 14:16:32 -0400817 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000818 }
Geoff Langbfdea662014-07-23 14:16:32 -0400819
820 if (context->getClientVersion() >= 3 &&
821 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
822 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
823 {
824 return;
825 }
826
Geoff Lang5d601382014-07-22 15:14:06 -0400827 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
828 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400829 {
Geoff Langb1196682014-07-23 13:47:29 -0400830 context->recordError(gl::Error(GL_INVALID_VALUE));
831 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400832 }
833
834 switch (target)
835 {
836 case GL_TEXTURE_2D:
837 {
838 gl::Texture2D *texture = context->getTexture2D();
Geoff Langb5348332014-09-02 13:16:34 -0400839 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
840 if (error.isError())
841 {
842 context->recordError(error);
843 return;
844 }
Geoff Langbfdea662014-07-23 14:16:32 -0400845 }
846 break;
847
848 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
852 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
853 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
854 {
855 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Langb5348332014-09-02 13:16:34 -0400856 gl::Error error = texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
857 if (error.isError())
858 {
859 context->recordError(error);
860 return;
861 }
Geoff Langbfdea662014-07-23 14:16:32 -0400862 }
863 break;
864
865 default:
Geoff Langb1196682014-07-23 13:47:29 -0400866 context->recordError(gl::Error(GL_INVALID_ENUM));
867 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400868 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000869 }
870}
871
872void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
873{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000874 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000875 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000876 target, level, internalformat, x, y, width, height, border);
877
Geoff Langbfdea662014-07-23 14:16:32 -0400878 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400879 if (context)
880 {
881 if (context->getClientVersion() < 3 &&
882 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
883 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000884 {
Geoff Langbfdea662014-07-23 14:16:32 -0400885 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000886 }
Geoff Langbfdea662014-07-23 14:16:32 -0400887
888 if (context->getClientVersion() >= 3 &&
889 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
890 0, 0, 0, x, y, width, height, border))
891 {
892 return;
893 }
894
895 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
896
897 switch (target)
898 {
899 case GL_TEXTURE_2D:
900 {
901 gl::Texture2D *texture = context->getTexture2D();
902 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
903 }
904 break;
905
906 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
907 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
908 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
909 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
910 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
911 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
912 {
913 gl::TextureCubeMap *texture = context->getTextureCubeMap();
914 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
915 }
916 break;
917
Geoff Langb1196682014-07-23 13:47:29 -0400918 default:
919 context->recordError(gl::Error(GL_INVALID_ENUM));
920 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400921 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000922 }
923}
924
925void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
926{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000927 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000928 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000929 target, level, xoffset, yoffset, x, y, width, height);
930
Geoff Langbfdea662014-07-23 14:16:32 -0400931 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400932 if (context)
933 {
934 if (context->getClientVersion() < 3 &&
935 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
936 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000937 {
Geoff Langbfdea662014-07-23 14:16:32 -0400938 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000939 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000940
Geoff Langbfdea662014-07-23 14:16:32 -0400941 if (context->getClientVersion() >= 3 &&
942 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
943 xoffset, yoffset, 0, x, y, width, height, 0))
944 {
945 return;
946 }
947
948 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
949
950 switch (target)
951 {
952 case GL_TEXTURE_2D:
953 {
954 gl::Texture2D *texture = context->getTexture2D();
955 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
956 }
957 break;
958
959 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
961 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
962 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
963 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
964 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
965 {
966 gl::TextureCubeMap *texture = context->getTextureCubeMap();
967 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
968 }
969 break;
970
971 default:
Geoff Langb1196682014-07-23 13:47:29 -0400972 context->recordError(gl::Error(GL_INVALID_ENUM));
973 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400974 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000975 }
976}
977
978GLuint __stdcall glCreateProgram(void)
979{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000980 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000981
Geoff Langbfdea662014-07-23 14:16:32 -0400982 gl::Context *context = gl::getNonLostContext();
983 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000984 {
Geoff Langbfdea662014-07-23 14:16:32 -0400985 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000986 }
987
988 return 0;
989}
990
991GLuint __stdcall glCreateShader(GLenum type)
992{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000993 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000994
Geoff Langbfdea662014-07-23 14:16:32 -0400995 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400996 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000997 {
Geoff Langbfdea662014-07-23 14:16:32 -0400998 switch (type)
999 {
1000 case GL_FRAGMENT_SHADER:
1001 case GL_VERTEX_SHADER:
1002 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -04001003
Geoff Langbfdea662014-07-23 14:16:32 -04001004 default:
Geoff Langb1196682014-07-23 13:47:29 -04001005 context->recordError(gl::Error(GL_INVALID_ENUM));
1006 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04001007 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001008 }
1009
1010 return 0;
1011}
1012
1013void __stdcall glCullFace(GLenum mode)
1014{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001015 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001016
Geoff Langb1196682014-07-23 13:47:29 -04001017 gl::Context *context = gl::getNonLostContext();
1018 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001019 {
Geoff Langb1196682014-07-23 13:47:29 -04001020 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001021 {
Geoff Langb1196682014-07-23 13:47:29 -04001022 case GL_FRONT:
1023 case GL_BACK:
1024 case GL_FRONT_AND_BACK:
1025 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001026
Geoff Langb1196682014-07-23 13:47:29 -04001027 default:
1028 context->recordError(gl::Error(GL_INVALID_ENUM));
1029 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001030 }
Geoff Langb1196682014-07-23 13:47:29 -04001031
1032 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001033 }
1034}
1035
1036void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
1037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001038 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001039
Geoff Langbfdea662014-07-23 14:16:32 -04001040 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001041 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +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->deleteBuffer(buffers[i]);
1052 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001053 }
1054}
1055
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001056void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
1057{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001058 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001059
Geoff Langbfdea662014-07-23 14:16:32 -04001060 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001061 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001062 {
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++)
1070 {
1071 context->deleteFenceNV(fences[i]);
1072 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001073 }
1074}
1075
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001076void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1077{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001078 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001079
Geoff Langbfdea662014-07-23 14:16:32 -04001080 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001081 if (context)
1082 {
Geoff Langb1196682014-07-23 13:47:29 -04001083 if (n < 0)
1084 {
1085 context->recordError(gl::Error(GL_INVALID_VALUE));
1086 return;
1087 }
1088
Geoff Langbfdea662014-07-23 14:16:32 -04001089 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001090 {
Geoff Langbfdea662014-07-23 14:16:32 -04001091 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001092 {
Geoff Langbfdea662014-07-23 14:16:32 -04001093 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001094 }
1095 }
1096 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001097}
1098
1099void __stdcall glDeleteProgram(GLuint program)
1100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001101 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001102
Geoff Langbfdea662014-07-23 14:16:32 -04001103 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001104 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001105 {
Geoff Langb1196682014-07-23 13:47:29 -04001106 if (program == 0)
1107 {
1108 return;
1109 }
1110
Geoff Langbfdea662014-07-23 14:16:32 -04001111 if (!context->getProgram(program))
1112 {
1113 if(context->getShader(program))
1114 {
Geoff Langb1196682014-07-23 13:47:29 -04001115 context->recordError(gl::Error(GL_INVALID_OPERATION));
1116 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001117 }
1118 else
1119 {
Geoff Langb1196682014-07-23 13:47:29 -04001120 context->recordError(gl::Error(GL_INVALID_VALUE));
1121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001122 }
1123 }
1124
1125 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001126 }
1127}
1128
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001129void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1130{
1131 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1132
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.com86bdb822012-01-20 18:24:39 +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->deleteQuery(ids[i]);
1145 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001146 }
1147}
1148
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001149void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1150{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001151 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
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 (n < 0)
1157 {
1158 context->recordError(gl::Error(GL_INVALID_VALUE));
1159 return;
1160 }
1161
Geoff Langbfdea662014-07-23 14:16:32 -04001162 for (int i = 0; i < n; i++)
1163 {
1164 context->deleteRenderbuffer(renderbuffers[i]);
1165 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001166 }
1167}
1168
1169void __stdcall glDeleteShader(GLuint shader)
1170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001171 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001172
Geoff Langbfdea662014-07-23 14:16:32 -04001173 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001174 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001175 {
Geoff Langb1196682014-07-23 13:47:29 -04001176 if (shader == 0)
1177 {
1178 return;
1179 }
1180
Geoff Langbfdea662014-07-23 14:16:32 -04001181 if (!context->getShader(shader))
1182 {
1183 if(context->getProgram(shader))
1184 {
Geoff Langb1196682014-07-23 13:47:29 -04001185 context->recordError(gl::Error(GL_INVALID_OPERATION));
1186 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001187 }
1188 else
1189 {
Geoff Langb1196682014-07-23 13:47:29 -04001190 context->recordError(gl::Error(GL_INVALID_VALUE));
1191 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001192 }
1193 }
1194
1195 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001196 }
1197}
1198
1199void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1200{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001201 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001202
Geoff Langbfdea662014-07-23 14:16:32 -04001203 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001204 if (context)
1205 {
Geoff Langb1196682014-07-23 13:47:29 -04001206 if (n < 0)
1207 {
1208 context->recordError(gl::Error(GL_INVALID_VALUE));
1209 return;
1210 }
1211
Geoff Langbfdea662014-07-23 14:16:32 -04001212 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001213 {
Geoff Langbfdea662014-07-23 14:16:32 -04001214 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001215 {
Geoff Langbfdea662014-07-23 14:16:32 -04001216 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001217 }
1218 }
1219 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001220}
1221
1222void __stdcall glDepthFunc(GLenum func)
1223{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001224 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001225
Geoff Langbfdea662014-07-23 14:16:32 -04001226 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001227 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001228 {
Geoff Langb1196682014-07-23 13:47:29 -04001229 switch (func)
1230 {
1231 case GL_NEVER:
1232 case GL_ALWAYS:
1233 case GL_LESS:
1234 case GL_LEQUAL:
1235 case GL_EQUAL:
1236 case GL_GREATER:
1237 case GL_GEQUAL:
1238 case GL_NOTEQUAL:
1239 context->getState().setDepthFunc(func);
1240 break;
1241
1242 default:
1243 context->recordError(gl::Error(GL_INVALID_ENUM));
1244 return;
1245 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001246 }
1247}
1248
1249void __stdcall glDepthMask(GLboolean flag)
1250{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001251 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001252
Geoff Langbfdea662014-07-23 14:16:32 -04001253 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001254 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001255 {
Geoff Langbfdea662014-07-23 14:16:32 -04001256 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001257 }
1258}
1259
1260void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1261{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001262 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001263
Geoff Langbfdea662014-07-23 14:16:32 -04001264 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001265 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266 {
Geoff Langbfdea662014-07-23 14:16:32 -04001267 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001268 }
1269}
1270
1271void __stdcall glDetachShader(GLuint program, GLuint shader)
1272{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001273 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001274
Geoff Langbfdea662014-07-23 14:16:32 -04001275 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001276 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277 {
Geoff Langbfdea662014-07-23 14:16:32 -04001278 gl::Program *programObject = context->getProgram(program);
1279 gl::Shader *shaderObject = context->getShader(shader);
1280
1281 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001282 {
Geoff Langbfdea662014-07-23 14:16:32 -04001283 gl::Shader *shaderByProgramHandle;
1284 shaderByProgramHandle = context->getShader(program);
1285 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001286 {
Geoff Langb1196682014-07-23 13:47:29 -04001287 context->recordError(gl::Error(GL_INVALID_VALUE));
1288 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001289 }
Geoff Langbfdea662014-07-23 14:16:32 -04001290 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001291 {
Geoff Langb1196682014-07-23 13:47:29 -04001292 context->recordError(gl::Error(GL_INVALID_OPERATION));
1293 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001294 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001295 }
Geoff Langbfdea662014-07-23 14:16:32 -04001296
1297 if (!shaderObject)
1298 {
1299 gl::Program *programByShaderHandle = context->getProgram(shader);
1300 if (!programByShaderHandle)
1301 {
Geoff Langb1196682014-07-23 13:47:29 -04001302 context->recordError(gl::Error(GL_INVALID_VALUE));
1303 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001304 }
1305 else
1306 {
Geoff Langb1196682014-07-23 13:47:29 -04001307 context->recordError(gl::Error(GL_INVALID_OPERATION));
1308 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001309 }
1310 }
1311
1312 if (!programObject->detachShader(shaderObject))
1313 {
Geoff Langb1196682014-07-23 13:47:29 -04001314 context->recordError(gl::Error(GL_INVALID_OPERATION));
1315 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001317 }
1318}
1319
1320void __stdcall glDisable(GLenum cap)
1321{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001322 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001323
Geoff Langbfdea662014-07-23 14:16:32 -04001324 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001325 if (context)
1326 {
1327 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001328 {
Geoff Langb1196682014-07-23 13:47:29 -04001329 context->recordError(gl::Error(GL_INVALID_ENUM));
1330 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001331 }
Geoff Langbfdea662014-07-23 14:16:32 -04001332
1333 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001334 }
1335}
1336
1337void __stdcall glDisableVertexAttribArray(GLuint index)
1338{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001339 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001340
Geoff Langbfdea662014-07-23 14:16:32 -04001341 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001342 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001343 {
Geoff Langb1196682014-07-23 13:47:29 -04001344 if (index >= gl::MAX_VERTEX_ATTRIBS)
1345 {
1346 context->recordError(gl::Error(GL_INVALID_VALUE));
1347 return;
1348 }
1349
Geoff Langbfdea662014-07-23 14:16:32 -04001350 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001351 }
1352}
1353
1354void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1355{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001356 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001357
Geoff Langbfdea662014-07-23 14:16:32 -04001358 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001359 if (context)
1360 {
Jamie Madill2b976812014-08-25 15:47:49 -04001361 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001362 {
Geoff Langbfdea662014-07-23 14:16:32 -04001363 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001364 }
Geoff Langbfdea662014-07-23 14:16:32 -04001365
Geoff Langc77e8c32014-09-08 16:28:24 -04001366 gl::Error error = context->drawArrays(mode, first, count, 0);
1367 if (error.isError())
1368 {
1369 context->recordError(error);
1370 return;
1371 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001372 }
1373}
1374
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001375void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1376{
1377 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1378
Geoff Langbfdea662014-07-23 14:16:32 -04001379 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001380 if (context)
1381 {
Geoff Lang87a93302014-09-16 13:29:43 -04001382 if (!ValidateDrawArraysInstancedANGLE(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001383 {
Geoff Langbfdea662014-07-23 14:16:32 -04001384 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001385 }
Geoff Langbfdea662014-07-23 14:16:32 -04001386
Geoff Langc77e8c32014-09-08 16:28:24 -04001387 gl::Error error = context->drawArrays(mode, first, count, primcount);
1388 if (error.isError())
1389 {
1390 context->recordError(error);
1391 return;
1392 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001393 }
1394}
1395
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001396void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001397{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001398 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 +00001399 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001400
Geoff Langbfdea662014-07-23 14:16:32 -04001401 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001402 if (context)
1403 {
Jamie Madill2b976812014-08-25 15:47:49 -04001404 rx::RangeUI indexRange;
1405 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001406 {
Geoff Langbfdea662014-07-23 14:16:32 -04001407 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001408 }
Geoff Langbfdea662014-07-23 14:16:32 -04001409
Geoff Langc77e8c32014-09-08 16:28:24 -04001410 gl::Error error = context->drawElements(mode, count, type, indices, 0, indexRange);
1411 if (error.isError())
1412 {
1413 context->recordError(error);
1414 return;
1415 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001416 }
1417}
1418
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001419void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1420{
1421 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1422 mode, count, type, indices, primcount);
1423
Geoff Langbfdea662014-07-23 14:16:32 -04001424 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001425 if (context)
1426 {
Jamie Madill2b976812014-08-25 15:47:49 -04001427 rx::RangeUI indexRange;
Geoff Lang87a93302014-09-16 13:29:43 -04001428 if (!ValidateDrawElementsInstancedANGLE(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001429 {
Geoff Langbfdea662014-07-23 14:16:32 -04001430 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001431 }
Geoff Langbfdea662014-07-23 14:16:32 -04001432
Geoff Langc77e8c32014-09-08 16:28:24 -04001433 gl::Error error = context->drawElements(mode, count, type, indices, primcount, indexRange);
1434 if (error.isError())
1435 {
1436 context->recordError(error);
1437 return;
1438 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001439 }
1440}
1441
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001442void __stdcall glEnable(GLenum cap)
1443{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001444 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001445
Geoff Langbfdea662014-07-23 14:16:32 -04001446 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001447 if (context)
1448 {
1449 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001450 {
Geoff Langb1196682014-07-23 13:47:29 -04001451 context->recordError(gl::Error(GL_INVALID_ENUM));
1452 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453 }
Geoff Langbfdea662014-07-23 14:16:32 -04001454
1455 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001456 }
1457}
1458
1459void __stdcall glEnableVertexAttribArray(GLuint index)
1460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001461 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001462
Geoff Langbfdea662014-07-23 14:16:32 -04001463 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001464 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001465 {
Geoff Langb1196682014-07-23 13:47:29 -04001466 if (index >= gl::MAX_VERTEX_ATTRIBS)
1467 {
1468 context->recordError(gl::Error(GL_INVALID_VALUE));
1469 return;
1470 }
1471
Geoff Langbfdea662014-07-23 14:16:32 -04001472 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001473 }
1474}
1475
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001476void __stdcall glEndQueryEXT(GLenum target)
1477{
1478 EVENT("GLenum target = 0x%X)", target);
1479
Geoff Langbfdea662014-07-23 14:16:32 -04001480 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001481 if (context)
1482 {
1483 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001484 {
Geoff Langbfdea662014-07-23 14:16:32 -04001485 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001486 }
Geoff Langbfdea662014-07-23 14:16:32 -04001487
Geoff Lang5aad9672014-09-08 11:10:42 -04001488 gl::Error error = context->endQuery(target);
1489 if (error.isError())
1490 {
1491 context->recordError(error);
1492 return;
1493 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001494 }
1495}
1496
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001497void __stdcall glFinishFenceNV(GLuint fence)
1498{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001499 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001500
Geoff Langbfdea662014-07-23 14:16:32 -04001501 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001502 if (context)
1503 {
1504 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1505
1506 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001507 {
Geoff Langb1196682014-07-23 13:47:29 -04001508 context->recordError(gl::Error(GL_INVALID_OPERATION));
1509 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001510 }
Geoff Langbfdea662014-07-23 14:16:32 -04001511
1512 if (fenceObject->isFence() != GL_TRUE)
1513 {
Geoff Langb1196682014-07-23 13:47:29 -04001514 context->recordError(gl::Error(GL_INVALID_OPERATION));
1515 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001516 }
1517
1518 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001519 }
1520}
1521
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001522void __stdcall glFinish(void)
1523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001524 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001525
Geoff Langbfdea662014-07-23 14:16:32 -04001526 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001527 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001528 {
Geoff Langbfdea662014-07-23 14:16:32 -04001529 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001530 }
1531}
1532
1533void __stdcall glFlush(void)
1534{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001535 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001536
Geoff Langbfdea662014-07-23 14:16:32 -04001537 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001538 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001539 {
Geoff Langbfdea662014-07-23 14:16:32 -04001540 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001541 }
1542}
1543
1544void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1545{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001546 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001547 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001548
Geoff Langbfdea662014-07-23 14:16:32 -04001549 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001550 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001551 {
Geoff Langb1196682014-07-23 13:47:29 -04001552 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1553 {
1554 context->recordError(gl::Error(GL_INVALID_ENUM));
1555 return;
1556 }
1557
Geoff Langbfdea662014-07-23 14:16:32 -04001558 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1559 {
1560 return;
1561 }
1562
1563 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1564 ASSERT(framebuffer);
1565
1566 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1567 {
1568 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1569 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1570 }
1571 else
1572 {
1573 switch (attachment)
1574 {
1575 case GL_DEPTH_ATTACHMENT:
1576 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1577 break;
1578 case GL_STENCIL_ATTACHMENT:
1579 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1580 break;
1581 case GL_DEPTH_STENCIL_ATTACHMENT:
1582 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1583 break;
1584 default:
1585 UNREACHABLE();
1586 break;
1587 }
1588 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001589 }
1590}
1591
1592void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1593{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001594 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001595 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001596
Geoff Langbfdea662014-07-23 14:16:32 -04001597 gl::Context *context = gl::getNonLostContext();
1598 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001599 {
Geoff Langbfdea662014-07-23 14:16:32 -04001600 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001601 {
Geoff Langbfdea662014-07-23 14:16:32 -04001602 return;
1603 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001604
Geoff Langbfdea662014-07-23 14:16:32 -04001605 if (texture == 0)
1606 {
1607 textarget = GL_NONE;
1608 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001609
Geoff Langbfdea662014-07-23 14:16:32 -04001610 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001611
Geoff Langbfdea662014-07-23 14:16:32 -04001612 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1613 {
1614 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1615 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1616 }
1617 else
1618 {
1619 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001620 {
Geoff Langbfdea662014-07-23 14:16:32 -04001621 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1622 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1623 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001624 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001625 }
1626 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001627}
1628
1629void __stdcall glFrontFace(GLenum mode)
1630{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001631 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001632
Geoff Langb1196682014-07-23 13:47:29 -04001633 gl::Context *context = gl::getNonLostContext();
1634 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001635 {
Geoff Langb1196682014-07-23 13:47:29 -04001636 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001637 {
Geoff Langb1196682014-07-23 13:47:29 -04001638 case GL_CW:
1639 case GL_CCW:
1640 context->getState().setFrontFace(mode);
1641 break;
1642 default:
1643 context->recordError(gl::Error(GL_INVALID_ENUM));
1644 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001645 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001646 }
1647}
1648
1649void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1650{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001651 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
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)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001655 {
Geoff Langb1196682014-07-23 13:47:29 -04001656 if (n < 0)
1657 {
1658 context->recordError(gl::Error(GL_INVALID_VALUE));
1659 return;
1660 }
1661
Geoff Langbfdea662014-07-23 14:16:32 -04001662 for (int i = 0; i < n; i++)
1663 {
1664 buffers[i] = context->createBuffer();
1665 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001666 }
1667}
1668
1669void __stdcall glGenerateMipmap(GLenum target)
1670{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001671 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001672
Geoff Langbfdea662014-07-23 14:16:32 -04001673 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001674 if (context)
1675 {
1676 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001677 {
Geoff Langb1196682014-07-23 13:47:29 -04001678 context->recordError(gl::Error(GL_INVALID_ENUM));
1679 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001680 }
Geoff Langbfdea662014-07-23 14:16:32 -04001681
1682 gl::Texture *texture = context->getTargetTexture(target);
1683
1684 if (texture == NULL)
1685 {
Geoff Langb1196682014-07-23 13:47:29 -04001686 context->recordError(gl::Error(GL_INVALID_OPERATION));
1687 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001688 }
1689
1690 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1691 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001692 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001693
1694 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1695 // unsized formats or that are color renderable and filterable. Since we do not track if
1696 // the texture was created with sized or unsized format (only sized formats are stored),
1697 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1698 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1699 // textures since they're the only texture format that can be created with unsized formats
1700 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1701 // was the last version to use add them.
1702 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1703 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1704 internalFormat == GL_ALPHA8_EXT;
1705
Geoff Lang5d601382014-07-22 15:14:06 -04001706 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1707 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001708 {
Geoff Langb1196682014-07-23 13:47:29 -04001709 context->recordError(gl::Error(GL_INVALID_OPERATION));
1710 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001711 }
1712
1713 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001714 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001715 {
Geoff Langb1196682014-07-23 13:47:29 -04001716 context->recordError(gl::Error(GL_INVALID_OPERATION));
1717 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001718 }
1719
1720 // Non-power of 2 ES2 check
1721 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1722 {
1723 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001724 context->recordError(gl::Error(GL_INVALID_OPERATION));
1725 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001726 }
1727
1728 // Cube completeness check
1729 if (target == GL_TEXTURE_CUBE_MAP)
1730 {
1731 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1732 if (!textureCube->isCubeComplete())
1733 {
Geoff Langb1196682014-07-23 13:47:29 -04001734 context->recordError(gl::Error(GL_INVALID_OPERATION));
1735 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001736 }
1737 }
1738
1739 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001740 }
1741}
1742
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001743void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1744{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001745 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001746
Geoff Langbfdea662014-07-23 14:16:32 -04001747 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001748 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +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 fences[i] = context->createFenceNV();
1759 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001760 }
1761}
1762
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001763void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1764{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001765 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001766
Geoff Langbfdea662014-07-23 14:16:32 -04001767 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001768 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001769 {
Geoff Langb1196682014-07-23 13:47:29 -04001770 if (n < 0)
1771 {
1772 context->recordError(gl::Error(GL_INVALID_VALUE));
1773 return;
1774 }
1775
Geoff Langbfdea662014-07-23 14:16:32 -04001776 for (int i = 0; i < n; i++)
1777 {
1778 framebuffers[i] = context->createFramebuffer();
1779 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001780 }
1781}
1782
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001783void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1784{
1785 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1786
Geoff Langbfdea662014-07-23 14:16:32 -04001787 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001788 if (context)
1789 {
1790 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001791 {
Geoff Langb1196682014-07-23 13:47:29 -04001792 context->recordError(gl::Error(GL_INVALID_VALUE));
1793 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001794 }
Geoff Langbfdea662014-07-23 14:16:32 -04001795
1796 for (GLsizei i = 0; i < n; i++)
1797 {
1798 ids[i] = context->createQuery();
1799 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001800 }
1801}
1802
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001803void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1804{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001805 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
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 renderbuffers[i] = context->createRenderbuffer();
1819 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001820 }
1821}
1822
1823void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1824{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001825 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001826
Geoff Langbfdea662014-07-23 14:16:32 -04001827 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001828 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001829 {
Geoff Langb1196682014-07-23 13:47:29 -04001830 if (n < 0)
1831 {
1832 context->recordError(gl::Error(GL_INVALID_VALUE));
1833 return;
1834 }
1835
Geoff Langbfdea662014-07-23 14:16:32 -04001836 for (int i = 0; i < n; i++)
1837 {
1838 textures[i] = context->createTexture();
1839 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001840 }
1841}
1842
daniel@transgaming.com85423182010-04-22 13:35:27 +00001843void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001845 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001846 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001847 program, index, bufsize, length, size, type, name);
1848
Geoff Langbfdea662014-07-23 14:16:32 -04001849 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001850 if (context)
1851 {
Geoff Langb1196682014-07-23 13:47:29 -04001852 if (bufsize < 0)
1853 {
1854 context->recordError(gl::Error(GL_INVALID_VALUE));
1855 return;
1856 }
1857
Geoff Langbfdea662014-07-23 14:16:32 -04001858 gl::Program *programObject = context->getProgram(program);
1859
1860 if (!programObject)
1861 {
1862 if (context->getShader(program))
1863 {
Geoff Langb1196682014-07-23 13:47:29 -04001864 context->recordError(gl::Error(GL_INVALID_OPERATION));
1865 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001866 }
1867 else
1868 {
Geoff Langb1196682014-07-23 13:47:29 -04001869 context->recordError(gl::Error(GL_INVALID_VALUE));
1870 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001871 }
1872 }
1873
1874 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001875 {
Geoff Langb1196682014-07-23 13:47:29 -04001876 context->recordError(gl::Error(GL_INVALID_VALUE));
1877 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001878 }
1879
Geoff Langbfdea662014-07-23 14:16:32 -04001880 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001881 }
1882}
1883
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001884void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001885{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001886 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001887 "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 +00001888 program, index, bufsize, length, size, type, name);
1889
Geoff Langbfdea662014-07-23 14:16:32 -04001890
1891 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001892 if (context)
1893 {
Geoff Langb1196682014-07-23 13:47:29 -04001894 if (bufsize < 0)
1895 {
1896 context->recordError(gl::Error(GL_INVALID_VALUE));
1897 return;
1898 }
1899
Geoff Langbfdea662014-07-23 14:16:32 -04001900 gl::Program *programObject = context->getProgram(program);
1901
1902 if (!programObject)
1903 {
1904 if (context->getShader(program))
1905 {
Geoff Langb1196682014-07-23 13:47:29 -04001906 context->recordError(gl::Error(GL_INVALID_OPERATION));
1907 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001908 }
1909 else
1910 {
Geoff Langb1196682014-07-23 13:47:29 -04001911 context->recordError(gl::Error(GL_INVALID_VALUE));
1912 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001913 }
1914 }
1915
1916 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001917 {
Geoff Langb1196682014-07-23 13:47:29 -04001918 context->recordError(gl::Error(GL_INVALID_VALUE));
1919 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001920 }
1921
Geoff Langbfdea662014-07-23 14:16:32 -04001922 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001923 }
1924}
1925
1926void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1927{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001928 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 +00001929 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001930
Geoff Langbfdea662014-07-23 14:16:32 -04001931 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001932 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001933 {
Geoff Langb1196682014-07-23 13:47:29 -04001934 if (maxcount < 0)
1935 {
1936 context->recordError(gl::Error(GL_INVALID_VALUE));
1937 return;
1938 }
1939
Geoff Langbfdea662014-07-23 14:16:32 -04001940 gl::Program *programObject = context->getProgram(program);
1941
1942 if (!programObject)
1943 {
1944 if (context->getShader(program))
1945 {
Geoff Langb1196682014-07-23 13:47:29 -04001946 context->recordError(gl::Error(GL_INVALID_OPERATION));
1947 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001948 }
1949 else
1950 {
Geoff Langb1196682014-07-23 13:47:29 -04001951 context->recordError(gl::Error(GL_INVALID_VALUE));
1952 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001953 }
1954 }
1955
1956 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001957 }
1958}
1959
Geoff Langb1196682014-07-23 13:47:29 -04001960GLint __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001961{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001962 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001963
Geoff Langbfdea662014-07-23 14:16:32 -04001964 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001965 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001966 {
Geoff Langbfdea662014-07-23 14:16:32 -04001967 gl::Program *programObject = context->getProgram(program);
1968
1969 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001970 {
Geoff Langbfdea662014-07-23 14:16:32 -04001971 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001972 {
Geoff Langb1196682014-07-23 13:47:29 -04001973 context->recordError(gl::Error(GL_INVALID_OPERATION));
1974 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001975 }
Geoff Langbfdea662014-07-23 14:16:32 -04001976 else
1977 {
Geoff Langb1196682014-07-23 13:47:29 -04001978 context->recordError(gl::Error(GL_INVALID_VALUE));
1979 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001980 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001981 }
Geoff Langbfdea662014-07-23 14:16:32 -04001982
1983 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1984 if (!programObject->isLinked() || !programBinary)
1985 {
Geoff Langb1196682014-07-23 13:47:29 -04001986 context->recordError(gl::Error(GL_INVALID_OPERATION));
1987 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001988 }
1989
1990 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001991 }
1992
1993 return -1;
1994}
1995
1996void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1997{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001998 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001999
Geoff Langbfdea662014-07-23 14:16:32 -04002000 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002001 if (context)
2002 {
2003 GLenum nativeType;
2004 unsigned int numParams = 0;
2005 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002006 {
Geoff Langbfdea662014-07-23 14:16:32 -04002007 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002008 }
Geoff Langbfdea662014-07-23 14:16:32 -04002009
2010 if (nativeType == GL_BOOL)
2011 {
2012 context->getBooleanv(pname, params);
2013 }
2014 else
2015 {
2016 CastStateValues(context, nativeType, pname, numParams, params);
2017 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002018 }
2019}
2020
2021void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
2022{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002023 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 +00002024
Geoff Langbfdea662014-07-23 14:16:32 -04002025 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002026 if (context)
2027 {
2028 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002029 {
Geoff Langb1196682014-07-23 13:47:29 -04002030 context->recordError(gl::Error(GL_INVALID_ENUM));
2031 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002032 }
Geoff Langbfdea662014-07-23 14:16:32 -04002033
2034 if (!gl::ValidBufferParameter(context, pname))
2035 {
Geoff Langb1196682014-07-23 13:47:29 -04002036 context->recordError(gl::Error(GL_INVALID_ENUM));
2037 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002038 }
2039
2040 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
2041
2042 if (!buffer)
2043 {
2044 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04002045 context->recordError(gl::Error(GL_INVALID_OPERATION));
2046 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002047 }
2048
2049 switch (pname)
2050 {
2051 case GL_BUFFER_USAGE:
2052 *params = static_cast<GLint>(buffer->getUsage());
2053 break;
2054 case GL_BUFFER_SIZE:
2055 *params = gl::clampCast<GLint>(buffer->getSize());
2056 break;
2057 case GL_BUFFER_ACCESS_FLAGS:
2058 *params = buffer->getAccessFlags();
2059 break;
2060 case GL_BUFFER_MAPPED:
2061 *params = static_cast<GLint>(buffer->isMapped());
2062 break;
2063 case GL_BUFFER_MAP_OFFSET:
2064 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2065 break;
2066 case GL_BUFFER_MAP_LENGTH:
2067 *params = gl::clampCast<GLint>(buffer->getMapLength());
2068 break;
2069 default: UNREACHABLE(); break;
2070 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002071 }
2072}
2073
2074GLenum __stdcall glGetError(void)
2075{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002076 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002077
2078 gl::Context *context = gl::getContext();
2079
2080 if (context)
2081 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002082 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002083 }
2084
2085 return GL_NO_ERROR;
2086}
2087
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002088void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
2089{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002090 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002091
Geoff Langbfdea662014-07-23 14:16:32 -04002092 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002093 if (context)
2094 {
2095 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2096
2097 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002098 {
Geoff Langb1196682014-07-23 13:47:29 -04002099 context->recordError(gl::Error(GL_INVALID_OPERATION));
2100 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002101 }
Geoff Langbfdea662014-07-23 14:16:32 -04002102
2103 if (fenceObject->isFence() != GL_TRUE)
2104 {
Geoff Langb1196682014-07-23 13:47:29 -04002105 context->recordError(gl::Error(GL_INVALID_OPERATION));
2106 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002107 }
2108
2109 switch (pname)
2110 {
2111 case GL_FENCE_STATUS_NV:
2112 case GL_FENCE_CONDITION_NV:
2113 break;
2114
Geoff Langb1196682014-07-23 13:47:29 -04002115 default:
2116 context->recordError(gl::Error(GL_INVALID_ENUM));
2117 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002118 }
2119
2120 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002121 }
2122}
2123
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002124void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2125{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002126 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002127
Geoff Langbfdea662014-07-23 14:16:32 -04002128 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002129 if (context)
2130 {
2131 GLenum nativeType;
2132 unsigned int numParams = 0;
2133 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002134 {
Geoff Langbfdea662014-07-23 14:16:32 -04002135 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002136 }
Geoff Langbfdea662014-07-23 14:16:32 -04002137
2138 if (nativeType == GL_FLOAT)
2139 {
2140 context->getFloatv(pname, params);
2141 }
2142 else
2143 {
2144 CastStateValues(context, nativeType, pname, numParams, params);
2145 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002146 }
2147}
2148
2149void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2150{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002151 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 +00002152 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002153
Geoff Langbfdea662014-07-23 14:16:32 -04002154 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002155 if (context)
2156 {
2157 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002158 {
Geoff Langb1196682014-07-23 13:47:29 -04002159 context->recordError(gl::Error(GL_INVALID_ENUM));
2160 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002161 }
2162
2163 int clientVersion = context->getClientVersion();
2164
2165 switch (pname)
2166 {
2167 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2168 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2169 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2170 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2171 break;
Geoff Langb1196682014-07-23 13:47:29 -04002172
Geoff Langbfdea662014-07-23 14:16:32 -04002173 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2174 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002175 {
Geoff Langb1196682014-07-23 13:47:29 -04002176 context->recordError(gl::Error(GL_INVALID_ENUM));
2177 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002178 }
Geoff Langbfdea662014-07-23 14:16:32 -04002179 break;
Geoff Langb1196682014-07-23 13:47:29 -04002180
Geoff Langbfdea662014-07-23 14:16:32 -04002181 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2182 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2183 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2184 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2185 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2186 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2187 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2188 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
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;
Geoff Langb1196682014-07-23 13:47:29 -04002195
Geoff Langbfdea662014-07-23 14:16:32 -04002196 default:
Geoff Langb1196682014-07-23 13:47:29 -04002197 context->recordError(gl::Error(GL_INVALID_ENUM));
2198 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002199 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002200
Geoff Langbfdea662014-07-23 14:16:32 -04002201 // Determine if the attachment is a valid enum
2202 switch (attachment)
2203 {
2204 case GL_BACK:
2205 case GL_FRONT:
2206 case GL_DEPTH:
2207 case GL_STENCIL:
2208 case GL_DEPTH_STENCIL_ATTACHMENT:
2209 if (clientVersion < 3)
2210 {
Geoff Langb1196682014-07-23 13:47:29 -04002211 context->recordError(gl::Error(GL_INVALID_ENUM));
2212 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002213 }
2214 break;
2215
2216 case GL_DEPTH_ATTACHMENT:
2217 case GL_STENCIL_ATTACHMENT:
2218 break;
2219
2220 default:
2221 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2222 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2223 {
Geoff Langb1196682014-07-23 13:47:29 -04002224 context->recordError(gl::Error(GL_INVALID_ENUM));
2225 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002226 }
2227 break;
2228 }
2229
2230 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2231 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2232
2233 if (framebufferHandle == 0)
2234 {
2235 if (clientVersion < 3)
2236 {
Geoff Langb1196682014-07-23 13:47:29 -04002237 context->recordError(gl::Error(GL_INVALID_OPERATION));
2238 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002239 }
2240
2241 switch (attachment)
2242 {
2243 case GL_BACK:
2244 case GL_DEPTH:
2245 case GL_STENCIL:
2246 break;
Geoff Langb1196682014-07-23 13:47:29 -04002247
Geoff Langbfdea662014-07-23 14:16:32 -04002248 default:
Geoff Langb1196682014-07-23 13:47:29 -04002249 context->recordError(gl::Error(GL_INVALID_OPERATION));
2250 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002251 }
2252 }
2253 else
2254 {
2255 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2256 {
2257 // Valid attachment query
2258 }
2259 else
2260 {
2261 switch (attachment)
2262 {
2263 case GL_DEPTH_ATTACHMENT:
2264 case GL_STENCIL_ATTACHMENT:
2265 break;
Geoff Langb1196682014-07-23 13:47:29 -04002266
Geoff Langbfdea662014-07-23 14:16:32 -04002267 case GL_DEPTH_STENCIL_ATTACHMENT:
2268 if (framebuffer->hasValidDepthStencil())
2269 {
Geoff Langb1196682014-07-23 13:47:29 -04002270 context->recordError(gl::Error(GL_INVALID_OPERATION));
2271 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002272 }
2273 break;
Geoff Langb1196682014-07-23 13:47:29 -04002274
Geoff Langbfdea662014-07-23 14:16:32 -04002275 default:
Geoff Langb1196682014-07-23 13:47:29 -04002276 context->recordError(gl::Error(GL_INVALID_OPERATION));
2277 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002278 }
2279 }
2280 }
2281
2282 GLenum attachmentType = GL_NONE;
2283 GLuint attachmentHandle = 0;
2284 GLuint attachmentLevel = 0;
2285 GLuint attachmentLayer = 0;
2286
2287 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2288
2289 if (attachmentObject)
2290 {
2291 attachmentType = attachmentObject->type();
2292 attachmentHandle = attachmentObject->id();
2293 attachmentLevel = attachmentObject->mipLevel();
2294 attachmentLayer = attachmentObject->layer();
2295 }
2296
2297 GLenum attachmentObjectType; // Type category
2298 if (framebufferHandle == 0)
2299 {
2300 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2301 }
2302 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2303 {
2304 attachmentObjectType = attachmentType;
2305 }
2306 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2307 {
2308 attachmentObjectType = GL_TEXTURE;
2309 }
2310 else
2311 {
2312 UNREACHABLE();
2313 return;
2314 }
2315
2316 if (attachmentObjectType == GL_NONE)
2317 {
2318 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2319 // is NONE, then querying any other pname will generate INVALID_ENUM.
2320
2321 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2322 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2323 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002324
Geoff Lang646559f2013-08-15 11:08:15 -04002325 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002326 {
Geoff Lang646559f2013-08-15 11:08:15 -04002327 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002328 *params = attachmentObjectType;
2329 break;
2330
Geoff Lang646559f2013-08-15 11:08:15 -04002331 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002332 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002333 {
Geoff Langb1196682014-07-23 13:47:29 -04002334 context->recordError(gl::Error(GL_INVALID_ENUM));
2335 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002336 }
Geoff Langbfdea662014-07-23 14:16:32 -04002337 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002338 break;
2339
2340 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002341 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002342 {
Geoff Langb1196682014-07-23 13:47:29 -04002343 context->recordError(gl::Error(GL_INVALID_ENUM));
2344 return;
Geoff Lang646559f2013-08-15 11:08:15 -04002345 }
2346 else
2347 {
Geoff Langb1196682014-07-23 13:47:29 -04002348 context->recordError(gl::Error(GL_INVALID_OPERATION));
2349 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002350 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002351 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002352 }
Geoff Langbfdea662014-07-23 14:16:32 -04002353 else
2354 {
2355 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2356 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2357 ASSERT(attachmentObject != NULL);
2358
2359 switch (pname)
2360 {
2361 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2362 *params = attachmentObjectType;
2363 break;
2364
2365 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2366 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2367 {
Geoff Langb1196682014-07-23 13:47:29 -04002368 context->recordError(gl::Error(GL_INVALID_ENUM));
2369 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002370 }
2371 *params = attachmentHandle;
2372 break;
2373
2374 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2375 if (attachmentObjectType != GL_TEXTURE)
2376 {
Geoff Langb1196682014-07-23 13:47:29 -04002377 context->recordError(gl::Error(GL_INVALID_ENUM));
2378 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002379 }
2380 *params = attachmentLevel;
2381 break;
2382
2383 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2384 if (attachmentObjectType != GL_TEXTURE)
2385 {
Geoff Langb1196682014-07-23 13:47:29 -04002386 context->recordError(gl::Error(GL_INVALID_ENUM));
2387 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002388 }
2389 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2390 break;
2391
2392 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2393 *params = attachmentObject->getRedSize();
2394 break;
2395
2396 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2397 *params = attachmentObject->getGreenSize();
2398 break;
2399
2400 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2401 *params = attachmentObject->getBlueSize();
2402 break;
2403
2404 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2405 *params = attachmentObject->getAlphaSize();
2406 break;
2407
2408 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2409 *params = attachmentObject->getDepthSize();
2410 break;
2411
2412 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2413 *params = attachmentObject->getStencilSize();
2414 break;
2415
2416 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
Jamie Madillee85d1b2014-09-17 10:35:23 -04002417 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT)
Geoff Langbfdea662014-07-23 14:16:32 -04002418 {
Geoff Langb1196682014-07-23 13:47:29 -04002419 context->recordError(gl::Error(GL_INVALID_OPERATION));
2420 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002421 }
2422 *params = attachmentObject->getComponentType();
2423 break;
2424
2425 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2426 *params = attachmentObject->getColorEncoding();
2427 break;
2428
2429 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2430 if (attachmentObjectType != GL_TEXTURE)
2431 {
Geoff Langb1196682014-07-23 13:47:29 -04002432 context->recordError(gl::Error(GL_INVALID_ENUM));
2433 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002434 }
2435 *params = attachmentLayer;
2436 break;
2437
2438 default:
2439 UNREACHABLE();
2440 break;
2441 }
2442 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002443 }
2444}
2445
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002446GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2447{
2448 EVENT("()");
2449
Geoff Langbfdea662014-07-23 14:16:32 -04002450 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002451
Geoff Langbfdea662014-07-23 14:16:32 -04002452 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002453 {
Geoff Langbfdea662014-07-23 14:16:32 -04002454 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002455 }
Geoff Langbfdea662014-07-23 14:16:32 -04002456
2457 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002458}
2459
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2461{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002462 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463
Geoff Langbfdea662014-07-23 14:16:32 -04002464 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002465 if (context)
2466 {
2467 GLenum nativeType;
2468 unsigned int numParams = 0;
2469
2470 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002471 {
Geoff Langbfdea662014-07-23 14:16:32 -04002472 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002473 }
Geoff Langbfdea662014-07-23 14:16:32 -04002474
2475 if (nativeType == GL_INT)
2476 {
2477 context->getIntegerv(pname, params);
2478 }
2479 else
2480 {
2481 CastStateValues(context, nativeType, pname, numParams, params);
2482 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002483 }
2484}
2485
2486void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2487{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002488 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002489
Geoff Langbfdea662014-07-23 14:16:32 -04002490 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002491 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002492 {
Geoff Langbfdea662014-07-23 14:16:32 -04002493 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002494
Geoff Langbfdea662014-07-23 14:16:32 -04002495 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002496 {
Geoff Langb1196682014-07-23 13:47:29 -04002497 context->recordError(gl::Error(GL_INVALID_VALUE));
2498 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002499 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002500
Geoff Langbfdea662014-07-23 14:16:32 -04002501 if (context->getClientVersion() < 3)
2502 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002503 switch (pname)
2504 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002505 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002506 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002507 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002508 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002509 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002510 context->recordError(gl::Error(GL_INVALID_ENUM));
2511 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002512 }
2513 }
Geoff Langbfdea662014-07-23 14:16:32 -04002514
2515 switch (pname)
2516 {
2517 case GL_DELETE_STATUS:
2518 *params = programObject->isFlaggedForDeletion();
2519 return;
2520 case GL_LINK_STATUS:
2521 *params = programObject->isLinked();
2522 return;
2523 case GL_VALIDATE_STATUS:
2524 *params = programObject->isValidated();
2525 return;
2526 case GL_INFO_LOG_LENGTH:
2527 *params = programObject->getInfoLogLength();
2528 return;
2529 case GL_ATTACHED_SHADERS:
2530 *params = programObject->getAttachedShadersCount();
2531 return;
2532 case GL_ACTIVE_ATTRIBUTES:
2533 *params = programObject->getActiveAttributeCount();
2534 return;
2535 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2536 *params = programObject->getActiveAttributeMaxLength();
2537 return;
2538 case GL_ACTIVE_UNIFORMS:
2539 *params = programObject->getActiveUniformCount();
2540 return;
2541 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2542 *params = programObject->getActiveUniformMaxLength();
2543 return;
2544 case GL_PROGRAM_BINARY_LENGTH_OES:
2545 *params = programObject->getProgramBinaryLength();
2546 return;
2547 case GL_ACTIVE_UNIFORM_BLOCKS:
2548 *params = programObject->getActiveUniformBlockCount();
2549 return;
2550 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2551 *params = programObject->getActiveUniformBlockMaxLength();
2552 break;
2553 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2554 *params = programObject->getTransformFeedbackBufferMode();
2555 break;
2556 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2557 *params = programObject->getTransformFeedbackVaryingCount();
2558 break;
2559 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2560 *params = programObject->getTransformFeedbackVaryingMaxLength();
2561 break;
Geoff Langb1196682014-07-23 13:47:29 -04002562
Geoff Langbfdea662014-07-23 14:16:32 -04002563 default:
Geoff Langb1196682014-07-23 13:47:29 -04002564 context->recordError(gl::Error(GL_INVALID_ENUM));
2565 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002566 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002567 }
2568}
2569
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002570void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002572 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 +00002573 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002574
Geoff Langbfdea662014-07-23 14:16:32 -04002575 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002576 if (context)
2577 {
Geoff Langb1196682014-07-23 13:47:29 -04002578 if (bufsize < 0)
2579 {
2580 context->recordError(gl::Error(GL_INVALID_VALUE));
2581 return;
2582 }
2583
Geoff Langbfdea662014-07-23 14:16:32 -04002584 gl::Program *programObject = context->getProgram(program);
2585
2586 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002587 {
Geoff Langb1196682014-07-23 13:47:29 -04002588 context->recordError(gl::Error(GL_INVALID_VALUE));
2589 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002590 }
2591
Geoff Langbfdea662014-07-23 14:16:32 -04002592 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002593 }
2594}
2595
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002596void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2597{
2598 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2599
Geoff Langbfdea662014-07-23 14:16:32 -04002600 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002601 if (context)
2602 {
2603 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002604 {
Geoff Langb1196682014-07-23 13:47:29 -04002605 context->recordError(gl::Error(GL_INVALID_ENUM));
2606 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002607 }
Geoff Langbfdea662014-07-23 14:16:32 -04002608
2609 switch (pname)
2610 {
2611 case GL_CURRENT_QUERY_EXT:
2612 params[0] = context->getState().getActiveQueryId(target);
2613 break;
2614
2615 default:
Geoff Langb1196682014-07-23 13:47:29 -04002616 context->recordError(gl::Error(GL_INVALID_ENUM));
2617 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002618 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002619 }
2620}
2621
2622void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2623{
2624 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2625
Geoff Langbfdea662014-07-23 14:16:32 -04002626 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002627 if (context)
2628 {
2629 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2630
2631 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002632 {
Geoff Langb1196682014-07-23 13:47:29 -04002633 context->recordError(gl::Error(GL_INVALID_OPERATION));
2634 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002635 }
Geoff Langbfdea662014-07-23 14:16:32 -04002636
2637 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2638 {
Geoff Langb1196682014-07-23 13:47:29 -04002639 context->recordError(gl::Error(GL_INVALID_OPERATION));
2640 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002641 }
2642
2643 switch(pname)
2644 {
2645 case GL_QUERY_RESULT_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002646 {
2647 gl::Error error = queryObject->getResult(params);
2648 if (error.isError())
2649 {
2650 context->recordError(error);
2651 return;
2652 }
2653 }
Geoff Langbfdea662014-07-23 14:16:32 -04002654 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002655
Geoff Langbfdea662014-07-23 14:16:32 -04002656 case GL_QUERY_RESULT_AVAILABLE_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002657 {
2658 gl::Error error = queryObject->isResultAvailable(params);
2659 if (error.isError())
2660 {
2661 context->recordError(error);
2662 return;
2663 }
2664 }
Geoff Langbfdea662014-07-23 14:16:32 -04002665 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002666
Geoff Langbfdea662014-07-23 14:16:32 -04002667 default:
Geoff Langb1196682014-07-23 13:47:29 -04002668 context->recordError(gl::Error(GL_INVALID_ENUM));
2669 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002670 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002671 }
2672}
2673
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002674void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2675{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002676 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 +00002677
Geoff Langbfdea662014-07-23 14:16:32 -04002678 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002679 if (context)
2680 {
2681 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002682 {
Geoff Langb1196682014-07-23 13:47:29 -04002683 context->recordError(gl::Error(GL_INVALID_ENUM));
2684 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002685 }
Geoff Langbfdea662014-07-23 14:16:32 -04002686
2687 if (context->getState().getRenderbufferId() == 0)
2688 {
Geoff Langb1196682014-07-23 13:47:29 -04002689 context->recordError(gl::Error(GL_INVALID_OPERATION));
2690 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002691 }
2692
2693 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2694
2695 switch (pname)
2696 {
2697 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2698 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2699 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2700 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2701 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2702 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2703 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2704 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2705 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002706
Geoff Langbfdea662014-07-23 14:16:32 -04002707 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2708 if (!context->getExtensions().framebufferMultisample)
2709 {
Geoff Langb1196682014-07-23 13:47:29 -04002710 context->recordError(gl::Error(GL_INVALID_ENUM));
2711 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002712 }
2713 *params = renderbuffer->getSamples();
2714 break;
Geoff Langb1196682014-07-23 13:47:29 -04002715
Geoff Langbfdea662014-07-23 14:16:32 -04002716 default:
Geoff Langb1196682014-07-23 13:47:29 -04002717 context->recordError(gl::Error(GL_INVALID_ENUM));
2718 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002719 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002720 }
2721}
2722
2723void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2724{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002725 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726
Geoff Langbfdea662014-07-23 14:16:32 -04002727 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002728 if (context)
2729 {
2730 gl::Shader *shaderObject = context->getShader(shader);
2731
2732 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002733 {
Geoff Langb1196682014-07-23 13:47:29 -04002734 context->recordError(gl::Error(GL_INVALID_VALUE));
2735 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002736 }
Geoff Langbfdea662014-07-23 14:16:32 -04002737
2738 switch (pname)
2739 {
2740 case GL_SHADER_TYPE:
2741 *params = shaderObject->getType();
2742 return;
2743 case GL_DELETE_STATUS:
2744 *params = shaderObject->isFlaggedForDeletion();
2745 return;
2746 case GL_COMPILE_STATUS:
2747 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2748 return;
2749 case GL_INFO_LOG_LENGTH:
2750 *params = shaderObject->getInfoLogLength();
2751 return;
2752 case GL_SHADER_SOURCE_LENGTH:
2753 *params = shaderObject->getSourceLength();
2754 return;
2755 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2756 *params = shaderObject->getTranslatedSourceLength();
2757 return;
Geoff Langb1196682014-07-23 13:47:29 -04002758
Geoff Langbfdea662014-07-23 14:16:32 -04002759 default:
Geoff Langb1196682014-07-23 13:47:29 -04002760 context->recordError(gl::Error(GL_INVALID_ENUM));
2761 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002762 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002763 }
2764}
2765
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002766void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002767{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002768 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 +00002769 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002770
Geoff Langbfdea662014-07-23 14:16:32 -04002771 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002772 if (context)
2773 {
Geoff Langb1196682014-07-23 13:47:29 -04002774 if (bufsize < 0)
2775 {
2776 context->recordError(gl::Error(GL_INVALID_VALUE));
2777 return;
2778 }
2779
Geoff Langbfdea662014-07-23 14:16:32 -04002780 gl::Shader *shaderObject = context->getShader(shader);
2781
2782 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002783 {
Geoff Langb1196682014-07-23 13:47:29 -04002784 context->recordError(gl::Error(GL_INVALID_VALUE));
2785 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002786 }
2787
Geoff Langbfdea662014-07-23 14:16:32 -04002788 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002789 }
2790}
2791
2792void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2793{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002794 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 +00002795 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002796
Geoff Langb1196682014-07-23 13:47:29 -04002797 gl::Context *context = gl::getNonLostContext();
2798 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002799 {
Geoff Langb1196682014-07-23 13:47:29 -04002800 switch (shadertype)
2801 {
2802 case GL_VERTEX_SHADER:
2803 case GL_FRAGMENT_SHADER:
2804 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002805
Geoff Langb1196682014-07-23 13:47:29 -04002806 default:
2807 context->recordError(gl::Error(GL_INVALID_ENUM));
2808 return;
2809 }
2810
2811 switch (precisiontype)
2812 {
2813 case GL_LOW_FLOAT:
2814 case GL_MEDIUM_FLOAT:
2815 case GL_HIGH_FLOAT:
2816 // Assume IEEE 754 precision
2817 range[0] = 127;
2818 range[1] = 127;
2819 *precision = 23;
2820 break;
2821
2822 case GL_LOW_INT:
2823 case GL_MEDIUM_INT:
2824 case GL_HIGH_INT:
2825 // Some (most) hardware only supports single-precision floating-point numbers,
2826 // which can accurately represent integers up to +/-16777216
2827 range[0] = 24;
2828 range[1] = 24;
2829 *precision = 0;
2830 break;
2831
2832 default:
2833 context->recordError(gl::Error(GL_INVALID_ENUM));
2834 return;
2835 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002836 }
2837}
2838
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002839void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002840{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002841 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 +00002842 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843
Geoff Langbfdea662014-07-23 14:16:32 -04002844 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002845 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002846 {
Geoff Langb1196682014-07-23 13:47:29 -04002847 if (bufsize < 0)
2848 {
2849 context->recordError(gl::Error(GL_INVALID_VALUE));
2850 return;
2851 }
2852
Geoff Langbfdea662014-07-23 14:16:32 -04002853 gl::Shader *shaderObject = context->getShader(shader);
2854
2855 if (!shaderObject)
2856 {
Geoff Langb1196682014-07-23 13:47:29 -04002857 context->recordError(gl::Error(GL_INVALID_OPERATION));
2858 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002859 }
2860
2861 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002862 }
2863}
2864
zmo@google.coma574f782011-10-03 21:45:23 +00002865void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2866{
2867 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2868 shader, bufsize, length, source);
2869
Geoff Langbfdea662014-07-23 14:16:32 -04002870 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002871 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002872 {
Geoff Langb1196682014-07-23 13:47:29 -04002873 if (bufsize < 0)
2874 {
2875 context->recordError(gl::Error(GL_INVALID_VALUE));
2876 return;
2877 }
2878
Geoff Langbfdea662014-07-23 14:16:32 -04002879 gl::Shader *shaderObject = context->getShader(shader);
2880
2881 if (!shaderObject)
2882 {
Geoff Langb1196682014-07-23 13:47:29 -04002883 context->recordError(gl::Error(GL_INVALID_OPERATION));
2884 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002885 }
2886
2887 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002888 }
2889}
2890
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002891const GLubyte* __stdcall glGetString(GLenum name)
2892{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002893 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002894
Geoff Langbfdea662014-07-23 14:16:32 -04002895 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002896
Geoff Langbfdea662014-07-23 14:16:32 -04002897 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002898 {
Geoff Langbfdea662014-07-23 14:16:32 -04002899 case GL_VENDOR:
2900 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002901
Geoff Langbfdea662014-07-23 14:16:32 -04002902 case GL_RENDERER:
2903 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002904
Geoff Langbfdea662014-07-23 14:16:32 -04002905 case GL_VERSION:
2906 if (context->getClientVersion() == 2)
2907 {
2908 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2909 }
2910 else
2911 {
2912 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2913 }
Geoff Langb1196682014-07-23 13:47:29 -04002914
Geoff Langbfdea662014-07-23 14:16:32 -04002915 case GL_SHADING_LANGUAGE_VERSION:
2916 if (context->getClientVersion() == 2)
2917 {
2918 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2919 }
2920 else
2921 {
2922 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2923 }
Geoff Langb1196682014-07-23 13:47:29 -04002924
Geoff Langbfdea662014-07-23 14:16:32 -04002925 case GL_EXTENSIONS:
2926 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002927
Geoff Langbfdea662014-07-23 14:16:32 -04002928 default:
Geoff Langb1196682014-07-23 13:47:29 -04002929 if (context)
2930 {
2931 context->recordError(gl::Error(GL_INVALID_ENUM));
2932 }
2933 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002934 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002935}
2936
2937void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2938{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002939 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 +00002940
Geoff Langbfdea662014-07-23 14:16:32 -04002941 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002942 if (context)
2943 {
2944 gl::Texture *texture = context->getTargetTexture(target);
2945
2946 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002947 {
Geoff Langb1196682014-07-23 13:47:29 -04002948 context->recordError(gl::Error(GL_INVALID_ENUM));
2949 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002950 }
Geoff Langbfdea662014-07-23 14:16:32 -04002951
2952 switch (pname)
2953 {
2954 case GL_TEXTURE_MAG_FILTER:
2955 *params = (GLfloat)texture->getSamplerState().magFilter;
2956 break;
2957 case GL_TEXTURE_MIN_FILTER:
2958 *params = (GLfloat)texture->getSamplerState().minFilter;
2959 break;
2960 case GL_TEXTURE_WRAP_S:
2961 *params = (GLfloat)texture->getSamplerState().wrapS;
2962 break;
2963 case GL_TEXTURE_WRAP_T:
2964 *params = (GLfloat)texture->getSamplerState().wrapT;
2965 break;
2966 case GL_TEXTURE_WRAP_R:
2967 if (context->getClientVersion() < 3)
2968 {
Geoff Langb1196682014-07-23 13:47:29 -04002969 context->recordError(gl::Error(GL_INVALID_ENUM));
2970 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002971 }
2972 *params = (GLfloat)texture->getSamplerState().wrapR;
2973 break;
2974 case GL_TEXTURE_IMMUTABLE_FORMAT:
2975 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2976 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2977 break;
2978 case GL_TEXTURE_IMMUTABLE_LEVELS:
2979 if (context->getClientVersion() < 3)
2980 {
Geoff Langb1196682014-07-23 13:47:29 -04002981 context->recordError(gl::Error(GL_INVALID_ENUM));
2982 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002983 }
2984 *params = (GLfloat)texture->immutableLevelCount();
2985 break;
2986 case GL_TEXTURE_USAGE_ANGLE:
2987 *params = (GLfloat)texture->getUsage();
2988 break;
2989 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2990 if (!context->getExtensions().textureFilterAnisotropic)
2991 {
Geoff Langb1196682014-07-23 13:47:29 -04002992 context->recordError(gl::Error(GL_INVALID_ENUM));
2993 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002994 }
2995 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2996 break;
2997 case GL_TEXTURE_SWIZZLE_R:
2998 if (context->getClientVersion() < 3)
2999 {
Geoff Langb1196682014-07-23 13:47:29 -04003000 context->recordError(gl::Error(GL_INVALID_ENUM));
3001 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003002 }
3003 *params = (GLfloat)texture->getSamplerState().swizzleRed;
3004 break;
3005 case GL_TEXTURE_SWIZZLE_G:
3006 if (context->getClientVersion() < 3)
3007 {
Geoff Langb1196682014-07-23 13:47:29 -04003008 context->recordError(gl::Error(GL_INVALID_ENUM));
3009 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003010 }
3011 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
3012 break;
3013 case GL_TEXTURE_SWIZZLE_B:
3014 if (context->getClientVersion() < 3)
3015 {
Geoff Langb1196682014-07-23 13:47:29 -04003016 context->recordError(gl::Error(GL_INVALID_ENUM));
3017 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003018 }
3019 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
3020 break;
3021 case GL_TEXTURE_SWIZZLE_A:
3022 if (context->getClientVersion() < 3)
3023 {
Geoff Langb1196682014-07-23 13:47:29 -04003024 context->recordError(gl::Error(GL_INVALID_ENUM));
3025 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003026 }
3027 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
3028 break;
3029 case GL_TEXTURE_BASE_LEVEL:
3030 if (context->getClientVersion() < 3)
3031 {
Geoff Langb1196682014-07-23 13:47:29 -04003032 context->recordError(gl::Error(GL_INVALID_ENUM));
3033 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003034 }
3035 *params = (GLfloat)texture->getSamplerState().baseLevel;
3036 break;
3037 case GL_TEXTURE_MAX_LEVEL:
3038 if (context->getClientVersion() < 3)
3039 {
Geoff Langb1196682014-07-23 13:47:29 -04003040 context->recordError(gl::Error(GL_INVALID_ENUM));
3041 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003042 }
3043 *params = (GLfloat)texture->getSamplerState().maxLevel;
3044 break;
3045 case GL_TEXTURE_MIN_LOD:
3046 if (context->getClientVersion() < 3)
3047 {
Geoff Langb1196682014-07-23 13:47:29 -04003048 context->recordError(gl::Error(GL_INVALID_ENUM));
3049 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003050 }
3051 *params = texture->getSamplerState().minLod;
3052 break;
3053 case GL_TEXTURE_MAX_LOD:
3054 if (context->getClientVersion() < 3)
3055 {
Geoff Langb1196682014-07-23 13:47:29 -04003056 context->recordError(gl::Error(GL_INVALID_ENUM));
3057 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003058 }
3059 *params = texture->getSamplerState().maxLod;
3060 break;
Geoff Langb1196682014-07-23 13:47:29 -04003061
Geoff Langbfdea662014-07-23 14:16:32 -04003062 default:
Geoff Langb1196682014-07-23 13:47:29 -04003063 context->recordError(gl::Error(GL_INVALID_ENUM));
3064 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003065 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003066 }
3067}
3068
3069void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
3070{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003071 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 +00003072
Geoff Langbfdea662014-07-23 14:16:32 -04003073 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003074 if (context)
3075 {
3076 gl::Texture *texture = context->getTargetTexture(target);
3077
3078 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003079 {
Geoff Langb1196682014-07-23 13:47:29 -04003080 context->recordError(gl::Error(GL_INVALID_ENUM));
3081 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003082 }
Geoff Langbfdea662014-07-23 14:16:32 -04003083
3084 switch (pname)
3085 {
3086 case GL_TEXTURE_MAG_FILTER:
3087 *params = texture->getSamplerState().magFilter;
3088 break;
3089 case GL_TEXTURE_MIN_FILTER:
3090 *params = texture->getSamplerState().minFilter;
3091 break;
3092 case GL_TEXTURE_WRAP_S:
3093 *params = texture->getSamplerState().wrapS;
3094 break;
3095 case GL_TEXTURE_WRAP_T:
3096 *params = texture->getSamplerState().wrapT;
3097 break;
3098 case GL_TEXTURE_WRAP_R:
3099 if (context->getClientVersion() < 3)
3100 {
Geoff Langb1196682014-07-23 13:47:29 -04003101 context->recordError(gl::Error(GL_INVALID_ENUM));
3102 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003103 }
3104 *params = texture->getSamplerState().wrapR;
3105 break;
3106 case GL_TEXTURE_IMMUTABLE_FORMAT:
3107 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3108 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3109 break;
3110 case GL_TEXTURE_IMMUTABLE_LEVELS:
3111 if (context->getClientVersion() < 3)
3112 {
Geoff Langb1196682014-07-23 13:47:29 -04003113 context->recordError(gl::Error(GL_INVALID_ENUM));
3114 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003115 }
3116 *params = texture->immutableLevelCount();
3117 break;
3118 case GL_TEXTURE_USAGE_ANGLE:
3119 *params = texture->getUsage();
3120 break;
3121 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3122 if (!context->getExtensions().textureFilterAnisotropic)
3123 {
Geoff Langb1196682014-07-23 13:47:29 -04003124 context->recordError(gl::Error(GL_INVALID_ENUM));
3125 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003126 }
3127 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3128 break;
3129 case GL_TEXTURE_SWIZZLE_R:
3130 if (context->getClientVersion() < 3)
3131 {
Geoff Langb1196682014-07-23 13:47:29 -04003132 context->recordError(gl::Error(GL_INVALID_ENUM));
3133 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003134 }
3135 *params = texture->getSamplerState().swizzleRed;
3136 break;
3137 case GL_TEXTURE_SWIZZLE_G:
3138 if (context->getClientVersion() < 3)
3139 {
Geoff Langb1196682014-07-23 13:47:29 -04003140 context->recordError(gl::Error(GL_INVALID_ENUM));
3141 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003142 }
3143 *params = texture->getSamplerState().swizzleGreen;
3144 break;
3145 case GL_TEXTURE_SWIZZLE_B:
3146 if (context->getClientVersion() < 3)
3147 {
Geoff Langb1196682014-07-23 13:47:29 -04003148 context->recordError(gl::Error(GL_INVALID_ENUM));
3149 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003150 }
3151 *params = texture->getSamplerState().swizzleBlue;
3152 break;
3153 case GL_TEXTURE_SWIZZLE_A:
3154 if (context->getClientVersion() < 3)
3155 {
Geoff Langb1196682014-07-23 13:47:29 -04003156 context->recordError(gl::Error(GL_INVALID_ENUM));
3157 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003158 }
3159 *params = texture->getSamplerState().swizzleAlpha;
3160 break;
3161 case GL_TEXTURE_BASE_LEVEL:
3162 if (context->getClientVersion() < 3)
3163 {
Geoff Langb1196682014-07-23 13:47:29 -04003164 context->recordError(gl::Error(GL_INVALID_ENUM));
3165 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003166 }
3167 *params = texture->getSamplerState().baseLevel;
3168 break;
3169 case GL_TEXTURE_MAX_LEVEL:
3170 if (context->getClientVersion() < 3)
3171 {
Geoff Langb1196682014-07-23 13:47:29 -04003172 context->recordError(gl::Error(GL_INVALID_ENUM));
3173 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003174 }
3175 *params = texture->getSamplerState().maxLevel;
3176 break;
3177 case GL_TEXTURE_MIN_LOD:
3178 if (context->getClientVersion() < 3)
3179 {
Geoff Langb1196682014-07-23 13:47:29 -04003180 context->recordError(gl::Error(GL_INVALID_ENUM));
3181 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003182 }
3183 *params = (GLint)texture->getSamplerState().minLod;
3184 break;
3185 case GL_TEXTURE_MAX_LOD:
3186 if (context->getClientVersion() < 3)
3187 {
Geoff Langb1196682014-07-23 13:47:29 -04003188 context->recordError(gl::Error(GL_INVALID_ENUM));
3189 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003190 }
3191 *params = (GLint)texture->getSamplerState().maxLod;
3192 break;
Geoff Langb1196682014-07-23 13:47:29 -04003193
Geoff Langbfdea662014-07-23 14:16:32 -04003194 default:
Geoff Langb1196682014-07-23 13:47:29 -04003195 context->recordError(gl::Error(GL_INVALID_ENUM));
3196 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003197 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003198 }
3199}
3200
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003201void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3202{
3203 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3204 program, location, bufSize, params);
3205
Geoff Langbfdea662014-07-23 14:16:32 -04003206 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003207 if (context)
3208 {
Jamie Madill0063c512014-08-25 15:47:53 -04003209 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003210 {
Jamie Madill0063c512014-08-25 15:47:53 -04003211 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003212 }
3213
Jamie Madilla502c742014-08-28 17:19:13 -04003214 gl::Program *programObject = context->getProgram(program);
3215 ASSERT(programObject);
3216 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003217 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003218
Jamie Madill99a1e982014-08-25 15:47:54 -04003219 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003220 }
3221}
3222
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003223void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3224{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003225 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003226
Geoff Langbfdea662014-07-23 14:16:32 -04003227 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003228 if (context)
3229 {
Jamie Madill0063c512014-08-25 15:47:53 -04003230 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003231 {
Jamie Madill0063c512014-08-25 15:47:53 -04003232 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003233 }
Geoff Langbfdea662014-07-23 14:16:32 -04003234
Jamie Madilla502c742014-08-28 17:19:13 -04003235 gl::Program *programObject = context->getProgram(program);
3236 ASSERT(programObject);
3237 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003238 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003239
Jamie Madill99a1e982014-08-25 15:47:54 -04003240 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003241 }
3242}
3243
3244void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3245{
Geoff Langbfdea662014-07-23 14:16:32 -04003246 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003247 program, location, bufSize, params);
3248
Geoff Langbfdea662014-07-23 14:16:32 -04003249 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003250 if (context)
3251 {
Jamie Madill0063c512014-08-25 15:47:53 -04003252 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003253 {
Jamie Madill0063c512014-08-25 15:47:53 -04003254 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003255 }
3256
Jamie Madilla502c742014-08-28 17:19:13 -04003257 gl::Program *programObject = context->getProgram(program);
3258 ASSERT(programObject);
3259 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003260 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003261
Jamie Madill99a1e982014-08-25 15:47:54 -04003262 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003263 }
3264}
3265
3266void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3267{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003268 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003269
Geoff Langbfdea662014-07-23 14:16:32 -04003270 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003271 if (context)
3272 {
Jamie Madill0063c512014-08-25 15:47:53 -04003273 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003274 {
Jamie Madill0063c512014-08-25 15:47:53 -04003275 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003276 }
Geoff Langbfdea662014-07-23 14:16:32 -04003277
Jamie Madilla502c742014-08-28 17:19:13 -04003278 gl::Program *programObject = context->getProgram(program);
3279 ASSERT(programObject);
3280 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003281 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003282
Jamie Madill99a1e982014-08-25 15:47:54 -04003283 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003284 }
3285}
3286
Geoff Langb1196682014-07-23 13:47:29 -04003287GLint __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003288{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003289 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003290
Geoff Langbfdea662014-07-23 14:16:32 -04003291 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003292 if (context)
3293 {
Geoff Langb1196682014-07-23 13:47:29 -04003294 if (strstr(name, "gl_") == name)
3295 {
3296 return -1;
3297 }
3298
Geoff Langbfdea662014-07-23 14:16:32 -04003299 gl::Program *programObject = context->getProgram(program);
3300
3301 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003302 {
Geoff Langbfdea662014-07-23 14:16:32 -04003303 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003304 {
Geoff Langb1196682014-07-23 13:47:29 -04003305 context->recordError(gl::Error(GL_INVALID_OPERATION));
3306 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003307 }
Geoff Langbfdea662014-07-23 14:16:32 -04003308 else
3309 {
Geoff Langb1196682014-07-23 13:47:29 -04003310 context->recordError(gl::Error(GL_INVALID_VALUE));
3311 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003312 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003313 }
Geoff Langbfdea662014-07-23 14:16:32 -04003314
3315 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3316 if (!programObject->isLinked() || !programBinary)
3317 {
Geoff Langb1196682014-07-23 13:47:29 -04003318 context->recordError(gl::Error(GL_INVALID_OPERATION));
3319 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003320 }
3321
3322 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003323 }
3324
3325 return -1;
3326}
3327
3328void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3329{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003330 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003331
Geoff Langbfdea662014-07-23 14:16:32 -04003332 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003333 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334 {
Geoff Langbfdea662014-07-23 14:16:32 -04003335 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003336 {
Geoff Langb1196682014-07-23 13:47:29 -04003337 context->recordError(gl::Error(GL_INVALID_VALUE));
3338 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003339 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003340
Geoff Langbfdea662014-07-23 14:16:32 -04003341 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003342 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003343 {
3344 return;
3345 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003346
Geoff Langbfdea662014-07-23 14:16:32 -04003347 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3348 {
3349 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3350 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003351 {
Geoff Langbfdea662014-07-23 14:16:32 -04003352 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003353 }
3354 }
Geoff Langbfdea662014-07-23 14:16:32 -04003355 else
3356 {
3357 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3358 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003359 }
3360}
3361
3362void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003364 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003365
Geoff Langbfdea662014-07-23 14:16:32 -04003366 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003367 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003368 {
Geoff Langbfdea662014-07-23 14:16:32 -04003369 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003370 {
Geoff Langb1196682014-07-23 13:47:29 -04003371 context->recordError(gl::Error(GL_INVALID_VALUE));
3372 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003373 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003374
Geoff Langbfdea662014-07-23 14:16:32 -04003375 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003376
Geoff Langb1196682014-07-23 13:47:29 -04003377 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003378 {
3379 return;
3380 }
Jamie Madillaff71502013-07-02 11:57:05 -04003381
Geoff Langbfdea662014-07-23 14:16:32 -04003382 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3383 {
3384 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3385 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003386 {
Geoff Langbfdea662014-07-23 14:16:32 -04003387 float currentValue = currentValueData.FloatValues[i];
3388 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003389 }
3390 }
Geoff Langbfdea662014-07-23 14:16:32 -04003391 else
3392 {
3393 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3394 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003395 }
3396}
3397
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003398void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003399{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003400 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003401
Geoff Langbfdea662014-07-23 14:16:32 -04003402 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003403 if (context)
3404 {
3405 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003406 {
Geoff Langb1196682014-07-23 13:47:29 -04003407 context->recordError(gl::Error(GL_INVALID_VALUE));
3408 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003409 }
Geoff Langbfdea662014-07-23 14:16:32 -04003410
3411 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3412 {
Geoff Langb1196682014-07-23 13:47:29 -04003413 context->recordError(gl::Error(GL_INVALID_ENUM));
3414 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003415 }
3416
3417 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418 }
3419}
3420
3421void __stdcall glHint(GLenum target, GLenum mode)
3422{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003423 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003424
Geoff Langbfdea662014-07-23 14:16:32 -04003425 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003426 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427 {
Geoff Langb1196682014-07-23 13:47:29 -04003428 switch (mode)
3429 {
3430 case GL_FASTEST:
3431 case GL_NICEST:
3432 case GL_DONT_CARE:
3433 break;
3434
3435 default:
3436 context->recordError(gl::Error(GL_INVALID_ENUM));
3437 return;
3438 }
3439
3440 switch (target)
3441 {
3442 case GL_GENERATE_MIPMAP_HINT:
3443 context->getState().setGenerateMipmapHint(mode);
3444 break;
3445
3446 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3447 context->getState().setFragmentShaderDerivativeHint(mode);
3448 break;
3449
3450 default:
3451 context->recordError(gl::Error(GL_INVALID_ENUM));
3452 return;
3453 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003454 }
3455}
3456
3457GLboolean __stdcall glIsBuffer(GLuint buffer)
3458{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003459 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003460
Geoff Langbfdea662014-07-23 14:16:32 -04003461 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003462 if (context && buffer)
3463 {
3464 gl::Buffer *bufferObject = context->getBuffer(buffer);
3465
3466 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003467 {
Geoff Langbfdea662014-07-23 14:16:32 -04003468 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003469 }
3470 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003471
3472 return GL_FALSE;
3473}
3474
3475GLboolean __stdcall glIsEnabled(GLenum cap)
3476{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003477 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003478
Geoff Langbfdea662014-07-23 14:16:32 -04003479 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003480 if (context)
3481 {
3482 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003483 {
Geoff Langb1196682014-07-23 13:47:29 -04003484 context->recordError(gl::Error(GL_INVALID_ENUM));
3485 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003486 }
Geoff Langbfdea662014-07-23 14:16:32 -04003487
3488 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003489 }
3490
3491 return false;
3492}
3493
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003494GLboolean __stdcall glIsFenceNV(GLuint fence)
3495{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003496 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003497
Geoff Langbfdea662014-07-23 14:16:32 -04003498 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003499 if (context)
3500 {
3501 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3502
3503 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003504 {
Geoff Langbfdea662014-07-23 14:16:32 -04003505 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003506 }
Geoff Langbfdea662014-07-23 14:16:32 -04003507
3508 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003509 }
3510
3511 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003512}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003513
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003514GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3515{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003516 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003517
Geoff Langbfdea662014-07-23 14:16:32 -04003518 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003519 if (context && framebuffer)
3520 {
3521 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3522
3523 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003524 {
Geoff Langbfdea662014-07-23 14:16:32 -04003525 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526 }
3527 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003528
3529 return GL_FALSE;
3530}
3531
3532GLboolean __stdcall glIsProgram(GLuint program)
3533{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003534 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003535
Geoff Langbfdea662014-07-23 14:16:32 -04003536 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003537 if (context && program)
3538 {
3539 gl::Program *programObject = context->getProgram(program);
3540
3541 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003542 {
Geoff Langbfdea662014-07-23 14:16:32 -04003543 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003544 }
3545 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003546
3547 return GL_FALSE;
3548}
3549
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003550GLboolean __stdcall glIsQueryEXT(GLuint id)
3551{
3552 EVENT("(GLuint id = %d)", id);
3553
Geoff Langbfdea662014-07-23 14:16:32 -04003554 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003555 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003556 {
Geoff Langbfdea662014-07-23 14:16:32 -04003557 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003558 }
3559
3560 return GL_FALSE;
3561}
3562
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003563GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3564{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003565 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003566
Geoff Langbfdea662014-07-23 14:16:32 -04003567 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003568 if (context && renderbuffer)
3569 {
3570 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3571
3572 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003573 {
Geoff Langbfdea662014-07-23 14:16:32 -04003574 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003575 }
3576 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003577
3578 return GL_FALSE;
3579}
3580
3581GLboolean __stdcall glIsShader(GLuint shader)
3582{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003583 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003584
Geoff Langbfdea662014-07-23 14:16:32 -04003585 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003586 if (context && shader)
3587 {
3588 gl::Shader *shaderObject = context->getShader(shader);
3589
3590 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003591 {
Geoff Langbfdea662014-07-23 14:16:32 -04003592 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003593 }
3594 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003595
3596 return GL_FALSE;
3597}
3598
3599GLboolean __stdcall glIsTexture(GLuint texture)
3600{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003601 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003602
Geoff Langbfdea662014-07-23 14:16:32 -04003603 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003604 if (context && texture)
3605 {
3606 gl::Texture *textureObject = context->getTexture(texture);
3607
3608 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003609 {
Geoff Langbfdea662014-07-23 14:16:32 -04003610 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003611 }
3612 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003613
3614 return GL_FALSE;
3615}
3616
3617void __stdcall glLineWidth(GLfloat width)
3618{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003619 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003620
Geoff Langbfdea662014-07-23 14:16:32 -04003621 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003622 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003623 {
Geoff Langb1196682014-07-23 13:47:29 -04003624 if (width <= 0.0f)
3625 {
3626 context->recordError(gl::Error(GL_INVALID_VALUE));
3627 return;
3628 }
3629
Geoff Langbfdea662014-07-23 14:16:32 -04003630 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003631 }
3632}
3633
3634void __stdcall glLinkProgram(GLuint program)
3635{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003636 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003637
Geoff Langbfdea662014-07-23 14:16:32 -04003638 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003639 if (context)
3640 {
3641 gl::Program *programObject = context->getProgram(program);
3642
3643 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003644 {
Geoff Langbfdea662014-07-23 14:16:32 -04003645 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003646 {
Geoff Langb1196682014-07-23 13:47:29 -04003647 context->recordError(gl::Error(GL_INVALID_OPERATION));
3648 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003649 }
Geoff Langbfdea662014-07-23 14:16:32 -04003650 else
3651 {
Geoff Langb1196682014-07-23 13:47:29 -04003652 context->recordError(gl::Error(GL_INVALID_VALUE));
3653 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003654 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003655 }
Geoff Langbfdea662014-07-23 14:16:32 -04003656
3657 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003658 }
3659}
3660
3661void __stdcall glPixelStorei(GLenum pname, GLint param)
3662{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003663 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664
Geoff Langbfdea662014-07-23 14:16:32 -04003665 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003666 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003667 {
Geoff Langbfdea662014-07-23 14:16:32 -04003668 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003669 {
Geoff Langbfdea662014-07-23 14:16:32 -04003670 case GL_UNPACK_ALIGNMENT:
3671 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003672 {
Geoff Langb1196682014-07-23 13:47:29 -04003673 context->recordError(gl::Error(GL_INVALID_VALUE));
3674 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003675 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003676
Geoff Langbfdea662014-07-23 14:16:32 -04003677 context->getState().setUnpackAlignment(param);
3678 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003679
Geoff Langbfdea662014-07-23 14:16:32 -04003680 case GL_PACK_ALIGNMENT:
3681 if (param != 1 && param != 2 && param != 4 && param != 8)
3682 {
Geoff Langb1196682014-07-23 13:47:29 -04003683 context->recordError(gl::Error(GL_INVALID_VALUE));
3684 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003685 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003686
Geoff Langbfdea662014-07-23 14:16:32 -04003687 context->getState().setPackAlignment(param);
3688 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003689
Geoff Langbfdea662014-07-23 14:16:32 -04003690 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3691 context->getState().setPackReverseRowOrder(param != 0);
3692 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003693
Geoff Langbfdea662014-07-23 14:16:32 -04003694 case GL_UNPACK_IMAGE_HEIGHT:
3695 case GL_UNPACK_SKIP_IMAGES:
3696 case GL_UNPACK_ROW_LENGTH:
3697 case GL_UNPACK_SKIP_ROWS:
3698 case GL_UNPACK_SKIP_PIXELS:
3699 case GL_PACK_ROW_LENGTH:
3700 case GL_PACK_SKIP_ROWS:
3701 case GL_PACK_SKIP_PIXELS:
3702 if (context->getClientVersion() < 3)
3703 {
Geoff Langb1196682014-07-23 13:47:29 -04003704 context->recordError(gl::Error(GL_INVALID_ENUM));
3705 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003706 }
Geoff Langbfdea662014-07-23 14:16:32 -04003707 UNIMPLEMENTED();
3708 break;
3709
3710 default:
Geoff Langb1196682014-07-23 13:47:29 -04003711 context->recordError(gl::Error(GL_INVALID_ENUM));
3712 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003713 }
3714 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003715}
3716
3717void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3718{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003719 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003720
Geoff Langbfdea662014-07-23 14:16:32 -04003721 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003722 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003723 {
Geoff Langbfdea662014-07-23 14:16:32 -04003724 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003725 }
3726}
3727
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003728void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3729 GLenum format, GLenum type, GLsizei bufSize,
3730 GLvoid *data)
3731{
3732 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3733 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3734 x, y, width, height, format, type, bufSize, data);
3735
Geoff Langbfdea662014-07-23 14:16:32 -04003736 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003737 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003738 {
Geoff Langb1196682014-07-23 13:47:29 -04003739 if (width < 0 || height < 0 || bufSize < 0)
3740 {
3741 context->recordError(gl::Error(GL_INVALID_VALUE));
3742 return;
3743 }
3744
Geoff Langbfdea662014-07-23 14:16:32 -04003745 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3746 format, type, &bufSize, data))
3747 {
3748 return;
3749 }
3750
Geoff Lang63d2fc72014-07-25 14:51:41 -04003751 gl::Error error = context->readPixels(x, y, width, height, format, type, &bufSize, data);
3752 if (error.isError())
3753 {
3754 context->recordError(error);
3755 return;
3756 }
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003757 }
3758}
3759
3760void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3761 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003762{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003763 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003764 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003765 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003766
Geoff Langbfdea662014-07-23 14:16:32 -04003767 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003768 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003769 {
Geoff Langb1196682014-07-23 13:47:29 -04003770 if (width < 0 || height < 0)
3771 {
3772 context->recordError(gl::Error(GL_INVALID_VALUE));
3773 return;
3774 }
3775
Geoff Langbfdea662014-07-23 14:16:32 -04003776 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3777 format, type, NULL, pixels))
3778 {
3779 return;
3780 }
3781
Geoff Lang63d2fc72014-07-25 14:51:41 -04003782 gl::Error error = context->readPixels(x, y, width, height, format, type, NULL, pixels);
3783 if (error.isError())
3784 {
3785 context->recordError(error);
3786 return;
3787 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003788 }
3789}
3790
3791void __stdcall glReleaseShaderCompiler(void)
3792{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003793 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003794
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003795 gl::Context *context = gl::getNonLostContext();
3796
3797 if (context)
3798 {
3799 context->releaseShaderCompiler();
3800 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003801}
3802
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003803void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003804{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003805 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 +00003806 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003807
Geoff Langbfdea662014-07-23 14:16:32 -04003808 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003809 if (context)
3810 {
3811 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3812 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003813 {
Geoff Langbfdea662014-07-23 14:16:32 -04003814 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003815 }
Geoff Langbfdea662014-07-23 14:16:32 -04003816
3817 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003818 }
3819}
3820
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003821void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3822{
3823 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3824}
3825
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003826void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3827{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003828 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003829
Geoff Langbfdea662014-07-23 14:16:32 -04003830 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003831
Geoff Langbfdea662014-07-23 14:16:32 -04003832 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003833 {
Geoff Langbfdea662014-07-23 14:16:32 -04003834 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003835 }
3836}
3837
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003838void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3839{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003840 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003841
Geoff Langbfdea662014-07-23 14:16:32 -04003842 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003843 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003844 {
Geoff Langb1196682014-07-23 13:47:29 -04003845 if (condition != GL_ALL_COMPLETED_NV)
3846 {
3847 context->recordError(gl::Error(GL_INVALID_ENUM));
3848 return;
3849 }
3850
Geoff Langbfdea662014-07-23 14:16:32 -04003851 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3852
3853 if (fenceObject == NULL)
3854 {
Geoff Langb1196682014-07-23 13:47:29 -04003855 context->recordError(gl::Error(GL_INVALID_OPERATION));
3856 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003857 }
3858
3859 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003860 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003861}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003862
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003863void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003865 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 +00003866
Geoff Langbfdea662014-07-23 14:16:32 -04003867 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003868 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003869 {
Geoff Langb1196682014-07-23 13:47:29 -04003870 if (width < 0 || height < 0)
3871 {
3872 context->recordError(gl::Error(GL_INVALID_VALUE));
3873 return;
3874 }
3875
Geoff Langbfdea662014-07-23 14:16:32 -04003876 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003877 }
3878}
3879
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003880void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003881{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003882 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003883 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003884 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003885
Geoff Lang900013c2014-07-07 11:32:19 -04003886 gl::Context* context = gl::getNonLostContext();
3887 if (context)
3888 {
3889 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3890 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3891 {
Geoff Langb1196682014-07-23 13:47:29 -04003892 context->recordError(gl::Error(GL_INVALID_ENUM));
3893 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003894 }
3895
3896 // No binary shader formats are supported.
3897 UNIMPLEMENTED();
3898 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003899}
3900
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003901void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003902{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003903 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 +00003904 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003905
Geoff Langbfdea662014-07-23 14:16:32 -04003906 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003907 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003908 {
Geoff Langb1196682014-07-23 13:47:29 -04003909 if (count < 0)
3910 {
3911 context->recordError(gl::Error(GL_INVALID_VALUE));
3912 return;
3913 }
3914
Geoff Langbfdea662014-07-23 14:16:32 -04003915 gl::Shader *shaderObject = context->getShader(shader);
3916
3917 if (!shaderObject)
3918 {
3919 if (context->getProgram(shader))
3920 {
Geoff Langb1196682014-07-23 13:47:29 -04003921 context->recordError(gl::Error(GL_INVALID_OPERATION));
3922 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003923 }
3924 else
3925 {
Geoff Langb1196682014-07-23 13:47:29 -04003926 context->recordError(gl::Error(GL_INVALID_VALUE));
3927 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003928 }
3929 }
3930
3931 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003932 }
3933}
3934
3935void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3936{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003937 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003938}
3939
3940void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3941{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003942 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 +00003943
Geoff Langbfdea662014-07-23 14:16:32 -04003944 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003945 if (context)
3946 {
Geoff Langb1196682014-07-23 13:47:29 -04003947 switch (face)
3948 {
3949 case GL_FRONT:
3950 case GL_BACK:
3951 case GL_FRONT_AND_BACK:
3952 break;
3953
3954 default:
3955 context->recordError(gl::Error(GL_INVALID_ENUM));
3956 return;
3957 }
3958
3959 switch (func)
3960 {
3961 case GL_NEVER:
3962 case GL_ALWAYS:
3963 case GL_LESS:
3964 case GL_LEQUAL:
3965 case GL_EQUAL:
3966 case GL_GEQUAL:
3967 case GL_GREATER:
3968 case GL_NOTEQUAL:
3969 break;
3970
3971 default:
3972 context->recordError(gl::Error(GL_INVALID_ENUM));
3973 return;
3974 }
3975
Geoff Langbfdea662014-07-23 14:16:32 -04003976 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3977 {
3978 context->getState().setStencilParams(func, ref, mask);
3979 }
3980
3981 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3982 {
3983 context->getState().setStencilBackParams(func, ref, mask);
3984 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003985 }
3986}
3987
3988void __stdcall glStencilMask(GLuint mask)
3989{
3990 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3991}
3992
3993void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003995 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003996
Geoff Langbfdea662014-07-23 14:16:32 -04003997 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003998 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003999 {
Geoff Langb1196682014-07-23 13:47:29 -04004000 switch (face)
4001 {
4002 case GL_FRONT:
4003 case GL_BACK:
4004 case GL_FRONT_AND_BACK:
4005 break;
4006
4007 default:
4008 context->recordError(gl::Error(GL_INVALID_ENUM));
4009 return;
4010 }
4011
Geoff Langbfdea662014-07-23 14:16:32 -04004012 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4013 {
4014 context->getState().setStencilWritemask(mask);
4015 }
4016
4017 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4018 {
4019 context->getState().setStencilBackWritemask(mask);
4020 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004021 }
4022}
4023
4024void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4025{
4026 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4027}
4028
4029void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4030{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004031 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 +00004032 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004033
Geoff Langbfdea662014-07-23 14:16:32 -04004034 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004035 if (context)
4036 {
Geoff Langb1196682014-07-23 13:47:29 -04004037 switch (face)
4038 {
4039 case GL_FRONT:
4040 case GL_BACK:
4041 case GL_FRONT_AND_BACK:
4042 break;
4043
4044 default:
4045 context->recordError(gl::Error(GL_INVALID_ENUM));
4046 return;
4047 }
4048
4049 switch (fail)
4050 {
4051 case GL_ZERO:
4052 case GL_KEEP:
4053 case GL_REPLACE:
4054 case GL_INCR:
4055 case GL_DECR:
4056 case GL_INVERT:
4057 case GL_INCR_WRAP:
4058 case GL_DECR_WRAP:
4059 break;
4060
4061 default:
4062 context->recordError(gl::Error(GL_INVALID_ENUM));
4063 return;
4064 }
4065
4066 switch (zfail)
4067 {
4068 case GL_ZERO:
4069 case GL_KEEP:
4070 case GL_REPLACE:
4071 case GL_INCR:
4072 case GL_DECR:
4073 case GL_INVERT:
4074 case GL_INCR_WRAP:
4075 case GL_DECR_WRAP:
4076 break;
4077
4078 default:
4079 context->recordError(gl::Error(GL_INVALID_ENUM));
4080 return;
4081 }
4082
4083 switch (zpass)
4084 {
4085 case GL_ZERO:
4086 case GL_KEEP:
4087 case GL_REPLACE:
4088 case GL_INCR:
4089 case GL_DECR:
4090 case GL_INVERT:
4091 case GL_INCR_WRAP:
4092 case GL_DECR_WRAP:
4093 break;
4094
4095 default:
4096 context->recordError(gl::Error(GL_INVALID_ENUM));
4097 return;
4098 }
4099
Geoff Langbfdea662014-07-23 14:16:32 -04004100 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4101 {
4102 context->getState().setStencilOperations(fail, zfail, zpass);
4103 }
4104
4105 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4106 {
4107 context->getState().setStencilBackOperations(fail, zfail, zpass);
4108 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004109 }
4110}
4111
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004112GLboolean __stdcall glTestFenceNV(GLuint fence)
4113{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004114 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004115
Geoff Langbfdea662014-07-23 14:16:32 -04004116 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004117 if (context)
4118 {
4119 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4120
4121 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004122 {
Geoff Langb1196682014-07-23 13:47:29 -04004123 context->recordError(gl::Error(GL_INVALID_OPERATION));
4124 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004125 }
Geoff Langbfdea662014-07-23 14:16:32 -04004126
4127 if (fenceObject->isFence() != GL_TRUE)
4128 {
Geoff Langb1196682014-07-23 13:47:29 -04004129 context->recordError(gl::Error(GL_INVALID_OPERATION));
4130 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004131 }
4132
4133 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004134 }
Geoff Langbfdea662014-07-23 14:16:32 -04004135
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004136 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004137}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004138
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004139void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4140 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004141{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004142 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004143 "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 +00004144 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004145
Geoff Langbfdea662014-07-23 14:16:32 -04004146 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004147 if (context)
4148 {
4149 if (context->getClientVersion() < 3 &&
4150 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4151 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004152 {
Geoff Langbfdea662014-07-23 14:16:32 -04004153 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004154 }
Geoff Langbfdea662014-07-23 14:16:32 -04004155
4156 if (context->getClientVersion() >= 3 &&
4157 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4158 0, 0, 0, width, height, 1, border, format, type, pixels))
4159 {
4160 return;
4161 }
4162
4163 switch (target)
4164 {
4165 case GL_TEXTURE_2D:
4166 {
4167 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004168 gl::Error error = texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4169 if (error.isError())
4170 {
4171 context->recordError(error);
4172 return;
4173 }
Geoff Langbfdea662014-07-23 14:16:32 -04004174 }
4175 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004176
Geoff Langbfdea662014-07-23 14:16:32 -04004177 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004178 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004179 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004180 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004181 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
Geoff Langbfdea662014-07-23 14:16:32 -04004182 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4183 {
4184 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang8376cea2014-09-02 11:47:07 -04004185 gl::Error error = texture->setImage(target, level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004186 if (error.isError())
4187 {
4188 context->recordError(error);
4189 return;
4190 }
Geoff Langbfdea662014-07-23 14:16:32 -04004191 }
4192 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004193
Geoff Langbfdea662014-07-23 14:16:32 -04004194 default: UNREACHABLE();
4195 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004196 }
4197}
4198
4199void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4200{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004201 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4202
Geoff Langbfdea662014-07-23 14:16:32 -04004203 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004204 if (context)
4205 {
4206 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004207 {
Geoff Langbfdea662014-07-23 14:16:32 -04004208 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004209 }
Geoff Langbfdea662014-07-23 14:16:32 -04004210
4211 gl::Texture *texture = context->getTargetTexture(target);
4212
4213 if (!texture)
4214 {
Geoff Langb1196682014-07-23 13:47:29 -04004215 context->recordError(gl::Error(GL_INVALID_ENUM));
4216 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004217 }
4218
4219 switch (pname)
4220 {
4221 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4222 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4223 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4224 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4225 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4226 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4227 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4228 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4229 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4230 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4231 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4232 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4233 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4234 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4235 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4236 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4237 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4238 default: UNREACHABLE(); break;
4239 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004240 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004241}
4242
4243void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4244{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004245 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004246}
4247
4248void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4249{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004250 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004251
Geoff Langbfdea662014-07-23 14:16:32 -04004252 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004253 if (context)
4254 {
4255 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004256 {
Geoff Langbfdea662014-07-23 14:16:32 -04004257 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
Geoff Langbfdea662014-07-23 14:16:32 -04004259
4260 gl::Texture *texture = context->getTargetTexture(target);
4261
4262 if (!texture)
4263 {
Geoff Langb1196682014-07-23 13:47:29 -04004264 context->recordError(gl::Error(GL_INVALID_ENUM));
4265 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004266 }
4267
4268 switch (pname)
4269 {
4270 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4271 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4272 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4273 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4274 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4275 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4276 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4277 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4278 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4279 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4280 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4281 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4282 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4283 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4284 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4285 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4286 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4287 default: UNREACHABLE(); break;
4288 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004289 }
4290}
4291
4292void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4293{
4294 glTexParameteri(target, pname, *params);
4295}
4296
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004297void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4298{
4299 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4300 target, levels, internalformat, width, height);
4301
Geoff Langbfdea662014-07-23 14:16:32 -04004302 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004303 if (context)
4304 {
4305 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004306 {
Geoff Langb1196682014-07-23 13:47:29 -04004307 context->recordError(gl::Error(GL_INVALID_OPERATION));
4308 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004309 }
Geoff Langbfdea662014-07-23 14:16:32 -04004310
4311 if (context->getClientVersion() < 3 &&
4312 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4313 {
4314 return;
4315 }
4316
4317 if (context->getClientVersion() >= 3 &&
4318 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4319 {
4320 return;
4321 }
4322
4323 switch (target)
4324 {
4325 case GL_TEXTURE_2D:
4326 {
4327 gl::Texture2D *texture2d = context->getTexture2D();
4328 texture2d->storage(levels, internalformat, width, height);
4329 }
4330 break;
4331
4332 case GL_TEXTURE_CUBE_MAP:
4333 {
4334 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4335 textureCube->storage(levels, internalformat, width);
4336 }
4337 break;
4338
4339 default:
Geoff Langb1196682014-07-23 13:47:29 -04004340 context->recordError(gl::Error(GL_INVALID_ENUM));
4341 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004342 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004343 }
4344}
4345
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004346void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4347 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004348{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004349 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004350 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004351 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004352 target, level, xoffset, yoffset, width, height, format, type, pixels);
4353
Geoff Langbfdea662014-07-23 14:16:32 -04004354 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004355 if (context)
4356 {
4357 if (context->getClientVersion() < 3 &&
4358 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4359 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004360 {
Geoff Langbfdea662014-07-23 14:16:32 -04004361 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004362 }
Geoff Langbfdea662014-07-23 14:16:32 -04004363
4364 if (context->getClientVersion() >= 3 &&
4365 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4366 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4367 {
4368 return;
4369 }
4370
4371 // Zero sized uploads are valid but no-ops
4372 if (width == 0 || height == 0)
4373 {
4374 return;
4375 }
4376
4377 switch (target)
4378 {
4379 case GL_TEXTURE_2D:
4380 {
4381 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004382 gl::Error error = texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4383 if (error.isError())
4384 {
4385 context->recordError(error);
4386 return;
4387 }
Geoff Langbfdea662014-07-23 14:16:32 -04004388 }
4389 break;
4390
4391 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4392 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4393 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4394 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4395 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4396 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4397 {
4398 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004399 gl::Error error = texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4400 if (error.isError())
4401 {
4402 context->recordError(error);
4403 return;
4404 }
Geoff Langbfdea662014-07-23 14:16:32 -04004405 }
4406 break;
4407
4408 default:
4409 UNREACHABLE();
4410 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004411 }
4412}
4413
4414void __stdcall glUniform1f(GLint location, GLfloat x)
4415{
4416 glUniform1fv(location, 1, &x);
4417}
4418
4419void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4420{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004421 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004422
Geoff Langbfdea662014-07-23 14:16:32 -04004423 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004424 if (context)
4425 {
4426 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004427 {
Geoff Langbfdea662014-07-23 14:16:32 -04004428 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004429 }
Geoff Langbfdea662014-07-23 14:16:32 -04004430
4431 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4432 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004433 }
4434}
4435
4436void __stdcall glUniform1i(GLint location, GLint x)
4437{
4438 glUniform1iv(location, 1, &x);
4439}
4440
4441void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4442{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004443 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004444
Geoff Langbfdea662014-07-23 14:16:32 -04004445 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004446 if (context)
4447 {
4448 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004449 {
Geoff Langbfdea662014-07-23 14:16:32 -04004450 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004451 }
Geoff Langbfdea662014-07-23 14:16:32 -04004452
4453 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4454 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004455 }
4456}
4457
4458void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4459{
4460 GLfloat xy[2] = {x, y};
4461
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004462 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004463}
4464
4465void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4466{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004467 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004468
Geoff Langbfdea662014-07-23 14:16:32 -04004469 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004470 if (context)
4471 {
4472 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004473 {
Geoff Langbfdea662014-07-23 14:16:32 -04004474 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004475 }
Geoff Langbfdea662014-07-23 14:16:32 -04004476
4477 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4478 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479 }
4480}
4481
4482void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4483{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004484 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004485
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004486 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004487}
4488
4489void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4490{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004491 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004492
Geoff Langbfdea662014-07-23 14:16:32 -04004493 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004494 if (context)
4495 {
4496 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004497 {
Geoff Langbfdea662014-07-23 14:16:32 -04004498 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004499 }
Geoff Langbfdea662014-07-23 14:16:32 -04004500
4501 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4502 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004503 }
4504}
4505
4506void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4507{
4508 GLfloat xyz[3] = {x, y, z};
4509
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004510 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004511}
4512
4513void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4514{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004515 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004516
Geoff Langbfdea662014-07-23 14:16:32 -04004517 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004518 if (context)
4519 {
4520 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004521 {
Geoff Langbfdea662014-07-23 14:16:32 -04004522 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004523 }
Geoff Langbfdea662014-07-23 14:16:32 -04004524
4525 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4526 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004527 }
4528}
4529
4530void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4531{
4532 GLint xyz[3] = {x, y, z};
4533
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004534 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004535}
4536
4537void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4538{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004539 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004540
Geoff Langbfdea662014-07-23 14:16:32 -04004541 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004542 if (context)
4543 {
4544 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004545 {
Geoff Langbfdea662014-07-23 14:16:32 -04004546 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004547 }
Geoff Langbfdea662014-07-23 14:16:32 -04004548
4549 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4550 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004551 }
4552}
4553
4554void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4555{
4556 GLfloat xyzw[4] = {x, y, z, w};
4557
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004558 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004559}
4560
4561void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4562{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004563 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004564
Geoff Langbfdea662014-07-23 14:16:32 -04004565 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004566 if (context)
4567 {
4568 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004569 {
Geoff Langbfdea662014-07-23 14:16:32 -04004570 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004571 }
Geoff Langbfdea662014-07-23 14:16:32 -04004572
4573 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4574 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004575 }
4576}
4577
4578void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4579{
4580 GLint xyzw[4] = {x, y, z, w};
4581
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004582 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004583}
4584
4585void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004587 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004588
Geoff Langbfdea662014-07-23 14:16:32 -04004589 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004590 if (context)
4591 {
4592 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004593 {
Geoff Langbfdea662014-07-23 14:16:32 -04004594 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004595 }
Geoff Langbfdea662014-07-23 14:16:32 -04004596
4597 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4598 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004599 }
4600}
4601
4602void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4603{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004604 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004605 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004606
Geoff Langbfdea662014-07-23 14:16:32 -04004607 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004608 if (context)
4609 {
4610 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004611 {
Geoff Langbfdea662014-07-23 14:16:32 -04004612 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004613 }
Geoff Langbfdea662014-07-23 14:16:32 -04004614
4615 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4616 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004617 }
4618}
4619
4620void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4621{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004622 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004623 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004624
Geoff Langbfdea662014-07-23 14:16:32 -04004625 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004626 if (context)
4627 {
4628 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004629 {
Geoff Langbfdea662014-07-23 14:16:32 -04004630 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004631 }
Geoff Langbfdea662014-07-23 14:16:32 -04004632
4633 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4634 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004635 }
4636}
4637
4638void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4639{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004640 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004641 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642
Geoff Langbfdea662014-07-23 14:16:32 -04004643 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004644 if (context)
4645 {
4646 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004647 {
Geoff Langbfdea662014-07-23 14:16:32 -04004648 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004649 }
Geoff Langbfdea662014-07-23 14:16:32 -04004650
4651 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4652 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004653 }
4654}
4655
4656void __stdcall glUseProgram(GLuint program)
4657{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004658 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004659
Geoff Langbfdea662014-07-23 14:16:32 -04004660 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004661 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004662 {
Geoff Langbfdea662014-07-23 14:16:32 -04004663 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004664
Geoff Langbfdea662014-07-23 14:16:32 -04004665 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004666 {
Geoff Langbfdea662014-07-23 14:16:32 -04004667 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004668 {
Geoff Langb1196682014-07-23 13:47:29 -04004669 context->recordError(gl::Error(GL_INVALID_OPERATION));
4670 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004671 }
Geoff Langbfdea662014-07-23 14:16:32 -04004672 else
4673 {
Geoff Langb1196682014-07-23 13:47:29 -04004674 context->recordError(gl::Error(GL_INVALID_VALUE));
4675 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004676 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004677 }
Geoff Langbfdea662014-07-23 14:16:32 -04004678
4679 if (program != 0 && !programObject->isLinked())
4680 {
Geoff Langb1196682014-07-23 13:47:29 -04004681 context->recordError(gl::Error(GL_INVALID_OPERATION));
4682 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004683 }
4684
4685 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004686 }
4687}
4688
4689void __stdcall glValidateProgram(GLuint program)
4690{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004691 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004692
Geoff Langbfdea662014-07-23 14:16:32 -04004693 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004694 if (context)
4695 {
4696 gl::Program *programObject = context->getProgram(program);
4697
4698 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004699 {
Geoff Langbfdea662014-07-23 14:16:32 -04004700 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004701 {
Geoff Langb1196682014-07-23 13:47:29 -04004702 context->recordError(gl::Error(GL_INVALID_OPERATION));
4703 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004704 }
Geoff Langbfdea662014-07-23 14:16:32 -04004705 else
4706 {
Geoff Langb1196682014-07-23 13:47:29 -04004707 context->recordError(gl::Error(GL_INVALID_VALUE));
4708 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004709 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004710 }
Geoff Langbfdea662014-07-23 14:16:32 -04004711
Brandon Jones43a53e22014-08-28 16:23:22 -07004712 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004713 }
4714}
4715
4716void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4717{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004718 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004719
Geoff Langbfdea662014-07-23 14:16:32 -04004720 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004721 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004722 {
Geoff Langb1196682014-07-23 13:47:29 -04004723 if (index >= gl::MAX_VERTEX_ATTRIBS)
4724 {
4725 context->recordError(gl::Error(GL_INVALID_VALUE));
4726 return;
4727 }
4728
Geoff Langbfdea662014-07-23 14:16:32 -04004729 GLfloat vals[4] = { x, 0, 0, 1 };
4730 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004731 }
4732}
4733
4734void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4735{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004736 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004737
Geoff Langbfdea662014-07-23 14:16:32 -04004738 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004739 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004740 {
Geoff Langb1196682014-07-23 13:47:29 -04004741 if (index >= gl::MAX_VERTEX_ATTRIBS)
4742 {
4743 context->recordError(gl::Error(GL_INVALID_VALUE));
4744 return;
4745 }
4746
Geoff Langbfdea662014-07-23 14:16:32 -04004747 GLfloat vals[4] = { values[0], 0, 0, 1 };
4748 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004749 }
4750}
4751
4752void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004754 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004755
Geoff Langbfdea662014-07-23 14:16:32 -04004756 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004757 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004758 {
Geoff Langb1196682014-07-23 13:47:29 -04004759 if (index >= gl::MAX_VERTEX_ATTRIBS)
4760 {
4761 context->recordError(gl::Error(GL_INVALID_VALUE));
4762 return;
4763 }
4764
Geoff Langbfdea662014-07-23 14:16:32 -04004765 GLfloat vals[4] = { x, y, 0, 1 };
4766 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004767 }
4768}
4769
4770void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4771{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004772 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004773
Geoff Langbfdea662014-07-23 14:16:32 -04004774 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004775 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004776 {
Geoff Langb1196682014-07-23 13:47:29 -04004777 if (index >= gl::MAX_VERTEX_ATTRIBS)
4778 {
4779 context->recordError(gl::Error(GL_INVALID_VALUE));
4780 return;
4781 }
4782
Geoff Langbfdea662014-07-23 14:16:32 -04004783 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4784 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004785 }
4786}
4787
4788void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4789{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004790 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 +00004791
Geoff Langbfdea662014-07-23 14:16:32 -04004792 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004793 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004794 {
Geoff Langb1196682014-07-23 13:47:29 -04004795 if (index >= gl::MAX_VERTEX_ATTRIBS)
4796 {
4797 context->recordError(gl::Error(GL_INVALID_VALUE));
4798 return;
4799 }
4800
Geoff Langbfdea662014-07-23 14:16:32 -04004801 GLfloat vals[4] = { x, y, z, 1 };
4802 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004803 }
4804}
4805
4806void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4807{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004808 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004809
Geoff Langbfdea662014-07-23 14:16:32 -04004810 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004811 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004812 {
Geoff Langb1196682014-07-23 13:47:29 -04004813 if (index >= gl::MAX_VERTEX_ATTRIBS)
4814 {
4815 context->recordError(gl::Error(GL_INVALID_VALUE));
4816 return;
4817 }
4818
Geoff Langbfdea662014-07-23 14:16:32 -04004819 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4820 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004821 }
4822}
4823
4824void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4825{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004826 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 +00004827
Geoff Langbfdea662014-07-23 14:16:32 -04004828 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004829 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004830 {
Geoff Langb1196682014-07-23 13:47:29 -04004831 if (index >= gl::MAX_VERTEX_ATTRIBS)
4832 {
4833 context->recordError(gl::Error(GL_INVALID_VALUE));
4834 return;
4835 }
4836
Geoff Langbfdea662014-07-23 14:16:32 -04004837 GLfloat vals[4] = { x, y, z, w };
4838 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004839 }
4840}
4841
4842void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4843{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004844 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004845
Geoff Langbfdea662014-07-23 14:16:32 -04004846 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004847 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004848 {
Geoff Langb1196682014-07-23 13:47:29 -04004849 if (index >= gl::MAX_VERTEX_ATTRIBS)
4850 {
4851 context->recordError(gl::Error(GL_INVALID_VALUE));
4852 return;
4853 }
4854
Geoff Langbfdea662014-07-23 14:16:32 -04004855 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004856 }
4857}
4858
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004859void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4860{
4861 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4862
Geoff Langbfdea662014-07-23 14:16:32 -04004863 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004864 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004865 {
Geoff Langb1196682014-07-23 13:47:29 -04004866 if (index >= gl::MAX_VERTEX_ATTRIBS)
4867 {
4868 context->recordError(gl::Error(GL_INVALID_VALUE));
4869 return;
4870 }
4871
Geoff Langbfdea662014-07-23 14:16:32 -04004872 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004873 }
4874}
4875
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004876void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004877{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004878 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004879 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004880 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004881
Geoff Langbfdea662014-07-23 14:16:32 -04004882 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004883 if (context)
4884 {
Geoff Langb1196682014-07-23 13:47:29 -04004885 if (index >= gl::MAX_VERTEX_ATTRIBS)
4886 {
4887 context->recordError(gl::Error(GL_INVALID_VALUE));
4888 return;
4889 }
4890
4891 if (size < 1 || size > 4)
4892 {
4893 context->recordError(gl::Error(GL_INVALID_VALUE));
4894 return;
4895 }
4896
4897 switch (type)
4898 {
4899 case GL_BYTE:
4900 case GL_UNSIGNED_BYTE:
4901 case GL_SHORT:
4902 case GL_UNSIGNED_SHORT:
4903 case GL_FIXED:
4904 case GL_FLOAT:
4905 break;
4906
4907 case GL_HALF_FLOAT:
4908 case GL_INT:
4909 case GL_UNSIGNED_INT:
4910 case GL_INT_2_10_10_10_REV:
4911 case GL_UNSIGNED_INT_2_10_10_10_REV:
4912 if (context->getClientVersion() < 3)
4913 {
4914 context->recordError(gl::Error(GL_INVALID_ENUM));
4915 return;
4916 }
4917 break;
4918
4919 default:
4920 context->recordError(gl::Error(GL_INVALID_ENUM));
4921 return;
4922 }
4923
4924 if (stride < 0)
4925 {
4926 context->recordError(gl::Error(GL_INVALID_VALUE));
4927 return;
4928 }
4929
4930 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4931 {
4932 context->recordError(gl::Error(GL_INVALID_OPERATION));
4933 return;
4934 }
4935
Geoff Langbfdea662014-07-23 14:16:32 -04004936 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4937 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4938 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4939 // and the pointer argument is not NULL.
4940 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004941 {
Geoff Langb1196682014-07-23 13:47:29 -04004942 context->recordError(gl::Error(GL_INVALID_OPERATION));
4943 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004944 }
4945
Geoff Langbfdea662014-07-23 14:16:32 -04004946 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4947 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004948 }
4949}
4950
4951void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4952{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004953 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 +00004954
Geoff Langbfdea662014-07-23 14:16:32 -04004955 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004956 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004957 {
Geoff Langb1196682014-07-23 13:47:29 -04004958 if (width < 0 || height < 0)
4959 {
4960 context->recordError(gl::Error(GL_INVALID_VALUE));
4961 return;
4962 }
4963
Geoff Langbfdea662014-07-23 14:16:32 -04004964 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004965 }
4966}
4967
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004968// OpenGL ES 3.0 functions
4969
4970void __stdcall glReadBuffer(GLenum mode)
4971{
4972 EVENT("(GLenum mode = 0x%X)", mode);
4973
Geoff Langbfdea662014-07-23 14:16:32 -04004974 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004975 if (context)
4976 {
4977 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004978 {
Geoff Langb1196682014-07-23 13:47:29 -04004979 context->recordError(gl::Error(GL_INVALID_OPERATION));
4980 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004981 }
Geoff Langbfdea662014-07-23 14:16:32 -04004982
4983 // glReadBuffer
4984 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004985 }
4986}
4987
4988void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4989{
4990 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4991 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4992
Geoff Langbfdea662014-07-23 14:16:32 -04004993 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004994 if (context)
4995 {
4996 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004997 {
Geoff Langb1196682014-07-23 13:47:29 -04004998 context->recordError(gl::Error(GL_INVALID_OPERATION));
4999 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005000 }
Geoff Langbfdea662014-07-23 14:16:32 -04005001
5002 // glDrawRangeElements
5003 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005004 }
5005}
5006
5007void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
5008{
5009 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
5010 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
5011 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5012 target, level, internalformat, width, height, depth, border, format, type, pixels);
5013
Geoff Langbfdea662014-07-23 14:16:32 -04005014 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005015 if (context)
5016 {
5017 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005018 {
Geoff Langb1196682014-07-23 13:47:29 -04005019 context->recordError(gl::Error(GL_INVALID_OPERATION));
5020 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005021 }
Geoff Langbfdea662014-07-23 14:16:32 -04005022
5023 // validateES3TexImageFormat sets the error code if there is an error
5024 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
5025 0, 0, 0, width, height, depth, border, format, type, pixels))
5026 {
5027 return;
5028 }
5029
5030 switch(target)
5031 {
5032 case GL_TEXTURE_3D:
5033 {
5034 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005035 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5036 if (error.isError())
5037 {
5038 context->recordError(error);
5039 return;
5040 }
Geoff Langbfdea662014-07-23 14:16:32 -04005041 }
5042 break;
5043
5044 case GL_TEXTURE_2D_ARRAY:
5045 {
5046 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005047 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5048 if (error.isError())
5049 {
5050 context->recordError(error);
5051 return;
5052 }
Geoff Langbfdea662014-07-23 14:16:32 -04005053 }
5054 break;
5055
5056 default:
Geoff Langb1196682014-07-23 13:47:29 -04005057 context->recordError(gl::Error(GL_INVALID_ENUM));
5058 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005059 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005060 }
5061}
5062
5063void __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)
5064{
5065 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5066 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5067 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5068 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
5069
Geoff Langbfdea662014-07-23 14:16:32 -04005070 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005071 if (context)
5072 {
5073 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005074 {
Geoff Langb1196682014-07-23 13:47:29 -04005075 context->recordError(gl::Error(GL_INVALID_OPERATION));
5076 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005077 }
Geoff Langbfdea662014-07-23 14:16:32 -04005078
5079 // validateES3TexImageFormat sets the error code if there is an error
5080 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5081 xoffset, yoffset, zoffset, width, height, depth, 0,
5082 format, type, pixels))
5083 {
5084 return;
5085 }
5086
5087 // Zero sized uploads are valid but no-ops
5088 if (width == 0 || height == 0 || depth == 0)
5089 {
5090 return;
5091 }
5092
5093 switch(target)
5094 {
5095 case GL_TEXTURE_3D:
5096 {
5097 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005098 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5099 if (error.isError())
5100 {
5101 context->recordError(error);
5102 return;
5103 }
Geoff Langbfdea662014-07-23 14:16:32 -04005104 }
5105 break;
5106
5107 case GL_TEXTURE_2D_ARRAY:
5108 {
5109 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005110 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5111 if (error.isError())
5112 {
5113 context->recordError(error);
5114 return;
5115 }
Geoff Langbfdea662014-07-23 14:16:32 -04005116 }
5117 break;
5118
5119 default:
Geoff Langb1196682014-07-23 13:47:29 -04005120 context->recordError(gl::Error(GL_INVALID_ENUM));
5121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005122 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005123 }
5124}
5125
5126void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5127{
5128 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5129 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5130 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5131
Geoff Langbfdea662014-07-23 14:16:32 -04005132 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005133 if (context)
5134 {
5135 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005136 {
Geoff Langb1196682014-07-23 13:47:29 -04005137 context->recordError(gl::Error(GL_INVALID_OPERATION));
5138 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005139 }
Geoff Langbfdea662014-07-23 14:16:32 -04005140
5141 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5142 x, y, width, height, 0))
5143 {
5144 return;
5145 }
5146
5147 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5148 gl::Texture *texture = NULL;
5149 switch (target)
5150 {
5151 case GL_TEXTURE_3D:
5152 texture = context->getTexture3D();
5153 break;
5154
5155 case GL_TEXTURE_2D_ARRAY:
5156 texture = context->getTexture2DArray();
5157 break;
5158
5159 default:
Geoff Langb1196682014-07-23 13:47:29 -04005160 context->recordError(gl::Error(GL_INVALID_ENUM));
5161 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005162 }
5163
5164 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005165 }
5166}
5167
5168void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5169{
Geoff Langeef52cc2013-10-16 15:07:39 -04005170 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 +00005171 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5172 "const GLvoid* data = 0x%0.8p)",
5173 target, level, internalformat, width, height, depth, border, imageSize, data);
5174
Geoff Langbfdea662014-07-23 14:16:32 -04005175 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005176 if (context)
5177 {
5178 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005179 {
Geoff Langb1196682014-07-23 13:47:29 -04005180 context->recordError(gl::Error(GL_INVALID_OPERATION));
5181 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005182 }
Geoff Langbfdea662014-07-23 14:16:32 -04005183
Geoff Lang5d601382014-07-22 15:14:06 -04005184 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5185 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005186 {
Geoff Langb1196682014-07-23 13:47:29 -04005187 context->recordError(gl::Error(GL_INVALID_VALUE));
5188 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005189 }
5190
5191 // validateES3TexImageFormat sets the error code if there is an error
5192 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5193 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5194 {
5195 return;
5196 }
5197
5198 switch(target)
5199 {
5200 case GL_TEXTURE_3D:
5201 {
5202 gl::Texture3D *texture = context->getTexture3D();
Geoff Langb5348332014-09-02 13:16:34 -04005203 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5204 if (error.isError())
5205 {
5206 context->recordError(error);
5207 return;
5208 }
Geoff Langbfdea662014-07-23 14:16:32 -04005209 }
5210 break;
5211
5212 case GL_TEXTURE_2D_ARRAY:
5213 {
5214 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Langb5348332014-09-02 13:16:34 -04005215 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5216 if (error.isError())
5217 {
5218 context->recordError(error);
5219 return;
5220 }
Geoff Langbfdea662014-07-23 14:16:32 -04005221 }
5222 break;
5223
5224 default:
Geoff Langb1196682014-07-23 13:47:29 -04005225 context->recordError(gl::Error(GL_INVALID_ENUM));
5226 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005227 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005228 }
5229}
5230
5231void __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)
5232{
5233 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5234 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5235 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5236 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5237
Geoff Langbfdea662014-07-23 14:16:32 -04005238 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005239 if (context)
5240 {
5241 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005242 {
Geoff Langb1196682014-07-23 13:47:29 -04005243 context->recordError(gl::Error(GL_INVALID_OPERATION));
5244 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005245 }
Geoff Langbfdea662014-07-23 14:16:32 -04005246
Geoff Lang5d601382014-07-22 15:14:06 -04005247 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5248 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005249 {
Geoff Langb1196682014-07-23 13:47:29 -04005250 context->recordError(gl::Error(GL_INVALID_VALUE));
5251 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005252 }
5253
5254 if (!data)
5255 {
Geoff Langb1196682014-07-23 13:47:29 -04005256 context->recordError(gl::Error(GL_INVALID_VALUE));
5257 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005258 }
5259
5260 // validateES3TexImageFormat sets the error code if there is an error
5261 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5262 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5263 {
5264 return;
5265 }
5266
5267 // Zero sized uploads are valid but no-ops
5268 if (width == 0 || height == 0)
5269 {
5270 return;
5271 }
5272
5273 switch(target)
5274 {
5275 case GL_TEXTURE_3D:
5276 {
5277 gl::Texture3D *texture = context->getTexture3D();
Geoff Langb5348332014-09-02 13:16:34 -04005278 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5279 format, imageSize, data);
5280 if (error.isError())
5281 {
5282 context->recordError(error);
5283 return;
5284 }
Geoff Langbfdea662014-07-23 14:16:32 -04005285 }
5286 break;
5287
5288 case GL_TEXTURE_2D_ARRAY:
5289 {
5290 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Langb5348332014-09-02 13:16:34 -04005291 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5292 format, imageSize, data);
5293 if (error.isError())
5294 {
5295 context->recordError(error);
5296 return;
5297 }
Geoff Langbfdea662014-07-23 14:16:32 -04005298 }
5299 break;
5300
Geoff Langb1196682014-07-23 13:47:29 -04005301 default:
5302 context->recordError(gl::Error(GL_INVALID_ENUM));
5303 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005304 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005305 }
5306}
5307
5308void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5309{
5310 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5311
Geoff Langbfdea662014-07-23 14:16:32 -04005312 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005313 if (context)
5314 {
5315 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005316 {
Geoff Langb1196682014-07-23 13:47:29 -04005317 context->recordError(gl::Error(GL_INVALID_OPERATION));
5318 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005319 }
Geoff Langbfdea662014-07-23 14:16:32 -04005320
5321 if (n < 0)
5322 {
Geoff Langb1196682014-07-23 13:47:29 -04005323 context->recordError(gl::Error(GL_INVALID_VALUE));
5324 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005325 }
5326
5327 for (GLsizei i = 0; i < n; i++)
5328 {
5329 ids[i] = context->createQuery();
5330 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005331 }
5332}
5333
5334void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5335{
5336 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5337
Geoff Langbfdea662014-07-23 14:16:32 -04005338 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005339 if (context)
5340 {
5341 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005342 {
Geoff Langb1196682014-07-23 13:47:29 -04005343 context->recordError(gl::Error(GL_INVALID_OPERATION));
5344 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005345 }
Geoff Langbfdea662014-07-23 14:16:32 -04005346
5347 if (n < 0)
5348 {
Geoff Langb1196682014-07-23 13:47:29 -04005349 context->recordError(gl::Error(GL_INVALID_VALUE));
5350 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005351 }
5352
5353 for (GLsizei i = 0; i < n; i++)
5354 {
5355 context->deleteQuery(ids[i]);
5356 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005357 }
5358}
5359
5360GLboolean __stdcall glIsQuery(GLuint id)
5361{
5362 EVENT("(GLuint id = %u)", id);
5363
Geoff Langbfdea662014-07-23 14:16:32 -04005364 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005365 if (context)
5366 {
5367 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005368 {
Geoff Langb1196682014-07-23 13:47:29 -04005369 context->recordError(gl::Error(GL_INVALID_OPERATION));
5370 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005371 }
Geoff Langbfdea662014-07-23 14:16:32 -04005372
5373 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005374 }
5375
5376 return GL_FALSE;
5377}
5378
5379void __stdcall glBeginQuery(GLenum target, GLuint id)
5380{
5381 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5382
Geoff Langbfdea662014-07-23 14:16:32 -04005383 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005384 if (context)
5385 {
5386 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005387 {
Geoff Langb1196682014-07-23 13:47:29 -04005388 context->recordError(gl::Error(GL_INVALID_OPERATION));
5389 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005390 }
Geoff Langbfdea662014-07-23 14:16:32 -04005391
5392 if (!ValidateBeginQuery(context, target, id))
5393 {
5394 return;
5395 }
Geoff Lang5aad9672014-09-08 11:10:42 -04005396
5397 gl::Error error = context->beginQuery(target, id);
5398 if (error.isError())
5399 {
5400 context->recordError(error);
5401 return;
5402 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005403 }
5404}
5405
5406void __stdcall glEndQuery(GLenum target)
5407{
5408 EVENT("(GLenum target = 0x%X)", target);
5409
Geoff Langbfdea662014-07-23 14:16:32 -04005410 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005411 if (context)
5412 {
5413 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005414 {
Geoff Langb1196682014-07-23 13:47:29 -04005415 context->recordError(gl::Error(GL_INVALID_OPERATION));
5416 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005417 }
Geoff Langbfdea662014-07-23 14:16:32 -04005418
5419 if (!ValidateEndQuery(context, target))
5420 {
5421 return;
5422 }
5423
Geoff Lang5aad9672014-09-08 11:10:42 -04005424 gl::Error error = context->endQuery(target);
5425 if (error.isError())
5426 {
5427 context->recordError(error);
5428 return;
5429 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005430 }
5431}
5432
5433void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5434{
5435 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5436
Geoff Langbfdea662014-07-23 14:16:32 -04005437 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005438 if (context)
5439 {
5440 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005441 {
Geoff Langb1196682014-07-23 13:47:29 -04005442 context->recordError(gl::Error(GL_INVALID_OPERATION));
5443 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005444 }
Geoff Langbfdea662014-07-23 14:16:32 -04005445
5446 if (!ValidQueryType(context, target))
5447 {
Geoff Langb1196682014-07-23 13:47:29 -04005448 context->recordError(gl::Error(GL_INVALID_ENUM));
5449 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005450 }
5451
5452 switch (pname)
5453 {
5454 case GL_CURRENT_QUERY:
5455 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5456 break;
5457
5458 default:
Geoff Langb1196682014-07-23 13:47:29 -04005459 context->recordError(gl::Error(GL_INVALID_ENUM));
5460 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005461 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005462 }
5463}
5464
5465void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5466{
5467 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5468
Geoff Langbfdea662014-07-23 14:16:32 -04005469 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005470 if (context)
5471 {
5472 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005473 {
Geoff Langb1196682014-07-23 13:47:29 -04005474 context->recordError(gl::Error(GL_INVALID_OPERATION));
5475 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005476 }
Geoff Langbfdea662014-07-23 14:16:32 -04005477
5478 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5479
5480 if (!queryObject)
5481 {
Geoff Langb1196682014-07-23 13:47:29 -04005482 context->recordError(gl::Error(GL_INVALID_OPERATION));
5483 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005484 }
5485
5486 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5487 {
Geoff Langb1196682014-07-23 13:47:29 -04005488 context->recordError(gl::Error(GL_INVALID_OPERATION));
5489 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005490 }
5491
5492 switch(pname)
5493 {
Geoff Lang5aad9672014-09-08 11:10:42 -04005494 case GL_QUERY_RESULT_EXT:
5495 {
5496 gl::Error error = queryObject->getResult(params);
5497 if (error.isError())
5498 {
5499 context->recordError(error);
5500 return;
5501 }
5502 }
Geoff Langbfdea662014-07-23 14:16:32 -04005503 break;
Geoff Langb1196682014-07-23 13:47:29 -04005504
Geoff Lang5aad9672014-09-08 11:10:42 -04005505 case GL_QUERY_RESULT_AVAILABLE_EXT:
5506 {
5507 gl::Error error = queryObject->isResultAvailable(params);
5508 if (error.isError())
5509 {
5510 context->recordError(error);
5511 return;
5512 }
5513 }
Geoff Langbfdea662014-07-23 14:16:32 -04005514 break;
Geoff Langb1196682014-07-23 13:47:29 -04005515
Geoff Langbfdea662014-07-23 14:16:32 -04005516 default:
Geoff Langb1196682014-07-23 13:47:29 -04005517 context->recordError(gl::Error(GL_INVALID_ENUM));
5518 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005520 }
5521}
5522
5523GLboolean __stdcall glUnmapBuffer(GLenum target)
5524{
5525 EVENT("(GLenum target = 0x%X)", target);
5526
Geoff Langbfdea662014-07-23 14:16:32 -04005527 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005528 if (context)
5529 {
5530 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005531 {
Geoff Langb1196682014-07-23 13:47:29 -04005532 context->recordError(gl::Error(GL_INVALID_OPERATION));
5533 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005534 }
Geoff Langbfdea662014-07-23 14:16:32 -04005535
5536 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005537 }
5538
5539 return GL_FALSE;
5540}
5541
5542void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5543{
5544 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5545
Geoff Langbfdea662014-07-23 14:16:32 -04005546 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005547 if (context)
5548 {
5549 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005550 {
Geoff Langb1196682014-07-23 13:47:29 -04005551 context->recordError(gl::Error(GL_INVALID_OPERATION));
5552 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005553 }
Geoff Langbfdea662014-07-23 14:16:32 -04005554
5555 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005556 }
5557}
5558
5559void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5560{
Geoff Langbfdea662014-07-23 14:16:32 -04005561 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005562 if (context)
5563 {
5564 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005565 {
Geoff Langb1196682014-07-23 13:47:29 -04005566 context->recordError(gl::Error(GL_INVALID_OPERATION));
5567 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005568 }
Geoff Langbfdea662014-07-23 14:16:32 -04005569
5570 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005571 }
5572}
5573
5574void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5575{
5576 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5577 location, count, transpose, value);
5578
Geoff Langbfdea662014-07-23 14:16:32 -04005579 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005580 if (context)
5581 {
5582 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005583 {
Geoff Langbfdea662014-07-23 14:16:32 -04005584 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005585 }
Geoff Langbfdea662014-07-23 14:16:32 -04005586
5587 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5588 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005589 }
5590}
5591
5592void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5593{
5594 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5595 location, count, transpose, value);
5596
Geoff Langbfdea662014-07-23 14:16:32 -04005597 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005598 if (context)
5599 {
5600 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005601 {
Geoff Langbfdea662014-07-23 14:16:32 -04005602 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005603 }
Geoff Langbfdea662014-07-23 14:16:32 -04005604
5605 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5606 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005607 }
5608}
5609
5610void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5611{
5612 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5613 location, count, transpose, value);
5614
Geoff Langbfdea662014-07-23 14:16:32 -04005615 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005616 if (context)
5617 {
5618 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005619 {
Geoff Langbfdea662014-07-23 14:16:32 -04005620 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005621 }
Geoff Langbfdea662014-07-23 14:16:32 -04005622
5623 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5624 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005625 }
5626}
5627
5628void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5629{
5630 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5631 location, count, transpose, value);
5632
Geoff Langbfdea662014-07-23 14:16:32 -04005633 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005634 if (context)
5635 {
5636 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005637 {
Geoff Langbfdea662014-07-23 14:16:32 -04005638 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005639 }
Geoff Langbfdea662014-07-23 14:16:32 -04005640
5641 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5642 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005643 }
5644}
5645
5646void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5647{
5648 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5649 location, count, transpose, value);
5650
Geoff Langbfdea662014-07-23 14:16:32 -04005651 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005652 if (context)
5653 {
5654 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005655 {
Geoff Langbfdea662014-07-23 14:16:32 -04005656 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005657 }
Geoff Langbfdea662014-07-23 14:16:32 -04005658
5659 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5660 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005661 }
5662}
5663
5664void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5665{
5666 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5667 location, count, transpose, value);
5668
Geoff Langbfdea662014-07-23 14:16:32 -04005669 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005670 if (context)
5671 {
5672 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005673 {
Geoff Langbfdea662014-07-23 14:16:32 -04005674 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005675 }
Geoff Langbfdea662014-07-23 14:16:32 -04005676
5677 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5678 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005679 }
5680}
5681
5682void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5683{
5684 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5685 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5686 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5687
Geoff Langbfdea662014-07-23 14:16:32 -04005688 gl::Context *context = gl::getNonLostContext();
5689 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005690 {
Geoff Langbfdea662014-07-23 14:16:32 -04005691 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005692 {
Geoff Langb1196682014-07-23 13:47:29 -04005693 context->recordError(gl::Error(GL_INVALID_OPERATION));
5694 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005695 }
Geoff Langbfdea662014-07-23 14:16:32 -04005696
5697 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5698 dstX0, dstY0, dstX1, dstY1, mask, filter,
5699 false))
5700 {
5701 return;
5702 }
5703
Geoff Lang64839152014-08-26 16:23:25 -04005704 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5705 mask, filter);
5706 if (error.isError())
5707 {
5708 context->recordError(error);
5709 return;
5710 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005711 }
5712}
5713
5714void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5715{
5716 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5717 target, samples, internalformat, width, height);
5718
Geoff Langbfdea662014-07-23 14:16:32 -04005719 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005720 if (context)
5721 {
5722 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005723 {
Geoff Langb1196682014-07-23 13:47:29 -04005724 context->recordError(gl::Error(GL_INVALID_OPERATION));
5725 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005726 }
Geoff Langbfdea662014-07-23 14:16:32 -04005727
5728 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5729 width, height, false))
5730 {
5731 return;
5732 }
5733
5734 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005735 }
5736}
5737
5738void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5739{
5740 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5741 target, attachment, texture, level, layer);
5742
Geoff Langbfdea662014-07-23 14:16:32 -04005743 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005744 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005745 {
Geoff Langbfdea662014-07-23 14:16:32 -04005746 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5747 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005748 {
Geoff Langbfdea662014-07-23 14:16:32 -04005749 return;
5750 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005751
Geoff Langbfdea662014-07-23 14:16:32 -04005752 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5753 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005754
Geoff Langbfdea662014-07-23 14:16:32 -04005755 gl::Texture *textureObject = context->getTexture(texture);
5756 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005757
Geoff Langbfdea662014-07-23 14:16:32 -04005758 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5759 {
5760 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5761 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5762 }
5763 else
5764 {
5765 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005766 {
Geoff Langbfdea662014-07-23 14:16:32 -04005767 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5768 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5769 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005770 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005771 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005772 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005773}
5774
5775GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5776{
5777 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5778 target, offset, length, access);
5779
Geoff Langbfdea662014-07-23 14:16:32 -04005780 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005781 if (context)
5782 {
5783 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005784 {
Geoff Langb1196682014-07-23 13:47:29 -04005785 context->recordError(gl::Error(GL_INVALID_OPERATION));
5786 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005787 }
Geoff Langbfdea662014-07-23 14:16:32 -04005788
5789 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005790 }
5791
5792 return NULL;
5793}
5794
5795void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5796{
5797 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5798
Geoff Langbfdea662014-07-23 14:16:32 -04005799 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005800 if (context)
5801 {
5802 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005803 {
Geoff Langb1196682014-07-23 13:47:29 -04005804 context->recordError(gl::Error(GL_INVALID_OPERATION));
5805 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005806 }
Geoff Langbfdea662014-07-23 14:16:32 -04005807
5808 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005809 }
5810}
5811
5812void __stdcall glBindVertexArray(GLuint array)
5813{
5814 EVENT("(GLuint array = %u)", array);
5815
Geoff Langbfdea662014-07-23 14:16:32 -04005816 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005817 if (context)
5818 {
5819 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005820 {
Geoff Langb1196682014-07-23 13:47:29 -04005821 context->recordError(gl::Error(GL_INVALID_OPERATION));
5822 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005823 }
Geoff Langbfdea662014-07-23 14:16:32 -04005824
5825 gl::VertexArray *vao = context->getVertexArray(array);
5826
5827 if (!vao)
5828 {
5829 // The default VAO should always exist
5830 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005831 context->recordError(gl::Error(GL_INVALID_OPERATION));
5832 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005833 }
5834
5835 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005836 }
5837}
5838
5839void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5840{
5841 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5842
Geoff Langbfdea662014-07-23 14:16:32 -04005843 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005844 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005845 {
Geoff Langbfdea662014-07-23 14:16:32 -04005846 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005847 {
Geoff Langb1196682014-07-23 13:47:29 -04005848 context->recordError(gl::Error(GL_INVALID_OPERATION));
5849 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005850 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005851
Geoff Langbfdea662014-07-23 14:16:32 -04005852 if (n < 0)
5853 {
Geoff Langb1196682014-07-23 13:47:29 -04005854 context->recordError(gl::Error(GL_INVALID_VALUE));
5855 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005856 }
Jamie Madilld1028542013-07-02 11:57:04 -04005857
Geoff Langbfdea662014-07-23 14:16:32 -04005858 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5859 {
5860 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005861 {
Geoff Langbfdea662014-07-23 14:16:32 -04005862 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005863 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005864 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005865 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005866}
5867
5868void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5869{
5870 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5871
Geoff Langbfdea662014-07-23 14:16:32 -04005872 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005873 if (context)
5874 {
5875 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005876 {
Geoff Langb1196682014-07-23 13:47:29 -04005877 context->recordError(gl::Error(GL_INVALID_OPERATION));
5878 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005879 }
Geoff Langbfdea662014-07-23 14:16:32 -04005880
5881 if (n < 0)
5882 {
Geoff Langb1196682014-07-23 13:47:29 -04005883 context->recordError(gl::Error(GL_INVALID_VALUE));
5884 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005885 }
5886
5887 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5888 {
5889 arrays[arrayIndex] = context->createVertexArray();
5890 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005891 }
5892}
5893
5894GLboolean __stdcall glIsVertexArray(GLuint array)
5895{
5896 EVENT("(GLuint array = %u)", array);
5897
Geoff Langbfdea662014-07-23 14:16:32 -04005898 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005899 if (context)
5900 {
5901 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005902 {
Geoff Langb1196682014-07-23 13:47:29 -04005903 context->recordError(gl::Error(GL_INVALID_OPERATION));
5904 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005905 }
Geoff Langbfdea662014-07-23 14:16:32 -04005906
5907 if (array == 0)
5908 {
5909 return GL_FALSE;
5910 }
5911
5912 gl::VertexArray *vao = context->getVertexArray(array);
5913
5914 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005915 }
5916
5917 return GL_FALSE;
5918}
5919
5920void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5921{
5922 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5923 target, index, data);
5924
Geoff Langbfdea662014-07-23 14:16:32 -04005925 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005926 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005927 {
Geoff Langbfdea662014-07-23 14:16:32 -04005928 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005929 {
Geoff Langb1196682014-07-23 13:47:29 -04005930 context->recordError(gl::Error(GL_INVALID_OPERATION));
5931 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005932 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005933
Geoff Lang3a61c322014-07-10 13:01:54 -04005934 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005935 switch (target)
5936 {
5937 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5938 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5939 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005940 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5941 {
Geoff Langb1196682014-07-23 13:47:29 -04005942 context->recordError(gl::Error(GL_INVALID_VALUE));
5943 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005944 }
Geoff Langbfdea662014-07-23 14:16:32 -04005945 break;
Geoff Langb1196682014-07-23 13:47:29 -04005946
Geoff Langbfdea662014-07-23 14:16:32 -04005947 case GL_UNIFORM_BUFFER_START:
5948 case GL_UNIFORM_BUFFER_SIZE:
5949 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005950 if (index >= caps.maxCombinedUniformBlocks)
5951 {
Geoff Langb1196682014-07-23 13:47:29 -04005952 context->recordError(gl::Error(GL_INVALID_VALUE));
5953 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005954 }
Geoff Langbfdea662014-07-23 14:16:32 -04005955 break;
Geoff Langb1196682014-07-23 13:47:29 -04005956
Geoff Langbfdea662014-07-23 14:16:32 -04005957 default:
Geoff Langb1196682014-07-23 13:47:29 -04005958 context->recordError(gl::Error(GL_INVALID_ENUM));
5959 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005960 }
5961
5962 if (!(context->getIndexedIntegerv(target, index, data)))
5963 {
5964 GLenum nativeType;
5965 unsigned int numParams = 0;
5966 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005967 {
5968 context->recordError(gl::Error(GL_INVALID_ENUM));
5969 return;
5970 }
Shannon Woods15934d52013-08-19 14:28:49 -04005971
Geoff Langbfdea662014-07-23 14:16:32 -04005972 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005973 {
Geoff Langbfdea662014-07-23 14:16:32 -04005974 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005975 }
Geoff Langbfdea662014-07-23 14:16:32 -04005976
5977 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005978 {
Geoff Langbfdea662014-07-23 14:16:32 -04005979 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5980 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5981 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005982
Geoff Langbfdea662014-07-23 14:16:32 -04005983 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005984
Geoff Langbfdea662014-07-23 14:16:32 -04005985 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005986 {
Geoff Langbfdea662014-07-23 14:16:32 -04005987 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5988 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005989 }
Geoff Langbfdea662014-07-23 14:16:32 -04005990
5991 delete [] int64Params;
5992 }
5993 else
5994 {
5995 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005996 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005997 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005998 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005999}
6000
6001void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
6002{
6003 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
6004
Geoff Langbfdea662014-07-23 14:16:32 -04006005 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006006 if (context)
6007 {
6008 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006009 {
Geoff Langb1196682014-07-23 13:47:29 -04006010 context->recordError(gl::Error(GL_INVALID_OPERATION));
6011 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006012 }
Geoff Langbfdea662014-07-23 14:16:32 -04006013
6014 switch (primitiveMode)
6015 {
6016 case GL_TRIANGLES:
6017 case GL_LINES:
6018 case GL_POINTS:
6019 break;
Geoff Langb1196682014-07-23 13:47:29 -04006020
Geoff Langbfdea662014-07-23 14:16:32 -04006021 default:
Geoff Langb1196682014-07-23 13:47:29 -04006022 context->recordError(gl::Error(GL_INVALID_ENUM));
6023 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006024 }
6025
6026 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6027 ASSERT(transformFeedback != NULL);
6028
6029 if (transformFeedback->isStarted())
6030 {
Geoff Langb1196682014-07-23 13:47:29 -04006031 context->recordError(gl::Error(GL_INVALID_OPERATION));
6032 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006033 }
6034
6035 if (transformFeedback->isPaused())
6036 {
6037 transformFeedback->resume();
6038 }
6039 else
6040 {
6041 transformFeedback->start(primitiveMode);
6042 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006043 }
6044}
6045
6046void __stdcall glEndTransformFeedback(void)
6047{
6048 EVENT("(void)");
6049
Geoff Langbfdea662014-07-23 14:16:32 -04006050 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006051 if (context)
6052 {
6053 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006054 {
Geoff Langb1196682014-07-23 13:47:29 -04006055 context->recordError(gl::Error(GL_INVALID_OPERATION));
6056 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006057 }
Geoff Langbfdea662014-07-23 14:16:32 -04006058
6059 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6060 ASSERT(transformFeedback != NULL);
6061
6062 if (!transformFeedback->isStarted())
6063 {
Geoff Langb1196682014-07-23 13:47:29 -04006064 context->recordError(gl::Error(GL_INVALID_OPERATION));
6065 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006066 }
6067
6068 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006069 }
6070}
6071
6072void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
6073{
6074 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
6075 target, index, buffer, offset, size);
6076
Geoff Langbfdea662014-07-23 14:16:32 -04006077 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006078 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006079 {
Geoff Langbfdea662014-07-23 14:16:32 -04006080 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006081 {
Geoff Langb1196682014-07-23 13:47:29 -04006082 context->recordError(gl::Error(GL_INVALID_OPERATION));
6083 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006084 }
6085
Geoff Lang3a61c322014-07-10 13:01:54 -04006086 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006087 switch (target)
6088 {
6089 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006090 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006091 {
Geoff Langb1196682014-07-23 13:47:29 -04006092 context->recordError(gl::Error(GL_INVALID_VALUE));
6093 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006094 }
Geoff Langbfdea662014-07-23 14:16:32 -04006095 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006096
Geoff Langbfdea662014-07-23 14:16:32 -04006097 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006098 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006099 {
Geoff Langb1196682014-07-23 13:47:29 -04006100 context->recordError(gl::Error(GL_INVALID_VALUE));
6101 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006102 }
Geoff Langbfdea662014-07-23 14:16:32 -04006103 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006104
Geoff Langbfdea662014-07-23 14:16:32 -04006105 default:
Geoff Langb1196682014-07-23 13:47:29 -04006106 context->recordError(gl::Error(GL_INVALID_ENUM));
6107 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006108 }
6109
6110 if (buffer != 0 && size <= 0)
6111 {
Geoff Langb1196682014-07-23 13:47:29 -04006112 context->recordError(gl::Error(GL_INVALID_VALUE));
6113 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006114 }
6115
6116 switch (target)
6117 {
6118 case GL_TRANSFORM_FEEDBACK_BUFFER:
6119
6120 // size and offset must be a multiple of 4
6121 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006122 {
Geoff Langb1196682014-07-23 13:47:29 -04006123 context->recordError(gl::Error(GL_INVALID_VALUE));
6124 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006125 }
6126
Geoff Langbfdea662014-07-23 14:16:32 -04006127 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
6128 context->bindGenericTransformFeedbackBuffer(buffer);
6129 break;
6130
6131 case GL_UNIFORM_BUFFER:
6132
6133 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006134 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006135 {
Geoff Langb1196682014-07-23 13:47:29 -04006136 context->recordError(gl::Error(GL_INVALID_VALUE));
6137 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006138 }
Geoff Langbfdea662014-07-23 14:16:32 -04006139
6140 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6141 context->bindGenericUniformBuffer(buffer);
6142 break;
6143
6144 default:
6145 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006146 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006147 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006148}
6149
6150void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
6151{
6152 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6153 target, index, buffer);
6154
Geoff Langbfdea662014-07-23 14:16:32 -04006155 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006156 if (context)
6157 {
6158 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006159 {
Geoff Langb1196682014-07-23 13:47:29 -04006160 context->recordError(gl::Error(GL_INVALID_OPERATION));
6161 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006162 }
Geoff Langbfdea662014-07-23 14:16:32 -04006163
Geoff Lang3a61c322014-07-10 13:01:54 -04006164 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006165 switch (target)
6166 {
6167 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006168 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006169 {
Geoff Langb1196682014-07-23 13:47:29 -04006170 context->recordError(gl::Error(GL_INVALID_VALUE));
6171 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006172 }
6173 break;
6174
6175 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006176 if (index >= caps.maxUniformBufferBindings)
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 default:
Geoff Langb1196682014-07-23 13:47:29 -04006184 context->recordError(gl::Error(GL_INVALID_ENUM));
6185 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006186 }
6187
6188 switch (target)
6189 {
6190 case GL_TRANSFORM_FEEDBACK_BUFFER:
6191 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6192 context->bindGenericTransformFeedbackBuffer(buffer);
6193 break;
6194
6195 case GL_UNIFORM_BUFFER:
6196 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6197 context->bindGenericUniformBuffer(buffer);
6198 break;
6199
6200 default:
6201 UNREACHABLE();
6202 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006203 }
6204}
6205
6206void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6207{
6208 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6209 program, count, varyings, bufferMode);
6210
Geoff Langbfdea662014-07-23 14:16:32 -04006211 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006212 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006213 {
Geoff Langbfdea662014-07-23 14:16:32 -04006214 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006215 {
Geoff Langb1196682014-07-23 13:47:29 -04006216 context->recordError(gl::Error(GL_INVALID_OPERATION));
6217 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006218 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006219
Geoff Langbfdea662014-07-23 14:16:32 -04006220 if (count < 0)
6221 {
Geoff Langb1196682014-07-23 13:47:29 -04006222 context->recordError(gl::Error(GL_INVALID_VALUE));
6223 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006224 }
6225
Geoff Lang05881a02014-07-10 14:05:30 -04006226 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006227 switch (bufferMode)
6228 {
6229 case GL_INTERLEAVED_ATTRIBS:
6230 break;
6231 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006232 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006233 {
Geoff Langb1196682014-07-23 13:47:29 -04006234 context->recordError(gl::Error(GL_INVALID_VALUE));
6235 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006236 }
Geoff Langbfdea662014-07-23 14:16:32 -04006237 break;
6238 default:
Geoff Langb1196682014-07-23 13:47:29 -04006239 context->recordError(gl::Error(GL_INVALID_ENUM));
6240 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006241 }
Geoff Langbfdea662014-07-23 14:16:32 -04006242
6243 if (!gl::ValidProgram(context, program))
6244 {
6245 return;
6246 }
6247
6248 gl::Program *programObject = context->getProgram(program);
6249 ASSERT(programObject);
6250
6251 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006252 }
6253}
6254
6255void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6256{
6257 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6258 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6259 program, index, bufSize, length, size, type, name);
6260
Geoff Langbfdea662014-07-23 14:16:32 -04006261 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006262 if (context)
6263 {
6264 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006265 {
Geoff Langb1196682014-07-23 13:47:29 -04006266 context->recordError(gl::Error(GL_INVALID_OPERATION));
6267 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006268 }
Geoff Langbfdea662014-07-23 14:16:32 -04006269
6270 if (bufSize < 0)
6271 {
Geoff Langb1196682014-07-23 13:47:29 -04006272 context->recordError(gl::Error(GL_INVALID_VALUE));
6273 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006274 }
6275
6276 if (!gl::ValidProgram(context, program))
6277 {
6278 return;
6279 }
6280
6281 gl::Program *programObject = context->getProgram(program);
6282 ASSERT(programObject);
6283
6284 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6285 {
Geoff Langb1196682014-07-23 13:47:29 -04006286 context->recordError(gl::Error(GL_INVALID_VALUE));
6287 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006288 }
6289
6290 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006291 }
6292}
6293
6294void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6295{
6296 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6297 index, size, type, stride, pointer);
6298
Geoff Langbfdea662014-07-23 14:16:32 -04006299 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006300 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006301 {
Geoff Langbfdea662014-07-23 14:16:32 -04006302 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006303 {
Geoff Langb1196682014-07-23 13:47:29 -04006304 context->recordError(gl::Error(GL_INVALID_OPERATION));
6305 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006306 }
6307
Geoff Langb1196682014-07-23 13:47:29 -04006308 if (index >= gl::MAX_VERTEX_ATTRIBS)
6309 {
6310 context->recordError(gl::Error(GL_INVALID_VALUE));
6311 return;
6312 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006313
Geoff Langb1196682014-07-23 13:47:29 -04006314 if (size < 1 || size > 4)
6315 {
6316 context->recordError(gl::Error(GL_INVALID_VALUE));
6317 return;
6318 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006319
Geoff Langb1196682014-07-23 13:47:29 -04006320 switch (type)
6321 {
6322 case GL_BYTE:
6323 case GL_UNSIGNED_BYTE:
6324 case GL_SHORT:
6325 case GL_UNSIGNED_SHORT:
6326 case GL_INT:
6327 case GL_UNSIGNED_INT:
6328 case GL_INT_2_10_10_10_REV:
6329 case GL_UNSIGNED_INT_2_10_10_10_REV:
6330 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006331
Geoff Langb1196682014-07-23 13:47:29 -04006332 default:
6333 context->recordError(gl::Error(GL_INVALID_ENUM));
6334 return;
6335 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006336
Geoff Langb1196682014-07-23 13:47:29 -04006337 if (stride < 0)
6338 {
6339 context->recordError(gl::Error(GL_INVALID_VALUE));
6340 return;
6341 }
Geoff Langbfdea662014-07-23 14:16:32 -04006342
Geoff Langb1196682014-07-23 13:47:29 -04006343 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6344 {
6345 context->recordError(gl::Error(GL_INVALID_OPERATION));
6346 return;
6347 }
6348
Geoff Langbfdea662014-07-23 14:16:32 -04006349 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6350 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6351 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6352 // and the pointer argument is not NULL.
6353 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006354 {
Geoff Langb1196682014-07-23 13:47:29 -04006355 context->recordError(gl::Error(GL_INVALID_OPERATION));
6356 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006357 }
6358
Geoff Langbfdea662014-07-23 14:16:32 -04006359 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6360 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006361 }
6362}
6363
6364void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6365{
6366 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6367 index, pname, params);
6368
Geoff Langbfdea662014-07-23 14:16:32 -04006369 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006370 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006371 {
Geoff Langbfdea662014-07-23 14:16:32 -04006372 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006373 {
Geoff Langb1196682014-07-23 13:47:29 -04006374 context->recordError(gl::Error(GL_INVALID_OPERATION));
6375 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006376 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006377
Geoff Langbfdea662014-07-23 14:16:32 -04006378 if (index >= gl::MAX_VERTEX_ATTRIBS)
6379 {
Geoff Langb1196682014-07-23 13:47:29 -04006380 context->recordError(gl::Error(GL_INVALID_VALUE));
6381 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006382 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006383
Geoff Langbfdea662014-07-23 14:16:32 -04006384 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006385
Geoff Langb1196682014-07-23 13:47:29 -04006386 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006387 {
6388 return;
6389 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006390
Geoff Langbfdea662014-07-23 14:16:32 -04006391 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6392 {
6393 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6394 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006395 {
Geoff Langbfdea662014-07-23 14:16:32 -04006396 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006397 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006398 }
Geoff Langbfdea662014-07-23 14:16:32 -04006399 else
6400 {
6401 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6402 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006403 }
6404}
6405
6406void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6407{
6408 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6409 index, pname, params);
6410
Geoff Langbfdea662014-07-23 14:16:32 -04006411 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006412 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006413 {
Geoff Langbfdea662014-07-23 14:16:32 -04006414 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006415 {
Geoff Langb1196682014-07-23 13:47:29 -04006416 context->recordError(gl::Error(GL_INVALID_OPERATION));
6417 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006418 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006419
Geoff Langbfdea662014-07-23 14:16:32 -04006420 if (index >= gl::MAX_VERTEX_ATTRIBS)
6421 {
Geoff Langb1196682014-07-23 13:47:29 -04006422 context->recordError(gl::Error(GL_INVALID_VALUE));
6423 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006424 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006425
Geoff Langbfdea662014-07-23 14:16:32 -04006426 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006427
Geoff Langb1196682014-07-23 13:47:29 -04006428 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006429 {
6430 return;
6431 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006432
Geoff Langbfdea662014-07-23 14:16:32 -04006433 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6434 {
6435 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6436 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006437 {
Geoff Langbfdea662014-07-23 14:16:32 -04006438 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006439 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006440 }
Geoff Langbfdea662014-07-23 14:16:32 -04006441 else
6442 {
6443 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6444 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006445 }
6446}
6447
6448void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6449{
6450 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6451 index, x, y, z, w);
6452
Geoff Langbfdea662014-07-23 14:16:32 -04006453 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006454 if (context)
6455 {
6456 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006457 {
Geoff Langb1196682014-07-23 13:47:29 -04006458 context->recordError(gl::Error(GL_INVALID_OPERATION));
6459 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006460 }
Geoff Langbfdea662014-07-23 14:16:32 -04006461
6462 if (index >= gl::MAX_VERTEX_ATTRIBS)
6463 {
Geoff Langb1196682014-07-23 13:47:29 -04006464 context->recordError(gl::Error(GL_INVALID_VALUE));
6465 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006466 }
6467
6468 GLint vals[4] = { x, y, z, w };
6469 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006470 }
6471}
6472
6473void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6474{
6475 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6476 index, x, y, z, w);
6477
Geoff Langbfdea662014-07-23 14:16:32 -04006478 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006479 if (context)
6480 {
6481 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006482 {
Geoff Langb1196682014-07-23 13:47:29 -04006483 context->recordError(gl::Error(GL_INVALID_OPERATION));
6484 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006485 }
Geoff Langbfdea662014-07-23 14:16:32 -04006486
6487 if (index >= gl::MAX_VERTEX_ATTRIBS)
6488 {
Geoff Langb1196682014-07-23 13:47:29 -04006489 context->recordError(gl::Error(GL_INVALID_VALUE));
6490 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006491 }
6492
6493 GLuint vals[4] = { x, y, z, w };
6494 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006495 }
6496}
6497
6498void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6499{
6500 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6501
Geoff Langbfdea662014-07-23 14:16:32 -04006502 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006503 if (context)
6504 {
6505 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006506 {
Geoff Langb1196682014-07-23 13:47:29 -04006507 context->recordError(gl::Error(GL_INVALID_OPERATION));
6508 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006509 }
Geoff Langbfdea662014-07-23 14:16:32 -04006510
6511 if (index >= gl::MAX_VERTEX_ATTRIBS)
6512 {
Geoff Langb1196682014-07-23 13:47:29 -04006513 context->recordError(gl::Error(GL_INVALID_VALUE));
6514 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006515 }
6516
6517 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006518 }
6519}
6520
6521void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6522{
6523 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6524
Geoff Langbfdea662014-07-23 14:16:32 -04006525 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006526 if (context)
6527 {
6528 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006529 {
Geoff Langb1196682014-07-23 13:47:29 -04006530 context->recordError(gl::Error(GL_INVALID_OPERATION));
6531 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006532 }
Geoff Langbfdea662014-07-23 14:16:32 -04006533
6534 if (index >= gl::MAX_VERTEX_ATTRIBS)
6535 {
Geoff Langb1196682014-07-23 13:47:29 -04006536 context->recordError(gl::Error(GL_INVALID_VALUE));
6537 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006538 }
6539
6540 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006541 }
6542}
6543
6544void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6545{
6546 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6547 program, location, params);
6548
Geoff Langbfdea662014-07-23 14:16:32 -04006549 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006550 if (context)
6551 {
Jamie Madill0063c512014-08-25 15:47:53 -04006552 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006553 {
Jamie Madill0063c512014-08-25 15:47:53 -04006554 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006555 }
Geoff Langbfdea662014-07-23 14:16:32 -04006556
Jamie Madilla502c742014-08-28 17:19:13 -04006557 gl::Program *programObject = context->getProgram(program);
6558 ASSERT(programObject);
6559 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006560 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006561
Jamie Madill99a1e982014-08-25 15:47:54 -04006562 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006563 }
6564}
6565
6566GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6567{
6568 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6569 program, name);
6570
Geoff Langbfdea662014-07-23 14:16:32 -04006571 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006572 if (context)
6573 {
6574 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006575 {
Geoff Langb1196682014-07-23 13:47:29 -04006576 context->recordError(gl::Error(GL_INVALID_OPERATION));
6577 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006578 }
Geoff Langbfdea662014-07-23 14:16:32 -04006579
6580 if (program == 0)
6581 {
Geoff Langb1196682014-07-23 13:47:29 -04006582 context->recordError(gl::Error(GL_INVALID_VALUE));
6583 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006584 }
6585
6586 gl::Program *programObject = context->getProgram(program);
6587
6588 if (!programObject || !programObject->isLinked())
6589 {
Geoff Langb1196682014-07-23 13:47:29 -04006590 context->recordError(gl::Error(GL_INVALID_OPERATION));
6591 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006592 }
6593
6594 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6595 if (!programBinary)
6596 {
Geoff Langb1196682014-07-23 13:47:29 -04006597 context->recordError(gl::Error(GL_INVALID_OPERATION));
6598 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006599 }
6600
6601 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006602 }
6603
6604 return 0;
6605}
6606
6607void __stdcall glUniform1ui(GLint location, GLuint v0)
6608{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006609 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006610}
6611
6612void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6613{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006614 const GLuint xy[] = { v0, v1 };
6615 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006616}
6617
6618void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6619{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006620 const GLuint xyz[] = { v0, v1, v2 };
6621 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006622}
6623
6624void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6625{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006626 const GLuint xyzw[] = { v0, v1, v2, v3 };
6627 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006628}
6629
6630void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6631{
6632 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6633 location, count, value);
6634
Geoff Langbfdea662014-07-23 14:16:32 -04006635 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006636 if (context)
6637 {
6638 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006639 {
Geoff Langbfdea662014-07-23 14:16:32 -04006640 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006641 }
Geoff Langbfdea662014-07-23 14:16:32 -04006642
6643 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6644 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006645 }
6646}
6647
6648void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6649{
6650 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6651 location, count, value);
6652
Geoff Langbfdea662014-07-23 14:16:32 -04006653 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006654 if (context)
6655 {
6656 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006657 {
Geoff Langbfdea662014-07-23 14:16:32 -04006658 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006659 }
Geoff Langbfdea662014-07-23 14:16:32 -04006660
6661 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6662 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006663 }
6664}
6665
6666void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6667{
6668 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6669 location, count, value);
6670
Geoff Langbfdea662014-07-23 14:16:32 -04006671 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006672 if (context)
6673 {
6674 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006675 {
Geoff Langbfdea662014-07-23 14:16:32 -04006676 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006677 }
Geoff Langbfdea662014-07-23 14:16:32 -04006678
6679 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6680 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006681 }
6682}
6683
6684void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6685{
6686 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6687 location, count, value);
6688
Geoff Langbfdea662014-07-23 14:16:32 -04006689 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006690 if (context)
6691 {
6692 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006693 {
Geoff Langbfdea662014-07-23 14:16:32 -04006694 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006695 }
Geoff Langbfdea662014-07-23 14:16:32 -04006696
6697 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6698 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006699 }
6700}
6701
6702void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6703{
6704 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6705 buffer, drawbuffer, value);
6706
Geoff Langbfdea662014-07-23 14:16:32 -04006707 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006708 if (context)
6709 {
6710 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006711 {
Geoff Langbfdea662014-07-23 14:16:32 -04006712 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006713 }
Geoff Langbfdea662014-07-23 14:16:32 -04006714
6715 switch (buffer)
6716 {
6717 case GL_COLOR:
6718 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6719 {
Geoff Langb1196682014-07-23 13:47:29 -04006720 context->recordError(gl::Error(GL_INVALID_VALUE));
6721 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006722 }
6723 break;
Geoff Langb1196682014-07-23 13:47:29 -04006724
Geoff Langbfdea662014-07-23 14:16:32 -04006725 case GL_STENCIL:
6726 if (drawbuffer != 0)
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 default:
Geoff Langb1196682014-07-23 13:47:29 -04006734 context->recordError(gl::Error(GL_INVALID_ENUM));
6735 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006736 }
6737
Geoff Langcc79b8c2014-07-25 13:48:02 -04006738 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6739 if (error.isError())
6740 {
6741 context->recordError(error);
6742 return;
6743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006744 }
6745}
6746
6747void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6748{
6749 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6750 buffer, drawbuffer, value);
6751
Geoff Langbfdea662014-07-23 14:16:32 -04006752 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006753 if (context)
6754 {
6755 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006756 {
Geoff Langbfdea662014-07-23 14:16:32 -04006757 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006758 }
Geoff Langbfdea662014-07-23 14:16:32 -04006759
6760 switch (buffer)
6761 {
6762 case GL_COLOR:
6763 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6764 {
Geoff Langb1196682014-07-23 13:47:29 -04006765 context->recordError(gl::Error(GL_INVALID_VALUE));
6766 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006767 }
6768 break;
Geoff Langb1196682014-07-23 13:47:29 -04006769
Geoff Langbfdea662014-07-23 14:16:32 -04006770 default:
Geoff Langb1196682014-07-23 13:47:29 -04006771 context->recordError(gl::Error(GL_INVALID_ENUM));
6772 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006773 }
6774
Geoff Langcc79b8c2014-07-25 13:48:02 -04006775 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6776 if (error.isError())
6777 {
6778 context->recordError(error);
6779 return;
6780 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006781 }
6782}
6783
6784void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6785{
6786 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6787 buffer, drawbuffer, value);
6788
Geoff Langbfdea662014-07-23 14:16:32 -04006789 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006790 if (context)
6791 {
6792 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006793 {
Geoff Langbfdea662014-07-23 14:16:32 -04006794 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006795 }
Geoff Langbfdea662014-07-23 14:16:32 -04006796
6797 switch (buffer)
6798 {
6799 case GL_COLOR:
6800 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6801 {
Geoff Langb1196682014-07-23 13:47:29 -04006802 context->recordError(gl::Error(GL_INVALID_VALUE));
6803 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006804 }
6805 break;
Geoff Langb1196682014-07-23 13:47:29 -04006806
Geoff Langbfdea662014-07-23 14:16:32 -04006807 case GL_DEPTH:
6808 if (drawbuffer != 0)
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 default:
Geoff Langb1196682014-07-23 13:47:29 -04006816 context->recordError(gl::Error(GL_INVALID_ENUM));
6817 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006818 }
6819
Geoff Langcc79b8c2014-07-25 13:48:02 -04006820 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6821 if (error.isError())
6822 {
6823 context->recordError(error);
6824 return;
6825 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006826 }
6827}
6828
6829void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6830{
6831 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6832 buffer, drawbuffer, depth, stencil);
6833
Geoff Langbfdea662014-07-23 14:16:32 -04006834 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006835 if (context)
6836 {
6837 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006838 {
Geoff Langbfdea662014-07-23 14:16:32 -04006839 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006840 }
Geoff Langbfdea662014-07-23 14:16:32 -04006841
6842 switch (buffer)
6843 {
6844 case GL_DEPTH_STENCIL:
6845 if (drawbuffer != 0)
6846 {
Geoff Langb1196682014-07-23 13:47:29 -04006847 context->recordError(gl::Error(GL_INVALID_VALUE));
6848 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006849 }
6850 break;
Geoff Langb1196682014-07-23 13:47:29 -04006851
Geoff Langbfdea662014-07-23 14:16:32 -04006852 default:
Geoff Langb1196682014-07-23 13:47:29 -04006853 context->recordError(gl::Error(GL_INVALID_ENUM));
6854 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006855 }
6856
Geoff Langcc79b8c2014-07-25 13:48:02 -04006857 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6858 if (error.isError())
6859 {
6860 context->recordError(error);
6861 return;
6862 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006863 }
6864}
6865
6866const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6867{
6868 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6869
Geoff Langbfdea662014-07-23 14:16:32 -04006870 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006871 if (context)
6872 {
6873 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006874 {
Geoff Langb1196682014-07-23 13:47:29 -04006875 context->recordError(gl::Error(GL_INVALID_OPERATION));
6876 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006877 }
Geoff Langbfdea662014-07-23 14:16:32 -04006878
6879 if (name != GL_EXTENSIONS)
6880 {
Geoff Langb1196682014-07-23 13:47:29 -04006881 context->recordError(gl::Error(GL_INVALID_ENUM));
6882 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006883 }
6884
6885 if (index >= context->getExtensionStringCount())
6886 {
Geoff Langb1196682014-07-23 13:47:29 -04006887 context->recordError(gl::Error(GL_INVALID_VALUE));
6888 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006889 }
6890
6891 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006892 }
6893
6894 return NULL;
6895}
6896
6897void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6898{
6899 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6900 readTarget, writeTarget, readOffset, writeOffset, size);
6901
Geoff Langbfdea662014-07-23 14:16:32 -04006902 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006903 if (context)
6904 {
6905 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006906 {
Geoff Langb1196682014-07-23 13:47:29 -04006907 context->recordError(gl::Error(GL_INVALID_OPERATION));
6908 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006909 }
Geoff Langbfdea662014-07-23 14:16:32 -04006910
6911 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6912 {
Geoff Langb1196682014-07-23 13:47:29 -04006913 context->recordError(gl::Error(GL_INVALID_ENUM));
6914 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006915 }
6916
6917 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6918 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6919
6920 if (!readBuffer || !writeBuffer)
6921 {
Geoff Langb1196682014-07-23 13:47:29 -04006922 context->recordError(gl::Error(GL_INVALID_OPERATION));
6923 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006924 }
6925
Jamie Madillcfaaf722014-07-31 10:47:54 -04006926 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006927 if (readBuffer->isMapped() || writeBuffer->isMapped())
6928 {
Geoff Langb1196682014-07-23 13:47:29 -04006929 context->recordError(gl::Error(GL_INVALID_OPERATION));
6930 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006931 }
6932
6933 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6934 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6935 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6936 {
Geoff Langb1196682014-07-23 13:47:29 -04006937 context->recordError(gl::Error(GL_INVALID_VALUE));
6938 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006939 }
6940
6941 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6942 {
Geoff Langb1196682014-07-23 13:47:29 -04006943 context->recordError(gl::Error(GL_INVALID_VALUE));
6944 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006945 }
6946
Geoff Langbfdea662014-07-23 14:16:32 -04006947 // if size is zero, the copy is a successful no-op
6948 if (size > 0)
6949 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006950 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6951 if (error.isError())
6952 {
6953 context->recordError(error);
6954 return;
6955 }
Geoff Langbfdea662014-07-23 14:16:32 -04006956 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006957 }
6958}
6959
6960void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6961{
6962 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6963 program, uniformCount, uniformNames, uniformIndices);
6964
Geoff Langbfdea662014-07-23 14:16:32 -04006965 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006966 if (context)
6967 {
6968 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006969 {
Geoff Langb1196682014-07-23 13:47:29 -04006970 context->recordError(gl::Error(GL_INVALID_OPERATION));
6971 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006972 }
6973
6974 if (uniformCount < 0)
6975 {
Geoff Langb1196682014-07-23 13:47:29 -04006976 context->recordError(gl::Error(GL_INVALID_VALUE));
6977 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006978 }
6979
6980 gl::Program *programObject = context->getProgram(program);
6981
6982 if (!programObject)
6983 {
6984 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006985 {
Geoff Langb1196682014-07-23 13:47:29 -04006986 context->recordError(gl::Error(GL_INVALID_OPERATION));
6987 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006988 }
Geoff Langbfdea662014-07-23 14:16:32 -04006989 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006990 {
Geoff Langb1196682014-07-23 13:47:29 -04006991 context->recordError(gl::Error(GL_INVALID_VALUE));
6992 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006993 }
Geoff Langbfdea662014-07-23 14:16:32 -04006994 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006995
Geoff Langbfdea662014-07-23 14:16:32 -04006996 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6997 if (!programObject->isLinked() || !programBinary)
6998 {
6999 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007000 {
Geoff Langbfdea662014-07-23 14:16:32 -04007001 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007002 }
7003 }
Geoff Langbfdea662014-07-23 14:16:32 -04007004 else
7005 {
7006 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7007 {
7008 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
7009 }
7010 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007011 }
7012}
7013
7014void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
7015{
7016 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7017 program, uniformCount, uniformIndices, pname, params);
7018
Geoff Langbfdea662014-07-23 14:16:32 -04007019 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007020 if (context)
7021 {
7022 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007023 {
Geoff Langb1196682014-07-23 13:47:29 -04007024 context->recordError(gl::Error(GL_INVALID_OPERATION));
7025 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007026 }
7027
7028 if (uniformCount < 0)
7029 {
Geoff Langb1196682014-07-23 13:47:29 -04007030 context->recordError(gl::Error(GL_INVALID_VALUE));
7031 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007032 }
7033
7034 gl::Program *programObject = context->getProgram(program);
7035
7036 if (!programObject)
7037 {
7038 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007039 {
Geoff Langb1196682014-07-23 13:47:29 -04007040 context->recordError(gl::Error(GL_INVALID_OPERATION));
7041 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007042 }
Geoff Langbfdea662014-07-23 14:16:32 -04007043 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007044 {
Geoff Langb1196682014-07-23 13:47:29 -04007045 context->recordError(gl::Error(GL_INVALID_VALUE));
7046 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007047 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007048 }
Geoff Langbfdea662014-07-23 14:16:32 -04007049
7050 switch (pname)
7051 {
7052 case GL_UNIFORM_TYPE:
7053 case GL_UNIFORM_SIZE:
7054 case GL_UNIFORM_NAME_LENGTH:
7055 case GL_UNIFORM_BLOCK_INDEX:
7056 case GL_UNIFORM_OFFSET:
7057 case GL_UNIFORM_ARRAY_STRIDE:
7058 case GL_UNIFORM_MATRIX_STRIDE:
7059 case GL_UNIFORM_IS_ROW_MAJOR:
7060 break;
Geoff Langb1196682014-07-23 13:47:29 -04007061
Geoff Langbfdea662014-07-23 14:16:32 -04007062 default:
Geoff Langb1196682014-07-23 13:47:29 -04007063 context->recordError(gl::Error(GL_INVALID_ENUM));
7064 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007065 }
7066
7067 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7068
7069 if (!programBinary && uniformCount > 0)
7070 {
Geoff Langb1196682014-07-23 13:47:29 -04007071 context->recordError(gl::Error(GL_INVALID_VALUE));
7072 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007073 }
7074
7075 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7076 {
7077 const GLuint index = uniformIndices[uniformId];
7078
7079 if (index >= (GLuint)programBinary->getActiveUniformCount())
7080 {
Geoff Langb1196682014-07-23 13:47:29 -04007081 context->recordError(gl::Error(GL_INVALID_VALUE));
7082 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007083 }
7084 }
7085
7086 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7087 {
7088 const GLuint index = uniformIndices[uniformId];
7089 params[uniformId] = programBinary->getActiveUniformi(index, pname);
7090 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007091 }
7092}
7093
7094GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
7095{
7096 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
7097
Geoff Langbfdea662014-07-23 14:16:32 -04007098 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007099 if (context)
7100 {
7101 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007102 {
Geoff Langb1196682014-07-23 13:47:29 -04007103 context->recordError(gl::Error(GL_INVALID_OPERATION));
7104 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04007105 }
7106
7107 gl::Program *programObject = context->getProgram(program);
7108
7109 if (!programObject)
7110 {
7111 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007112 {
Geoff Langb1196682014-07-23 13:47:29 -04007113 context->recordError(gl::Error(GL_INVALID_OPERATION));
7114 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007115 }
Geoff Langbfdea662014-07-23 14:16:32 -04007116 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007117 {
Geoff Langb1196682014-07-23 13:47:29 -04007118 context->recordError(gl::Error(GL_INVALID_VALUE));
7119 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007120 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007121 }
Geoff Langbfdea662014-07-23 14:16:32 -04007122
7123 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7124 if (!programBinary)
7125 {
7126 return GL_INVALID_INDEX;
7127 }
7128
7129 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007130 }
7131
7132 return 0;
7133}
7134
7135void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
7136{
7137 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7138 program, uniformBlockIndex, pname, params);
7139
Geoff Langbfdea662014-07-23 14:16:32 -04007140 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007141 if (context)
7142 {
7143 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007144 {
Geoff Langb1196682014-07-23 13:47:29 -04007145 context->recordError(gl::Error(GL_INVALID_OPERATION));
7146 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007147 }
7148 gl::Program *programObject = context->getProgram(program);
7149
7150 if (!programObject)
7151 {
7152 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007153 {
Geoff Langb1196682014-07-23 13:47:29 -04007154 context->recordError(gl::Error(GL_INVALID_OPERATION));
7155 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007156 }
Geoff Langbfdea662014-07-23 14:16:32 -04007157 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007158 {
Geoff Langb1196682014-07-23 13:47:29 -04007159 context->recordError(gl::Error(GL_INVALID_VALUE));
7160 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007161 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007162 }
Geoff Langbfdea662014-07-23 14:16:32 -04007163
7164 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7165
7166 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7167 {
Geoff Langb1196682014-07-23 13:47:29 -04007168 context->recordError(gl::Error(GL_INVALID_VALUE));
7169 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007170 }
7171
7172 switch (pname)
7173 {
7174 case GL_UNIFORM_BLOCK_BINDING:
7175 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7176 break;
7177
7178 case GL_UNIFORM_BLOCK_DATA_SIZE:
7179 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7180 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7181 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7182 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7183 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7184 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7185 break;
7186
7187 default:
Geoff Langb1196682014-07-23 13:47:29 -04007188 context->recordError(gl::Error(GL_INVALID_ENUM));
7189 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007190 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007191 }
7192}
7193
7194void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7195{
7196 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7197 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7198
Geoff Langbfdea662014-07-23 14:16:32 -04007199 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007200 if (context)
7201 {
7202 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007203 {
Geoff Langb1196682014-07-23 13:47:29 -04007204 context->recordError(gl::Error(GL_INVALID_OPERATION));
7205 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007206 }
7207
7208 gl::Program *programObject = context->getProgram(program);
7209
7210 if (!programObject)
7211 {
7212 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007213 {
Geoff Langb1196682014-07-23 13:47:29 -04007214 context->recordError(gl::Error(GL_INVALID_OPERATION));
7215 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007216 }
Geoff Langbfdea662014-07-23 14:16:32 -04007217 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007218 {
Geoff Langb1196682014-07-23 13:47:29 -04007219 context->recordError(gl::Error(GL_INVALID_VALUE));
7220 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007221 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007222 }
Geoff Langbfdea662014-07-23 14:16:32 -04007223
7224 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7225
7226 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7227 {
Geoff Langb1196682014-07-23 13:47:29 -04007228 context->recordError(gl::Error(GL_INVALID_VALUE));
7229 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007230 }
7231
7232 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007233 }
7234}
7235
7236void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7237{
7238 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7239 program, uniformBlockIndex, uniformBlockBinding);
7240
Geoff Langbfdea662014-07-23 14:16:32 -04007241 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007242 if (context)
7243 {
7244 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007245 {
Geoff Langb1196682014-07-23 13:47:29 -04007246 context->recordError(gl::Error(GL_INVALID_OPERATION));
7247 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007248 }
7249
Geoff Lang3a61c322014-07-10 13:01:54 -04007250 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007251 {
Geoff Langb1196682014-07-23 13:47:29 -04007252 context->recordError(gl::Error(GL_INVALID_VALUE));
7253 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007254 }
7255
7256 gl::Program *programObject = context->getProgram(program);
7257
7258 if (!programObject)
7259 {
7260 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007261 {
Geoff Langb1196682014-07-23 13:47:29 -04007262 context->recordError(gl::Error(GL_INVALID_OPERATION));
7263 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007264 }
Geoff Langbfdea662014-07-23 14:16:32 -04007265 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007266 {
Geoff Langb1196682014-07-23 13:47:29 -04007267 context->recordError(gl::Error(GL_INVALID_VALUE));
7268 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007269 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007270 }
Geoff Langbfdea662014-07-23 14:16:32 -04007271
7272 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7273
7274 // if never linked, there won't be any uniform blocks
7275 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7276 {
Geoff Langb1196682014-07-23 13:47:29 -04007277 context->recordError(gl::Error(GL_INVALID_VALUE));
7278 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007279 }
7280
7281 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007282 }
7283}
7284
7285void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7286{
7287 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7288 mode, first, count, instanceCount);
7289
Geoff Langbfdea662014-07-23 14:16:32 -04007290 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007291 if (context)
7292 {
7293 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007294 {
Geoff Langb1196682014-07-23 13:47:29 -04007295 context->recordError(gl::Error(GL_INVALID_OPERATION));
7296 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007297 }
Geoff Langbfdea662014-07-23 14:16:32 -04007298
7299 // glDrawArraysInstanced
7300 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007301 }
7302}
7303
7304void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7305{
7306 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7307 mode, count, type, indices, instanceCount);
7308
Geoff Langbfdea662014-07-23 14:16:32 -04007309 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007310 if (context)
7311 {
7312 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007313 {
Geoff Langb1196682014-07-23 13:47:29 -04007314 context->recordError(gl::Error(GL_INVALID_OPERATION));
7315 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007316 }
Geoff Langbfdea662014-07-23 14:16:32 -04007317
7318 // glDrawElementsInstanced
7319 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007320 }
7321}
7322
7323GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7324{
7325 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7326
Geoff Langbfdea662014-07-23 14:16:32 -04007327 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007328 if (context)
7329 {
7330 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007331 {
Geoff Langb1196682014-07-23 13:47:29 -04007332 context->recordError(gl::Error(GL_INVALID_OPERATION));
7333 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007334 }
Geoff Langbfdea662014-07-23 14:16:32 -04007335
7336 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7337 {
Geoff Langb1196682014-07-23 13:47:29 -04007338 context->recordError(gl::Error(GL_INVALID_ENUM));
7339 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007340 }
7341
7342 if (flags != 0)
7343 {
Geoff Langb1196682014-07-23 13:47:29 -04007344 context->recordError(gl::Error(GL_INVALID_VALUE));
7345 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007346 }
7347
7348 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007349 }
7350
7351 return NULL;
7352}
7353
7354GLboolean __stdcall glIsSync(GLsync sync)
7355{
7356 EVENT("(GLsync sync = 0x%0.8p)", sync);
7357
Geoff Langbfdea662014-07-23 14:16:32 -04007358 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007359 if (context)
7360 {
7361 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007362 {
Geoff Langb1196682014-07-23 13:47:29 -04007363 context->recordError(gl::Error(GL_INVALID_OPERATION));
7364 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007365 }
Geoff Langbfdea662014-07-23 14:16:32 -04007366
7367 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007368 }
7369
7370 return GL_FALSE;
7371}
7372
7373void __stdcall glDeleteSync(GLsync sync)
7374{
7375 EVENT("(GLsync sync = 0x%0.8p)", sync);
7376
Geoff Langbfdea662014-07-23 14:16:32 -04007377 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007378 if (context)
7379 {
7380 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007381 {
Geoff Langb1196682014-07-23 13:47:29 -04007382 context->recordError(gl::Error(GL_INVALID_OPERATION));
7383 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007384 }
Geoff Langbfdea662014-07-23 14:16:32 -04007385
7386 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7387 {
Geoff Langb1196682014-07-23 13:47:29 -04007388 context->recordError(gl::Error(GL_INVALID_VALUE));
7389 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007390 }
7391
7392 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007393 }
7394}
7395
7396GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7397{
7398 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7399 sync, flags, timeout);
7400
Geoff Langbfdea662014-07-23 14:16:32 -04007401 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007402 if (context)
7403 {
7404 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007405 {
Geoff Langb1196682014-07-23 13:47:29 -04007406 context->recordError(gl::Error(GL_INVALID_OPERATION));
7407 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007408 }
Geoff Langbfdea662014-07-23 14:16:32 -04007409
7410 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7411 {
Geoff Langb1196682014-07-23 13:47:29 -04007412 context->recordError(gl::Error(GL_INVALID_VALUE));
7413 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007414 }
7415
7416 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7417
7418 if (!fenceSync)
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 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007425 }
7426
7427 return GL_FALSE;
7428}
7429
7430void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7431{
7432 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7433 sync, flags, timeout);
7434
Geoff Langbfdea662014-07-23 14:16:32 -04007435 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007436 if (context)
7437 {
7438 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007439 {
Geoff Langb1196682014-07-23 13:47:29 -04007440 context->recordError(gl::Error(GL_INVALID_OPERATION));
7441 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007442 }
Geoff Langbfdea662014-07-23 14:16:32 -04007443
7444 if (flags != 0)
7445 {
Geoff Langb1196682014-07-23 13:47:29 -04007446 context->recordError(gl::Error(GL_INVALID_VALUE));
7447 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007448 }
7449
7450 if (timeout != GL_TIMEOUT_IGNORED)
7451 {
Geoff Langb1196682014-07-23 13:47:29 -04007452 context->recordError(gl::Error(GL_INVALID_VALUE));
7453 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007454 }
7455
7456 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7457
7458 if (!fenceSync)
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 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007465 }
7466}
7467
7468void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7469{
7470 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7471 pname, params);
7472
Geoff Langbfdea662014-07-23 14:16:32 -04007473 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007474 if (context)
7475 {
7476 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007477 {
Geoff Langb1196682014-07-23 13:47:29 -04007478 context->recordError(gl::Error(GL_INVALID_OPERATION));
7479 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007480 }
Geoff Langbfdea662014-07-23 14:16:32 -04007481
7482 GLenum nativeType;
7483 unsigned int numParams = 0;
7484 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7485 {
7486 return;
7487 }
7488
7489 if (nativeType == GL_INT_64_ANGLEX)
7490 {
7491 context->getInteger64v(pname, params);
7492 }
7493 else
7494 {
7495 CastStateValues(context, nativeType, pname, numParams, params);
7496 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007497 }
7498}
7499
7500void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7501{
7502 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7503 sync, pname, bufSize, length, values);
7504
Geoff Langbfdea662014-07-23 14:16:32 -04007505 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007506 if (context)
7507 {
7508 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007509 {
Geoff Langb1196682014-07-23 13:47:29 -04007510 context->recordError(gl::Error(GL_INVALID_OPERATION));
7511 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007512 }
Geoff Langbfdea662014-07-23 14:16:32 -04007513
7514 if (bufSize < 0)
7515 {
Geoff Langb1196682014-07-23 13:47:29 -04007516 context->recordError(gl::Error(GL_INVALID_VALUE));
7517 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007518 }
7519
7520 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7521
7522 if (!fenceSync)
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 switch (pname)
7529 {
7530 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7531 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7532 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7533 case GL_SYNC_FLAGS: values[0] = 0; break;
7534
7535 default:
Geoff Langb1196682014-07-23 13:47:29 -04007536 context->recordError(gl::Error(GL_INVALID_ENUM));
7537 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007538 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007539 }
7540}
7541
7542void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7543{
7544 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7545 target, index, data);
7546
Geoff Langbfdea662014-07-23 14:16:32 -04007547 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007548 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007549 {
Geoff Langbfdea662014-07-23 14:16:32 -04007550 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007551 {
Geoff Langb1196682014-07-23 13:47:29 -04007552 context->recordError(gl::Error(GL_INVALID_OPERATION));
7553 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007554 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007555
Geoff Lang3a61c322014-07-10 13:01:54 -04007556 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007557 switch (target)
7558 {
7559 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7560 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7561 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007562 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7563 {
Geoff Langb1196682014-07-23 13:47:29 -04007564 context->recordError(gl::Error(GL_INVALID_VALUE));
7565 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007566 }
Geoff Langbfdea662014-07-23 14:16:32 -04007567 break;
Geoff Langb1196682014-07-23 13:47:29 -04007568
Geoff Langbfdea662014-07-23 14:16:32 -04007569 case GL_UNIFORM_BUFFER_START:
7570 case GL_UNIFORM_BUFFER_SIZE:
7571 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007572 if (index >= caps.maxUniformBufferBindings)
7573 {
Geoff Langb1196682014-07-23 13:47:29 -04007574 context->recordError(gl::Error(GL_INVALID_VALUE));
7575 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007576 }
Geoff Langbfdea662014-07-23 14:16:32 -04007577 break;
Geoff Langb1196682014-07-23 13:47:29 -04007578
Geoff Langbfdea662014-07-23 14:16:32 -04007579 default:
Geoff Langb1196682014-07-23 13:47:29 -04007580 context->recordError(gl::Error(GL_INVALID_ENUM));
7581 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007582 }
7583
7584 if (!(context->getIndexedInteger64v(target, index, data)))
7585 {
7586 GLenum nativeType;
7587 unsigned int numParams = 0;
7588 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007589 {
7590 context->recordError(gl::Error(GL_INVALID_ENUM));
7591 return;
7592 }
Shannon Woods15934d52013-08-19 14:28:49 -04007593
Geoff Langbfdea662014-07-23 14:16:32 -04007594 if (numParams == 0)
7595 return; // it is known that pname is valid, but there are no parameters to return
7596
7597 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007598 {
Geoff Langbfdea662014-07-23 14:16:32 -04007599 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007600
Geoff Langbfdea662014-07-23 14:16:32 -04007601 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007602
Geoff Langbfdea662014-07-23 14:16:32 -04007603 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007604 {
Geoff Langbfdea662014-07-23 14:16:32 -04007605 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007606 }
Geoff Langbfdea662014-07-23 14:16:32 -04007607
7608 delete [] intParams;
7609 }
7610 else
7611 {
7612 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007613 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007615 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007616}
7617
7618void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7619{
7620 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7621 target, pname, params);
7622
Geoff Langbfdea662014-07-23 14:16:32 -04007623 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007624 if (context)
7625 {
7626 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007627 {
Geoff Langb1196682014-07-23 13:47:29 -04007628 context->recordError(gl::Error(GL_INVALID_OPERATION));
7629 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007630 }
Geoff Langbfdea662014-07-23 14:16:32 -04007631
7632 if (!gl::ValidBufferTarget(context, target))
7633 {
Geoff Langb1196682014-07-23 13:47:29 -04007634 context->recordError(gl::Error(GL_INVALID_ENUM));
7635 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007636 }
7637
7638 if (!gl::ValidBufferParameter(context, pname))
7639 {
Geoff Langb1196682014-07-23 13:47:29 -04007640 context->recordError(gl::Error(GL_INVALID_ENUM));
7641 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007642 }
7643
7644 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7645
7646 if (!buffer)
7647 {
7648 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007649 context->recordError(gl::Error(GL_INVALID_OPERATION));
7650 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007651 }
7652
7653 switch (pname)
7654 {
7655 case GL_BUFFER_USAGE:
7656 *params = static_cast<GLint64>(buffer->getUsage());
7657 break;
7658 case GL_BUFFER_SIZE:
7659 *params = buffer->getSize();
7660 break;
7661 case GL_BUFFER_ACCESS_FLAGS:
7662 *params = static_cast<GLint64>(buffer->getAccessFlags());
7663 break;
7664 case GL_BUFFER_MAPPED:
7665 *params = static_cast<GLint64>(buffer->isMapped());
7666 break;
7667 case GL_BUFFER_MAP_OFFSET:
7668 *params = buffer->getMapOffset();
7669 break;
7670 case GL_BUFFER_MAP_LENGTH:
7671 *params = buffer->getMapLength();
7672 break;
7673 default: UNREACHABLE(); break;
7674 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007675 }
7676}
7677
7678void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7679{
7680 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7681
Geoff Langbfdea662014-07-23 14:16:32 -04007682 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007683 if (context)
7684 {
7685 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007686 {
Geoff Langb1196682014-07-23 13:47:29 -04007687 context->recordError(gl::Error(GL_INVALID_OPERATION));
7688 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007689 }
Geoff Langbfdea662014-07-23 14:16:32 -04007690
7691 if (count < 0)
7692 {
Geoff Langb1196682014-07-23 13:47:29 -04007693 context->recordError(gl::Error(GL_INVALID_VALUE));
7694 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007695 }
7696
7697 for (int i = 0; i < count; i++)
7698 {
7699 samplers[i] = context->createSampler();
7700 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007701 }
7702}
7703
7704void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7705{
7706 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7707
Geoff Langbfdea662014-07-23 14:16:32 -04007708 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007709 if (context)
7710 {
7711 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007712 {
Geoff Langb1196682014-07-23 13:47:29 -04007713 context->recordError(gl::Error(GL_INVALID_OPERATION));
7714 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007715 }
Geoff Langbfdea662014-07-23 14:16:32 -04007716
7717 if (count < 0)
7718 {
Geoff Langb1196682014-07-23 13:47:29 -04007719 context->recordError(gl::Error(GL_INVALID_VALUE));
7720 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007721 }
7722
7723 for (int i = 0; i < count; i++)
7724 {
7725 context->deleteSampler(samplers[i]);
7726 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007727 }
7728}
7729
7730GLboolean __stdcall glIsSampler(GLuint sampler)
7731{
7732 EVENT("(GLuint sampler = %u)", sampler);
7733
Geoff Langbfdea662014-07-23 14:16:32 -04007734 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007735 if (context)
7736 {
7737 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007738 {
Geoff Langb1196682014-07-23 13:47:29 -04007739 context->recordError(gl::Error(GL_INVALID_OPERATION));
7740 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007741 }
Geoff Langbfdea662014-07-23 14:16:32 -04007742
7743 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007744 }
7745
7746 return GL_FALSE;
7747}
7748
7749void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7750{
7751 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7752
Geoff Langbfdea662014-07-23 14:16:32 -04007753 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007754 if (context)
7755 {
7756 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007757 {
Geoff Langb1196682014-07-23 13:47:29 -04007758 context->recordError(gl::Error(GL_INVALID_OPERATION));
7759 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007760 }
Geoff Langbfdea662014-07-23 14:16:32 -04007761
7762 if (sampler != 0 && !context->isSampler(sampler))
7763 {
Geoff Langb1196682014-07-23 13:47:29 -04007764 context->recordError(gl::Error(GL_INVALID_OPERATION));
7765 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007766 }
7767
Geoff Lang3a61c322014-07-10 13:01:54 -04007768 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007769 {
Geoff Langb1196682014-07-23 13:47:29 -04007770 context->recordError(gl::Error(GL_INVALID_VALUE));
7771 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007772 }
7773
7774 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007775 }
7776}
7777
7778void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7779{
7780 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7781
Geoff Langbfdea662014-07-23 14:16:32 -04007782 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007783 if (context)
7784 {
7785 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007786 {
Geoff Langb1196682014-07-23 13:47:29 -04007787 context->recordError(gl::Error(GL_INVALID_OPERATION));
7788 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007789 }
Geoff Langbfdea662014-07-23 14:16:32 -04007790
Geoff Langb1196682014-07-23 13:47:29 -04007791 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007792 {
7793 return;
7794 }
7795
7796 if (!gl::ValidateTexParamParameters(context, pname, param))
7797 {
7798 return;
7799 }
7800
7801 if (!context->isSampler(sampler))
7802 {
Geoff Langb1196682014-07-23 13:47:29 -04007803 context->recordError(gl::Error(GL_INVALID_OPERATION));
7804 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007805 }
7806
7807 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007808 }
7809}
7810
7811void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7812{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007813 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007814}
7815
7816void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7817{
7818 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7819
Geoff Langbfdea662014-07-23 14:16:32 -04007820 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007821 if (context)
7822 {
7823 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007824 {
Geoff Langb1196682014-07-23 13:47:29 -04007825 context->recordError(gl::Error(GL_INVALID_OPERATION));
7826 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007827 }
Geoff Langbfdea662014-07-23 14:16:32 -04007828
Geoff Langb1196682014-07-23 13:47:29 -04007829 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007830 {
7831 return;
7832 }
7833
7834 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7835 {
7836 return;
7837 }
7838
7839 if (!context->isSampler(sampler))
7840 {
Geoff Langb1196682014-07-23 13:47:29 -04007841 context->recordError(gl::Error(GL_INVALID_OPERATION));
7842 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007843 }
7844
7845 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007846 }
7847}
7848
7849void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7850{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007851 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007852}
7853
7854void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7855{
7856 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7857
Geoff Langbfdea662014-07-23 14:16:32 -04007858 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007859 if (context)
7860 {
7861 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007862 {
Geoff Langb1196682014-07-23 13:47:29 -04007863 context->recordError(gl::Error(GL_INVALID_OPERATION));
7864 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007865 }
Geoff Langbfdea662014-07-23 14:16:32 -04007866
Geoff Langb1196682014-07-23 13:47:29 -04007867 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007868 {
7869 return;
7870 }
7871
7872 if (!context->isSampler(sampler))
7873 {
Geoff Langb1196682014-07-23 13:47:29 -04007874 context->recordError(gl::Error(GL_INVALID_OPERATION));
7875 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007876 }
7877
7878 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007879 }
7880}
7881
7882void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7883{
7884 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7885
Geoff Langbfdea662014-07-23 14:16:32 -04007886 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007887 if (context)
7888 {
7889 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007890 {
Geoff Langb1196682014-07-23 13:47:29 -04007891 context->recordError(gl::Error(GL_INVALID_OPERATION));
7892 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007893 }
Geoff Langbfdea662014-07-23 14:16:32 -04007894
Geoff Langb1196682014-07-23 13:47:29 -04007895 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007896 {
7897 return;
7898 }
7899
7900 if (!context->isSampler(sampler))
7901 {
Geoff Langb1196682014-07-23 13:47:29 -04007902 context->recordError(gl::Error(GL_INVALID_OPERATION));
7903 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007904 }
7905
7906 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007907 }
7908}
7909
7910void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7911{
7912 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7913
Geoff Langbfdea662014-07-23 14:16:32 -04007914 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007915 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007916 {
Geoff Langbfdea662014-07-23 14:16:32 -04007917 if (context->getClientVersion() < 3)
7918 {
Geoff Langb1196682014-07-23 13:47:29 -04007919 context->recordError(gl::Error(GL_INVALID_OPERATION));
7920 return;
7921 }
7922
7923 if (index >= gl::MAX_VERTEX_ATTRIBS)
7924 {
7925 context->recordError(gl::Error(GL_INVALID_VALUE));
7926 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007927 }
7928
7929 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007930 }
7931}
7932
7933void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7934{
7935 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7936
Geoff Langbfdea662014-07-23 14:16:32 -04007937 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007938 if (context)
7939 {
7940 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007941 {
Geoff Langb1196682014-07-23 13:47:29 -04007942 context->recordError(gl::Error(GL_INVALID_OPERATION));
7943 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007944 }
Geoff Langbfdea662014-07-23 14:16:32 -04007945
7946 switch (target)
7947 {
7948 case GL_TRANSFORM_FEEDBACK:
7949 {
7950 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7951 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7952 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7953 {
Geoff Langb1196682014-07-23 13:47:29 -04007954 context->recordError(gl::Error(GL_INVALID_OPERATION));
7955 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007956 }
7957
7958 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7959 if (context->getTransformFeedback(id) == NULL)
7960 {
Geoff Langb1196682014-07-23 13:47:29 -04007961 context->recordError(gl::Error(GL_INVALID_OPERATION));
7962 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007963 }
7964
7965 context->bindTransformFeedback(id);
7966 }
7967 break;
7968
7969 default:
Geoff Langb1196682014-07-23 13:47:29 -04007970 context->recordError(gl::Error(GL_INVALID_ENUM));
7971 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007972 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007973 }
7974}
7975
7976void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7977{
7978 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7979
Geoff Langbfdea662014-07-23 14:16:32 -04007980 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007981 if (context)
7982 {
7983 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007984 {
Geoff Langb1196682014-07-23 13:47:29 -04007985 context->recordError(gl::Error(GL_INVALID_OPERATION));
7986 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007987 }
Geoff Langbfdea662014-07-23 14:16:32 -04007988
7989 for (int i = 0; i < n; i++)
7990 {
7991 context->deleteTransformFeedback(ids[i]);
7992 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007993 }
7994}
7995
7996void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7997{
7998 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7999
Geoff Langbfdea662014-07-23 14:16:32 -04008000 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008001 if (context)
8002 {
8003 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008004 {
Geoff Langb1196682014-07-23 13:47:29 -04008005 context->recordError(gl::Error(GL_INVALID_OPERATION));
8006 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008007 }
Geoff Langbfdea662014-07-23 14:16:32 -04008008
8009 for (int i = 0; i < n; i++)
8010 {
8011 ids[i] = context->createTransformFeedback();
8012 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008013 }
8014}
8015
8016GLboolean __stdcall glIsTransformFeedback(GLuint id)
8017{
8018 EVENT("(GLuint id = %u)", id);
8019
Geoff Langbfdea662014-07-23 14:16:32 -04008020 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008021 if (context)
8022 {
8023 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008024 {
Geoff Langb1196682014-07-23 13:47:29 -04008025 context->recordError(gl::Error(GL_INVALID_OPERATION));
8026 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008027 }
Geoff Langbfdea662014-07-23 14:16:32 -04008028
8029 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008030 }
8031
8032 return GL_FALSE;
8033}
8034
8035void __stdcall glPauseTransformFeedback(void)
8036{
8037 EVENT("(void)");
8038
Geoff Langbfdea662014-07-23 14:16:32 -04008039 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008040 if (context)
8041 {
8042 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008043 {
Geoff Langb1196682014-07-23 13:47:29 -04008044 context->recordError(gl::Error(GL_INVALID_OPERATION));
8045 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008046 }
Geoff Langbfdea662014-07-23 14:16:32 -04008047
8048 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8049 ASSERT(transformFeedback != NULL);
8050
8051 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
8052 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
8053 {
Geoff Langb1196682014-07-23 13:47:29 -04008054 context->recordError(gl::Error(GL_INVALID_OPERATION));
8055 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008056 }
8057
8058 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008059 }
8060}
8061
8062void __stdcall glResumeTransformFeedback(void)
8063{
8064 EVENT("(void)");
8065
Geoff Langbfdea662014-07-23 14:16:32 -04008066 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008067 if (context)
8068 {
8069 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008070 {
Geoff Langb1196682014-07-23 13:47:29 -04008071 context->recordError(gl::Error(GL_INVALID_OPERATION));
8072 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008073 }
Geoff Langbfdea662014-07-23 14:16:32 -04008074
8075 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8076 ASSERT(transformFeedback != NULL);
8077
8078 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
8079 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
8080 {
Geoff Langb1196682014-07-23 13:47:29 -04008081 context->recordError(gl::Error(GL_INVALID_OPERATION));
8082 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008083 }
8084
8085 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008086 }
8087}
8088
8089void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
8090{
8091 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
8092 program, bufSize, length, binaryFormat, binary);
8093
Geoff Langbfdea662014-07-23 14:16:32 -04008094 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008095 if (context)
8096 {
8097 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008098 {
Geoff Langb1196682014-07-23 13:47:29 -04008099 context->recordError(gl::Error(GL_INVALID_OPERATION));
8100 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008101 }
Geoff Langbfdea662014-07-23 14:16:32 -04008102
8103 // glGetProgramBinary
8104 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008105 }
8106}
8107
8108void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
8109{
8110 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
8111 program, binaryFormat, binary, length);
8112
Geoff Langbfdea662014-07-23 14:16:32 -04008113 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008114 if (context)
8115 {
8116 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008117 {
Geoff Langb1196682014-07-23 13:47:29 -04008118 context->recordError(gl::Error(GL_INVALID_OPERATION));
8119 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008120 }
Geoff Langbfdea662014-07-23 14:16:32 -04008121
8122 // glProgramBinary
8123 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008124 }
8125}
8126
8127void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
8128{
8129 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
8130 program, pname, value);
8131
Geoff Langbfdea662014-07-23 14:16:32 -04008132 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008133 if (context)
8134 {
8135 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008136 {
Geoff Langb1196682014-07-23 13:47:29 -04008137 context->recordError(gl::Error(GL_INVALID_OPERATION));
8138 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008139 }
Geoff Langbfdea662014-07-23 14:16:32 -04008140
8141 // glProgramParameteri
8142 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008143 }
8144}
8145
8146void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
8147{
8148 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8149 target, numAttachments, attachments);
8150
Geoff Langbfdea662014-07-23 14:16:32 -04008151 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008152 if (context)
8153 {
8154 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008155 {
Geoff Langb1196682014-07-23 13:47:29 -04008156 context->recordError(gl::Error(GL_INVALID_OPERATION));
8157 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008158 }
Geoff Langbfdea662014-07-23 14:16:32 -04008159
8160 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8161 {
8162 return;
8163 }
8164
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008165 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8166 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8167 {
8168 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8169 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008170 }
8171}
8172
8173void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
8174{
8175 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8176 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8177 target, numAttachments, attachments, x, y, width, height);
8178
Geoff Langbfdea662014-07-23 14:16:32 -04008179 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008180 if (context)
8181 {
8182 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008183 {
Geoff Langb1196682014-07-23 13:47:29 -04008184 context->recordError(gl::Error(GL_INVALID_OPERATION));
8185 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008186 }
Geoff Langbfdea662014-07-23 14:16:32 -04008187
8188 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8189 {
8190 return;
8191 }
8192
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008193 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8194 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8195 {
8196 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8197 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008198 }
8199}
8200
8201void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8202{
8203 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8204 target, levels, internalformat, width, height);
8205
Geoff Langbfdea662014-07-23 14:16:32 -04008206 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008207 if (context)
8208 {
8209 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008210 {
Geoff Langb1196682014-07-23 13:47:29 -04008211 context->recordError(gl::Error(GL_INVALID_OPERATION));
8212 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008213 }
Geoff Langbfdea662014-07-23 14:16:32 -04008214
8215 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8216 {
8217 return;
8218 }
8219
8220 switch (target)
8221 {
8222 case GL_TEXTURE_2D:
8223 {
8224 gl::Texture2D *texture2d = context->getTexture2D();
8225 texture2d->storage(levels, internalformat, width, height);
8226 }
8227 break;
8228
8229 case GL_TEXTURE_CUBE_MAP:
8230 {
8231 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8232 textureCube->storage(levels, internalformat, width);
8233 }
8234 break;
8235
8236 default:
Geoff Langb1196682014-07-23 13:47:29 -04008237 context->recordError(gl::Error(GL_INVALID_ENUM));
8238 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008239 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008240 }
8241}
8242
8243void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8244{
8245 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8246 "GLsizei height = %d, GLsizei depth = %d)",
8247 target, levels, internalformat, width, height, depth);
8248
Geoff Langbfdea662014-07-23 14:16:32 -04008249 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008250 if (context)
8251 {
8252 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008253 {
Geoff Langb1196682014-07-23 13:47:29 -04008254 context->recordError(gl::Error(GL_INVALID_OPERATION));
8255 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008256 }
Geoff Langbfdea662014-07-23 14:16:32 -04008257
8258 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8259 {
8260 return;
8261 }
8262
8263 switch (target)
8264 {
8265 case GL_TEXTURE_3D:
8266 {
8267 gl::Texture3D *texture3d = context->getTexture3D();
8268 texture3d->storage(levels, internalformat, width, height, depth);
8269 }
8270 break;
8271
8272 case GL_TEXTURE_2D_ARRAY:
8273 {
8274 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8275 texture2darray->storage(levels, internalformat, width, height, depth);
8276 }
8277 break;
8278
8279 default:
8280 UNREACHABLE();
8281 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008282 }
8283}
8284
8285void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8286{
8287 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8288 "GLint* params = 0x%0.8p)",
8289 target, internalformat, pname, bufSize, params);
8290
Geoff Langbfdea662014-07-23 14:16:32 -04008291 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008292 if (context)
8293 {
8294 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008295 {
Geoff Langb1196682014-07-23 13:47:29 -04008296 context->recordError(gl::Error(GL_INVALID_OPERATION));
8297 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008298 }
Geoff Langbfdea662014-07-23 14:16:32 -04008299
8300 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8301 if (!formatCaps.renderable)
8302 {
Geoff Langb1196682014-07-23 13:47:29 -04008303 context->recordError(gl::Error(GL_INVALID_ENUM));
8304 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008305 }
8306
8307 if (target != GL_RENDERBUFFER)
8308 {
Geoff Langb1196682014-07-23 13:47:29 -04008309 context->recordError(gl::Error(GL_INVALID_ENUM));
8310 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008311 }
8312
8313 if (bufSize < 0)
8314 {
Geoff Langb1196682014-07-23 13:47:29 -04008315 context->recordError(gl::Error(GL_INVALID_VALUE));
8316 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008317 }
8318
8319 switch (pname)
8320 {
8321 case GL_NUM_SAMPLE_COUNTS:
8322 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008323 {
8324 *params = formatCaps.sampleCounts.size();
8325 }
Geoff Langbfdea662014-07-23 14:16:32 -04008326 break;
Geoff Langb1196682014-07-23 13:47:29 -04008327
Geoff Langbfdea662014-07-23 14:16:32 -04008328 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008329 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008330 break;
Geoff Langb1196682014-07-23 13:47:29 -04008331
Geoff Langbfdea662014-07-23 14:16:32 -04008332 default:
Geoff Langb1196682014-07-23 13:47:29 -04008333 context->recordError(gl::Error(GL_INVALID_ENUM));
8334 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008335 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008336 }
8337}
8338
8339// Extension functions
8340
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008341void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8342 GLbitfield mask, GLenum filter)
8343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008344 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008345 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8346 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8347 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8348
Geoff Langbfdea662014-07-23 14:16:32 -04008349 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008350 if (context)
8351 {
8352 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8353 dstX0, dstY0, dstX1, dstY1, mask, filter,
8354 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008355 {
Geoff Langbfdea662014-07-23 14:16:32 -04008356 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008357 }
Geoff Langbfdea662014-07-23 14:16:32 -04008358
Geoff Lang64839152014-08-26 16:23:25 -04008359 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8360 mask, filter);
8361 if (error.isError())
8362 {
8363 context->recordError(error);
8364 return;
8365 }
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008366 }
8367}
8368
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008369void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8370 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008371{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008372 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008373 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008374 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008375 target, level, internalformat, width, height, depth, border, format, type, pixels);
8376
Geoff Langbfdea662014-07-23 14:16:32 -04008377 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008378}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008379
Geoff Langbfdea662014-07-23 14:16:32 -04008380void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008381 GLenum *binaryFormat, void *binary)
8382{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008383 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 +00008384 program, bufSize, length, binaryFormat, binary);
8385
Geoff Langbfdea662014-07-23 14:16:32 -04008386 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008387 if (context)
8388 {
8389 gl::Program *programObject = context->getProgram(program);
8390
8391 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008392 {
Geoff Langb1196682014-07-23 13:47:29 -04008393 context->recordError(gl::Error(GL_INVALID_OPERATION));
8394 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008395 }
Geoff Langbfdea662014-07-23 14:16:32 -04008396
8397 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8398
8399 if (!programBinary)
8400 {
Geoff Langb1196682014-07-23 13:47:29 -04008401 context->recordError(gl::Error(GL_INVALID_OPERATION));
8402 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008403 }
8404
Geoff Lang900013c2014-07-07 11:32:19 -04008405 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04008406 {
Geoff Langb1196682014-07-23 13:47:29 -04008407 context->recordError(gl::Error(GL_INVALID_OPERATION));
8408 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008409 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008410 }
8411}
8412
8413void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8414 const void *binary, GLint length)
8415{
8416 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8417 program, binaryFormat, binary, length);
8418
Geoff Langbfdea662014-07-23 14:16:32 -04008419 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008420 if (context)
8421 {
Geoff Lang900013c2014-07-07 11:32:19 -04008422 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8423 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008424 {
Geoff Langb1196682014-07-23 13:47:29 -04008425 context->recordError(gl::Error(GL_INVALID_ENUM));
8426 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008427 }
Geoff Langbfdea662014-07-23 14:16:32 -04008428
8429 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008430 if (!programObject)
8431 {
Geoff Langb1196682014-07-23 13:47:29 -04008432 context->recordError(gl::Error(GL_INVALID_OPERATION));
8433 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008434 }
8435
Geoff Lang900013c2014-07-07 11:32:19 -04008436 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008437 }
8438}
8439
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008440void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8441{
8442 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8443
Geoff Langbfdea662014-07-23 14:16:32 -04008444 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008445 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008446 {
Geoff Langbfdea662014-07-23 14:16:32 -04008447 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008448 {
Geoff Langb1196682014-07-23 13:47:29 -04008449 context->recordError(gl::Error(GL_INVALID_VALUE));
8450 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008451 }
8452
8453 if (context->getState().getDrawFramebuffer()->id() == 0)
8454 {
8455 if (n != 1)
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_OPERATION));
8458 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008459 }
8460
Geoff Langbfdea662014-07-23 14:16:32 -04008461 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008462 {
Geoff Langb1196682014-07-23 13:47:29 -04008463 context->recordError(gl::Error(GL_INVALID_OPERATION));
8464 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008465 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008466 }
Geoff Langbfdea662014-07-23 14:16:32 -04008467 else
8468 {
8469 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8470 {
8471 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8472 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8473 {
Geoff Langb1196682014-07-23 13:47:29 -04008474 context->recordError(gl::Error(GL_INVALID_OPERATION));
8475 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008476 }
8477 }
8478 }
8479
8480 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8481
8482 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8483 {
8484 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8485 }
8486
8487 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8488 {
8489 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8490 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008491 }
8492}
8493
Shannon Woodsb3801742014-03-27 14:59:19 -04008494void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8495{
8496 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8497
Geoff Langbfdea662014-07-23 14:16:32 -04008498 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008499 if (context)
8500 {
8501 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008502 {
Geoff Langb1196682014-07-23 13:47:29 -04008503 context->recordError(gl::Error(GL_INVALID_ENUM));
8504 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008505 }
Geoff Langbfdea662014-07-23 14:16:32 -04008506
8507 if (pname != GL_BUFFER_MAP_POINTER)
8508 {
Geoff Langb1196682014-07-23 13:47:29 -04008509 context->recordError(gl::Error(GL_INVALID_ENUM));
8510 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008511 }
8512
8513 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8514
8515 if (!buffer || !buffer->isMapped())
8516 {
8517 *params = NULL;
8518 }
8519 else
8520 {
8521 *params = buffer->getMapPointer();
8522 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008523 }
8524}
8525
8526void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8527{
8528 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8529
Geoff Langbfdea662014-07-23 14:16:32 -04008530 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008531 if (context)
8532 {
8533 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008534 {
Geoff Langb1196682014-07-23 13:47:29 -04008535 context->recordError(gl::Error(GL_INVALID_ENUM));
8536 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008537 }
Geoff Langbfdea662014-07-23 14:16:32 -04008538
8539 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8540
8541 if (buffer == NULL)
8542 {
Geoff Langb1196682014-07-23 13:47:29 -04008543 context->recordError(gl::Error(GL_INVALID_OPERATION));
8544 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008545 }
8546
8547 if (access != GL_WRITE_ONLY_OES)
8548 {
Geoff Langb1196682014-07-23 13:47:29 -04008549 context->recordError(gl::Error(GL_INVALID_ENUM));
8550 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008551 }
8552
8553 if (buffer->isMapped())
8554 {
Geoff Langb1196682014-07-23 13:47:29 -04008555 context->recordError(gl::Error(GL_INVALID_OPERATION));
8556 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008557 }
8558
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008559 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8560 if (error.isError())
8561 {
8562 context->recordError(error);
8563 return NULL;
8564 }
8565
8566 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008567 }
8568
8569 return NULL;
8570}
8571
8572GLboolean __stdcall glUnmapBufferOES(GLenum target)
8573{
8574 EVENT("(GLenum target = 0x%X)", target);
8575
Geoff Langbfdea662014-07-23 14:16:32 -04008576 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008577 if (context)
8578 {
8579 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008580 {
Geoff Langb1196682014-07-23 13:47:29 -04008581 context->recordError(gl::Error(GL_INVALID_ENUM));
8582 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008583 }
Geoff Langbfdea662014-07-23 14:16:32 -04008584
8585 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8586
8587 if (buffer == NULL || !buffer->isMapped())
8588 {
Geoff Langb1196682014-07-23 13:47:29 -04008589 context->recordError(gl::Error(GL_INVALID_OPERATION));
8590 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008591 }
8592
8593 // TODO: detect if we had corruption. if so, throw an error and return false.
8594
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008595 gl::Error error = buffer->unmap();
8596 if (error.isError())
8597 {
8598 context->recordError(error);
8599 return GL_FALSE;
8600 }
Geoff Langbfdea662014-07-23 14:16:32 -04008601
8602 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008603 }
8604
8605 return GL_FALSE;
8606}
8607
Shannon Woods916e7692014-03-27 16:58:22 -04008608void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8609{
8610 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8611 target, offset, length, access);
8612
Geoff Langbfdea662014-07-23 14:16:32 -04008613 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008614 if (context)
8615 {
8616 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008617 {
Geoff Langb1196682014-07-23 13:47:29 -04008618 context->recordError(gl::Error(GL_INVALID_ENUM));
8619 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008620 }
Geoff Langbfdea662014-07-23 14:16:32 -04008621
8622 if (offset < 0 || length < 0)
8623 {
Geoff Langb1196682014-07-23 13:47:29 -04008624 context->recordError(gl::Error(GL_INVALID_VALUE));
8625 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008626 }
8627
8628 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8629
8630 if (buffer == NULL)
8631 {
Geoff Langb1196682014-07-23 13:47:29 -04008632 context->recordError(gl::Error(GL_INVALID_OPERATION));
8633 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008634 }
8635
8636 // Check for buffer overflow
8637 size_t offsetSize = static_cast<size_t>(offset);
8638 size_t lengthSize = static_cast<size_t>(length);
8639
8640 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8641 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8642 {
Geoff Langb1196682014-07-23 13:47:29 -04008643 context->recordError(gl::Error(GL_INVALID_VALUE));
8644 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008645 }
8646
8647 // Check for invalid bits in the mask
8648 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8649 GL_MAP_WRITE_BIT |
8650 GL_MAP_INVALIDATE_RANGE_BIT |
8651 GL_MAP_INVALIDATE_BUFFER_BIT |
8652 GL_MAP_FLUSH_EXPLICIT_BIT |
8653 GL_MAP_UNSYNCHRONIZED_BIT;
8654
8655 if (access & ~(allAccessBits))
8656 {
Geoff Langb1196682014-07-23 13:47:29 -04008657 context->recordError(gl::Error(GL_INVALID_VALUE));
8658 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008659 }
8660
8661 if (length == 0 || buffer->isMapped())
8662 {
Geoff Langb1196682014-07-23 13:47:29 -04008663 context->recordError(gl::Error(GL_INVALID_OPERATION));
8664 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008665 }
8666
8667 // Check for invalid bit combinations
8668 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8669 {
Geoff Langb1196682014-07-23 13:47:29 -04008670 context->recordError(gl::Error(GL_INVALID_OPERATION));
8671 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008672 }
8673
8674 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8675 GL_MAP_INVALIDATE_BUFFER_BIT |
8676 GL_MAP_UNSYNCHRONIZED_BIT;
8677
8678 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8679 {
Geoff Langb1196682014-07-23 13:47:29 -04008680 context->recordError(gl::Error(GL_INVALID_OPERATION));
8681 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008682 }
8683
8684 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8685 {
Geoff Langb1196682014-07-23 13:47:29 -04008686 context->recordError(gl::Error(GL_INVALID_OPERATION));
8687 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008688 }
8689
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008690 gl::Error error = buffer->mapRange(offset, length, access);
8691 if (error.isError())
8692 {
8693 context->recordError(error);
8694 return NULL;
8695 }
8696
8697 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008698 }
8699
8700 return NULL;
8701}
8702
8703void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8704{
8705 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8706
Geoff Langbfdea662014-07-23 14:16:32 -04008707 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008708 if (context)
8709 {
8710 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008711 {
Geoff Langb1196682014-07-23 13:47:29 -04008712 context->recordError(gl::Error(GL_INVALID_VALUE));
8713 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008714 }
Geoff Langbfdea662014-07-23 14:16:32 -04008715
8716 if (!gl::ValidBufferTarget(context, target))
8717 {
Geoff Langb1196682014-07-23 13:47:29 -04008718 context->recordError(gl::Error(GL_INVALID_ENUM));
8719 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008720 }
8721
8722 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8723
8724 if (buffer == NULL)
8725 {
Geoff Langb1196682014-07-23 13:47:29 -04008726 context->recordError(gl::Error(GL_INVALID_OPERATION));
8727 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008728 }
8729
8730 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8731 {
Geoff Langb1196682014-07-23 13:47:29 -04008732 context->recordError(gl::Error(GL_INVALID_OPERATION));
8733 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008734 }
8735
8736 // Check for buffer overflow
8737 size_t offsetSize = static_cast<size_t>(offset);
8738 size_t lengthSize = static_cast<size_t>(length);
8739
8740 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8741 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8742 {
Geoff Langb1196682014-07-23 13:47:29 -04008743 context->recordError(gl::Error(GL_INVALID_VALUE));
8744 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008745 }
8746
8747 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008748 }
8749}
8750
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008751__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8752{
8753 struct Extension
8754 {
8755 const char *name;
8756 __eglMustCastToProperFunctionPointerType address;
8757 };
8758
8759 static const Extension glExtensions[] =
8760 {
8761 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008762 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008763 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008764 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8765 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8766 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8767 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8768 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8769 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8770 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008771 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008772 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008773 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8774 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8775 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8776 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008777 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8778 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8779 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8780 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8781 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8782 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8783 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008784 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008785 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8786 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8787 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008788 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008789 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8790 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8791 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008792 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8793 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8794 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008795
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008796 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008797 {
8798 if (strcmp(procname, glExtensions[ext].name) == 0)
8799 {
8800 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8801 }
8802 }
8803
8804 return NULL;
8805}
8806
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008807// Non-public functions used by EGL
8808
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008809bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008810{
8811 EVENT("(egl::Surface* surface = 0x%0.8p)",
8812 surface);
8813
Geoff Langbfdea662014-07-23 14:16:32 -04008814 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008815 if (context)
8816 {
8817 gl::Texture2D *textureObject = context->getTexture2D();
8818 ASSERT(textureObject != NULL);
8819
8820 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008821 {
Geoff Langbfdea662014-07-23 14:16:32 -04008822 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008823 }
Geoff Langbfdea662014-07-23 14:16:32 -04008824
8825 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008826 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008827
8828 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008829}
8830
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008831}