blob: 4532889db246e2c88d364822a2d3b4e5fb64a549 [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
Geoff Langb543aff2014-09-30 14:52:54 -04003657 gl::Error error = context->linkProgram(program);
3658 if (error.isError())
3659 {
3660 context->recordError(error);
3661 return;
3662 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003663 }
3664}
3665
3666void __stdcall glPixelStorei(GLenum pname, GLint param)
3667{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003668 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003669
Geoff Langbfdea662014-07-23 14:16:32 -04003670 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003671 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003672 {
Geoff Langbfdea662014-07-23 14:16:32 -04003673 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003674 {
Geoff Langbfdea662014-07-23 14:16:32 -04003675 case GL_UNPACK_ALIGNMENT:
3676 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003677 {
Geoff Langb1196682014-07-23 13:47:29 -04003678 context->recordError(gl::Error(GL_INVALID_VALUE));
3679 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003680 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003681
Geoff Langbfdea662014-07-23 14:16:32 -04003682 context->getState().setUnpackAlignment(param);
3683 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003684
Geoff Langbfdea662014-07-23 14:16:32 -04003685 case GL_PACK_ALIGNMENT:
3686 if (param != 1 && param != 2 && param != 4 && param != 8)
3687 {
Geoff Langb1196682014-07-23 13:47:29 -04003688 context->recordError(gl::Error(GL_INVALID_VALUE));
3689 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003690 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003691
Geoff Langbfdea662014-07-23 14:16:32 -04003692 context->getState().setPackAlignment(param);
3693 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003694
Geoff Langbfdea662014-07-23 14:16:32 -04003695 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3696 context->getState().setPackReverseRowOrder(param != 0);
3697 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003698
Geoff Langbfdea662014-07-23 14:16:32 -04003699 case GL_UNPACK_IMAGE_HEIGHT:
3700 case GL_UNPACK_SKIP_IMAGES:
3701 case GL_UNPACK_ROW_LENGTH:
3702 case GL_UNPACK_SKIP_ROWS:
3703 case GL_UNPACK_SKIP_PIXELS:
3704 case GL_PACK_ROW_LENGTH:
3705 case GL_PACK_SKIP_ROWS:
3706 case GL_PACK_SKIP_PIXELS:
3707 if (context->getClientVersion() < 3)
3708 {
Geoff Langb1196682014-07-23 13:47:29 -04003709 context->recordError(gl::Error(GL_INVALID_ENUM));
3710 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003711 }
Geoff Langbfdea662014-07-23 14:16:32 -04003712 UNIMPLEMENTED();
3713 break;
3714
3715 default:
Geoff Langb1196682014-07-23 13:47:29 -04003716 context->recordError(gl::Error(GL_INVALID_ENUM));
3717 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003718 }
3719 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003720}
3721
3722void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3723{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003724 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003725
Geoff Langbfdea662014-07-23 14:16:32 -04003726 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003727 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003728 {
Geoff Langbfdea662014-07-23 14:16:32 -04003729 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003730 }
3731}
3732
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003733void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3734 GLenum format, GLenum type, GLsizei bufSize,
3735 GLvoid *data)
3736{
3737 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3738 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3739 x, y, width, height, format, type, bufSize, data);
3740
Geoff Langbfdea662014-07-23 14:16:32 -04003741 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003742 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003743 {
Geoff Langb1196682014-07-23 13:47:29 -04003744 if (width < 0 || height < 0 || bufSize < 0)
3745 {
3746 context->recordError(gl::Error(GL_INVALID_VALUE));
3747 return;
3748 }
3749
Geoff Langbfdea662014-07-23 14:16:32 -04003750 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3751 format, type, &bufSize, data))
3752 {
3753 return;
3754 }
3755
Geoff Lang63d2fc72014-07-25 14:51:41 -04003756 gl::Error error = context->readPixels(x, y, width, height, format, type, &bufSize, data);
3757 if (error.isError())
3758 {
3759 context->recordError(error);
3760 return;
3761 }
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003762 }
3763}
3764
3765void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3766 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003767{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003768 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003769 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003770 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003771
Geoff Langbfdea662014-07-23 14:16:32 -04003772 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003773 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003774 {
Geoff Langb1196682014-07-23 13:47:29 -04003775 if (width < 0 || height < 0)
3776 {
3777 context->recordError(gl::Error(GL_INVALID_VALUE));
3778 return;
3779 }
3780
Geoff Langbfdea662014-07-23 14:16:32 -04003781 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3782 format, type, NULL, pixels))
3783 {
3784 return;
3785 }
3786
Geoff Lang63d2fc72014-07-25 14:51:41 -04003787 gl::Error error = context->readPixels(x, y, width, height, format, type, NULL, pixels);
3788 if (error.isError())
3789 {
3790 context->recordError(error);
3791 return;
3792 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003793 }
3794}
3795
3796void __stdcall glReleaseShaderCompiler(void)
3797{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003798 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003799
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003800 gl::Context *context = gl::getNonLostContext();
3801
3802 if (context)
3803 {
3804 context->releaseShaderCompiler();
3805 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003806}
3807
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003808void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003809{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003810 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 +00003811 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003812
Geoff Langbfdea662014-07-23 14:16:32 -04003813 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003814 if (context)
3815 {
3816 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3817 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003818 {
Geoff Langbfdea662014-07-23 14:16:32 -04003819 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003820 }
Geoff Langbfdea662014-07-23 14:16:32 -04003821
3822 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003823 }
3824}
3825
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003826void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3827{
3828 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3829}
3830
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003831void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3832{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003833 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003834
Geoff Langbfdea662014-07-23 14:16:32 -04003835 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003836
Geoff Langbfdea662014-07-23 14:16:32 -04003837 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838 {
Geoff Langbfdea662014-07-23 14:16:32 -04003839 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003840 }
3841}
3842
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003843void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003845 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003846
Geoff Langbfdea662014-07-23 14:16:32 -04003847 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003848 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003849 {
Geoff Langb1196682014-07-23 13:47:29 -04003850 if (condition != GL_ALL_COMPLETED_NV)
3851 {
3852 context->recordError(gl::Error(GL_INVALID_ENUM));
3853 return;
3854 }
3855
Geoff Langbfdea662014-07-23 14:16:32 -04003856 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3857
3858 if (fenceObject == NULL)
3859 {
Geoff Langb1196682014-07-23 13:47:29 -04003860 context->recordError(gl::Error(GL_INVALID_OPERATION));
3861 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003862 }
3863
3864 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003865 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003866}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003867
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003868void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3869{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003870 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 +00003871
Geoff Langbfdea662014-07-23 14:16:32 -04003872 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003873 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003874 {
Geoff Langb1196682014-07-23 13:47:29 -04003875 if (width < 0 || height < 0)
3876 {
3877 context->recordError(gl::Error(GL_INVALID_VALUE));
3878 return;
3879 }
3880
Geoff Langbfdea662014-07-23 14:16:32 -04003881 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003882 }
3883}
3884
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003885void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003886{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003887 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003888 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003889 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003890
Geoff Lang900013c2014-07-07 11:32:19 -04003891 gl::Context* context = gl::getNonLostContext();
3892 if (context)
3893 {
3894 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3895 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3896 {
Geoff Langb1196682014-07-23 13:47:29 -04003897 context->recordError(gl::Error(GL_INVALID_ENUM));
3898 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003899 }
3900
3901 // No binary shader formats are supported.
3902 UNIMPLEMENTED();
3903 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003904}
3905
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003906void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003907{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003908 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 +00003909 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003910
Geoff Langbfdea662014-07-23 14:16:32 -04003911 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003912 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003913 {
Geoff Langb1196682014-07-23 13:47:29 -04003914 if (count < 0)
3915 {
3916 context->recordError(gl::Error(GL_INVALID_VALUE));
3917 return;
3918 }
3919
Geoff Langbfdea662014-07-23 14:16:32 -04003920 gl::Shader *shaderObject = context->getShader(shader);
3921
3922 if (!shaderObject)
3923 {
3924 if (context->getProgram(shader))
3925 {
Geoff Langb1196682014-07-23 13:47:29 -04003926 context->recordError(gl::Error(GL_INVALID_OPERATION));
3927 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003928 }
3929 else
3930 {
Geoff Langb1196682014-07-23 13:47:29 -04003931 context->recordError(gl::Error(GL_INVALID_VALUE));
3932 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003933 }
3934 }
3935
3936 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003937 }
3938}
3939
3940void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3941{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003942 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003943}
3944
3945void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3946{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003947 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 +00003948
Geoff Langbfdea662014-07-23 14:16:32 -04003949 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003950 if (context)
3951 {
Geoff Langb1196682014-07-23 13:47:29 -04003952 switch (face)
3953 {
3954 case GL_FRONT:
3955 case GL_BACK:
3956 case GL_FRONT_AND_BACK:
3957 break;
3958
3959 default:
3960 context->recordError(gl::Error(GL_INVALID_ENUM));
3961 return;
3962 }
3963
3964 switch (func)
3965 {
3966 case GL_NEVER:
3967 case GL_ALWAYS:
3968 case GL_LESS:
3969 case GL_LEQUAL:
3970 case GL_EQUAL:
3971 case GL_GEQUAL:
3972 case GL_GREATER:
3973 case GL_NOTEQUAL:
3974 break;
3975
3976 default:
3977 context->recordError(gl::Error(GL_INVALID_ENUM));
3978 return;
3979 }
3980
Geoff Langbfdea662014-07-23 14:16:32 -04003981 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3982 {
3983 context->getState().setStencilParams(func, ref, mask);
3984 }
3985
3986 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3987 {
3988 context->getState().setStencilBackParams(func, ref, mask);
3989 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003990 }
3991}
3992
3993void __stdcall glStencilMask(GLuint mask)
3994{
3995 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3996}
3997
3998void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3999{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004000 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004001
Geoff Langbfdea662014-07-23 14:16:32 -04004002 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004003 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004004 {
Geoff Langb1196682014-07-23 13:47:29 -04004005 switch (face)
4006 {
4007 case GL_FRONT:
4008 case GL_BACK:
4009 case GL_FRONT_AND_BACK:
4010 break;
4011
4012 default:
4013 context->recordError(gl::Error(GL_INVALID_ENUM));
4014 return;
4015 }
4016
Geoff Langbfdea662014-07-23 14:16:32 -04004017 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4018 {
4019 context->getState().setStencilWritemask(mask);
4020 }
4021
4022 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4023 {
4024 context->getState().setStencilBackWritemask(mask);
4025 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004026 }
4027}
4028
4029void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4030{
4031 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4032}
4033
4034void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4035{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004036 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 +00004037 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004038
Geoff Langbfdea662014-07-23 14:16:32 -04004039 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004040 if (context)
4041 {
Geoff Langb1196682014-07-23 13:47:29 -04004042 switch (face)
4043 {
4044 case GL_FRONT:
4045 case GL_BACK:
4046 case GL_FRONT_AND_BACK:
4047 break;
4048
4049 default:
4050 context->recordError(gl::Error(GL_INVALID_ENUM));
4051 return;
4052 }
4053
4054 switch (fail)
4055 {
4056 case GL_ZERO:
4057 case GL_KEEP:
4058 case GL_REPLACE:
4059 case GL_INCR:
4060 case GL_DECR:
4061 case GL_INVERT:
4062 case GL_INCR_WRAP:
4063 case GL_DECR_WRAP:
4064 break;
4065
4066 default:
4067 context->recordError(gl::Error(GL_INVALID_ENUM));
4068 return;
4069 }
4070
4071 switch (zfail)
4072 {
4073 case GL_ZERO:
4074 case GL_KEEP:
4075 case GL_REPLACE:
4076 case GL_INCR:
4077 case GL_DECR:
4078 case GL_INVERT:
4079 case GL_INCR_WRAP:
4080 case GL_DECR_WRAP:
4081 break;
4082
4083 default:
4084 context->recordError(gl::Error(GL_INVALID_ENUM));
4085 return;
4086 }
4087
4088 switch (zpass)
4089 {
4090 case GL_ZERO:
4091 case GL_KEEP:
4092 case GL_REPLACE:
4093 case GL_INCR:
4094 case GL_DECR:
4095 case GL_INVERT:
4096 case GL_INCR_WRAP:
4097 case GL_DECR_WRAP:
4098 break;
4099
4100 default:
4101 context->recordError(gl::Error(GL_INVALID_ENUM));
4102 return;
4103 }
4104
Geoff Langbfdea662014-07-23 14:16:32 -04004105 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4106 {
4107 context->getState().setStencilOperations(fail, zfail, zpass);
4108 }
4109
4110 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4111 {
4112 context->getState().setStencilBackOperations(fail, zfail, zpass);
4113 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004114 }
4115}
4116
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004117GLboolean __stdcall glTestFenceNV(GLuint fence)
4118{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004119 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004120
Geoff Langbfdea662014-07-23 14:16:32 -04004121 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004122 if (context)
4123 {
4124 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4125
4126 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004127 {
Geoff Langb1196682014-07-23 13:47:29 -04004128 context->recordError(gl::Error(GL_INVALID_OPERATION));
4129 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004130 }
Geoff Langbfdea662014-07-23 14:16:32 -04004131
4132 if (fenceObject->isFence() != GL_TRUE)
4133 {
Geoff Langb1196682014-07-23 13:47:29 -04004134 context->recordError(gl::Error(GL_INVALID_OPERATION));
4135 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004136 }
4137
4138 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004139 }
Geoff Langbfdea662014-07-23 14:16:32 -04004140
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004141 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004142}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004143
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004144void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4145 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004146{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004147 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004148 "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 +00004149 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004150
Geoff Langbfdea662014-07-23 14:16:32 -04004151 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004152 if (context)
4153 {
4154 if (context->getClientVersion() < 3 &&
4155 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4156 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004157 {
Geoff Langbfdea662014-07-23 14:16:32 -04004158 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004159 }
Geoff Langbfdea662014-07-23 14:16:32 -04004160
4161 if (context->getClientVersion() >= 3 &&
4162 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4163 0, 0, 0, width, height, 1, border, format, type, pixels))
4164 {
4165 return;
4166 }
4167
4168 switch (target)
4169 {
4170 case GL_TEXTURE_2D:
4171 {
4172 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004173 gl::Error error = texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4174 if (error.isError())
4175 {
4176 context->recordError(error);
4177 return;
4178 }
Geoff Langbfdea662014-07-23 14:16:32 -04004179 }
4180 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004181
Geoff Langbfdea662014-07-23 14:16:32 -04004182 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004183 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004184 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004185 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004186 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
Geoff Langbfdea662014-07-23 14:16:32 -04004187 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4188 {
4189 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang8376cea2014-09-02 11:47:07 -04004190 gl::Error error = texture->setImage(target, level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004191 if (error.isError())
4192 {
4193 context->recordError(error);
4194 return;
4195 }
Geoff Langbfdea662014-07-23 14:16:32 -04004196 }
4197 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004198
Geoff Langbfdea662014-07-23 14:16:32 -04004199 default: UNREACHABLE();
4200 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004201 }
4202}
4203
4204void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4205{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004206 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4207
Geoff Langbfdea662014-07-23 14:16:32 -04004208 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004209 if (context)
4210 {
4211 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004212 {
Geoff Langbfdea662014-07-23 14:16:32 -04004213 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004214 }
Geoff Langbfdea662014-07-23 14:16:32 -04004215
4216 gl::Texture *texture = context->getTargetTexture(target);
4217
4218 if (!texture)
4219 {
Geoff Langb1196682014-07-23 13:47:29 -04004220 context->recordError(gl::Error(GL_INVALID_ENUM));
4221 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004222 }
4223
4224 switch (pname)
4225 {
4226 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4227 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4228 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4229 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4230 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4231 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4232 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4233 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4234 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4235 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4236 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4237 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4238 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4239 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4240 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4241 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4242 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4243 default: UNREACHABLE(); break;
4244 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004245 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004246}
4247
4248void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4249{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004250 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004251}
4252
4253void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4254{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004255 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004256
Geoff Langbfdea662014-07-23 14:16:32 -04004257 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004258 if (context)
4259 {
4260 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004261 {
Geoff Langbfdea662014-07-23 14:16:32 -04004262 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004263 }
Geoff Langbfdea662014-07-23 14:16:32 -04004264
4265 gl::Texture *texture = context->getTargetTexture(target);
4266
4267 if (!texture)
4268 {
Geoff Langb1196682014-07-23 13:47:29 -04004269 context->recordError(gl::Error(GL_INVALID_ENUM));
4270 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004271 }
4272
4273 switch (pname)
4274 {
4275 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4276 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4277 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4278 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4279 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4280 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4281 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4282 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4283 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4284 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4285 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4286 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4287 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4288 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4289 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4290 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4291 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4292 default: UNREACHABLE(); break;
4293 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004294 }
4295}
4296
4297void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4298{
4299 glTexParameteri(target, pname, *params);
4300}
4301
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004302void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4303{
4304 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4305 target, levels, internalformat, width, height);
4306
Geoff Langbfdea662014-07-23 14:16:32 -04004307 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004308 if (context)
4309 {
4310 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004311 {
Geoff Langb1196682014-07-23 13:47:29 -04004312 context->recordError(gl::Error(GL_INVALID_OPERATION));
4313 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004314 }
Geoff Langbfdea662014-07-23 14:16:32 -04004315
4316 if (context->getClientVersion() < 3 &&
4317 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4318 {
4319 return;
4320 }
4321
4322 if (context->getClientVersion() >= 3 &&
4323 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4324 {
4325 return;
4326 }
4327
4328 switch (target)
4329 {
4330 case GL_TEXTURE_2D:
4331 {
4332 gl::Texture2D *texture2d = context->getTexture2D();
4333 texture2d->storage(levels, internalformat, width, height);
4334 }
4335 break;
4336
4337 case GL_TEXTURE_CUBE_MAP:
4338 {
4339 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4340 textureCube->storage(levels, internalformat, width);
4341 }
4342 break;
4343
4344 default:
Geoff Langb1196682014-07-23 13:47:29 -04004345 context->recordError(gl::Error(GL_INVALID_ENUM));
4346 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004347 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004348 }
4349}
4350
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004351void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4352 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004353{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004354 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004355 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004356 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004357 target, level, xoffset, yoffset, width, height, format, type, pixels);
4358
Geoff Langbfdea662014-07-23 14:16:32 -04004359 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004360 if (context)
4361 {
4362 if (context->getClientVersion() < 3 &&
4363 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4364 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004365 {
Geoff Langbfdea662014-07-23 14:16:32 -04004366 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004367 }
Geoff Langbfdea662014-07-23 14:16:32 -04004368
4369 if (context->getClientVersion() >= 3 &&
4370 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4371 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4372 {
4373 return;
4374 }
4375
4376 // Zero sized uploads are valid but no-ops
4377 if (width == 0 || height == 0)
4378 {
4379 return;
4380 }
4381
4382 switch (target)
4383 {
4384 case GL_TEXTURE_2D:
4385 {
4386 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004387 gl::Error error = texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4388 if (error.isError())
4389 {
4390 context->recordError(error);
4391 return;
4392 }
Geoff Langbfdea662014-07-23 14:16:32 -04004393 }
4394 break;
4395
4396 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4397 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4398 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4399 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4400 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4401 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4402 {
4403 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004404 gl::Error error = texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4405 if (error.isError())
4406 {
4407 context->recordError(error);
4408 return;
4409 }
Geoff Langbfdea662014-07-23 14:16:32 -04004410 }
4411 break;
4412
4413 default:
4414 UNREACHABLE();
4415 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004416 }
4417}
4418
4419void __stdcall glUniform1f(GLint location, GLfloat x)
4420{
4421 glUniform1fv(location, 1, &x);
4422}
4423
4424void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4425{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004426 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004427
Geoff Langbfdea662014-07-23 14:16:32 -04004428 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004429 if (context)
4430 {
4431 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004432 {
Geoff Langbfdea662014-07-23 14:16:32 -04004433 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004434 }
Geoff Langbfdea662014-07-23 14:16:32 -04004435
4436 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4437 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438 }
4439}
4440
4441void __stdcall glUniform1i(GLint location, GLint x)
4442{
4443 glUniform1iv(location, 1, &x);
4444}
4445
4446void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004448 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004449
Geoff Langbfdea662014-07-23 14:16:32 -04004450 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004451 if (context)
4452 {
4453 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454 {
Geoff Langbfdea662014-07-23 14:16:32 -04004455 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004456 }
Geoff Langbfdea662014-07-23 14:16:32 -04004457
4458 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4459 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004460 }
4461}
4462
4463void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4464{
4465 GLfloat xy[2] = {x, y};
4466
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004467 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004468}
4469
4470void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4471{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004472 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004473
Geoff Langbfdea662014-07-23 14:16:32 -04004474 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004475 if (context)
4476 {
4477 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004478 {
Geoff Langbfdea662014-07-23 14:16:32 -04004479 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480 }
Geoff Langbfdea662014-07-23 14:16:32 -04004481
4482 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4483 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004484 }
4485}
4486
4487void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4488{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004489 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004491 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004492}
4493
4494void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4495{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004496 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004497
Geoff Langbfdea662014-07-23 14:16:32 -04004498 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004499 if (context)
4500 {
4501 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004502 {
Geoff Langbfdea662014-07-23 14:16:32 -04004503 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004504 }
Geoff Langbfdea662014-07-23 14:16:32 -04004505
4506 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4507 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508 }
4509}
4510
4511void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4512{
4513 GLfloat xyz[3] = {x, y, z};
4514
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004515 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004516}
4517
4518void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4519{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004520 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004521
Geoff Langbfdea662014-07-23 14:16:32 -04004522 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004523 if (context)
4524 {
4525 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004526 {
Geoff Langbfdea662014-07-23 14:16:32 -04004527 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004528 }
Geoff Langbfdea662014-07-23 14:16:32 -04004529
4530 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4531 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004532 }
4533}
4534
4535void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4536{
4537 GLint xyz[3] = {x, y, z};
4538
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004539 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004540}
4541
4542void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4543{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004544 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004545
Geoff Langbfdea662014-07-23 14:16:32 -04004546 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004547 if (context)
4548 {
4549 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004550 {
Geoff Langbfdea662014-07-23 14:16:32 -04004551 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004552 }
Geoff Langbfdea662014-07-23 14:16:32 -04004553
4554 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4555 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004556 }
4557}
4558
4559void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4560{
4561 GLfloat xyzw[4] = {x, y, z, w};
4562
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004563 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004564}
4565
4566void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4567{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004568 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004569
Geoff Langbfdea662014-07-23 14:16:32 -04004570 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004571 if (context)
4572 {
4573 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004574 {
Geoff Langbfdea662014-07-23 14:16:32 -04004575 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004576 }
Geoff Langbfdea662014-07-23 14:16:32 -04004577
4578 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4579 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004580 }
4581}
4582
4583void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4584{
4585 GLint xyzw[4] = {x, y, z, w};
4586
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004587 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004588}
4589
4590void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4591{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004592 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004593
Geoff Langbfdea662014-07-23 14:16:32 -04004594 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004595 if (context)
4596 {
4597 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004598 {
Geoff Langbfdea662014-07-23 14:16:32 -04004599 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004600 }
Geoff Langbfdea662014-07-23 14:16:32 -04004601
4602 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4603 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004604 }
4605}
4606
4607void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4608{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004609 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004610 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004611
Geoff Langbfdea662014-07-23 14:16:32 -04004612 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004613 if (context)
4614 {
4615 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004616 {
Geoff Langbfdea662014-07-23 14:16:32 -04004617 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004618 }
Geoff Langbfdea662014-07-23 14:16:32 -04004619
4620 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4621 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004622 }
4623}
4624
4625void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4626{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004627 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004628 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004629
Geoff Langbfdea662014-07-23 14:16:32 -04004630 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004631 if (context)
4632 {
4633 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634 {
Geoff Langbfdea662014-07-23 14:16:32 -04004635 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004636 }
Geoff Langbfdea662014-07-23 14:16:32 -04004637
4638 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4639 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004640 }
4641}
4642
4643void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4644{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004645 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004646 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004647
Geoff Langbfdea662014-07-23 14:16:32 -04004648 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004649 if (context)
4650 {
4651 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004652 {
Geoff Langbfdea662014-07-23 14:16:32 -04004653 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004654 }
Geoff Langbfdea662014-07-23 14:16:32 -04004655
4656 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4657 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004658 }
4659}
4660
4661void __stdcall glUseProgram(GLuint program)
4662{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004663 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004664
Geoff Langbfdea662014-07-23 14:16:32 -04004665 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004666 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004667 {
Geoff Langbfdea662014-07-23 14:16:32 -04004668 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004669
Geoff Langbfdea662014-07-23 14:16:32 -04004670 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004671 {
Geoff Langbfdea662014-07-23 14:16:32 -04004672 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004673 {
Geoff Langb1196682014-07-23 13:47:29 -04004674 context->recordError(gl::Error(GL_INVALID_OPERATION));
4675 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004676 }
Geoff Langbfdea662014-07-23 14:16:32 -04004677 else
4678 {
Geoff Langb1196682014-07-23 13:47:29 -04004679 context->recordError(gl::Error(GL_INVALID_VALUE));
4680 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004681 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004682 }
Geoff Langbfdea662014-07-23 14:16:32 -04004683
4684 if (program != 0 && !programObject->isLinked())
4685 {
Geoff Langb1196682014-07-23 13:47:29 -04004686 context->recordError(gl::Error(GL_INVALID_OPERATION));
4687 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004688 }
4689
4690 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004691 }
4692}
4693
4694void __stdcall glValidateProgram(GLuint program)
4695{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004696 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004697
Geoff Langbfdea662014-07-23 14:16:32 -04004698 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004699 if (context)
4700 {
4701 gl::Program *programObject = context->getProgram(program);
4702
4703 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004704 {
Geoff Langbfdea662014-07-23 14:16:32 -04004705 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004706 {
Geoff Langb1196682014-07-23 13:47:29 -04004707 context->recordError(gl::Error(GL_INVALID_OPERATION));
4708 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004709 }
Geoff Langbfdea662014-07-23 14:16:32 -04004710 else
4711 {
Geoff Langb1196682014-07-23 13:47:29 -04004712 context->recordError(gl::Error(GL_INVALID_VALUE));
4713 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004714 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004715 }
Geoff Langbfdea662014-07-23 14:16:32 -04004716
Brandon Jones43a53e22014-08-28 16:23:22 -07004717 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004718 }
4719}
4720
4721void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4722{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004723 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004724
Geoff Langbfdea662014-07-23 14:16:32 -04004725 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004726 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004727 {
Geoff Langb1196682014-07-23 13:47:29 -04004728 if (index >= gl::MAX_VERTEX_ATTRIBS)
4729 {
4730 context->recordError(gl::Error(GL_INVALID_VALUE));
4731 return;
4732 }
4733
Geoff Langbfdea662014-07-23 14:16:32 -04004734 GLfloat vals[4] = { x, 0, 0, 1 };
4735 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004736 }
4737}
4738
4739void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4740{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004741 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004742
Geoff Langbfdea662014-07-23 14:16:32 -04004743 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004744 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004745 {
Geoff Langb1196682014-07-23 13:47:29 -04004746 if (index >= gl::MAX_VERTEX_ATTRIBS)
4747 {
4748 context->recordError(gl::Error(GL_INVALID_VALUE));
4749 return;
4750 }
4751
Geoff Langbfdea662014-07-23 14:16:32 -04004752 GLfloat vals[4] = { values[0], 0, 0, 1 };
4753 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004754 }
4755}
4756
4757void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4758{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004759 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004760
Geoff Langbfdea662014-07-23 14:16:32 -04004761 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004762 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004763 {
Geoff Langb1196682014-07-23 13:47:29 -04004764 if (index >= gl::MAX_VERTEX_ATTRIBS)
4765 {
4766 context->recordError(gl::Error(GL_INVALID_VALUE));
4767 return;
4768 }
4769
Geoff Langbfdea662014-07-23 14:16:32 -04004770 GLfloat vals[4] = { x, y, 0, 1 };
4771 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004772 }
4773}
4774
4775void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004777 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004778
Geoff Langbfdea662014-07-23 14:16:32 -04004779 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004780 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004781 {
Geoff Langb1196682014-07-23 13:47:29 -04004782 if (index >= gl::MAX_VERTEX_ATTRIBS)
4783 {
4784 context->recordError(gl::Error(GL_INVALID_VALUE));
4785 return;
4786 }
4787
Geoff Langbfdea662014-07-23 14:16:32 -04004788 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4789 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004790 }
4791}
4792
4793void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4794{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004795 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 +00004796
Geoff Langbfdea662014-07-23 14:16:32 -04004797 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004798 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004799 {
Geoff Langb1196682014-07-23 13:47:29 -04004800 if (index >= gl::MAX_VERTEX_ATTRIBS)
4801 {
4802 context->recordError(gl::Error(GL_INVALID_VALUE));
4803 return;
4804 }
4805
Geoff Langbfdea662014-07-23 14:16:32 -04004806 GLfloat vals[4] = { x, y, z, 1 };
4807 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004808 }
4809}
4810
4811void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4812{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004813 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004814
Geoff Langbfdea662014-07-23 14:16:32 -04004815 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004816 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004817 {
Geoff Langb1196682014-07-23 13:47:29 -04004818 if (index >= gl::MAX_VERTEX_ATTRIBS)
4819 {
4820 context->recordError(gl::Error(GL_INVALID_VALUE));
4821 return;
4822 }
4823
Geoff Langbfdea662014-07-23 14:16:32 -04004824 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4825 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004826 }
4827}
4828
4829void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4830{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004831 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 +00004832
Geoff Langbfdea662014-07-23 14:16:32 -04004833 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004834 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004835 {
Geoff Langb1196682014-07-23 13:47:29 -04004836 if (index >= gl::MAX_VERTEX_ATTRIBS)
4837 {
4838 context->recordError(gl::Error(GL_INVALID_VALUE));
4839 return;
4840 }
4841
Geoff Langbfdea662014-07-23 14:16:32 -04004842 GLfloat vals[4] = { x, y, z, w };
4843 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004844 }
4845}
4846
4847void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4848{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004849 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004850
Geoff Langbfdea662014-07-23 14:16:32 -04004851 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004852 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004853 {
Geoff Langb1196682014-07-23 13:47:29 -04004854 if (index >= gl::MAX_VERTEX_ATTRIBS)
4855 {
4856 context->recordError(gl::Error(GL_INVALID_VALUE));
4857 return;
4858 }
4859
Geoff Langbfdea662014-07-23 14:16:32 -04004860 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004861 }
4862}
4863
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004864void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4865{
4866 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4867
Geoff Langbfdea662014-07-23 14:16:32 -04004868 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004869 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004870 {
Geoff Langb1196682014-07-23 13:47:29 -04004871 if (index >= gl::MAX_VERTEX_ATTRIBS)
4872 {
4873 context->recordError(gl::Error(GL_INVALID_VALUE));
4874 return;
4875 }
4876
Geoff Langbfdea662014-07-23 14:16:32 -04004877 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004878 }
4879}
4880
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004881void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004882{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004883 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004884 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004885 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004886
Geoff Langbfdea662014-07-23 14:16:32 -04004887 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004888 if (context)
4889 {
Geoff Langb1196682014-07-23 13:47:29 -04004890 if (index >= gl::MAX_VERTEX_ATTRIBS)
4891 {
4892 context->recordError(gl::Error(GL_INVALID_VALUE));
4893 return;
4894 }
4895
4896 if (size < 1 || size > 4)
4897 {
4898 context->recordError(gl::Error(GL_INVALID_VALUE));
4899 return;
4900 }
4901
4902 switch (type)
4903 {
4904 case GL_BYTE:
4905 case GL_UNSIGNED_BYTE:
4906 case GL_SHORT:
4907 case GL_UNSIGNED_SHORT:
4908 case GL_FIXED:
4909 case GL_FLOAT:
4910 break;
4911
4912 case GL_HALF_FLOAT:
4913 case GL_INT:
4914 case GL_UNSIGNED_INT:
4915 case GL_INT_2_10_10_10_REV:
4916 case GL_UNSIGNED_INT_2_10_10_10_REV:
4917 if (context->getClientVersion() < 3)
4918 {
4919 context->recordError(gl::Error(GL_INVALID_ENUM));
4920 return;
4921 }
4922 break;
4923
4924 default:
4925 context->recordError(gl::Error(GL_INVALID_ENUM));
4926 return;
4927 }
4928
4929 if (stride < 0)
4930 {
4931 context->recordError(gl::Error(GL_INVALID_VALUE));
4932 return;
4933 }
4934
4935 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4936 {
4937 context->recordError(gl::Error(GL_INVALID_OPERATION));
4938 return;
4939 }
4940
Geoff Langbfdea662014-07-23 14:16:32 -04004941 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4942 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4943 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4944 // and the pointer argument is not NULL.
4945 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004946 {
Geoff Langb1196682014-07-23 13:47:29 -04004947 context->recordError(gl::Error(GL_INVALID_OPERATION));
4948 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004949 }
4950
Geoff Langbfdea662014-07-23 14:16:32 -04004951 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4952 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004953 }
4954}
4955
4956void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4957{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004958 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 +00004959
Geoff Langbfdea662014-07-23 14:16:32 -04004960 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004961 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004962 {
Geoff Langb1196682014-07-23 13:47:29 -04004963 if (width < 0 || height < 0)
4964 {
4965 context->recordError(gl::Error(GL_INVALID_VALUE));
4966 return;
4967 }
4968
Geoff Langbfdea662014-07-23 14:16:32 -04004969 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004970 }
4971}
4972
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004973// OpenGL ES 3.0 functions
4974
4975void __stdcall glReadBuffer(GLenum mode)
4976{
4977 EVENT("(GLenum mode = 0x%X)", mode);
4978
Geoff Langbfdea662014-07-23 14:16:32 -04004979 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004980 if (context)
4981 {
4982 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004983 {
Geoff Langb1196682014-07-23 13:47:29 -04004984 context->recordError(gl::Error(GL_INVALID_OPERATION));
4985 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004986 }
Geoff Langbfdea662014-07-23 14:16:32 -04004987
4988 // glReadBuffer
4989 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004990 }
4991}
4992
4993void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4994{
4995 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4996 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4997
Geoff Langbfdea662014-07-23 14:16:32 -04004998 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004999 if (context)
5000 {
5001 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005002 {
Geoff Langb1196682014-07-23 13:47:29 -04005003 context->recordError(gl::Error(GL_INVALID_OPERATION));
5004 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005005 }
Geoff Langbfdea662014-07-23 14:16:32 -04005006
5007 // glDrawRangeElements
5008 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005009 }
5010}
5011
5012void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
5013{
5014 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
5015 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
5016 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5017 target, level, internalformat, width, height, depth, border, format, type, pixels);
5018
Geoff Langbfdea662014-07-23 14:16:32 -04005019 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005020 if (context)
5021 {
5022 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005023 {
Geoff Langb1196682014-07-23 13:47:29 -04005024 context->recordError(gl::Error(GL_INVALID_OPERATION));
5025 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005026 }
Geoff Langbfdea662014-07-23 14:16:32 -04005027
5028 // validateES3TexImageFormat sets the error code if there is an error
5029 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
5030 0, 0, 0, width, height, depth, border, format, type, pixels))
5031 {
5032 return;
5033 }
5034
5035 switch(target)
5036 {
5037 case GL_TEXTURE_3D:
5038 {
5039 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005040 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5041 if (error.isError())
5042 {
5043 context->recordError(error);
5044 return;
5045 }
Geoff Langbfdea662014-07-23 14:16:32 -04005046 }
5047 break;
5048
5049 case GL_TEXTURE_2D_ARRAY:
5050 {
5051 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005052 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5053 if (error.isError())
5054 {
5055 context->recordError(error);
5056 return;
5057 }
Geoff Langbfdea662014-07-23 14:16:32 -04005058 }
5059 break;
5060
5061 default:
Geoff Langb1196682014-07-23 13:47:29 -04005062 context->recordError(gl::Error(GL_INVALID_ENUM));
5063 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005065 }
5066}
5067
5068void __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)
5069{
5070 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5071 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5072 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5073 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
5074
Geoff Langbfdea662014-07-23 14:16:32 -04005075 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005076 if (context)
5077 {
5078 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005079 {
Geoff Langb1196682014-07-23 13:47:29 -04005080 context->recordError(gl::Error(GL_INVALID_OPERATION));
5081 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005082 }
Geoff Langbfdea662014-07-23 14:16:32 -04005083
5084 // validateES3TexImageFormat sets the error code if there is an error
5085 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5086 xoffset, yoffset, zoffset, width, height, depth, 0,
5087 format, type, pixels))
5088 {
5089 return;
5090 }
5091
5092 // Zero sized uploads are valid but no-ops
5093 if (width == 0 || height == 0 || depth == 0)
5094 {
5095 return;
5096 }
5097
5098 switch(target)
5099 {
5100 case GL_TEXTURE_3D:
5101 {
5102 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005103 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5104 if (error.isError())
5105 {
5106 context->recordError(error);
5107 return;
5108 }
Geoff Langbfdea662014-07-23 14:16:32 -04005109 }
5110 break;
5111
5112 case GL_TEXTURE_2D_ARRAY:
5113 {
5114 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005115 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5116 if (error.isError())
5117 {
5118 context->recordError(error);
5119 return;
5120 }
Geoff Langbfdea662014-07-23 14:16:32 -04005121 }
5122 break;
5123
5124 default:
Geoff Langb1196682014-07-23 13:47:29 -04005125 context->recordError(gl::Error(GL_INVALID_ENUM));
5126 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005127 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005128 }
5129}
5130
5131void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5132{
5133 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5134 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5135 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5136
Geoff Langbfdea662014-07-23 14:16:32 -04005137 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005138 if (context)
5139 {
5140 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005141 {
Geoff Langb1196682014-07-23 13:47:29 -04005142 context->recordError(gl::Error(GL_INVALID_OPERATION));
5143 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005144 }
Geoff Langbfdea662014-07-23 14:16:32 -04005145
5146 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5147 x, y, width, height, 0))
5148 {
5149 return;
5150 }
5151
5152 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5153 gl::Texture *texture = NULL;
5154 switch (target)
5155 {
5156 case GL_TEXTURE_3D:
5157 texture = context->getTexture3D();
5158 break;
5159
5160 case GL_TEXTURE_2D_ARRAY:
5161 texture = context->getTexture2DArray();
5162 break;
5163
5164 default:
Geoff Langb1196682014-07-23 13:47:29 -04005165 context->recordError(gl::Error(GL_INVALID_ENUM));
5166 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005167 }
5168
5169 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005170 }
5171}
5172
5173void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5174{
Geoff Langeef52cc2013-10-16 15:07:39 -04005175 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 +00005176 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5177 "const GLvoid* data = 0x%0.8p)",
5178 target, level, internalformat, width, height, depth, border, imageSize, data);
5179
Geoff Langbfdea662014-07-23 14:16:32 -04005180 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005181 if (context)
5182 {
5183 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005184 {
Geoff Langb1196682014-07-23 13:47:29 -04005185 context->recordError(gl::Error(GL_INVALID_OPERATION));
5186 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005187 }
Geoff Langbfdea662014-07-23 14:16:32 -04005188
Geoff Lang5d601382014-07-22 15:14:06 -04005189 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5190 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005191 {
Geoff Langb1196682014-07-23 13:47:29 -04005192 context->recordError(gl::Error(GL_INVALID_VALUE));
5193 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005194 }
5195
5196 // validateES3TexImageFormat sets the error code if there is an error
5197 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5198 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5199 {
5200 return;
5201 }
5202
5203 switch(target)
5204 {
5205 case GL_TEXTURE_3D:
5206 {
5207 gl::Texture3D *texture = context->getTexture3D();
Geoff Langb5348332014-09-02 13:16:34 -04005208 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5209 if (error.isError())
5210 {
5211 context->recordError(error);
5212 return;
5213 }
Geoff Langbfdea662014-07-23 14:16:32 -04005214 }
5215 break;
5216
5217 case GL_TEXTURE_2D_ARRAY:
5218 {
5219 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Langb5348332014-09-02 13:16:34 -04005220 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5221 if (error.isError())
5222 {
5223 context->recordError(error);
5224 return;
5225 }
Geoff Langbfdea662014-07-23 14:16:32 -04005226 }
5227 break;
5228
5229 default:
Geoff Langb1196682014-07-23 13:47:29 -04005230 context->recordError(gl::Error(GL_INVALID_ENUM));
5231 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005232 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005233 }
5234}
5235
5236void __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)
5237{
5238 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5239 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5240 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5241 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5242
Geoff Langbfdea662014-07-23 14:16:32 -04005243 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005244 if (context)
5245 {
5246 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005247 {
Geoff Langb1196682014-07-23 13:47:29 -04005248 context->recordError(gl::Error(GL_INVALID_OPERATION));
5249 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005250 }
Geoff Langbfdea662014-07-23 14:16:32 -04005251
Geoff Lang5d601382014-07-22 15:14:06 -04005252 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5253 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005254 {
Geoff Langb1196682014-07-23 13:47:29 -04005255 context->recordError(gl::Error(GL_INVALID_VALUE));
5256 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005257 }
5258
5259 if (!data)
5260 {
Geoff Langb1196682014-07-23 13:47:29 -04005261 context->recordError(gl::Error(GL_INVALID_VALUE));
5262 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005263 }
5264
5265 // validateES3TexImageFormat sets the error code if there is an error
5266 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5267 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5268 {
5269 return;
5270 }
5271
5272 // Zero sized uploads are valid but no-ops
5273 if (width == 0 || height == 0)
5274 {
5275 return;
5276 }
5277
5278 switch(target)
5279 {
5280 case GL_TEXTURE_3D:
5281 {
5282 gl::Texture3D *texture = context->getTexture3D();
Geoff Langb5348332014-09-02 13:16:34 -04005283 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5284 format, imageSize, data);
5285 if (error.isError())
5286 {
5287 context->recordError(error);
5288 return;
5289 }
Geoff Langbfdea662014-07-23 14:16:32 -04005290 }
5291 break;
5292
5293 case GL_TEXTURE_2D_ARRAY:
5294 {
5295 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Langb5348332014-09-02 13:16:34 -04005296 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5297 format, imageSize, data);
5298 if (error.isError())
5299 {
5300 context->recordError(error);
5301 return;
5302 }
Geoff Langbfdea662014-07-23 14:16:32 -04005303 }
5304 break;
5305
Geoff Langb1196682014-07-23 13:47:29 -04005306 default:
5307 context->recordError(gl::Error(GL_INVALID_ENUM));
5308 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005309 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005310 }
5311}
5312
5313void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5314{
5315 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5316
Geoff Langbfdea662014-07-23 14:16:32 -04005317 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005318 if (context)
5319 {
5320 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005321 {
Geoff Langb1196682014-07-23 13:47:29 -04005322 context->recordError(gl::Error(GL_INVALID_OPERATION));
5323 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005324 }
Geoff Langbfdea662014-07-23 14:16:32 -04005325
5326 if (n < 0)
5327 {
Geoff Langb1196682014-07-23 13:47:29 -04005328 context->recordError(gl::Error(GL_INVALID_VALUE));
5329 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005330 }
5331
5332 for (GLsizei i = 0; i < n; i++)
5333 {
5334 ids[i] = context->createQuery();
5335 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005336 }
5337}
5338
5339void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5340{
5341 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5342
Geoff Langbfdea662014-07-23 14:16:32 -04005343 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005344 if (context)
5345 {
5346 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005347 {
Geoff Langb1196682014-07-23 13:47:29 -04005348 context->recordError(gl::Error(GL_INVALID_OPERATION));
5349 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005350 }
Geoff Langbfdea662014-07-23 14:16:32 -04005351
5352 if (n < 0)
5353 {
Geoff Langb1196682014-07-23 13:47:29 -04005354 context->recordError(gl::Error(GL_INVALID_VALUE));
5355 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005356 }
5357
5358 for (GLsizei i = 0; i < n; i++)
5359 {
5360 context->deleteQuery(ids[i]);
5361 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005362 }
5363}
5364
5365GLboolean __stdcall glIsQuery(GLuint id)
5366{
5367 EVENT("(GLuint id = %u)", id);
5368
Geoff Langbfdea662014-07-23 14:16:32 -04005369 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005370 if (context)
5371 {
5372 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005373 {
Geoff Langb1196682014-07-23 13:47:29 -04005374 context->recordError(gl::Error(GL_INVALID_OPERATION));
5375 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005376 }
Geoff Langbfdea662014-07-23 14:16:32 -04005377
5378 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005379 }
5380
5381 return GL_FALSE;
5382}
5383
5384void __stdcall glBeginQuery(GLenum target, GLuint id)
5385{
5386 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5387
Geoff Langbfdea662014-07-23 14:16:32 -04005388 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005389 if (context)
5390 {
5391 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005392 {
Geoff Langb1196682014-07-23 13:47:29 -04005393 context->recordError(gl::Error(GL_INVALID_OPERATION));
5394 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005395 }
Geoff Langbfdea662014-07-23 14:16:32 -04005396
5397 if (!ValidateBeginQuery(context, target, id))
5398 {
5399 return;
5400 }
Geoff Lang5aad9672014-09-08 11:10:42 -04005401
5402 gl::Error error = context->beginQuery(target, id);
5403 if (error.isError())
5404 {
5405 context->recordError(error);
5406 return;
5407 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005408 }
5409}
5410
5411void __stdcall glEndQuery(GLenum target)
5412{
5413 EVENT("(GLenum target = 0x%X)", target);
5414
Geoff Langbfdea662014-07-23 14:16:32 -04005415 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005416 if (context)
5417 {
5418 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005419 {
Geoff Langb1196682014-07-23 13:47:29 -04005420 context->recordError(gl::Error(GL_INVALID_OPERATION));
5421 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005422 }
Geoff Langbfdea662014-07-23 14:16:32 -04005423
5424 if (!ValidateEndQuery(context, target))
5425 {
5426 return;
5427 }
5428
Geoff Lang5aad9672014-09-08 11:10:42 -04005429 gl::Error error = context->endQuery(target);
5430 if (error.isError())
5431 {
5432 context->recordError(error);
5433 return;
5434 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005435 }
5436}
5437
5438void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5439{
5440 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5441
Geoff Langbfdea662014-07-23 14:16:32 -04005442 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005443 if (context)
5444 {
5445 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005446 {
Geoff Langb1196682014-07-23 13:47:29 -04005447 context->recordError(gl::Error(GL_INVALID_OPERATION));
5448 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005449 }
Geoff Langbfdea662014-07-23 14:16:32 -04005450
5451 if (!ValidQueryType(context, target))
5452 {
Geoff Langb1196682014-07-23 13:47:29 -04005453 context->recordError(gl::Error(GL_INVALID_ENUM));
5454 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005455 }
5456
5457 switch (pname)
5458 {
5459 case GL_CURRENT_QUERY:
5460 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5461 break;
5462
5463 default:
Geoff Langb1196682014-07-23 13:47:29 -04005464 context->recordError(gl::Error(GL_INVALID_ENUM));
5465 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005466 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005467 }
5468}
5469
5470void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5471{
5472 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5473
Geoff Langbfdea662014-07-23 14:16:32 -04005474 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005475 if (context)
5476 {
5477 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005478 {
Geoff Langb1196682014-07-23 13:47:29 -04005479 context->recordError(gl::Error(GL_INVALID_OPERATION));
5480 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005481 }
Geoff Langbfdea662014-07-23 14:16:32 -04005482
5483 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5484
5485 if (!queryObject)
5486 {
Geoff Langb1196682014-07-23 13:47:29 -04005487 context->recordError(gl::Error(GL_INVALID_OPERATION));
5488 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005489 }
5490
5491 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5492 {
Geoff Langb1196682014-07-23 13:47:29 -04005493 context->recordError(gl::Error(GL_INVALID_OPERATION));
5494 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005495 }
5496
5497 switch(pname)
5498 {
Geoff Lang5aad9672014-09-08 11:10:42 -04005499 case GL_QUERY_RESULT_EXT:
5500 {
5501 gl::Error error = queryObject->getResult(params);
5502 if (error.isError())
5503 {
5504 context->recordError(error);
5505 return;
5506 }
5507 }
Geoff Langbfdea662014-07-23 14:16:32 -04005508 break;
Geoff Langb1196682014-07-23 13:47:29 -04005509
Geoff Lang5aad9672014-09-08 11:10:42 -04005510 case GL_QUERY_RESULT_AVAILABLE_EXT:
5511 {
5512 gl::Error error = queryObject->isResultAvailable(params);
5513 if (error.isError())
5514 {
5515 context->recordError(error);
5516 return;
5517 }
5518 }
Geoff Langbfdea662014-07-23 14:16:32 -04005519 break;
Geoff Langb1196682014-07-23 13:47:29 -04005520
Geoff Langbfdea662014-07-23 14:16:32 -04005521 default:
Geoff Langb1196682014-07-23 13:47:29 -04005522 context->recordError(gl::Error(GL_INVALID_ENUM));
5523 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005524 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005525 }
5526}
5527
5528GLboolean __stdcall glUnmapBuffer(GLenum target)
5529{
5530 EVENT("(GLenum target = 0x%X)", target);
5531
Geoff Langbfdea662014-07-23 14:16:32 -04005532 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005533 if (context)
5534 {
5535 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005536 {
Geoff Langb1196682014-07-23 13:47:29 -04005537 context->recordError(gl::Error(GL_INVALID_OPERATION));
5538 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005539 }
Geoff Langbfdea662014-07-23 14:16:32 -04005540
5541 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005542 }
5543
5544 return GL_FALSE;
5545}
5546
5547void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5548{
5549 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5550
Geoff Langbfdea662014-07-23 14:16:32 -04005551 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005552 if (context)
5553 {
5554 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005555 {
Geoff Langb1196682014-07-23 13:47:29 -04005556 context->recordError(gl::Error(GL_INVALID_OPERATION));
5557 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005558 }
Geoff Langbfdea662014-07-23 14:16:32 -04005559
5560 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005561 }
5562}
5563
5564void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5565{
Geoff Langbfdea662014-07-23 14:16:32 -04005566 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005567 if (context)
5568 {
5569 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005570 {
Geoff Langb1196682014-07-23 13:47:29 -04005571 context->recordError(gl::Error(GL_INVALID_OPERATION));
5572 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005573 }
Geoff Langbfdea662014-07-23 14:16:32 -04005574
5575 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005576 }
5577}
5578
5579void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5580{
5581 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5582 location, count, transpose, value);
5583
Geoff Langbfdea662014-07-23 14:16:32 -04005584 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005585 if (context)
5586 {
5587 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005588 {
Geoff Langbfdea662014-07-23 14:16:32 -04005589 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005590 }
Geoff Langbfdea662014-07-23 14:16:32 -04005591
5592 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5593 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005594 }
5595}
5596
5597void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5598{
5599 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5600 location, count, transpose, value);
5601
Geoff Langbfdea662014-07-23 14:16:32 -04005602 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005603 if (context)
5604 {
5605 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005606 {
Geoff Langbfdea662014-07-23 14:16:32 -04005607 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005608 }
Geoff Langbfdea662014-07-23 14:16:32 -04005609
5610 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5611 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005612 }
5613}
5614
5615void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5616{
5617 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5618 location, count, transpose, value);
5619
Geoff Langbfdea662014-07-23 14:16:32 -04005620 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005621 if (context)
5622 {
5623 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005624 {
Geoff Langbfdea662014-07-23 14:16:32 -04005625 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005626 }
Geoff Langbfdea662014-07-23 14:16:32 -04005627
5628 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5629 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005630 }
5631}
5632
5633void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5634{
5635 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5636 location, count, transpose, value);
5637
Geoff Langbfdea662014-07-23 14:16:32 -04005638 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005639 if (context)
5640 {
5641 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005642 {
Geoff Langbfdea662014-07-23 14:16:32 -04005643 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005644 }
Geoff Langbfdea662014-07-23 14:16:32 -04005645
5646 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5647 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005648 }
5649}
5650
5651void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5652{
5653 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5654 location, count, transpose, value);
5655
Geoff Langbfdea662014-07-23 14:16:32 -04005656 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005657 if (context)
5658 {
5659 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005660 {
Geoff Langbfdea662014-07-23 14:16:32 -04005661 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005662 }
Geoff Langbfdea662014-07-23 14:16:32 -04005663
5664 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5665 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005666 }
5667}
5668
5669void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5670{
5671 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5672 location, count, transpose, value);
5673
Geoff Langbfdea662014-07-23 14:16:32 -04005674 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005675 if (context)
5676 {
5677 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005678 {
Geoff Langbfdea662014-07-23 14:16:32 -04005679 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005680 }
Geoff Langbfdea662014-07-23 14:16:32 -04005681
5682 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5683 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005684 }
5685}
5686
5687void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5688{
5689 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5690 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5691 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5692
Geoff Langbfdea662014-07-23 14:16:32 -04005693 gl::Context *context = gl::getNonLostContext();
5694 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005695 {
Geoff Langbfdea662014-07-23 14:16:32 -04005696 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005697 {
Geoff Langb1196682014-07-23 13:47:29 -04005698 context->recordError(gl::Error(GL_INVALID_OPERATION));
5699 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005700 }
Geoff Langbfdea662014-07-23 14:16:32 -04005701
5702 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5703 dstX0, dstY0, dstX1, dstY1, mask, filter,
5704 false))
5705 {
5706 return;
5707 }
5708
Geoff Lang64839152014-08-26 16:23:25 -04005709 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5710 mask, filter);
5711 if (error.isError())
5712 {
5713 context->recordError(error);
5714 return;
5715 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005716 }
5717}
5718
5719void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5720{
5721 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5722 target, samples, internalformat, width, height);
5723
Geoff Langbfdea662014-07-23 14:16:32 -04005724 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005725 if (context)
5726 {
5727 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005728 {
Geoff Langb1196682014-07-23 13:47:29 -04005729 context->recordError(gl::Error(GL_INVALID_OPERATION));
5730 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005731 }
Geoff Langbfdea662014-07-23 14:16:32 -04005732
5733 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5734 width, height, false))
5735 {
5736 return;
5737 }
5738
5739 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005740 }
5741}
5742
5743void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5744{
5745 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5746 target, attachment, texture, level, layer);
5747
Geoff Langbfdea662014-07-23 14:16:32 -04005748 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005749 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005750 {
Geoff Langbfdea662014-07-23 14:16:32 -04005751 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5752 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005753 {
Geoff Langbfdea662014-07-23 14:16:32 -04005754 return;
5755 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005756
Geoff Langbfdea662014-07-23 14:16:32 -04005757 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5758 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005759
Geoff Langbfdea662014-07-23 14:16:32 -04005760 gl::Texture *textureObject = context->getTexture(texture);
5761 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005762
Geoff Langbfdea662014-07-23 14:16:32 -04005763 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5764 {
5765 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5766 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5767 }
5768 else
5769 {
5770 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005771 {
Geoff Langbfdea662014-07-23 14:16:32 -04005772 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5773 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5774 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005775 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005776 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005777 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005778}
5779
5780GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5781{
5782 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5783 target, offset, length, access);
5784
Geoff Langbfdea662014-07-23 14:16:32 -04005785 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005786 if (context)
5787 {
5788 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005789 {
Geoff Langb1196682014-07-23 13:47:29 -04005790 context->recordError(gl::Error(GL_INVALID_OPERATION));
5791 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005792 }
Geoff Langbfdea662014-07-23 14:16:32 -04005793
5794 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005795 }
5796
5797 return NULL;
5798}
5799
5800void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5801{
5802 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5803
Geoff Langbfdea662014-07-23 14:16:32 -04005804 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005805 if (context)
5806 {
5807 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005808 {
Geoff Langb1196682014-07-23 13:47:29 -04005809 context->recordError(gl::Error(GL_INVALID_OPERATION));
5810 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005811 }
Geoff Langbfdea662014-07-23 14:16:32 -04005812
5813 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005814 }
5815}
5816
5817void __stdcall glBindVertexArray(GLuint array)
5818{
5819 EVENT("(GLuint array = %u)", array);
5820
Geoff Langbfdea662014-07-23 14:16:32 -04005821 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005822 if (context)
5823 {
5824 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005825 {
Geoff Langb1196682014-07-23 13:47:29 -04005826 context->recordError(gl::Error(GL_INVALID_OPERATION));
5827 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005828 }
Geoff Langbfdea662014-07-23 14:16:32 -04005829
5830 gl::VertexArray *vao = context->getVertexArray(array);
5831
5832 if (!vao)
5833 {
5834 // The default VAO should always exist
5835 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005836 context->recordError(gl::Error(GL_INVALID_OPERATION));
5837 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005838 }
5839
5840 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005841 }
5842}
5843
5844void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5845{
5846 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5847
Geoff Langbfdea662014-07-23 14:16:32 -04005848 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005849 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005850 {
Geoff Langbfdea662014-07-23 14:16:32 -04005851 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005852 {
Geoff Langb1196682014-07-23 13:47:29 -04005853 context->recordError(gl::Error(GL_INVALID_OPERATION));
5854 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005855 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005856
Geoff Langbfdea662014-07-23 14:16:32 -04005857 if (n < 0)
5858 {
Geoff Langb1196682014-07-23 13:47:29 -04005859 context->recordError(gl::Error(GL_INVALID_VALUE));
5860 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005861 }
Jamie Madilld1028542013-07-02 11:57:04 -04005862
Geoff Langbfdea662014-07-23 14:16:32 -04005863 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5864 {
5865 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005866 {
Geoff Langbfdea662014-07-23 14:16:32 -04005867 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005868 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005869 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005871}
5872
5873void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5874{
5875 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5876
Geoff Langbfdea662014-07-23 14:16:32 -04005877 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005878 if (context)
5879 {
5880 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005881 {
Geoff Langb1196682014-07-23 13:47:29 -04005882 context->recordError(gl::Error(GL_INVALID_OPERATION));
5883 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005884 }
Geoff Langbfdea662014-07-23 14:16:32 -04005885
5886 if (n < 0)
5887 {
Geoff Langb1196682014-07-23 13:47:29 -04005888 context->recordError(gl::Error(GL_INVALID_VALUE));
5889 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005890 }
5891
5892 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5893 {
5894 arrays[arrayIndex] = context->createVertexArray();
5895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005896 }
5897}
5898
5899GLboolean __stdcall glIsVertexArray(GLuint array)
5900{
5901 EVENT("(GLuint array = %u)", array);
5902
Geoff Langbfdea662014-07-23 14:16:32 -04005903 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005904 if (context)
5905 {
5906 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005907 {
Geoff Langb1196682014-07-23 13:47:29 -04005908 context->recordError(gl::Error(GL_INVALID_OPERATION));
5909 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005910 }
Geoff Langbfdea662014-07-23 14:16:32 -04005911
5912 if (array == 0)
5913 {
5914 return GL_FALSE;
5915 }
5916
5917 gl::VertexArray *vao = context->getVertexArray(array);
5918
5919 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005920 }
5921
5922 return GL_FALSE;
5923}
5924
5925void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5926{
5927 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5928 target, index, data);
5929
Geoff Langbfdea662014-07-23 14:16:32 -04005930 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005931 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005932 {
Geoff Langbfdea662014-07-23 14:16:32 -04005933 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005934 {
Geoff Langb1196682014-07-23 13:47:29 -04005935 context->recordError(gl::Error(GL_INVALID_OPERATION));
5936 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005937 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005938
Geoff Lang3a61c322014-07-10 13:01:54 -04005939 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005940 switch (target)
5941 {
5942 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5943 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5944 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005945 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5946 {
Geoff Langb1196682014-07-23 13:47:29 -04005947 context->recordError(gl::Error(GL_INVALID_VALUE));
5948 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005949 }
Geoff Langbfdea662014-07-23 14:16:32 -04005950 break;
Geoff Langb1196682014-07-23 13:47:29 -04005951
Geoff Langbfdea662014-07-23 14:16:32 -04005952 case GL_UNIFORM_BUFFER_START:
5953 case GL_UNIFORM_BUFFER_SIZE:
5954 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005955 if (index >= caps.maxCombinedUniformBlocks)
5956 {
Geoff Langb1196682014-07-23 13:47:29 -04005957 context->recordError(gl::Error(GL_INVALID_VALUE));
5958 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005959 }
Geoff Langbfdea662014-07-23 14:16:32 -04005960 break;
Geoff Langb1196682014-07-23 13:47:29 -04005961
Geoff Langbfdea662014-07-23 14:16:32 -04005962 default:
Geoff Langb1196682014-07-23 13:47:29 -04005963 context->recordError(gl::Error(GL_INVALID_ENUM));
5964 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005965 }
5966
5967 if (!(context->getIndexedIntegerv(target, index, data)))
5968 {
5969 GLenum nativeType;
5970 unsigned int numParams = 0;
5971 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005972 {
5973 context->recordError(gl::Error(GL_INVALID_ENUM));
5974 return;
5975 }
Shannon Woods15934d52013-08-19 14:28:49 -04005976
Geoff Langbfdea662014-07-23 14:16:32 -04005977 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005978 {
Geoff Langbfdea662014-07-23 14:16:32 -04005979 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005980 }
Geoff Langbfdea662014-07-23 14:16:32 -04005981
5982 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005983 {
Geoff Langbfdea662014-07-23 14:16:32 -04005984 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5985 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5986 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005987
Geoff Langbfdea662014-07-23 14:16:32 -04005988 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005989
Geoff Langbfdea662014-07-23 14:16:32 -04005990 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005991 {
Geoff Langbfdea662014-07-23 14:16:32 -04005992 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5993 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005994 }
Geoff Langbfdea662014-07-23 14:16:32 -04005995
5996 delete [] int64Params;
5997 }
5998 else
5999 {
6000 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04006001 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006002 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006003 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006004}
6005
6006void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
6007{
6008 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
6009
Geoff Langbfdea662014-07-23 14:16:32 -04006010 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006011 if (context)
6012 {
6013 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006014 {
Geoff Langb1196682014-07-23 13:47:29 -04006015 context->recordError(gl::Error(GL_INVALID_OPERATION));
6016 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006017 }
Geoff Langbfdea662014-07-23 14:16:32 -04006018
6019 switch (primitiveMode)
6020 {
6021 case GL_TRIANGLES:
6022 case GL_LINES:
6023 case GL_POINTS:
6024 break;
Geoff Langb1196682014-07-23 13:47:29 -04006025
Geoff Langbfdea662014-07-23 14:16:32 -04006026 default:
Geoff Langb1196682014-07-23 13:47:29 -04006027 context->recordError(gl::Error(GL_INVALID_ENUM));
6028 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006029 }
6030
6031 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6032 ASSERT(transformFeedback != NULL);
6033
6034 if (transformFeedback->isStarted())
6035 {
Geoff Langb1196682014-07-23 13:47:29 -04006036 context->recordError(gl::Error(GL_INVALID_OPERATION));
6037 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006038 }
6039
6040 if (transformFeedback->isPaused())
6041 {
6042 transformFeedback->resume();
6043 }
6044 else
6045 {
6046 transformFeedback->start(primitiveMode);
6047 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006048 }
6049}
6050
6051void __stdcall glEndTransformFeedback(void)
6052{
6053 EVENT("(void)");
6054
Geoff Langbfdea662014-07-23 14:16:32 -04006055 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006056 if (context)
6057 {
6058 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006059 {
Geoff Langb1196682014-07-23 13:47:29 -04006060 context->recordError(gl::Error(GL_INVALID_OPERATION));
6061 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006062 }
Geoff Langbfdea662014-07-23 14:16:32 -04006063
6064 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6065 ASSERT(transformFeedback != NULL);
6066
6067 if (!transformFeedback->isStarted())
6068 {
Geoff Langb1196682014-07-23 13:47:29 -04006069 context->recordError(gl::Error(GL_INVALID_OPERATION));
6070 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006071 }
6072
6073 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006074 }
6075}
6076
6077void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
6078{
6079 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
6080 target, index, buffer, offset, size);
6081
Geoff Langbfdea662014-07-23 14:16:32 -04006082 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006083 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006084 {
Geoff Langbfdea662014-07-23 14:16:32 -04006085 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006086 {
Geoff Langb1196682014-07-23 13:47:29 -04006087 context->recordError(gl::Error(GL_INVALID_OPERATION));
6088 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006089 }
6090
Geoff Lang3a61c322014-07-10 13:01:54 -04006091 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006092 switch (target)
6093 {
6094 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006095 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006096 {
Geoff Langb1196682014-07-23 13:47:29 -04006097 context->recordError(gl::Error(GL_INVALID_VALUE));
6098 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006099 }
Geoff Langbfdea662014-07-23 14:16:32 -04006100 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006101
Geoff Langbfdea662014-07-23 14:16:32 -04006102 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006103 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006104 {
Geoff Langb1196682014-07-23 13:47:29 -04006105 context->recordError(gl::Error(GL_INVALID_VALUE));
6106 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006107 }
Geoff Langbfdea662014-07-23 14:16:32 -04006108 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006109
Geoff Langbfdea662014-07-23 14:16:32 -04006110 default:
Geoff Langb1196682014-07-23 13:47:29 -04006111 context->recordError(gl::Error(GL_INVALID_ENUM));
6112 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006113 }
6114
6115 if (buffer != 0 && size <= 0)
6116 {
Geoff Langb1196682014-07-23 13:47:29 -04006117 context->recordError(gl::Error(GL_INVALID_VALUE));
6118 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006119 }
6120
6121 switch (target)
6122 {
6123 case GL_TRANSFORM_FEEDBACK_BUFFER:
6124
6125 // size and offset must be a multiple of 4
6126 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006127 {
Geoff Langb1196682014-07-23 13:47:29 -04006128 context->recordError(gl::Error(GL_INVALID_VALUE));
6129 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006130 }
6131
Geoff Langbfdea662014-07-23 14:16:32 -04006132 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
6133 context->bindGenericTransformFeedbackBuffer(buffer);
6134 break;
6135
6136 case GL_UNIFORM_BUFFER:
6137
6138 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006139 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006140 {
Geoff Langb1196682014-07-23 13:47:29 -04006141 context->recordError(gl::Error(GL_INVALID_VALUE));
6142 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006143 }
Geoff Langbfdea662014-07-23 14:16:32 -04006144
6145 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6146 context->bindGenericUniformBuffer(buffer);
6147 break;
6148
6149 default:
6150 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006151 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006152 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006153}
6154
6155void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
6156{
6157 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6158 target, index, buffer);
6159
Geoff Langbfdea662014-07-23 14:16:32 -04006160 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006161 if (context)
6162 {
6163 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006164 {
Geoff Langb1196682014-07-23 13:47:29 -04006165 context->recordError(gl::Error(GL_INVALID_OPERATION));
6166 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006167 }
Geoff Langbfdea662014-07-23 14:16:32 -04006168
Geoff Lang3a61c322014-07-10 13:01:54 -04006169 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006170 switch (target)
6171 {
6172 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006173 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006174 {
Geoff Langb1196682014-07-23 13:47:29 -04006175 context->recordError(gl::Error(GL_INVALID_VALUE));
6176 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006177 }
6178 break;
6179
6180 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006181 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006182 {
Geoff Langb1196682014-07-23 13:47:29 -04006183 context->recordError(gl::Error(GL_INVALID_VALUE));
6184 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006185 }
6186 break;
6187
6188 default:
Geoff Langb1196682014-07-23 13:47:29 -04006189 context->recordError(gl::Error(GL_INVALID_ENUM));
6190 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006191 }
6192
6193 switch (target)
6194 {
6195 case GL_TRANSFORM_FEEDBACK_BUFFER:
6196 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6197 context->bindGenericTransformFeedbackBuffer(buffer);
6198 break;
6199
6200 case GL_UNIFORM_BUFFER:
6201 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6202 context->bindGenericUniformBuffer(buffer);
6203 break;
6204
6205 default:
6206 UNREACHABLE();
6207 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006208 }
6209}
6210
6211void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6212{
6213 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6214 program, count, varyings, bufferMode);
6215
Geoff Langbfdea662014-07-23 14:16:32 -04006216 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006217 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006218 {
Geoff Langbfdea662014-07-23 14:16:32 -04006219 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006220 {
Geoff Langb1196682014-07-23 13:47:29 -04006221 context->recordError(gl::Error(GL_INVALID_OPERATION));
6222 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006223 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006224
Geoff Langbfdea662014-07-23 14:16:32 -04006225 if (count < 0)
6226 {
Geoff Langb1196682014-07-23 13:47:29 -04006227 context->recordError(gl::Error(GL_INVALID_VALUE));
6228 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006229 }
6230
Geoff Lang05881a02014-07-10 14:05:30 -04006231 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006232 switch (bufferMode)
6233 {
6234 case GL_INTERLEAVED_ATTRIBS:
6235 break;
6236 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006237 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006238 {
Geoff Langb1196682014-07-23 13:47:29 -04006239 context->recordError(gl::Error(GL_INVALID_VALUE));
6240 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006241 }
Geoff Langbfdea662014-07-23 14:16:32 -04006242 break;
6243 default:
Geoff Langb1196682014-07-23 13:47:29 -04006244 context->recordError(gl::Error(GL_INVALID_ENUM));
6245 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006246 }
Geoff Langbfdea662014-07-23 14:16:32 -04006247
6248 if (!gl::ValidProgram(context, program))
6249 {
6250 return;
6251 }
6252
6253 gl::Program *programObject = context->getProgram(program);
6254 ASSERT(programObject);
6255
6256 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006257 }
6258}
6259
6260void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6261{
6262 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6263 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6264 program, index, bufSize, length, size, type, name);
6265
Geoff Langbfdea662014-07-23 14:16:32 -04006266 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006267 if (context)
6268 {
6269 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006270 {
Geoff Langb1196682014-07-23 13:47:29 -04006271 context->recordError(gl::Error(GL_INVALID_OPERATION));
6272 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006273 }
Geoff Langbfdea662014-07-23 14:16:32 -04006274
6275 if (bufSize < 0)
6276 {
Geoff Langb1196682014-07-23 13:47:29 -04006277 context->recordError(gl::Error(GL_INVALID_VALUE));
6278 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006279 }
6280
6281 if (!gl::ValidProgram(context, program))
6282 {
6283 return;
6284 }
6285
6286 gl::Program *programObject = context->getProgram(program);
6287 ASSERT(programObject);
6288
6289 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6290 {
Geoff Langb1196682014-07-23 13:47:29 -04006291 context->recordError(gl::Error(GL_INVALID_VALUE));
6292 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006293 }
6294
6295 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006296 }
6297}
6298
6299void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6300{
6301 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6302 index, size, type, stride, pointer);
6303
Geoff Langbfdea662014-07-23 14:16:32 -04006304 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006305 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006306 {
Geoff Langbfdea662014-07-23 14:16:32 -04006307 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006308 {
Geoff Langb1196682014-07-23 13:47:29 -04006309 context->recordError(gl::Error(GL_INVALID_OPERATION));
6310 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006311 }
6312
Geoff Langb1196682014-07-23 13:47:29 -04006313 if (index >= gl::MAX_VERTEX_ATTRIBS)
6314 {
6315 context->recordError(gl::Error(GL_INVALID_VALUE));
6316 return;
6317 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006318
Geoff Langb1196682014-07-23 13:47:29 -04006319 if (size < 1 || size > 4)
6320 {
6321 context->recordError(gl::Error(GL_INVALID_VALUE));
6322 return;
6323 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006324
Geoff Langb1196682014-07-23 13:47:29 -04006325 switch (type)
6326 {
6327 case GL_BYTE:
6328 case GL_UNSIGNED_BYTE:
6329 case GL_SHORT:
6330 case GL_UNSIGNED_SHORT:
6331 case GL_INT:
6332 case GL_UNSIGNED_INT:
6333 case GL_INT_2_10_10_10_REV:
6334 case GL_UNSIGNED_INT_2_10_10_10_REV:
6335 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006336
Geoff Langb1196682014-07-23 13:47:29 -04006337 default:
6338 context->recordError(gl::Error(GL_INVALID_ENUM));
6339 return;
6340 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006341
Geoff Langb1196682014-07-23 13:47:29 -04006342 if (stride < 0)
6343 {
6344 context->recordError(gl::Error(GL_INVALID_VALUE));
6345 return;
6346 }
Geoff Langbfdea662014-07-23 14:16:32 -04006347
Geoff Langb1196682014-07-23 13:47:29 -04006348 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6349 {
6350 context->recordError(gl::Error(GL_INVALID_OPERATION));
6351 return;
6352 }
6353
Geoff Langbfdea662014-07-23 14:16:32 -04006354 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6355 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6356 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6357 // and the pointer argument is not NULL.
6358 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006359 {
Geoff Langb1196682014-07-23 13:47:29 -04006360 context->recordError(gl::Error(GL_INVALID_OPERATION));
6361 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006362 }
6363
Geoff Langbfdea662014-07-23 14:16:32 -04006364 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6365 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006366 }
6367}
6368
6369void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6370{
6371 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6372 index, pname, params);
6373
Geoff Langbfdea662014-07-23 14:16:32 -04006374 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006375 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006376 {
Geoff Langbfdea662014-07-23 14:16:32 -04006377 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006378 {
Geoff Langb1196682014-07-23 13:47:29 -04006379 context->recordError(gl::Error(GL_INVALID_OPERATION));
6380 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006381 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006382
Geoff Langbfdea662014-07-23 14:16:32 -04006383 if (index >= gl::MAX_VERTEX_ATTRIBS)
6384 {
Geoff Langb1196682014-07-23 13:47:29 -04006385 context->recordError(gl::Error(GL_INVALID_VALUE));
6386 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006387 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006388
Geoff Langbfdea662014-07-23 14:16:32 -04006389 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006390
Geoff Langb1196682014-07-23 13:47:29 -04006391 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006392 {
6393 return;
6394 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006395
Geoff Langbfdea662014-07-23 14:16:32 -04006396 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6397 {
6398 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6399 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006400 {
Geoff Langbfdea662014-07-23 14:16:32 -04006401 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006402 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006403 }
Geoff Langbfdea662014-07-23 14:16:32 -04006404 else
6405 {
6406 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6407 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006408 }
6409}
6410
6411void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6412{
6413 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6414 index, pname, params);
6415
Geoff Langbfdea662014-07-23 14:16:32 -04006416 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006417 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006418 {
Geoff Langbfdea662014-07-23 14:16:32 -04006419 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006420 {
Geoff Langb1196682014-07-23 13:47:29 -04006421 context->recordError(gl::Error(GL_INVALID_OPERATION));
6422 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006423 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006424
Geoff Langbfdea662014-07-23 14:16:32 -04006425 if (index >= gl::MAX_VERTEX_ATTRIBS)
6426 {
Geoff Langb1196682014-07-23 13:47:29 -04006427 context->recordError(gl::Error(GL_INVALID_VALUE));
6428 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006429 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006430
Geoff Langbfdea662014-07-23 14:16:32 -04006431 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006432
Geoff Langb1196682014-07-23 13:47:29 -04006433 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006434 {
6435 return;
6436 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006437
Geoff Langbfdea662014-07-23 14:16:32 -04006438 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6439 {
6440 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6441 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006442 {
Geoff Langbfdea662014-07-23 14:16:32 -04006443 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006444 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006445 }
Geoff Langbfdea662014-07-23 14:16:32 -04006446 else
6447 {
6448 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6449 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006450 }
6451}
6452
6453void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6454{
6455 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6456 index, x, y, z, w);
6457
Geoff Langbfdea662014-07-23 14:16:32 -04006458 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006459 if (context)
6460 {
6461 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006462 {
Geoff Langb1196682014-07-23 13:47:29 -04006463 context->recordError(gl::Error(GL_INVALID_OPERATION));
6464 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006465 }
Geoff Langbfdea662014-07-23 14:16:32 -04006466
6467 if (index >= gl::MAX_VERTEX_ATTRIBS)
6468 {
Geoff Langb1196682014-07-23 13:47:29 -04006469 context->recordError(gl::Error(GL_INVALID_VALUE));
6470 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006471 }
6472
6473 GLint vals[4] = { x, y, z, w };
6474 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006475 }
6476}
6477
6478void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6479{
6480 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6481 index, x, y, z, w);
6482
Geoff Langbfdea662014-07-23 14:16:32 -04006483 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006484 if (context)
6485 {
6486 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006487 {
Geoff Langb1196682014-07-23 13:47:29 -04006488 context->recordError(gl::Error(GL_INVALID_OPERATION));
6489 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006490 }
Geoff Langbfdea662014-07-23 14:16:32 -04006491
6492 if (index >= gl::MAX_VERTEX_ATTRIBS)
6493 {
Geoff Langb1196682014-07-23 13:47:29 -04006494 context->recordError(gl::Error(GL_INVALID_VALUE));
6495 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006496 }
6497
6498 GLuint vals[4] = { x, y, z, w };
6499 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006500 }
6501}
6502
6503void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6504{
6505 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6506
Geoff Langbfdea662014-07-23 14:16:32 -04006507 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006508 if (context)
6509 {
6510 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006511 {
Geoff Langb1196682014-07-23 13:47:29 -04006512 context->recordError(gl::Error(GL_INVALID_OPERATION));
6513 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006514 }
Geoff Langbfdea662014-07-23 14:16:32 -04006515
6516 if (index >= gl::MAX_VERTEX_ATTRIBS)
6517 {
Geoff Langb1196682014-07-23 13:47:29 -04006518 context->recordError(gl::Error(GL_INVALID_VALUE));
6519 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006520 }
6521
6522 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006523 }
6524}
6525
6526void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6527{
6528 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6529
Geoff Langbfdea662014-07-23 14:16:32 -04006530 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006531 if (context)
6532 {
6533 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006534 {
Geoff Langb1196682014-07-23 13:47:29 -04006535 context->recordError(gl::Error(GL_INVALID_OPERATION));
6536 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006537 }
Geoff Langbfdea662014-07-23 14:16:32 -04006538
6539 if (index >= gl::MAX_VERTEX_ATTRIBS)
6540 {
Geoff Langb1196682014-07-23 13:47:29 -04006541 context->recordError(gl::Error(GL_INVALID_VALUE));
6542 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006543 }
6544
6545 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006546 }
6547}
6548
6549void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6550{
6551 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6552 program, location, params);
6553
Geoff Langbfdea662014-07-23 14:16:32 -04006554 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006555 if (context)
6556 {
Jamie Madill0063c512014-08-25 15:47:53 -04006557 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006558 {
Jamie Madill0063c512014-08-25 15:47:53 -04006559 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006560 }
Geoff Langbfdea662014-07-23 14:16:32 -04006561
Jamie Madilla502c742014-08-28 17:19:13 -04006562 gl::Program *programObject = context->getProgram(program);
6563 ASSERT(programObject);
6564 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006565 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006566
Jamie Madill99a1e982014-08-25 15:47:54 -04006567 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006568 }
6569}
6570
6571GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6572{
6573 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6574 program, name);
6575
Geoff Langbfdea662014-07-23 14:16:32 -04006576 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006577 if (context)
6578 {
6579 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006580 {
Geoff Langb1196682014-07-23 13:47:29 -04006581 context->recordError(gl::Error(GL_INVALID_OPERATION));
6582 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006583 }
Geoff Langbfdea662014-07-23 14:16:32 -04006584
6585 if (program == 0)
6586 {
Geoff Langb1196682014-07-23 13:47:29 -04006587 context->recordError(gl::Error(GL_INVALID_VALUE));
6588 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006589 }
6590
6591 gl::Program *programObject = context->getProgram(program);
6592
6593 if (!programObject || !programObject->isLinked())
6594 {
Geoff Langb1196682014-07-23 13:47:29 -04006595 context->recordError(gl::Error(GL_INVALID_OPERATION));
6596 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006597 }
6598
6599 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6600 if (!programBinary)
6601 {
Geoff Langb1196682014-07-23 13:47:29 -04006602 context->recordError(gl::Error(GL_INVALID_OPERATION));
6603 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006604 }
6605
6606 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006607 }
6608
6609 return 0;
6610}
6611
6612void __stdcall glUniform1ui(GLint location, GLuint v0)
6613{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006614 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006615}
6616
6617void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6618{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006619 const GLuint xy[] = { v0, v1 };
6620 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006621}
6622
6623void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6624{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006625 const GLuint xyz[] = { v0, v1, v2 };
6626 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006627}
6628
6629void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6630{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006631 const GLuint xyzw[] = { v0, v1, v2, v3 };
6632 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006633}
6634
6635void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6636{
6637 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6638 location, count, value);
6639
Geoff Langbfdea662014-07-23 14:16:32 -04006640 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006641 if (context)
6642 {
6643 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006644 {
Geoff Langbfdea662014-07-23 14:16:32 -04006645 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006646 }
Geoff Langbfdea662014-07-23 14:16:32 -04006647
6648 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6649 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006650 }
6651}
6652
6653void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6654{
6655 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6656 location, count, value);
6657
Geoff Langbfdea662014-07-23 14:16:32 -04006658 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006659 if (context)
6660 {
6661 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006662 {
Geoff Langbfdea662014-07-23 14:16:32 -04006663 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006664 }
Geoff Langbfdea662014-07-23 14:16:32 -04006665
6666 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6667 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006668 }
6669}
6670
6671void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6672{
6673 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6674 location, count, value);
6675
Geoff Langbfdea662014-07-23 14:16:32 -04006676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006677 if (context)
6678 {
6679 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006680 {
Geoff Langbfdea662014-07-23 14:16:32 -04006681 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006682 }
Geoff Langbfdea662014-07-23 14:16:32 -04006683
6684 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6685 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006686 }
6687}
6688
6689void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6690{
6691 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6692 location, count, value);
6693
Geoff Langbfdea662014-07-23 14:16:32 -04006694 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006695 if (context)
6696 {
6697 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006698 {
Geoff Langbfdea662014-07-23 14:16:32 -04006699 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006700 }
Geoff Langbfdea662014-07-23 14:16:32 -04006701
6702 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6703 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006704 }
6705}
6706
6707void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6708{
6709 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6710 buffer, drawbuffer, value);
6711
Geoff Langbfdea662014-07-23 14:16:32 -04006712 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006713 if (context)
6714 {
6715 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006716 {
Geoff Langbfdea662014-07-23 14:16:32 -04006717 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006718 }
Geoff Langbfdea662014-07-23 14:16:32 -04006719
6720 switch (buffer)
6721 {
6722 case GL_COLOR:
6723 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6724 {
Geoff Langb1196682014-07-23 13:47:29 -04006725 context->recordError(gl::Error(GL_INVALID_VALUE));
6726 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006727 }
6728 break;
Geoff Langb1196682014-07-23 13:47:29 -04006729
Geoff Langbfdea662014-07-23 14:16:32 -04006730 case GL_STENCIL:
6731 if (drawbuffer != 0)
6732 {
Geoff Langb1196682014-07-23 13:47:29 -04006733 context->recordError(gl::Error(GL_INVALID_VALUE));
6734 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006735 }
6736 break;
Geoff Langb1196682014-07-23 13:47:29 -04006737
Geoff Langbfdea662014-07-23 14:16:32 -04006738 default:
Geoff Langb1196682014-07-23 13:47:29 -04006739 context->recordError(gl::Error(GL_INVALID_ENUM));
6740 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006741 }
6742
Geoff Langcc79b8c2014-07-25 13:48:02 -04006743 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6744 if (error.isError())
6745 {
6746 context->recordError(error);
6747 return;
6748 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006749 }
6750}
6751
6752void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6753{
6754 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6755 buffer, drawbuffer, value);
6756
Geoff Langbfdea662014-07-23 14:16:32 -04006757 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006758 if (context)
6759 {
6760 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006761 {
Geoff Langbfdea662014-07-23 14:16:32 -04006762 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006763 }
Geoff Langbfdea662014-07-23 14:16:32 -04006764
6765 switch (buffer)
6766 {
6767 case GL_COLOR:
6768 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6769 {
Geoff Langb1196682014-07-23 13:47:29 -04006770 context->recordError(gl::Error(GL_INVALID_VALUE));
6771 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006772 }
6773 break;
Geoff Langb1196682014-07-23 13:47:29 -04006774
Geoff Langbfdea662014-07-23 14:16:32 -04006775 default:
Geoff Langb1196682014-07-23 13:47:29 -04006776 context->recordError(gl::Error(GL_INVALID_ENUM));
6777 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006778 }
6779
Geoff Langcc79b8c2014-07-25 13:48:02 -04006780 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6781 if (error.isError())
6782 {
6783 context->recordError(error);
6784 return;
6785 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006786 }
6787}
6788
6789void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6790{
6791 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6792 buffer, drawbuffer, value);
6793
Geoff Langbfdea662014-07-23 14:16:32 -04006794 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006795 if (context)
6796 {
6797 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006798 {
Geoff Langbfdea662014-07-23 14:16:32 -04006799 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006800 }
Geoff Langbfdea662014-07-23 14:16:32 -04006801
6802 switch (buffer)
6803 {
6804 case GL_COLOR:
6805 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6806 {
Geoff Langb1196682014-07-23 13:47:29 -04006807 context->recordError(gl::Error(GL_INVALID_VALUE));
6808 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006809 }
6810 break;
Geoff Langb1196682014-07-23 13:47:29 -04006811
Geoff Langbfdea662014-07-23 14:16:32 -04006812 case GL_DEPTH:
6813 if (drawbuffer != 0)
6814 {
Geoff Langb1196682014-07-23 13:47:29 -04006815 context->recordError(gl::Error(GL_INVALID_VALUE));
6816 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006817 }
6818 break;
Geoff Langb1196682014-07-23 13:47:29 -04006819
Geoff Langbfdea662014-07-23 14:16:32 -04006820 default:
Geoff Langb1196682014-07-23 13:47:29 -04006821 context->recordError(gl::Error(GL_INVALID_ENUM));
6822 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006823 }
6824
Geoff Langcc79b8c2014-07-25 13:48:02 -04006825 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6826 if (error.isError())
6827 {
6828 context->recordError(error);
6829 return;
6830 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006831 }
6832}
6833
6834void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6835{
6836 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6837 buffer, drawbuffer, depth, stencil);
6838
Geoff Langbfdea662014-07-23 14:16:32 -04006839 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006840 if (context)
6841 {
6842 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006843 {
Geoff Langbfdea662014-07-23 14:16:32 -04006844 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006845 }
Geoff Langbfdea662014-07-23 14:16:32 -04006846
6847 switch (buffer)
6848 {
6849 case GL_DEPTH_STENCIL:
6850 if (drawbuffer != 0)
6851 {
Geoff Langb1196682014-07-23 13:47:29 -04006852 context->recordError(gl::Error(GL_INVALID_VALUE));
6853 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006854 }
6855 break;
Geoff Langb1196682014-07-23 13:47:29 -04006856
Geoff Langbfdea662014-07-23 14:16:32 -04006857 default:
Geoff Langb1196682014-07-23 13:47:29 -04006858 context->recordError(gl::Error(GL_INVALID_ENUM));
6859 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006860 }
6861
Geoff Langcc79b8c2014-07-25 13:48:02 -04006862 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6863 if (error.isError())
6864 {
6865 context->recordError(error);
6866 return;
6867 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006868 }
6869}
6870
6871const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6872{
6873 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6874
Geoff Langbfdea662014-07-23 14:16:32 -04006875 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006876 if (context)
6877 {
6878 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006879 {
Geoff Langb1196682014-07-23 13:47:29 -04006880 context->recordError(gl::Error(GL_INVALID_OPERATION));
6881 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006882 }
Geoff Langbfdea662014-07-23 14:16:32 -04006883
6884 if (name != GL_EXTENSIONS)
6885 {
Geoff Langb1196682014-07-23 13:47:29 -04006886 context->recordError(gl::Error(GL_INVALID_ENUM));
6887 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006888 }
6889
6890 if (index >= context->getExtensionStringCount())
6891 {
Geoff Langb1196682014-07-23 13:47:29 -04006892 context->recordError(gl::Error(GL_INVALID_VALUE));
6893 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006894 }
6895
6896 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006897 }
6898
6899 return NULL;
6900}
6901
6902void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6903{
6904 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6905 readTarget, writeTarget, readOffset, writeOffset, size);
6906
Geoff Langbfdea662014-07-23 14:16:32 -04006907 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006908 if (context)
6909 {
6910 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006911 {
Geoff Langb1196682014-07-23 13:47:29 -04006912 context->recordError(gl::Error(GL_INVALID_OPERATION));
6913 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006914 }
Geoff Langbfdea662014-07-23 14:16:32 -04006915
6916 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6917 {
Geoff Langb1196682014-07-23 13:47:29 -04006918 context->recordError(gl::Error(GL_INVALID_ENUM));
6919 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006920 }
6921
6922 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6923 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6924
6925 if (!readBuffer || !writeBuffer)
6926 {
Geoff Langb1196682014-07-23 13:47:29 -04006927 context->recordError(gl::Error(GL_INVALID_OPERATION));
6928 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006929 }
6930
Jamie Madillcfaaf722014-07-31 10:47:54 -04006931 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006932 if (readBuffer->isMapped() || writeBuffer->isMapped())
6933 {
Geoff Langb1196682014-07-23 13:47:29 -04006934 context->recordError(gl::Error(GL_INVALID_OPERATION));
6935 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006936 }
6937
6938 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6939 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6940 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6941 {
Geoff Langb1196682014-07-23 13:47:29 -04006942 context->recordError(gl::Error(GL_INVALID_VALUE));
6943 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006944 }
6945
6946 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6947 {
Geoff Langb1196682014-07-23 13:47:29 -04006948 context->recordError(gl::Error(GL_INVALID_VALUE));
6949 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006950 }
6951
Geoff Langbfdea662014-07-23 14:16:32 -04006952 // if size is zero, the copy is a successful no-op
6953 if (size > 0)
6954 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006955 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6956 if (error.isError())
6957 {
6958 context->recordError(error);
6959 return;
6960 }
Geoff Langbfdea662014-07-23 14:16:32 -04006961 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006962 }
6963}
6964
6965void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6966{
6967 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6968 program, uniformCount, uniformNames, uniformIndices);
6969
Geoff Langbfdea662014-07-23 14:16:32 -04006970 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006971 if (context)
6972 {
6973 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006974 {
Geoff Langb1196682014-07-23 13:47:29 -04006975 context->recordError(gl::Error(GL_INVALID_OPERATION));
6976 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006977 }
6978
6979 if (uniformCount < 0)
6980 {
Geoff Langb1196682014-07-23 13:47:29 -04006981 context->recordError(gl::Error(GL_INVALID_VALUE));
6982 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006983 }
6984
6985 gl::Program *programObject = context->getProgram(program);
6986
6987 if (!programObject)
6988 {
6989 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006990 {
Geoff Langb1196682014-07-23 13:47:29 -04006991 context->recordError(gl::Error(GL_INVALID_OPERATION));
6992 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006993 }
Geoff Langbfdea662014-07-23 14:16:32 -04006994 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006995 {
Geoff Langb1196682014-07-23 13:47:29 -04006996 context->recordError(gl::Error(GL_INVALID_VALUE));
6997 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006998 }
Geoff Langbfdea662014-07-23 14:16:32 -04006999 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007000
Geoff Langbfdea662014-07-23 14:16:32 -04007001 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7002 if (!programObject->isLinked() || !programBinary)
7003 {
7004 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007005 {
Geoff Langbfdea662014-07-23 14:16:32 -04007006 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007007 }
7008 }
Geoff Langbfdea662014-07-23 14:16:32 -04007009 else
7010 {
7011 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7012 {
7013 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
7014 }
7015 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007016 }
7017}
7018
7019void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
7020{
7021 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7022 program, uniformCount, uniformIndices, pname, params);
7023
Geoff Langbfdea662014-07-23 14:16:32 -04007024 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007025 if (context)
7026 {
7027 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007028 {
Geoff Langb1196682014-07-23 13:47:29 -04007029 context->recordError(gl::Error(GL_INVALID_OPERATION));
7030 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007031 }
7032
7033 if (uniformCount < 0)
7034 {
Geoff Langb1196682014-07-23 13:47:29 -04007035 context->recordError(gl::Error(GL_INVALID_VALUE));
7036 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007037 }
7038
7039 gl::Program *programObject = context->getProgram(program);
7040
7041 if (!programObject)
7042 {
7043 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007044 {
Geoff Langb1196682014-07-23 13:47:29 -04007045 context->recordError(gl::Error(GL_INVALID_OPERATION));
7046 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007047 }
Geoff Langbfdea662014-07-23 14:16:32 -04007048 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007049 {
Geoff Langb1196682014-07-23 13:47:29 -04007050 context->recordError(gl::Error(GL_INVALID_VALUE));
7051 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007052 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007053 }
Geoff Langbfdea662014-07-23 14:16:32 -04007054
7055 switch (pname)
7056 {
7057 case GL_UNIFORM_TYPE:
7058 case GL_UNIFORM_SIZE:
7059 case GL_UNIFORM_NAME_LENGTH:
7060 case GL_UNIFORM_BLOCK_INDEX:
7061 case GL_UNIFORM_OFFSET:
7062 case GL_UNIFORM_ARRAY_STRIDE:
7063 case GL_UNIFORM_MATRIX_STRIDE:
7064 case GL_UNIFORM_IS_ROW_MAJOR:
7065 break;
Geoff Langb1196682014-07-23 13:47:29 -04007066
Geoff Langbfdea662014-07-23 14:16:32 -04007067 default:
Geoff Langb1196682014-07-23 13:47:29 -04007068 context->recordError(gl::Error(GL_INVALID_ENUM));
7069 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007070 }
7071
7072 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7073
7074 if (!programBinary && uniformCount > 0)
7075 {
Geoff Langb1196682014-07-23 13:47:29 -04007076 context->recordError(gl::Error(GL_INVALID_VALUE));
7077 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007078 }
7079
7080 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7081 {
7082 const GLuint index = uniformIndices[uniformId];
7083
7084 if (index >= (GLuint)programBinary->getActiveUniformCount())
7085 {
Geoff Langb1196682014-07-23 13:47:29 -04007086 context->recordError(gl::Error(GL_INVALID_VALUE));
7087 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007088 }
7089 }
7090
7091 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7092 {
7093 const GLuint index = uniformIndices[uniformId];
7094 params[uniformId] = programBinary->getActiveUniformi(index, pname);
7095 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007096 }
7097}
7098
7099GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
7100{
7101 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
7102
Geoff Langbfdea662014-07-23 14:16:32 -04007103 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007104 if (context)
7105 {
7106 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007107 {
Geoff Langb1196682014-07-23 13:47:29 -04007108 context->recordError(gl::Error(GL_INVALID_OPERATION));
7109 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04007110 }
7111
7112 gl::Program *programObject = context->getProgram(program);
7113
7114 if (!programObject)
7115 {
7116 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007117 {
Geoff Langb1196682014-07-23 13:47:29 -04007118 context->recordError(gl::Error(GL_INVALID_OPERATION));
7119 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007120 }
Geoff Langbfdea662014-07-23 14:16:32 -04007121 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007122 {
Geoff Langb1196682014-07-23 13:47:29 -04007123 context->recordError(gl::Error(GL_INVALID_VALUE));
7124 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007125 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007126 }
Geoff Langbfdea662014-07-23 14:16:32 -04007127
7128 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7129 if (!programBinary)
7130 {
7131 return GL_INVALID_INDEX;
7132 }
7133
7134 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007135 }
7136
7137 return 0;
7138}
7139
7140void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
7141{
7142 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7143 program, uniformBlockIndex, pname, params);
7144
Geoff Langbfdea662014-07-23 14:16:32 -04007145 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007146 if (context)
7147 {
7148 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007149 {
Geoff Langb1196682014-07-23 13:47:29 -04007150 context->recordError(gl::Error(GL_INVALID_OPERATION));
7151 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007152 }
7153 gl::Program *programObject = context->getProgram(program);
7154
7155 if (!programObject)
7156 {
7157 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007158 {
Geoff Langb1196682014-07-23 13:47:29 -04007159 context->recordError(gl::Error(GL_INVALID_OPERATION));
7160 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007161 }
Geoff Langbfdea662014-07-23 14:16:32 -04007162 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007163 {
Geoff Langb1196682014-07-23 13:47:29 -04007164 context->recordError(gl::Error(GL_INVALID_VALUE));
7165 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007166 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007167 }
Geoff Langbfdea662014-07-23 14:16:32 -04007168
7169 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7170
7171 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7172 {
Geoff Langb1196682014-07-23 13:47:29 -04007173 context->recordError(gl::Error(GL_INVALID_VALUE));
7174 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007175 }
7176
7177 switch (pname)
7178 {
7179 case GL_UNIFORM_BLOCK_BINDING:
7180 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7181 break;
7182
7183 case GL_UNIFORM_BLOCK_DATA_SIZE:
7184 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7185 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7186 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7187 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7188 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7189 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7190 break;
7191
7192 default:
Geoff Langb1196682014-07-23 13:47:29 -04007193 context->recordError(gl::Error(GL_INVALID_ENUM));
7194 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007195 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007196 }
7197}
7198
7199void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7200{
7201 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7202 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7203
Geoff Langbfdea662014-07-23 14:16:32 -04007204 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007205 if (context)
7206 {
7207 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007208 {
Geoff Langb1196682014-07-23 13:47:29 -04007209 context->recordError(gl::Error(GL_INVALID_OPERATION));
7210 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007211 }
7212
7213 gl::Program *programObject = context->getProgram(program);
7214
7215 if (!programObject)
7216 {
7217 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007218 {
Geoff Langb1196682014-07-23 13:47:29 -04007219 context->recordError(gl::Error(GL_INVALID_OPERATION));
7220 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007221 }
Geoff Langbfdea662014-07-23 14:16:32 -04007222 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007223 {
Geoff Langb1196682014-07-23 13:47:29 -04007224 context->recordError(gl::Error(GL_INVALID_VALUE));
7225 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007226 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007227 }
Geoff Langbfdea662014-07-23 14:16:32 -04007228
7229 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7230
7231 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7232 {
Geoff Langb1196682014-07-23 13:47:29 -04007233 context->recordError(gl::Error(GL_INVALID_VALUE));
7234 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007235 }
7236
7237 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007238 }
7239}
7240
7241void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7242{
7243 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7244 program, uniformBlockIndex, uniformBlockBinding);
7245
Geoff Langbfdea662014-07-23 14:16:32 -04007246 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007247 if (context)
7248 {
7249 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007250 {
Geoff Langb1196682014-07-23 13:47:29 -04007251 context->recordError(gl::Error(GL_INVALID_OPERATION));
7252 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007253 }
7254
Geoff Lang3a61c322014-07-10 13:01:54 -04007255 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007256 {
Geoff Langb1196682014-07-23 13:47:29 -04007257 context->recordError(gl::Error(GL_INVALID_VALUE));
7258 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007259 }
7260
7261 gl::Program *programObject = context->getProgram(program);
7262
7263 if (!programObject)
7264 {
7265 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007266 {
Geoff Langb1196682014-07-23 13:47:29 -04007267 context->recordError(gl::Error(GL_INVALID_OPERATION));
7268 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007269 }
Geoff Langbfdea662014-07-23 14:16:32 -04007270 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007271 {
Geoff Langb1196682014-07-23 13:47:29 -04007272 context->recordError(gl::Error(GL_INVALID_VALUE));
7273 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007274 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007275 }
Geoff Langbfdea662014-07-23 14:16:32 -04007276
7277 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7278
7279 // if never linked, there won't be any uniform blocks
7280 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7281 {
Geoff Langb1196682014-07-23 13:47:29 -04007282 context->recordError(gl::Error(GL_INVALID_VALUE));
7283 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007284 }
7285
7286 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007287 }
7288}
7289
7290void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7291{
7292 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7293 mode, first, count, instanceCount);
7294
Geoff Langbfdea662014-07-23 14:16:32 -04007295 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007296 if (context)
7297 {
7298 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007299 {
Geoff Langb1196682014-07-23 13:47:29 -04007300 context->recordError(gl::Error(GL_INVALID_OPERATION));
7301 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007302 }
Geoff Langbfdea662014-07-23 14:16:32 -04007303
7304 // glDrawArraysInstanced
7305 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007306 }
7307}
7308
7309void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7310{
7311 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7312 mode, count, type, indices, instanceCount);
7313
Geoff Langbfdea662014-07-23 14:16:32 -04007314 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007315 if (context)
7316 {
7317 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007318 {
Geoff Langb1196682014-07-23 13:47:29 -04007319 context->recordError(gl::Error(GL_INVALID_OPERATION));
7320 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007321 }
Geoff Langbfdea662014-07-23 14:16:32 -04007322
7323 // glDrawElementsInstanced
7324 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007325 }
7326}
7327
7328GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7329{
7330 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7331
Geoff Langbfdea662014-07-23 14:16:32 -04007332 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007333 if (context)
7334 {
7335 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007336 {
Geoff Langb1196682014-07-23 13:47:29 -04007337 context->recordError(gl::Error(GL_INVALID_OPERATION));
7338 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007339 }
Geoff Langbfdea662014-07-23 14:16:32 -04007340
7341 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7342 {
Geoff Langb1196682014-07-23 13:47:29 -04007343 context->recordError(gl::Error(GL_INVALID_ENUM));
7344 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007345 }
7346
7347 if (flags != 0)
7348 {
Geoff Langb1196682014-07-23 13:47:29 -04007349 context->recordError(gl::Error(GL_INVALID_VALUE));
7350 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007351 }
7352
7353 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007354 }
7355
7356 return NULL;
7357}
7358
7359GLboolean __stdcall glIsSync(GLsync sync)
7360{
7361 EVENT("(GLsync sync = 0x%0.8p)", sync);
7362
Geoff Langbfdea662014-07-23 14:16:32 -04007363 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007364 if (context)
7365 {
7366 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007367 {
Geoff Langb1196682014-07-23 13:47:29 -04007368 context->recordError(gl::Error(GL_INVALID_OPERATION));
7369 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007370 }
Geoff Langbfdea662014-07-23 14:16:32 -04007371
7372 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007373 }
7374
7375 return GL_FALSE;
7376}
7377
7378void __stdcall glDeleteSync(GLsync sync)
7379{
7380 EVENT("(GLsync sync = 0x%0.8p)", sync);
7381
Geoff Langbfdea662014-07-23 14:16:32 -04007382 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007383 if (context)
7384 {
7385 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007386 {
Geoff Langb1196682014-07-23 13:47:29 -04007387 context->recordError(gl::Error(GL_INVALID_OPERATION));
7388 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007389 }
Geoff Langbfdea662014-07-23 14:16:32 -04007390
7391 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7392 {
Geoff Langb1196682014-07-23 13:47:29 -04007393 context->recordError(gl::Error(GL_INVALID_VALUE));
7394 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007395 }
7396
7397 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007398 }
7399}
7400
7401GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7402{
7403 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7404 sync, flags, timeout);
7405
Geoff Langbfdea662014-07-23 14:16:32 -04007406 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007407 if (context)
7408 {
7409 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007410 {
Geoff Langb1196682014-07-23 13:47:29 -04007411 context->recordError(gl::Error(GL_INVALID_OPERATION));
7412 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007413 }
Geoff Langbfdea662014-07-23 14:16:32 -04007414
7415 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7416 {
Geoff Langb1196682014-07-23 13:47:29 -04007417 context->recordError(gl::Error(GL_INVALID_VALUE));
7418 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007419 }
7420
7421 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7422
7423 if (!fenceSync)
7424 {
Geoff Langb1196682014-07-23 13:47:29 -04007425 context->recordError(gl::Error(GL_INVALID_VALUE));
7426 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007427 }
7428
7429 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007430 }
7431
7432 return GL_FALSE;
7433}
7434
7435void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7436{
7437 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7438 sync, flags, timeout);
7439
Geoff Langbfdea662014-07-23 14:16:32 -04007440 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007441 if (context)
7442 {
7443 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007444 {
Geoff Langb1196682014-07-23 13:47:29 -04007445 context->recordError(gl::Error(GL_INVALID_OPERATION));
7446 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007447 }
Geoff Langbfdea662014-07-23 14:16:32 -04007448
7449 if (flags != 0)
7450 {
Geoff Langb1196682014-07-23 13:47:29 -04007451 context->recordError(gl::Error(GL_INVALID_VALUE));
7452 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007453 }
7454
7455 if (timeout != GL_TIMEOUT_IGNORED)
7456 {
Geoff Langb1196682014-07-23 13:47:29 -04007457 context->recordError(gl::Error(GL_INVALID_VALUE));
7458 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007459 }
7460
7461 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7462
7463 if (!fenceSync)
7464 {
Geoff Langb1196682014-07-23 13:47:29 -04007465 context->recordError(gl::Error(GL_INVALID_VALUE));
7466 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007467 }
7468
7469 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007470 }
7471}
7472
7473void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7474{
7475 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7476 pname, params);
7477
Geoff Langbfdea662014-07-23 14:16:32 -04007478 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007479 if (context)
7480 {
7481 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007482 {
Geoff Langb1196682014-07-23 13:47:29 -04007483 context->recordError(gl::Error(GL_INVALID_OPERATION));
7484 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007485 }
Geoff Langbfdea662014-07-23 14:16:32 -04007486
7487 GLenum nativeType;
7488 unsigned int numParams = 0;
7489 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7490 {
7491 return;
7492 }
7493
7494 if (nativeType == GL_INT_64_ANGLEX)
7495 {
7496 context->getInteger64v(pname, params);
7497 }
7498 else
7499 {
7500 CastStateValues(context, nativeType, pname, numParams, params);
7501 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007502 }
7503}
7504
7505void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7506{
7507 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7508 sync, pname, bufSize, length, values);
7509
Geoff Langbfdea662014-07-23 14:16:32 -04007510 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007511 if (context)
7512 {
7513 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007514 {
Geoff Langb1196682014-07-23 13:47:29 -04007515 context->recordError(gl::Error(GL_INVALID_OPERATION));
7516 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007517 }
Geoff Langbfdea662014-07-23 14:16:32 -04007518
7519 if (bufSize < 0)
7520 {
Geoff Langb1196682014-07-23 13:47:29 -04007521 context->recordError(gl::Error(GL_INVALID_VALUE));
7522 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007523 }
7524
7525 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7526
7527 if (!fenceSync)
7528 {
Geoff Langb1196682014-07-23 13:47:29 -04007529 context->recordError(gl::Error(GL_INVALID_VALUE));
7530 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007531 }
7532
7533 switch (pname)
7534 {
7535 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7536 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7537 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7538 case GL_SYNC_FLAGS: values[0] = 0; break;
7539
7540 default:
Geoff Langb1196682014-07-23 13:47:29 -04007541 context->recordError(gl::Error(GL_INVALID_ENUM));
7542 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007543 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007544 }
7545}
7546
7547void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7548{
7549 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7550 target, index, data);
7551
Geoff Langbfdea662014-07-23 14:16:32 -04007552 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007553 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007554 {
Geoff Langbfdea662014-07-23 14:16:32 -04007555 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007556 {
Geoff Langb1196682014-07-23 13:47:29 -04007557 context->recordError(gl::Error(GL_INVALID_OPERATION));
7558 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007559 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007560
Geoff Lang3a61c322014-07-10 13:01:54 -04007561 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007562 switch (target)
7563 {
7564 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7565 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7566 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007567 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7568 {
Geoff Langb1196682014-07-23 13:47:29 -04007569 context->recordError(gl::Error(GL_INVALID_VALUE));
7570 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007571 }
Geoff Langbfdea662014-07-23 14:16:32 -04007572 break;
Geoff Langb1196682014-07-23 13:47:29 -04007573
Geoff Langbfdea662014-07-23 14:16:32 -04007574 case GL_UNIFORM_BUFFER_START:
7575 case GL_UNIFORM_BUFFER_SIZE:
7576 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007577 if (index >= caps.maxUniformBufferBindings)
7578 {
Geoff Langb1196682014-07-23 13:47:29 -04007579 context->recordError(gl::Error(GL_INVALID_VALUE));
7580 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007581 }
Geoff Langbfdea662014-07-23 14:16:32 -04007582 break;
Geoff Langb1196682014-07-23 13:47:29 -04007583
Geoff Langbfdea662014-07-23 14:16:32 -04007584 default:
Geoff Langb1196682014-07-23 13:47:29 -04007585 context->recordError(gl::Error(GL_INVALID_ENUM));
7586 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007587 }
7588
7589 if (!(context->getIndexedInteger64v(target, index, data)))
7590 {
7591 GLenum nativeType;
7592 unsigned int numParams = 0;
7593 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007594 {
7595 context->recordError(gl::Error(GL_INVALID_ENUM));
7596 return;
7597 }
Shannon Woods15934d52013-08-19 14:28:49 -04007598
Geoff Langbfdea662014-07-23 14:16:32 -04007599 if (numParams == 0)
7600 return; // it is known that pname is valid, but there are no parameters to return
7601
7602 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007603 {
Geoff Langbfdea662014-07-23 14:16:32 -04007604 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007605
Geoff Langbfdea662014-07-23 14:16:32 -04007606 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007607
Geoff Langbfdea662014-07-23 14:16:32 -04007608 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007609 {
Geoff Langbfdea662014-07-23 14:16:32 -04007610 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007611 }
Geoff Langbfdea662014-07-23 14:16:32 -04007612
7613 delete [] intParams;
7614 }
7615 else
7616 {
7617 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007618 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007619 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007621}
7622
7623void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7624{
7625 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7626 target, pname, params);
7627
Geoff Langbfdea662014-07-23 14:16:32 -04007628 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007629 if (context)
7630 {
7631 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007632 {
Geoff Langb1196682014-07-23 13:47:29 -04007633 context->recordError(gl::Error(GL_INVALID_OPERATION));
7634 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007635 }
Geoff Langbfdea662014-07-23 14:16:32 -04007636
7637 if (!gl::ValidBufferTarget(context, target))
7638 {
Geoff Langb1196682014-07-23 13:47:29 -04007639 context->recordError(gl::Error(GL_INVALID_ENUM));
7640 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007641 }
7642
7643 if (!gl::ValidBufferParameter(context, pname))
7644 {
Geoff Langb1196682014-07-23 13:47:29 -04007645 context->recordError(gl::Error(GL_INVALID_ENUM));
7646 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007647 }
7648
7649 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7650
7651 if (!buffer)
7652 {
7653 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007654 context->recordError(gl::Error(GL_INVALID_OPERATION));
7655 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007656 }
7657
7658 switch (pname)
7659 {
7660 case GL_BUFFER_USAGE:
7661 *params = static_cast<GLint64>(buffer->getUsage());
7662 break;
7663 case GL_BUFFER_SIZE:
7664 *params = buffer->getSize();
7665 break;
7666 case GL_BUFFER_ACCESS_FLAGS:
7667 *params = static_cast<GLint64>(buffer->getAccessFlags());
7668 break;
7669 case GL_BUFFER_MAPPED:
7670 *params = static_cast<GLint64>(buffer->isMapped());
7671 break;
7672 case GL_BUFFER_MAP_OFFSET:
7673 *params = buffer->getMapOffset();
7674 break;
7675 case GL_BUFFER_MAP_LENGTH:
7676 *params = buffer->getMapLength();
7677 break;
7678 default: UNREACHABLE(); break;
7679 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007680 }
7681}
7682
7683void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7684{
7685 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7686
Geoff Langbfdea662014-07-23 14:16:32 -04007687 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007688 if (context)
7689 {
7690 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007691 {
Geoff Langb1196682014-07-23 13:47:29 -04007692 context->recordError(gl::Error(GL_INVALID_OPERATION));
7693 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007694 }
Geoff Langbfdea662014-07-23 14:16:32 -04007695
7696 if (count < 0)
7697 {
Geoff Langb1196682014-07-23 13:47:29 -04007698 context->recordError(gl::Error(GL_INVALID_VALUE));
7699 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007700 }
7701
7702 for (int i = 0; i < count; i++)
7703 {
7704 samplers[i] = context->createSampler();
7705 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007706 }
7707}
7708
7709void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7710{
7711 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7712
Geoff Langbfdea662014-07-23 14:16:32 -04007713 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007714 if (context)
7715 {
7716 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007717 {
Geoff Langb1196682014-07-23 13:47:29 -04007718 context->recordError(gl::Error(GL_INVALID_OPERATION));
7719 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007720 }
Geoff Langbfdea662014-07-23 14:16:32 -04007721
7722 if (count < 0)
7723 {
Geoff Langb1196682014-07-23 13:47:29 -04007724 context->recordError(gl::Error(GL_INVALID_VALUE));
7725 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007726 }
7727
7728 for (int i = 0; i < count; i++)
7729 {
7730 context->deleteSampler(samplers[i]);
7731 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007732 }
7733}
7734
7735GLboolean __stdcall glIsSampler(GLuint sampler)
7736{
7737 EVENT("(GLuint sampler = %u)", sampler);
7738
Geoff Langbfdea662014-07-23 14:16:32 -04007739 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007740 if (context)
7741 {
7742 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007743 {
Geoff Langb1196682014-07-23 13:47:29 -04007744 context->recordError(gl::Error(GL_INVALID_OPERATION));
7745 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007746 }
Geoff Langbfdea662014-07-23 14:16:32 -04007747
7748 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007749 }
7750
7751 return GL_FALSE;
7752}
7753
7754void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7755{
7756 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7757
Geoff Langbfdea662014-07-23 14:16:32 -04007758 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007759 if (context)
7760 {
7761 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007762 {
Geoff Langb1196682014-07-23 13:47:29 -04007763 context->recordError(gl::Error(GL_INVALID_OPERATION));
7764 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007765 }
Geoff Langbfdea662014-07-23 14:16:32 -04007766
7767 if (sampler != 0 && !context->isSampler(sampler))
7768 {
Geoff Langb1196682014-07-23 13:47:29 -04007769 context->recordError(gl::Error(GL_INVALID_OPERATION));
7770 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007771 }
7772
Geoff Lang3a61c322014-07-10 13:01:54 -04007773 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007774 {
Geoff Langb1196682014-07-23 13:47:29 -04007775 context->recordError(gl::Error(GL_INVALID_VALUE));
7776 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007777 }
7778
7779 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007780 }
7781}
7782
7783void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7784{
7785 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7786
Geoff Langbfdea662014-07-23 14:16:32 -04007787 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007788 if (context)
7789 {
7790 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007791 {
Geoff Langb1196682014-07-23 13:47:29 -04007792 context->recordError(gl::Error(GL_INVALID_OPERATION));
7793 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007794 }
Geoff Langbfdea662014-07-23 14:16:32 -04007795
Geoff Langb1196682014-07-23 13:47:29 -04007796 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007797 {
7798 return;
7799 }
7800
7801 if (!gl::ValidateTexParamParameters(context, pname, param))
7802 {
7803 return;
7804 }
7805
7806 if (!context->isSampler(sampler))
7807 {
Geoff Langb1196682014-07-23 13:47:29 -04007808 context->recordError(gl::Error(GL_INVALID_OPERATION));
7809 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007810 }
7811
7812 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007813 }
7814}
7815
7816void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7817{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007818 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007819}
7820
7821void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7822{
7823 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7824
Geoff Langbfdea662014-07-23 14:16:32 -04007825 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007826 if (context)
7827 {
7828 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007829 {
Geoff Langb1196682014-07-23 13:47:29 -04007830 context->recordError(gl::Error(GL_INVALID_OPERATION));
7831 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007832 }
Geoff Langbfdea662014-07-23 14:16:32 -04007833
Geoff Langb1196682014-07-23 13:47:29 -04007834 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007835 {
7836 return;
7837 }
7838
7839 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7840 {
7841 return;
7842 }
7843
7844 if (!context->isSampler(sampler))
7845 {
Geoff Langb1196682014-07-23 13:47:29 -04007846 context->recordError(gl::Error(GL_INVALID_OPERATION));
7847 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007848 }
7849
7850 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007851 }
7852}
7853
7854void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7855{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007856 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007857}
7858
7859void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7860{
7861 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7862
Geoff Langbfdea662014-07-23 14:16:32 -04007863 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007864 if (context)
7865 {
7866 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007867 {
Geoff Langb1196682014-07-23 13:47:29 -04007868 context->recordError(gl::Error(GL_INVALID_OPERATION));
7869 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007870 }
Geoff Langbfdea662014-07-23 14:16:32 -04007871
Geoff Langb1196682014-07-23 13:47:29 -04007872 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007873 {
7874 return;
7875 }
7876
7877 if (!context->isSampler(sampler))
7878 {
Geoff Langb1196682014-07-23 13:47:29 -04007879 context->recordError(gl::Error(GL_INVALID_OPERATION));
7880 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007881 }
7882
7883 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007884 }
7885}
7886
7887void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7888{
7889 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7890
Geoff Langbfdea662014-07-23 14:16:32 -04007891 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007892 if (context)
7893 {
7894 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007895 {
Geoff Langb1196682014-07-23 13:47:29 -04007896 context->recordError(gl::Error(GL_INVALID_OPERATION));
7897 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007898 }
Geoff Langbfdea662014-07-23 14:16:32 -04007899
Geoff Langb1196682014-07-23 13:47:29 -04007900 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007901 {
7902 return;
7903 }
7904
7905 if (!context->isSampler(sampler))
7906 {
Geoff Langb1196682014-07-23 13:47:29 -04007907 context->recordError(gl::Error(GL_INVALID_OPERATION));
7908 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007909 }
7910
7911 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007912 }
7913}
7914
7915void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7916{
7917 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7918
Geoff Langbfdea662014-07-23 14:16:32 -04007919 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007920 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007921 {
Geoff Langbfdea662014-07-23 14:16:32 -04007922 if (context->getClientVersion() < 3)
7923 {
Geoff Langb1196682014-07-23 13:47:29 -04007924 context->recordError(gl::Error(GL_INVALID_OPERATION));
7925 return;
7926 }
7927
7928 if (index >= gl::MAX_VERTEX_ATTRIBS)
7929 {
7930 context->recordError(gl::Error(GL_INVALID_VALUE));
7931 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007932 }
7933
7934 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007935 }
7936}
7937
7938void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7939{
7940 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7941
Geoff Langbfdea662014-07-23 14:16:32 -04007942 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007943 if (context)
7944 {
7945 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007946 {
Geoff Langb1196682014-07-23 13:47:29 -04007947 context->recordError(gl::Error(GL_INVALID_OPERATION));
7948 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007949 }
Geoff Langbfdea662014-07-23 14:16:32 -04007950
7951 switch (target)
7952 {
7953 case GL_TRANSFORM_FEEDBACK:
7954 {
7955 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7956 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7957 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7958 {
Geoff Langb1196682014-07-23 13:47:29 -04007959 context->recordError(gl::Error(GL_INVALID_OPERATION));
7960 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007961 }
7962
7963 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7964 if (context->getTransformFeedback(id) == NULL)
7965 {
Geoff Langb1196682014-07-23 13:47:29 -04007966 context->recordError(gl::Error(GL_INVALID_OPERATION));
7967 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007968 }
7969
7970 context->bindTransformFeedback(id);
7971 }
7972 break;
7973
7974 default:
Geoff Langb1196682014-07-23 13:47:29 -04007975 context->recordError(gl::Error(GL_INVALID_ENUM));
7976 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007977 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007978 }
7979}
7980
7981void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7982{
7983 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7984
Geoff Langbfdea662014-07-23 14:16:32 -04007985 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007986 if (context)
7987 {
7988 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007989 {
Geoff Langb1196682014-07-23 13:47:29 -04007990 context->recordError(gl::Error(GL_INVALID_OPERATION));
7991 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007992 }
Geoff Langbfdea662014-07-23 14:16:32 -04007993
7994 for (int i = 0; i < n; i++)
7995 {
7996 context->deleteTransformFeedback(ids[i]);
7997 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007998 }
7999}
8000
8001void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
8002{
8003 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8004
Geoff Langbfdea662014-07-23 14:16:32 -04008005 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008006 if (context)
8007 {
8008 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008009 {
Geoff Langb1196682014-07-23 13:47:29 -04008010 context->recordError(gl::Error(GL_INVALID_OPERATION));
8011 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008012 }
Geoff Langbfdea662014-07-23 14:16:32 -04008013
8014 for (int i = 0; i < n; i++)
8015 {
8016 ids[i] = context->createTransformFeedback();
8017 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008018 }
8019}
8020
8021GLboolean __stdcall glIsTransformFeedback(GLuint id)
8022{
8023 EVENT("(GLuint id = %u)", id);
8024
Geoff Langbfdea662014-07-23 14:16:32 -04008025 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008026 if (context)
8027 {
8028 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008029 {
Geoff Langb1196682014-07-23 13:47:29 -04008030 context->recordError(gl::Error(GL_INVALID_OPERATION));
8031 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008032 }
Geoff Langbfdea662014-07-23 14:16:32 -04008033
8034 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008035 }
8036
8037 return GL_FALSE;
8038}
8039
8040void __stdcall glPauseTransformFeedback(void)
8041{
8042 EVENT("(void)");
8043
Geoff Langbfdea662014-07-23 14:16:32 -04008044 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008045 if (context)
8046 {
8047 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008048 {
Geoff Langb1196682014-07-23 13:47:29 -04008049 context->recordError(gl::Error(GL_INVALID_OPERATION));
8050 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008051 }
Geoff Langbfdea662014-07-23 14:16:32 -04008052
8053 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8054 ASSERT(transformFeedback != NULL);
8055
8056 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
8057 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
8058 {
Geoff Langb1196682014-07-23 13:47:29 -04008059 context->recordError(gl::Error(GL_INVALID_OPERATION));
8060 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008061 }
8062
8063 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008064 }
8065}
8066
8067void __stdcall glResumeTransformFeedback(void)
8068{
8069 EVENT("(void)");
8070
Geoff Langbfdea662014-07-23 14:16:32 -04008071 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008072 if (context)
8073 {
8074 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008075 {
Geoff Langb1196682014-07-23 13:47:29 -04008076 context->recordError(gl::Error(GL_INVALID_OPERATION));
8077 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008078 }
Geoff Langbfdea662014-07-23 14:16:32 -04008079
8080 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8081 ASSERT(transformFeedback != NULL);
8082
8083 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
8084 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
8085 {
Geoff Langb1196682014-07-23 13:47:29 -04008086 context->recordError(gl::Error(GL_INVALID_OPERATION));
8087 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008088 }
8089
8090 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008091 }
8092}
8093
8094void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
8095{
8096 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
8097 program, bufSize, length, binaryFormat, binary);
8098
Geoff Langbfdea662014-07-23 14:16:32 -04008099 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008100 if (context)
8101 {
8102 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008103 {
Geoff Langb1196682014-07-23 13:47:29 -04008104 context->recordError(gl::Error(GL_INVALID_OPERATION));
8105 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008106 }
Geoff Langbfdea662014-07-23 14:16:32 -04008107
8108 // glGetProgramBinary
8109 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008110 }
8111}
8112
8113void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
8114{
8115 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
8116 program, binaryFormat, binary, length);
8117
Geoff Langbfdea662014-07-23 14:16:32 -04008118 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008119 if (context)
8120 {
8121 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008122 {
Geoff Langb1196682014-07-23 13:47:29 -04008123 context->recordError(gl::Error(GL_INVALID_OPERATION));
8124 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008125 }
Geoff Langbfdea662014-07-23 14:16:32 -04008126
8127 // glProgramBinary
8128 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008129 }
8130}
8131
8132void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
8133{
8134 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
8135 program, pname, value);
8136
Geoff Langbfdea662014-07-23 14:16:32 -04008137 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008138 if (context)
8139 {
8140 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008141 {
Geoff Langb1196682014-07-23 13:47:29 -04008142 context->recordError(gl::Error(GL_INVALID_OPERATION));
8143 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008144 }
Geoff Langbfdea662014-07-23 14:16:32 -04008145
8146 // glProgramParameteri
8147 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008148 }
8149}
8150
8151void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
8152{
8153 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8154 target, numAttachments, attachments);
8155
Geoff Langbfdea662014-07-23 14:16:32 -04008156 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008157 if (context)
8158 {
8159 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008160 {
Geoff Langb1196682014-07-23 13:47:29 -04008161 context->recordError(gl::Error(GL_INVALID_OPERATION));
8162 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008163 }
Geoff Langbfdea662014-07-23 14:16:32 -04008164
8165 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8166 {
8167 return;
8168 }
8169
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008170 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8171 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8172 {
8173 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8174 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008175 }
8176}
8177
8178void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
8179{
8180 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8181 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8182 target, numAttachments, attachments, x, y, width, height);
8183
Geoff Langbfdea662014-07-23 14:16:32 -04008184 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008185 if (context)
8186 {
8187 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008188 {
Geoff Langb1196682014-07-23 13:47:29 -04008189 context->recordError(gl::Error(GL_INVALID_OPERATION));
8190 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008191 }
Geoff Langbfdea662014-07-23 14:16:32 -04008192
8193 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8194 {
8195 return;
8196 }
8197
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008198 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8199 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8200 {
8201 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8202 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008203 }
8204}
8205
8206void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8207{
8208 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8209 target, levels, internalformat, width, height);
8210
Geoff Langbfdea662014-07-23 14:16:32 -04008211 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008212 if (context)
8213 {
8214 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008215 {
Geoff Langb1196682014-07-23 13:47:29 -04008216 context->recordError(gl::Error(GL_INVALID_OPERATION));
8217 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008218 }
Geoff Langbfdea662014-07-23 14:16:32 -04008219
8220 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8221 {
8222 return;
8223 }
8224
8225 switch (target)
8226 {
8227 case GL_TEXTURE_2D:
8228 {
8229 gl::Texture2D *texture2d = context->getTexture2D();
8230 texture2d->storage(levels, internalformat, width, height);
8231 }
8232 break;
8233
8234 case GL_TEXTURE_CUBE_MAP:
8235 {
8236 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8237 textureCube->storage(levels, internalformat, width);
8238 }
8239 break;
8240
8241 default:
Geoff Langb1196682014-07-23 13:47:29 -04008242 context->recordError(gl::Error(GL_INVALID_ENUM));
8243 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008244 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008245 }
8246}
8247
8248void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8249{
8250 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8251 "GLsizei height = %d, GLsizei depth = %d)",
8252 target, levels, internalformat, width, height, depth);
8253
Geoff Langbfdea662014-07-23 14:16:32 -04008254 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008255 if (context)
8256 {
8257 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008258 {
Geoff Langb1196682014-07-23 13:47:29 -04008259 context->recordError(gl::Error(GL_INVALID_OPERATION));
8260 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008261 }
Geoff Langbfdea662014-07-23 14:16:32 -04008262
8263 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8264 {
8265 return;
8266 }
8267
8268 switch (target)
8269 {
8270 case GL_TEXTURE_3D:
8271 {
8272 gl::Texture3D *texture3d = context->getTexture3D();
8273 texture3d->storage(levels, internalformat, width, height, depth);
8274 }
8275 break;
8276
8277 case GL_TEXTURE_2D_ARRAY:
8278 {
8279 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8280 texture2darray->storage(levels, internalformat, width, height, depth);
8281 }
8282 break;
8283
8284 default:
8285 UNREACHABLE();
8286 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008287 }
8288}
8289
8290void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8291{
8292 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8293 "GLint* params = 0x%0.8p)",
8294 target, internalformat, pname, bufSize, params);
8295
Geoff Langbfdea662014-07-23 14:16:32 -04008296 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008297 if (context)
8298 {
8299 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008300 {
Geoff Langb1196682014-07-23 13:47:29 -04008301 context->recordError(gl::Error(GL_INVALID_OPERATION));
8302 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008303 }
Geoff Langbfdea662014-07-23 14:16:32 -04008304
8305 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8306 if (!formatCaps.renderable)
8307 {
Geoff Langb1196682014-07-23 13:47:29 -04008308 context->recordError(gl::Error(GL_INVALID_ENUM));
8309 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008310 }
8311
8312 if (target != GL_RENDERBUFFER)
8313 {
Geoff Langb1196682014-07-23 13:47:29 -04008314 context->recordError(gl::Error(GL_INVALID_ENUM));
8315 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008316 }
8317
8318 if (bufSize < 0)
8319 {
Geoff Langb1196682014-07-23 13:47:29 -04008320 context->recordError(gl::Error(GL_INVALID_VALUE));
8321 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008322 }
8323
8324 switch (pname)
8325 {
8326 case GL_NUM_SAMPLE_COUNTS:
8327 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008328 {
8329 *params = formatCaps.sampleCounts.size();
8330 }
Geoff Langbfdea662014-07-23 14:16:32 -04008331 break;
Geoff Langb1196682014-07-23 13:47:29 -04008332
Geoff Langbfdea662014-07-23 14:16:32 -04008333 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008334 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008335 break;
Geoff Langb1196682014-07-23 13:47:29 -04008336
Geoff Langbfdea662014-07-23 14:16:32 -04008337 default:
Geoff Langb1196682014-07-23 13:47:29 -04008338 context->recordError(gl::Error(GL_INVALID_ENUM));
8339 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008340 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008341 }
8342}
8343
8344// Extension functions
8345
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008346void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8347 GLbitfield mask, GLenum filter)
8348{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008349 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008350 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8351 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8352 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8353
Geoff Langbfdea662014-07-23 14:16:32 -04008354 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008355 if (context)
8356 {
8357 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8358 dstX0, dstY0, dstX1, dstY1, mask, filter,
8359 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008360 {
Geoff Langbfdea662014-07-23 14:16:32 -04008361 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008362 }
Geoff Langbfdea662014-07-23 14:16:32 -04008363
Geoff Lang64839152014-08-26 16:23:25 -04008364 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8365 mask, filter);
8366 if (error.isError())
8367 {
8368 context->recordError(error);
8369 return;
8370 }
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008371 }
8372}
8373
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008374void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8375 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008376{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008377 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008378 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008379 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008380 target, level, internalformat, width, height, depth, border, format, type, pixels);
8381
Geoff Langbfdea662014-07-23 14:16:32 -04008382 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008383}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008384
Geoff Langbfdea662014-07-23 14:16:32 -04008385void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008386 GLenum *binaryFormat, void *binary)
8387{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008388 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 +00008389 program, bufSize, length, binaryFormat, binary);
8390
Geoff Langbfdea662014-07-23 14:16:32 -04008391 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008392 if (context)
8393 {
8394 gl::Program *programObject = context->getProgram(program);
8395
8396 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008397 {
Geoff Langb1196682014-07-23 13:47:29 -04008398 context->recordError(gl::Error(GL_INVALID_OPERATION));
8399 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008400 }
Geoff Langbfdea662014-07-23 14:16:32 -04008401
8402 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8403
8404 if (!programBinary)
8405 {
Geoff Langb1196682014-07-23 13:47:29 -04008406 context->recordError(gl::Error(GL_INVALID_OPERATION));
8407 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008408 }
8409
Geoff Langb543aff2014-09-30 14:52:54 -04008410 gl::Error error = programBinary->save(binaryFormat, binary, bufSize, length);
8411 if (error.isError())
Geoff Langbfdea662014-07-23 14:16:32 -04008412 {
Geoff Langb543aff2014-09-30 14:52:54 -04008413 context->recordError(error);
Geoff Langb1196682014-07-23 13:47:29 -04008414 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008415 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008416 }
8417}
8418
8419void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8420 const void *binary, GLint length)
8421{
8422 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8423 program, binaryFormat, binary, length);
8424
Geoff Langbfdea662014-07-23 14:16:32 -04008425 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008426 if (context)
8427 {
Geoff Lang900013c2014-07-07 11:32:19 -04008428 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8429 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008430 {
Geoff Langb1196682014-07-23 13:47:29 -04008431 context->recordError(gl::Error(GL_INVALID_ENUM));
8432 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008433 }
Geoff Langbfdea662014-07-23 14:16:32 -04008434
8435 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008436 if (!programObject)
8437 {
Geoff Langb1196682014-07-23 13:47:29 -04008438 context->recordError(gl::Error(GL_INVALID_OPERATION));
8439 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008440 }
8441
Geoff Langb543aff2014-09-30 14:52:54 -04008442 gl::Error error = context->setProgramBinary(program, binaryFormat, binary, length);
8443 if (error.isError())
8444 {
8445 context->recordError(error);
8446 return;
8447 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008448 }
8449}
8450
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008451void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8452{
8453 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8454
Geoff Langbfdea662014-07-23 14:16:32 -04008455 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008456 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008457 {
Geoff Langbfdea662014-07-23 14:16:32 -04008458 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008459 {
Geoff Langb1196682014-07-23 13:47:29 -04008460 context->recordError(gl::Error(GL_INVALID_VALUE));
8461 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008462 }
8463
8464 if (context->getState().getDrawFramebuffer()->id() == 0)
8465 {
8466 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008467 {
Geoff Langb1196682014-07-23 13:47:29 -04008468 context->recordError(gl::Error(GL_INVALID_OPERATION));
8469 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008470 }
8471
Geoff Langbfdea662014-07-23 14:16:32 -04008472 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008473 {
Geoff Langb1196682014-07-23 13:47:29 -04008474 context->recordError(gl::Error(GL_INVALID_OPERATION));
8475 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008476 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008477 }
Geoff Langbfdea662014-07-23 14:16:32 -04008478 else
8479 {
8480 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8481 {
8482 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8483 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8484 {
Geoff Langb1196682014-07-23 13:47:29 -04008485 context->recordError(gl::Error(GL_INVALID_OPERATION));
8486 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008487 }
8488 }
8489 }
8490
8491 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8492
8493 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8494 {
8495 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8496 }
8497
8498 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8499 {
8500 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8501 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008502 }
8503}
8504
Shannon Woodsb3801742014-03-27 14:59:19 -04008505void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8506{
8507 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8508
Geoff Langbfdea662014-07-23 14:16:32 -04008509 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008510 if (context)
8511 {
8512 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008513 {
Geoff Langb1196682014-07-23 13:47:29 -04008514 context->recordError(gl::Error(GL_INVALID_ENUM));
8515 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008516 }
Geoff Langbfdea662014-07-23 14:16:32 -04008517
8518 if (pname != GL_BUFFER_MAP_POINTER)
8519 {
Geoff Langb1196682014-07-23 13:47:29 -04008520 context->recordError(gl::Error(GL_INVALID_ENUM));
8521 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008522 }
8523
8524 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8525
8526 if (!buffer || !buffer->isMapped())
8527 {
8528 *params = NULL;
8529 }
8530 else
8531 {
8532 *params = buffer->getMapPointer();
8533 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008534 }
8535}
8536
8537void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8538{
8539 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8540
Geoff Langbfdea662014-07-23 14:16:32 -04008541 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008542 if (context)
8543 {
8544 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008545 {
Geoff Langb1196682014-07-23 13:47:29 -04008546 context->recordError(gl::Error(GL_INVALID_ENUM));
8547 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008548 }
Geoff Langbfdea662014-07-23 14:16:32 -04008549
8550 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8551
8552 if (buffer == NULL)
8553 {
Geoff Langb1196682014-07-23 13:47:29 -04008554 context->recordError(gl::Error(GL_INVALID_OPERATION));
8555 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008556 }
8557
8558 if (access != GL_WRITE_ONLY_OES)
8559 {
Geoff Langb1196682014-07-23 13:47:29 -04008560 context->recordError(gl::Error(GL_INVALID_ENUM));
8561 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008562 }
8563
8564 if (buffer->isMapped())
8565 {
Geoff Langb1196682014-07-23 13:47:29 -04008566 context->recordError(gl::Error(GL_INVALID_OPERATION));
8567 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008568 }
8569
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008570 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8571 if (error.isError())
8572 {
8573 context->recordError(error);
8574 return NULL;
8575 }
8576
8577 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008578 }
8579
8580 return NULL;
8581}
8582
8583GLboolean __stdcall glUnmapBufferOES(GLenum target)
8584{
8585 EVENT("(GLenum target = 0x%X)", target);
8586
Geoff Langbfdea662014-07-23 14:16:32 -04008587 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008588 if (context)
8589 {
8590 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008591 {
Geoff Langb1196682014-07-23 13:47:29 -04008592 context->recordError(gl::Error(GL_INVALID_ENUM));
8593 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008594 }
Geoff Langbfdea662014-07-23 14:16:32 -04008595
8596 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8597
8598 if (buffer == NULL || !buffer->isMapped())
8599 {
Geoff Langb1196682014-07-23 13:47:29 -04008600 context->recordError(gl::Error(GL_INVALID_OPERATION));
8601 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008602 }
8603
8604 // TODO: detect if we had corruption. if so, throw an error and return false.
8605
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008606 gl::Error error = buffer->unmap();
8607 if (error.isError())
8608 {
8609 context->recordError(error);
8610 return GL_FALSE;
8611 }
Geoff Langbfdea662014-07-23 14:16:32 -04008612
8613 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008614 }
8615
8616 return GL_FALSE;
8617}
8618
Shannon Woods916e7692014-03-27 16:58:22 -04008619void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8620{
8621 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8622 target, offset, length, access);
8623
Geoff Langbfdea662014-07-23 14:16:32 -04008624 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008625 if (context)
8626 {
8627 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008628 {
Geoff Langb1196682014-07-23 13:47:29 -04008629 context->recordError(gl::Error(GL_INVALID_ENUM));
8630 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008631 }
Geoff Langbfdea662014-07-23 14:16:32 -04008632
8633 if (offset < 0 || length < 0)
8634 {
Geoff Langb1196682014-07-23 13:47:29 -04008635 context->recordError(gl::Error(GL_INVALID_VALUE));
8636 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008637 }
8638
8639 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8640
8641 if (buffer == NULL)
8642 {
Geoff Langb1196682014-07-23 13:47:29 -04008643 context->recordError(gl::Error(GL_INVALID_OPERATION));
8644 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008645 }
8646
8647 // Check for buffer overflow
8648 size_t offsetSize = static_cast<size_t>(offset);
8649 size_t lengthSize = static_cast<size_t>(length);
8650
8651 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8652 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8653 {
Geoff Langb1196682014-07-23 13:47:29 -04008654 context->recordError(gl::Error(GL_INVALID_VALUE));
8655 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008656 }
8657
8658 // Check for invalid bits in the mask
8659 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8660 GL_MAP_WRITE_BIT |
8661 GL_MAP_INVALIDATE_RANGE_BIT |
8662 GL_MAP_INVALIDATE_BUFFER_BIT |
8663 GL_MAP_FLUSH_EXPLICIT_BIT |
8664 GL_MAP_UNSYNCHRONIZED_BIT;
8665
8666 if (access & ~(allAccessBits))
8667 {
Geoff Langb1196682014-07-23 13:47:29 -04008668 context->recordError(gl::Error(GL_INVALID_VALUE));
8669 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008670 }
8671
8672 if (length == 0 || buffer->isMapped())
8673 {
Geoff Langb1196682014-07-23 13:47:29 -04008674 context->recordError(gl::Error(GL_INVALID_OPERATION));
8675 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008676 }
8677
8678 // Check for invalid bit combinations
8679 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8680 {
Geoff Langb1196682014-07-23 13:47:29 -04008681 context->recordError(gl::Error(GL_INVALID_OPERATION));
8682 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008683 }
8684
8685 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8686 GL_MAP_INVALIDATE_BUFFER_BIT |
8687 GL_MAP_UNSYNCHRONIZED_BIT;
8688
8689 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8690 {
Geoff Langb1196682014-07-23 13:47:29 -04008691 context->recordError(gl::Error(GL_INVALID_OPERATION));
8692 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008693 }
8694
8695 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8696 {
Geoff Langb1196682014-07-23 13:47:29 -04008697 context->recordError(gl::Error(GL_INVALID_OPERATION));
8698 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008699 }
8700
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008701 gl::Error error = buffer->mapRange(offset, length, access);
8702 if (error.isError())
8703 {
8704 context->recordError(error);
8705 return NULL;
8706 }
8707
8708 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008709 }
8710
8711 return NULL;
8712}
8713
8714void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8715{
8716 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8717
Geoff Langbfdea662014-07-23 14:16:32 -04008718 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008719 if (context)
8720 {
8721 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008722 {
Geoff Langb1196682014-07-23 13:47:29 -04008723 context->recordError(gl::Error(GL_INVALID_VALUE));
8724 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008725 }
Geoff Langbfdea662014-07-23 14:16:32 -04008726
8727 if (!gl::ValidBufferTarget(context, target))
8728 {
Geoff Langb1196682014-07-23 13:47:29 -04008729 context->recordError(gl::Error(GL_INVALID_ENUM));
8730 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008731 }
8732
8733 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8734
8735 if (buffer == NULL)
8736 {
Geoff Langb1196682014-07-23 13:47:29 -04008737 context->recordError(gl::Error(GL_INVALID_OPERATION));
8738 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008739 }
8740
8741 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8742 {
Geoff Langb1196682014-07-23 13:47:29 -04008743 context->recordError(gl::Error(GL_INVALID_OPERATION));
8744 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008745 }
8746
8747 // Check for buffer overflow
8748 size_t offsetSize = static_cast<size_t>(offset);
8749 size_t lengthSize = static_cast<size_t>(length);
8750
8751 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8752 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8753 {
Geoff Langb1196682014-07-23 13:47:29 -04008754 context->recordError(gl::Error(GL_INVALID_VALUE));
8755 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008756 }
8757
8758 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008759 }
8760}
8761
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008762__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8763{
8764 struct Extension
8765 {
8766 const char *name;
8767 __eglMustCastToProperFunctionPointerType address;
8768 };
8769
8770 static const Extension glExtensions[] =
8771 {
8772 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008773 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008774 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008775 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8776 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8777 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8778 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8779 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8780 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8781 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008782 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008783 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008784 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8785 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8786 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8787 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008788 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8789 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8790 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8791 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8792 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8793 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8794 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008795 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008796 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8797 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8798 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008799 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008800 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8801 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8802 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008803 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8804 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8805 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008806
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008807 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008808 {
8809 if (strcmp(procname, glExtensions[ext].name) == 0)
8810 {
8811 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8812 }
8813 }
8814
8815 return NULL;
8816}
8817
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008818// Non-public functions used by EGL
8819
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008820bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008821{
8822 EVENT("(egl::Surface* surface = 0x%0.8p)",
8823 surface);
8824
Geoff Langbfdea662014-07-23 14:16:32 -04008825 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008826 if (context)
8827 {
8828 gl::Texture2D *textureObject = context->getTexture2D();
8829 ASSERT(textureObject != NULL);
8830
8831 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008832 {
Geoff Langbfdea662014-07-23 14:16:32 -04008833 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008834 }
Geoff Langbfdea662014-07-23 14:16:32 -04008835
8836 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008837 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008838
8839 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008840}
8841
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008842}