blob: a62e163f5d37115d8f6b172e6c8271e0eaa73369 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Geoff Lang48dcae72014-02-05 16:28:24 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
8
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00009#include "common/version.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040010#include "common/utilities.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000013#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000014#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000015#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000016#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000017#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000018#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000019#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000020#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000021#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000022#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040023#include "libGLESv2/VertexArray.h"
Brandon Jones5bf98292014-06-06 17:19:38 -070024#include "libGLESv2/VertexAttribute.h"
Geoff Langc8058452014-02-03 12:04:11 -050025#include "libGLESv2/TransformFeedback.h"
Jamie Madille261b442014-06-25 12:42:21 -040026#include "libGLESv2/FramebufferAttachment.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027
Geoff Lange8ebe7f2013-08-05 15:03:13 -040028#include "libGLESv2/validationES.h"
29#include "libGLESv2/validationES2.h"
30#include "libGLESv2/validationES3.h"
Jamie Madill55856b12014-01-02 13:59:50 -050031#include "libGLESv2/queryconversions.h"
Jamie Madill478fdb22013-07-19 16:36:59 -040032
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033extern "C"
34{
35
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000036// OpenGL ES 2.0 functions
37
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038void __stdcall glActiveTexture(GLenum texture)
39{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000040 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000041
Geoff Langbfdea662014-07-23 14:16:32 -040042 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -040043 if (context)
44 {
Geoff Lang3a61c322014-07-10 13:01:54 -040045 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000046 {
Geoff Langb1196682014-07-23 13:47:29 -040047 context->recordError(gl::Error(GL_INVALID_ENUM));
48 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049 }
Geoff Langbfdea662014-07-23 14:16:32 -040050
51 context->getState().setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052 }
53}
54
55void __stdcall glAttachShader(GLuint program, GLuint shader)
56{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000057 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000058
Geoff Langbfdea662014-07-23 14:16:32 -040059 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -040060 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000061 {
Geoff Langbfdea662014-07-23 14:16:32 -040062 gl::Program *programObject = context->getProgram(program);
63 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064
Geoff Langbfdea662014-07-23 14:16:32 -040065 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066 {
Geoff Langbfdea662014-07-23 14:16:32 -040067 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000068 {
Geoff Langb1196682014-07-23 13:47:29 -040069 context->recordError(gl::Error(GL_INVALID_OPERATION));
70 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000071 }
Geoff Langbfdea662014-07-23 14:16:32 -040072 else
73 {
Geoff Langb1196682014-07-23 13:47:29 -040074 context->recordError(gl::Error(GL_INVALID_VALUE));
75 return;
Geoff Langbfdea662014-07-23 14:16:32 -040076 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000077 }
Geoff Langbfdea662014-07-23 14:16:32 -040078
79 if (!shaderObject)
80 {
81 if (context->getProgram(shader))
82 {
Geoff Langb1196682014-07-23 13:47:29 -040083 context->recordError(gl::Error(GL_INVALID_OPERATION));
84 return;
Geoff Langbfdea662014-07-23 14:16:32 -040085 }
86 else
87 {
Geoff Langb1196682014-07-23 13:47:29 -040088 context->recordError(gl::Error(GL_INVALID_VALUE));
89 return;
Geoff Langbfdea662014-07-23 14:16:32 -040090 }
91 }
92
93 if (!programObject->attachShader(shaderObject))
94 {
Geoff Langb1196682014-07-23 13:47:29 -040095 context->recordError(gl::Error(GL_INVALID_OPERATION));
96 return;
Geoff Langbfdea662014-07-23 14:16:32 -040097 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098 }
99}
100
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000101void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
102{
103 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
104
Geoff Langbfdea662014-07-23 14:16:32 -0400105 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400106 if (context)
107 {
108 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000109 {
Geoff Langbfdea662014-07-23 14:16:32 -0400110 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000111 }
Geoff Langbfdea662014-07-23 14:16:32 -0400112
Geoff Lang5aad9672014-09-08 11:10:42 -0400113 gl::Error error = context->beginQuery(target, id);
114 if (error.isError())
115 {
116 context->recordError(error);
117 return;
118 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000119 }
120}
121
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000122void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000124 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
Geoff Langbfdea662014-07-23 14:16:32 -0400126 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400127 if (context)
128 {
Geoff Langb1196682014-07-23 13:47:29 -0400129 if (index >= gl::MAX_VERTEX_ATTRIBS)
130 {
131 context->recordError(gl::Error(GL_INVALID_VALUE));
132 return;
133 }
134
Geoff Langbfdea662014-07-23 14:16:32 -0400135 gl::Program *programObject = context->getProgram(program);
136
137 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000138 {
Geoff Langbfdea662014-07-23 14:16:32 -0400139 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000140 {
Geoff Langb1196682014-07-23 13:47:29 -0400141 context->recordError(gl::Error(GL_INVALID_OPERATION));
142 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000143 }
Geoff Langbfdea662014-07-23 14:16:32 -0400144 else
145 {
Geoff Langb1196682014-07-23 13:47:29 -0400146 context->recordError(gl::Error(GL_INVALID_VALUE));
147 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400148 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000149 }
Geoff Langbfdea662014-07-23 14:16:32 -0400150
151 if (strncmp(name, "gl_", 3) == 0)
152 {
Geoff Langb1196682014-07-23 13:47:29 -0400153 context->recordError(gl::Error(GL_INVALID_OPERATION));
154 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400155 }
156
157 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000158 }
159}
160
161void __stdcall glBindBuffer(GLenum target, GLuint buffer)
162{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000163 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000164
Geoff Langbfdea662014-07-23 14:16:32 -0400165 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400166 if (context)
167 {
168 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000169 {
Geoff Langb1196682014-07-23 13:47:29 -0400170 context->recordError(gl::Error(GL_INVALID_ENUM));
171 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000172 }
Geoff Langbfdea662014-07-23 14:16:32 -0400173
174 switch (target)
175 {
176 case GL_ARRAY_BUFFER:
177 context->bindArrayBuffer(buffer);
178 return;
179 case GL_ELEMENT_ARRAY_BUFFER:
180 context->bindElementArrayBuffer(buffer);
181 return;
182 case GL_COPY_READ_BUFFER:
183 context->bindCopyReadBuffer(buffer);
184 return;
185 case GL_COPY_WRITE_BUFFER:
186 context->bindCopyWriteBuffer(buffer);
187 return;
188 case GL_PIXEL_PACK_BUFFER:
189 context->bindPixelPackBuffer(buffer);
190 return;
191 case GL_PIXEL_UNPACK_BUFFER:
192 context->bindPixelUnpackBuffer(buffer);
193 return;
194 case GL_UNIFORM_BUFFER:
195 context->bindGenericUniformBuffer(buffer);
196 return;
197 case GL_TRANSFORM_FEEDBACK_BUFFER:
198 context->bindGenericTransformFeedbackBuffer(buffer);
199 return;
Geoff Langb1196682014-07-23 13:47:29 -0400200
Geoff Langbfdea662014-07-23 14:16:32 -0400201 default:
Geoff Langb1196682014-07-23 13:47:29 -0400202 context->recordError(gl::Error(GL_INVALID_ENUM));
203 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400204 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000205 }
206}
207
208void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000210 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000211
Geoff Langbfdea662014-07-23 14:16:32 -0400212 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400213 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000214 {
Geoff Langb1196682014-07-23 13:47:29 -0400215 if (!gl::ValidFramebufferTarget(target))
216 {
217 context->recordError(gl::Error(GL_INVALID_ENUM));
218 return;
219 }
220
Geoff Langbfdea662014-07-23 14:16:32 -0400221 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
222 {
223 context->bindReadFramebuffer(framebuffer);
224 }
225
226 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
227 {
228 context->bindDrawFramebuffer(framebuffer);
229 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000230 }
231}
232
233void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
234{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000235 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000236
Geoff Langbfdea662014-07-23 14:16:32 -0400237 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400238 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000239 {
Geoff Langb1196682014-07-23 13:47:29 -0400240 if (target != GL_RENDERBUFFER)
241 {
242 context->recordError(gl::Error(GL_INVALID_ENUM));
243 return;
244 }
245
Geoff Langbfdea662014-07-23 14:16:32 -0400246 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000247 }
248}
249
250void __stdcall glBindTexture(GLenum target, GLuint texture)
251{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000252 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000253
Geoff Langbfdea662014-07-23 14:16:32 -0400254 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400255 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000256 {
Geoff Langbfdea662014-07-23 14:16:32 -0400257 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000258
Geoff Langbfdea662014-07-23 14:16:32 -0400259 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000260 {
Geoff Langb1196682014-07-23 13:47:29 -0400261 context->recordError(gl::Error(GL_INVALID_OPERATION));
262 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400263 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000264
Geoff Langbfdea662014-07-23 14:16:32 -0400265 switch (target)
266 {
267 case GL_TEXTURE_2D:
Geoff Langbfdea662014-07-23 14:16:32 -0400268 case GL_TEXTURE_CUBE_MAP:
Geoff Lang76b10c92014-09-05 16:28:14 -0400269 break;
Geoff Langb1196682014-07-23 13:47:29 -0400270
Geoff Langbfdea662014-07-23 14:16:32 -0400271 case GL_TEXTURE_3D:
Geoff Langbfdea662014-07-23 14:16:32 -0400272 case GL_TEXTURE_2D_ARRAY:
273 if (context->getClientVersion() < 3)
274 {
Geoff Langb1196682014-07-23 13:47:29 -0400275 context->recordError(gl::Error(GL_INVALID_ENUM));
276 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400277 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400278 break;
Geoff Langb1196682014-07-23 13:47:29 -0400279
Geoff Langbfdea662014-07-23 14:16:32 -0400280 default:
Geoff Langb1196682014-07-23 13:47:29 -0400281 context->recordError(gl::Error(GL_INVALID_ENUM));
282 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000283 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400284
285 context->bindTexture(target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000286 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287}
288
289void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000291 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000292 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000293
Geoff Langbfdea662014-07-23 14:16:32 -0400294 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000295
Geoff Langbfdea662014-07-23 14:16:32 -0400296 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000297 {
Geoff Langbfdea662014-07-23 14:16:32 -0400298 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000299 }
300}
301
302void __stdcall glBlendEquation(GLenum mode)
303{
304 glBlendEquationSeparate(mode, mode);
305}
306
307void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
308{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000309 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000310
Geoff Langbfdea662014-07-23 14:16:32 -0400311 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400312 if (context)
313 {
Geoff Langb1196682014-07-23 13:47:29 -0400314 switch (modeRGB)
315 {
316 case GL_FUNC_ADD:
317 case GL_FUNC_SUBTRACT:
318 case GL_FUNC_REVERSE_SUBTRACT:
319 case GL_MIN:
320 case GL_MAX:
321 break;
322
323 default:
324 context->recordError(gl::Error(GL_INVALID_ENUM));
325 return;
326 }
327
328 switch (modeAlpha)
329 {
330 case GL_FUNC_ADD:
331 case GL_FUNC_SUBTRACT:
332 case GL_FUNC_REVERSE_SUBTRACT:
333 case GL_MIN:
334 case GL_MAX:
335 break;
336
337 default:
338 context->recordError(gl::Error(GL_INVALID_ENUM));
339 return;
340 }
341
Geoff Langbfdea662014-07-23 14:16:32 -0400342 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000343 }
344}
345
346void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
347{
348 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
349}
350
351void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
352{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000353 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000354 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000355
Geoff Langbfdea662014-07-23 14:16:32 -0400356 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400357 if (context)
358 {
Geoff Langb1196682014-07-23 13:47:29 -0400359 switch (srcRGB)
360 {
361 case GL_ZERO:
362 case GL_ONE:
363 case GL_SRC_COLOR:
364 case GL_ONE_MINUS_SRC_COLOR:
365 case GL_DST_COLOR:
366 case GL_ONE_MINUS_DST_COLOR:
367 case GL_SRC_ALPHA:
368 case GL_ONE_MINUS_SRC_ALPHA:
369 case GL_DST_ALPHA:
370 case GL_ONE_MINUS_DST_ALPHA:
371 case GL_CONSTANT_COLOR:
372 case GL_ONE_MINUS_CONSTANT_COLOR:
373 case GL_CONSTANT_ALPHA:
374 case GL_ONE_MINUS_CONSTANT_ALPHA:
375 case GL_SRC_ALPHA_SATURATE:
376 break;
377
378 default:
379 context->recordError(gl::Error(GL_INVALID_ENUM));
380 return;
381 }
382
383 switch (dstRGB)
384 {
385 case GL_ZERO:
386 case GL_ONE:
387 case GL_SRC_COLOR:
388 case GL_ONE_MINUS_SRC_COLOR:
389 case GL_DST_COLOR:
390 case GL_ONE_MINUS_DST_COLOR:
391 case GL_SRC_ALPHA:
392 case GL_ONE_MINUS_SRC_ALPHA:
393 case GL_DST_ALPHA:
394 case GL_ONE_MINUS_DST_ALPHA:
395 case GL_CONSTANT_COLOR:
396 case GL_ONE_MINUS_CONSTANT_COLOR:
397 case GL_CONSTANT_ALPHA:
398 case GL_ONE_MINUS_CONSTANT_ALPHA:
399 break;
400
401 case GL_SRC_ALPHA_SATURATE:
402 if (context->getClientVersion() < 3)
403 {
404 context->recordError(gl::Error(GL_INVALID_ENUM));
405 return;
406 }
407 break;
408
409 default:
410 context->recordError(gl::Error(GL_INVALID_ENUM));
411 return;
412 }
413
414 switch (srcAlpha)
415 {
416 case GL_ZERO:
417 case GL_ONE:
418 case GL_SRC_COLOR:
419 case GL_ONE_MINUS_SRC_COLOR:
420 case GL_DST_COLOR:
421 case GL_ONE_MINUS_DST_COLOR:
422 case GL_SRC_ALPHA:
423 case GL_ONE_MINUS_SRC_ALPHA:
424 case GL_DST_ALPHA:
425 case GL_ONE_MINUS_DST_ALPHA:
426 case GL_CONSTANT_COLOR:
427 case GL_ONE_MINUS_CONSTANT_COLOR:
428 case GL_CONSTANT_ALPHA:
429 case GL_ONE_MINUS_CONSTANT_ALPHA:
430 case GL_SRC_ALPHA_SATURATE:
431 break;
432
433 default:
434 context->recordError(gl::Error(GL_INVALID_ENUM));
435 return;
436 }
437
438 switch (dstAlpha)
439 {
440 case GL_ZERO:
441 case GL_ONE:
442 case GL_SRC_COLOR:
443 case GL_ONE_MINUS_SRC_COLOR:
444 case GL_DST_COLOR:
445 case GL_ONE_MINUS_DST_COLOR:
446 case GL_SRC_ALPHA:
447 case GL_ONE_MINUS_SRC_ALPHA:
448 case GL_DST_ALPHA:
449 case GL_ONE_MINUS_DST_ALPHA:
450 case GL_CONSTANT_COLOR:
451 case GL_ONE_MINUS_CONSTANT_COLOR:
452 case GL_CONSTANT_ALPHA:
453 case GL_ONE_MINUS_CONSTANT_ALPHA:
454 break;
455
456 case GL_SRC_ALPHA_SATURATE:
457 if (context->getClientVersion() < 3)
458 {
459 context->recordError(gl::Error(GL_INVALID_ENUM));
460 return;
461 }
462 break;
463
464 default:
465 context->recordError(gl::Error(GL_INVALID_ENUM));
466 return;
467 }
468
469 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
470 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
471
472 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
473 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
474
475 if (constantColorUsed && constantAlphaUsed)
476 {
477 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
478 context->recordError(gl::Error(GL_INVALID_OPERATION));
479 return;
480 }
481
Geoff Langbfdea662014-07-23 14:16:32 -0400482 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000483 }
484}
485
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000486void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000487{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000488 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000489 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000490
Geoff Langbfdea662014-07-23 14:16:32 -0400491 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400492 if (context)
493 {
Geoff Langb1196682014-07-23 13:47:29 -0400494 if (size < 0)
495 {
496 context->recordError(gl::Error(GL_INVALID_VALUE));
497 return;
498 }
499
500 switch (usage)
501 {
502 case GL_STREAM_DRAW:
503 case GL_STATIC_DRAW:
504 case GL_DYNAMIC_DRAW:
505 break;
506
507 case GL_STREAM_READ:
508 case GL_STREAM_COPY:
509 case GL_STATIC_READ:
510 case GL_STATIC_COPY:
511 case GL_DYNAMIC_READ:
512 case GL_DYNAMIC_COPY:
513 if (context->getClientVersion() < 3)
514 {
515 context->recordError(gl::Error(GL_INVALID_ENUM));
516 return;
517 }
518 break;
519
520 default:
521 context->recordError(gl::Error(GL_INVALID_ENUM));
522 return;
523 }
524
Geoff Langbfdea662014-07-23 14:16:32 -0400525 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000526 {
Geoff Langb1196682014-07-23 13:47:29 -0400527 context->recordError(gl::Error(GL_INVALID_ENUM));
528 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000529 }
530
Geoff Langbfdea662014-07-23 14:16:32 -0400531 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
532
533 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000534 {
Geoff Langb1196682014-07-23 13:47:29 -0400535 context->recordError(gl::Error(GL_INVALID_OPERATION));
536 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000537 }
Geoff Langbfdea662014-07-23 14:16:32 -0400538
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400539 gl::Error error = buffer->bufferData(data, size, usage);
540 if (error.isError())
541 {
542 context->recordError(error);
543 return;
544 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000545 }
546}
547
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000548void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000549{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000550 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000551 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000552
Geoff Langbfdea662014-07-23 14:16:32 -0400553 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400554 if (context)
555 {
Geoff Langb1196682014-07-23 13:47:29 -0400556 if (size < 0 || offset < 0)
557 {
558 context->recordError(gl::Error(GL_INVALID_VALUE));
559 return;
560 }
561
562 if (data == NULL)
563 {
564 return;
565 }
566
Geoff Langbfdea662014-07-23 14:16:32 -0400567 if (!gl::ValidBufferTarget(context, target))
568 {
Geoff Langb1196682014-07-23 13:47:29 -0400569 context->recordError(gl::Error(GL_INVALID_ENUM));
570 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400571 }
572
573 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
574
575 if (!buffer)
576 {
Geoff Langb1196682014-07-23 13:47:29 -0400577 context->recordError(gl::Error(GL_INVALID_OPERATION));
578 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400579 }
580
581 if (buffer->isMapped())
582 {
Geoff Langb1196682014-07-23 13:47:29 -0400583 context->recordError(gl::Error(GL_INVALID_OPERATION));
584 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400585 }
586
587 // Check for possible overflow of size + offset
588 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
589 {
Geoff Langb1196682014-07-23 13:47:29 -0400590 context->recordError(gl::Error(GL_OUT_OF_MEMORY));
591 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400592 }
593
594 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000595 {
Geoff Langb1196682014-07-23 13:47:29 -0400596 context->recordError(gl::Error(GL_INVALID_VALUE));
597 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000598 }
599
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400600 gl::Error error = buffer->bufferSubData(data, size, offset);
601 if (error.isError())
602 {
603 context->recordError(error);
604 return;
605 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000606 }
607}
608
609GLenum __stdcall glCheckFramebufferStatus(GLenum target)
610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000611 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000612
Geoff Langbfdea662014-07-23 14:16:32 -0400613 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400614 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000615 {
Geoff Langb1196682014-07-23 13:47:29 -0400616 if (!gl::ValidFramebufferTarget(target))
617 {
618 context->recordError(gl::Error(GL_INVALID_ENUM));
619 return 0;
620 }
621
Geoff Langbfdea662014-07-23 14:16:32 -0400622 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
623 ASSERT(framebuffer);
624 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625 }
626
627 return 0;
628}
629
630void __stdcall glClear(GLbitfield mask)
631{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000632 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000633
Geoff Langbfdea662014-07-23 14:16:32 -0400634 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400635 if (context)
636 {
637 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
638
639 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000640 {
Geoff Langb1196682014-07-23 13:47:29 -0400641 context->recordError(gl::Error(GL_INVALID_FRAMEBUFFER_OPERATION));
642 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000643 }
Geoff Langbfdea662014-07-23 14:16:32 -0400644
645 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
646 {
Geoff Langb1196682014-07-23 13:47:29 -0400647 context->recordError(gl::Error(GL_INVALID_VALUE));
648 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400649 }
650
Geoff Langcc79b8c2014-07-25 13:48:02 -0400651 gl::Error error = context->clear(mask);
652 if (error.isError())
653 {
654 context->recordError(error);
655 return;
656 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000657 }
658}
659
660void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000662 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000663 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000664
Geoff Langbfdea662014-07-23 14:16:32 -0400665 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400666 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000667 {
Geoff Langbfdea662014-07-23 14:16:32 -0400668 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000669 }
670}
671
672void __stdcall glClearDepthf(GLclampf depth)
673{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000674 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000675
Geoff Langbfdea662014-07-23 14:16:32 -0400676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400677 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000678 {
Geoff Langbfdea662014-07-23 14:16:32 -0400679 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000680 }
681}
682
683void __stdcall glClearStencil(GLint s)
684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000685 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000686
Geoff Langbfdea662014-07-23 14:16:32 -0400687 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400688 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000689 {
Geoff Langbfdea662014-07-23 14:16:32 -0400690 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000691 }
692}
693
694void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
695{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000696 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000697 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000698
Geoff Langbfdea662014-07-23 14:16:32 -0400699 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400700 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000701 {
Geoff Langbfdea662014-07-23 14:16:32 -0400702 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000703 }
704}
705
706void __stdcall glCompileShader(GLuint shader)
707{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000708 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000709
Geoff Langbfdea662014-07-23 14:16:32 -0400710 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400711 if (context)
712 {
713 gl::Shader *shaderObject = context->getShader(shader);
714
715 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000716 {
Geoff Langbfdea662014-07-23 14:16:32 -0400717 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000718 {
Geoff Langb1196682014-07-23 13:47:29 -0400719 context->recordError(gl::Error(GL_INVALID_OPERATION));
720 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000721 }
Geoff Langbfdea662014-07-23 14:16:32 -0400722 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000723 {
Geoff Langb1196682014-07-23 13:47:29 -0400724 context->recordError(gl::Error(GL_INVALID_VALUE));
725 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000726 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000727 }
Geoff Langbfdea662014-07-23 14:16:32 -0400728
729 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000730 }
Geoff Langbfdea662014-07-23 14:16:32 -0400731}
732
733void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
734 GLint border, GLsizei imageSize, const GLvoid* data)
735{
736 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
737 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
738 target, level, internalformat, width, height, border, imageSize, data);
739
740 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400741 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000742 {
Geoff Langbfdea662014-07-23 14:16:32 -0400743 if (context->getClientVersion() < 3 &&
744 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
745 0, 0, width, height, border, GL_NONE, GL_NONE, data))
746 {
747 return;
748 }
749
750 if (context->getClientVersion() >= 3 &&
751 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
752 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
753 {
754 return;
755 }
756
Geoff Lang5d601382014-07-22 15:14:06 -0400757 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
758 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400759 {
Geoff Langb1196682014-07-23 13:47:29 -0400760 context->recordError(gl::Error(GL_INVALID_VALUE));
761 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400762 }
763
764 switch (target)
765 {
766 case GL_TEXTURE_2D:
767 {
768 gl::Texture2D *texture = context->getTexture2D();
769 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
770 }
771 break;
772
773 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
774 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
775 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
776 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
777 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
778 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
779 {
780 gl::TextureCubeMap *texture = context->getTextureCubeMap();
781 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
782 }
783 break;
784
785 default:
Geoff Langb1196682014-07-23 13:47:29 -0400786 context->recordError(gl::Error(GL_INVALID_ENUM));
787 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400788 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000789 }
790}
791
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000792void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
793 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000794{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000795 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000796 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000797 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000798 target, level, xoffset, yoffset, width, height, format, imageSize, data);
799
Geoff Langbfdea662014-07-23 14:16:32 -0400800 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400801 if (context)
802 {
803 if (context->getClientVersion() < 3 &&
804 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
805 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000806 {
Geoff Langbfdea662014-07-23 14:16:32 -0400807 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000808 }
Geoff Langbfdea662014-07-23 14:16:32 -0400809
810 if (context->getClientVersion() >= 3 &&
811 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
812 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
813 {
814 return;
815 }
816
Geoff Lang5d601382014-07-22 15:14:06 -0400817 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
818 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400819 {
Geoff Langb1196682014-07-23 13:47:29 -0400820 context->recordError(gl::Error(GL_INVALID_VALUE));
821 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400822 }
823
824 switch (target)
825 {
826 case GL_TEXTURE_2D:
827 {
828 gl::Texture2D *texture = context->getTexture2D();
829 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
830 }
831 break;
832
833 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
834 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
835 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
836 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
837 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
838 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
839 {
840 gl::TextureCubeMap *texture = context->getTextureCubeMap();
841 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
842 }
843 break;
844
845 default:
Geoff Langb1196682014-07-23 13:47:29 -0400846 context->recordError(gl::Error(GL_INVALID_ENUM));
847 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400848 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000849 }
850}
851
852void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
853{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000854 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000855 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000856 target, level, internalformat, x, y, width, height, border);
857
Geoff Langbfdea662014-07-23 14:16:32 -0400858 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400859 if (context)
860 {
861 if (context->getClientVersion() < 3 &&
862 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
863 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000864 {
Geoff Langbfdea662014-07-23 14:16:32 -0400865 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000866 }
Geoff Langbfdea662014-07-23 14:16:32 -0400867
868 if (context->getClientVersion() >= 3 &&
869 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
870 0, 0, 0, x, y, width, height, border))
871 {
872 return;
873 }
874
875 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
876
877 switch (target)
878 {
879 case GL_TEXTURE_2D:
880 {
881 gl::Texture2D *texture = context->getTexture2D();
882 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
883 }
884 break;
885
886 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
887 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
888 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
889 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
890 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
891 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
892 {
893 gl::TextureCubeMap *texture = context->getTextureCubeMap();
894 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
895 }
896 break;
897
Geoff Langb1196682014-07-23 13:47:29 -0400898 default:
899 context->recordError(gl::Error(GL_INVALID_ENUM));
900 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400901 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000902 }
903}
904
905void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
906{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000907 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000908 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000909 target, level, xoffset, yoffset, x, y, width, height);
910
Geoff Langbfdea662014-07-23 14:16:32 -0400911 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400912 if (context)
913 {
914 if (context->getClientVersion() < 3 &&
915 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
916 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000917 {
Geoff Langbfdea662014-07-23 14:16:32 -0400918 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000919 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000920
Geoff Langbfdea662014-07-23 14:16:32 -0400921 if (context->getClientVersion() >= 3 &&
922 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
923 xoffset, yoffset, 0, x, y, width, height, 0))
924 {
925 return;
926 }
927
928 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
929
930 switch (target)
931 {
932 case GL_TEXTURE_2D:
933 {
934 gl::Texture2D *texture = context->getTexture2D();
935 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
936 }
937 break;
938
939 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
940 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
941 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
942 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
943 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
944 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
945 {
946 gl::TextureCubeMap *texture = context->getTextureCubeMap();
947 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
948 }
949 break;
950
951 default:
Geoff Langb1196682014-07-23 13:47:29 -0400952 context->recordError(gl::Error(GL_INVALID_ENUM));
953 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400954 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000955 }
956}
957
958GLuint __stdcall glCreateProgram(void)
959{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000960 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000961
Geoff Langbfdea662014-07-23 14:16:32 -0400962 gl::Context *context = gl::getNonLostContext();
963 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000964 {
Geoff Langbfdea662014-07-23 14:16:32 -0400965 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000966 }
967
968 return 0;
969}
970
971GLuint __stdcall glCreateShader(GLenum type)
972{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000973 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000974
Geoff Langbfdea662014-07-23 14:16:32 -0400975 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400976 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000977 {
Geoff Langbfdea662014-07-23 14:16:32 -0400978 switch (type)
979 {
980 case GL_FRAGMENT_SHADER:
981 case GL_VERTEX_SHADER:
982 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -0400983
Geoff Langbfdea662014-07-23 14:16:32 -0400984 default:
Geoff Langb1196682014-07-23 13:47:29 -0400985 context->recordError(gl::Error(GL_INVALID_ENUM));
986 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -0400987 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000988 }
989
990 return 0;
991}
992
993void __stdcall glCullFace(GLenum mode)
994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000995 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000996
Geoff Langb1196682014-07-23 13:47:29 -0400997 gl::Context *context = gl::getNonLostContext();
998 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000999 {
Geoff Langb1196682014-07-23 13:47:29 -04001000 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001001 {
Geoff Langb1196682014-07-23 13:47:29 -04001002 case GL_FRONT:
1003 case GL_BACK:
1004 case GL_FRONT_AND_BACK:
1005 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001006
Geoff Langb1196682014-07-23 13:47:29 -04001007 default:
1008 context->recordError(gl::Error(GL_INVALID_ENUM));
1009 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001010 }
Geoff Langb1196682014-07-23 13:47:29 -04001011
1012 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001013 }
1014}
1015
1016void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
1017{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001018 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001019
Geoff Langbfdea662014-07-23 14:16:32 -04001020 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001021 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001022 {
Geoff Langb1196682014-07-23 13:47:29 -04001023 if (n < 0)
1024 {
1025 context->recordError(gl::Error(GL_INVALID_VALUE));
1026 return;
1027 }
1028
Geoff Langbfdea662014-07-23 14:16:32 -04001029 for (int i = 0; i < n; i++)
1030 {
1031 context->deleteBuffer(buffers[i]);
1032 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001033 }
1034}
1035
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001036void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
1037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001038 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001039
Geoff Langbfdea662014-07-23 14:16:32 -04001040 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001041 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001042 {
Geoff Langb1196682014-07-23 13:47:29 -04001043 if (n < 0)
1044 {
1045 context->recordError(gl::Error(GL_INVALID_VALUE));
1046 return;
1047 }
1048
Geoff Langbfdea662014-07-23 14:16:32 -04001049 for (int i = 0; i < n; i++)
1050 {
1051 context->deleteFenceNV(fences[i]);
1052 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001053 }
1054}
1055
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001056void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1057{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001058 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001059
Geoff Langbfdea662014-07-23 14:16:32 -04001060 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001061 if (context)
1062 {
Geoff Langb1196682014-07-23 13:47:29 -04001063 if (n < 0)
1064 {
1065 context->recordError(gl::Error(GL_INVALID_VALUE));
1066 return;
1067 }
1068
Geoff Langbfdea662014-07-23 14:16:32 -04001069 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001070 {
Geoff Langbfdea662014-07-23 14:16:32 -04001071 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001072 {
Geoff Langbfdea662014-07-23 14:16:32 -04001073 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001074 }
1075 }
1076 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001077}
1078
1079void __stdcall glDeleteProgram(GLuint program)
1080{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001081 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001082
Geoff Langbfdea662014-07-23 14:16:32 -04001083 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001084 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001085 {
Geoff Langb1196682014-07-23 13:47:29 -04001086 if (program == 0)
1087 {
1088 return;
1089 }
1090
Geoff Langbfdea662014-07-23 14:16:32 -04001091 if (!context->getProgram(program))
1092 {
1093 if(context->getShader(program))
1094 {
Geoff Langb1196682014-07-23 13:47:29 -04001095 context->recordError(gl::Error(GL_INVALID_OPERATION));
1096 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001097 }
1098 else
1099 {
Geoff Langb1196682014-07-23 13:47:29 -04001100 context->recordError(gl::Error(GL_INVALID_VALUE));
1101 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001102 }
1103 }
1104
1105 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001106 }
1107}
1108
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001109void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1110{
1111 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1112
Geoff Langbfdea662014-07-23 14:16:32 -04001113 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001114 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001115 {
Geoff Langb1196682014-07-23 13:47:29 -04001116 if (n < 0)
1117 {
1118 context->recordError(gl::Error(GL_INVALID_VALUE));
1119 return;
1120 }
1121
Geoff Langbfdea662014-07-23 14:16:32 -04001122 for (int i = 0; i < n; i++)
1123 {
1124 context->deleteQuery(ids[i]);
1125 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001126 }
1127}
1128
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001129void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1130{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001131 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001132
Geoff Langbfdea662014-07-23 14:16:32 -04001133 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001134 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001135 {
Geoff Langb1196682014-07-23 13:47:29 -04001136 if (n < 0)
1137 {
1138 context->recordError(gl::Error(GL_INVALID_VALUE));
1139 return;
1140 }
1141
Geoff Langbfdea662014-07-23 14:16:32 -04001142 for (int i = 0; i < n; i++)
1143 {
1144 context->deleteRenderbuffer(renderbuffers[i]);
1145 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001146 }
1147}
1148
1149void __stdcall glDeleteShader(GLuint shader)
1150{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001151 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001152
Geoff Langbfdea662014-07-23 14:16:32 -04001153 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001154 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001155 {
Geoff Langb1196682014-07-23 13:47:29 -04001156 if (shader == 0)
1157 {
1158 return;
1159 }
1160
Geoff Langbfdea662014-07-23 14:16:32 -04001161 if (!context->getShader(shader))
1162 {
1163 if(context->getProgram(shader))
1164 {
Geoff Langb1196682014-07-23 13:47:29 -04001165 context->recordError(gl::Error(GL_INVALID_OPERATION));
1166 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001167 }
1168 else
1169 {
Geoff Langb1196682014-07-23 13:47:29 -04001170 context->recordError(gl::Error(GL_INVALID_VALUE));
1171 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001172 }
1173 }
1174
1175 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001176 }
1177}
1178
1179void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1180{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001181 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001182
Geoff Langbfdea662014-07-23 14:16:32 -04001183 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001184 if (context)
1185 {
Geoff Langb1196682014-07-23 13:47:29 -04001186 if (n < 0)
1187 {
1188 context->recordError(gl::Error(GL_INVALID_VALUE));
1189 return;
1190 }
1191
Geoff Langbfdea662014-07-23 14:16:32 -04001192 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001193 {
Geoff Langbfdea662014-07-23 14:16:32 -04001194 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001195 {
Geoff Langbfdea662014-07-23 14:16:32 -04001196 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001197 }
1198 }
1199 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001200}
1201
1202void __stdcall glDepthFunc(GLenum func)
1203{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001204 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001205
Geoff Langbfdea662014-07-23 14:16:32 -04001206 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001207 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001208 {
Geoff Langb1196682014-07-23 13:47:29 -04001209 switch (func)
1210 {
1211 case GL_NEVER:
1212 case GL_ALWAYS:
1213 case GL_LESS:
1214 case GL_LEQUAL:
1215 case GL_EQUAL:
1216 case GL_GREATER:
1217 case GL_GEQUAL:
1218 case GL_NOTEQUAL:
1219 context->getState().setDepthFunc(func);
1220 break;
1221
1222 default:
1223 context->recordError(gl::Error(GL_INVALID_ENUM));
1224 return;
1225 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001226 }
1227}
1228
1229void __stdcall glDepthMask(GLboolean flag)
1230{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001231 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001232
Geoff Langbfdea662014-07-23 14:16:32 -04001233 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001234 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001235 {
Geoff Langbfdea662014-07-23 14:16:32 -04001236 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001237 }
1238}
1239
1240void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1241{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001242 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001243
Geoff Langbfdea662014-07-23 14:16:32 -04001244 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001245 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001246 {
Geoff Langbfdea662014-07-23 14:16:32 -04001247 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001248 }
1249}
1250
1251void __stdcall glDetachShader(GLuint program, GLuint shader)
1252{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001253 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001254
Geoff Langbfdea662014-07-23 14:16:32 -04001255 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001256 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001257 {
Geoff Langbfdea662014-07-23 14:16:32 -04001258 gl::Program *programObject = context->getProgram(program);
1259 gl::Shader *shaderObject = context->getShader(shader);
1260
1261 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001262 {
Geoff Langbfdea662014-07-23 14:16:32 -04001263 gl::Shader *shaderByProgramHandle;
1264 shaderByProgramHandle = context->getShader(program);
1265 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266 {
Geoff Langb1196682014-07-23 13:47:29 -04001267 context->recordError(gl::Error(GL_INVALID_VALUE));
1268 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001269 }
Geoff Langbfdea662014-07-23 14:16:32 -04001270 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001271 {
Geoff Langb1196682014-07-23 13:47:29 -04001272 context->recordError(gl::Error(GL_INVALID_OPERATION));
1273 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001274 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001275 }
Geoff Langbfdea662014-07-23 14:16:32 -04001276
1277 if (!shaderObject)
1278 {
1279 gl::Program *programByShaderHandle = context->getProgram(shader);
1280 if (!programByShaderHandle)
1281 {
Geoff Langb1196682014-07-23 13:47:29 -04001282 context->recordError(gl::Error(GL_INVALID_VALUE));
1283 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001284 }
1285 else
1286 {
Geoff Langb1196682014-07-23 13:47:29 -04001287 context->recordError(gl::Error(GL_INVALID_OPERATION));
1288 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001289 }
1290 }
1291
1292 if (!programObject->detachShader(shaderObject))
1293 {
Geoff Langb1196682014-07-23 13:47:29 -04001294 context->recordError(gl::Error(GL_INVALID_OPERATION));
1295 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001296 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001297 }
1298}
1299
1300void __stdcall glDisable(GLenum cap)
1301{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001302 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001303
Geoff Langbfdea662014-07-23 14:16:32 -04001304 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001305 if (context)
1306 {
1307 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001308 {
Geoff Langb1196682014-07-23 13:47:29 -04001309 context->recordError(gl::Error(GL_INVALID_ENUM));
1310 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001311 }
Geoff Langbfdea662014-07-23 14:16:32 -04001312
1313 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001314 }
1315}
1316
1317void __stdcall glDisableVertexAttribArray(GLuint index)
1318{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001319 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001320
Geoff Langbfdea662014-07-23 14:16:32 -04001321 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001322 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001323 {
Geoff Langb1196682014-07-23 13:47:29 -04001324 if (index >= gl::MAX_VERTEX_ATTRIBS)
1325 {
1326 context->recordError(gl::Error(GL_INVALID_VALUE));
1327 return;
1328 }
1329
Geoff Langbfdea662014-07-23 14:16:32 -04001330 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001331 }
1332}
1333
1334void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1335{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001336 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001337
Geoff Langbfdea662014-07-23 14:16:32 -04001338 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001339 if (context)
1340 {
Jamie Madill2b976812014-08-25 15:47:49 -04001341 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001342 {
Geoff Langbfdea662014-07-23 14:16:32 -04001343 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001344 }
Geoff Langbfdea662014-07-23 14:16:32 -04001345
1346 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001347 }
1348}
1349
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001350void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1351{
1352 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1353
Geoff Langbfdea662014-07-23 14:16:32 -04001354 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001355 if (context)
1356 {
Geoff Lang87a93302014-09-16 13:29:43 -04001357 if (!ValidateDrawArraysInstancedANGLE(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001358 {
Geoff Langbfdea662014-07-23 14:16:32 -04001359 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001360 }
Geoff Langbfdea662014-07-23 14:16:32 -04001361
1362 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001363 }
1364}
1365
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001366void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001367{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001368 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 +00001369 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001370
Geoff Langbfdea662014-07-23 14:16:32 -04001371 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001372 if (context)
1373 {
Jamie Madill2b976812014-08-25 15:47:49 -04001374 rx::RangeUI indexRange;
1375 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001376 {
Geoff Langbfdea662014-07-23 14:16:32 -04001377 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001378 }
Geoff Langbfdea662014-07-23 14:16:32 -04001379
Jamie Madill2b976812014-08-25 15:47:49 -04001380 context->drawElements(mode, count, type, indices, 0, indexRange);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001381 }
1382}
1383
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001384void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1385{
1386 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1387 mode, count, type, indices, primcount);
1388
Geoff Langbfdea662014-07-23 14:16:32 -04001389 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001390 if (context)
1391 {
Jamie Madill2b976812014-08-25 15:47:49 -04001392 rx::RangeUI indexRange;
Geoff Lang87a93302014-09-16 13:29:43 -04001393 if (!ValidateDrawElementsInstancedANGLE(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001394 {
Geoff Langbfdea662014-07-23 14:16:32 -04001395 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001396 }
Geoff Langbfdea662014-07-23 14:16:32 -04001397
Jamie Madill2b976812014-08-25 15:47:49 -04001398 context->drawElements(mode, count, type, indices, primcount, indexRange);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001399 }
1400}
1401
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001402void __stdcall glEnable(GLenum cap)
1403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001404 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001405
Geoff Langbfdea662014-07-23 14:16:32 -04001406 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001407 if (context)
1408 {
1409 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001410 {
Geoff Langb1196682014-07-23 13:47:29 -04001411 context->recordError(gl::Error(GL_INVALID_ENUM));
1412 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001413 }
Geoff Langbfdea662014-07-23 14:16:32 -04001414
1415 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001416 }
1417}
1418
1419void __stdcall glEnableVertexAttribArray(GLuint index)
1420{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001421 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001422
Geoff Langbfdea662014-07-23 14:16:32 -04001423 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001424 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001425 {
Geoff Langb1196682014-07-23 13:47:29 -04001426 if (index >= gl::MAX_VERTEX_ATTRIBS)
1427 {
1428 context->recordError(gl::Error(GL_INVALID_VALUE));
1429 return;
1430 }
1431
Geoff Langbfdea662014-07-23 14:16:32 -04001432 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001433 }
1434}
1435
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001436void __stdcall glEndQueryEXT(GLenum target)
1437{
1438 EVENT("GLenum target = 0x%X)", target);
1439
Geoff Langbfdea662014-07-23 14:16:32 -04001440 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001441 if (context)
1442 {
1443 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001444 {
Geoff Langbfdea662014-07-23 14:16:32 -04001445 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001446 }
Geoff Langbfdea662014-07-23 14:16:32 -04001447
Geoff Lang5aad9672014-09-08 11:10:42 -04001448 gl::Error error = context->endQuery(target);
1449 if (error.isError())
1450 {
1451 context->recordError(error);
1452 return;
1453 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001454 }
1455}
1456
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001457void __stdcall glFinishFenceNV(GLuint fence)
1458{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001459 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001460
Geoff Langbfdea662014-07-23 14:16:32 -04001461 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001462 if (context)
1463 {
1464 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1465
1466 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001467 {
Geoff Langb1196682014-07-23 13:47:29 -04001468 context->recordError(gl::Error(GL_INVALID_OPERATION));
1469 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001470 }
Geoff Langbfdea662014-07-23 14:16:32 -04001471
1472 if (fenceObject->isFence() != GL_TRUE)
1473 {
Geoff Langb1196682014-07-23 13:47:29 -04001474 context->recordError(gl::Error(GL_INVALID_OPERATION));
1475 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001476 }
1477
1478 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001479 }
1480}
1481
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001482void __stdcall glFinish(void)
1483{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001484 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001485
Geoff Langbfdea662014-07-23 14:16:32 -04001486 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001487 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001488 {
Geoff Langbfdea662014-07-23 14:16:32 -04001489 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001490 }
1491}
1492
1493void __stdcall glFlush(void)
1494{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001495 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001496
Geoff Langbfdea662014-07-23 14:16:32 -04001497 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001498 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001499 {
Geoff Langbfdea662014-07-23 14:16:32 -04001500 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001501 }
1502}
1503
1504void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001506 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001507 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001508
Geoff Langbfdea662014-07-23 14:16:32 -04001509 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001510 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001511 {
Geoff Langb1196682014-07-23 13:47:29 -04001512 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1513 {
1514 context->recordError(gl::Error(GL_INVALID_ENUM));
1515 return;
1516 }
1517
Geoff Langbfdea662014-07-23 14:16:32 -04001518 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1519 {
1520 return;
1521 }
1522
1523 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1524 ASSERT(framebuffer);
1525
1526 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1527 {
1528 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1529 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1530 }
1531 else
1532 {
1533 switch (attachment)
1534 {
1535 case GL_DEPTH_ATTACHMENT:
1536 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1537 break;
1538 case GL_STENCIL_ATTACHMENT:
1539 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1540 break;
1541 case GL_DEPTH_STENCIL_ATTACHMENT:
1542 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1543 break;
1544 default:
1545 UNREACHABLE();
1546 break;
1547 }
1548 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001549 }
1550}
1551
1552void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1553{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001554 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001555 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001556
Geoff Langbfdea662014-07-23 14:16:32 -04001557 gl::Context *context = gl::getNonLostContext();
1558 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001559 {
Geoff Langbfdea662014-07-23 14:16:32 -04001560 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001561 {
Geoff Langbfdea662014-07-23 14:16:32 -04001562 return;
1563 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001564
Geoff Langbfdea662014-07-23 14:16:32 -04001565 if (texture == 0)
1566 {
1567 textarget = GL_NONE;
1568 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001569
Geoff Langbfdea662014-07-23 14:16:32 -04001570 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001571
Geoff Langbfdea662014-07-23 14:16:32 -04001572 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1573 {
1574 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1575 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1576 }
1577 else
1578 {
1579 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001580 {
Geoff Langbfdea662014-07-23 14:16:32 -04001581 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1582 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1583 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001584 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001585 }
1586 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001587}
1588
1589void __stdcall glFrontFace(GLenum mode)
1590{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001591 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001592
Geoff Langb1196682014-07-23 13:47:29 -04001593 gl::Context *context = gl::getNonLostContext();
1594 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001595 {
Geoff Langb1196682014-07-23 13:47:29 -04001596 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001597 {
Geoff Langb1196682014-07-23 13:47:29 -04001598 case GL_CW:
1599 case GL_CCW:
1600 context->getState().setFrontFace(mode);
1601 break;
1602 default:
1603 context->recordError(gl::Error(GL_INVALID_ENUM));
1604 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001605 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001606 }
1607}
1608
1609void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001611 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001612
Geoff Langbfdea662014-07-23 14:16:32 -04001613 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001614 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001615 {
Geoff Langb1196682014-07-23 13:47:29 -04001616 if (n < 0)
1617 {
1618 context->recordError(gl::Error(GL_INVALID_VALUE));
1619 return;
1620 }
1621
Geoff Langbfdea662014-07-23 14:16:32 -04001622 for (int i = 0; i < n; i++)
1623 {
1624 buffers[i] = context->createBuffer();
1625 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001626 }
1627}
1628
1629void __stdcall glGenerateMipmap(GLenum target)
1630{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001631 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001632
Geoff Langbfdea662014-07-23 14:16:32 -04001633 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001634 if (context)
1635 {
1636 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001637 {
Geoff Langb1196682014-07-23 13:47:29 -04001638 context->recordError(gl::Error(GL_INVALID_ENUM));
1639 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001640 }
Geoff Langbfdea662014-07-23 14:16:32 -04001641
1642 gl::Texture *texture = context->getTargetTexture(target);
1643
1644 if (texture == NULL)
1645 {
Geoff Langb1196682014-07-23 13:47:29 -04001646 context->recordError(gl::Error(GL_INVALID_OPERATION));
1647 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001648 }
1649
1650 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1651 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001652 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001653
1654 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1655 // unsized formats or that are color renderable and filterable. Since we do not track if
1656 // the texture was created with sized or unsized format (only sized formats are stored),
1657 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1658 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1659 // textures since they're the only texture format that can be created with unsized formats
1660 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1661 // was the last version to use add them.
1662 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1663 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1664 internalFormat == GL_ALPHA8_EXT;
1665
Geoff Lang5d601382014-07-22 15:14:06 -04001666 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1667 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001668 {
Geoff Langb1196682014-07-23 13:47:29 -04001669 context->recordError(gl::Error(GL_INVALID_OPERATION));
1670 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001671 }
1672
1673 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001674 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001675 {
Geoff Langb1196682014-07-23 13:47:29 -04001676 context->recordError(gl::Error(GL_INVALID_OPERATION));
1677 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001678 }
1679
1680 // Non-power of 2 ES2 check
1681 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1682 {
1683 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001684 context->recordError(gl::Error(GL_INVALID_OPERATION));
1685 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001686 }
1687
1688 // Cube completeness check
1689 if (target == GL_TEXTURE_CUBE_MAP)
1690 {
1691 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1692 if (!textureCube->isCubeComplete())
1693 {
Geoff Langb1196682014-07-23 13:47:29 -04001694 context->recordError(gl::Error(GL_INVALID_OPERATION));
1695 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001696 }
1697 }
1698
1699 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001700 }
1701}
1702
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001703void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1704{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001705 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001706
Geoff Langbfdea662014-07-23 14:16:32 -04001707 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001708 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001709 {
Geoff Langb1196682014-07-23 13:47:29 -04001710 if (n < 0)
1711 {
1712 context->recordError(gl::Error(GL_INVALID_VALUE));
1713 return;
1714 }
1715
Geoff Langbfdea662014-07-23 14:16:32 -04001716 for (int i = 0; i < n; i++)
1717 {
1718 fences[i] = context->createFenceNV();
1719 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001720 }
1721}
1722
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001723void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1724{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001725 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001726
Geoff Langbfdea662014-07-23 14:16:32 -04001727 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001728 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001729 {
Geoff Langb1196682014-07-23 13:47:29 -04001730 if (n < 0)
1731 {
1732 context->recordError(gl::Error(GL_INVALID_VALUE));
1733 return;
1734 }
1735
Geoff Langbfdea662014-07-23 14:16:32 -04001736 for (int i = 0; i < n; i++)
1737 {
1738 framebuffers[i] = context->createFramebuffer();
1739 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001740 }
1741}
1742
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001743void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1744{
1745 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1746
Geoff Langbfdea662014-07-23 14:16:32 -04001747 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001748 if (context)
1749 {
1750 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001751 {
Geoff Langb1196682014-07-23 13:47:29 -04001752 context->recordError(gl::Error(GL_INVALID_VALUE));
1753 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001754 }
Geoff Langbfdea662014-07-23 14:16:32 -04001755
1756 for (GLsizei i = 0; i < n; i++)
1757 {
1758 ids[i] = context->createQuery();
1759 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001760 }
1761}
1762
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001763void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1764{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001765 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
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 renderbuffers[i] = context->createRenderbuffer();
1779 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001780 }
1781}
1782
1783void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1784{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001785 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001786
Geoff Langbfdea662014-07-23 14:16:32 -04001787 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001788 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001789 {
Geoff Langb1196682014-07-23 13:47:29 -04001790 if (n < 0)
1791 {
1792 context->recordError(gl::Error(GL_INVALID_VALUE));
1793 return;
1794 }
1795
Geoff Langbfdea662014-07-23 14:16:32 -04001796 for (int i = 0; i < n; i++)
1797 {
1798 textures[i] = context->createTexture();
1799 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001800 }
1801}
1802
daniel@transgaming.com85423182010-04-22 13:35:27 +00001803void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001804{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001805 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001806 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001807 program, index, bufsize, length, size, type, name);
1808
Geoff Langbfdea662014-07-23 14:16:32 -04001809 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001810 if (context)
1811 {
Geoff Langb1196682014-07-23 13:47:29 -04001812 if (bufsize < 0)
1813 {
1814 context->recordError(gl::Error(GL_INVALID_VALUE));
1815 return;
1816 }
1817
Geoff Langbfdea662014-07-23 14:16:32 -04001818 gl::Program *programObject = context->getProgram(program);
1819
1820 if (!programObject)
1821 {
1822 if (context->getShader(program))
1823 {
Geoff Langb1196682014-07-23 13:47:29 -04001824 context->recordError(gl::Error(GL_INVALID_OPERATION));
1825 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001826 }
1827 else
1828 {
Geoff Langb1196682014-07-23 13:47:29 -04001829 context->recordError(gl::Error(GL_INVALID_VALUE));
1830 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001831 }
1832 }
1833
1834 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001835 {
Geoff Langb1196682014-07-23 13:47:29 -04001836 context->recordError(gl::Error(GL_INVALID_VALUE));
1837 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001838 }
1839
Geoff Langbfdea662014-07-23 14:16:32 -04001840 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001841 }
1842}
1843
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001844void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001845{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001846 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001847 "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 +00001848 program, index, bufsize, length, size, type, name);
1849
Geoff Langbfdea662014-07-23 14:16:32 -04001850
1851 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001852 if (context)
1853 {
Geoff Langb1196682014-07-23 13:47:29 -04001854 if (bufsize < 0)
1855 {
1856 context->recordError(gl::Error(GL_INVALID_VALUE));
1857 return;
1858 }
1859
Geoff Langbfdea662014-07-23 14:16:32 -04001860 gl::Program *programObject = context->getProgram(program);
1861
1862 if (!programObject)
1863 {
1864 if (context->getShader(program))
1865 {
Geoff Langb1196682014-07-23 13:47:29 -04001866 context->recordError(gl::Error(GL_INVALID_OPERATION));
1867 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001868 }
1869 else
1870 {
Geoff Langb1196682014-07-23 13:47:29 -04001871 context->recordError(gl::Error(GL_INVALID_VALUE));
1872 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001873 }
1874 }
1875
1876 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001877 {
Geoff Langb1196682014-07-23 13:47:29 -04001878 context->recordError(gl::Error(GL_INVALID_VALUE));
1879 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001880 }
1881
Geoff Langbfdea662014-07-23 14:16:32 -04001882 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001883 }
1884}
1885
1886void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1887{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001888 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 +00001889 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001890
Geoff Langbfdea662014-07-23 14:16:32 -04001891 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001892 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001893 {
Geoff Langb1196682014-07-23 13:47:29 -04001894 if (maxcount < 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 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001917 }
1918}
1919
Geoff Langb1196682014-07-23 13:47:29 -04001920GLint __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001921{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001922 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001923
Geoff Langbfdea662014-07-23 14:16:32 -04001924 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001925 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001926 {
Geoff Langbfdea662014-07-23 14:16:32 -04001927 gl::Program *programObject = context->getProgram(program);
1928
1929 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001930 {
Geoff Langbfdea662014-07-23 14:16:32 -04001931 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001932 {
Geoff Langb1196682014-07-23 13:47:29 -04001933 context->recordError(gl::Error(GL_INVALID_OPERATION));
1934 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001935 }
Geoff Langbfdea662014-07-23 14:16:32 -04001936 else
1937 {
Geoff Langb1196682014-07-23 13:47:29 -04001938 context->recordError(gl::Error(GL_INVALID_VALUE));
1939 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001940 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001941 }
Geoff Langbfdea662014-07-23 14:16:32 -04001942
1943 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1944 if (!programObject->isLinked() || !programBinary)
1945 {
Geoff Langb1196682014-07-23 13:47:29 -04001946 context->recordError(gl::Error(GL_INVALID_OPERATION));
1947 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001948 }
1949
1950 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001951 }
1952
1953 return -1;
1954}
1955
1956void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1957{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001958 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001959
Geoff Langbfdea662014-07-23 14:16:32 -04001960 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001961 if (context)
1962 {
1963 GLenum nativeType;
1964 unsigned int numParams = 0;
1965 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001966 {
Geoff Langbfdea662014-07-23 14:16:32 -04001967 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001968 }
Geoff Langbfdea662014-07-23 14:16:32 -04001969
1970 if (nativeType == GL_BOOL)
1971 {
1972 context->getBooleanv(pname, params);
1973 }
1974 else
1975 {
1976 CastStateValues(context, nativeType, pname, numParams, params);
1977 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001978 }
1979}
1980
1981void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1982{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001983 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 +00001984
Geoff Langbfdea662014-07-23 14:16:32 -04001985 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001986 if (context)
1987 {
1988 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001989 {
Geoff Langb1196682014-07-23 13:47:29 -04001990 context->recordError(gl::Error(GL_INVALID_ENUM));
1991 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001992 }
Geoff Langbfdea662014-07-23 14:16:32 -04001993
1994 if (!gl::ValidBufferParameter(context, pname))
1995 {
Geoff Langb1196682014-07-23 13:47:29 -04001996 context->recordError(gl::Error(GL_INVALID_ENUM));
1997 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001998 }
1999
2000 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
2001
2002 if (!buffer)
2003 {
2004 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04002005 context->recordError(gl::Error(GL_INVALID_OPERATION));
2006 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002007 }
2008
2009 switch (pname)
2010 {
2011 case GL_BUFFER_USAGE:
2012 *params = static_cast<GLint>(buffer->getUsage());
2013 break;
2014 case GL_BUFFER_SIZE:
2015 *params = gl::clampCast<GLint>(buffer->getSize());
2016 break;
2017 case GL_BUFFER_ACCESS_FLAGS:
2018 *params = buffer->getAccessFlags();
2019 break;
2020 case GL_BUFFER_MAPPED:
2021 *params = static_cast<GLint>(buffer->isMapped());
2022 break;
2023 case GL_BUFFER_MAP_OFFSET:
2024 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2025 break;
2026 case GL_BUFFER_MAP_LENGTH:
2027 *params = gl::clampCast<GLint>(buffer->getMapLength());
2028 break;
2029 default: UNREACHABLE(); break;
2030 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002031 }
2032}
2033
2034GLenum __stdcall glGetError(void)
2035{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002036 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002037
2038 gl::Context *context = gl::getContext();
2039
2040 if (context)
2041 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002042 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002043 }
2044
2045 return GL_NO_ERROR;
2046}
2047
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002048void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
2049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002050 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002051
Geoff Langbfdea662014-07-23 14:16:32 -04002052 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002053 if (context)
2054 {
2055 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2056
2057 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002058 {
Geoff Langb1196682014-07-23 13:47:29 -04002059 context->recordError(gl::Error(GL_INVALID_OPERATION));
2060 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002061 }
Geoff Langbfdea662014-07-23 14:16:32 -04002062
2063 if (fenceObject->isFence() != GL_TRUE)
2064 {
Geoff Langb1196682014-07-23 13:47:29 -04002065 context->recordError(gl::Error(GL_INVALID_OPERATION));
2066 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002067 }
2068
2069 switch (pname)
2070 {
2071 case GL_FENCE_STATUS_NV:
2072 case GL_FENCE_CONDITION_NV:
2073 break;
2074
Geoff Langb1196682014-07-23 13:47:29 -04002075 default:
2076 context->recordError(gl::Error(GL_INVALID_ENUM));
2077 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002078 }
2079
2080 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002081 }
2082}
2083
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002084void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2085{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002086 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002087
Geoff Langbfdea662014-07-23 14:16:32 -04002088 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002089 if (context)
2090 {
2091 GLenum nativeType;
2092 unsigned int numParams = 0;
2093 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002094 {
Geoff Langbfdea662014-07-23 14:16:32 -04002095 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002096 }
Geoff Langbfdea662014-07-23 14:16:32 -04002097
2098 if (nativeType == GL_FLOAT)
2099 {
2100 context->getFloatv(pname, params);
2101 }
2102 else
2103 {
2104 CastStateValues(context, nativeType, pname, numParams, params);
2105 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002106 }
2107}
2108
2109void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2110{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002111 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 +00002112 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002113
Geoff Langbfdea662014-07-23 14:16:32 -04002114 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002115 if (context)
2116 {
2117 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002118 {
Geoff Langb1196682014-07-23 13:47:29 -04002119 context->recordError(gl::Error(GL_INVALID_ENUM));
2120 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002121 }
2122
2123 int clientVersion = context->getClientVersion();
2124
2125 switch (pname)
2126 {
2127 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2128 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2129 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2130 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2131 break;
Geoff Langb1196682014-07-23 13:47:29 -04002132
Geoff Langbfdea662014-07-23 14:16:32 -04002133 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2134 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002135 {
Geoff Langb1196682014-07-23 13:47:29 -04002136 context->recordError(gl::Error(GL_INVALID_ENUM));
2137 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002138 }
Geoff Langbfdea662014-07-23 14:16:32 -04002139 break;
Geoff Langb1196682014-07-23 13:47:29 -04002140
Geoff Langbfdea662014-07-23 14:16:32 -04002141 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2142 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2143 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2144 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2145 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2146 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2147 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2148 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2149 if (clientVersion < 3)
2150 {
Geoff Langb1196682014-07-23 13:47:29 -04002151 context->recordError(gl::Error(GL_INVALID_ENUM));
2152 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002153 }
2154 break;
Geoff Langb1196682014-07-23 13:47:29 -04002155
Geoff Langbfdea662014-07-23 14:16:32 -04002156 default:
Geoff Langb1196682014-07-23 13:47:29 -04002157 context->recordError(gl::Error(GL_INVALID_ENUM));
2158 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002159 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002160
Geoff Langbfdea662014-07-23 14:16:32 -04002161 // Determine if the attachment is a valid enum
2162 switch (attachment)
2163 {
2164 case GL_BACK:
2165 case GL_FRONT:
2166 case GL_DEPTH:
2167 case GL_STENCIL:
2168 case GL_DEPTH_STENCIL_ATTACHMENT:
2169 if (clientVersion < 3)
2170 {
Geoff Langb1196682014-07-23 13:47:29 -04002171 context->recordError(gl::Error(GL_INVALID_ENUM));
2172 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002173 }
2174 break;
2175
2176 case GL_DEPTH_ATTACHMENT:
2177 case GL_STENCIL_ATTACHMENT:
2178 break;
2179
2180 default:
2181 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2182 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2183 {
Geoff Langb1196682014-07-23 13:47:29 -04002184 context->recordError(gl::Error(GL_INVALID_ENUM));
2185 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002186 }
2187 break;
2188 }
2189
2190 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2191 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2192
2193 if (framebufferHandle == 0)
2194 {
2195 if (clientVersion < 3)
2196 {
Geoff Langb1196682014-07-23 13:47:29 -04002197 context->recordError(gl::Error(GL_INVALID_OPERATION));
2198 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002199 }
2200
2201 switch (attachment)
2202 {
2203 case GL_BACK:
2204 case GL_DEPTH:
2205 case GL_STENCIL:
2206 break;
Geoff Langb1196682014-07-23 13:47:29 -04002207
Geoff Langbfdea662014-07-23 14:16:32 -04002208 default:
Geoff Langb1196682014-07-23 13:47:29 -04002209 context->recordError(gl::Error(GL_INVALID_OPERATION));
2210 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002211 }
2212 }
2213 else
2214 {
2215 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2216 {
2217 // Valid attachment query
2218 }
2219 else
2220 {
2221 switch (attachment)
2222 {
2223 case GL_DEPTH_ATTACHMENT:
2224 case GL_STENCIL_ATTACHMENT:
2225 break;
Geoff Langb1196682014-07-23 13:47:29 -04002226
Geoff Langbfdea662014-07-23 14:16:32 -04002227 case GL_DEPTH_STENCIL_ATTACHMENT:
2228 if (framebuffer->hasValidDepthStencil())
2229 {
Geoff Langb1196682014-07-23 13:47:29 -04002230 context->recordError(gl::Error(GL_INVALID_OPERATION));
2231 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002232 }
2233 break;
Geoff Langb1196682014-07-23 13:47:29 -04002234
Geoff Langbfdea662014-07-23 14:16:32 -04002235 default:
Geoff Langb1196682014-07-23 13:47:29 -04002236 context->recordError(gl::Error(GL_INVALID_OPERATION));
2237 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002238 }
2239 }
2240 }
2241
2242 GLenum attachmentType = GL_NONE;
2243 GLuint attachmentHandle = 0;
2244 GLuint attachmentLevel = 0;
2245 GLuint attachmentLayer = 0;
2246
2247 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2248
2249 if (attachmentObject)
2250 {
2251 attachmentType = attachmentObject->type();
2252 attachmentHandle = attachmentObject->id();
2253 attachmentLevel = attachmentObject->mipLevel();
2254 attachmentLayer = attachmentObject->layer();
2255 }
2256
2257 GLenum attachmentObjectType; // Type category
2258 if (framebufferHandle == 0)
2259 {
2260 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2261 }
2262 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2263 {
2264 attachmentObjectType = attachmentType;
2265 }
2266 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2267 {
2268 attachmentObjectType = GL_TEXTURE;
2269 }
2270 else
2271 {
2272 UNREACHABLE();
2273 return;
2274 }
2275
2276 if (attachmentObjectType == GL_NONE)
2277 {
2278 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2279 // is NONE, then querying any other pname will generate INVALID_ENUM.
2280
2281 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2282 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2283 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002284
Geoff Lang646559f2013-08-15 11:08:15 -04002285 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002286 {
Geoff Lang646559f2013-08-15 11:08:15 -04002287 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002288 *params = attachmentObjectType;
2289 break;
2290
Geoff Lang646559f2013-08-15 11:08:15 -04002291 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002292 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002293 {
Geoff Langb1196682014-07-23 13:47:29 -04002294 context->recordError(gl::Error(GL_INVALID_ENUM));
2295 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002296 }
Geoff Langbfdea662014-07-23 14:16:32 -04002297 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002298 break;
2299
2300 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002301 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002302 {
Geoff Langb1196682014-07-23 13:47:29 -04002303 context->recordError(gl::Error(GL_INVALID_ENUM));
2304 return;
Geoff Lang646559f2013-08-15 11:08:15 -04002305 }
2306 else
2307 {
Geoff Langb1196682014-07-23 13:47:29 -04002308 context->recordError(gl::Error(GL_INVALID_OPERATION));
2309 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002310 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002311 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002312 }
Geoff Langbfdea662014-07-23 14:16:32 -04002313 else
2314 {
2315 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2316 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2317 ASSERT(attachmentObject != NULL);
2318
2319 switch (pname)
2320 {
2321 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2322 *params = attachmentObjectType;
2323 break;
2324
2325 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2326 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2327 {
Geoff Langb1196682014-07-23 13:47:29 -04002328 context->recordError(gl::Error(GL_INVALID_ENUM));
2329 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002330 }
2331 *params = attachmentHandle;
2332 break;
2333
2334 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2335 if (attachmentObjectType != GL_TEXTURE)
2336 {
Geoff Langb1196682014-07-23 13:47:29 -04002337 context->recordError(gl::Error(GL_INVALID_ENUM));
2338 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002339 }
2340 *params = attachmentLevel;
2341 break;
2342
2343 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2344 if (attachmentObjectType != GL_TEXTURE)
2345 {
Geoff Langb1196682014-07-23 13:47:29 -04002346 context->recordError(gl::Error(GL_INVALID_ENUM));
2347 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002348 }
2349 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2350 break;
2351
2352 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2353 *params = attachmentObject->getRedSize();
2354 break;
2355
2356 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2357 *params = attachmentObject->getGreenSize();
2358 break;
2359
2360 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2361 *params = attachmentObject->getBlueSize();
2362 break;
2363
2364 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2365 *params = attachmentObject->getAlphaSize();
2366 break;
2367
2368 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2369 *params = attachmentObject->getDepthSize();
2370 break;
2371
2372 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2373 *params = attachmentObject->getStencilSize();
2374 break;
2375
2376 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
Jamie Madillee85d1b2014-09-17 10:35:23 -04002377 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT)
Geoff Langbfdea662014-07-23 14:16:32 -04002378 {
Geoff Langb1196682014-07-23 13:47:29 -04002379 context->recordError(gl::Error(GL_INVALID_OPERATION));
2380 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002381 }
2382 *params = attachmentObject->getComponentType();
2383 break;
2384
2385 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2386 *params = attachmentObject->getColorEncoding();
2387 break;
2388
2389 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2390 if (attachmentObjectType != GL_TEXTURE)
2391 {
Geoff Langb1196682014-07-23 13:47:29 -04002392 context->recordError(gl::Error(GL_INVALID_ENUM));
2393 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002394 }
2395 *params = attachmentLayer;
2396 break;
2397
2398 default:
2399 UNREACHABLE();
2400 break;
2401 }
2402 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002403 }
2404}
2405
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002406GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2407{
2408 EVENT("()");
2409
Geoff Langbfdea662014-07-23 14:16:32 -04002410 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002411
Geoff Langbfdea662014-07-23 14:16:32 -04002412 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002413 {
Geoff Langbfdea662014-07-23 14:16:32 -04002414 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002415 }
Geoff Langbfdea662014-07-23 14:16:32 -04002416
2417 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002418}
2419
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002420void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2421{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002422 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002423
Geoff Langbfdea662014-07-23 14:16:32 -04002424 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002425 if (context)
2426 {
2427 GLenum nativeType;
2428 unsigned int numParams = 0;
2429
2430 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002431 {
Geoff Langbfdea662014-07-23 14:16:32 -04002432 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002433 }
Geoff Langbfdea662014-07-23 14:16:32 -04002434
2435 if (nativeType == GL_INT)
2436 {
2437 context->getIntegerv(pname, params);
2438 }
2439 else
2440 {
2441 CastStateValues(context, nativeType, pname, numParams, params);
2442 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002443 }
2444}
2445
2446void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002448 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449
Geoff Langbfdea662014-07-23 14:16:32 -04002450 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002451 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002452 {
Geoff Langbfdea662014-07-23 14:16:32 -04002453 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002454
Geoff Langbfdea662014-07-23 14:16:32 -04002455 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002456 {
Geoff Langb1196682014-07-23 13:47:29 -04002457 context->recordError(gl::Error(GL_INVALID_VALUE));
2458 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002459 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460
Geoff Langbfdea662014-07-23 14:16:32 -04002461 if (context->getClientVersion() < 3)
2462 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 switch (pname)
2464 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002465 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002466 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002467 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002468 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002469 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002470 context->recordError(gl::Error(GL_INVALID_ENUM));
2471 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002472 }
2473 }
Geoff Langbfdea662014-07-23 14:16:32 -04002474
2475 switch (pname)
2476 {
2477 case GL_DELETE_STATUS:
2478 *params = programObject->isFlaggedForDeletion();
2479 return;
2480 case GL_LINK_STATUS:
2481 *params = programObject->isLinked();
2482 return;
2483 case GL_VALIDATE_STATUS:
2484 *params = programObject->isValidated();
2485 return;
2486 case GL_INFO_LOG_LENGTH:
2487 *params = programObject->getInfoLogLength();
2488 return;
2489 case GL_ATTACHED_SHADERS:
2490 *params = programObject->getAttachedShadersCount();
2491 return;
2492 case GL_ACTIVE_ATTRIBUTES:
2493 *params = programObject->getActiveAttributeCount();
2494 return;
2495 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2496 *params = programObject->getActiveAttributeMaxLength();
2497 return;
2498 case GL_ACTIVE_UNIFORMS:
2499 *params = programObject->getActiveUniformCount();
2500 return;
2501 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2502 *params = programObject->getActiveUniformMaxLength();
2503 return;
2504 case GL_PROGRAM_BINARY_LENGTH_OES:
2505 *params = programObject->getProgramBinaryLength();
2506 return;
2507 case GL_ACTIVE_UNIFORM_BLOCKS:
2508 *params = programObject->getActiveUniformBlockCount();
2509 return;
2510 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2511 *params = programObject->getActiveUniformBlockMaxLength();
2512 break;
2513 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2514 *params = programObject->getTransformFeedbackBufferMode();
2515 break;
2516 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2517 *params = programObject->getTransformFeedbackVaryingCount();
2518 break;
2519 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2520 *params = programObject->getTransformFeedbackVaryingMaxLength();
2521 break;
Geoff Langb1196682014-07-23 13:47:29 -04002522
Geoff Langbfdea662014-07-23 14:16:32 -04002523 default:
Geoff Langb1196682014-07-23 13:47:29 -04002524 context->recordError(gl::Error(GL_INVALID_ENUM));
2525 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002526 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002527 }
2528}
2529
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002530void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002531{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002532 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 +00002533 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002534
Geoff Langbfdea662014-07-23 14:16:32 -04002535 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002536 if (context)
2537 {
Geoff Langb1196682014-07-23 13:47:29 -04002538 if (bufsize < 0)
2539 {
2540 context->recordError(gl::Error(GL_INVALID_VALUE));
2541 return;
2542 }
2543
Geoff Langbfdea662014-07-23 14:16:32 -04002544 gl::Program *programObject = context->getProgram(program);
2545
2546 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002547 {
Geoff Langb1196682014-07-23 13:47:29 -04002548 context->recordError(gl::Error(GL_INVALID_VALUE));
2549 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002550 }
2551
Geoff Langbfdea662014-07-23 14:16:32 -04002552 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002553 }
2554}
2555
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002556void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2557{
2558 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2559
Geoff Langbfdea662014-07-23 14:16:32 -04002560 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002561 if (context)
2562 {
2563 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002564 {
Geoff Langb1196682014-07-23 13:47:29 -04002565 context->recordError(gl::Error(GL_INVALID_ENUM));
2566 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002567 }
Geoff Langbfdea662014-07-23 14:16:32 -04002568
2569 switch (pname)
2570 {
2571 case GL_CURRENT_QUERY_EXT:
2572 params[0] = context->getState().getActiveQueryId(target);
2573 break;
2574
2575 default:
Geoff Langb1196682014-07-23 13:47:29 -04002576 context->recordError(gl::Error(GL_INVALID_ENUM));
2577 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002578 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002579 }
2580}
2581
2582void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2583{
2584 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2585
Geoff Langbfdea662014-07-23 14:16:32 -04002586 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002587 if (context)
2588 {
2589 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2590
2591 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002592 {
Geoff Langb1196682014-07-23 13:47:29 -04002593 context->recordError(gl::Error(GL_INVALID_OPERATION));
2594 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002595 }
Geoff Langbfdea662014-07-23 14:16:32 -04002596
2597 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2598 {
Geoff Langb1196682014-07-23 13:47:29 -04002599 context->recordError(gl::Error(GL_INVALID_OPERATION));
2600 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002601 }
2602
2603 switch(pname)
2604 {
2605 case GL_QUERY_RESULT_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002606 {
2607 gl::Error error = queryObject->getResult(params);
2608 if (error.isError())
2609 {
2610 context->recordError(error);
2611 return;
2612 }
2613 }
Geoff Langbfdea662014-07-23 14:16:32 -04002614 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002615
Geoff Langbfdea662014-07-23 14:16:32 -04002616 case GL_QUERY_RESULT_AVAILABLE_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002617 {
2618 gl::Error error = queryObject->isResultAvailable(params);
2619 if (error.isError())
2620 {
2621 context->recordError(error);
2622 return;
2623 }
2624 }
Geoff Langbfdea662014-07-23 14:16:32 -04002625 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002626
Geoff Langbfdea662014-07-23 14:16:32 -04002627 default:
Geoff Langb1196682014-07-23 13:47:29 -04002628 context->recordError(gl::Error(GL_INVALID_ENUM));
2629 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002630 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002631 }
2632}
2633
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002634void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2635{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002636 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 +00002637
Geoff Langbfdea662014-07-23 14:16:32 -04002638 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002639 if (context)
2640 {
2641 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002642 {
Geoff Langb1196682014-07-23 13:47:29 -04002643 context->recordError(gl::Error(GL_INVALID_ENUM));
2644 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002645 }
Geoff Langbfdea662014-07-23 14:16:32 -04002646
2647 if (context->getState().getRenderbufferId() == 0)
2648 {
Geoff Langb1196682014-07-23 13:47:29 -04002649 context->recordError(gl::Error(GL_INVALID_OPERATION));
2650 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002651 }
2652
2653 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2654
2655 switch (pname)
2656 {
2657 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2658 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2659 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2660 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2661 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2662 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2663 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2664 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2665 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002666
Geoff Langbfdea662014-07-23 14:16:32 -04002667 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2668 if (!context->getExtensions().framebufferMultisample)
2669 {
Geoff Langb1196682014-07-23 13:47:29 -04002670 context->recordError(gl::Error(GL_INVALID_ENUM));
2671 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002672 }
2673 *params = renderbuffer->getSamples();
2674 break;
Geoff Langb1196682014-07-23 13:47:29 -04002675
Geoff Langbfdea662014-07-23 14:16:32 -04002676 default:
Geoff Langb1196682014-07-23 13:47:29 -04002677 context->recordError(gl::Error(GL_INVALID_ENUM));
2678 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002679 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002680 }
2681}
2682
2683void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002685 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002686
Geoff Langbfdea662014-07-23 14:16:32 -04002687 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002688 if (context)
2689 {
2690 gl::Shader *shaderObject = context->getShader(shader);
2691
2692 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002693 {
Geoff Langb1196682014-07-23 13:47:29 -04002694 context->recordError(gl::Error(GL_INVALID_VALUE));
2695 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002696 }
Geoff Langbfdea662014-07-23 14:16:32 -04002697
2698 switch (pname)
2699 {
2700 case GL_SHADER_TYPE:
2701 *params = shaderObject->getType();
2702 return;
2703 case GL_DELETE_STATUS:
2704 *params = shaderObject->isFlaggedForDeletion();
2705 return;
2706 case GL_COMPILE_STATUS:
2707 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2708 return;
2709 case GL_INFO_LOG_LENGTH:
2710 *params = shaderObject->getInfoLogLength();
2711 return;
2712 case GL_SHADER_SOURCE_LENGTH:
2713 *params = shaderObject->getSourceLength();
2714 return;
2715 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2716 *params = shaderObject->getTranslatedSourceLength();
2717 return;
Geoff Langb1196682014-07-23 13:47:29 -04002718
Geoff Langbfdea662014-07-23 14:16:32 -04002719 default:
Geoff Langb1196682014-07-23 13:47:29 -04002720 context->recordError(gl::Error(GL_INVALID_ENUM));
2721 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002722 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002723 }
2724}
2725
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002726void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002727{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002728 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 +00002729 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002730
Geoff Langbfdea662014-07-23 14:16:32 -04002731 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002732 if (context)
2733 {
Geoff Langb1196682014-07-23 13:47:29 -04002734 if (bufsize < 0)
2735 {
2736 context->recordError(gl::Error(GL_INVALID_VALUE));
2737 return;
2738 }
2739
Geoff Langbfdea662014-07-23 14:16:32 -04002740 gl::Shader *shaderObject = context->getShader(shader);
2741
2742 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002743 {
Geoff Langb1196682014-07-23 13:47:29 -04002744 context->recordError(gl::Error(GL_INVALID_VALUE));
2745 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002746 }
2747
Geoff Langbfdea662014-07-23 14:16:32 -04002748 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002749 }
2750}
2751
2752void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002754 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 +00002755 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002756
Geoff Langb1196682014-07-23 13:47:29 -04002757 gl::Context *context = gl::getNonLostContext();
2758 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002759 {
Geoff Langb1196682014-07-23 13:47:29 -04002760 switch (shadertype)
2761 {
2762 case GL_VERTEX_SHADER:
2763 case GL_FRAGMENT_SHADER:
2764 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002765
Geoff Langb1196682014-07-23 13:47:29 -04002766 default:
2767 context->recordError(gl::Error(GL_INVALID_ENUM));
2768 return;
2769 }
2770
2771 switch (precisiontype)
2772 {
2773 case GL_LOW_FLOAT:
2774 case GL_MEDIUM_FLOAT:
2775 case GL_HIGH_FLOAT:
2776 // Assume IEEE 754 precision
2777 range[0] = 127;
2778 range[1] = 127;
2779 *precision = 23;
2780 break;
2781
2782 case GL_LOW_INT:
2783 case GL_MEDIUM_INT:
2784 case GL_HIGH_INT:
2785 // Some (most) hardware only supports single-precision floating-point numbers,
2786 // which can accurately represent integers up to +/-16777216
2787 range[0] = 24;
2788 range[1] = 24;
2789 *precision = 0;
2790 break;
2791
2792 default:
2793 context->recordError(gl::Error(GL_INVALID_ENUM));
2794 return;
2795 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002796 }
2797}
2798
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002799void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002800{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002801 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 +00002802 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002803
Geoff Langbfdea662014-07-23 14:16:32 -04002804 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002805 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002806 {
Geoff Langb1196682014-07-23 13:47:29 -04002807 if (bufsize < 0)
2808 {
2809 context->recordError(gl::Error(GL_INVALID_VALUE));
2810 return;
2811 }
2812
Geoff Langbfdea662014-07-23 14:16:32 -04002813 gl::Shader *shaderObject = context->getShader(shader);
2814
2815 if (!shaderObject)
2816 {
Geoff Langb1196682014-07-23 13:47:29 -04002817 context->recordError(gl::Error(GL_INVALID_OPERATION));
2818 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002819 }
2820
2821 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002822 }
2823}
2824
zmo@google.coma574f782011-10-03 21:45:23 +00002825void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2826{
2827 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2828 shader, bufsize, length, source);
2829
Geoff Langbfdea662014-07-23 14:16:32 -04002830 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002831 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002832 {
Geoff Langb1196682014-07-23 13:47:29 -04002833 if (bufsize < 0)
2834 {
2835 context->recordError(gl::Error(GL_INVALID_VALUE));
2836 return;
2837 }
2838
Geoff Langbfdea662014-07-23 14:16:32 -04002839 gl::Shader *shaderObject = context->getShader(shader);
2840
2841 if (!shaderObject)
2842 {
Geoff Langb1196682014-07-23 13:47:29 -04002843 context->recordError(gl::Error(GL_INVALID_OPERATION));
2844 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002845 }
2846
2847 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002848 }
2849}
2850
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002851const GLubyte* __stdcall glGetString(GLenum name)
2852{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002853 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002854
Geoff Langbfdea662014-07-23 14:16:32 -04002855 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002856
Geoff Langbfdea662014-07-23 14:16:32 -04002857 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002858 {
Geoff Langbfdea662014-07-23 14:16:32 -04002859 case GL_VENDOR:
2860 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002861
Geoff Langbfdea662014-07-23 14:16:32 -04002862 case GL_RENDERER:
2863 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002864
Geoff Langbfdea662014-07-23 14:16:32 -04002865 case GL_VERSION:
2866 if (context->getClientVersion() == 2)
2867 {
2868 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2869 }
2870 else
2871 {
2872 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2873 }
Geoff Langb1196682014-07-23 13:47:29 -04002874
Geoff Langbfdea662014-07-23 14:16:32 -04002875 case GL_SHADING_LANGUAGE_VERSION:
2876 if (context->getClientVersion() == 2)
2877 {
2878 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2879 }
2880 else
2881 {
2882 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2883 }
Geoff Langb1196682014-07-23 13:47:29 -04002884
Geoff Langbfdea662014-07-23 14:16:32 -04002885 case GL_EXTENSIONS:
2886 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002887
Geoff Langbfdea662014-07-23 14:16:32 -04002888 default:
Geoff Langb1196682014-07-23 13:47:29 -04002889 if (context)
2890 {
2891 context->recordError(gl::Error(GL_INVALID_ENUM));
2892 }
2893 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002894 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002895}
2896
2897void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002899 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 +00002900
Geoff Langbfdea662014-07-23 14:16:32 -04002901 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002902 if (context)
2903 {
2904 gl::Texture *texture = context->getTargetTexture(target);
2905
2906 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002907 {
Geoff Langb1196682014-07-23 13:47:29 -04002908 context->recordError(gl::Error(GL_INVALID_ENUM));
2909 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002910 }
Geoff Langbfdea662014-07-23 14:16:32 -04002911
2912 switch (pname)
2913 {
2914 case GL_TEXTURE_MAG_FILTER:
2915 *params = (GLfloat)texture->getSamplerState().magFilter;
2916 break;
2917 case GL_TEXTURE_MIN_FILTER:
2918 *params = (GLfloat)texture->getSamplerState().minFilter;
2919 break;
2920 case GL_TEXTURE_WRAP_S:
2921 *params = (GLfloat)texture->getSamplerState().wrapS;
2922 break;
2923 case GL_TEXTURE_WRAP_T:
2924 *params = (GLfloat)texture->getSamplerState().wrapT;
2925 break;
2926 case GL_TEXTURE_WRAP_R:
2927 if (context->getClientVersion() < 3)
2928 {
Geoff Langb1196682014-07-23 13:47:29 -04002929 context->recordError(gl::Error(GL_INVALID_ENUM));
2930 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002931 }
2932 *params = (GLfloat)texture->getSamplerState().wrapR;
2933 break;
2934 case GL_TEXTURE_IMMUTABLE_FORMAT:
2935 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2936 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2937 break;
2938 case GL_TEXTURE_IMMUTABLE_LEVELS:
2939 if (context->getClientVersion() < 3)
2940 {
Geoff Langb1196682014-07-23 13:47:29 -04002941 context->recordError(gl::Error(GL_INVALID_ENUM));
2942 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002943 }
2944 *params = (GLfloat)texture->immutableLevelCount();
2945 break;
2946 case GL_TEXTURE_USAGE_ANGLE:
2947 *params = (GLfloat)texture->getUsage();
2948 break;
2949 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2950 if (!context->getExtensions().textureFilterAnisotropic)
2951 {
Geoff Langb1196682014-07-23 13:47:29 -04002952 context->recordError(gl::Error(GL_INVALID_ENUM));
2953 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002954 }
2955 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2956 break;
2957 case GL_TEXTURE_SWIZZLE_R:
2958 if (context->getClientVersion() < 3)
2959 {
Geoff Langb1196682014-07-23 13:47:29 -04002960 context->recordError(gl::Error(GL_INVALID_ENUM));
2961 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002962 }
2963 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2964 break;
2965 case GL_TEXTURE_SWIZZLE_G:
2966 if (context->getClientVersion() < 3)
2967 {
Geoff Langb1196682014-07-23 13:47:29 -04002968 context->recordError(gl::Error(GL_INVALID_ENUM));
2969 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002970 }
2971 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2972 break;
2973 case GL_TEXTURE_SWIZZLE_B:
2974 if (context->getClientVersion() < 3)
2975 {
Geoff Langb1196682014-07-23 13:47:29 -04002976 context->recordError(gl::Error(GL_INVALID_ENUM));
2977 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002978 }
2979 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2980 break;
2981 case GL_TEXTURE_SWIZZLE_A:
2982 if (context->getClientVersion() < 3)
2983 {
Geoff Langb1196682014-07-23 13:47:29 -04002984 context->recordError(gl::Error(GL_INVALID_ENUM));
2985 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002986 }
2987 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2988 break;
2989 case GL_TEXTURE_BASE_LEVEL:
2990 if (context->getClientVersion() < 3)
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().baseLevel;
2996 break;
2997 case GL_TEXTURE_MAX_LEVEL:
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().maxLevel;
3004 break;
3005 case GL_TEXTURE_MIN_LOD:
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 = texture->getSamplerState().minLod;
3012 break;
3013 case GL_TEXTURE_MAX_LOD:
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 = texture->getSamplerState().maxLod;
3020 break;
Geoff Langb1196682014-07-23 13:47:29 -04003021
Geoff Langbfdea662014-07-23 14:16:32 -04003022 default:
Geoff Langb1196682014-07-23 13:47:29 -04003023 context->recordError(gl::Error(GL_INVALID_ENUM));
3024 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003025 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003026 }
3027}
3028
3029void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
3030{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003031 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 +00003032
Geoff Langbfdea662014-07-23 14:16:32 -04003033 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003034 if (context)
3035 {
3036 gl::Texture *texture = context->getTargetTexture(target);
3037
3038 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003039 {
Geoff Langb1196682014-07-23 13:47:29 -04003040 context->recordError(gl::Error(GL_INVALID_ENUM));
3041 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003042 }
Geoff Langbfdea662014-07-23 14:16:32 -04003043
3044 switch (pname)
3045 {
3046 case GL_TEXTURE_MAG_FILTER:
3047 *params = texture->getSamplerState().magFilter;
3048 break;
3049 case GL_TEXTURE_MIN_FILTER:
3050 *params = texture->getSamplerState().minFilter;
3051 break;
3052 case GL_TEXTURE_WRAP_S:
3053 *params = texture->getSamplerState().wrapS;
3054 break;
3055 case GL_TEXTURE_WRAP_T:
3056 *params = texture->getSamplerState().wrapT;
3057 break;
3058 case GL_TEXTURE_WRAP_R:
3059 if (context->getClientVersion() < 3)
3060 {
Geoff Langb1196682014-07-23 13:47:29 -04003061 context->recordError(gl::Error(GL_INVALID_ENUM));
3062 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003063 }
3064 *params = texture->getSamplerState().wrapR;
3065 break;
3066 case GL_TEXTURE_IMMUTABLE_FORMAT:
3067 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3068 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3069 break;
3070 case GL_TEXTURE_IMMUTABLE_LEVELS:
3071 if (context->getClientVersion() < 3)
3072 {
Geoff Langb1196682014-07-23 13:47:29 -04003073 context->recordError(gl::Error(GL_INVALID_ENUM));
3074 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003075 }
3076 *params = texture->immutableLevelCount();
3077 break;
3078 case GL_TEXTURE_USAGE_ANGLE:
3079 *params = texture->getUsage();
3080 break;
3081 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3082 if (!context->getExtensions().textureFilterAnisotropic)
3083 {
Geoff Langb1196682014-07-23 13:47:29 -04003084 context->recordError(gl::Error(GL_INVALID_ENUM));
3085 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003086 }
3087 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3088 break;
3089 case GL_TEXTURE_SWIZZLE_R:
3090 if (context->getClientVersion() < 3)
3091 {
Geoff Langb1196682014-07-23 13:47:29 -04003092 context->recordError(gl::Error(GL_INVALID_ENUM));
3093 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003094 }
3095 *params = texture->getSamplerState().swizzleRed;
3096 break;
3097 case GL_TEXTURE_SWIZZLE_G:
3098 if (context->getClientVersion() < 3)
3099 {
Geoff Langb1196682014-07-23 13:47:29 -04003100 context->recordError(gl::Error(GL_INVALID_ENUM));
3101 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003102 }
3103 *params = texture->getSamplerState().swizzleGreen;
3104 break;
3105 case GL_TEXTURE_SWIZZLE_B:
3106 if (context->getClientVersion() < 3)
3107 {
Geoff Langb1196682014-07-23 13:47:29 -04003108 context->recordError(gl::Error(GL_INVALID_ENUM));
3109 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003110 }
3111 *params = texture->getSamplerState().swizzleBlue;
3112 break;
3113 case GL_TEXTURE_SWIZZLE_A:
3114 if (context->getClientVersion() < 3)
3115 {
Geoff Langb1196682014-07-23 13:47:29 -04003116 context->recordError(gl::Error(GL_INVALID_ENUM));
3117 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003118 }
3119 *params = texture->getSamplerState().swizzleAlpha;
3120 break;
3121 case GL_TEXTURE_BASE_LEVEL:
3122 if (context->getClientVersion() < 3)
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 = texture->getSamplerState().baseLevel;
3128 break;
3129 case GL_TEXTURE_MAX_LEVEL:
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().maxLevel;
3136 break;
3137 case GL_TEXTURE_MIN_LOD:
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 = (GLint)texture->getSamplerState().minLod;
3144 break;
3145 case GL_TEXTURE_MAX_LOD:
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 = (GLint)texture->getSamplerState().maxLod;
3152 break;
Geoff Langb1196682014-07-23 13:47:29 -04003153
Geoff Langbfdea662014-07-23 14:16:32 -04003154 default:
Geoff Langb1196682014-07-23 13:47:29 -04003155 context->recordError(gl::Error(GL_INVALID_ENUM));
3156 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003157 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003158 }
3159}
3160
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003161void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3162{
3163 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3164 program, location, bufSize, params);
3165
Geoff Langbfdea662014-07-23 14:16:32 -04003166 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003167 if (context)
3168 {
Jamie Madill0063c512014-08-25 15:47:53 -04003169 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003170 {
Jamie Madill0063c512014-08-25 15:47:53 -04003171 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003172 }
3173
Jamie Madilla502c742014-08-28 17:19:13 -04003174 gl::Program *programObject = context->getProgram(program);
3175 ASSERT(programObject);
3176 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003177 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003178
Jamie Madill99a1e982014-08-25 15:47:54 -04003179 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003180 }
3181}
3182
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003183void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3184{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003185 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003186
Geoff Langbfdea662014-07-23 14:16:32 -04003187 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003188 if (context)
3189 {
Jamie Madill0063c512014-08-25 15:47:53 -04003190 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003191 {
Jamie Madill0063c512014-08-25 15:47:53 -04003192 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003193 }
Geoff Langbfdea662014-07-23 14:16:32 -04003194
Jamie Madilla502c742014-08-28 17:19:13 -04003195 gl::Program *programObject = context->getProgram(program);
3196 ASSERT(programObject);
3197 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003198 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003199
Jamie Madill99a1e982014-08-25 15:47:54 -04003200 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003201 }
3202}
3203
3204void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3205{
Geoff Langbfdea662014-07-23 14:16:32 -04003206 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003207 program, location, bufSize, params);
3208
Geoff Langbfdea662014-07-23 14:16:32 -04003209 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003210 if (context)
3211 {
Jamie Madill0063c512014-08-25 15:47:53 -04003212 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003213 {
Jamie Madill0063c512014-08-25 15:47:53 -04003214 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003215 }
3216
Jamie Madilla502c742014-08-28 17:19:13 -04003217 gl::Program *programObject = context->getProgram(program);
3218 ASSERT(programObject);
3219 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003220 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003221
Jamie Madill99a1e982014-08-25 15:47:54 -04003222 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003223 }
3224}
3225
3226void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3227{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003228 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229
Geoff Langbfdea662014-07-23 14:16:32 -04003230 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003231 if (context)
3232 {
Jamie Madill0063c512014-08-25 15:47:53 -04003233 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003234 {
Jamie Madill0063c512014-08-25 15:47:53 -04003235 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003236 }
Geoff Langbfdea662014-07-23 14:16:32 -04003237
Jamie Madilla502c742014-08-28 17:19:13 -04003238 gl::Program *programObject = context->getProgram(program);
3239 ASSERT(programObject);
3240 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003241 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003242
Jamie Madill99a1e982014-08-25 15:47:54 -04003243 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003244 }
3245}
3246
Geoff Langb1196682014-07-23 13:47:29 -04003247GLint __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003248{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003249 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003250
Geoff Langbfdea662014-07-23 14:16:32 -04003251 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003252 if (context)
3253 {
Geoff Langb1196682014-07-23 13:47:29 -04003254 if (strstr(name, "gl_") == name)
3255 {
3256 return -1;
3257 }
3258
Geoff Langbfdea662014-07-23 14:16:32 -04003259 gl::Program *programObject = context->getProgram(program);
3260
3261 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003262 {
Geoff Langbfdea662014-07-23 14:16:32 -04003263 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003264 {
Geoff Langb1196682014-07-23 13:47:29 -04003265 context->recordError(gl::Error(GL_INVALID_OPERATION));
3266 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003267 }
Geoff Langbfdea662014-07-23 14:16:32 -04003268 else
3269 {
Geoff Langb1196682014-07-23 13:47:29 -04003270 context->recordError(gl::Error(GL_INVALID_VALUE));
3271 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003272 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003273 }
Geoff Langbfdea662014-07-23 14:16:32 -04003274
3275 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3276 if (!programObject->isLinked() || !programBinary)
3277 {
Geoff Langb1196682014-07-23 13:47:29 -04003278 context->recordError(gl::Error(GL_INVALID_OPERATION));
3279 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003280 }
3281
3282 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003283 }
3284
3285 return -1;
3286}
3287
3288void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003290 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003291
Geoff Langbfdea662014-07-23 14:16:32 -04003292 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003293 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003294 {
Geoff Langbfdea662014-07-23 14:16:32 -04003295 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003296 {
Geoff Langb1196682014-07-23 13:47:29 -04003297 context->recordError(gl::Error(GL_INVALID_VALUE));
3298 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003299 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003300
Geoff Langbfdea662014-07-23 14:16:32 -04003301 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003302 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003303 {
3304 return;
3305 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003306
Geoff Langbfdea662014-07-23 14:16:32 -04003307 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3308 {
3309 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3310 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003311 {
Geoff Langbfdea662014-07-23 14:16:32 -04003312 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003313 }
3314 }
Geoff Langbfdea662014-07-23 14:16:32 -04003315 else
3316 {
3317 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3318 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003319 }
3320}
3321
3322void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3323{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003324 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325
Geoff Langbfdea662014-07-23 14:16:32 -04003326 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003327 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328 {
Geoff Langbfdea662014-07-23 14:16:32 -04003329 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003330 {
Geoff Langb1196682014-07-23 13:47:29 -04003331 context->recordError(gl::Error(GL_INVALID_VALUE));
3332 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003333 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003334
Geoff Langbfdea662014-07-23 14:16:32 -04003335 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003336
Geoff Langb1196682014-07-23 13:47:29 -04003337 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003338 {
3339 return;
3340 }
Jamie Madillaff71502013-07-02 11:57:05 -04003341
Geoff Langbfdea662014-07-23 14:16:32 -04003342 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3343 {
3344 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3345 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003346 {
Geoff Langbfdea662014-07-23 14:16:32 -04003347 float currentValue = currentValueData.FloatValues[i];
3348 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003349 }
3350 }
Geoff Langbfdea662014-07-23 14:16:32 -04003351 else
3352 {
3353 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3354 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003355 }
3356}
3357
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003358void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003359{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003360 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003361
Geoff Langbfdea662014-07-23 14:16:32 -04003362 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003363 if (context)
3364 {
3365 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003366 {
Geoff Langb1196682014-07-23 13:47:29 -04003367 context->recordError(gl::Error(GL_INVALID_VALUE));
3368 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003369 }
Geoff Langbfdea662014-07-23 14:16:32 -04003370
3371 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3372 {
Geoff Langb1196682014-07-23 13:47:29 -04003373 context->recordError(gl::Error(GL_INVALID_ENUM));
3374 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003375 }
3376
3377 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003378 }
3379}
3380
3381void __stdcall glHint(GLenum target, GLenum mode)
3382{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003383 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003384
Geoff Langbfdea662014-07-23 14:16:32 -04003385 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003386 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003387 {
Geoff Langb1196682014-07-23 13:47:29 -04003388 switch (mode)
3389 {
3390 case GL_FASTEST:
3391 case GL_NICEST:
3392 case GL_DONT_CARE:
3393 break;
3394
3395 default:
3396 context->recordError(gl::Error(GL_INVALID_ENUM));
3397 return;
3398 }
3399
3400 switch (target)
3401 {
3402 case GL_GENERATE_MIPMAP_HINT:
3403 context->getState().setGenerateMipmapHint(mode);
3404 break;
3405
3406 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3407 context->getState().setFragmentShaderDerivativeHint(mode);
3408 break;
3409
3410 default:
3411 context->recordError(gl::Error(GL_INVALID_ENUM));
3412 return;
3413 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003414 }
3415}
3416
3417GLboolean __stdcall glIsBuffer(GLuint buffer)
3418{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003419 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003420
Geoff Langbfdea662014-07-23 14:16:32 -04003421 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003422 if (context && buffer)
3423 {
3424 gl::Buffer *bufferObject = context->getBuffer(buffer);
3425
3426 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427 {
Geoff Langbfdea662014-07-23 14:16:32 -04003428 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003429 }
3430 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003431
3432 return GL_FALSE;
3433}
3434
3435GLboolean __stdcall glIsEnabled(GLenum cap)
3436{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003437 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003438
Geoff Langbfdea662014-07-23 14:16:32 -04003439 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003440 if (context)
3441 {
3442 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003443 {
Geoff Langb1196682014-07-23 13:47:29 -04003444 context->recordError(gl::Error(GL_INVALID_ENUM));
3445 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003446 }
Geoff Langbfdea662014-07-23 14:16:32 -04003447
3448 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449 }
3450
3451 return false;
3452}
3453
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003454GLboolean __stdcall glIsFenceNV(GLuint fence)
3455{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003456 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003457
Geoff Langbfdea662014-07-23 14:16:32 -04003458 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003459 if (context)
3460 {
3461 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3462
3463 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003464 {
Geoff Langbfdea662014-07-23 14:16:32 -04003465 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003466 }
Geoff Langbfdea662014-07-23 14:16:32 -04003467
3468 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003469 }
3470
3471 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003472}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003473
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003474GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3475{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003476 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003477
Geoff Langbfdea662014-07-23 14:16:32 -04003478 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003479 if (context && framebuffer)
3480 {
3481 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3482
3483 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003484 {
Geoff Langbfdea662014-07-23 14:16:32 -04003485 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003486 }
3487 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003488
3489 return GL_FALSE;
3490}
3491
3492GLboolean __stdcall glIsProgram(GLuint program)
3493{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003494 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003495
Geoff Langbfdea662014-07-23 14:16:32 -04003496 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003497 if (context && program)
3498 {
3499 gl::Program *programObject = context->getProgram(program);
3500
3501 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502 {
Geoff Langbfdea662014-07-23 14:16:32 -04003503 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003504 }
3505 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003506
3507 return GL_FALSE;
3508}
3509
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003510GLboolean __stdcall glIsQueryEXT(GLuint id)
3511{
3512 EVENT("(GLuint id = %d)", id);
3513
Geoff Langbfdea662014-07-23 14:16:32 -04003514 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003515 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003516 {
Geoff Langbfdea662014-07-23 14:16:32 -04003517 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003518 }
3519
3520 return GL_FALSE;
3521}
3522
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003523GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3524{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003525 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526
Geoff Langbfdea662014-07-23 14:16:32 -04003527 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003528 if (context && renderbuffer)
3529 {
3530 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3531
3532 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003533 {
Geoff Langbfdea662014-07-23 14:16:32 -04003534 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003535 }
3536 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003537
3538 return GL_FALSE;
3539}
3540
3541GLboolean __stdcall glIsShader(GLuint shader)
3542{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003543 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003544
Geoff Langbfdea662014-07-23 14:16:32 -04003545 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003546 if (context && shader)
3547 {
3548 gl::Shader *shaderObject = context->getShader(shader);
3549
3550 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003551 {
Geoff Langbfdea662014-07-23 14:16:32 -04003552 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003553 }
3554 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003555
3556 return GL_FALSE;
3557}
3558
3559GLboolean __stdcall glIsTexture(GLuint texture)
3560{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003561 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003562
Geoff Langbfdea662014-07-23 14:16:32 -04003563 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003564 if (context && texture)
3565 {
3566 gl::Texture *textureObject = context->getTexture(texture);
3567
3568 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003569 {
Geoff Langbfdea662014-07-23 14:16:32 -04003570 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571 }
3572 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003573
3574 return GL_FALSE;
3575}
3576
3577void __stdcall glLineWidth(GLfloat width)
3578{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003579 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003580
Geoff Langbfdea662014-07-23 14:16:32 -04003581 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003582 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003583 {
Geoff Langb1196682014-07-23 13:47:29 -04003584 if (width <= 0.0f)
3585 {
3586 context->recordError(gl::Error(GL_INVALID_VALUE));
3587 return;
3588 }
3589
Geoff Langbfdea662014-07-23 14:16:32 -04003590 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003591 }
3592}
3593
3594void __stdcall glLinkProgram(GLuint program)
3595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003596 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003597
Geoff Langbfdea662014-07-23 14:16:32 -04003598 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003599 if (context)
3600 {
3601 gl::Program *programObject = context->getProgram(program);
3602
3603 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003604 {
Geoff Langbfdea662014-07-23 14:16:32 -04003605 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606 {
Geoff Langb1196682014-07-23 13:47:29 -04003607 context->recordError(gl::Error(GL_INVALID_OPERATION));
3608 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003609 }
Geoff Langbfdea662014-07-23 14:16:32 -04003610 else
3611 {
Geoff Langb1196682014-07-23 13:47:29 -04003612 context->recordError(gl::Error(GL_INVALID_VALUE));
3613 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003614 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003615 }
Geoff Langbfdea662014-07-23 14:16:32 -04003616
3617 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618 }
3619}
3620
3621void __stdcall glPixelStorei(GLenum pname, GLint param)
3622{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003623 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003624
Geoff Langbfdea662014-07-23 14:16:32 -04003625 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003626 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003627 {
Geoff Langbfdea662014-07-23 14:16:32 -04003628 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003629 {
Geoff Langbfdea662014-07-23 14:16:32 -04003630 case GL_UNPACK_ALIGNMENT:
3631 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003632 {
Geoff Langb1196682014-07-23 13:47:29 -04003633 context->recordError(gl::Error(GL_INVALID_VALUE));
3634 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003635 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003636
Geoff Langbfdea662014-07-23 14:16:32 -04003637 context->getState().setUnpackAlignment(param);
3638 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003639
Geoff Langbfdea662014-07-23 14:16:32 -04003640 case GL_PACK_ALIGNMENT:
3641 if (param != 1 && param != 2 && param != 4 && param != 8)
3642 {
Geoff Langb1196682014-07-23 13:47:29 -04003643 context->recordError(gl::Error(GL_INVALID_VALUE));
3644 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003645 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003646
Geoff Langbfdea662014-07-23 14:16:32 -04003647 context->getState().setPackAlignment(param);
3648 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003649
Geoff Langbfdea662014-07-23 14:16:32 -04003650 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3651 context->getState().setPackReverseRowOrder(param != 0);
3652 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003653
Geoff Langbfdea662014-07-23 14:16:32 -04003654 case GL_UNPACK_IMAGE_HEIGHT:
3655 case GL_UNPACK_SKIP_IMAGES:
3656 case GL_UNPACK_ROW_LENGTH:
3657 case GL_UNPACK_SKIP_ROWS:
3658 case GL_UNPACK_SKIP_PIXELS:
3659 case GL_PACK_ROW_LENGTH:
3660 case GL_PACK_SKIP_ROWS:
3661 case GL_PACK_SKIP_PIXELS:
3662 if (context->getClientVersion() < 3)
3663 {
Geoff Langb1196682014-07-23 13:47:29 -04003664 context->recordError(gl::Error(GL_INVALID_ENUM));
3665 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003666 }
Geoff Langbfdea662014-07-23 14:16:32 -04003667 UNIMPLEMENTED();
3668 break;
3669
3670 default:
Geoff Langb1196682014-07-23 13:47:29 -04003671 context->recordError(gl::Error(GL_INVALID_ENUM));
3672 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003673 }
3674 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003675}
3676
3677void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003679 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003680
Geoff Langbfdea662014-07-23 14:16:32 -04003681 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003682 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003683 {
Geoff Langbfdea662014-07-23 14:16:32 -04003684 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003685 }
3686}
3687
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003688void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3689 GLenum format, GLenum type, GLsizei bufSize,
3690 GLvoid *data)
3691{
3692 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3693 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3694 x, y, width, height, format, type, bufSize, data);
3695
Geoff Langbfdea662014-07-23 14:16:32 -04003696 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003697 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003698 {
Geoff Langb1196682014-07-23 13:47:29 -04003699 if (width < 0 || height < 0 || bufSize < 0)
3700 {
3701 context->recordError(gl::Error(GL_INVALID_VALUE));
3702 return;
3703 }
3704
Geoff Langbfdea662014-07-23 14:16:32 -04003705 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3706 format, type, &bufSize, data))
3707 {
3708 return;
3709 }
3710
Geoff Lang63d2fc72014-07-25 14:51:41 -04003711 gl::Error error = context->readPixels(x, y, width, height, format, type, &bufSize, data);
3712 if (error.isError())
3713 {
3714 context->recordError(error);
3715 return;
3716 }
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003717 }
3718}
3719
3720void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3721 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003722{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003723 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003724 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003725 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003726
Geoff Langbfdea662014-07-23 14:16:32 -04003727 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003728 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003729 {
Geoff Langb1196682014-07-23 13:47:29 -04003730 if (width < 0 || height < 0)
3731 {
3732 context->recordError(gl::Error(GL_INVALID_VALUE));
3733 return;
3734 }
3735
Geoff Langbfdea662014-07-23 14:16:32 -04003736 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3737 format, type, NULL, pixels))
3738 {
3739 return;
3740 }
3741
Geoff Lang63d2fc72014-07-25 14:51:41 -04003742 gl::Error error = context->readPixels(x, y, width, height, format, type, NULL, pixels);
3743 if (error.isError())
3744 {
3745 context->recordError(error);
3746 return;
3747 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003748 }
3749}
3750
3751void __stdcall glReleaseShaderCompiler(void)
3752{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003753 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003754
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003755 gl::Context *context = gl::getNonLostContext();
3756
3757 if (context)
3758 {
3759 context->releaseShaderCompiler();
3760 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003761}
3762
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003763void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003764{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003765 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 +00003766 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003767
Geoff Langbfdea662014-07-23 14:16:32 -04003768 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003769 if (context)
3770 {
3771 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3772 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003773 {
Geoff Langbfdea662014-07-23 14:16:32 -04003774 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003775 }
Geoff Langbfdea662014-07-23 14:16:32 -04003776
3777 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778 }
3779}
3780
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003781void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3782{
3783 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3784}
3785
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003786void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3787{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003788 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789
Geoff Langbfdea662014-07-23 14:16:32 -04003790 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003791
Geoff Langbfdea662014-07-23 14:16:32 -04003792 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003793 {
Geoff Langbfdea662014-07-23 14:16:32 -04003794 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003795 }
3796}
3797
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003798void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3799{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003800 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003801
Geoff Langbfdea662014-07-23 14:16:32 -04003802 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003803 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003804 {
Geoff Langb1196682014-07-23 13:47:29 -04003805 if (condition != GL_ALL_COMPLETED_NV)
3806 {
3807 context->recordError(gl::Error(GL_INVALID_ENUM));
3808 return;
3809 }
3810
Geoff Langbfdea662014-07-23 14:16:32 -04003811 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3812
3813 if (fenceObject == NULL)
3814 {
Geoff Langb1196682014-07-23 13:47:29 -04003815 context->recordError(gl::Error(GL_INVALID_OPERATION));
3816 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003817 }
3818
3819 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003820 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003821}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003822
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003823void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3824{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003825 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 +00003826
Geoff Langbfdea662014-07-23 14:16:32 -04003827 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003828 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003829 {
Geoff Langb1196682014-07-23 13:47:29 -04003830 if (width < 0 || height < 0)
3831 {
3832 context->recordError(gl::Error(GL_INVALID_VALUE));
3833 return;
3834 }
3835
Geoff Langbfdea662014-07-23 14:16:32 -04003836 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003837 }
3838}
3839
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003840void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003841{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003842 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003843 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003844 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003845
Geoff Lang900013c2014-07-07 11:32:19 -04003846 gl::Context* context = gl::getNonLostContext();
3847 if (context)
3848 {
3849 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3850 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3851 {
Geoff Langb1196682014-07-23 13:47:29 -04003852 context->recordError(gl::Error(GL_INVALID_ENUM));
3853 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003854 }
3855
3856 // No binary shader formats are supported.
3857 UNIMPLEMENTED();
3858 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003859}
3860
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003861void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003862{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003863 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 +00003864 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003865
Geoff Langbfdea662014-07-23 14:16:32 -04003866 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003867 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003868 {
Geoff Langb1196682014-07-23 13:47:29 -04003869 if (count < 0)
3870 {
3871 context->recordError(gl::Error(GL_INVALID_VALUE));
3872 return;
3873 }
3874
Geoff Langbfdea662014-07-23 14:16:32 -04003875 gl::Shader *shaderObject = context->getShader(shader);
3876
3877 if (!shaderObject)
3878 {
3879 if (context->getProgram(shader))
3880 {
Geoff Langb1196682014-07-23 13:47:29 -04003881 context->recordError(gl::Error(GL_INVALID_OPERATION));
3882 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003883 }
3884 else
3885 {
Geoff Langb1196682014-07-23 13:47:29 -04003886 context->recordError(gl::Error(GL_INVALID_VALUE));
3887 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003888 }
3889 }
3890
3891 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003892 }
3893}
3894
3895void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3896{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003897 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003898}
3899
3900void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3901{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003902 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 +00003903
Geoff Langbfdea662014-07-23 14:16:32 -04003904 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003905 if (context)
3906 {
Geoff Langb1196682014-07-23 13:47:29 -04003907 switch (face)
3908 {
3909 case GL_FRONT:
3910 case GL_BACK:
3911 case GL_FRONT_AND_BACK:
3912 break;
3913
3914 default:
3915 context->recordError(gl::Error(GL_INVALID_ENUM));
3916 return;
3917 }
3918
3919 switch (func)
3920 {
3921 case GL_NEVER:
3922 case GL_ALWAYS:
3923 case GL_LESS:
3924 case GL_LEQUAL:
3925 case GL_EQUAL:
3926 case GL_GEQUAL:
3927 case GL_GREATER:
3928 case GL_NOTEQUAL:
3929 break;
3930
3931 default:
3932 context->recordError(gl::Error(GL_INVALID_ENUM));
3933 return;
3934 }
3935
Geoff Langbfdea662014-07-23 14:16:32 -04003936 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3937 {
3938 context->getState().setStencilParams(func, ref, mask);
3939 }
3940
3941 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3942 {
3943 context->getState().setStencilBackParams(func, ref, mask);
3944 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003945 }
3946}
3947
3948void __stdcall glStencilMask(GLuint mask)
3949{
3950 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3951}
3952
3953void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3954{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003955 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003956
Geoff Langbfdea662014-07-23 14:16:32 -04003957 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003958 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003959 {
Geoff Langb1196682014-07-23 13:47:29 -04003960 switch (face)
3961 {
3962 case GL_FRONT:
3963 case GL_BACK:
3964 case GL_FRONT_AND_BACK:
3965 break;
3966
3967 default:
3968 context->recordError(gl::Error(GL_INVALID_ENUM));
3969 return;
3970 }
3971
Geoff Langbfdea662014-07-23 14:16:32 -04003972 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3973 {
3974 context->getState().setStencilWritemask(mask);
3975 }
3976
3977 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3978 {
3979 context->getState().setStencilBackWritemask(mask);
3980 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003981 }
3982}
3983
3984void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3985{
3986 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3987}
3988
3989void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3990{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003991 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 +00003992 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003993
Geoff Langbfdea662014-07-23 14:16:32 -04003994 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003995 if (context)
3996 {
Geoff Langb1196682014-07-23 13:47:29 -04003997 switch (face)
3998 {
3999 case GL_FRONT:
4000 case GL_BACK:
4001 case GL_FRONT_AND_BACK:
4002 break;
4003
4004 default:
4005 context->recordError(gl::Error(GL_INVALID_ENUM));
4006 return;
4007 }
4008
4009 switch (fail)
4010 {
4011 case GL_ZERO:
4012 case GL_KEEP:
4013 case GL_REPLACE:
4014 case GL_INCR:
4015 case GL_DECR:
4016 case GL_INVERT:
4017 case GL_INCR_WRAP:
4018 case GL_DECR_WRAP:
4019 break;
4020
4021 default:
4022 context->recordError(gl::Error(GL_INVALID_ENUM));
4023 return;
4024 }
4025
4026 switch (zfail)
4027 {
4028 case GL_ZERO:
4029 case GL_KEEP:
4030 case GL_REPLACE:
4031 case GL_INCR:
4032 case GL_DECR:
4033 case GL_INVERT:
4034 case GL_INCR_WRAP:
4035 case GL_DECR_WRAP:
4036 break;
4037
4038 default:
4039 context->recordError(gl::Error(GL_INVALID_ENUM));
4040 return;
4041 }
4042
4043 switch (zpass)
4044 {
4045 case GL_ZERO:
4046 case GL_KEEP:
4047 case GL_REPLACE:
4048 case GL_INCR:
4049 case GL_DECR:
4050 case GL_INVERT:
4051 case GL_INCR_WRAP:
4052 case GL_DECR_WRAP:
4053 break;
4054
4055 default:
4056 context->recordError(gl::Error(GL_INVALID_ENUM));
4057 return;
4058 }
4059
Geoff Langbfdea662014-07-23 14:16:32 -04004060 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4061 {
4062 context->getState().setStencilOperations(fail, zfail, zpass);
4063 }
4064
4065 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4066 {
4067 context->getState().setStencilBackOperations(fail, zfail, zpass);
4068 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004069 }
4070}
4071
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004072GLboolean __stdcall glTestFenceNV(GLuint fence)
4073{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004074 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004075
Geoff Langbfdea662014-07-23 14:16:32 -04004076 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004077 if (context)
4078 {
4079 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4080
4081 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004082 {
Geoff Langb1196682014-07-23 13:47:29 -04004083 context->recordError(gl::Error(GL_INVALID_OPERATION));
4084 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004085 }
Geoff Langbfdea662014-07-23 14:16:32 -04004086
4087 if (fenceObject->isFence() != GL_TRUE)
4088 {
Geoff Langb1196682014-07-23 13:47:29 -04004089 context->recordError(gl::Error(GL_INVALID_OPERATION));
4090 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004091 }
4092
4093 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004094 }
Geoff Langbfdea662014-07-23 14:16:32 -04004095
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004096 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004097}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004098
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004099void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4100 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004101{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004102 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004103 "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 +00004104 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004105
Geoff Langbfdea662014-07-23 14:16:32 -04004106 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004107 if (context)
4108 {
4109 if (context->getClientVersion() < 3 &&
4110 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4111 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004112 {
Geoff Langbfdea662014-07-23 14:16:32 -04004113 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004114 }
Geoff Langbfdea662014-07-23 14:16:32 -04004115
4116 if (context->getClientVersion() >= 3 &&
4117 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4118 0, 0, 0, width, height, 1, border, format, type, pixels))
4119 {
4120 return;
4121 }
4122
4123 switch (target)
4124 {
4125 case GL_TEXTURE_2D:
4126 {
4127 gl::Texture2D *texture = context->getTexture2D();
4128 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4129 }
4130 break;
4131 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4132 {
4133 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4134 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4135 }
4136 break;
4137 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4138 {
4139 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4140 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4141 }
4142 break;
4143 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4144 {
4145 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4146 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4147 }
4148 break;
4149 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4150 {
4151 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4152 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4153 }
4154 break;
4155 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4156 {
4157 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4158 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4159 }
4160 break;
4161 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4162 {
4163 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4164 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4165 }
4166 break;
4167 default: UNREACHABLE();
4168 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004169 }
4170}
4171
4172void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4173{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004174 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4175
Geoff Langbfdea662014-07-23 14:16:32 -04004176 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004177 if (context)
4178 {
4179 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004180 {
Geoff Langbfdea662014-07-23 14:16:32 -04004181 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004182 }
Geoff Langbfdea662014-07-23 14:16:32 -04004183
4184 gl::Texture *texture = context->getTargetTexture(target);
4185
4186 if (!texture)
4187 {
Geoff Langb1196682014-07-23 13:47:29 -04004188 context->recordError(gl::Error(GL_INVALID_ENUM));
4189 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004190 }
4191
4192 switch (pname)
4193 {
4194 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4195 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4196 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4197 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4198 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4199 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4200 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4201 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4202 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4203 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4204 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4205 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4206 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4207 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4208 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4209 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4210 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4211 default: UNREACHABLE(); break;
4212 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004213 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004214}
4215
4216void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4217{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004218 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004219}
4220
4221void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4222{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004223 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004224
Geoff Langbfdea662014-07-23 14:16:32 -04004225 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004226 if (context)
4227 {
4228 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004229 {
Geoff Langbfdea662014-07-23 14:16:32 -04004230 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004231 }
Geoff Langbfdea662014-07-23 14:16:32 -04004232
4233 gl::Texture *texture = context->getTargetTexture(target);
4234
4235 if (!texture)
4236 {
Geoff Langb1196682014-07-23 13:47:29 -04004237 context->recordError(gl::Error(GL_INVALID_ENUM));
4238 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004239 }
4240
4241 switch (pname)
4242 {
4243 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4244 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4245 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4246 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4247 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4248 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4249 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4250 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4251 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4252 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4253 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4254 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4255 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4256 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4257 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4258 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4259 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4260 default: UNREACHABLE(); break;
4261 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004262 }
4263}
4264
4265void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4266{
4267 glTexParameteri(target, pname, *params);
4268}
4269
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004270void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4271{
4272 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4273 target, levels, internalformat, width, height);
4274
Geoff Langbfdea662014-07-23 14:16:32 -04004275 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004276 if (context)
4277 {
4278 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004279 {
Geoff Langb1196682014-07-23 13:47:29 -04004280 context->recordError(gl::Error(GL_INVALID_OPERATION));
4281 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004282 }
Geoff Langbfdea662014-07-23 14:16:32 -04004283
4284 if (context->getClientVersion() < 3 &&
4285 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4286 {
4287 return;
4288 }
4289
4290 if (context->getClientVersion() >= 3 &&
4291 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4292 {
4293 return;
4294 }
4295
4296 switch (target)
4297 {
4298 case GL_TEXTURE_2D:
4299 {
4300 gl::Texture2D *texture2d = context->getTexture2D();
4301 texture2d->storage(levels, internalformat, width, height);
4302 }
4303 break;
4304
4305 case GL_TEXTURE_CUBE_MAP:
4306 {
4307 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4308 textureCube->storage(levels, internalformat, width);
4309 }
4310 break;
4311
4312 default:
Geoff Langb1196682014-07-23 13:47:29 -04004313 context->recordError(gl::Error(GL_INVALID_ENUM));
4314 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004315 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004316 }
4317}
4318
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004319void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4320 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004321{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004322 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004323 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004324 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004325 target, level, xoffset, yoffset, width, height, format, type, pixels);
4326
Geoff Langbfdea662014-07-23 14:16:32 -04004327 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004328 if (context)
4329 {
4330 if (context->getClientVersion() < 3 &&
4331 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4332 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004333 {
Geoff Langbfdea662014-07-23 14:16:32 -04004334 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004335 }
Geoff Langbfdea662014-07-23 14:16:32 -04004336
4337 if (context->getClientVersion() >= 3 &&
4338 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4339 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4340 {
4341 return;
4342 }
4343
4344 // Zero sized uploads are valid but no-ops
4345 if (width == 0 || height == 0)
4346 {
4347 return;
4348 }
4349
4350 switch (target)
4351 {
4352 case GL_TEXTURE_2D:
4353 {
4354 gl::Texture2D *texture = context->getTexture2D();
4355 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4356 }
4357 break;
4358
4359 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4360 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4361 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4362 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4363 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4364 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4365 {
4366 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4367 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4368 }
4369 break;
4370
4371 default:
4372 UNREACHABLE();
4373 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004374 }
4375}
4376
4377void __stdcall glUniform1f(GLint location, GLfloat x)
4378{
4379 glUniform1fv(location, 1, &x);
4380}
4381
4382void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4383{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004384 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004385
Geoff Langbfdea662014-07-23 14:16:32 -04004386 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004387 if (context)
4388 {
4389 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004390 {
Geoff Langbfdea662014-07-23 14:16:32 -04004391 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004392 }
Geoff Langbfdea662014-07-23 14:16:32 -04004393
4394 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4395 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004396 }
4397}
4398
4399void __stdcall glUniform1i(GLint location, GLint x)
4400{
4401 glUniform1iv(location, 1, &x);
4402}
4403
4404void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4405{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004406 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004407
Geoff Langbfdea662014-07-23 14:16:32 -04004408 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004409 if (context)
4410 {
4411 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004412 {
Geoff Langbfdea662014-07-23 14:16:32 -04004413 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004414 }
Geoff Langbfdea662014-07-23 14:16:32 -04004415
4416 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4417 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004418 }
4419}
4420
4421void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4422{
4423 GLfloat xy[2] = {x, y};
4424
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004425 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004426}
4427
4428void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4429{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004430 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004431
Geoff Langbfdea662014-07-23 14:16:32 -04004432 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004433 if (context)
4434 {
4435 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004436 {
Geoff Langbfdea662014-07-23 14:16:32 -04004437 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438 }
Geoff Langbfdea662014-07-23 14:16:32 -04004439
4440 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4441 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442 }
4443}
4444
4445void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4446{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004447 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004448
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004449 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450}
4451
4452void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4453{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004454 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004455
Geoff Langbfdea662014-07-23 14:16:32 -04004456 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004457 if (context)
4458 {
4459 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004460 {
Geoff Langbfdea662014-07-23 14:16:32 -04004461 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004462 }
Geoff Langbfdea662014-07-23 14:16:32 -04004463
4464 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4465 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004466 }
4467}
4468
4469void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4470{
4471 GLfloat xyz[3] = {x, y, z};
4472
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004473 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004474}
4475
4476void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4477{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004478 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479
Geoff Langbfdea662014-07-23 14:16:32 -04004480 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004481 if (context)
4482 {
4483 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004484 {
Geoff Langbfdea662014-07-23 14:16:32 -04004485 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004486 }
Geoff Langbfdea662014-07-23 14:16:32 -04004487
4488 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4489 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490 }
4491}
4492
4493void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4494{
4495 GLint xyz[3] = {x, y, z};
4496
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004497 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004498}
4499
4500void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4501{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004502 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004503
Geoff Langbfdea662014-07-23 14:16:32 -04004504 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004505 if (context)
4506 {
4507 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004508 {
Geoff Langbfdea662014-07-23 14:16:32 -04004509 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004510 }
Geoff Langbfdea662014-07-23 14:16:32 -04004511
4512 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4513 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004514 }
4515}
4516
4517void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4518{
4519 GLfloat xyzw[4] = {x, y, z, w};
4520
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004521 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004522}
4523
4524void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4525{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004526 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004527
Geoff Langbfdea662014-07-23 14:16:32 -04004528 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004529 if (context)
4530 {
4531 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004532 {
Geoff Langbfdea662014-07-23 14:16:32 -04004533 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004534 }
Geoff Langbfdea662014-07-23 14:16:32 -04004535
4536 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4537 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004538 }
4539}
4540
4541void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4542{
4543 GLint xyzw[4] = {x, y, z, w};
4544
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004545 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004546}
4547
4548void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4549{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004550 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004551
Geoff Langbfdea662014-07-23 14:16:32 -04004552 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004553 if (context)
4554 {
4555 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004556 {
Geoff Langbfdea662014-07-23 14:16:32 -04004557 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004558 }
Geoff Langbfdea662014-07-23 14:16:32 -04004559
4560 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4561 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562 }
4563}
4564
4565void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4566{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004567 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004568 location, count, transpose, value);
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 (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
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->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004580 }
4581}
4582
4583void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4584{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004585 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004586 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004587
Geoff Langbfdea662014-07-23 14:16:32 -04004588 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004589 if (context)
4590 {
4591 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004592 {
Geoff Langbfdea662014-07-23 14:16:32 -04004593 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004594 }
Geoff Langbfdea662014-07-23 14:16:32 -04004595
4596 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4597 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004598 }
4599}
4600
4601void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4602{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004603 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004604 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004605
Geoff Langbfdea662014-07-23 14:16:32 -04004606 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004607 if (context)
4608 {
4609 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004610 {
Geoff Langbfdea662014-07-23 14:16:32 -04004611 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004612 }
Geoff Langbfdea662014-07-23 14:16:32 -04004613
4614 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4615 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004616 }
4617}
4618
4619void __stdcall glUseProgram(GLuint program)
4620{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004621 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004622
Geoff Langbfdea662014-07-23 14:16:32 -04004623 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004624 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004625 {
Geoff Langbfdea662014-07-23 14:16:32 -04004626 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627
Geoff Langbfdea662014-07-23 14:16:32 -04004628 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004629 {
Geoff Langbfdea662014-07-23 14:16:32 -04004630 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004631 {
Geoff Langb1196682014-07-23 13:47:29 -04004632 context->recordError(gl::Error(GL_INVALID_OPERATION));
4633 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634 }
Geoff Langbfdea662014-07-23 14:16:32 -04004635 else
4636 {
Geoff Langb1196682014-07-23 13:47:29 -04004637 context->recordError(gl::Error(GL_INVALID_VALUE));
4638 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004639 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004640 }
Geoff Langbfdea662014-07-23 14:16:32 -04004641
4642 if (program != 0 && !programObject->isLinked())
4643 {
Geoff Langb1196682014-07-23 13:47:29 -04004644 context->recordError(gl::Error(GL_INVALID_OPERATION));
4645 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004646 }
4647
4648 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004649 }
4650}
4651
4652void __stdcall glValidateProgram(GLuint program)
4653{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004654 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004655
Geoff Langbfdea662014-07-23 14:16:32 -04004656 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004657 if (context)
4658 {
4659 gl::Program *programObject = context->getProgram(program);
4660
4661 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004662 {
Geoff Langbfdea662014-07-23 14:16:32 -04004663 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004664 {
Geoff Langb1196682014-07-23 13:47:29 -04004665 context->recordError(gl::Error(GL_INVALID_OPERATION));
4666 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004667 }
Geoff Langbfdea662014-07-23 14:16:32 -04004668 else
4669 {
Geoff Langb1196682014-07-23 13:47:29 -04004670 context->recordError(gl::Error(GL_INVALID_VALUE));
4671 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004672 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004673 }
Geoff Langbfdea662014-07-23 14:16:32 -04004674
Brandon Jones43a53e22014-08-28 16:23:22 -07004675 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004676 }
4677}
4678
4679void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4680{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004681 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004682
Geoff Langbfdea662014-07-23 14:16:32 -04004683 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004684 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004685 {
Geoff Langb1196682014-07-23 13:47:29 -04004686 if (index >= gl::MAX_VERTEX_ATTRIBS)
4687 {
4688 context->recordError(gl::Error(GL_INVALID_VALUE));
4689 return;
4690 }
4691
Geoff Langbfdea662014-07-23 14:16:32 -04004692 GLfloat vals[4] = { x, 0, 0, 1 };
4693 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004694 }
4695}
4696
4697void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4698{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004699 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004700
Geoff Langbfdea662014-07-23 14:16:32 -04004701 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004702 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004703 {
Geoff Langb1196682014-07-23 13:47:29 -04004704 if (index >= gl::MAX_VERTEX_ATTRIBS)
4705 {
4706 context->recordError(gl::Error(GL_INVALID_VALUE));
4707 return;
4708 }
4709
Geoff Langbfdea662014-07-23 14:16:32 -04004710 GLfloat vals[4] = { values[0], 0, 0, 1 };
4711 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004712 }
4713}
4714
4715void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4716{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004717 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004718
Geoff Langbfdea662014-07-23 14:16:32 -04004719 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004720 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004721 {
Geoff Langb1196682014-07-23 13:47:29 -04004722 if (index >= gl::MAX_VERTEX_ATTRIBS)
4723 {
4724 context->recordError(gl::Error(GL_INVALID_VALUE));
4725 return;
4726 }
4727
Geoff Langbfdea662014-07-23 14:16:32 -04004728 GLfloat vals[4] = { x, y, 0, 1 };
4729 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004730 }
4731}
4732
4733void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4734{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004735 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004736
Geoff Langbfdea662014-07-23 14:16:32 -04004737 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004738 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004739 {
Geoff Langb1196682014-07-23 13:47:29 -04004740 if (index >= gl::MAX_VERTEX_ATTRIBS)
4741 {
4742 context->recordError(gl::Error(GL_INVALID_VALUE));
4743 return;
4744 }
4745
Geoff Langbfdea662014-07-23 14:16:32 -04004746 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4747 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004748 }
4749}
4750
4751void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4752{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004753 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 +00004754
Geoff Langbfdea662014-07-23 14:16:32 -04004755 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004756 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004757 {
Geoff Langb1196682014-07-23 13:47:29 -04004758 if (index >= gl::MAX_VERTEX_ATTRIBS)
4759 {
4760 context->recordError(gl::Error(GL_INVALID_VALUE));
4761 return;
4762 }
4763
Geoff Langbfdea662014-07-23 14:16:32 -04004764 GLfloat vals[4] = { x, y, z, 1 };
4765 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004766 }
4767}
4768
4769void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4770{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004771 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004772
Geoff Langbfdea662014-07-23 14:16:32 -04004773 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004774 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004775 {
Geoff Langb1196682014-07-23 13:47:29 -04004776 if (index >= gl::MAX_VERTEX_ATTRIBS)
4777 {
4778 context->recordError(gl::Error(GL_INVALID_VALUE));
4779 return;
4780 }
4781
Geoff Langbfdea662014-07-23 14:16:32 -04004782 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4783 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004784 }
4785}
4786
4787void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4788{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004789 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 +00004790
Geoff Langbfdea662014-07-23 14:16:32 -04004791 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004792 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004793 {
Geoff Langb1196682014-07-23 13:47:29 -04004794 if (index >= gl::MAX_VERTEX_ATTRIBS)
4795 {
4796 context->recordError(gl::Error(GL_INVALID_VALUE));
4797 return;
4798 }
4799
Geoff Langbfdea662014-07-23 14:16:32 -04004800 GLfloat vals[4] = { x, y, z, w };
4801 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004802 }
4803}
4804
4805void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4806{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004807 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004808
Geoff Langbfdea662014-07-23 14:16:32 -04004809 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004810 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004811 {
Geoff Langb1196682014-07-23 13:47:29 -04004812 if (index >= gl::MAX_VERTEX_ATTRIBS)
4813 {
4814 context->recordError(gl::Error(GL_INVALID_VALUE));
4815 return;
4816 }
4817
Geoff Langbfdea662014-07-23 14:16:32 -04004818 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004819 }
4820}
4821
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004822void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4823{
4824 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4825
Geoff Langbfdea662014-07-23 14:16:32 -04004826 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004827 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004828 {
Geoff Langb1196682014-07-23 13:47:29 -04004829 if (index >= gl::MAX_VERTEX_ATTRIBS)
4830 {
4831 context->recordError(gl::Error(GL_INVALID_VALUE));
4832 return;
4833 }
4834
Geoff Langbfdea662014-07-23 14:16:32 -04004835 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004836 }
4837}
4838
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004839void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004840{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004841 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004842 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004843 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004844
Geoff Langbfdea662014-07-23 14:16:32 -04004845 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004846 if (context)
4847 {
Geoff Langb1196682014-07-23 13:47:29 -04004848 if (index >= gl::MAX_VERTEX_ATTRIBS)
4849 {
4850 context->recordError(gl::Error(GL_INVALID_VALUE));
4851 return;
4852 }
4853
4854 if (size < 1 || size > 4)
4855 {
4856 context->recordError(gl::Error(GL_INVALID_VALUE));
4857 return;
4858 }
4859
4860 switch (type)
4861 {
4862 case GL_BYTE:
4863 case GL_UNSIGNED_BYTE:
4864 case GL_SHORT:
4865 case GL_UNSIGNED_SHORT:
4866 case GL_FIXED:
4867 case GL_FLOAT:
4868 break;
4869
4870 case GL_HALF_FLOAT:
4871 case GL_INT:
4872 case GL_UNSIGNED_INT:
4873 case GL_INT_2_10_10_10_REV:
4874 case GL_UNSIGNED_INT_2_10_10_10_REV:
4875 if (context->getClientVersion() < 3)
4876 {
4877 context->recordError(gl::Error(GL_INVALID_ENUM));
4878 return;
4879 }
4880 break;
4881
4882 default:
4883 context->recordError(gl::Error(GL_INVALID_ENUM));
4884 return;
4885 }
4886
4887 if (stride < 0)
4888 {
4889 context->recordError(gl::Error(GL_INVALID_VALUE));
4890 return;
4891 }
4892
4893 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4894 {
4895 context->recordError(gl::Error(GL_INVALID_OPERATION));
4896 return;
4897 }
4898
Geoff Langbfdea662014-07-23 14:16:32 -04004899 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4900 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4901 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4902 // and the pointer argument is not NULL.
4903 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004904 {
Geoff Langb1196682014-07-23 13:47:29 -04004905 context->recordError(gl::Error(GL_INVALID_OPERATION));
4906 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004907 }
4908
Geoff Langbfdea662014-07-23 14:16:32 -04004909 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4910 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004911 }
4912}
4913
4914void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4915{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004916 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 +00004917
Geoff Langbfdea662014-07-23 14:16:32 -04004918 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004919 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004920 {
Geoff Langb1196682014-07-23 13:47:29 -04004921 if (width < 0 || height < 0)
4922 {
4923 context->recordError(gl::Error(GL_INVALID_VALUE));
4924 return;
4925 }
4926
Geoff Langbfdea662014-07-23 14:16:32 -04004927 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004928 }
4929}
4930
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004931// OpenGL ES 3.0 functions
4932
4933void __stdcall glReadBuffer(GLenum mode)
4934{
4935 EVENT("(GLenum mode = 0x%X)", mode);
4936
Geoff Langbfdea662014-07-23 14:16:32 -04004937 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004938 if (context)
4939 {
4940 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004941 {
Geoff Langb1196682014-07-23 13:47:29 -04004942 context->recordError(gl::Error(GL_INVALID_OPERATION));
4943 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004944 }
Geoff Langbfdea662014-07-23 14:16:32 -04004945
4946 // glReadBuffer
4947 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004948 }
4949}
4950
4951void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4952{
4953 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4954 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4955
Geoff Langbfdea662014-07-23 14:16:32 -04004956 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004957 if (context)
4958 {
4959 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004960 {
Geoff Langb1196682014-07-23 13:47:29 -04004961 context->recordError(gl::Error(GL_INVALID_OPERATION));
4962 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004963 }
Geoff Langbfdea662014-07-23 14:16:32 -04004964
4965 // glDrawRangeElements
4966 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004967 }
4968}
4969
4970void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4971{
4972 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4973 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4974 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4975 target, level, internalformat, width, height, depth, border, format, type, pixels);
4976
Geoff Langbfdea662014-07-23 14:16:32 -04004977 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004978 if (context)
4979 {
4980 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004981 {
Geoff Langb1196682014-07-23 13:47:29 -04004982 context->recordError(gl::Error(GL_INVALID_OPERATION));
4983 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004984 }
Geoff Langbfdea662014-07-23 14:16:32 -04004985
4986 // validateES3TexImageFormat sets the error code if there is an error
4987 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4988 0, 0, 0, width, height, depth, border, format, type, pixels))
4989 {
4990 return;
4991 }
4992
4993 switch(target)
4994 {
4995 case GL_TEXTURE_3D:
4996 {
4997 gl::Texture3D *texture = context->getTexture3D();
4998 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4999 }
5000 break;
5001
5002 case GL_TEXTURE_2D_ARRAY:
5003 {
5004 gl::Texture2DArray *texture = context->getTexture2DArray();
5005 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5006 }
5007 break;
5008
5009 default:
Geoff Langb1196682014-07-23 13:47:29 -04005010 context->recordError(gl::Error(GL_INVALID_ENUM));
5011 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005012 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005013 }
5014}
5015
5016void __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)
5017{
5018 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5019 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5020 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5021 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
5022
Geoff Langbfdea662014-07-23 14:16:32 -04005023 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005024 if (context)
5025 {
5026 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005027 {
Geoff Langb1196682014-07-23 13:47:29 -04005028 context->recordError(gl::Error(GL_INVALID_OPERATION));
5029 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005030 }
Geoff Langbfdea662014-07-23 14:16:32 -04005031
5032 // validateES3TexImageFormat sets the error code if there is an error
5033 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5034 xoffset, yoffset, zoffset, width, height, depth, 0,
5035 format, type, pixels))
5036 {
5037 return;
5038 }
5039
5040 // Zero sized uploads are valid but no-ops
5041 if (width == 0 || height == 0 || depth == 0)
5042 {
5043 return;
5044 }
5045
5046 switch(target)
5047 {
5048 case GL_TEXTURE_3D:
5049 {
5050 gl::Texture3D *texture = context->getTexture3D();
5051 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5052 }
5053 break;
5054
5055 case GL_TEXTURE_2D_ARRAY:
5056 {
5057 gl::Texture2DArray *texture = context->getTexture2DArray();
5058 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5059 }
5060 break;
5061
5062 default:
Geoff Langb1196682014-07-23 13:47:29 -04005063 context->recordError(gl::Error(GL_INVALID_ENUM));
5064 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005065 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005066 }
5067}
5068
5069void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5070{
5071 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5072 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5073 target, level, xoffset, yoffset, zoffset, x, y, width, height);
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 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5085 x, y, width, height, 0))
5086 {
5087 return;
5088 }
5089
5090 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5091 gl::Texture *texture = NULL;
5092 switch (target)
5093 {
5094 case GL_TEXTURE_3D:
5095 texture = context->getTexture3D();
5096 break;
5097
5098 case GL_TEXTURE_2D_ARRAY:
5099 texture = context->getTexture2DArray();
5100 break;
5101
5102 default:
Geoff Langb1196682014-07-23 13:47:29 -04005103 context->recordError(gl::Error(GL_INVALID_ENUM));
5104 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005105 }
5106
5107 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005108 }
5109}
5110
5111void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5112{
Geoff Langeef52cc2013-10-16 15:07:39 -04005113 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 +00005114 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5115 "const GLvoid* data = 0x%0.8p)",
5116 target, level, internalformat, width, height, depth, border, imageSize, data);
5117
Geoff Langbfdea662014-07-23 14:16:32 -04005118 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005119 if (context)
5120 {
5121 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005122 {
Geoff Langb1196682014-07-23 13:47:29 -04005123 context->recordError(gl::Error(GL_INVALID_OPERATION));
5124 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005125 }
Geoff Langbfdea662014-07-23 14:16:32 -04005126
Geoff Lang5d601382014-07-22 15:14:06 -04005127 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5128 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005129 {
Geoff Langb1196682014-07-23 13:47:29 -04005130 context->recordError(gl::Error(GL_INVALID_VALUE));
5131 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005132 }
5133
5134 // validateES3TexImageFormat sets the error code if there is an error
5135 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5136 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5137 {
5138 return;
5139 }
5140
5141 switch(target)
5142 {
5143 case GL_TEXTURE_3D:
5144 {
5145 gl::Texture3D *texture = context->getTexture3D();
5146 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5147 }
5148 break;
5149
5150 case GL_TEXTURE_2D_ARRAY:
5151 {
5152 gl::Texture2DArray *texture = context->getTexture2DArray();
5153 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5154 }
5155 break;
5156
5157 default:
Geoff Langb1196682014-07-23 13:47:29 -04005158 context->recordError(gl::Error(GL_INVALID_ENUM));
5159 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005160 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005161 }
5162}
5163
5164void __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)
5165{
5166 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5167 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5168 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5169 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5170
Geoff Langbfdea662014-07-23 14:16:32 -04005171 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005172 if (context)
5173 {
5174 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005175 {
Geoff Langb1196682014-07-23 13:47:29 -04005176 context->recordError(gl::Error(GL_INVALID_OPERATION));
5177 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005178 }
Geoff Langbfdea662014-07-23 14:16:32 -04005179
Geoff Lang5d601382014-07-22 15:14:06 -04005180 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5181 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005182 {
Geoff Langb1196682014-07-23 13:47:29 -04005183 context->recordError(gl::Error(GL_INVALID_VALUE));
5184 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005185 }
5186
5187 if (!data)
5188 {
Geoff Langb1196682014-07-23 13:47:29 -04005189 context->recordError(gl::Error(GL_INVALID_VALUE));
5190 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005191 }
5192
5193 // validateES3TexImageFormat sets the error code if there is an error
5194 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5195 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5196 {
5197 return;
5198 }
5199
5200 // Zero sized uploads are valid but no-ops
5201 if (width == 0 || height == 0)
5202 {
5203 return;
5204 }
5205
5206 switch(target)
5207 {
5208 case GL_TEXTURE_3D:
5209 {
5210 gl::Texture3D *texture = context->getTexture3D();
5211 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5212 format, imageSize, data);
5213 }
5214 break;
5215
5216 case GL_TEXTURE_2D_ARRAY:
5217 {
5218 gl::Texture2DArray *texture = context->getTexture2DArray();
5219 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5220 format, imageSize, data);
5221 }
5222 break;
5223
Geoff Langb1196682014-07-23 13:47:29 -04005224 default:
5225 context->recordError(gl::Error(GL_INVALID_ENUM));
5226 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005227 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005228 }
5229}
5230
5231void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5232{
5233 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5234
Geoff Langbfdea662014-07-23 14:16:32 -04005235 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005236 if (context)
5237 {
5238 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005239 {
Geoff Langb1196682014-07-23 13:47:29 -04005240 context->recordError(gl::Error(GL_INVALID_OPERATION));
5241 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005242 }
Geoff Langbfdea662014-07-23 14:16:32 -04005243
5244 if (n < 0)
5245 {
Geoff Langb1196682014-07-23 13:47:29 -04005246 context->recordError(gl::Error(GL_INVALID_VALUE));
5247 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005248 }
5249
5250 for (GLsizei i = 0; i < n; i++)
5251 {
5252 ids[i] = context->createQuery();
5253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005254 }
5255}
5256
5257void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5258{
5259 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5260
Geoff Langbfdea662014-07-23 14:16:32 -04005261 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005262 if (context)
5263 {
5264 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005265 {
Geoff Langb1196682014-07-23 13:47:29 -04005266 context->recordError(gl::Error(GL_INVALID_OPERATION));
5267 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005268 }
Geoff Langbfdea662014-07-23 14:16:32 -04005269
5270 if (n < 0)
5271 {
Geoff Langb1196682014-07-23 13:47:29 -04005272 context->recordError(gl::Error(GL_INVALID_VALUE));
5273 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005274 }
5275
5276 for (GLsizei i = 0; i < n; i++)
5277 {
5278 context->deleteQuery(ids[i]);
5279 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005280 }
5281}
5282
5283GLboolean __stdcall glIsQuery(GLuint id)
5284{
5285 EVENT("(GLuint id = %u)", id);
5286
Geoff Langbfdea662014-07-23 14:16:32 -04005287 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005288 if (context)
5289 {
5290 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005291 {
Geoff Langb1196682014-07-23 13:47:29 -04005292 context->recordError(gl::Error(GL_INVALID_OPERATION));
5293 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005294 }
Geoff Langbfdea662014-07-23 14:16:32 -04005295
5296 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005297 }
5298
5299 return GL_FALSE;
5300}
5301
5302void __stdcall glBeginQuery(GLenum target, GLuint id)
5303{
5304 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5305
Geoff Langbfdea662014-07-23 14:16:32 -04005306 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005307 if (context)
5308 {
5309 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005310 {
Geoff Langb1196682014-07-23 13:47:29 -04005311 context->recordError(gl::Error(GL_INVALID_OPERATION));
5312 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005313 }
Geoff Langbfdea662014-07-23 14:16:32 -04005314
5315 if (!ValidateBeginQuery(context, target, id))
5316 {
5317 return;
5318 }
Geoff Lang5aad9672014-09-08 11:10:42 -04005319
5320 gl::Error error = context->beginQuery(target, id);
5321 if (error.isError())
5322 {
5323 context->recordError(error);
5324 return;
5325 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005326 }
5327}
5328
5329void __stdcall glEndQuery(GLenum target)
5330{
5331 EVENT("(GLenum target = 0x%X)", target);
5332
Geoff Langbfdea662014-07-23 14:16:32 -04005333 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005334 if (context)
5335 {
5336 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005337 {
Geoff Langb1196682014-07-23 13:47:29 -04005338 context->recordError(gl::Error(GL_INVALID_OPERATION));
5339 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005340 }
Geoff Langbfdea662014-07-23 14:16:32 -04005341
5342 if (!ValidateEndQuery(context, target))
5343 {
5344 return;
5345 }
5346
Geoff Lang5aad9672014-09-08 11:10:42 -04005347 gl::Error error = context->endQuery(target);
5348 if (error.isError())
5349 {
5350 context->recordError(error);
5351 return;
5352 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005353 }
5354}
5355
5356void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5357{
5358 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5359
Geoff Langbfdea662014-07-23 14:16:32 -04005360 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005361 if (context)
5362 {
5363 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005364 {
Geoff Langb1196682014-07-23 13:47:29 -04005365 context->recordError(gl::Error(GL_INVALID_OPERATION));
5366 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005367 }
Geoff Langbfdea662014-07-23 14:16:32 -04005368
5369 if (!ValidQueryType(context, target))
5370 {
Geoff Langb1196682014-07-23 13:47:29 -04005371 context->recordError(gl::Error(GL_INVALID_ENUM));
5372 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005373 }
5374
5375 switch (pname)
5376 {
5377 case GL_CURRENT_QUERY:
5378 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5379 break;
5380
5381 default:
Geoff Langb1196682014-07-23 13:47:29 -04005382 context->recordError(gl::Error(GL_INVALID_ENUM));
5383 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005384 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005385 }
5386}
5387
5388void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5389{
5390 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5391
Geoff Langbfdea662014-07-23 14:16:32 -04005392 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005393 if (context)
5394 {
5395 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005396 {
Geoff Langb1196682014-07-23 13:47:29 -04005397 context->recordError(gl::Error(GL_INVALID_OPERATION));
5398 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005399 }
Geoff Langbfdea662014-07-23 14:16:32 -04005400
5401 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5402
5403 if (!queryObject)
5404 {
Geoff Langb1196682014-07-23 13:47:29 -04005405 context->recordError(gl::Error(GL_INVALID_OPERATION));
5406 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005407 }
5408
5409 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5410 {
Geoff Langb1196682014-07-23 13:47:29 -04005411 context->recordError(gl::Error(GL_INVALID_OPERATION));
5412 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005413 }
5414
5415 switch(pname)
5416 {
Geoff Lang5aad9672014-09-08 11:10:42 -04005417 case GL_QUERY_RESULT_EXT:
5418 {
5419 gl::Error error = queryObject->getResult(params);
5420 if (error.isError())
5421 {
5422 context->recordError(error);
5423 return;
5424 }
5425 }
Geoff Langbfdea662014-07-23 14:16:32 -04005426 break;
Geoff Langb1196682014-07-23 13:47:29 -04005427
Geoff Lang5aad9672014-09-08 11:10:42 -04005428 case GL_QUERY_RESULT_AVAILABLE_EXT:
5429 {
5430 gl::Error error = queryObject->isResultAvailable(params);
5431 if (error.isError())
5432 {
5433 context->recordError(error);
5434 return;
5435 }
5436 }
Geoff Langbfdea662014-07-23 14:16:32 -04005437 break;
Geoff Langb1196682014-07-23 13:47:29 -04005438
Geoff Langbfdea662014-07-23 14:16:32 -04005439 default:
Geoff Langb1196682014-07-23 13:47:29 -04005440 context->recordError(gl::Error(GL_INVALID_ENUM));
5441 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005442 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005443 }
5444}
5445
5446GLboolean __stdcall glUnmapBuffer(GLenum target)
5447{
5448 EVENT("(GLenum target = 0x%X)", target);
5449
Geoff Langbfdea662014-07-23 14:16:32 -04005450 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005451 if (context)
5452 {
5453 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005454 {
Geoff Langb1196682014-07-23 13:47:29 -04005455 context->recordError(gl::Error(GL_INVALID_OPERATION));
5456 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005457 }
Geoff Langbfdea662014-07-23 14:16:32 -04005458
5459 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005460 }
5461
5462 return GL_FALSE;
5463}
5464
5465void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5466{
5467 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5468
Geoff Langbfdea662014-07-23 14:16:32 -04005469 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005470 if (context)
5471 {
5472 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005473 {
Geoff Langb1196682014-07-23 13:47:29 -04005474 context->recordError(gl::Error(GL_INVALID_OPERATION));
5475 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005476 }
Geoff Langbfdea662014-07-23 14:16:32 -04005477
5478 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005479 }
5480}
5481
5482void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5483{
Geoff Langbfdea662014-07-23 14:16:32 -04005484 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005485 if (context)
5486 {
5487 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005488 {
Geoff Langb1196682014-07-23 13:47:29 -04005489 context->recordError(gl::Error(GL_INVALID_OPERATION));
5490 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005491 }
Geoff Langbfdea662014-07-23 14:16:32 -04005492
5493 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005494 }
5495}
5496
5497void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5498{
5499 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5500 location, count, transpose, value);
5501
Geoff Langbfdea662014-07-23 14:16:32 -04005502 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005503 if (context)
5504 {
5505 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005506 {
Geoff Langbfdea662014-07-23 14:16:32 -04005507 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005508 }
Geoff Langbfdea662014-07-23 14:16:32 -04005509
5510 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5511 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005512 }
5513}
5514
5515void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5516{
5517 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5518 location, count, transpose, value);
5519
Geoff Langbfdea662014-07-23 14:16:32 -04005520 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005521 if (context)
5522 {
5523 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005524 {
Geoff Langbfdea662014-07-23 14:16:32 -04005525 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005526 }
Geoff Langbfdea662014-07-23 14:16:32 -04005527
5528 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5529 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005530 }
5531}
5532
5533void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5534{
5535 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5536 location, count, transpose, value);
5537
Geoff Langbfdea662014-07-23 14:16:32 -04005538 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005539 if (context)
5540 {
5541 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005542 {
Geoff Langbfdea662014-07-23 14:16:32 -04005543 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005544 }
Geoff Langbfdea662014-07-23 14:16:32 -04005545
5546 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5547 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005548 }
5549}
5550
5551void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5552{
5553 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5554 location, count, transpose, value);
5555
Geoff Langbfdea662014-07-23 14:16:32 -04005556 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005557 if (context)
5558 {
5559 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005560 {
Geoff Langbfdea662014-07-23 14:16:32 -04005561 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005562 }
Geoff Langbfdea662014-07-23 14:16:32 -04005563
5564 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5565 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005566 }
5567}
5568
5569void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5570{
5571 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5572 location, count, transpose, value);
5573
Geoff Langbfdea662014-07-23 14:16:32 -04005574 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005575 if (context)
5576 {
5577 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005578 {
Geoff Langbfdea662014-07-23 14:16:32 -04005579 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005580 }
Geoff Langbfdea662014-07-23 14:16:32 -04005581
5582 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5583 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005584 }
5585}
5586
5587void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5588{
5589 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5590 location, count, transpose, value);
5591
Geoff Langbfdea662014-07-23 14:16:32 -04005592 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005593 if (context)
5594 {
5595 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005596 {
Geoff Langbfdea662014-07-23 14:16:32 -04005597 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005598 }
Geoff Langbfdea662014-07-23 14:16:32 -04005599
5600 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5601 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005602 }
5603}
5604
5605void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5606{
5607 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5608 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5609 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5610
Geoff Langbfdea662014-07-23 14:16:32 -04005611 gl::Context *context = gl::getNonLostContext();
5612 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005613 {
Geoff Langbfdea662014-07-23 14:16:32 -04005614 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005615 {
Geoff Langb1196682014-07-23 13:47:29 -04005616 context->recordError(gl::Error(GL_INVALID_OPERATION));
5617 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005618 }
Geoff Langbfdea662014-07-23 14:16:32 -04005619
5620 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5621 dstX0, dstY0, dstX1, dstY1, mask, filter,
5622 false))
5623 {
5624 return;
5625 }
5626
5627 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5628 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005629 }
5630}
5631
5632void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5633{
5634 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5635 target, samples, internalformat, width, height);
5636
Geoff Langbfdea662014-07-23 14:16:32 -04005637 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005638 if (context)
5639 {
5640 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005641 {
Geoff Langb1196682014-07-23 13:47:29 -04005642 context->recordError(gl::Error(GL_INVALID_OPERATION));
5643 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005644 }
Geoff Langbfdea662014-07-23 14:16:32 -04005645
5646 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5647 width, height, false))
5648 {
5649 return;
5650 }
5651
5652 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005653 }
5654}
5655
5656void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5657{
5658 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5659 target, attachment, texture, level, layer);
5660
Geoff Langbfdea662014-07-23 14:16:32 -04005661 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005662 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005663 {
Geoff Langbfdea662014-07-23 14:16:32 -04005664 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5665 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005666 {
Geoff Langbfdea662014-07-23 14:16:32 -04005667 return;
5668 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005669
Geoff Langbfdea662014-07-23 14:16:32 -04005670 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5671 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005672
Geoff Langbfdea662014-07-23 14:16:32 -04005673 gl::Texture *textureObject = context->getTexture(texture);
5674 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005675
Geoff Langbfdea662014-07-23 14:16:32 -04005676 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5677 {
5678 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5679 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5680 }
5681 else
5682 {
5683 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005684 {
Geoff Langbfdea662014-07-23 14:16:32 -04005685 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5686 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5687 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005688 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005689 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005690 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005691}
5692
5693GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5694{
5695 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5696 target, offset, length, access);
5697
Geoff Langbfdea662014-07-23 14:16:32 -04005698 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005699 if (context)
5700 {
5701 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005702 {
Geoff Langb1196682014-07-23 13:47:29 -04005703 context->recordError(gl::Error(GL_INVALID_OPERATION));
5704 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005705 }
Geoff Langbfdea662014-07-23 14:16:32 -04005706
5707 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005708 }
5709
5710 return NULL;
5711}
5712
5713void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5714{
5715 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5716
Geoff Langbfdea662014-07-23 14:16:32 -04005717 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005718 if (context)
5719 {
5720 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005721 {
Geoff Langb1196682014-07-23 13:47:29 -04005722 context->recordError(gl::Error(GL_INVALID_OPERATION));
5723 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005724 }
Geoff Langbfdea662014-07-23 14:16:32 -04005725
5726 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005727 }
5728}
5729
5730void __stdcall glBindVertexArray(GLuint array)
5731{
5732 EVENT("(GLuint array = %u)", array);
5733
Geoff Langbfdea662014-07-23 14:16:32 -04005734 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005735 if (context)
5736 {
5737 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005738 {
Geoff Langb1196682014-07-23 13:47:29 -04005739 context->recordError(gl::Error(GL_INVALID_OPERATION));
5740 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005741 }
Geoff Langbfdea662014-07-23 14:16:32 -04005742
5743 gl::VertexArray *vao = context->getVertexArray(array);
5744
5745 if (!vao)
5746 {
5747 // The default VAO should always exist
5748 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005749 context->recordError(gl::Error(GL_INVALID_OPERATION));
5750 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005751 }
5752
5753 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005754 }
5755}
5756
5757void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5758{
5759 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5760
Geoff Langbfdea662014-07-23 14:16:32 -04005761 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005762 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005763 {
Geoff Langbfdea662014-07-23 14:16:32 -04005764 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005765 {
Geoff Langb1196682014-07-23 13:47:29 -04005766 context->recordError(gl::Error(GL_INVALID_OPERATION));
5767 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005768 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005769
Geoff Langbfdea662014-07-23 14:16:32 -04005770 if (n < 0)
5771 {
Geoff Langb1196682014-07-23 13:47:29 -04005772 context->recordError(gl::Error(GL_INVALID_VALUE));
5773 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005774 }
Jamie Madilld1028542013-07-02 11:57:04 -04005775
Geoff Langbfdea662014-07-23 14:16:32 -04005776 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5777 {
5778 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005779 {
Geoff Langbfdea662014-07-23 14:16:32 -04005780 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005781 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005782 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005783 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005784}
5785
5786void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5787{
5788 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5789
Geoff Langbfdea662014-07-23 14:16:32 -04005790 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005791 if (context)
5792 {
5793 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005794 {
Geoff Langb1196682014-07-23 13:47:29 -04005795 context->recordError(gl::Error(GL_INVALID_OPERATION));
5796 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005797 }
Geoff Langbfdea662014-07-23 14:16:32 -04005798
5799 if (n < 0)
5800 {
Geoff Langb1196682014-07-23 13:47:29 -04005801 context->recordError(gl::Error(GL_INVALID_VALUE));
5802 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005803 }
5804
5805 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5806 {
5807 arrays[arrayIndex] = context->createVertexArray();
5808 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005809 }
5810}
5811
5812GLboolean __stdcall glIsVertexArray(GLuint array)
5813{
5814 EVENT("(GLuint array = %u)", array);
5815
Geoff Langbfdea662014-07-23 14:16:32 -04005816 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005817 if (context)
5818 {
5819 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005820 {
Geoff Langb1196682014-07-23 13:47:29 -04005821 context->recordError(gl::Error(GL_INVALID_OPERATION));
5822 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005823 }
Geoff Langbfdea662014-07-23 14:16:32 -04005824
5825 if (array == 0)
5826 {
5827 return GL_FALSE;
5828 }
5829
5830 gl::VertexArray *vao = context->getVertexArray(array);
5831
5832 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005833 }
5834
5835 return GL_FALSE;
5836}
5837
5838void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5839{
5840 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5841 target, index, data);
5842
Geoff Langbfdea662014-07-23 14:16:32 -04005843 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005844 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005845 {
Geoff Langbfdea662014-07-23 14:16:32 -04005846 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005847 {
Geoff Langb1196682014-07-23 13:47:29 -04005848 context->recordError(gl::Error(GL_INVALID_OPERATION));
5849 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005850 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005851
Geoff Lang3a61c322014-07-10 13:01:54 -04005852 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005853 switch (target)
5854 {
5855 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5856 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5857 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005858 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5859 {
Geoff Langb1196682014-07-23 13:47:29 -04005860 context->recordError(gl::Error(GL_INVALID_VALUE));
5861 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005862 }
Geoff Langbfdea662014-07-23 14:16:32 -04005863 break;
Geoff Langb1196682014-07-23 13:47:29 -04005864
Geoff Langbfdea662014-07-23 14:16:32 -04005865 case GL_UNIFORM_BUFFER_START:
5866 case GL_UNIFORM_BUFFER_SIZE:
5867 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005868 if (index >= caps.maxCombinedUniformBlocks)
5869 {
Geoff Langb1196682014-07-23 13:47:29 -04005870 context->recordError(gl::Error(GL_INVALID_VALUE));
5871 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005872 }
Geoff Langbfdea662014-07-23 14:16:32 -04005873 break;
Geoff Langb1196682014-07-23 13:47:29 -04005874
Geoff Langbfdea662014-07-23 14:16:32 -04005875 default:
Geoff Langb1196682014-07-23 13:47:29 -04005876 context->recordError(gl::Error(GL_INVALID_ENUM));
5877 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005878 }
5879
5880 if (!(context->getIndexedIntegerv(target, index, data)))
5881 {
5882 GLenum nativeType;
5883 unsigned int numParams = 0;
5884 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005885 {
5886 context->recordError(gl::Error(GL_INVALID_ENUM));
5887 return;
5888 }
Shannon Woods15934d52013-08-19 14:28:49 -04005889
Geoff Langbfdea662014-07-23 14:16:32 -04005890 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005891 {
Geoff Langbfdea662014-07-23 14:16:32 -04005892 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005893 }
Geoff Langbfdea662014-07-23 14:16:32 -04005894
5895 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005896 {
Geoff Langbfdea662014-07-23 14:16:32 -04005897 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5898 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5899 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005900
Geoff Langbfdea662014-07-23 14:16:32 -04005901 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005902
Geoff Langbfdea662014-07-23 14:16:32 -04005903 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005904 {
Geoff Langbfdea662014-07-23 14:16:32 -04005905 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5906 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005907 }
Geoff Langbfdea662014-07-23 14:16:32 -04005908
5909 delete [] int64Params;
5910 }
5911 else
5912 {
5913 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005914 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005916 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005917}
5918
5919void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5920{
5921 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5922
Geoff Langbfdea662014-07-23 14:16:32 -04005923 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005924 if (context)
5925 {
5926 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005927 {
Geoff Langb1196682014-07-23 13:47:29 -04005928 context->recordError(gl::Error(GL_INVALID_OPERATION));
5929 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005930 }
Geoff Langbfdea662014-07-23 14:16:32 -04005931
5932 switch (primitiveMode)
5933 {
5934 case GL_TRIANGLES:
5935 case GL_LINES:
5936 case GL_POINTS:
5937 break;
Geoff Langb1196682014-07-23 13:47:29 -04005938
Geoff Langbfdea662014-07-23 14:16:32 -04005939 default:
Geoff Langb1196682014-07-23 13:47:29 -04005940 context->recordError(gl::Error(GL_INVALID_ENUM));
5941 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005942 }
5943
5944 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5945 ASSERT(transformFeedback != NULL);
5946
5947 if (transformFeedback->isStarted())
5948 {
Geoff Langb1196682014-07-23 13:47:29 -04005949 context->recordError(gl::Error(GL_INVALID_OPERATION));
5950 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005951 }
5952
5953 if (transformFeedback->isPaused())
5954 {
5955 transformFeedback->resume();
5956 }
5957 else
5958 {
5959 transformFeedback->start(primitiveMode);
5960 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005961 }
5962}
5963
5964void __stdcall glEndTransformFeedback(void)
5965{
5966 EVENT("(void)");
5967
Geoff Langbfdea662014-07-23 14:16:32 -04005968 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005969 if (context)
5970 {
5971 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005972 {
Geoff Langb1196682014-07-23 13:47:29 -04005973 context->recordError(gl::Error(GL_INVALID_OPERATION));
5974 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005975 }
Geoff Langbfdea662014-07-23 14:16:32 -04005976
5977 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5978 ASSERT(transformFeedback != NULL);
5979
5980 if (!transformFeedback->isStarted())
5981 {
Geoff Langb1196682014-07-23 13:47:29 -04005982 context->recordError(gl::Error(GL_INVALID_OPERATION));
5983 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005984 }
5985
5986 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005987 }
5988}
5989
5990void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5991{
5992 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5993 target, index, buffer, offset, size);
5994
Geoff Langbfdea662014-07-23 14:16:32 -04005995 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005996 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005997 {
Geoff Langbfdea662014-07-23 14:16:32 -04005998 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005999 {
Geoff Langb1196682014-07-23 13:47:29 -04006000 context->recordError(gl::Error(GL_INVALID_OPERATION));
6001 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006002 }
6003
Geoff Lang3a61c322014-07-10 13:01:54 -04006004 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006005 switch (target)
6006 {
6007 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006008 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006009 {
Geoff Langb1196682014-07-23 13:47:29 -04006010 context->recordError(gl::Error(GL_INVALID_VALUE));
6011 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006012 }
Geoff Langbfdea662014-07-23 14:16:32 -04006013 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006014
Geoff Langbfdea662014-07-23 14:16:32 -04006015 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006016 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006017 {
Geoff Langb1196682014-07-23 13:47:29 -04006018 context->recordError(gl::Error(GL_INVALID_VALUE));
6019 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006020 }
Geoff Langbfdea662014-07-23 14:16:32 -04006021 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006022
Geoff Langbfdea662014-07-23 14:16:32 -04006023 default:
Geoff Langb1196682014-07-23 13:47:29 -04006024 context->recordError(gl::Error(GL_INVALID_ENUM));
6025 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006026 }
6027
6028 if (buffer != 0 && size <= 0)
6029 {
Geoff Langb1196682014-07-23 13:47:29 -04006030 context->recordError(gl::Error(GL_INVALID_VALUE));
6031 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006032 }
6033
6034 switch (target)
6035 {
6036 case GL_TRANSFORM_FEEDBACK_BUFFER:
6037
6038 // size and offset must be a multiple of 4
6039 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006040 {
Geoff Langb1196682014-07-23 13:47:29 -04006041 context->recordError(gl::Error(GL_INVALID_VALUE));
6042 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006043 }
6044
Geoff Langbfdea662014-07-23 14:16:32 -04006045 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
6046 context->bindGenericTransformFeedbackBuffer(buffer);
6047 break;
6048
6049 case GL_UNIFORM_BUFFER:
6050
6051 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006052 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006053 {
Geoff Langb1196682014-07-23 13:47:29 -04006054 context->recordError(gl::Error(GL_INVALID_VALUE));
6055 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006056 }
Geoff Langbfdea662014-07-23 14:16:32 -04006057
6058 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6059 context->bindGenericUniformBuffer(buffer);
6060 break;
6061
6062 default:
6063 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006065 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006066}
6067
6068void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
6069{
6070 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6071 target, index, buffer);
6072
Geoff Langbfdea662014-07-23 14:16:32 -04006073 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006074 if (context)
6075 {
6076 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006077 {
Geoff Langb1196682014-07-23 13:47:29 -04006078 context->recordError(gl::Error(GL_INVALID_OPERATION));
6079 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006080 }
Geoff Langbfdea662014-07-23 14:16:32 -04006081
Geoff Lang3a61c322014-07-10 13:01:54 -04006082 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006083 switch (target)
6084 {
6085 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006086 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006087 {
Geoff Langb1196682014-07-23 13:47:29 -04006088 context->recordError(gl::Error(GL_INVALID_VALUE));
6089 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006090 }
6091 break;
6092
6093 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006094 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006095 {
Geoff Langb1196682014-07-23 13:47:29 -04006096 context->recordError(gl::Error(GL_INVALID_VALUE));
6097 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006098 }
6099 break;
6100
6101 default:
Geoff Langb1196682014-07-23 13:47:29 -04006102 context->recordError(gl::Error(GL_INVALID_ENUM));
6103 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006104 }
6105
6106 switch (target)
6107 {
6108 case GL_TRANSFORM_FEEDBACK_BUFFER:
6109 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6110 context->bindGenericTransformFeedbackBuffer(buffer);
6111 break;
6112
6113 case GL_UNIFORM_BUFFER:
6114 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6115 context->bindGenericUniformBuffer(buffer);
6116 break;
6117
6118 default:
6119 UNREACHABLE();
6120 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006121 }
6122}
6123
6124void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6125{
6126 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6127 program, count, varyings, bufferMode);
6128
Geoff Langbfdea662014-07-23 14:16:32 -04006129 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006130 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006131 {
Geoff Langbfdea662014-07-23 14:16:32 -04006132 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006133 {
Geoff Langb1196682014-07-23 13:47:29 -04006134 context->recordError(gl::Error(GL_INVALID_OPERATION));
6135 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006136 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006137
Geoff Langbfdea662014-07-23 14:16:32 -04006138 if (count < 0)
6139 {
Geoff Langb1196682014-07-23 13:47:29 -04006140 context->recordError(gl::Error(GL_INVALID_VALUE));
6141 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006142 }
6143
Geoff Lang05881a02014-07-10 14:05:30 -04006144 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006145 switch (bufferMode)
6146 {
6147 case GL_INTERLEAVED_ATTRIBS:
6148 break;
6149 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006150 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006151 {
Geoff Langb1196682014-07-23 13:47:29 -04006152 context->recordError(gl::Error(GL_INVALID_VALUE));
6153 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006154 }
Geoff Langbfdea662014-07-23 14:16:32 -04006155 break;
6156 default:
Geoff Langb1196682014-07-23 13:47:29 -04006157 context->recordError(gl::Error(GL_INVALID_ENUM));
6158 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006159 }
Geoff Langbfdea662014-07-23 14:16:32 -04006160
6161 if (!gl::ValidProgram(context, program))
6162 {
6163 return;
6164 }
6165
6166 gl::Program *programObject = context->getProgram(program);
6167 ASSERT(programObject);
6168
6169 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006170 }
6171}
6172
6173void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6174{
6175 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6176 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6177 program, index, bufSize, length, size, type, name);
6178
Geoff Langbfdea662014-07-23 14:16:32 -04006179 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006180 if (context)
6181 {
6182 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006183 {
Geoff Langb1196682014-07-23 13:47:29 -04006184 context->recordError(gl::Error(GL_INVALID_OPERATION));
6185 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006186 }
Geoff Langbfdea662014-07-23 14:16:32 -04006187
6188 if (bufSize < 0)
6189 {
Geoff Langb1196682014-07-23 13:47:29 -04006190 context->recordError(gl::Error(GL_INVALID_VALUE));
6191 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006192 }
6193
6194 if (!gl::ValidProgram(context, program))
6195 {
6196 return;
6197 }
6198
6199 gl::Program *programObject = context->getProgram(program);
6200 ASSERT(programObject);
6201
6202 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6203 {
Geoff Langb1196682014-07-23 13:47:29 -04006204 context->recordError(gl::Error(GL_INVALID_VALUE));
6205 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006206 }
6207
6208 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006209 }
6210}
6211
6212void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6213{
6214 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6215 index, size, type, stride, pointer);
6216
Geoff Langbfdea662014-07-23 14:16:32 -04006217 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006218 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006219 {
Geoff Langbfdea662014-07-23 14:16:32 -04006220 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006221 {
Geoff Langb1196682014-07-23 13:47:29 -04006222 context->recordError(gl::Error(GL_INVALID_OPERATION));
6223 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006224 }
6225
Geoff Langb1196682014-07-23 13:47:29 -04006226 if (index >= gl::MAX_VERTEX_ATTRIBS)
6227 {
6228 context->recordError(gl::Error(GL_INVALID_VALUE));
6229 return;
6230 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006231
Geoff Langb1196682014-07-23 13:47:29 -04006232 if (size < 1 || size > 4)
6233 {
6234 context->recordError(gl::Error(GL_INVALID_VALUE));
6235 return;
6236 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006237
Geoff Langb1196682014-07-23 13:47:29 -04006238 switch (type)
6239 {
6240 case GL_BYTE:
6241 case GL_UNSIGNED_BYTE:
6242 case GL_SHORT:
6243 case GL_UNSIGNED_SHORT:
6244 case GL_INT:
6245 case GL_UNSIGNED_INT:
6246 case GL_INT_2_10_10_10_REV:
6247 case GL_UNSIGNED_INT_2_10_10_10_REV:
6248 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006249
Geoff Langb1196682014-07-23 13:47:29 -04006250 default:
6251 context->recordError(gl::Error(GL_INVALID_ENUM));
6252 return;
6253 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006254
Geoff Langb1196682014-07-23 13:47:29 -04006255 if (stride < 0)
6256 {
6257 context->recordError(gl::Error(GL_INVALID_VALUE));
6258 return;
6259 }
Geoff Langbfdea662014-07-23 14:16:32 -04006260
Geoff Langb1196682014-07-23 13:47:29 -04006261 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6262 {
6263 context->recordError(gl::Error(GL_INVALID_OPERATION));
6264 return;
6265 }
6266
Geoff Langbfdea662014-07-23 14:16:32 -04006267 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6268 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6269 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6270 // and the pointer argument is not NULL.
6271 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006272 {
Geoff Langb1196682014-07-23 13:47:29 -04006273 context->recordError(gl::Error(GL_INVALID_OPERATION));
6274 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006275 }
6276
Geoff Langbfdea662014-07-23 14:16:32 -04006277 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6278 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006279 }
6280}
6281
6282void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6283{
6284 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6285 index, pname, params);
6286
Geoff Langbfdea662014-07-23 14:16:32 -04006287 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006288 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006289 {
Geoff Langbfdea662014-07-23 14:16:32 -04006290 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006291 {
Geoff Langb1196682014-07-23 13:47:29 -04006292 context->recordError(gl::Error(GL_INVALID_OPERATION));
6293 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006294 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006295
Geoff Langbfdea662014-07-23 14:16:32 -04006296 if (index >= gl::MAX_VERTEX_ATTRIBS)
6297 {
Geoff Langb1196682014-07-23 13:47:29 -04006298 context->recordError(gl::Error(GL_INVALID_VALUE));
6299 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006300 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006301
Geoff Langbfdea662014-07-23 14:16:32 -04006302 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006303
Geoff Langb1196682014-07-23 13:47:29 -04006304 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006305 {
6306 return;
6307 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006308
Geoff Langbfdea662014-07-23 14:16:32 -04006309 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6310 {
6311 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6312 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006313 {
Geoff Langbfdea662014-07-23 14:16:32 -04006314 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006315 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006316 }
Geoff Langbfdea662014-07-23 14:16:32 -04006317 else
6318 {
6319 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6320 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006321 }
6322}
6323
6324void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6325{
6326 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6327 index, pname, params);
6328
Geoff Langbfdea662014-07-23 14:16:32 -04006329 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006330 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006331 {
Geoff Langbfdea662014-07-23 14:16:32 -04006332 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006333 {
Geoff Langb1196682014-07-23 13:47:29 -04006334 context->recordError(gl::Error(GL_INVALID_OPERATION));
6335 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006336 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006337
Geoff Langbfdea662014-07-23 14:16:32 -04006338 if (index >= gl::MAX_VERTEX_ATTRIBS)
6339 {
Geoff Langb1196682014-07-23 13:47:29 -04006340 context->recordError(gl::Error(GL_INVALID_VALUE));
6341 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006342 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006343
Geoff Langbfdea662014-07-23 14:16:32 -04006344 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006345
Geoff Langb1196682014-07-23 13:47:29 -04006346 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006347 {
6348 return;
6349 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006350
Geoff Langbfdea662014-07-23 14:16:32 -04006351 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6352 {
6353 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6354 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006355 {
Geoff Langbfdea662014-07-23 14:16:32 -04006356 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006357 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006358 }
Geoff Langbfdea662014-07-23 14:16:32 -04006359 else
6360 {
6361 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6362 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006363 }
6364}
6365
6366void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6367{
6368 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6369 index, x, y, z, w);
6370
Geoff Langbfdea662014-07-23 14:16:32 -04006371 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006372 if (context)
6373 {
6374 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006375 {
Geoff Langb1196682014-07-23 13:47:29 -04006376 context->recordError(gl::Error(GL_INVALID_OPERATION));
6377 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006378 }
Geoff Langbfdea662014-07-23 14:16:32 -04006379
6380 if (index >= gl::MAX_VERTEX_ATTRIBS)
6381 {
Geoff Langb1196682014-07-23 13:47:29 -04006382 context->recordError(gl::Error(GL_INVALID_VALUE));
6383 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006384 }
6385
6386 GLint vals[4] = { x, y, z, w };
6387 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006388 }
6389}
6390
6391void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6392{
6393 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6394 index, x, y, z, w);
6395
Geoff Langbfdea662014-07-23 14:16:32 -04006396 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006397 if (context)
6398 {
6399 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006400 {
Geoff Langb1196682014-07-23 13:47:29 -04006401 context->recordError(gl::Error(GL_INVALID_OPERATION));
6402 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006403 }
Geoff Langbfdea662014-07-23 14:16:32 -04006404
6405 if (index >= gl::MAX_VERTEX_ATTRIBS)
6406 {
Geoff Langb1196682014-07-23 13:47:29 -04006407 context->recordError(gl::Error(GL_INVALID_VALUE));
6408 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006409 }
6410
6411 GLuint vals[4] = { x, y, z, w };
6412 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006413 }
6414}
6415
6416void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6417{
6418 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6419
Geoff Langbfdea662014-07-23 14:16:32 -04006420 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006421 if (context)
6422 {
6423 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006424 {
Geoff Langb1196682014-07-23 13:47:29 -04006425 context->recordError(gl::Error(GL_INVALID_OPERATION));
6426 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006427 }
Geoff Langbfdea662014-07-23 14:16:32 -04006428
6429 if (index >= gl::MAX_VERTEX_ATTRIBS)
6430 {
Geoff Langb1196682014-07-23 13:47:29 -04006431 context->recordError(gl::Error(GL_INVALID_VALUE));
6432 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006433 }
6434
6435 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006436 }
6437}
6438
6439void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6440{
6441 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6442
Geoff Langbfdea662014-07-23 14:16:32 -04006443 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006444 if (context)
6445 {
6446 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006447 {
Geoff Langb1196682014-07-23 13:47:29 -04006448 context->recordError(gl::Error(GL_INVALID_OPERATION));
6449 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006450 }
Geoff Langbfdea662014-07-23 14:16:32 -04006451
6452 if (index >= gl::MAX_VERTEX_ATTRIBS)
6453 {
Geoff Langb1196682014-07-23 13:47:29 -04006454 context->recordError(gl::Error(GL_INVALID_VALUE));
6455 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006456 }
6457
6458 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006459 }
6460}
6461
6462void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6463{
6464 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6465 program, location, params);
6466
Geoff Langbfdea662014-07-23 14:16:32 -04006467 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006468 if (context)
6469 {
Jamie Madill0063c512014-08-25 15:47:53 -04006470 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006471 {
Jamie Madill0063c512014-08-25 15:47:53 -04006472 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006473 }
Geoff Langbfdea662014-07-23 14:16:32 -04006474
Jamie Madilla502c742014-08-28 17:19:13 -04006475 gl::Program *programObject = context->getProgram(program);
6476 ASSERT(programObject);
6477 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006478 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006479
Jamie Madill99a1e982014-08-25 15:47:54 -04006480 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006481 }
6482}
6483
6484GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6485{
6486 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6487 program, name);
6488
Geoff Langbfdea662014-07-23 14:16:32 -04006489 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006490 if (context)
6491 {
6492 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006493 {
Geoff Langb1196682014-07-23 13:47:29 -04006494 context->recordError(gl::Error(GL_INVALID_OPERATION));
6495 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006496 }
Geoff Langbfdea662014-07-23 14:16:32 -04006497
6498 if (program == 0)
6499 {
Geoff Langb1196682014-07-23 13:47:29 -04006500 context->recordError(gl::Error(GL_INVALID_VALUE));
6501 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006502 }
6503
6504 gl::Program *programObject = context->getProgram(program);
6505
6506 if (!programObject || !programObject->isLinked())
6507 {
Geoff Langb1196682014-07-23 13:47:29 -04006508 context->recordError(gl::Error(GL_INVALID_OPERATION));
6509 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006510 }
6511
6512 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6513 if (!programBinary)
6514 {
Geoff Langb1196682014-07-23 13:47:29 -04006515 context->recordError(gl::Error(GL_INVALID_OPERATION));
6516 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006517 }
6518
6519 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006520 }
6521
6522 return 0;
6523}
6524
6525void __stdcall glUniform1ui(GLint location, GLuint v0)
6526{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006527 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006528}
6529
6530void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6531{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006532 const GLuint xy[] = { v0, v1 };
6533 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006534}
6535
6536void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6537{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006538 const GLuint xyz[] = { v0, v1, v2 };
6539 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006540}
6541
6542void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6543{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006544 const GLuint xyzw[] = { v0, v1, v2, v3 };
6545 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006546}
6547
6548void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6549{
6550 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6551 location, count, value);
6552
Geoff Langbfdea662014-07-23 14:16:32 -04006553 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006554 if (context)
6555 {
6556 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006557 {
Geoff Langbfdea662014-07-23 14:16:32 -04006558 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006559 }
Geoff Langbfdea662014-07-23 14:16:32 -04006560
6561 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6562 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006563 }
6564}
6565
6566void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6567{
6568 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6569 location, count, value);
6570
Geoff Langbfdea662014-07-23 14:16:32 -04006571 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006572 if (context)
6573 {
6574 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006575 {
Geoff Langbfdea662014-07-23 14:16:32 -04006576 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006577 }
Geoff Langbfdea662014-07-23 14:16:32 -04006578
6579 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6580 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006581 }
6582}
6583
6584void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6585{
6586 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6587 location, count, value);
6588
Geoff Langbfdea662014-07-23 14:16:32 -04006589 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006590 if (context)
6591 {
6592 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006593 {
Geoff Langbfdea662014-07-23 14:16:32 -04006594 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006595 }
Geoff Langbfdea662014-07-23 14:16:32 -04006596
6597 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6598 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006599 }
6600}
6601
6602void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6603{
6604 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6605 location, count, value);
6606
Geoff Langbfdea662014-07-23 14:16:32 -04006607 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006608 if (context)
6609 {
6610 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006611 {
Geoff Langbfdea662014-07-23 14:16:32 -04006612 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006613 }
Geoff Langbfdea662014-07-23 14:16:32 -04006614
6615 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6616 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006617 }
6618}
6619
6620void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6621{
6622 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6623 buffer, drawbuffer, value);
6624
Geoff Langbfdea662014-07-23 14:16:32 -04006625 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006626 if (context)
6627 {
6628 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006629 {
Geoff Langbfdea662014-07-23 14:16:32 -04006630 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006631 }
Geoff Langbfdea662014-07-23 14:16:32 -04006632
6633 switch (buffer)
6634 {
6635 case GL_COLOR:
6636 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6637 {
Geoff Langb1196682014-07-23 13:47:29 -04006638 context->recordError(gl::Error(GL_INVALID_VALUE));
6639 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006640 }
6641 break;
Geoff Langb1196682014-07-23 13:47:29 -04006642
Geoff Langbfdea662014-07-23 14:16:32 -04006643 case GL_STENCIL:
6644 if (drawbuffer != 0)
6645 {
Geoff Langb1196682014-07-23 13:47:29 -04006646 context->recordError(gl::Error(GL_INVALID_VALUE));
6647 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006648 }
6649 break;
Geoff Langb1196682014-07-23 13:47:29 -04006650
Geoff Langbfdea662014-07-23 14:16:32 -04006651 default:
Geoff Langb1196682014-07-23 13:47:29 -04006652 context->recordError(gl::Error(GL_INVALID_ENUM));
6653 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006654 }
6655
Geoff Langcc79b8c2014-07-25 13:48:02 -04006656 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6657 if (error.isError())
6658 {
6659 context->recordError(error);
6660 return;
6661 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006662 }
6663}
6664
6665void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6666{
6667 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6668 buffer, drawbuffer, value);
6669
Geoff Langbfdea662014-07-23 14:16:32 -04006670 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006671 if (context)
6672 {
6673 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006674 {
Geoff Langbfdea662014-07-23 14:16:32 -04006675 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006676 }
Geoff Langbfdea662014-07-23 14:16:32 -04006677
6678 switch (buffer)
6679 {
6680 case GL_COLOR:
6681 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6682 {
Geoff Langb1196682014-07-23 13:47:29 -04006683 context->recordError(gl::Error(GL_INVALID_VALUE));
6684 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006685 }
6686 break;
Geoff Langb1196682014-07-23 13:47:29 -04006687
Geoff Langbfdea662014-07-23 14:16:32 -04006688 default:
Geoff Langb1196682014-07-23 13:47:29 -04006689 context->recordError(gl::Error(GL_INVALID_ENUM));
6690 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006691 }
6692
Geoff Langcc79b8c2014-07-25 13:48:02 -04006693 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6694 if (error.isError())
6695 {
6696 context->recordError(error);
6697 return;
6698 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006699 }
6700}
6701
6702void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6703{
6704 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6705 buffer, drawbuffer, value);
6706
Geoff Langbfdea662014-07-23 14:16:32 -04006707 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006708 if (context)
6709 {
6710 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006711 {
Geoff Langbfdea662014-07-23 14:16:32 -04006712 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006713 }
Geoff Langbfdea662014-07-23 14:16:32 -04006714
6715 switch (buffer)
6716 {
6717 case GL_COLOR:
6718 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6719 {
Geoff Langb1196682014-07-23 13:47:29 -04006720 context->recordError(gl::Error(GL_INVALID_VALUE));
6721 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006722 }
6723 break;
Geoff Langb1196682014-07-23 13:47:29 -04006724
Geoff Langbfdea662014-07-23 14:16:32 -04006725 case GL_DEPTH:
6726 if (drawbuffer != 0)
6727 {
Geoff Langb1196682014-07-23 13:47:29 -04006728 context->recordError(gl::Error(GL_INVALID_VALUE));
6729 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006730 }
6731 break;
Geoff Langb1196682014-07-23 13:47:29 -04006732
Geoff Langbfdea662014-07-23 14:16:32 -04006733 default:
Geoff Langb1196682014-07-23 13:47:29 -04006734 context->recordError(gl::Error(GL_INVALID_ENUM));
6735 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006736 }
6737
Geoff Langcc79b8c2014-07-25 13:48:02 -04006738 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6739 if (error.isError())
6740 {
6741 context->recordError(error);
6742 return;
6743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006744 }
6745}
6746
6747void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6748{
6749 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6750 buffer, drawbuffer, depth, stencil);
6751
Geoff Langbfdea662014-07-23 14:16:32 -04006752 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006753 if (context)
6754 {
6755 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006756 {
Geoff Langbfdea662014-07-23 14:16:32 -04006757 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006758 }
Geoff Langbfdea662014-07-23 14:16:32 -04006759
6760 switch (buffer)
6761 {
6762 case GL_DEPTH_STENCIL:
6763 if (drawbuffer != 0)
6764 {
Geoff Langb1196682014-07-23 13:47:29 -04006765 context->recordError(gl::Error(GL_INVALID_VALUE));
6766 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006767 }
6768 break;
Geoff Langb1196682014-07-23 13:47:29 -04006769
Geoff Langbfdea662014-07-23 14:16:32 -04006770 default:
Geoff Langb1196682014-07-23 13:47:29 -04006771 context->recordError(gl::Error(GL_INVALID_ENUM));
6772 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006773 }
6774
Geoff Langcc79b8c2014-07-25 13:48:02 -04006775 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6776 if (error.isError())
6777 {
6778 context->recordError(error);
6779 return;
6780 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006781 }
6782}
6783
6784const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6785{
6786 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6787
Geoff Langbfdea662014-07-23 14:16:32 -04006788 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006789 if (context)
6790 {
6791 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006792 {
Geoff Langb1196682014-07-23 13:47:29 -04006793 context->recordError(gl::Error(GL_INVALID_OPERATION));
6794 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006795 }
Geoff Langbfdea662014-07-23 14:16:32 -04006796
6797 if (name != GL_EXTENSIONS)
6798 {
Geoff Langb1196682014-07-23 13:47:29 -04006799 context->recordError(gl::Error(GL_INVALID_ENUM));
6800 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006801 }
6802
6803 if (index >= context->getExtensionStringCount())
6804 {
Geoff Langb1196682014-07-23 13:47:29 -04006805 context->recordError(gl::Error(GL_INVALID_VALUE));
6806 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006807 }
6808
6809 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006810 }
6811
6812 return NULL;
6813}
6814
6815void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6816{
6817 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6818 readTarget, writeTarget, readOffset, writeOffset, size);
6819
Geoff Langbfdea662014-07-23 14:16:32 -04006820 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006821 if (context)
6822 {
6823 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006824 {
Geoff Langb1196682014-07-23 13:47:29 -04006825 context->recordError(gl::Error(GL_INVALID_OPERATION));
6826 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006827 }
Geoff Langbfdea662014-07-23 14:16:32 -04006828
6829 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6830 {
Geoff Langb1196682014-07-23 13:47:29 -04006831 context->recordError(gl::Error(GL_INVALID_ENUM));
6832 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006833 }
6834
6835 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6836 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6837
6838 if (!readBuffer || !writeBuffer)
6839 {
Geoff Langb1196682014-07-23 13:47:29 -04006840 context->recordError(gl::Error(GL_INVALID_OPERATION));
6841 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006842 }
6843
Jamie Madillcfaaf722014-07-31 10:47:54 -04006844 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006845 if (readBuffer->isMapped() || writeBuffer->isMapped())
6846 {
Geoff Langb1196682014-07-23 13:47:29 -04006847 context->recordError(gl::Error(GL_INVALID_OPERATION));
6848 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006849 }
6850
6851 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6852 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6853 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6854 {
Geoff Langb1196682014-07-23 13:47:29 -04006855 context->recordError(gl::Error(GL_INVALID_VALUE));
6856 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006857 }
6858
6859 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6860 {
Geoff Langb1196682014-07-23 13:47:29 -04006861 context->recordError(gl::Error(GL_INVALID_VALUE));
6862 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006863 }
6864
Geoff Langbfdea662014-07-23 14:16:32 -04006865 // if size is zero, the copy is a successful no-op
6866 if (size > 0)
6867 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006868 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6869 if (error.isError())
6870 {
6871 context->recordError(error);
6872 return;
6873 }
Geoff Langbfdea662014-07-23 14:16:32 -04006874 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006875 }
6876}
6877
6878void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6879{
6880 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6881 program, uniformCount, uniformNames, uniformIndices);
6882
Geoff Langbfdea662014-07-23 14:16:32 -04006883 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006884 if (context)
6885 {
6886 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006887 {
Geoff Langb1196682014-07-23 13:47:29 -04006888 context->recordError(gl::Error(GL_INVALID_OPERATION));
6889 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006890 }
6891
6892 if (uniformCount < 0)
6893 {
Geoff Langb1196682014-07-23 13:47:29 -04006894 context->recordError(gl::Error(GL_INVALID_VALUE));
6895 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006896 }
6897
6898 gl::Program *programObject = context->getProgram(program);
6899
6900 if (!programObject)
6901 {
6902 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006903 {
Geoff Langb1196682014-07-23 13:47:29 -04006904 context->recordError(gl::Error(GL_INVALID_OPERATION));
6905 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006906 }
Geoff Langbfdea662014-07-23 14:16:32 -04006907 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006908 {
Geoff Langb1196682014-07-23 13:47:29 -04006909 context->recordError(gl::Error(GL_INVALID_VALUE));
6910 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006911 }
Geoff Langbfdea662014-07-23 14:16:32 -04006912 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006913
Geoff Langbfdea662014-07-23 14:16:32 -04006914 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6915 if (!programObject->isLinked() || !programBinary)
6916 {
6917 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006918 {
Geoff Langbfdea662014-07-23 14:16:32 -04006919 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006920 }
6921 }
Geoff Langbfdea662014-07-23 14:16:32 -04006922 else
6923 {
6924 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6925 {
6926 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6927 }
6928 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006929 }
6930}
6931
6932void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6933{
6934 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6935 program, uniformCount, uniformIndices, pname, params);
6936
Geoff Langbfdea662014-07-23 14:16:32 -04006937 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006938 if (context)
6939 {
6940 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006941 {
Geoff Langb1196682014-07-23 13:47:29 -04006942 context->recordError(gl::Error(GL_INVALID_OPERATION));
6943 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006944 }
6945
6946 if (uniformCount < 0)
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
6952 gl::Program *programObject = context->getProgram(program);
6953
6954 if (!programObject)
6955 {
6956 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006957 {
Geoff Langb1196682014-07-23 13:47:29 -04006958 context->recordError(gl::Error(GL_INVALID_OPERATION));
6959 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006960 }
Geoff Langbfdea662014-07-23 14:16:32 -04006961 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006962 {
Geoff Langb1196682014-07-23 13:47:29 -04006963 context->recordError(gl::Error(GL_INVALID_VALUE));
6964 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006965 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006966 }
Geoff Langbfdea662014-07-23 14:16:32 -04006967
6968 switch (pname)
6969 {
6970 case GL_UNIFORM_TYPE:
6971 case GL_UNIFORM_SIZE:
6972 case GL_UNIFORM_NAME_LENGTH:
6973 case GL_UNIFORM_BLOCK_INDEX:
6974 case GL_UNIFORM_OFFSET:
6975 case GL_UNIFORM_ARRAY_STRIDE:
6976 case GL_UNIFORM_MATRIX_STRIDE:
6977 case GL_UNIFORM_IS_ROW_MAJOR:
6978 break;
Geoff Langb1196682014-07-23 13:47:29 -04006979
Geoff Langbfdea662014-07-23 14:16:32 -04006980 default:
Geoff Langb1196682014-07-23 13:47:29 -04006981 context->recordError(gl::Error(GL_INVALID_ENUM));
6982 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006983 }
6984
6985 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6986
6987 if (!programBinary && uniformCount > 0)
6988 {
Geoff Langb1196682014-07-23 13:47:29 -04006989 context->recordError(gl::Error(GL_INVALID_VALUE));
6990 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006991 }
6992
6993 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6994 {
6995 const GLuint index = uniformIndices[uniformId];
6996
6997 if (index >= (GLuint)programBinary->getActiveUniformCount())
6998 {
Geoff Langb1196682014-07-23 13:47:29 -04006999 context->recordError(gl::Error(GL_INVALID_VALUE));
7000 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007001 }
7002 }
7003
7004 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7005 {
7006 const GLuint index = uniformIndices[uniformId];
7007 params[uniformId] = programBinary->getActiveUniformi(index, pname);
7008 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007009 }
7010}
7011
7012GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
7013{
7014 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
7015
Geoff Langbfdea662014-07-23 14:16:32 -04007016 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007017 if (context)
7018 {
7019 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007020 {
Geoff Langb1196682014-07-23 13:47:29 -04007021 context->recordError(gl::Error(GL_INVALID_OPERATION));
7022 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04007023 }
7024
7025 gl::Program *programObject = context->getProgram(program);
7026
7027 if (!programObject)
7028 {
7029 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007030 {
Geoff Langb1196682014-07-23 13:47:29 -04007031 context->recordError(gl::Error(GL_INVALID_OPERATION));
7032 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007033 }
Geoff Langbfdea662014-07-23 14:16:32 -04007034 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007035 {
Geoff Langb1196682014-07-23 13:47:29 -04007036 context->recordError(gl::Error(GL_INVALID_VALUE));
7037 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007038 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007039 }
Geoff Langbfdea662014-07-23 14:16:32 -04007040
7041 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7042 if (!programBinary)
7043 {
7044 return GL_INVALID_INDEX;
7045 }
7046
7047 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007048 }
7049
7050 return 0;
7051}
7052
7053void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
7054{
7055 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7056 program, uniformBlockIndex, pname, params);
7057
Geoff Langbfdea662014-07-23 14:16:32 -04007058 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007059 if (context)
7060 {
7061 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007062 {
Geoff Langb1196682014-07-23 13:47:29 -04007063 context->recordError(gl::Error(GL_INVALID_OPERATION));
7064 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007065 }
7066 gl::Program *programObject = context->getProgram(program);
7067
7068 if (!programObject)
7069 {
7070 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007071 {
Geoff Langb1196682014-07-23 13:47:29 -04007072 context->recordError(gl::Error(GL_INVALID_OPERATION));
7073 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007074 }
Geoff Langbfdea662014-07-23 14:16:32 -04007075 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007076 {
Geoff Langb1196682014-07-23 13:47:29 -04007077 context->recordError(gl::Error(GL_INVALID_VALUE));
7078 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007079 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007080 }
Geoff Langbfdea662014-07-23 14:16:32 -04007081
7082 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7083
7084 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
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 switch (pname)
7091 {
7092 case GL_UNIFORM_BLOCK_BINDING:
7093 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7094 break;
7095
7096 case GL_UNIFORM_BLOCK_DATA_SIZE:
7097 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7098 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7099 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7100 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7101 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7102 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7103 break;
7104
7105 default:
Geoff Langb1196682014-07-23 13:47:29 -04007106 context->recordError(gl::Error(GL_INVALID_ENUM));
7107 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007108 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007109 }
7110}
7111
7112void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7113{
7114 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7115 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7116
Geoff Langbfdea662014-07-23 14:16:32 -04007117 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007118 if (context)
7119 {
7120 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007121 {
Geoff Langb1196682014-07-23 13:47:29 -04007122 context->recordError(gl::Error(GL_INVALID_OPERATION));
7123 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007124 }
7125
7126 gl::Program *programObject = context->getProgram(program);
7127
7128 if (!programObject)
7129 {
7130 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007131 {
Geoff Langb1196682014-07-23 13:47:29 -04007132 context->recordError(gl::Error(GL_INVALID_OPERATION));
7133 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007134 }
Geoff Langbfdea662014-07-23 14:16:32 -04007135 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007136 {
Geoff Langb1196682014-07-23 13:47:29 -04007137 context->recordError(gl::Error(GL_INVALID_VALUE));
7138 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007139 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007140 }
Geoff Langbfdea662014-07-23 14:16:32 -04007141
7142 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7143
7144 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7145 {
Geoff Langb1196682014-07-23 13:47:29 -04007146 context->recordError(gl::Error(GL_INVALID_VALUE));
7147 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007148 }
7149
7150 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007151 }
7152}
7153
7154void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7155{
7156 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7157 program, uniformBlockIndex, uniformBlockBinding);
7158
Geoff Langbfdea662014-07-23 14:16:32 -04007159 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007160 if (context)
7161 {
7162 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007163 {
Geoff Langb1196682014-07-23 13:47:29 -04007164 context->recordError(gl::Error(GL_INVALID_OPERATION));
7165 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007166 }
7167
Geoff Lang3a61c322014-07-10 13:01:54 -04007168 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007169 {
Geoff Langb1196682014-07-23 13:47:29 -04007170 context->recordError(gl::Error(GL_INVALID_VALUE));
7171 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007172 }
7173
7174 gl::Program *programObject = context->getProgram(program);
7175
7176 if (!programObject)
7177 {
7178 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007179 {
Geoff Langb1196682014-07-23 13:47:29 -04007180 context->recordError(gl::Error(GL_INVALID_OPERATION));
7181 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007182 }
Geoff Langbfdea662014-07-23 14:16:32 -04007183 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007184 {
Geoff Langb1196682014-07-23 13:47:29 -04007185 context->recordError(gl::Error(GL_INVALID_VALUE));
7186 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007187 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007188 }
Geoff Langbfdea662014-07-23 14:16:32 -04007189
7190 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7191
7192 // if never linked, there won't be any uniform blocks
7193 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7194 {
Geoff Langb1196682014-07-23 13:47:29 -04007195 context->recordError(gl::Error(GL_INVALID_VALUE));
7196 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007197 }
7198
7199 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007200 }
7201}
7202
7203void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7204{
7205 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7206 mode, first, count, instanceCount);
7207
Geoff Langbfdea662014-07-23 14:16:32 -04007208 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007209 if (context)
7210 {
7211 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007212 {
Geoff Langb1196682014-07-23 13:47:29 -04007213 context->recordError(gl::Error(GL_INVALID_OPERATION));
7214 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007215 }
Geoff Langbfdea662014-07-23 14:16:32 -04007216
7217 // glDrawArraysInstanced
7218 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007219 }
7220}
7221
7222void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7223{
7224 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7225 mode, count, type, indices, instanceCount);
7226
Geoff Langbfdea662014-07-23 14:16:32 -04007227 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007228 if (context)
7229 {
7230 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007231 {
Geoff Langb1196682014-07-23 13:47:29 -04007232 context->recordError(gl::Error(GL_INVALID_OPERATION));
7233 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007234 }
Geoff Langbfdea662014-07-23 14:16:32 -04007235
7236 // glDrawElementsInstanced
7237 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007238 }
7239}
7240
7241GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7242{
7243 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7244
Geoff Langbfdea662014-07-23 14:16:32 -04007245 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007246 if (context)
7247 {
7248 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007249 {
Geoff Langb1196682014-07-23 13:47:29 -04007250 context->recordError(gl::Error(GL_INVALID_OPERATION));
7251 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007252 }
Geoff Langbfdea662014-07-23 14:16:32 -04007253
7254 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7255 {
Geoff Langb1196682014-07-23 13:47:29 -04007256 context->recordError(gl::Error(GL_INVALID_ENUM));
7257 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007258 }
7259
7260 if (flags != 0)
7261 {
Geoff Langb1196682014-07-23 13:47:29 -04007262 context->recordError(gl::Error(GL_INVALID_VALUE));
7263 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007264 }
7265
7266 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007267 }
7268
7269 return NULL;
7270}
7271
7272GLboolean __stdcall glIsSync(GLsync sync)
7273{
7274 EVENT("(GLsync sync = 0x%0.8p)", sync);
7275
Geoff Langbfdea662014-07-23 14:16:32 -04007276 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007277 if (context)
7278 {
7279 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007280 {
Geoff Langb1196682014-07-23 13:47:29 -04007281 context->recordError(gl::Error(GL_INVALID_OPERATION));
7282 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007283 }
Geoff Langbfdea662014-07-23 14:16:32 -04007284
7285 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007286 }
7287
7288 return GL_FALSE;
7289}
7290
7291void __stdcall glDeleteSync(GLsync sync)
7292{
7293 EVENT("(GLsync sync = 0x%0.8p)", sync);
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 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7305 {
Geoff Langb1196682014-07-23 13:47:29 -04007306 context->recordError(gl::Error(GL_INVALID_VALUE));
7307 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007308 }
7309
7310 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007311 }
7312}
7313
7314GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7315{
7316 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7317 sync, flags, timeout);
7318
Geoff Langbfdea662014-07-23 14:16:32 -04007319 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007320 if (context)
7321 {
7322 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007323 {
Geoff Langb1196682014-07-23 13:47:29 -04007324 context->recordError(gl::Error(GL_INVALID_OPERATION));
7325 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007326 }
Geoff Langbfdea662014-07-23 14:16:32 -04007327
7328 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7329 {
Geoff Langb1196682014-07-23 13:47:29 -04007330 context->recordError(gl::Error(GL_INVALID_VALUE));
7331 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007332 }
7333
7334 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7335
7336 if (!fenceSync)
7337 {
Geoff Langb1196682014-07-23 13:47:29 -04007338 context->recordError(gl::Error(GL_INVALID_VALUE));
7339 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007340 }
7341
7342 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007343 }
7344
7345 return GL_FALSE;
7346}
7347
7348void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7349{
7350 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7351 sync, flags, timeout);
7352
Geoff Langbfdea662014-07-23 14:16:32 -04007353 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007354 if (context)
7355 {
7356 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007357 {
Geoff Langb1196682014-07-23 13:47:29 -04007358 context->recordError(gl::Error(GL_INVALID_OPERATION));
7359 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007360 }
Geoff Langbfdea662014-07-23 14:16:32 -04007361
7362 if (flags != 0)
7363 {
Geoff Langb1196682014-07-23 13:47:29 -04007364 context->recordError(gl::Error(GL_INVALID_VALUE));
7365 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007366 }
7367
7368 if (timeout != GL_TIMEOUT_IGNORED)
7369 {
Geoff Langb1196682014-07-23 13:47:29 -04007370 context->recordError(gl::Error(GL_INVALID_VALUE));
7371 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007372 }
7373
7374 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7375
7376 if (!fenceSync)
7377 {
Geoff Langb1196682014-07-23 13:47:29 -04007378 context->recordError(gl::Error(GL_INVALID_VALUE));
7379 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007380 }
7381
7382 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007383 }
7384}
7385
7386void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7387{
7388 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7389 pname, params);
7390
Geoff Langbfdea662014-07-23 14:16:32 -04007391 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007392 if (context)
7393 {
7394 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007395 {
Geoff Langb1196682014-07-23 13:47:29 -04007396 context->recordError(gl::Error(GL_INVALID_OPERATION));
7397 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007398 }
Geoff Langbfdea662014-07-23 14:16:32 -04007399
7400 GLenum nativeType;
7401 unsigned int numParams = 0;
7402 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7403 {
7404 return;
7405 }
7406
7407 if (nativeType == GL_INT_64_ANGLEX)
7408 {
7409 context->getInteger64v(pname, params);
7410 }
7411 else
7412 {
7413 CastStateValues(context, nativeType, pname, numParams, params);
7414 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007415 }
7416}
7417
7418void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7419{
7420 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7421 sync, pname, bufSize, length, values);
7422
Geoff Langbfdea662014-07-23 14:16:32 -04007423 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007424 if (context)
7425 {
7426 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007427 {
Geoff Langb1196682014-07-23 13:47:29 -04007428 context->recordError(gl::Error(GL_INVALID_OPERATION));
7429 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007430 }
Geoff Langbfdea662014-07-23 14:16:32 -04007431
7432 if (bufSize < 0)
7433 {
Geoff Langb1196682014-07-23 13:47:29 -04007434 context->recordError(gl::Error(GL_INVALID_VALUE));
7435 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007436 }
7437
7438 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7439
7440 if (!fenceSync)
7441 {
Geoff Langb1196682014-07-23 13:47:29 -04007442 context->recordError(gl::Error(GL_INVALID_VALUE));
7443 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007444 }
7445
7446 switch (pname)
7447 {
7448 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7449 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7450 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7451 case GL_SYNC_FLAGS: values[0] = 0; break;
7452
7453 default:
Geoff Langb1196682014-07-23 13:47:29 -04007454 context->recordError(gl::Error(GL_INVALID_ENUM));
7455 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007456 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007457 }
7458}
7459
7460void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7461{
7462 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7463 target, index, data);
7464
Geoff Langbfdea662014-07-23 14:16:32 -04007465 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007466 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007467 {
Geoff Langbfdea662014-07-23 14:16:32 -04007468 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007469 {
Geoff Langb1196682014-07-23 13:47:29 -04007470 context->recordError(gl::Error(GL_INVALID_OPERATION));
7471 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007472 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007473
Geoff Lang3a61c322014-07-10 13:01:54 -04007474 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007475 switch (target)
7476 {
7477 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7478 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7479 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007480 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7481 {
Geoff Langb1196682014-07-23 13:47:29 -04007482 context->recordError(gl::Error(GL_INVALID_VALUE));
7483 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007484 }
Geoff Langbfdea662014-07-23 14:16:32 -04007485 break;
Geoff Langb1196682014-07-23 13:47:29 -04007486
Geoff Langbfdea662014-07-23 14:16:32 -04007487 case GL_UNIFORM_BUFFER_START:
7488 case GL_UNIFORM_BUFFER_SIZE:
7489 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007490 if (index >= caps.maxUniformBufferBindings)
7491 {
Geoff Langb1196682014-07-23 13:47:29 -04007492 context->recordError(gl::Error(GL_INVALID_VALUE));
7493 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007494 }
Geoff Langbfdea662014-07-23 14:16:32 -04007495 break;
Geoff Langb1196682014-07-23 13:47:29 -04007496
Geoff Langbfdea662014-07-23 14:16:32 -04007497 default:
Geoff Langb1196682014-07-23 13:47:29 -04007498 context->recordError(gl::Error(GL_INVALID_ENUM));
7499 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007500 }
7501
7502 if (!(context->getIndexedInteger64v(target, index, data)))
7503 {
7504 GLenum nativeType;
7505 unsigned int numParams = 0;
7506 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007507 {
7508 context->recordError(gl::Error(GL_INVALID_ENUM));
7509 return;
7510 }
Shannon Woods15934d52013-08-19 14:28:49 -04007511
Geoff Langbfdea662014-07-23 14:16:32 -04007512 if (numParams == 0)
7513 return; // it is known that pname is valid, but there are no parameters to return
7514
7515 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007516 {
Geoff Langbfdea662014-07-23 14:16:32 -04007517 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007518
Geoff Langbfdea662014-07-23 14:16:32 -04007519 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007520
Geoff Langbfdea662014-07-23 14:16:32 -04007521 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007522 {
Geoff Langbfdea662014-07-23 14:16:32 -04007523 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007524 }
Geoff Langbfdea662014-07-23 14:16:32 -04007525
7526 delete [] intParams;
7527 }
7528 else
7529 {
7530 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007531 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007532 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007533 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007534}
7535
7536void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7537{
7538 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7539 target, pname, params);
7540
Geoff Langbfdea662014-07-23 14:16:32 -04007541 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007542 if (context)
7543 {
7544 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007545 {
Geoff Langb1196682014-07-23 13:47:29 -04007546 context->recordError(gl::Error(GL_INVALID_OPERATION));
7547 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007548 }
Geoff Langbfdea662014-07-23 14:16:32 -04007549
7550 if (!gl::ValidBufferTarget(context, target))
7551 {
Geoff Langb1196682014-07-23 13:47:29 -04007552 context->recordError(gl::Error(GL_INVALID_ENUM));
7553 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007554 }
7555
7556 if (!gl::ValidBufferParameter(context, pname))
7557 {
Geoff Langb1196682014-07-23 13:47:29 -04007558 context->recordError(gl::Error(GL_INVALID_ENUM));
7559 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007560 }
7561
7562 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7563
7564 if (!buffer)
7565 {
7566 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007567 context->recordError(gl::Error(GL_INVALID_OPERATION));
7568 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007569 }
7570
7571 switch (pname)
7572 {
7573 case GL_BUFFER_USAGE:
7574 *params = static_cast<GLint64>(buffer->getUsage());
7575 break;
7576 case GL_BUFFER_SIZE:
7577 *params = buffer->getSize();
7578 break;
7579 case GL_BUFFER_ACCESS_FLAGS:
7580 *params = static_cast<GLint64>(buffer->getAccessFlags());
7581 break;
7582 case GL_BUFFER_MAPPED:
7583 *params = static_cast<GLint64>(buffer->isMapped());
7584 break;
7585 case GL_BUFFER_MAP_OFFSET:
7586 *params = buffer->getMapOffset();
7587 break;
7588 case GL_BUFFER_MAP_LENGTH:
7589 *params = buffer->getMapLength();
7590 break;
7591 default: UNREACHABLE(); break;
7592 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007593 }
7594}
7595
7596void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7597{
7598 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7599
Geoff Langbfdea662014-07-23 14:16:32 -04007600 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007601 if (context)
7602 {
7603 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007604 {
Geoff Langb1196682014-07-23 13:47:29 -04007605 context->recordError(gl::Error(GL_INVALID_OPERATION));
7606 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007607 }
Geoff Langbfdea662014-07-23 14:16:32 -04007608
7609 if (count < 0)
7610 {
Geoff Langb1196682014-07-23 13:47:29 -04007611 context->recordError(gl::Error(GL_INVALID_VALUE));
7612 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007613 }
7614
7615 for (int i = 0; i < count; i++)
7616 {
7617 samplers[i] = context->createSampler();
7618 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007619 }
7620}
7621
7622void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7623{
7624 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7625
Geoff Langbfdea662014-07-23 14:16:32 -04007626 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007627 if (context)
7628 {
7629 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007630 {
Geoff Langb1196682014-07-23 13:47:29 -04007631 context->recordError(gl::Error(GL_INVALID_OPERATION));
7632 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007633 }
Geoff Langbfdea662014-07-23 14:16:32 -04007634
7635 if (count < 0)
7636 {
Geoff Langb1196682014-07-23 13:47:29 -04007637 context->recordError(gl::Error(GL_INVALID_VALUE));
7638 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007639 }
7640
7641 for (int i = 0; i < count; i++)
7642 {
7643 context->deleteSampler(samplers[i]);
7644 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007645 }
7646}
7647
7648GLboolean __stdcall glIsSampler(GLuint sampler)
7649{
7650 EVENT("(GLuint sampler = %u)", sampler);
7651
Geoff Langbfdea662014-07-23 14:16:32 -04007652 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007653 if (context)
7654 {
7655 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007656 {
Geoff Langb1196682014-07-23 13:47:29 -04007657 context->recordError(gl::Error(GL_INVALID_OPERATION));
7658 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007659 }
Geoff Langbfdea662014-07-23 14:16:32 -04007660
7661 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007662 }
7663
7664 return GL_FALSE;
7665}
7666
7667void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7668{
7669 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7670
Geoff Langbfdea662014-07-23 14:16:32 -04007671 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007672 if (context)
7673 {
7674 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007675 {
Geoff Langb1196682014-07-23 13:47:29 -04007676 context->recordError(gl::Error(GL_INVALID_OPERATION));
7677 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007678 }
Geoff Langbfdea662014-07-23 14:16:32 -04007679
7680 if (sampler != 0 && !context->isSampler(sampler))
7681 {
Geoff Langb1196682014-07-23 13:47:29 -04007682 context->recordError(gl::Error(GL_INVALID_OPERATION));
7683 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007684 }
7685
Geoff Lang3a61c322014-07-10 13:01:54 -04007686 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007687 {
Geoff Langb1196682014-07-23 13:47:29 -04007688 context->recordError(gl::Error(GL_INVALID_VALUE));
7689 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007690 }
7691
7692 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007693 }
7694}
7695
7696void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7697{
7698 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7699
Geoff Langbfdea662014-07-23 14:16:32 -04007700 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007701 if (context)
7702 {
7703 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007704 {
Geoff Langb1196682014-07-23 13:47:29 -04007705 context->recordError(gl::Error(GL_INVALID_OPERATION));
7706 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007707 }
Geoff Langbfdea662014-07-23 14:16:32 -04007708
Geoff Langb1196682014-07-23 13:47:29 -04007709 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007710 {
7711 return;
7712 }
7713
7714 if (!gl::ValidateTexParamParameters(context, pname, param))
7715 {
7716 return;
7717 }
7718
7719 if (!context->isSampler(sampler))
7720 {
Geoff Langb1196682014-07-23 13:47:29 -04007721 context->recordError(gl::Error(GL_INVALID_OPERATION));
7722 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007723 }
7724
7725 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007726 }
7727}
7728
7729void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7730{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007731 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007732}
7733
7734void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7735{
7736 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7737
Geoff Langbfdea662014-07-23 14:16:32 -04007738 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007739 if (context)
7740 {
7741 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007742 {
Geoff Langb1196682014-07-23 13:47:29 -04007743 context->recordError(gl::Error(GL_INVALID_OPERATION));
7744 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007745 }
Geoff Langbfdea662014-07-23 14:16:32 -04007746
Geoff Langb1196682014-07-23 13:47:29 -04007747 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007748 {
7749 return;
7750 }
7751
7752 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7753 {
7754 return;
7755 }
7756
7757 if (!context->isSampler(sampler))
7758 {
Geoff Langb1196682014-07-23 13:47:29 -04007759 context->recordError(gl::Error(GL_INVALID_OPERATION));
7760 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007761 }
7762
7763 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007764 }
7765}
7766
7767void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7768{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007769 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007770}
7771
7772void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7773{
7774 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7775
Geoff Langbfdea662014-07-23 14:16:32 -04007776 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007777 if (context)
7778 {
7779 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007780 {
Geoff Langb1196682014-07-23 13:47:29 -04007781 context->recordError(gl::Error(GL_INVALID_OPERATION));
7782 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007783 }
Geoff Langbfdea662014-07-23 14:16:32 -04007784
Geoff Langb1196682014-07-23 13:47:29 -04007785 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007786 {
7787 return;
7788 }
7789
7790 if (!context->isSampler(sampler))
7791 {
Geoff Langb1196682014-07-23 13:47:29 -04007792 context->recordError(gl::Error(GL_INVALID_OPERATION));
7793 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007794 }
7795
7796 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007797 }
7798}
7799
7800void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7801{
7802 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7803
Geoff Langbfdea662014-07-23 14:16:32 -04007804 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007805 if (context)
7806 {
7807 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007808 {
Geoff Langb1196682014-07-23 13:47:29 -04007809 context->recordError(gl::Error(GL_INVALID_OPERATION));
7810 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007811 }
Geoff Langbfdea662014-07-23 14:16:32 -04007812
Geoff Langb1196682014-07-23 13:47:29 -04007813 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007814 {
7815 return;
7816 }
7817
7818 if (!context->isSampler(sampler))
7819 {
Geoff Langb1196682014-07-23 13:47:29 -04007820 context->recordError(gl::Error(GL_INVALID_OPERATION));
7821 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007822 }
7823
7824 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007825 }
7826}
7827
7828void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7829{
7830 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7831
Geoff Langbfdea662014-07-23 14:16:32 -04007832 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007833 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007834 {
Geoff Langbfdea662014-07-23 14:16:32 -04007835 if (context->getClientVersion() < 3)
7836 {
Geoff Langb1196682014-07-23 13:47:29 -04007837 context->recordError(gl::Error(GL_INVALID_OPERATION));
7838 return;
7839 }
7840
7841 if (index >= gl::MAX_VERTEX_ATTRIBS)
7842 {
7843 context->recordError(gl::Error(GL_INVALID_VALUE));
7844 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007845 }
7846
7847 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007848 }
7849}
7850
7851void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7852{
7853 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7854
Geoff Langbfdea662014-07-23 14:16:32 -04007855 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007856 if (context)
7857 {
7858 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007859 {
Geoff Langb1196682014-07-23 13:47:29 -04007860 context->recordError(gl::Error(GL_INVALID_OPERATION));
7861 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007862 }
Geoff Langbfdea662014-07-23 14:16:32 -04007863
7864 switch (target)
7865 {
7866 case GL_TRANSFORM_FEEDBACK:
7867 {
7868 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7869 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7870 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7871 {
Geoff Langb1196682014-07-23 13:47:29 -04007872 context->recordError(gl::Error(GL_INVALID_OPERATION));
7873 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007874 }
7875
7876 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7877 if (context->getTransformFeedback(id) == NULL)
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 context->bindTransformFeedback(id);
7884 }
7885 break;
7886
7887 default:
Geoff Langb1196682014-07-23 13:47:29 -04007888 context->recordError(gl::Error(GL_INVALID_ENUM));
7889 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007890 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007891 }
7892}
7893
7894void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7895{
7896 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7897
Geoff Langbfdea662014-07-23 14:16:32 -04007898 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007899 if (context)
7900 {
7901 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007902 {
Geoff Langb1196682014-07-23 13:47:29 -04007903 context->recordError(gl::Error(GL_INVALID_OPERATION));
7904 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007905 }
Geoff Langbfdea662014-07-23 14:16:32 -04007906
7907 for (int i = 0; i < n; i++)
7908 {
7909 context->deleteTransformFeedback(ids[i]);
7910 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007911 }
7912}
7913
7914void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7915{
7916 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7917
Geoff Langbfdea662014-07-23 14:16:32 -04007918 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007919 if (context)
7920 {
7921 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007922 {
Geoff Langb1196682014-07-23 13:47:29 -04007923 context->recordError(gl::Error(GL_INVALID_OPERATION));
7924 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007925 }
Geoff Langbfdea662014-07-23 14:16:32 -04007926
7927 for (int i = 0; i < n; i++)
7928 {
7929 ids[i] = context->createTransformFeedback();
7930 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007931 }
7932}
7933
7934GLboolean __stdcall glIsTransformFeedback(GLuint id)
7935{
7936 EVENT("(GLuint id = %u)", id);
7937
Geoff Langbfdea662014-07-23 14:16:32 -04007938 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007939 if (context)
7940 {
7941 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007942 {
Geoff Langb1196682014-07-23 13:47:29 -04007943 context->recordError(gl::Error(GL_INVALID_OPERATION));
7944 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007945 }
Geoff Langbfdea662014-07-23 14:16:32 -04007946
7947 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007948 }
7949
7950 return GL_FALSE;
7951}
7952
7953void __stdcall glPauseTransformFeedback(void)
7954{
7955 EVENT("(void)");
7956
Geoff Langbfdea662014-07-23 14:16:32 -04007957 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007958 if (context)
7959 {
7960 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007961 {
Geoff Langb1196682014-07-23 13:47:29 -04007962 context->recordError(gl::Error(GL_INVALID_OPERATION));
7963 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007964 }
Geoff Langbfdea662014-07-23 14:16:32 -04007965
7966 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7967 ASSERT(transformFeedback != NULL);
7968
7969 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7970 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7971 {
Geoff Langb1196682014-07-23 13:47:29 -04007972 context->recordError(gl::Error(GL_INVALID_OPERATION));
7973 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007974 }
7975
7976 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007977 }
7978}
7979
7980void __stdcall glResumeTransformFeedback(void)
7981{
7982 EVENT("(void)");
7983
Geoff Langbfdea662014-07-23 14:16:32 -04007984 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007985 if (context)
7986 {
7987 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007988 {
Geoff Langb1196682014-07-23 13:47:29 -04007989 context->recordError(gl::Error(GL_INVALID_OPERATION));
7990 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007991 }
Geoff Langbfdea662014-07-23 14:16:32 -04007992
7993 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7994 ASSERT(transformFeedback != NULL);
7995
7996 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7997 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7998 {
Geoff Langb1196682014-07-23 13:47:29 -04007999 context->recordError(gl::Error(GL_INVALID_OPERATION));
8000 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008001 }
8002
8003 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008004 }
8005}
8006
8007void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
8008{
8009 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
8010 program, bufSize, length, binaryFormat, binary);
8011
Geoff Langbfdea662014-07-23 14:16:32 -04008012 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008013 if (context)
8014 {
8015 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008016 {
Geoff Langb1196682014-07-23 13:47:29 -04008017 context->recordError(gl::Error(GL_INVALID_OPERATION));
8018 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008019 }
Geoff Langbfdea662014-07-23 14:16:32 -04008020
8021 // glGetProgramBinary
8022 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008023 }
8024}
8025
8026void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
8027{
8028 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
8029 program, binaryFormat, binary, length);
8030
Geoff Langbfdea662014-07-23 14:16:32 -04008031 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008032 if (context)
8033 {
8034 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008035 {
Geoff Langb1196682014-07-23 13:47:29 -04008036 context->recordError(gl::Error(GL_INVALID_OPERATION));
8037 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008038 }
Geoff Langbfdea662014-07-23 14:16:32 -04008039
8040 // glProgramBinary
8041 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008042 }
8043}
8044
8045void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
8046{
8047 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
8048 program, pname, value);
8049
Geoff Langbfdea662014-07-23 14:16:32 -04008050 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008051 if (context)
8052 {
8053 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008054 {
Geoff Langb1196682014-07-23 13:47:29 -04008055 context->recordError(gl::Error(GL_INVALID_OPERATION));
8056 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008057 }
Geoff Langbfdea662014-07-23 14:16:32 -04008058
8059 // glProgramParameteri
8060 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008061 }
8062}
8063
8064void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
8065{
8066 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8067 target, numAttachments, attachments);
8068
Geoff Langbfdea662014-07-23 14:16:32 -04008069 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008070 if (context)
8071 {
8072 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008073 {
Geoff Langb1196682014-07-23 13:47:29 -04008074 context->recordError(gl::Error(GL_INVALID_OPERATION));
8075 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008076 }
Geoff Langbfdea662014-07-23 14:16:32 -04008077
8078 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8079 {
8080 return;
8081 }
8082
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008083 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8084 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8085 {
8086 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8087 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008088 }
8089}
8090
8091void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
8092{
8093 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8094 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8095 target, numAttachments, attachments, x, y, width, height);
8096
Geoff Langbfdea662014-07-23 14:16:32 -04008097 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008098 if (context)
8099 {
8100 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008101 {
Geoff Langb1196682014-07-23 13:47:29 -04008102 context->recordError(gl::Error(GL_INVALID_OPERATION));
8103 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008104 }
Geoff Langbfdea662014-07-23 14:16:32 -04008105
8106 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8107 {
8108 return;
8109 }
8110
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008111 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8112 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8113 {
8114 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8115 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008116 }
8117}
8118
8119void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8120{
8121 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8122 target, levels, internalformat, width, height);
8123
Geoff Langbfdea662014-07-23 14:16:32 -04008124 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008125 if (context)
8126 {
8127 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008128 {
Geoff Langb1196682014-07-23 13:47:29 -04008129 context->recordError(gl::Error(GL_INVALID_OPERATION));
8130 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008131 }
Geoff Langbfdea662014-07-23 14:16:32 -04008132
8133 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8134 {
8135 return;
8136 }
8137
8138 switch (target)
8139 {
8140 case GL_TEXTURE_2D:
8141 {
8142 gl::Texture2D *texture2d = context->getTexture2D();
8143 texture2d->storage(levels, internalformat, width, height);
8144 }
8145 break;
8146
8147 case GL_TEXTURE_CUBE_MAP:
8148 {
8149 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8150 textureCube->storage(levels, internalformat, width);
8151 }
8152 break;
8153
8154 default:
Geoff Langb1196682014-07-23 13:47:29 -04008155 context->recordError(gl::Error(GL_INVALID_ENUM));
8156 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008157 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008158 }
8159}
8160
8161void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8162{
8163 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8164 "GLsizei height = %d, GLsizei depth = %d)",
8165 target, levels, internalformat, width, height, depth);
8166
Geoff Langbfdea662014-07-23 14:16:32 -04008167 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008168 if (context)
8169 {
8170 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008171 {
Geoff Langb1196682014-07-23 13:47:29 -04008172 context->recordError(gl::Error(GL_INVALID_OPERATION));
8173 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008174 }
Geoff Langbfdea662014-07-23 14:16:32 -04008175
8176 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8177 {
8178 return;
8179 }
8180
8181 switch (target)
8182 {
8183 case GL_TEXTURE_3D:
8184 {
8185 gl::Texture3D *texture3d = context->getTexture3D();
8186 texture3d->storage(levels, internalformat, width, height, depth);
8187 }
8188 break;
8189
8190 case GL_TEXTURE_2D_ARRAY:
8191 {
8192 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8193 texture2darray->storage(levels, internalformat, width, height, depth);
8194 }
8195 break;
8196
8197 default:
8198 UNREACHABLE();
8199 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008200 }
8201}
8202
8203void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8204{
8205 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8206 "GLint* params = 0x%0.8p)",
8207 target, internalformat, pname, bufSize, params);
8208
Geoff Langbfdea662014-07-23 14:16:32 -04008209 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008210 if (context)
8211 {
8212 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008213 {
Geoff Langb1196682014-07-23 13:47:29 -04008214 context->recordError(gl::Error(GL_INVALID_OPERATION));
8215 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008216 }
Geoff Langbfdea662014-07-23 14:16:32 -04008217
8218 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8219 if (!formatCaps.renderable)
8220 {
Geoff Langb1196682014-07-23 13:47:29 -04008221 context->recordError(gl::Error(GL_INVALID_ENUM));
8222 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008223 }
8224
8225 if (target != GL_RENDERBUFFER)
8226 {
Geoff Langb1196682014-07-23 13:47:29 -04008227 context->recordError(gl::Error(GL_INVALID_ENUM));
8228 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008229 }
8230
8231 if (bufSize < 0)
8232 {
Geoff Langb1196682014-07-23 13:47:29 -04008233 context->recordError(gl::Error(GL_INVALID_VALUE));
8234 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008235 }
8236
8237 switch (pname)
8238 {
8239 case GL_NUM_SAMPLE_COUNTS:
8240 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008241 {
8242 *params = formatCaps.sampleCounts.size();
8243 }
Geoff Langbfdea662014-07-23 14:16:32 -04008244 break;
Geoff Langb1196682014-07-23 13:47:29 -04008245
Geoff Langbfdea662014-07-23 14:16:32 -04008246 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008247 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008248 break;
Geoff Langb1196682014-07-23 13:47:29 -04008249
Geoff Langbfdea662014-07-23 14:16:32 -04008250 default:
Geoff Langb1196682014-07-23 13:47:29 -04008251 context->recordError(gl::Error(GL_INVALID_ENUM));
8252 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008254 }
8255}
8256
8257// Extension functions
8258
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008259void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8260 GLbitfield mask, GLenum filter)
8261{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008262 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008263 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8264 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8265 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8266
Geoff Langbfdea662014-07-23 14:16:32 -04008267 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008268 if (context)
8269 {
8270 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8271 dstX0, dstY0, dstX1, dstY1, mask, filter,
8272 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008273 {
Geoff Langbfdea662014-07-23 14:16:32 -04008274 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008275 }
Geoff Langbfdea662014-07-23 14:16:32 -04008276
8277 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8278 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008279 }
8280}
8281
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008282void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8283 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008284{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008285 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008286 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008287 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008288 target, level, internalformat, width, height, depth, border, format, type, pixels);
8289
Geoff Langbfdea662014-07-23 14:16:32 -04008290 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008291}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008292
Geoff Langbfdea662014-07-23 14:16:32 -04008293void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008294 GLenum *binaryFormat, void *binary)
8295{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008296 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 +00008297 program, bufSize, length, binaryFormat, binary);
8298
Geoff Langbfdea662014-07-23 14:16:32 -04008299 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008300 if (context)
8301 {
8302 gl::Program *programObject = context->getProgram(program);
8303
8304 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008305 {
Geoff Langb1196682014-07-23 13:47:29 -04008306 context->recordError(gl::Error(GL_INVALID_OPERATION));
8307 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008308 }
Geoff Langbfdea662014-07-23 14:16:32 -04008309
8310 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8311
8312 if (!programBinary)
8313 {
Geoff Langb1196682014-07-23 13:47:29 -04008314 context->recordError(gl::Error(GL_INVALID_OPERATION));
8315 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008316 }
8317
Geoff Lang900013c2014-07-07 11:32:19 -04008318 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04008319 {
Geoff Langb1196682014-07-23 13:47:29 -04008320 context->recordError(gl::Error(GL_INVALID_OPERATION));
8321 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008322 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008323 }
8324}
8325
8326void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8327 const void *binary, GLint length)
8328{
8329 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8330 program, binaryFormat, binary, length);
8331
Geoff Langbfdea662014-07-23 14:16:32 -04008332 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008333 if (context)
8334 {
Geoff Lang900013c2014-07-07 11:32:19 -04008335 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8336 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008337 {
Geoff Langb1196682014-07-23 13:47:29 -04008338 context->recordError(gl::Error(GL_INVALID_ENUM));
8339 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008340 }
Geoff Langbfdea662014-07-23 14:16:32 -04008341
8342 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008343 if (!programObject)
8344 {
Geoff Langb1196682014-07-23 13:47:29 -04008345 context->recordError(gl::Error(GL_INVALID_OPERATION));
8346 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008347 }
8348
Geoff Lang900013c2014-07-07 11:32:19 -04008349 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008350 }
8351}
8352
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008353void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8354{
8355 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8356
Geoff Langbfdea662014-07-23 14:16:32 -04008357 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008358 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008359 {
Geoff Langbfdea662014-07-23 14:16:32 -04008360 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008361 {
Geoff Langb1196682014-07-23 13:47:29 -04008362 context->recordError(gl::Error(GL_INVALID_VALUE));
8363 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008364 }
8365
8366 if (context->getState().getDrawFramebuffer()->id() == 0)
8367 {
8368 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008369 {
Geoff Langb1196682014-07-23 13:47:29 -04008370 context->recordError(gl::Error(GL_INVALID_OPERATION));
8371 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008372 }
8373
Geoff Langbfdea662014-07-23 14:16:32 -04008374 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008375 {
Geoff Langb1196682014-07-23 13:47:29 -04008376 context->recordError(gl::Error(GL_INVALID_OPERATION));
8377 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008378 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008379 }
Geoff Langbfdea662014-07-23 14:16:32 -04008380 else
8381 {
8382 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8383 {
8384 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8385 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8386 {
Geoff Langb1196682014-07-23 13:47:29 -04008387 context->recordError(gl::Error(GL_INVALID_OPERATION));
8388 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008389 }
8390 }
8391 }
8392
8393 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8394
8395 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8396 {
8397 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8398 }
8399
8400 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8401 {
8402 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8403 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008404 }
8405}
8406
Shannon Woodsb3801742014-03-27 14:59:19 -04008407void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8408{
8409 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8410
Geoff Langbfdea662014-07-23 14:16:32 -04008411 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008412 if (context)
8413 {
8414 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008415 {
Geoff Langb1196682014-07-23 13:47:29 -04008416 context->recordError(gl::Error(GL_INVALID_ENUM));
8417 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008418 }
Geoff Langbfdea662014-07-23 14:16:32 -04008419
8420 if (pname != GL_BUFFER_MAP_POINTER)
8421 {
Geoff Langb1196682014-07-23 13:47:29 -04008422 context->recordError(gl::Error(GL_INVALID_ENUM));
8423 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008424 }
8425
8426 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8427
8428 if (!buffer || !buffer->isMapped())
8429 {
8430 *params = NULL;
8431 }
8432 else
8433 {
8434 *params = buffer->getMapPointer();
8435 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008436 }
8437}
8438
8439void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8440{
8441 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8442
Geoff Langbfdea662014-07-23 14:16:32 -04008443 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008444 if (context)
8445 {
8446 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008447 {
Geoff Langb1196682014-07-23 13:47:29 -04008448 context->recordError(gl::Error(GL_INVALID_ENUM));
8449 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008450 }
Geoff Langbfdea662014-07-23 14:16:32 -04008451
8452 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8453
8454 if (buffer == NULL)
8455 {
Geoff Langb1196682014-07-23 13:47:29 -04008456 context->recordError(gl::Error(GL_INVALID_OPERATION));
8457 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008458 }
8459
8460 if (access != GL_WRITE_ONLY_OES)
8461 {
Geoff Langb1196682014-07-23 13:47:29 -04008462 context->recordError(gl::Error(GL_INVALID_ENUM));
8463 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008464 }
8465
8466 if (buffer->isMapped())
8467 {
Geoff Langb1196682014-07-23 13:47:29 -04008468 context->recordError(gl::Error(GL_INVALID_OPERATION));
8469 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008470 }
8471
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008472 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8473 if (error.isError())
8474 {
8475 context->recordError(error);
8476 return NULL;
8477 }
8478
8479 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008480 }
8481
8482 return NULL;
8483}
8484
8485GLboolean __stdcall glUnmapBufferOES(GLenum target)
8486{
8487 EVENT("(GLenum target = 0x%X)", target);
8488
Geoff Langbfdea662014-07-23 14:16:32 -04008489 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008490 if (context)
8491 {
8492 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008493 {
Geoff Langb1196682014-07-23 13:47:29 -04008494 context->recordError(gl::Error(GL_INVALID_ENUM));
8495 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008496 }
Geoff Langbfdea662014-07-23 14:16:32 -04008497
8498 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8499
8500 if (buffer == NULL || !buffer->isMapped())
8501 {
Geoff Langb1196682014-07-23 13:47:29 -04008502 context->recordError(gl::Error(GL_INVALID_OPERATION));
8503 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008504 }
8505
8506 // TODO: detect if we had corruption. if so, throw an error and return false.
8507
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008508 gl::Error error = buffer->unmap();
8509 if (error.isError())
8510 {
8511 context->recordError(error);
8512 return GL_FALSE;
8513 }
Geoff Langbfdea662014-07-23 14:16:32 -04008514
8515 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008516 }
8517
8518 return GL_FALSE;
8519}
8520
Shannon Woods916e7692014-03-27 16:58:22 -04008521void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8522{
8523 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8524 target, offset, length, access);
8525
Geoff Langbfdea662014-07-23 14:16:32 -04008526 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008527 if (context)
8528 {
8529 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008530 {
Geoff Langb1196682014-07-23 13:47:29 -04008531 context->recordError(gl::Error(GL_INVALID_ENUM));
8532 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008533 }
Geoff Langbfdea662014-07-23 14:16:32 -04008534
8535 if (offset < 0 || length < 0)
8536 {
Geoff Langb1196682014-07-23 13:47:29 -04008537 context->recordError(gl::Error(GL_INVALID_VALUE));
8538 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008539 }
8540
8541 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8542
8543 if (buffer == NULL)
8544 {
Geoff Langb1196682014-07-23 13:47:29 -04008545 context->recordError(gl::Error(GL_INVALID_OPERATION));
8546 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008547 }
8548
8549 // Check for buffer overflow
8550 size_t offsetSize = static_cast<size_t>(offset);
8551 size_t lengthSize = static_cast<size_t>(length);
8552
8553 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8554 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8555 {
Geoff Langb1196682014-07-23 13:47:29 -04008556 context->recordError(gl::Error(GL_INVALID_VALUE));
8557 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008558 }
8559
8560 // Check for invalid bits in the mask
8561 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8562 GL_MAP_WRITE_BIT |
8563 GL_MAP_INVALIDATE_RANGE_BIT |
8564 GL_MAP_INVALIDATE_BUFFER_BIT |
8565 GL_MAP_FLUSH_EXPLICIT_BIT |
8566 GL_MAP_UNSYNCHRONIZED_BIT;
8567
8568 if (access & ~(allAccessBits))
8569 {
Geoff Langb1196682014-07-23 13:47:29 -04008570 context->recordError(gl::Error(GL_INVALID_VALUE));
8571 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008572 }
8573
8574 if (length == 0 || buffer->isMapped())
8575 {
Geoff Langb1196682014-07-23 13:47:29 -04008576 context->recordError(gl::Error(GL_INVALID_OPERATION));
8577 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008578 }
8579
8580 // Check for invalid bit combinations
8581 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8582 {
Geoff Langb1196682014-07-23 13:47:29 -04008583 context->recordError(gl::Error(GL_INVALID_OPERATION));
8584 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008585 }
8586
8587 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8588 GL_MAP_INVALIDATE_BUFFER_BIT |
8589 GL_MAP_UNSYNCHRONIZED_BIT;
8590
8591 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8592 {
Geoff Langb1196682014-07-23 13:47:29 -04008593 context->recordError(gl::Error(GL_INVALID_OPERATION));
8594 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008595 }
8596
8597 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8598 {
Geoff Langb1196682014-07-23 13:47:29 -04008599 context->recordError(gl::Error(GL_INVALID_OPERATION));
8600 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008601 }
8602
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008603 gl::Error error = buffer->mapRange(offset, length, access);
8604 if (error.isError())
8605 {
8606 context->recordError(error);
8607 return NULL;
8608 }
8609
8610 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008611 }
8612
8613 return NULL;
8614}
8615
8616void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8617{
8618 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8619
Geoff Langbfdea662014-07-23 14:16:32 -04008620 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008621 if (context)
8622 {
8623 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008624 {
Geoff Langb1196682014-07-23 13:47:29 -04008625 context->recordError(gl::Error(GL_INVALID_VALUE));
8626 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008627 }
Geoff Langbfdea662014-07-23 14:16:32 -04008628
8629 if (!gl::ValidBufferTarget(context, target))
8630 {
Geoff Langb1196682014-07-23 13:47:29 -04008631 context->recordError(gl::Error(GL_INVALID_ENUM));
8632 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008633 }
8634
8635 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8636
8637 if (buffer == NULL)
8638 {
Geoff Langb1196682014-07-23 13:47:29 -04008639 context->recordError(gl::Error(GL_INVALID_OPERATION));
8640 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008641 }
8642
8643 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8644 {
Geoff Langb1196682014-07-23 13:47:29 -04008645 context->recordError(gl::Error(GL_INVALID_OPERATION));
8646 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008647 }
8648
8649 // Check for buffer overflow
8650 size_t offsetSize = static_cast<size_t>(offset);
8651 size_t lengthSize = static_cast<size_t>(length);
8652
8653 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8654 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8655 {
Geoff Langb1196682014-07-23 13:47:29 -04008656 context->recordError(gl::Error(GL_INVALID_VALUE));
8657 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008658 }
8659
8660 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008661 }
8662}
8663
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008664__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8665{
8666 struct Extension
8667 {
8668 const char *name;
8669 __eglMustCastToProperFunctionPointerType address;
8670 };
8671
8672 static const Extension glExtensions[] =
8673 {
8674 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008675 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008676 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008677 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8678 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8679 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8680 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8681 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8682 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8683 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008684 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008685 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008686 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8687 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8688 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8689 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008690 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8691 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8692 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8693 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8694 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8695 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8696 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008697 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008698 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8699 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8700 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008701 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008702 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8703 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8704 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008705 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8706 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8707 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008708
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008709 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008710 {
8711 if (strcmp(procname, glExtensions[ext].name) == 0)
8712 {
8713 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8714 }
8715 }
8716
8717 return NULL;
8718}
8719
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008720// Non-public functions used by EGL
8721
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008722bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008723{
8724 EVENT("(egl::Surface* surface = 0x%0.8p)",
8725 surface);
8726
Geoff Langbfdea662014-07-23 14:16:32 -04008727 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008728 if (context)
8729 {
8730 gl::Texture2D *textureObject = context->getTexture2D();
8731 ASSERT(textureObject != NULL);
8732
8733 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008734 {
Geoff Langbfdea662014-07-23 14:16:32 -04008735 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008736 }
Geoff Langbfdea662014-07-23 14:16:32 -04008737
8738 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008739 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008740
8741 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008742}
8743
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008744}