blob: 8005b6e05fcffdc53a90b965183382320b7212b8 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Geoff Lang48dcae72014-02-05 16:28:24 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
8
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00009#include "common/version.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040010#include "common/utilities.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000013#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000014#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000015#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000016#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000017#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000018#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000019#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000020#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000021#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000022#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040023#include "libGLESv2/VertexArray.h"
Brandon Jones5bf98292014-06-06 17:19:38 -070024#include "libGLESv2/VertexAttribute.h"
Geoff Langc8058452014-02-03 12:04:11 -050025#include "libGLESv2/TransformFeedback.h"
Jamie Madille261b442014-06-25 12:42:21 -040026#include "libGLESv2/FramebufferAttachment.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027
Geoff Lange8ebe7f2013-08-05 15:03:13 -040028#include "libGLESv2/validationES.h"
29#include "libGLESv2/validationES2.h"
30#include "libGLESv2/validationES3.h"
Jamie Madill55856b12014-01-02 13:59:50 -050031#include "libGLESv2/queryconversions.h"
Jamie Madill478fdb22013-07-19 16:36:59 -040032
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033extern "C"
34{
35
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000036// OpenGL ES 2.0 functions
37
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038void __stdcall glActiveTexture(GLenum texture)
39{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000040 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000041
Geoff Langbfdea662014-07-23 14:16:32 -040042 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -040043 if (context)
44 {
Geoff Lang3a61c322014-07-10 13:01:54 -040045 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000046 {
Geoff Langb1196682014-07-23 13:47:29 -040047 context->recordError(gl::Error(GL_INVALID_ENUM));
48 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049 }
Geoff Langbfdea662014-07-23 14:16:32 -040050
51 context->getState().setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052 }
53}
54
55void __stdcall glAttachShader(GLuint program, GLuint shader)
56{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000057 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000058
Geoff Langbfdea662014-07-23 14:16:32 -040059 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -040060 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000061 {
Geoff Langbfdea662014-07-23 14:16:32 -040062 gl::Program *programObject = context->getProgram(program);
63 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064
Geoff Langbfdea662014-07-23 14:16:32 -040065 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066 {
Geoff Langbfdea662014-07-23 14:16:32 -040067 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000068 {
Geoff Langb1196682014-07-23 13:47:29 -040069 context->recordError(gl::Error(GL_INVALID_OPERATION));
70 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000071 }
Geoff Langbfdea662014-07-23 14:16:32 -040072 else
73 {
Geoff Langb1196682014-07-23 13:47:29 -040074 context->recordError(gl::Error(GL_INVALID_VALUE));
75 return;
Geoff Langbfdea662014-07-23 14:16:32 -040076 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000077 }
Geoff Langbfdea662014-07-23 14:16:32 -040078
79 if (!shaderObject)
80 {
81 if (context->getProgram(shader))
82 {
Geoff Langb1196682014-07-23 13:47:29 -040083 context->recordError(gl::Error(GL_INVALID_OPERATION));
84 return;
Geoff Langbfdea662014-07-23 14:16:32 -040085 }
86 else
87 {
Geoff Langb1196682014-07-23 13:47:29 -040088 context->recordError(gl::Error(GL_INVALID_VALUE));
89 return;
Geoff Langbfdea662014-07-23 14:16:32 -040090 }
91 }
92
93 if (!programObject->attachShader(shaderObject))
94 {
Geoff Langb1196682014-07-23 13:47:29 -040095 context->recordError(gl::Error(GL_INVALID_OPERATION));
96 return;
Geoff Langbfdea662014-07-23 14:16:32 -040097 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098 }
99}
100
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000101void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
102{
103 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
104
Geoff Langbfdea662014-07-23 14:16:32 -0400105 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400106 if (context)
107 {
108 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000109 {
Geoff Langbfdea662014-07-23 14:16:32 -0400110 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000111 }
Geoff Langbfdea662014-07-23 14:16:32 -0400112
Geoff Lang5aad9672014-09-08 11:10:42 -0400113 gl::Error error = context->beginQuery(target, id);
114 if (error.isError())
115 {
116 context->recordError(error);
117 return;
118 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000119 }
120}
121
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000122void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000124 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
Geoff Langbfdea662014-07-23 14:16:32 -0400126 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400127 if (context)
128 {
Geoff Langb1196682014-07-23 13:47:29 -0400129 if (index >= gl::MAX_VERTEX_ATTRIBS)
130 {
131 context->recordError(gl::Error(GL_INVALID_VALUE));
132 return;
133 }
134
Geoff Langbfdea662014-07-23 14:16:32 -0400135 gl::Program *programObject = context->getProgram(program);
136
137 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000138 {
Geoff Langbfdea662014-07-23 14:16:32 -0400139 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000140 {
Geoff Langb1196682014-07-23 13:47:29 -0400141 context->recordError(gl::Error(GL_INVALID_OPERATION));
142 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000143 }
Geoff Langbfdea662014-07-23 14:16:32 -0400144 else
145 {
Geoff Langb1196682014-07-23 13:47:29 -0400146 context->recordError(gl::Error(GL_INVALID_VALUE));
147 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400148 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000149 }
Geoff Langbfdea662014-07-23 14:16:32 -0400150
151 if (strncmp(name, "gl_", 3) == 0)
152 {
Geoff Langb1196682014-07-23 13:47:29 -0400153 context->recordError(gl::Error(GL_INVALID_OPERATION));
154 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400155 }
156
157 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000158 }
159}
160
161void __stdcall glBindBuffer(GLenum target, GLuint buffer)
162{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000163 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000164
Geoff Langbfdea662014-07-23 14:16:32 -0400165 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400166 if (context)
167 {
168 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000169 {
Geoff Langb1196682014-07-23 13:47:29 -0400170 context->recordError(gl::Error(GL_INVALID_ENUM));
171 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000172 }
Geoff Langbfdea662014-07-23 14:16:32 -0400173
174 switch (target)
175 {
176 case GL_ARRAY_BUFFER:
177 context->bindArrayBuffer(buffer);
178 return;
179 case GL_ELEMENT_ARRAY_BUFFER:
180 context->bindElementArrayBuffer(buffer);
181 return;
182 case GL_COPY_READ_BUFFER:
183 context->bindCopyReadBuffer(buffer);
184 return;
185 case GL_COPY_WRITE_BUFFER:
186 context->bindCopyWriteBuffer(buffer);
187 return;
188 case GL_PIXEL_PACK_BUFFER:
189 context->bindPixelPackBuffer(buffer);
190 return;
191 case GL_PIXEL_UNPACK_BUFFER:
192 context->bindPixelUnpackBuffer(buffer);
193 return;
194 case GL_UNIFORM_BUFFER:
195 context->bindGenericUniformBuffer(buffer);
196 return;
197 case GL_TRANSFORM_FEEDBACK_BUFFER:
198 context->bindGenericTransformFeedbackBuffer(buffer);
199 return;
Geoff Langb1196682014-07-23 13:47:29 -0400200
Geoff Langbfdea662014-07-23 14:16:32 -0400201 default:
Geoff Langb1196682014-07-23 13:47:29 -0400202 context->recordError(gl::Error(GL_INVALID_ENUM));
203 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400204 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000205 }
206}
207
208void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000210 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000211
Geoff Langbfdea662014-07-23 14:16:32 -0400212 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400213 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000214 {
Geoff Langb1196682014-07-23 13:47:29 -0400215 if (!gl::ValidFramebufferTarget(target))
216 {
217 context->recordError(gl::Error(GL_INVALID_ENUM));
218 return;
219 }
220
Geoff Langbfdea662014-07-23 14:16:32 -0400221 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
222 {
223 context->bindReadFramebuffer(framebuffer);
224 }
225
226 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
227 {
228 context->bindDrawFramebuffer(framebuffer);
229 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000230 }
231}
232
233void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
234{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000235 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000236
Geoff Langbfdea662014-07-23 14:16:32 -0400237 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400238 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000239 {
Geoff Langb1196682014-07-23 13:47:29 -0400240 if (target != GL_RENDERBUFFER)
241 {
242 context->recordError(gl::Error(GL_INVALID_ENUM));
243 return;
244 }
245
Geoff Langbfdea662014-07-23 14:16:32 -0400246 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000247 }
248}
249
250void __stdcall glBindTexture(GLenum target, GLuint texture)
251{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000252 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000253
Geoff Langbfdea662014-07-23 14:16:32 -0400254 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400255 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000256 {
Geoff Langbfdea662014-07-23 14:16:32 -0400257 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000258
Geoff Langbfdea662014-07-23 14:16:32 -0400259 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000260 {
Geoff Langb1196682014-07-23 13:47:29 -0400261 context->recordError(gl::Error(GL_INVALID_OPERATION));
262 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400263 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000264
Geoff Langbfdea662014-07-23 14:16:32 -0400265 switch (target)
266 {
267 case GL_TEXTURE_2D:
Geoff Langbfdea662014-07-23 14:16:32 -0400268 case GL_TEXTURE_CUBE_MAP:
Geoff Lang76b10c92014-09-05 16:28:14 -0400269 break;
Geoff Langb1196682014-07-23 13:47:29 -0400270
Geoff Langbfdea662014-07-23 14:16:32 -0400271 case GL_TEXTURE_3D:
Geoff Langbfdea662014-07-23 14:16:32 -0400272 case GL_TEXTURE_2D_ARRAY:
273 if (context->getClientVersion() < 3)
274 {
Geoff Langb1196682014-07-23 13:47:29 -0400275 context->recordError(gl::Error(GL_INVALID_ENUM));
276 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400277 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400278 break;
Geoff Langb1196682014-07-23 13:47:29 -0400279
Geoff Langbfdea662014-07-23 14:16:32 -0400280 default:
Geoff Langb1196682014-07-23 13:47:29 -0400281 context->recordError(gl::Error(GL_INVALID_ENUM));
282 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000283 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400284
285 context->bindTexture(target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000286 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287}
288
289void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000291 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000292 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000293
Geoff Langbfdea662014-07-23 14:16:32 -0400294 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000295
Geoff Langbfdea662014-07-23 14:16:32 -0400296 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000297 {
Geoff Langbfdea662014-07-23 14:16:32 -0400298 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000299 }
300}
301
302void __stdcall glBlendEquation(GLenum mode)
303{
304 glBlendEquationSeparate(mode, mode);
305}
306
307void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
308{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000309 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000310
Geoff Langbfdea662014-07-23 14:16:32 -0400311 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400312 if (context)
313 {
Geoff Langb1196682014-07-23 13:47:29 -0400314 switch (modeRGB)
315 {
316 case GL_FUNC_ADD:
317 case GL_FUNC_SUBTRACT:
318 case GL_FUNC_REVERSE_SUBTRACT:
319 case GL_MIN:
320 case GL_MAX:
321 break;
322
323 default:
324 context->recordError(gl::Error(GL_INVALID_ENUM));
325 return;
326 }
327
328 switch (modeAlpha)
329 {
330 case GL_FUNC_ADD:
331 case GL_FUNC_SUBTRACT:
332 case GL_FUNC_REVERSE_SUBTRACT:
333 case GL_MIN:
334 case GL_MAX:
335 break;
336
337 default:
338 context->recordError(gl::Error(GL_INVALID_ENUM));
339 return;
340 }
341
Geoff Langbfdea662014-07-23 14:16:32 -0400342 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000343 }
344}
345
346void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
347{
348 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
349}
350
351void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
352{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000353 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000354 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000355
Geoff Langbfdea662014-07-23 14:16:32 -0400356 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400357 if (context)
358 {
Geoff Langb1196682014-07-23 13:47:29 -0400359 switch (srcRGB)
360 {
361 case GL_ZERO:
362 case GL_ONE:
363 case GL_SRC_COLOR:
364 case GL_ONE_MINUS_SRC_COLOR:
365 case GL_DST_COLOR:
366 case GL_ONE_MINUS_DST_COLOR:
367 case GL_SRC_ALPHA:
368 case GL_ONE_MINUS_SRC_ALPHA:
369 case GL_DST_ALPHA:
370 case GL_ONE_MINUS_DST_ALPHA:
371 case GL_CONSTANT_COLOR:
372 case GL_ONE_MINUS_CONSTANT_COLOR:
373 case GL_CONSTANT_ALPHA:
374 case GL_ONE_MINUS_CONSTANT_ALPHA:
375 case GL_SRC_ALPHA_SATURATE:
376 break;
377
378 default:
379 context->recordError(gl::Error(GL_INVALID_ENUM));
380 return;
381 }
382
383 switch (dstRGB)
384 {
385 case GL_ZERO:
386 case GL_ONE:
387 case GL_SRC_COLOR:
388 case GL_ONE_MINUS_SRC_COLOR:
389 case GL_DST_COLOR:
390 case GL_ONE_MINUS_DST_COLOR:
391 case GL_SRC_ALPHA:
392 case GL_ONE_MINUS_SRC_ALPHA:
393 case GL_DST_ALPHA:
394 case GL_ONE_MINUS_DST_ALPHA:
395 case GL_CONSTANT_COLOR:
396 case GL_ONE_MINUS_CONSTANT_COLOR:
397 case GL_CONSTANT_ALPHA:
398 case GL_ONE_MINUS_CONSTANT_ALPHA:
399 break;
400
401 case GL_SRC_ALPHA_SATURATE:
402 if (context->getClientVersion() < 3)
403 {
404 context->recordError(gl::Error(GL_INVALID_ENUM));
405 return;
406 }
407 break;
408
409 default:
410 context->recordError(gl::Error(GL_INVALID_ENUM));
411 return;
412 }
413
414 switch (srcAlpha)
415 {
416 case GL_ZERO:
417 case GL_ONE:
418 case GL_SRC_COLOR:
419 case GL_ONE_MINUS_SRC_COLOR:
420 case GL_DST_COLOR:
421 case GL_ONE_MINUS_DST_COLOR:
422 case GL_SRC_ALPHA:
423 case GL_ONE_MINUS_SRC_ALPHA:
424 case GL_DST_ALPHA:
425 case GL_ONE_MINUS_DST_ALPHA:
426 case GL_CONSTANT_COLOR:
427 case GL_ONE_MINUS_CONSTANT_COLOR:
428 case GL_CONSTANT_ALPHA:
429 case GL_ONE_MINUS_CONSTANT_ALPHA:
430 case GL_SRC_ALPHA_SATURATE:
431 break;
432
433 default:
434 context->recordError(gl::Error(GL_INVALID_ENUM));
435 return;
436 }
437
438 switch (dstAlpha)
439 {
440 case GL_ZERO:
441 case GL_ONE:
442 case GL_SRC_COLOR:
443 case GL_ONE_MINUS_SRC_COLOR:
444 case GL_DST_COLOR:
445 case GL_ONE_MINUS_DST_COLOR:
446 case GL_SRC_ALPHA:
447 case GL_ONE_MINUS_SRC_ALPHA:
448 case GL_DST_ALPHA:
449 case GL_ONE_MINUS_DST_ALPHA:
450 case GL_CONSTANT_COLOR:
451 case GL_ONE_MINUS_CONSTANT_COLOR:
452 case GL_CONSTANT_ALPHA:
453 case GL_ONE_MINUS_CONSTANT_ALPHA:
454 break;
455
456 case GL_SRC_ALPHA_SATURATE:
457 if (context->getClientVersion() < 3)
458 {
459 context->recordError(gl::Error(GL_INVALID_ENUM));
460 return;
461 }
462 break;
463
464 default:
465 context->recordError(gl::Error(GL_INVALID_ENUM));
466 return;
467 }
468
469 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
470 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
471
472 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
473 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
474
475 if (constantColorUsed && constantAlphaUsed)
476 {
477 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
478 context->recordError(gl::Error(GL_INVALID_OPERATION));
479 return;
480 }
481
Geoff Langbfdea662014-07-23 14:16:32 -0400482 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000483 }
484}
485
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000486void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000487{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000488 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000489 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000490
Geoff Langbfdea662014-07-23 14:16:32 -0400491 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400492 if (context)
493 {
Geoff Langb1196682014-07-23 13:47:29 -0400494 if (size < 0)
495 {
496 context->recordError(gl::Error(GL_INVALID_VALUE));
497 return;
498 }
499
500 switch (usage)
501 {
502 case GL_STREAM_DRAW:
503 case GL_STATIC_DRAW:
504 case GL_DYNAMIC_DRAW:
505 break;
506
507 case GL_STREAM_READ:
508 case GL_STREAM_COPY:
509 case GL_STATIC_READ:
510 case GL_STATIC_COPY:
511 case GL_DYNAMIC_READ:
512 case GL_DYNAMIC_COPY:
513 if (context->getClientVersion() < 3)
514 {
515 context->recordError(gl::Error(GL_INVALID_ENUM));
516 return;
517 }
518 break;
519
520 default:
521 context->recordError(gl::Error(GL_INVALID_ENUM));
522 return;
523 }
524
Geoff Langbfdea662014-07-23 14:16:32 -0400525 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000526 {
Geoff Langb1196682014-07-23 13:47:29 -0400527 context->recordError(gl::Error(GL_INVALID_ENUM));
528 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000529 }
530
Geoff Langbfdea662014-07-23 14:16:32 -0400531 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
532
533 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000534 {
Geoff Langb1196682014-07-23 13:47:29 -0400535 context->recordError(gl::Error(GL_INVALID_OPERATION));
536 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000537 }
Geoff Langbfdea662014-07-23 14:16:32 -0400538
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400539 gl::Error error = buffer->bufferData(data, size, usage);
540 if (error.isError())
541 {
542 context->recordError(error);
543 return;
544 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000545 }
546}
547
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000548void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000549{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000550 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000551 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000552
Geoff Langbfdea662014-07-23 14:16:32 -0400553 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400554 if (context)
555 {
Geoff Langb1196682014-07-23 13:47:29 -0400556 if (size < 0 || offset < 0)
557 {
558 context->recordError(gl::Error(GL_INVALID_VALUE));
559 return;
560 }
561
562 if (data == NULL)
563 {
564 return;
565 }
566
Geoff Langbfdea662014-07-23 14:16:32 -0400567 if (!gl::ValidBufferTarget(context, target))
568 {
Geoff Langb1196682014-07-23 13:47:29 -0400569 context->recordError(gl::Error(GL_INVALID_ENUM));
570 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400571 }
572
573 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
574
575 if (!buffer)
576 {
Geoff Langb1196682014-07-23 13:47:29 -0400577 context->recordError(gl::Error(GL_INVALID_OPERATION));
578 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400579 }
580
581 if (buffer->isMapped())
582 {
Geoff Langb1196682014-07-23 13:47:29 -0400583 context->recordError(gl::Error(GL_INVALID_OPERATION));
584 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400585 }
586
587 // Check for possible overflow of size + offset
588 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
589 {
Geoff Langb1196682014-07-23 13:47:29 -0400590 context->recordError(gl::Error(GL_OUT_OF_MEMORY));
591 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400592 }
593
594 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000595 {
Geoff Langb1196682014-07-23 13:47:29 -0400596 context->recordError(gl::Error(GL_INVALID_VALUE));
597 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000598 }
599
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400600 gl::Error error = buffer->bufferSubData(data, size, offset);
601 if (error.isError())
602 {
603 context->recordError(error);
604 return;
605 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000606 }
607}
608
609GLenum __stdcall glCheckFramebufferStatus(GLenum target)
610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000611 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000612
Geoff Langbfdea662014-07-23 14:16:32 -0400613 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400614 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000615 {
Geoff Langb1196682014-07-23 13:47:29 -0400616 if (!gl::ValidFramebufferTarget(target))
617 {
618 context->recordError(gl::Error(GL_INVALID_ENUM));
619 return 0;
620 }
621
Geoff Langbfdea662014-07-23 14:16:32 -0400622 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
623 ASSERT(framebuffer);
624 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625 }
626
627 return 0;
628}
629
630void __stdcall glClear(GLbitfield mask)
631{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000632 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000633
Geoff Langbfdea662014-07-23 14:16:32 -0400634 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400635 if (context)
636 {
637 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
638
639 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000640 {
Geoff Langb1196682014-07-23 13:47:29 -0400641 context->recordError(gl::Error(GL_INVALID_FRAMEBUFFER_OPERATION));
642 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000643 }
Geoff Langbfdea662014-07-23 14:16:32 -0400644
645 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
646 {
Geoff Langb1196682014-07-23 13:47:29 -0400647 context->recordError(gl::Error(GL_INVALID_VALUE));
648 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400649 }
650
Geoff Langcc79b8c2014-07-25 13:48:02 -0400651 gl::Error error = context->clear(mask);
652 if (error.isError())
653 {
654 context->recordError(error);
655 return;
656 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000657 }
658}
659
660void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000662 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000663 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000664
Geoff Langbfdea662014-07-23 14:16:32 -0400665 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400666 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000667 {
Geoff Langbfdea662014-07-23 14:16:32 -0400668 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000669 }
670}
671
672void __stdcall glClearDepthf(GLclampf depth)
673{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000674 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000675
Geoff Langbfdea662014-07-23 14:16:32 -0400676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400677 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000678 {
Geoff Langbfdea662014-07-23 14:16:32 -0400679 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000680 }
681}
682
683void __stdcall glClearStencil(GLint s)
684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000685 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000686
Geoff Langbfdea662014-07-23 14:16:32 -0400687 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400688 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000689 {
Geoff Langbfdea662014-07-23 14:16:32 -0400690 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000691 }
692}
693
694void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
695{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000696 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000697 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000698
Geoff Langbfdea662014-07-23 14:16:32 -0400699 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400700 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000701 {
Geoff Langbfdea662014-07-23 14:16:32 -0400702 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000703 }
704}
705
706void __stdcall glCompileShader(GLuint shader)
707{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000708 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000709
Geoff Langbfdea662014-07-23 14:16:32 -0400710 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400711 if (context)
712 {
713 gl::Shader *shaderObject = context->getShader(shader);
714
715 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000716 {
Geoff Langbfdea662014-07-23 14:16:32 -0400717 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000718 {
Geoff Langb1196682014-07-23 13:47:29 -0400719 context->recordError(gl::Error(GL_INVALID_OPERATION));
720 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000721 }
Geoff Langbfdea662014-07-23 14:16:32 -0400722 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000723 {
Geoff Langb1196682014-07-23 13:47:29 -0400724 context->recordError(gl::Error(GL_INVALID_VALUE));
725 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000726 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000727 }
Geoff Langbfdea662014-07-23 14:16:32 -0400728
729 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000730 }
Geoff Langbfdea662014-07-23 14:16:32 -0400731}
732
733void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
734 GLint border, GLsizei imageSize, const GLvoid* data)
735{
736 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
737 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
738 target, level, internalformat, width, height, border, imageSize, data);
739
740 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400741 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000742 {
Geoff Langbfdea662014-07-23 14:16:32 -0400743 if (context->getClientVersion() < 3 &&
744 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
745 0, 0, width, height, border, GL_NONE, GL_NONE, data))
746 {
747 return;
748 }
749
750 if (context->getClientVersion() >= 3 &&
751 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
752 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
753 {
754 return;
755 }
756
Geoff Lang5d601382014-07-22 15:14:06 -0400757 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
758 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400759 {
Geoff Langb1196682014-07-23 13:47:29 -0400760 context->recordError(gl::Error(GL_INVALID_VALUE));
761 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400762 }
763
764 switch (target)
765 {
766 case GL_TEXTURE_2D:
767 {
768 gl::Texture2D *texture = context->getTexture2D();
Geoff Langb5348332014-09-02 13:16:34 -0400769 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
770 if (error.isError())
771 {
772 context->recordError(error);
773 return;
774 }
Geoff Langbfdea662014-07-23 14:16:32 -0400775 }
776 break;
777
778 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
779 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
780 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
781 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
782 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
783 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
784 {
785 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Langb5348332014-09-02 13:16:34 -0400786 gl::Error error = texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
787 if (error.isError())
788 {
789 context->recordError(error);
790 return;
791 }
Geoff Langbfdea662014-07-23 14:16:32 -0400792 }
793 break;
794
795 default:
Geoff Langb1196682014-07-23 13:47:29 -0400796 context->recordError(gl::Error(GL_INVALID_ENUM));
797 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400798 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000799 }
800}
801
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000802void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
803 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000804{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000805 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000806 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000807 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000808 target, level, xoffset, yoffset, width, height, format, imageSize, data);
809
Geoff Langbfdea662014-07-23 14:16:32 -0400810 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400811 if (context)
812 {
813 if (context->getClientVersion() < 3 &&
814 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
815 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000816 {
Geoff Langbfdea662014-07-23 14:16:32 -0400817 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000818 }
Geoff Langbfdea662014-07-23 14:16:32 -0400819
820 if (context->getClientVersion() >= 3 &&
821 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
822 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
823 {
824 return;
825 }
826
Geoff Lang5d601382014-07-22 15:14:06 -0400827 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
828 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400829 {
Geoff Langb1196682014-07-23 13:47:29 -0400830 context->recordError(gl::Error(GL_INVALID_VALUE));
831 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400832 }
833
834 switch (target)
835 {
836 case GL_TEXTURE_2D:
837 {
838 gl::Texture2D *texture = context->getTexture2D();
Geoff Langb5348332014-09-02 13:16:34 -0400839 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
840 if (error.isError())
841 {
842 context->recordError(error);
843 return;
844 }
Geoff Langbfdea662014-07-23 14:16:32 -0400845 }
846 break;
847
848 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
852 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
853 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
854 {
855 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Langb5348332014-09-02 13:16:34 -0400856 gl::Error error = texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
857 if (error.isError())
858 {
859 context->recordError(error);
860 return;
861 }
Geoff Langbfdea662014-07-23 14:16:32 -0400862 }
863 break;
864
865 default:
Geoff Langb1196682014-07-23 13:47:29 -0400866 context->recordError(gl::Error(GL_INVALID_ENUM));
867 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400868 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000869 }
870}
871
872void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
873{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000874 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000875 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000876 target, level, internalformat, x, y, width, height, border);
877
Geoff Langbfdea662014-07-23 14:16:32 -0400878 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400879 if (context)
880 {
881 if (context->getClientVersion() < 3 &&
882 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
883 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000884 {
Geoff Langbfdea662014-07-23 14:16:32 -0400885 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000886 }
Geoff Langbfdea662014-07-23 14:16:32 -0400887
888 if (context->getClientVersion() >= 3 &&
889 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
890 0, 0, 0, x, y, width, height, border))
891 {
892 return;
893 }
894
895 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
896
897 switch (target)
898 {
899 case GL_TEXTURE_2D:
900 {
901 gl::Texture2D *texture = context->getTexture2D();
902 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
903 }
904 break;
905
906 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
907 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
908 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
909 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
910 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
911 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
912 {
913 gl::TextureCubeMap *texture = context->getTextureCubeMap();
914 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
915 }
916 break;
917
Geoff Langb1196682014-07-23 13:47:29 -0400918 default:
919 context->recordError(gl::Error(GL_INVALID_ENUM));
920 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400921 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000922 }
923}
924
925void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
926{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000927 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000928 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000929 target, level, xoffset, yoffset, x, y, width, height);
930
Geoff Langbfdea662014-07-23 14:16:32 -0400931 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400932 if (context)
933 {
934 if (context->getClientVersion() < 3 &&
935 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
936 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000937 {
Geoff Langbfdea662014-07-23 14:16:32 -0400938 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000939 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000940
Geoff Langbfdea662014-07-23 14:16:32 -0400941 if (context->getClientVersion() >= 3 &&
942 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
943 xoffset, yoffset, 0, x, y, width, height, 0))
944 {
945 return;
946 }
947
948 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
949
950 switch (target)
951 {
952 case GL_TEXTURE_2D:
953 {
954 gl::Texture2D *texture = context->getTexture2D();
955 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
956 }
957 break;
958
959 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
961 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
962 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
963 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
964 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
965 {
966 gl::TextureCubeMap *texture = context->getTextureCubeMap();
967 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
968 }
969 break;
970
971 default:
Geoff Langb1196682014-07-23 13:47:29 -0400972 context->recordError(gl::Error(GL_INVALID_ENUM));
973 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400974 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000975 }
976}
977
978GLuint __stdcall glCreateProgram(void)
979{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000980 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000981
Geoff Langbfdea662014-07-23 14:16:32 -0400982 gl::Context *context = gl::getNonLostContext();
983 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000984 {
Geoff Langbfdea662014-07-23 14:16:32 -0400985 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000986 }
987
988 return 0;
989}
990
991GLuint __stdcall glCreateShader(GLenum type)
992{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000993 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000994
Geoff Langbfdea662014-07-23 14:16:32 -0400995 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400996 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000997 {
Geoff Langbfdea662014-07-23 14:16:32 -0400998 switch (type)
999 {
1000 case GL_FRAGMENT_SHADER:
1001 case GL_VERTEX_SHADER:
1002 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -04001003
Geoff Langbfdea662014-07-23 14:16:32 -04001004 default:
Geoff Langb1196682014-07-23 13:47:29 -04001005 context->recordError(gl::Error(GL_INVALID_ENUM));
1006 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04001007 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001008 }
1009
1010 return 0;
1011}
1012
1013void __stdcall glCullFace(GLenum mode)
1014{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001015 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001016
Geoff Langb1196682014-07-23 13:47:29 -04001017 gl::Context *context = gl::getNonLostContext();
1018 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001019 {
Geoff Langb1196682014-07-23 13:47:29 -04001020 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001021 {
Geoff Langb1196682014-07-23 13:47:29 -04001022 case GL_FRONT:
1023 case GL_BACK:
1024 case GL_FRONT_AND_BACK:
1025 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001026
Geoff Langb1196682014-07-23 13:47:29 -04001027 default:
1028 context->recordError(gl::Error(GL_INVALID_ENUM));
1029 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001030 }
Geoff Langb1196682014-07-23 13:47:29 -04001031
1032 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001033 }
1034}
1035
1036void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
1037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001038 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001039
Geoff Langbfdea662014-07-23 14:16:32 -04001040 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001041 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001042 {
Geoff Langb1196682014-07-23 13:47:29 -04001043 if (n < 0)
1044 {
1045 context->recordError(gl::Error(GL_INVALID_VALUE));
1046 return;
1047 }
1048
Geoff Langbfdea662014-07-23 14:16:32 -04001049 for (int i = 0; i < n; i++)
1050 {
1051 context->deleteBuffer(buffers[i]);
1052 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001053 }
1054}
1055
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001056void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
1057{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001058 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001059
Geoff Langbfdea662014-07-23 14:16:32 -04001060 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001061 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001062 {
Geoff Langb1196682014-07-23 13:47:29 -04001063 if (n < 0)
1064 {
1065 context->recordError(gl::Error(GL_INVALID_VALUE));
1066 return;
1067 }
1068
Geoff Langbfdea662014-07-23 14:16:32 -04001069 for (int i = 0; i < n; i++)
1070 {
1071 context->deleteFenceNV(fences[i]);
1072 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001073 }
1074}
1075
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001076void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1077{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001078 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001079
Geoff Langbfdea662014-07-23 14:16:32 -04001080 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001081 if (context)
1082 {
Geoff Langb1196682014-07-23 13:47:29 -04001083 if (n < 0)
1084 {
1085 context->recordError(gl::Error(GL_INVALID_VALUE));
1086 return;
1087 }
1088
Geoff Langbfdea662014-07-23 14:16:32 -04001089 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001090 {
Geoff Langbfdea662014-07-23 14:16:32 -04001091 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001092 {
Geoff Langbfdea662014-07-23 14:16:32 -04001093 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001094 }
1095 }
1096 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001097}
1098
1099void __stdcall glDeleteProgram(GLuint program)
1100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001101 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001102
Geoff Langbfdea662014-07-23 14:16:32 -04001103 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001104 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001105 {
Geoff Langb1196682014-07-23 13:47:29 -04001106 if (program == 0)
1107 {
1108 return;
1109 }
1110
Geoff Langbfdea662014-07-23 14:16:32 -04001111 if (!context->getProgram(program))
1112 {
1113 if(context->getShader(program))
1114 {
Geoff Langb1196682014-07-23 13:47:29 -04001115 context->recordError(gl::Error(GL_INVALID_OPERATION));
1116 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001117 }
1118 else
1119 {
Geoff Langb1196682014-07-23 13:47:29 -04001120 context->recordError(gl::Error(GL_INVALID_VALUE));
1121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001122 }
1123 }
1124
1125 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001126 }
1127}
1128
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001129void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1130{
1131 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1132
Geoff Langbfdea662014-07-23 14:16:32 -04001133 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001134 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001135 {
Geoff Langb1196682014-07-23 13:47:29 -04001136 if (n < 0)
1137 {
1138 context->recordError(gl::Error(GL_INVALID_VALUE));
1139 return;
1140 }
1141
Geoff Langbfdea662014-07-23 14:16:32 -04001142 for (int i = 0; i < n; i++)
1143 {
1144 context->deleteQuery(ids[i]);
1145 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001146 }
1147}
1148
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001149void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1150{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001151 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001152
Geoff Langbfdea662014-07-23 14:16:32 -04001153 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001154 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001155 {
Geoff Langb1196682014-07-23 13:47:29 -04001156 if (n < 0)
1157 {
1158 context->recordError(gl::Error(GL_INVALID_VALUE));
1159 return;
1160 }
1161
Geoff Langbfdea662014-07-23 14:16:32 -04001162 for (int i = 0; i < n; i++)
1163 {
1164 context->deleteRenderbuffer(renderbuffers[i]);
1165 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001166 }
1167}
1168
1169void __stdcall glDeleteShader(GLuint shader)
1170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001171 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001172
Geoff Langbfdea662014-07-23 14:16:32 -04001173 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001174 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001175 {
Geoff Langb1196682014-07-23 13:47:29 -04001176 if (shader == 0)
1177 {
1178 return;
1179 }
1180
Geoff Langbfdea662014-07-23 14:16:32 -04001181 if (!context->getShader(shader))
1182 {
1183 if(context->getProgram(shader))
1184 {
Geoff Langb1196682014-07-23 13:47:29 -04001185 context->recordError(gl::Error(GL_INVALID_OPERATION));
1186 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001187 }
1188 else
1189 {
Geoff Langb1196682014-07-23 13:47:29 -04001190 context->recordError(gl::Error(GL_INVALID_VALUE));
1191 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001192 }
1193 }
1194
1195 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001196 }
1197}
1198
1199void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1200{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001201 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001202
Geoff Langbfdea662014-07-23 14:16:32 -04001203 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001204 if (context)
1205 {
Geoff Langb1196682014-07-23 13:47:29 -04001206 if (n < 0)
1207 {
1208 context->recordError(gl::Error(GL_INVALID_VALUE));
1209 return;
1210 }
1211
Geoff Langbfdea662014-07-23 14:16:32 -04001212 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001213 {
Geoff Langbfdea662014-07-23 14:16:32 -04001214 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001215 {
Geoff Langbfdea662014-07-23 14:16:32 -04001216 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001217 }
1218 }
1219 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001220}
1221
1222void __stdcall glDepthFunc(GLenum func)
1223{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001224 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001225
Geoff Langbfdea662014-07-23 14:16:32 -04001226 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001227 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001228 {
Geoff Langb1196682014-07-23 13:47:29 -04001229 switch (func)
1230 {
1231 case GL_NEVER:
1232 case GL_ALWAYS:
1233 case GL_LESS:
1234 case GL_LEQUAL:
1235 case GL_EQUAL:
1236 case GL_GREATER:
1237 case GL_GEQUAL:
1238 case GL_NOTEQUAL:
1239 context->getState().setDepthFunc(func);
1240 break;
1241
1242 default:
1243 context->recordError(gl::Error(GL_INVALID_ENUM));
1244 return;
1245 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001246 }
1247}
1248
1249void __stdcall glDepthMask(GLboolean flag)
1250{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001251 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001252
Geoff Langbfdea662014-07-23 14:16:32 -04001253 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001254 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001255 {
Geoff Langbfdea662014-07-23 14:16:32 -04001256 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001257 }
1258}
1259
1260void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1261{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001262 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001263
Geoff Langbfdea662014-07-23 14:16:32 -04001264 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001265 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266 {
Geoff Langbfdea662014-07-23 14:16:32 -04001267 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001268 }
1269}
1270
1271void __stdcall glDetachShader(GLuint program, GLuint shader)
1272{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001273 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001274
Geoff Langbfdea662014-07-23 14:16:32 -04001275 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001276 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277 {
Geoff Langbfdea662014-07-23 14:16:32 -04001278 gl::Program *programObject = context->getProgram(program);
1279 gl::Shader *shaderObject = context->getShader(shader);
1280
1281 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001282 {
Geoff Langbfdea662014-07-23 14:16:32 -04001283 gl::Shader *shaderByProgramHandle;
1284 shaderByProgramHandle = context->getShader(program);
1285 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001286 {
Geoff Langb1196682014-07-23 13:47:29 -04001287 context->recordError(gl::Error(GL_INVALID_VALUE));
1288 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001289 }
Geoff Langbfdea662014-07-23 14:16:32 -04001290 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001291 {
Geoff Langb1196682014-07-23 13:47:29 -04001292 context->recordError(gl::Error(GL_INVALID_OPERATION));
1293 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001294 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001295 }
Geoff Langbfdea662014-07-23 14:16:32 -04001296
1297 if (!shaderObject)
1298 {
1299 gl::Program *programByShaderHandle = context->getProgram(shader);
1300 if (!programByShaderHandle)
1301 {
Geoff Langb1196682014-07-23 13:47:29 -04001302 context->recordError(gl::Error(GL_INVALID_VALUE));
1303 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001304 }
1305 else
1306 {
Geoff Langb1196682014-07-23 13:47:29 -04001307 context->recordError(gl::Error(GL_INVALID_OPERATION));
1308 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001309 }
1310 }
1311
1312 if (!programObject->detachShader(shaderObject))
1313 {
Geoff Langb1196682014-07-23 13:47:29 -04001314 context->recordError(gl::Error(GL_INVALID_OPERATION));
1315 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001317 }
1318}
1319
1320void __stdcall glDisable(GLenum cap)
1321{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001322 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001323
Geoff Langbfdea662014-07-23 14:16:32 -04001324 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001325 if (context)
1326 {
1327 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001328 {
Geoff Langb1196682014-07-23 13:47:29 -04001329 context->recordError(gl::Error(GL_INVALID_ENUM));
1330 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001331 }
Geoff Langbfdea662014-07-23 14:16:32 -04001332
1333 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001334 }
1335}
1336
1337void __stdcall glDisableVertexAttribArray(GLuint index)
1338{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001339 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001340
Geoff Langbfdea662014-07-23 14:16:32 -04001341 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001342 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001343 {
Geoff Langb1196682014-07-23 13:47:29 -04001344 if (index >= gl::MAX_VERTEX_ATTRIBS)
1345 {
1346 context->recordError(gl::Error(GL_INVALID_VALUE));
1347 return;
1348 }
1349
Geoff Langbfdea662014-07-23 14:16:32 -04001350 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001351 }
1352}
1353
1354void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1355{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001356 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001357
Geoff Langbfdea662014-07-23 14:16:32 -04001358 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001359 if (context)
1360 {
Jamie Madill2b976812014-08-25 15:47:49 -04001361 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001362 {
Geoff Langbfdea662014-07-23 14:16:32 -04001363 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001364 }
Geoff Langbfdea662014-07-23 14:16:32 -04001365
Geoff Langc77e8c32014-09-08 16:28:24 -04001366 gl::Error error = context->drawArrays(mode, first, count, 0);
1367 if (error.isError())
1368 {
1369 context->recordError(error);
1370 return;
1371 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001372 }
1373}
1374
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001375void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1376{
1377 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1378
Geoff Langbfdea662014-07-23 14:16:32 -04001379 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001380 if (context)
1381 {
Geoff Lang87a93302014-09-16 13:29:43 -04001382 if (!ValidateDrawArraysInstancedANGLE(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001383 {
Geoff Langbfdea662014-07-23 14:16:32 -04001384 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001385 }
Geoff Langbfdea662014-07-23 14:16:32 -04001386
Geoff Langc77e8c32014-09-08 16:28:24 -04001387 gl::Error error = context->drawArrays(mode, first, count, primcount);
1388 if (error.isError())
1389 {
1390 context->recordError(error);
1391 return;
1392 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001393 }
1394}
1395
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001396void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001397{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001398 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001399 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001400
Geoff Langbfdea662014-07-23 14:16:32 -04001401 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001402 if (context)
1403 {
Jamie Madill2b976812014-08-25 15:47:49 -04001404 rx::RangeUI indexRange;
1405 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001406 {
Geoff Langbfdea662014-07-23 14:16:32 -04001407 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001408 }
Geoff Langbfdea662014-07-23 14:16:32 -04001409
Geoff Langc77e8c32014-09-08 16:28:24 -04001410 gl::Error error = context->drawElements(mode, count, type, indices, 0, indexRange);
1411 if (error.isError())
1412 {
1413 context->recordError(error);
1414 return;
1415 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001416 }
1417}
1418
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001419void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1420{
1421 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1422 mode, count, type, indices, primcount);
1423
Geoff Langbfdea662014-07-23 14:16:32 -04001424 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001425 if (context)
1426 {
Jamie Madill2b976812014-08-25 15:47:49 -04001427 rx::RangeUI indexRange;
Geoff Lang87a93302014-09-16 13:29:43 -04001428 if (!ValidateDrawElementsInstancedANGLE(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001429 {
Geoff Langbfdea662014-07-23 14:16:32 -04001430 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001431 }
Geoff Langbfdea662014-07-23 14:16:32 -04001432
Geoff Langc77e8c32014-09-08 16:28:24 -04001433 gl::Error error = context->drawElements(mode, count, type, indices, primcount, indexRange);
1434 if (error.isError())
1435 {
1436 context->recordError(error);
1437 return;
1438 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001439 }
1440}
1441
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001442void __stdcall glEnable(GLenum cap)
1443{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001444 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001445
Geoff Langbfdea662014-07-23 14:16:32 -04001446 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001447 if (context)
1448 {
1449 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001450 {
Geoff Langb1196682014-07-23 13:47:29 -04001451 context->recordError(gl::Error(GL_INVALID_ENUM));
1452 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453 }
Geoff Langbfdea662014-07-23 14:16:32 -04001454
1455 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001456 }
1457}
1458
1459void __stdcall glEnableVertexAttribArray(GLuint index)
1460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001461 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001462
Geoff Langbfdea662014-07-23 14:16:32 -04001463 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001464 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001465 {
Geoff Langb1196682014-07-23 13:47:29 -04001466 if (index >= gl::MAX_VERTEX_ATTRIBS)
1467 {
1468 context->recordError(gl::Error(GL_INVALID_VALUE));
1469 return;
1470 }
1471
Geoff Langbfdea662014-07-23 14:16:32 -04001472 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001473 }
1474}
1475
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001476void __stdcall glEndQueryEXT(GLenum target)
1477{
1478 EVENT("GLenum target = 0x%X)", target);
1479
Geoff Langbfdea662014-07-23 14:16:32 -04001480 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001481 if (context)
1482 {
1483 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001484 {
Geoff Langbfdea662014-07-23 14:16:32 -04001485 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001486 }
Geoff Langbfdea662014-07-23 14:16:32 -04001487
Geoff Lang5aad9672014-09-08 11:10:42 -04001488 gl::Error error = context->endQuery(target);
1489 if (error.isError())
1490 {
1491 context->recordError(error);
1492 return;
1493 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001494 }
1495}
1496
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001497void __stdcall glFinishFenceNV(GLuint fence)
1498{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001499 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001500
Geoff Langbfdea662014-07-23 14:16:32 -04001501 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001502 if (context)
1503 {
1504 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1505
1506 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001507 {
Geoff Langb1196682014-07-23 13:47:29 -04001508 context->recordError(gl::Error(GL_INVALID_OPERATION));
1509 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001510 }
Geoff Langbfdea662014-07-23 14:16:32 -04001511
1512 if (fenceObject->isFence() != GL_TRUE)
1513 {
Geoff Langb1196682014-07-23 13:47:29 -04001514 context->recordError(gl::Error(GL_INVALID_OPERATION));
1515 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001516 }
1517
1518 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001519 }
1520}
1521
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001522void __stdcall glFinish(void)
1523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001524 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001525
Geoff Langbfdea662014-07-23 14:16:32 -04001526 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001527 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001528 {
Geoff Langbfdea662014-07-23 14:16:32 -04001529 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001530 }
1531}
1532
1533void __stdcall glFlush(void)
1534{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001535 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001536
Geoff Langbfdea662014-07-23 14:16:32 -04001537 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001538 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001539 {
Geoff Langbfdea662014-07-23 14:16:32 -04001540 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001541 }
1542}
1543
1544void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1545{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001546 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001547 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001548
Geoff Langbfdea662014-07-23 14:16:32 -04001549 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001550 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001551 {
Geoff Langb1196682014-07-23 13:47:29 -04001552 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1553 {
1554 context->recordError(gl::Error(GL_INVALID_ENUM));
1555 return;
1556 }
1557
Geoff Langbfdea662014-07-23 14:16:32 -04001558 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1559 {
1560 return;
1561 }
1562
1563 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1564 ASSERT(framebuffer);
1565
1566 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1567 {
1568 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1569 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1570 }
1571 else
1572 {
1573 switch (attachment)
1574 {
1575 case GL_DEPTH_ATTACHMENT:
1576 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1577 break;
1578 case GL_STENCIL_ATTACHMENT:
1579 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1580 break;
1581 case GL_DEPTH_STENCIL_ATTACHMENT:
1582 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1583 break;
1584 default:
1585 UNREACHABLE();
1586 break;
1587 }
1588 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001589 }
1590}
1591
1592void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1593{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001594 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001595 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001596
Geoff Langbfdea662014-07-23 14:16:32 -04001597 gl::Context *context = gl::getNonLostContext();
1598 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001599 {
Geoff Langbfdea662014-07-23 14:16:32 -04001600 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001601 {
Geoff Langbfdea662014-07-23 14:16:32 -04001602 return;
1603 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001604
Geoff Langbfdea662014-07-23 14:16:32 -04001605 if (texture == 0)
1606 {
1607 textarget = GL_NONE;
1608 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001609
Geoff Langbfdea662014-07-23 14:16:32 -04001610 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001611
Geoff Langbfdea662014-07-23 14:16:32 -04001612 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1613 {
1614 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1615 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1616 }
1617 else
1618 {
1619 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001620 {
Geoff Langbfdea662014-07-23 14:16:32 -04001621 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1622 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1623 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001624 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001625 }
1626 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001627}
1628
1629void __stdcall glFrontFace(GLenum mode)
1630{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001631 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001632
Geoff Langb1196682014-07-23 13:47:29 -04001633 gl::Context *context = gl::getNonLostContext();
1634 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001635 {
Geoff Langb1196682014-07-23 13:47:29 -04001636 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001637 {
Geoff Langb1196682014-07-23 13:47:29 -04001638 case GL_CW:
1639 case GL_CCW:
1640 context->getState().setFrontFace(mode);
1641 break;
1642 default:
1643 context->recordError(gl::Error(GL_INVALID_ENUM));
1644 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001645 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001646 }
1647}
1648
1649void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1650{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001651 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001652
Geoff Langbfdea662014-07-23 14:16:32 -04001653 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001654 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001655 {
Geoff Langb1196682014-07-23 13:47:29 -04001656 if (n < 0)
1657 {
1658 context->recordError(gl::Error(GL_INVALID_VALUE));
1659 return;
1660 }
1661
Geoff Langbfdea662014-07-23 14:16:32 -04001662 for (int i = 0; i < n; i++)
1663 {
1664 buffers[i] = context->createBuffer();
1665 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001666 }
1667}
1668
1669void __stdcall glGenerateMipmap(GLenum target)
1670{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001671 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001672
Geoff Langbfdea662014-07-23 14:16:32 -04001673 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001674 if (context)
1675 {
1676 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001677 {
Geoff Langb1196682014-07-23 13:47:29 -04001678 context->recordError(gl::Error(GL_INVALID_ENUM));
1679 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001680 }
Geoff Langbfdea662014-07-23 14:16:32 -04001681
1682 gl::Texture *texture = context->getTargetTexture(target);
1683
1684 if (texture == NULL)
1685 {
Geoff Langb1196682014-07-23 13:47:29 -04001686 context->recordError(gl::Error(GL_INVALID_OPERATION));
1687 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001688 }
1689
1690 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1691 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001692 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001693
1694 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1695 // unsized formats or that are color renderable and filterable. Since we do not track if
1696 // the texture was created with sized or unsized format (only sized formats are stored),
1697 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1698 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1699 // textures since they're the only texture format that can be created with unsized formats
1700 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1701 // was the last version to use add them.
1702 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1703 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1704 internalFormat == GL_ALPHA8_EXT;
1705
Geoff Lang5d601382014-07-22 15:14:06 -04001706 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1707 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001708 {
Geoff Langb1196682014-07-23 13:47:29 -04001709 context->recordError(gl::Error(GL_INVALID_OPERATION));
1710 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001711 }
1712
1713 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001714 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001715 {
Geoff Langb1196682014-07-23 13:47:29 -04001716 context->recordError(gl::Error(GL_INVALID_OPERATION));
1717 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001718 }
1719
1720 // Non-power of 2 ES2 check
1721 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1722 {
1723 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001724 context->recordError(gl::Error(GL_INVALID_OPERATION));
1725 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001726 }
1727
1728 // Cube completeness check
1729 if (target == GL_TEXTURE_CUBE_MAP)
1730 {
1731 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1732 if (!textureCube->isCubeComplete())
1733 {
Geoff Langb1196682014-07-23 13:47:29 -04001734 context->recordError(gl::Error(GL_INVALID_OPERATION));
1735 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001736 }
1737 }
1738
1739 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001740 }
1741}
1742
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001743void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1744{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001745 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001746
Geoff Langbfdea662014-07-23 14:16:32 -04001747 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001748 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001749 {
Geoff Langb1196682014-07-23 13:47:29 -04001750 if (n < 0)
1751 {
1752 context->recordError(gl::Error(GL_INVALID_VALUE));
1753 return;
1754 }
1755
Geoff Langbfdea662014-07-23 14:16:32 -04001756 for (int i = 0; i < n; i++)
1757 {
1758 fences[i] = context->createFenceNV();
1759 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001760 }
1761}
1762
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001763void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1764{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001765 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001766
Geoff Langbfdea662014-07-23 14:16:32 -04001767 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001768 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001769 {
Geoff Langb1196682014-07-23 13:47:29 -04001770 if (n < 0)
1771 {
1772 context->recordError(gl::Error(GL_INVALID_VALUE));
1773 return;
1774 }
1775
Geoff Langbfdea662014-07-23 14:16:32 -04001776 for (int i = 0; i < n; i++)
1777 {
1778 framebuffers[i] = context->createFramebuffer();
1779 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001780 }
1781}
1782
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001783void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1784{
1785 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1786
Geoff Langbfdea662014-07-23 14:16:32 -04001787 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001788 if (context)
1789 {
1790 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001791 {
Geoff Langb1196682014-07-23 13:47:29 -04001792 context->recordError(gl::Error(GL_INVALID_VALUE));
1793 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001794 }
Geoff Langbfdea662014-07-23 14:16:32 -04001795
1796 for (GLsizei i = 0; i < n; i++)
1797 {
1798 ids[i] = context->createQuery();
1799 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001800 }
1801}
1802
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001803void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1804{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001805 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001806
Geoff Langbfdea662014-07-23 14:16:32 -04001807 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001808 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001809 {
Geoff Langb1196682014-07-23 13:47:29 -04001810 if (n < 0)
1811 {
1812 context->recordError(gl::Error(GL_INVALID_VALUE));
1813 return;
1814 }
1815
Geoff Langbfdea662014-07-23 14:16:32 -04001816 for (int i = 0; i < n; i++)
1817 {
1818 renderbuffers[i] = context->createRenderbuffer();
1819 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001820 }
1821}
1822
1823void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1824{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001825 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001826
Geoff Langbfdea662014-07-23 14:16:32 -04001827 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001828 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001829 {
Geoff Langb1196682014-07-23 13:47:29 -04001830 if (n < 0)
1831 {
1832 context->recordError(gl::Error(GL_INVALID_VALUE));
1833 return;
1834 }
1835
Geoff Langbfdea662014-07-23 14:16:32 -04001836 for (int i = 0; i < n; i++)
1837 {
1838 textures[i] = context->createTexture();
1839 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001840 }
1841}
1842
daniel@transgaming.com85423182010-04-22 13:35:27 +00001843void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001845 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001846 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001847 program, index, bufsize, length, size, type, name);
1848
Geoff Langbfdea662014-07-23 14:16:32 -04001849 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001850 if (context)
1851 {
Geoff Langb1196682014-07-23 13:47:29 -04001852 if (bufsize < 0)
1853 {
1854 context->recordError(gl::Error(GL_INVALID_VALUE));
1855 return;
1856 }
1857
Geoff Langbfdea662014-07-23 14:16:32 -04001858 gl::Program *programObject = context->getProgram(program);
1859
1860 if (!programObject)
1861 {
1862 if (context->getShader(program))
1863 {
Geoff Langb1196682014-07-23 13:47:29 -04001864 context->recordError(gl::Error(GL_INVALID_OPERATION));
1865 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001866 }
1867 else
1868 {
Geoff Langb1196682014-07-23 13:47:29 -04001869 context->recordError(gl::Error(GL_INVALID_VALUE));
1870 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001871 }
1872 }
1873
1874 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001875 {
Geoff Langb1196682014-07-23 13:47:29 -04001876 context->recordError(gl::Error(GL_INVALID_VALUE));
1877 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001878 }
1879
Geoff Langbfdea662014-07-23 14:16:32 -04001880 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001881 }
1882}
1883
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001884void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001885{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001886 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001887 "GLsizei* length = 0x%0.8p, GLint* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001888 program, index, bufsize, length, size, type, name);
1889
Geoff Langbfdea662014-07-23 14:16:32 -04001890
1891 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001892 if (context)
1893 {
Geoff Langb1196682014-07-23 13:47:29 -04001894 if (bufsize < 0)
1895 {
1896 context->recordError(gl::Error(GL_INVALID_VALUE));
1897 return;
1898 }
1899
Geoff Langbfdea662014-07-23 14:16:32 -04001900 gl::Program *programObject = context->getProgram(program);
1901
1902 if (!programObject)
1903 {
1904 if (context->getShader(program))
1905 {
Geoff Langb1196682014-07-23 13:47:29 -04001906 context->recordError(gl::Error(GL_INVALID_OPERATION));
1907 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001908 }
1909 else
1910 {
Geoff Langb1196682014-07-23 13:47:29 -04001911 context->recordError(gl::Error(GL_INVALID_VALUE));
1912 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001913 }
1914 }
1915
1916 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001917 {
Geoff Langb1196682014-07-23 13:47:29 -04001918 context->recordError(gl::Error(GL_INVALID_VALUE));
1919 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001920 }
1921
Geoff Langbfdea662014-07-23 14:16:32 -04001922 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001923 }
1924}
1925
1926void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1927{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001928 EVENT("(GLuint program = %d, GLsizei maxcount = %d, GLsizei* count = 0x%0.8p, GLuint* shaders = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001929 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001930
Geoff Langbfdea662014-07-23 14:16:32 -04001931 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001932 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001933 {
Geoff Langb1196682014-07-23 13:47:29 -04001934 if (maxcount < 0)
1935 {
1936 context->recordError(gl::Error(GL_INVALID_VALUE));
1937 return;
1938 }
1939
Geoff Langbfdea662014-07-23 14:16:32 -04001940 gl::Program *programObject = context->getProgram(program);
1941
1942 if (!programObject)
1943 {
1944 if (context->getShader(program))
1945 {
Geoff Langb1196682014-07-23 13:47:29 -04001946 context->recordError(gl::Error(GL_INVALID_OPERATION));
1947 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001948 }
1949 else
1950 {
Geoff Langb1196682014-07-23 13:47:29 -04001951 context->recordError(gl::Error(GL_INVALID_VALUE));
1952 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001953 }
1954 }
1955
1956 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001957 }
1958}
1959
Geoff Langb1196682014-07-23 13:47:29 -04001960GLint __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001961{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001962 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001963
Geoff Langbfdea662014-07-23 14:16:32 -04001964 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001965 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001966 {
Geoff Langbfdea662014-07-23 14:16:32 -04001967 gl::Program *programObject = context->getProgram(program);
1968
1969 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001970 {
Geoff Langbfdea662014-07-23 14:16:32 -04001971 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001972 {
Geoff Langb1196682014-07-23 13:47:29 -04001973 context->recordError(gl::Error(GL_INVALID_OPERATION));
1974 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001975 }
Geoff Langbfdea662014-07-23 14:16:32 -04001976 else
1977 {
Geoff Langb1196682014-07-23 13:47:29 -04001978 context->recordError(gl::Error(GL_INVALID_VALUE));
1979 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001980 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001981 }
Geoff Langbfdea662014-07-23 14:16:32 -04001982
1983 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1984 if (!programObject->isLinked() || !programBinary)
1985 {
Geoff Langb1196682014-07-23 13:47:29 -04001986 context->recordError(gl::Error(GL_INVALID_OPERATION));
1987 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001988 }
1989
1990 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001991 }
1992
1993 return -1;
1994}
1995
1996void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1997{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001998 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001999
Geoff Langbfdea662014-07-23 14:16:32 -04002000 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002001 if (context)
2002 {
2003 GLenum nativeType;
2004 unsigned int numParams = 0;
2005 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002006 {
Geoff Langbfdea662014-07-23 14:16:32 -04002007 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002008 }
Geoff Langbfdea662014-07-23 14:16:32 -04002009
2010 if (nativeType == GL_BOOL)
2011 {
2012 context->getBooleanv(pname, params);
2013 }
2014 else
2015 {
2016 CastStateValues(context, nativeType, pname, numParams, params);
2017 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002018 }
2019}
2020
2021void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
2022{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002023 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002024
Geoff Langbfdea662014-07-23 14:16:32 -04002025 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002026 if (context)
2027 {
2028 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002029 {
Geoff Langb1196682014-07-23 13:47:29 -04002030 context->recordError(gl::Error(GL_INVALID_ENUM));
2031 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002032 }
Geoff Langbfdea662014-07-23 14:16:32 -04002033
2034 if (!gl::ValidBufferParameter(context, pname))
2035 {
Geoff Langb1196682014-07-23 13:47:29 -04002036 context->recordError(gl::Error(GL_INVALID_ENUM));
2037 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002038 }
2039
2040 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
2041
2042 if (!buffer)
2043 {
2044 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04002045 context->recordError(gl::Error(GL_INVALID_OPERATION));
2046 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002047 }
2048
2049 switch (pname)
2050 {
2051 case GL_BUFFER_USAGE:
2052 *params = static_cast<GLint>(buffer->getUsage());
2053 break;
2054 case GL_BUFFER_SIZE:
2055 *params = gl::clampCast<GLint>(buffer->getSize());
2056 break;
2057 case GL_BUFFER_ACCESS_FLAGS:
2058 *params = buffer->getAccessFlags();
2059 break;
2060 case GL_BUFFER_MAPPED:
2061 *params = static_cast<GLint>(buffer->isMapped());
2062 break;
2063 case GL_BUFFER_MAP_OFFSET:
2064 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2065 break;
2066 case GL_BUFFER_MAP_LENGTH:
2067 *params = gl::clampCast<GLint>(buffer->getMapLength());
2068 break;
2069 default: UNREACHABLE(); break;
2070 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002071 }
2072}
2073
2074GLenum __stdcall glGetError(void)
2075{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002076 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002077
2078 gl::Context *context = gl::getContext();
2079
2080 if (context)
2081 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002082 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002083 }
2084
2085 return GL_NO_ERROR;
2086}
2087
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002088void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
2089{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002090 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002091
Geoff Langbfdea662014-07-23 14:16:32 -04002092 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002093 if (context)
2094 {
2095 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2096
2097 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002098 {
Geoff Langb1196682014-07-23 13:47:29 -04002099 context->recordError(gl::Error(GL_INVALID_OPERATION));
2100 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002101 }
Geoff Langbfdea662014-07-23 14:16:32 -04002102
2103 if (fenceObject->isFence() != GL_TRUE)
2104 {
Geoff Langb1196682014-07-23 13:47:29 -04002105 context->recordError(gl::Error(GL_INVALID_OPERATION));
2106 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002107 }
2108
2109 switch (pname)
2110 {
2111 case GL_FENCE_STATUS_NV:
2112 case GL_FENCE_CONDITION_NV:
2113 break;
2114
Geoff Langb1196682014-07-23 13:47:29 -04002115 default:
2116 context->recordError(gl::Error(GL_INVALID_ENUM));
2117 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002118 }
2119
Geoff Lang882033e2014-09-30 11:26:07 -04002120 gl::Error error = fenceObject->getFencei(pname, params);
2121 if (error.isError())
2122 {
2123 context->recordError(error);
2124 return;
2125 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002126 }
2127}
2128
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002129void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2130{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002131 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002132
Geoff Langbfdea662014-07-23 14:16:32 -04002133 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002134 if (context)
2135 {
2136 GLenum nativeType;
2137 unsigned int numParams = 0;
2138 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002139 {
Geoff Langbfdea662014-07-23 14:16:32 -04002140 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002141 }
Geoff Langbfdea662014-07-23 14:16:32 -04002142
2143 if (nativeType == GL_FLOAT)
2144 {
2145 context->getFloatv(pname, params);
2146 }
2147 else
2148 {
2149 CastStateValues(context, nativeType, pname, numParams, params);
2150 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002151 }
2152}
2153
2154void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2155{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002156 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 +00002157 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002158
Geoff Langbfdea662014-07-23 14:16:32 -04002159 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002160 if (context)
2161 {
2162 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002163 {
Geoff Langb1196682014-07-23 13:47:29 -04002164 context->recordError(gl::Error(GL_INVALID_ENUM));
2165 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002166 }
2167
2168 int clientVersion = context->getClientVersion();
2169
2170 switch (pname)
2171 {
2172 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2173 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2174 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2175 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2176 break;
Geoff Langb1196682014-07-23 13:47:29 -04002177
Geoff Langbfdea662014-07-23 14:16:32 -04002178 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2179 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002180 {
Geoff Langb1196682014-07-23 13:47:29 -04002181 context->recordError(gl::Error(GL_INVALID_ENUM));
2182 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002183 }
Geoff Langbfdea662014-07-23 14:16:32 -04002184 break;
Geoff Langb1196682014-07-23 13:47:29 -04002185
Geoff Langbfdea662014-07-23 14:16:32 -04002186 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2187 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2188 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2189 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2190 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2191 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2192 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2193 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2194 if (clientVersion < 3)
2195 {
Geoff Langb1196682014-07-23 13:47:29 -04002196 context->recordError(gl::Error(GL_INVALID_ENUM));
2197 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002198 }
2199 break;
Geoff Langb1196682014-07-23 13:47:29 -04002200
Geoff Langbfdea662014-07-23 14:16:32 -04002201 default:
Geoff Langb1196682014-07-23 13:47:29 -04002202 context->recordError(gl::Error(GL_INVALID_ENUM));
2203 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002204 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002205
Geoff Langbfdea662014-07-23 14:16:32 -04002206 // Determine if the attachment is a valid enum
2207 switch (attachment)
2208 {
2209 case GL_BACK:
2210 case GL_FRONT:
2211 case GL_DEPTH:
2212 case GL_STENCIL:
2213 case GL_DEPTH_STENCIL_ATTACHMENT:
2214 if (clientVersion < 3)
2215 {
Geoff Langb1196682014-07-23 13:47:29 -04002216 context->recordError(gl::Error(GL_INVALID_ENUM));
2217 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002218 }
2219 break;
2220
2221 case GL_DEPTH_ATTACHMENT:
2222 case GL_STENCIL_ATTACHMENT:
2223 break;
2224
2225 default:
2226 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2227 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2228 {
Geoff Langb1196682014-07-23 13:47:29 -04002229 context->recordError(gl::Error(GL_INVALID_ENUM));
2230 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002231 }
2232 break;
2233 }
2234
2235 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2236 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2237
2238 if (framebufferHandle == 0)
2239 {
2240 if (clientVersion < 3)
2241 {
Geoff Langb1196682014-07-23 13:47:29 -04002242 context->recordError(gl::Error(GL_INVALID_OPERATION));
2243 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002244 }
2245
2246 switch (attachment)
2247 {
2248 case GL_BACK:
2249 case GL_DEPTH:
2250 case GL_STENCIL:
2251 break;
Geoff Langb1196682014-07-23 13:47:29 -04002252
Geoff Langbfdea662014-07-23 14:16:32 -04002253 default:
Geoff Langb1196682014-07-23 13:47:29 -04002254 context->recordError(gl::Error(GL_INVALID_OPERATION));
2255 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002256 }
2257 }
2258 else
2259 {
2260 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2261 {
2262 // Valid attachment query
2263 }
2264 else
2265 {
2266 switch (attachment)
2267 {
2268 case GL_DEPTH_ATTACHMENT:
2269 case GL_STENCIL_ATTACHMENT:
2270 break;
Geoff Langb1196682014-07-23 13:47:29 -04002271
Geoff Langbfdea662014-07-23 14:16:32 -04002272 case GL_DEPTH_STENCIL_ATTACHMENT:
2273 if (framebuffer->hasValidDepthStencil())
2274 {
Geoff Langb1196682014-07-23 13:47:29 -04002275 context->recordError(gl::Error(GL_INVALID_OPERATION));
2276 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002277 }
2278 break;
Geoff Langb1196682014-07-23 13:47:29 -04002279
Geoff Langbfdea662014-07-23 14:16:32 -04002280 default:
Geoff Langb1196682014-07-23 13:47:29 -04002281 context->recordError(gl::Error(GL_INVALID_OPERATION));
2282 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002283 }
2284 }
2285 }
2286
2287 GLenum attachmentType = GL_NONE;
2288 GLuint attachmentHandle = 0;
2289 GLuint attachmentLevel = 0;
2290 GLuint attachmentLayer = 0;
2291
2292 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2293
2294 if (attachmentObject)
2295 {
2296 attachmentType = attachmentObject->type();
2297 attachmentHandle = attachmentObject->id();
2298 attachmentLevel = attachmentObject->mipLevel();
2299 attachmentLayer = attachmentObject->layer();
2300 }
2301
2302 GLenum attachmentObjectType; // Type category
2303 if (framebufferHandle == 0)
2304 {
2305 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2306 }
2307 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2308 {
2309 attachmentObjectType = attachmentType;
2310 }
2311 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2312 {
2313 attachmentObjectType = GL_TEXTURE;
2314 }
2315 else
2316 {
2317 UNREACHABLE();
2318 return;
2319 }
2320
2321 if (attachmentObjectType == GL_NONE)
2322 {
2323 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2324 // is NONE, then querying any other pname will generate INVALID_ENUM.
2325
2326 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2327 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2328 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002329
Geoff Lang646559f2013-08-15 11:08:15 -04002330 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002331 {
Geoff Lang646559f2013-08-15 11:08:15 -04002332 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002333 *params = attachmentObjectType;
2334 break;
2335
Geoff Lang646559f2013-08-15 11:08:15 -04002336 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002337 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002338 {
Geoff Langb1196682014-07-23 13:47:29 -04002339 context->recordError(gl::Error(GL_INVALID_ENUM));
2340 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002341 }
Geoff Langbfdea662014-07-23 14:16:32 -04002342 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002343 break;
2344
2345 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002346 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002347 {
Geoff Langb1196682014-07-23 13:47:29 -04002348 context->recordError(gl::Error(GL_INVALID_ENUM));
2349 return;
Geoff Lang646559f2013-08-15 11:08:15 -04002350 }
2351 else
2352 {
Geoff Langb1196682014-07-23 13:47:29 -04002353 context->recordError(gl::Error(GL_INVALID_OPERATION));
2354 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002355 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002356 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002357 }
Geoff Langbfdea662014-07-23 14:16:32 -04002358 else
2359 {
2360 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2361 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2362 ASSERT(attachmentObject != NULL);
2363
2364 switch (pname)
2365 {
2366 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2367 *params = attachmentObjectType;
2368 break;
2369
2370 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2371 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2372 {
Geoff Langb1196682014-07-23 13:47:29 -04002373 context->recordError(gl::Error(GL_INVALID_ENUM));
2374 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002375 }
2376 *params = attachmentHandle;
2377 break;
2378
2379 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2380 if (attachmentObjectType != GL_TEXTURE)
2381 {
Geoff Langb1196682014-07-23 13:47:29 -04002382 context->recordError(gl::Error(GL_INVALID_ENUM));
2383 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002384 }
2385 *params = attachmentLevel;
2386 break;
2387
2388 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2389 if (attachmentObjectType != GL_TEXTURE)
2390 {
Geoff Langb1196682014-07-23 13:47:29 -04002391 context->recordError(gl::Error(GL_INVALID_ENUM));
2392 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002393 }
2394 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2395 break;
2396
2397 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2398 *params = attachmentObject->getRedSize();
2399 break;
2400
2401 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2402 *params = attachmentObject->getGreenSize();
2403 break;
2404
2405 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2406 *params = attachmentObject->getBlueSize();
2407 break;
2408
2409 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2410 *params = attachmentObject->getAlphaSize();
2411 break;
2412
2413 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2414 *params = attachmentObject->getDepthSize();
2415 break;
2416
2417 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2418 *params = attachmentObject->getStencilSize();
2419 break;
2420
2421 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
Jamie Madillee85d1b2014-09-17 10:35:23 -04002422 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT)
Geoff Langbfdea662014-07-23 14:16:32 -04002423 {
Geoff Langb1196682014-07-23 13:47:29 -04002424 context->recordError(gl::Error(GL_INVALID_OPERATION));
2425 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002426 }
2427 *params = attachmentObject->getComponentType();
2428 break;
2429
2430 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2431 *params = attachmentObject->getColorEncoding();
2432 break;
2433
2434 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2435 if (attachmentObjectType != GL_TEXTURE)
2436 {
Geoff Langb1196682014-07-23 13:47:29 -04002437 context->recordError(gl::Error(GL_INVALID_ENUM));
2438 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002439 }
2440 *params = attachmentLayer;
2441 break;
2442
2443 default:
2444 UNREACHABLE();
2445 break;
2446 }
2447 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002448 }
2449}
2450
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002451GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2452{
2453 EVENT("()");
2454
Geoff Langbfdea662014-07-23 14:16:32 -04002455 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002456
Geoff Langbfdea662014-07-23 14:16:32 -04002457 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002458 {
Geoff Langbfdea662014-07-23 14:16:32 -04002459 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002460 }
Geoff Langbfdea662014-07-23 14:16:32 -04002461
2462 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002463}
2464
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002465void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2466{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002467 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002468
Geoff Langbfdea662014-07-23 14:16:32 -04002469 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002470 if (context)
2471 {
2472 GLenum nativeType;
2473 unsigned int numParams = 0;
2474
2475 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002476 {
Geoff Langbfdea662014-07-23 14:16:32 -04002477 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002478 }
Geoff Langbfdea662014-07-23 14:16:32 -04002479
2480 if (nativeType == GL_INT)
2481 {
2482 context->getIntegerv(pname, params);
2483 }
2484 else
2485 {
2486 CastStateValues(context, nativeType, pname, numParams, params);
2487 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002488 }
2489}
2490
2491void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2492{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002493 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002494
Geoff Langbfdea662014-07-23 14:16:32 -04002495 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002496 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002497 {
Geoff Langbfdea662014-07-23 14:16:32 -04002498 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002499
Geoff Langbfdea662014-07-23 14:16:32 -04002500 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002501 {
Geoff Langb1196682014-07-23 13:47:29 -04002502 context->recordError(gl::Error(GL_INVALID_VALUE));
2503 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002504 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002505
Geoff Langbfdea662014-07-23 14:16:32 -04002506 if (context->getClientVersion() < 3)
2507 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002508 switch (pname)
2509 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002510 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002511 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002512 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002513 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002514 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002515 context->recordError(gl::Error(GL_INVALID_ENUM));
2516 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002517 }
2518 }
Geoff Langbfdea662014-07-23 14:16:32 -04002519
2520 switch (pname)
2521 {
2522 case GL_DELETE_STATUS:
2523 *params = programObject->isFlaggedForDeletion();
2524 return;
2525 case GL_LINK_STATUS:
2526 *params = programObject->isLinked();
2527 return;
2528 case GL_VALIDATE_STATUS:
2529 *params = programObject->isValidated();
2530 return;
2531 case GL_INFO_LOG_LENGTH:
2532 *params = programObject->getInfoLogLength();
2533 return;
2534 case GL_ATTACHED_SHADERS:
2535 *params = programObject->getAttachedShadersCount();
2536 return;
2537 case GL_ACTIVE_ATTRIBUTES:
2538 *params = programObject->getActiveAttributeCount();
2539 return;
2540 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2541 *params = programObject->getActiveAttributeMaxLength();
2542 return;
2543 case GL_ACTIVE_UNIFORMS:
2544 *params = programObject->getActiveUniformCount();
2545 return;
2546 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2547 *params = programObject->getActiveUniformMaxLength();
2548 return;
2549 case GL_PROGRAM_BINARY_LENGTH_OES:
2550 *params = programObject->getProgramBinaryLength();
2551 return;
2552 case GL_ACTIVE_UNIFORM_BLOCKS:
2553 *params = programObject->getActiveUniformBlockCount();
2554 return;
2555 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2556 *params = programObject->getActiveUniformBlockMaxLength();
2557 break;
2558 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2559 *params = programObject->getTransformFeedbackBufferMode();
2560 break;
2561 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2562 *params = programObject->getTransformFeedbackVaryingCount();
2563 break;
2564 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2565 *params = programObject->getTransformFeedbackVaryingMaxLength();
2566 break;
Geoff Langb1196682014-07-23 13:47:29 -04002567
Geoff Langbfdea662014-07-23 14:16:32 -04002568 default:
Geoff Langb1196682014-07-23 13:47:29 -04002569 context->recordError(gl::Error(GL_INVALID_ENUM));
2570 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002571 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002572 }
2573}
2574
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002575void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002576{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002577 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 +00002578 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002579
Geoff Langbfdea662014-07-23 14:16:32 -04002580 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002581 if (context)
2582 {
Geoff Langb1196682014-07-23 13:47:29 -04002583 if (bufsize < 0)
2584 {
2585 context->recordError(gl::Error(GL_INVALID_VALUE));
2586 return;
2587 }
2588
Geoff Langbfdea662014-07-23 14:16:32 -04002589 gl::Program *programObject = context->getProgram(program);
2590
2591 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002592 {
Geoff Langb1196682014-07-23 13:47:29 -04002593 context->recordError(gl::Error(GL_INVALID_VALUE));
2594 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002595 }
2596
Geoff Langbfdea662014-07-23 14:16:32 -04002597 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002598 }
2599}
2600
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002601void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2602{
2603 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2604
Geoff Langbfdea662014-07-23 14:16:32 -04002605 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002606 if (context)
2607 {
2608 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002609 {
Geoff Langb1196682014-07-23 13:47:29 -04002610 context->recordError(gl::Error(GL_INVALID_ENUM));
2611 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002612 }
Geoff Langbfdea662014-07-23 14:16:32 -04002613
2614 switch (pname)
2615 {
2616 case GL_CURRENT_QUERY_EXT:
2617 params[0] = context->getState().getActiveQueryId(target);
2618 break;
2619
2620 default:
Geoff Langb1196682014-07-23 13:47:29 -04002621 context->recordError(gl::Error(GL_INVALID_ENUM));
2622 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002623 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002624 }
2625}
2626
2627void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2628{
2629 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2630
Geoff Langbfdea662014-07-23 14:16:32 -04002631 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002632 if (context)
2633 {
2634 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2635
2636 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002637 {
Geoff Langb1196682014-07-23 13:47:29 -04002638 context->recordError(gl::Error(GL_INVALID_OPERATION));
2639 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002640 }
Geoff Langbfdea662014-07-23 14:16:32 -04002641
2642 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2643 {
Geoff Langb1196682014-07-23 13:47:29 -04002644 context->recordError(gl::Error(GL_INVALID_OPERATION));
2645 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002646 }
2647
2648 switch(pname)
2649 {
2650 case GL_QUERY_RESULT_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002651 {
2652 gl::Error error = queryObject->getResult(params);
2653 if (error.isError())
2654 {
2655 context->recordError(error);
2656 return;
2657 }
2658 }
Geoff Langbfdea662014-07-23 14:16:32 -04002659 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002660
Geoff Langbfdea662014-07-23 14:16:32 -04002661 case GL_QUERY_RESULT_AVAILABLE_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002662 {
2663 gl::Error error = queryObject->isResultAvailable(params);
2664 if (error.isError())
2665 {
2666 context->recordError(error);
2667 return;
2668 }
2669 }
Geoff Langbfdea662014-07-23 14:16:32 -04002670 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002671
Geoff Langbfdea662014-07-23 14:16:32 -04002672 default:
Geoff Langb1196682014-07-23 13:47:29 -04002673 context->recordError(gl::Error(GL_INVALID_ENUM));
2674 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002675 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002676 }
2677}
2678
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002679void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2680{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002681 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 +00002682
Geoff Langbfdea662014-07-23 14:16:32 -04002683 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002684 if (context)
2685 {
2686 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002687 {
Geoff Langb1196682014-07-23 13:47:29 -04002688 context->recordError(gl::Error(GL_INVALID_ENUM));
2689 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002690 }
Geoff Langbfdea662014-07-23 14:16:32 -04002691
2692 if (context->getState().getRenderbufferId() == 0)
2693 {
Geoff Langb1196682014-07-23 13:47:29 -04002694 context->recordError(gl::Error(GL_INVALID_OPERATION));
2695 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002696 }
2697
2698 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2699
2700 switch (pname)
2701 {
2702 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2703 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2704 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2705 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2706 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2707 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2708 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2709 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2710 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002711
Geoff Langbfdea662014-07-23 14:16:32 -04002712 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2713 if (!context->getExtensions().framebufferMultisample)
2714 {
Geoff Langb1196682014-07-23 13:47:29 -04002715 context->recordError(gl::Error(GL_INVALID_ENUM));
2716 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002717 }
2718 *params = renderbuffer->getSamples();
2719 break;
Geoff Langb1196682014-07-23 13:47:29 -04002720
Geoff Langbfdea662014-07-23 14:16:32 -04002721 default:
Geoff Langb1196682014-07-23 13:47:29 -04002722 context->recordError(gl::Error(GL_INVALID_ENUM));
2723 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002724 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002725 }
2726}
2727
2728void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002730 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002731
Geoff Langbfdea662014-07-23 14:16:32 -04002732 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002733 if (context)
2734 {
2735 gl::Shader *shaderObject = context->getShader(shader);
2736
2737 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002738 {
Geoff Langb1196682014-07-23 13:47:29 -04002739 context->recordError(gl::Error(GL_INVALID_VALUE));
2740 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002741 }
Geoff Langbfdea662014-07-23 14:16:32 -04002742
2743 switch (pname)
2744 {
2745 case GL_SHADER_TYPE:
2746 *params = shaderObject->getType();
2747 return;
2748 case GL_DELETE_STATUS:
2749 *params = shaderObject->isFlaggedForDeletion();
2750 return;
2751 case GL_COMPILE_STATUS:
2752 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2753 return;
2754 case GL_INFO_LOG_LENGTH:
2755 *params = shaderObject->getInfoLogLength();
2756 return;
2757 case GL_SHADER_SOURCE_LENGTH:
2758 *params = shaderObject->getSourceLength();
2759 return;
2760 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2761 *params = shaderObject->getTranslatedSourceLength();
2762 return;
Geoff Langb1196682014-07-23 13:47:29 -04002763
Geoff Langbfdea662014-07-23 14:16:32 -04002764 default:
Geoff Langb1196682014-07-23 13:47:29 -04002765 context->recordError(gl::Error(GL_INVALID_ENUM));
2766 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002767 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002768 }
2769}
2770
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002771void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002772{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002773 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 +00002774 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002775
Geoff Langbfdea662014-07-23 14:16:32 -04002776 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002777 if (context)
2778 {
Geoff Langb1196682014-07-23 13:47:29 -04002779 if (bufsize < 0)
2780 {
2781 context->recordError(gl::Error(GL_INVALID_VALUE));
2782 return;
2783 }
2784
Geoff Langbfdea662014-07-23 14:16:32 -04002785 gl::Shader *shaderObject = context->getShader(shader);
2786
2787 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002788 {
Geoff Langb1196682014-07-23 13:47:29 -04002789 context->recordError(gl::Error(GL_INVALID_VALUE));
2790 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002791 }
2792
Geoff Langbfdea662014-07-23 14:16:32 -04002793 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002794 }
2795}
2796
2797void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2798{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002799 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 +00002800 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002801
Geoff Langb1196682014-07-23 13:47:29 -04002802 gl::Context *context = gl::getNonLostContext();
2803 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002804 {
Geoff Langb1196682014-07-23 13:47:29 -04002805 switch (shadertype)
2806 {
2807 case GL_VERTEX_SHADER:
2808 case GL_FRAGMENT_SHADER:
2809 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002810
Geoff Langb1196682014-07-23 13:47:29 -04002811 default:
2812 context->recordError(gl::Error(GL_INVALID_ENUM));
2813 return;
2814 }
2815
2816 switch (precisiontype)
2817 {
2818 case GL_LOW_FLOAT:
2819 case GL_MEDIUM_FLOAT:
2820 case GL_HIGH_FLOAT:
2821 // Assume IEEE 754 precision
2822 range[0] = 127;
2823 range[1] = 127;
2824 *precision = 23;
2825 break;
2826
2827 case GL_LOW_INT:
2828 case GL_MEDIUM_INT:
2829 case GL_HIGH_INT:
2830 // Some (most) hardware only supports single-precision floating-point numbers,
2831 // which can accurately represent integers up to +/-16777216
2832 range[0] = 24;
2833 range[1] = 24;
2834 *precision = 0;
2835 break;
2836
2837 default:
2838 context->recordError(gl::Error(GL_INVALID_ENUM));
2839 return;
2840 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002841 }
2842}
2843
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002844void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002845{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002846 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 +00002847 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002848
Geoff Langbfdea662014-07-23 14:16:32 -04002849 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002850 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002851 {
Geoff Langb1196682014-07-23 13:47:29 -04002852 if (bufsize < 0)
2853 {
2854 context->recordError(gl::Error(GL_INVALID_VALUE));
2855 return;
2856 }
2857
Geoff Langbfdea662014-07-23 14:16:32 -04002858 gl::Shader *shaderObject = context->getShader(shader);
2859
2860 if (!shaderObject)
2861 {
Geoff Langb1196682014-07-23 13:47:29 -04002862 context->recordError(gl::Error(GL_INVALID_OPERATION));
2863 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002864 }
2865
2866 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002867 }
2868}
2869
zmo@google.coma574f782011-10-03 21:45:23 +00002870void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2871{
2872 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2873 shader, bufsize, length, source);
2874
Geoff Langbfdea662014-07-23 14:16:32 -04002875 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002876 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002877 {
Geoff Langb1196682014-07-23 13:47:29 -04002878 if (bufsize < 0)
2879 {
2880 context->recordError(gl::Error(GL_INVALID_VALUE));
2881 return;
2882 }
2883
Geoff Langbfdea662014-07-23 14:16:32 -04002884 gl::Shader *shaderObject = context->getShader(shader);
2885
2886 if (!shaderObject)
2887 {
Geoff Langb1196682014-07-23 13:47:29 -04002888 context->recordError(gl::Error(GL_INVALID_OPERATION));
2889 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002890 }
2891
2892 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002893 }
2894}
2895
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002896const GLubyte* __stdcall glGetString(GLenum name)
2897{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002898 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002899
Geoff Langbfdea662014-07-23 14:16:32 -04002900 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002901
Geoff Langbfdea662014-07-23 14:16:32 -04002902 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002903 {
Geoff Langbfdea662014-07-23 14:16:32 -04002904 case GL_VENDOR:
2905 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002906
Geoff Langbfdea662014-07-23 14:16:32 -04002907 case GL_RENDERER:
2908 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002909
Geoff Langbfdea662014-07-23 14:16:32 -04002910 case GL_VERSION:
2911 if (context->getClientVersion() == 2)
2912 {
2913 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2914 }
2915 else
2916 {
2917 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2918 }
Geoff Langb1196682014-07-23 13:47:29 -04002919
Geoff Langbfdea662014-07-23 14:16:32 -04002920 case GL_SHADING_LANGUAGE_VERSION:
2921 if (context->getClientVersion() == 2)
2922 {
2923 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2924 }
2925 else
2926 {
2927 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2928 }
Geoff Langb1196682014-07-23 13:47:29 -04002929
Geoff Langbfdea662014-07-23 14:16:32 -04002930 case GL_EXTENSIONS:
2931 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002932
Geoff Langbfdea662014-07-23 14:16:32 -04002933 default:
Geoff Langb1196682014-07-23 13:47:29 -04002934 if (context)
2935 {
2936 context->recordError(gl::Error(GL_INVALID_ENUM));
2937 }
2938 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002939 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002940}
2941
2942void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2943{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002944 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 +00002945
Geoff Langbfdea662014-07-23 14:16:32 -04002946 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002947 if (context)
2948 {
2949 gl::Texture *texture = context->getTargetTexture(target);
2950
2951 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002952 {
Geoff Langb1196682014-07-23 13:47:29 -04002953 context->recordError(gl::Error(GL_INVALID_ENUM));
2954 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002955 }
Geoff Langbfdea662014-07-23 14:16:32 -04002956
2957 switch (pname)
2958 {
2959 case GL_TEXTURE_MAG_FILTER:
2960 *params = (GLfloat)texture->getSamplerState().magFilter;
2961 break;
2962 case GL_TEXTURE_MIN_FILTER:
2963 *params = (GLfloat)texture->getSamplerState().minFilter;
2964 break;
2965 case GL_TEXTURE_WRAP_S:
2966 *params = (GLfloat)texture->getSamplerState().wrapS;
2967 break;
2968 case GL_TEXTURE_WRAP_T:
2969 *params = (GLfloat)texture->getSamplerState().wrapT;
2970 break;
2971 case GL_TEXTURE_WRAP_R:
2972 if (context->getClientVersion() < 3)
2973 {
Geoff Langb1196682014-07-23 13:47:29 -04002974 context->recordError(gl::Error(GL_INVALID_ENUM));
2975 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002976 }
2977 *params = (GLfloat)texture->getSamplerState().wrapR;
2978 break;
2979 case GL_TEXTURE_IMMUTABLE_FORMAT:
2980 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2981 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2982 break;
2983 case GL_TEXTURE_IMMUTABLE_LEVELS:
2984 if (context->getClientVersion() < 3)
2985 {
Geoff Langb1196682014-07-23 13:47:29 -04002986 context->recordError(gl::Error(GL_INVALID_ENUM));
2987 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002988 }
2989 *params = (GLfloat)texture->immutableLevelCount();
2990 break;
2991 case GL_TEXTURE_USAGE_ANGLE:
2992 *params = (GLfloat)texture->getUsage();
2993 break;
2994 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2995 if (!context->getExtensions().textureFilterAnisotropic)
2996 {
Geoff Langb1196682014-07-23 13:47:29 -04002997 context->recordError(gl::Error(GL_INVALID_ENUM));
2998 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002999 }
3000 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
3001 break;
3002 case GL_TEXTURE_SWIZZLE_R:
3003 if (context->getClientVersion() < 3)
3004 {
Geoff Langb1196682014-07-23 13:47:29 -04003005 context->recordError(gl::Error(GL_INVALID_ENUM));
3006 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003007 }
3008 *params = (GLfloat)texture->getSamplerState().swizzleRed;
3009 break;
3010 case GL_TEXTURE_SWIZZLE_G:
3011 if (context->getClientVersion() < 3)
3012 {
Geoff Langb1196682014-07-23 13:47:29 -04003013 context->recordError(gl::Error(GL_INVALID_ENUM));
3014 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003015 }
3016 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
3017 break;
3018 case GL_TEXTURE_SWIZZLE_B:
3019 if (context->getClientVersion() < 3)
3020 {
Geoff Langb1196682014-07-23 13:47:29 -04003021 context->recordError(gl::Error(GL_INVALID_ENUM));
3022 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003023 }
3024 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
3025 break;
3026 case GL_TEXTURE_SWIZZLE_A:
3027 if (context->getClientVersion() < 3)
3028 {
Geoff Langb1196682014-07-23 13:47:29 -04003029 context->recordError(gl::Error(GL_INVALID_ENUM));
3030 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003031 }
3032 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
3033 break;
3034 case GL_TEXTURE_BASE_LEVEL:
3035 if (context->getClientVersion() < 3)
3036 {
Geoff Langb1196682014-07-23 13:47:29 -04003037 context->recordError(gl::Error(GL_INVALID_ENUM));
3038 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003039 }
3040 *params = (GLfloat)texture->getSamplerState().baseLevel;
3041 break;
3042 case GL_TEXTURE_MAX_LEVEL:
3043 if (context->getClientVersion() < 3)
3044 {
Geoff Langb1196682014-07-23 13:47:29 -04003045 context->recordError(gl::Error(GL_INVALID_ENUM));
3046 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003047 }
3048 *params = (GLfloat)texture->getSamplerState().maxLevel;
3049 break;
3050 case GL_TEXTURE_MIN_LOD:
3051 if (context->getClientVersion() < 3)
3052 {
Geoff Langb1196682014-07-23 13:47:29 -04003053 context->recordError(gl::Error(GL_INVALID_ENUM));
3054 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003055 }
3056 *params = texture->getSamplerState().minLod;
3057 break;
3058 case GL_TEXTURE_MAX_LOD:
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().maxLod;
3065 break;
Geoff Langb1196682014-07-23 13:47:29 -04003066
Geoff Langbfdea662014-07-23 14:16:32 -04003067 default:
Geoff Langb1196682014-07-23 13:47:29 -04003068 context->recordError(gl::Error(GL_INVALID_ENUM));
3069 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003070 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003071 }
3072}
3073
3074void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
3075{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003076 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 +00003077
Geoff Langbfdea662014-07-23 14:16:32 -04003078 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003079 if (context)
3080 {
3081 gl::Texture *texture = context->getTargetTexture(target);
3082
3083 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003084 {
Geoff Langb1196682014-07-23 13:47:29 -04003085 context->recordError(gl::Error(GL_INVALID_ENUM));
3086 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003087 }
Geoff Langbfdea662014-07-23 14:16:32 -04003088
3089 switch (pname)
3090 {
3091 case GL_TEXTURE_MAG_FILTER:
3092 *params = texture->getSamplerState().magFilter;
3093 break;
3094 case GL_TEXTURE_MIN_FILTER:
3095 *params = texture->getSamplerState().minFilter;
3096 break;
3097 case GL_TEXTURE_WRAP_S:
3098 *params = texture->getSamplerState().wrapS;
3099 break;
3100 case GL_TEXTURE_WRAP_T:
3101 *params = texture->getSamplerState().wrapT;
3102 break;
3103 case GL_TEXTURE_WRAP_R:
3104 if (context->getClientVersion() < 3)
3105 {
Geoff Langb1196682014-07-23 13:47:29 -04003106 context->recordError(gl::Error(GL_INVALID_ENUM));
3107 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003108 }
3109 *params = texture->getSamplerState().wrapR;
3110 break;
3111 case GL_TEXTURE_IMMUTABLE_FORMAT:
3112 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3113 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3114 break;
3115 case GL_TEXTURE_IMMUTABLE_LEVELS:
3116 if (context->getClientVersion() < 3)
3117 {
Geoff Langb1196682014-07-23 13:47:29 -04003118 context->recordError(gl::Error(GL_INVALID_ENUM));
3119 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003120 }
3121 *params = texture->immutableLevelCount();
3122 break;
3123 case GL_TEXTURE_USAGE_ANGLE:
3124 *params = texture->getUsage();
3125 break;
3126 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3127 if (!context->getExtensions().textureFilterAnisotropic)
3128 {
Geoff Langb1196682014-07-23 13:47:29 -04003129 context->recordError(gl::Error(GL_INVALID_ENUM));
3130 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003131 }
3132 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3133 break;
3134 case GL_TEXTURE_SWIZZLE_R:
3135 if (context->getClientVersion() < 3)
3136 {
Geoff Langb1196682014-07-23 13:47:29 -04003137 context->recordError(gl::Error(GL_INVALID_ENUM));
3138 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003139 }
3140 *params = texture->getSamplerState().swizzleRed;
3141 break;
3142 case GL_TEXTURE_SWIZZLE_G:
3143 if (context->getClientVersion() < 3)
3144 {
Geoff Langb1196682014-07-23 13:47:29 -04003145 context->recordError(gl::Error(GL_INVALID_ENUM));
3146 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003147 }
3148 *params = texture->getSamplerState().swizzleGreen;
3149 break;
3150 case GL_TEXTURE_SWIZZLE_B:
3151 if (context->getClientVersion() < 3)
3152 {
Geoff Langb1196682014-07-23 13:47:29 -04003153 context->recordError(gl::Error(GL_INVALID_ENUM));
3154 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003155 }
3156 *params = texture->getSamplerState().swizzleBlue;
3157 break;
3158 case GL_TEXTURE_SWIZZLE_A:
3159 if (context->getClientVersion() < 3)
3160 {
Geoff Langb1196682014-07-23 13:47:29 -04003161 context->recordError(gl::Error(GL_INVALID_ENUM));
3162 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003163 }
3164 *params = texture->getSamplerState().swizzleAlpha;
3165 break;
3166 case GL_TEXTURE_BASE_LEVEL:
3167 if (context->getClientVersion() < 3)
3168 {
Geoff Langb1196682014-07-23 13:47:29 -04003169 context->recordError(gl::Error(GL_INVALID_ENUM));
3170 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003171 }
3172 *params = texture->getSamplerState().baseLevel;
3173 break;
3174 case GL_TEXTURE_MAX_LEVEL:
3175 if (context->getClientVersion() < 3)
3176 {
Geoff Langb1196682014-07-23 13:47:29 -04003177 context->recordError(gl::Error(GL_INVALID_ENUM));
3178 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003179 }
3180 *params = texture->getSamplerState().maxLevel;
3181 break;
3182 case GL_TEXTURE_MIN_LOD:
3183 if (context->getClientVersion() < 3)
3184 {
Geoff Langb1196682014-07-23 13:47:29 -04003185 context->recordError(gl::Error(GL_INVALID_ENUM));
3186 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003187 }
3188 *params = (GLint)texture->getSamplerState().minLod;
3189 break;
3190 case GL_TEXTURE_MAX_LOD:
3191 if (context->getClientVersion() < 3)
3192 {
Geoff Langb1196682014-07-23 13:47:29 -04003193 context->recordError(gl::Error(GL_INVALID_ENUM));
3194 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003195 }
3196 *params = (GLint)texture->getSamplerState().maxLod;
3197 break;
Geoff Langb1196682014-07-23 13:47:29 -04003198
Geoff Langbfdea662014-07-23 14:16:32 -04003199 default:
Geoff Langb1196682014-07-23 13:47:29 -04003200 context->recordError(gl::Error(GL_INVALID_ENUM));
3201 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003202 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003203 }
3204}
3205
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003206void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3207{
3208 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3209 program, location, bufSize, params);
3210
Geoff Langbfdea662014-07-23 14:16:32 -04003211 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003212 if (context)
3213 {
Jamie Madill0063c512014-08-25 15:47:53 -04003214 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003215 {
Jamie Madill0063c512014-08-25 15:47:53 -04003216 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003217 }
3218
Jamie Madilla502c742014-08-28 17:19:13 -04003219 gl::Program *programObject = context->getProgram(program);
3220 ASSERT(programObject);
3221 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003222 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003223
Jamie Madill99a1e982014-08-25 15:47:54 -04003224 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003225 }
3226}
3227
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003228void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3229{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003230 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003231
Geoff Langbfdea662014-07-23 14:16:32 -04003232 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003233 if (context)
3234 {
Jamie Madill0063c512014-08-25 15:47:53 -04003235 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003236 {
Jamie Madill0063c512014-08-25 15:47:53 -04003237 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003238 }
Geoff Langbfdea662014-07-23 14:16:32 -04003239
Jamie Madilla502c742014-08-28 17:19:13 -04003240 gl::Program *programObject = context->getProgram(program);
3241 ASSERT(programObject);
3242 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003243 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003244
Jamie Madill99a1e982014-08-25 15:47:54 -04003245 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003246 }
3247}
3248
3249void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3250{
Geoff Langbfdea662014-07-23 14:16:32 -04003251 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003252 program, location, bufSize, params);
3253
Geoff Langbfdea662014-07-23 14:16:32 -04003254 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003255 if (context)
3256 {
Jamie Madill0063c512014-08-25 15:47:53 -04003257 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003258 {
Jamie Madill0063c512014-08-25 15:47:53 -04003259 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003260 }
3261
Jamie Madilla502c742014-08-28 17:19:13 -04003262 gl::Program *programObject = context->getProgram(program);
3263 ASSERT(programObject);
3264 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003265 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003266
Jamie Madill99a1e982014-08-25 15:47:54 -04003267 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268 }
3269}
3270
3271void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3272{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003273 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003274
Geoff Langbfdea662014-07-23 14:16:32 -04003275 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003276 if (context)
3277 {
Jamie Madill0063c512014-08-25 15:47:53 -04003278 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003279 {
Jamie Madill0063c512014-08-25 15:47:53 -04003280 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003281 }
Geoff Langbfdea662014-07-23 14:16:32 -04003282
Jamie Madilla502c742014-08-28 17:19:13 -04003283 gl::Program *programObject = context->getProgram(program);
3284 ASSERT(programObject);
3285 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003286 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003287
Jamie Madill99a1e982014-08-25 15:47:54 -04003288 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003289 }
3290}
3291
Geoff Langb1196682014-07-23 13:47:29 -04003292GLint __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003293{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003294 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003295
Geoff Langbfdea662014-07-23 14:16:32 -04003296 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003297 if (context)
3298 {
Geoff Langb1196682014-07-23 13:47:29 -04003299 if (strstr(name, "gl_") == name)
3300 {
3301 return -1;
3302 }
3303
Geoff Langbfdea662014-07-23 14:16:32 -04003304 gl::Program *programObject = context->getProgram(program);
3305
3306 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003307 {
Geoff Langbfdea662014-07-23 14:16:32 -04003308 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003309 {
Geoff Langb1196682014-07-23 13:47:29 -04003310 context->recordError(gl::Error(GL_INVALID_OPERATION));
3311 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003312 }
Geoff Langbfdea662014-07-23 14:16:32 -04003313 else
3314 {
Geoff Langb1196682014-07-23 13:47:29 -04003315 context->recordError(gl::Error(GL_INVALID_VALUE));
3316 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003317 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003318 }
Geoff Langbfdea662014-07-23 14:16:32 -04003319
3320 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3321 if (!programObject->isLinked() || !programBinary)
3322 {
Geoff Langb1196682014-07-23 13:47:29 -04003323 context->recordError(gl::Error(GL_INVALID_OPERATION));
3324 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003325 }
3326
3327 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328 }
3329
3330 return -1;
3331}
3332
3333void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3334{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003335 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003336
Geoff Langbfdea662014-07-23 14:16:32 -04003337 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003338 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003339 {
Geoff Langbfdea662014-07-23 14:16:32 -04003340 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003341 {
Geoff Langb1196682014-07-23 13:47:29 -04003342 context->recordError(gl::Error(GL_INVALID_VALUE));
3343 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003344 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003345
Geoff Langbfdea662014-07-23 14:16:32 -04003346 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003347 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003348 {
3349 return;
3350 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003351
Geoff Langbfdea662014-07-23 14:16:32 -04003352 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3353 {
3354 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3355 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003356 {
Geoff Langbfdea662014-07-23 14:16:32 -04003357 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003358 }
3359 }
Geoff Langbfdea662014-07-23 14:16:32 -04003360 else
3361 {
3362 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3363 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364 }
3365}
3366
3367void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3368{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003369 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003370
Geoff Langbfdea662014-07-23 14:16:32 -04003371 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003372 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003373 {
Geoff Langbfdea662014-07-23 14:16:32 -04003374 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003375 {
Geoff Langb1196682014-07-23 13:47:29 -04003376 context->recordError(gl::Error(GL_INVALID_VALUE));
3377 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003378 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003379
Geoff Langbfdea662014-07-23 14:16:32 -04003380 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003381
Geoff Langb1196682014-07-23 13:47:29 -04003382 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003383 {
3384 return;
3385 }
Jamie Madillaff71502013-07-02 11:57:05 -04003386
Geoff Langbfdea662014-07-23 14:16:32 -04003387 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3388 {
3389 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3390 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003391 {
Geoff Langbfdea662014-07-23 14:16:32 -04003392 float currentValue = currentValueData.FloatValues[i];
3393 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003394 }
3395 }
Geoff Langbfdea662014-07-23 14:16:32 -04003396 else
3397 {
3398 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3399 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003400 }
3401}
3402
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003403void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003404{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003405 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003406
Geoff Langbfdea662014-07-23 14:16:32 -04003407 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003408 if (context)
3409 {
3410 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003411 {
Geoff Langb1196682014-07-23 13:47:29 -04003412 context->recordError(gl::Error(GL_INVALID_VALUE));
3413 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003414 }
Geoff Langbfdea662014-07-23 14:16:32 -04003415
3416 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3417 {
Geoff Langb1196682014-07-23 13:47:29 -04003418 context->recordError(gl::Error(GL_INVALID_ENUM));
3419 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003420 }
3421
3422 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003423 }
3424}
3425
3426void __stdcall glHint(GLenum target, GLenum mode)
3427{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003428 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003429
Geoff Langbfdea662014-07-23 14:16:32 -04003430 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003431 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003432 {
Geoff Langb1196682014-07-23 13:47:29 -04003433 switch (mode)
3434 {
3435 case GL_FASTEST:
3436 case GL_NICEST:
3437 case GL_DONT_CARE:
3438 break;
3439
3440 default:
3441 context->recordError(gl::Error(GL_INVALID_ENUM));
3442 return;
3443 }
3444
3445 switch (target)
3446 {
3447 case GL_GENERATE_MIPMAP_HINT:
3448 context->getState().setGenerateMipmapHint(mode);
3449 break;
3450
3451 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3452 context->getState().setFragmentShaderDerivativeHint(mode);
3453 break;
3454
3455 default:
3456 context->recordError(gl::Error(GL_INVALID_ENUM));
3457 return;
3458 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003459 }
3460}
3461
3462GLboolean __stdcall glIsBuffer(GLuint buffer)
3463{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003464 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003465
Geoff Langbfdea662014-07-23 14:16:32 -04003466 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003467 if (context && buffer)
3468 {
3469 gl::Buffer *bufferObject = context->getBuffer(buffer);
3470
3471 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003472 {
Geoff Langbfdea662014-07-23 14:16:32 -04003473 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003474 }
3475 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003476
3477 return GL_FALSE;
3478}
3479
3480GLboolean __stdcall glIsEnabled(GLenum cap)
3481{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003482 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003483
Geoff Langbfdea662014-07-23 14:16:32 -04003484 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003485 if (context)
3486 {
3487 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003488 {
Geoff Langb1196682014-07-23 13:47:29 -04003489 context->recordError(gl::Error(GL_INVALID_ENUM));
3490 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003491 }
Geoff Langbfdea662014-07-23 14:16:32 -04003492
3493 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494 }
3495
3496 return false;
3497}
3498
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003499GLboolean __stdcall glIsFenceNV(GLuint fence)
3500{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003501 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003502
Geoff Langbfdea662014-07-23 14:16:32 -04003503 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003504 if (context)
3505 {
3506 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3507
3508 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003509 {
Geoff Langbfdea662014-07-23 14:16:32 -04003510 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003511 }
Geoff Langbfdea662014-07-23 14:16:32 -04003512
3513 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003514 }
3515
3516 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003517}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003518
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003519GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3520{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003521 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003522
Geoff Langbfdea662014-07-23 14:16:32 -04003523 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003524 if (context && framebuffer)
3525 {
3526 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3527
3528 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003529 {
Geoff Langbfdea662014-07-23 14:16:32 -04003530 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003531 }
3532 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003533
3534 return GL_FALSE;
3535}
3536
3537GLboolean __stdcall glIsProgram(GLuint program)
3538{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003539 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003540
Geoff Langbfdea662014-07-23 14:16:32 -04003541 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003542 if (context && program)
3543 {
3544 gl::Program *programObject = context->getProgram(program);
3545
3546 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003547 {
Geoff Langbfdea662014-07-23 14:16:32 -04003548 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003549 }
3550 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003551
3552 return GL_FALSE;
3553}
3554
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003555GLboolean __stdcall glIsQueryEXT(GLuint id)
3556{
3557 EVENT("(GLuint id = %d)", id);
3558
Geoff Langbfdea662014-07-23 14:16:32 -04003559 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003560 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003561 {
Geoff Langbfdea662014-07-23 14:16:32 -04003562 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003563 }
3564
3565 return GL_FALSE;
3566}
3567
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3569{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003570 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571
Geoff Langbfdea662014-07-23 14:16:32 -04003572 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003573 if (context && renderbuffer)
3574 {
3575 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3576
3577 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003578 {
Geoff Langbfdea662014-07-23 14:16:32 -04003579 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003580 }
3581 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582
3583 return GL_FALSE;
3584}
3585
3586GLboolean __stdcall glIsShader(GLuint shader)
3587{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003588 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003589
Geoff Langbfdea662014-07-23 14:16:32 -04003590 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003591 if (context && shader)
3592 {
3593 gl::Shader *shaderObject = context->getShader(shader);
3594
3595 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003596 {
Geoff Langbfdea662014-07-23 14:16:32 -04003597 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598 }
3599 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003600
3601 return GL_FALSE;
3602}
3603
3604GLboolean __stdcall glIsTexture(GLuint texture)
3605{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003606 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003607
Geoff Langbfdea662014-07-23 14:16:32 -04003608 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003609 if (context && texture)
3610 {
3611 gl::Texture *textureObject = context->getTexture(texture);
3612
3613 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003614 {
Geoff Langbfdea662014-07-23 14:16:32 -04003615 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003616 }
3617 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618
3619 return GL_FALSE;
3620}
3621
3622void __stdcall glLineWidth(GLfloat width)
3623{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003624 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003625
Geoff Langbfdea662014-07-23 14:16:32 -04003626 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003627 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003628 {
Geoff Langb1196682014-07-23 13:47:29 -04003629 if (width <= 0.0f)
3630 {
3631 context->recordError(gl::Error(GL_INVALID_VALUE));
3632 return;
3633 }
3634
Geoff Langbfdea662014-07-23 14:16:32 -04003635 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003636 }
3637}
3638
3639void __stdcall glLinkProgram(GLuint program)
3640{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003641 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003642
Geoff Langbfdea662014-07-23 14:16:32 -04003643 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003644 if (context)
3645 {
3646 gl::Program *programObject = context->getProgram(program);
3647
3648 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003649 {
Geoff Langbfdea662014-07-23 14:16:32 -04003650 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003651 {
Geoff Langb1196682014-07-23 13:47:29 -04003652 context->recordError(gl::Error(GL_INVALID_OPERATION));
3653 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003654 }
Geoff Langbfdea662014-07-23 14:16:32 -04003655 else
3656 {
Geoff Langb1196682014-07-23 13:47:29 -04003657 context->recordError(gl::Error(GL_INVALID_VALUE));
3658 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003659 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003660 }
Geoff Langbfdea662014-07-23 14:16:32 -04003661
Geoff Langb543aff2014-09-30 14:52:54 -04003662 gl::Error error = context->linkProgram(program);
3663 if (error.isError())
3664 {
3665 context->recordError(error);
3666 return;
3667 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003668 }
3669}
3670
3671void __stdcall glPixelStorei(GLenum pname, GLint param)
3672{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003673 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003674
Geoff Langbfdea662014-07-23 14:16:32 -04003675 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003676 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003677 {
Geoff Langbfdea662014-07-23 14:16:32 -04003678 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003679 {
Geoff Langbfdea662014-07-23 14:16:32 -04003680 case GL_UNPACK_ALIGNMENT:
3681 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003682 {
Geoff Langb1196682014-07-23 13:47:29 -04003683 context->recordError(gl::Error(GL_INVALID_VALUE));
3684 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003685 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003686
Geoff Langbfdea662014-07-23 14:16:32 -04003687 context->getState().setUnpackAlignment(param);
3688 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003689
Geoff Langbfdea662014-07-23 14:16:32 -04003690 case GL_PACK_ALIGNMENT:
3691 if (param != 1 && param != 2 && param != 4 && param != 8)
3692 {
Geoff Langb1196682014-07-23 13:47:29 -04003693 context->recordError(gl::Error(GL_INVALID_VALUE));
3694 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003695 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003696
Geoff Langbfdea662014-07-23 14:16:32 -04003697 context->getState().setPackAlignment(param);
3698 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003699
Geoff Langbfdea662014-07-23 14:16:32 -04003700 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3701 context->getState().setPackReverseRowOrder(param != 0);
3702 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003703
Geoff Langbfdea662014-07-23 14:16:32 -04003704 case GL_UNPACK_IMAGE_HEIGHT:
3705 case GL_UNPACK_SKIP_IMAGES:
3706 case GL_UNPACK_ROW_LENGTH:
3707 case GL_UNPACK_SKIP_ROWS:
3708 case GL_UNPACK_SKIP_PIXELS:
3709 case GL_PACK_ROW_LENGTH:
3710 case GL_PACK_SKIP_ROWS:
3711 case GL_PACK_SKIP_PIXELS:
3712 if (context->getClientVersion() < 3)
3713 {
Geoff Langb1196682014-07-23 13:47:29 -04003714 context->recordError(gl::Error(GL_INVALID_ENUM));
3715 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003716 }
Geoff Langbfdea662014-07-23 14:16:32 -04003717 UNIMPLEMENTED();
3718 break;
3719
3720 default:
Geoff Langb1196682014-07-23 13:47:29 -04003721 context->recordError(gl::Error(GL_INVALID_ENUM));
3722 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003723 }
3724 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003725}
3726
3727void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3728{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003729 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003730
Geoff Langbfdea662014-07-23 14:16:32 -04003731 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003732 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733 {
Geoff Langbfdea662014-07-23 14:16:32 -04003734 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003735 }
3736}
3737
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003738void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3739 GLenum format, GLenum type, GLsizei bufSize,
3740 GLvoid *data)
3741{
3742 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3743 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3744 x, y, width, height, format, type, bufSize, data);
3745
Geoff Langbfdea662014-07-23 14:16:32 -04003746 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003747 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003748 {
Geoff Langb1196682014-07-23 13:47:29 -04003749 if (width < 0 || height < 0 || bufSize < 0)
3750 {
3751 context->recordError(gl::Error(GL_INVALID_VALUE));
3752 return;
3753 }
3754
Geoff Langbfdea662014-07-23 14:16:32 -04003755 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3756 format, type, &bufSize, data))
3757 {
3758 return;
3759 }
3760
Geoff Lang63d2fc72014-07-25 14:51:41 -04003761 gl::Error error = context->readPixels(x, y, width, height, format, type, &bufSize, data);
3762 if (error.isError())
3763 {
3764 context->recordError(error);
3765 return;
3766 }
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003767 }
3768}
3769
3770void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3771 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003772{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003773 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003774 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003775 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003776
Geoff Langbfdea662014-07-23 14:16:32 -04003777 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003778 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003779 {
Geoff Langb1196682014-07-23 13:47:29 -04003780 if (width < 0 || height < 0)
3781 {
3782 context->recordError(gl::Error(GL_INVALID_VALUE));
3783 return;
3784 }
3785
Geoff Langbfdea662014-07-23 14:16:32 -04003786 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3787 format, type, NULL, pixels))
3788 {
3789 return;
3790 }
3791
Geoff Lang63d2fc72014-07-25 14:51:41 -04003792 gl::Error error = context->readPixels(x, y, width, height, format, type, NULL, pixels);
3793 if (error.isError())
3794 {
3795 context->recordError(error);
3796 return;
3797 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003798 }
3799}
3800
3801void __stdcall glReleaseShaderCompiler(void)
3802{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003803 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003804
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003805 gl::Context *context = gl::getNonLostContext();
3806
3807 if (context)
3808 {
3809 context->releaseShaderCompiler();
3810 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003811}
3812
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003813void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003814{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003815 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 +00003816 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003817
Geoff Langbfdea662014-07-23 14:16:32 -04003818 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003819 if (context)
3820 {
3821 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3822 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003823 {
Geoff Langbfdea662014-07-23 14:16:32 -04003824 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003825 }
Geoff Langbfdea662014-07-23 14:16:32 -04003826
3827 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003828 }
3829}
3830
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003831void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3832{
3833 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3834}
3835
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003836void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3837{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003838 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003839
Geoff Langbfdea662014-07-23 14:16:32 -04003840 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003841
Geoff Langbfdea662014-07-23 14:16:32 -04003842 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003843 {
Geoff Langbfdea662014-07-23 14:16:32 -04003844 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003845 }
3846}
3847
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003848void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3849{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003850 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003851
Geoff Langbfdea662014-07-23 14:16:32 -04003852 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003853 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003854 {
Geoff Langb1196682014-07-23 13:47:29 -04003855 if (condition != GL_ALL_COMPLETED_NV)
3856 {
3857 context->recordError(gl::Error(GL_INVALID_ENUM));
3858 return;
3859 }
3860
Geoff Langbfdea662014-07-23 14:16:32 -04003861 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3862
3863 if (fenceObject == NULL)
3864 {
Geoff Langb1196682014-07-23 13:47:29 -04003865 context->recordError(gl::Error(GL_INVALID_OPERATION));
3866 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003867 }
3868
Geoff Lang882033e2014-09-30 11:26:07 -04003869 gl::Error error = fenceObject->setFence(condition);
3870 if (error.isError())
3871 {
3872 context->recordError(error);
3873 return;
3874 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003875 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003876}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003877
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003878void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3879{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003880 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 +00003881
Geoff Langbfdea662014-07-23 14:16:32 -04003882 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003883 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003884 {
Geoff Langb1196682014-07-23 13:47:29 -04003885 if (width < 0 || height < 0)
3886 {
3887 context->recordError(gl::Error(GL_INVALID_VALUE));
3888 return;
3889 }
3890
Geoff Langbfdea662014-07-23 14:16:32 -04003891 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003892 }
3893}
3894
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003895void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003896{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003897 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003898 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003899 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003900
Geoff Lang900013c2014-07-07 11:32:19 -04003901 gl::Context* context = gl::getNonLostContext();
3902 if (context)
3903 {
3904 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3905 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3906 {
Geoff Langb1196682014-07-23 13:47:29 -04003907 context->recordError(gl::Error(GL_INVALID_ENUM));
3908 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003909 }
3910
3911 // No binary shader formats are supported.
3912 UNIMPLEMENTED();
3913 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003914}
3915
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003916void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003918 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 +00003919 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920
Geoff Langbfdea662014-07-23 14:16:32 -04003921 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003922 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003923 {
Geoff Langb1196682014-07-23 13:47:29 -04003924 if (count < 0)
3925 {
3926 context->recordError(gl::Error(GL_INVALID_VALUE));
3927 return;
3928 }
3929
Geoff Langbfdea662014-07-23 14:16:32 -04003930 gl::Shader *shaderObject = context->getShader(shader);
3931
3932 if (!shaderObject)
3933 {
3934 if (context->getProgram(shader))
3935 {
Geoff Langb1196682014-07-23 13:47:29 -04003936 context->recordError(gl::Error(GL_INVALID_OPERATION));
3937 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003938 }
3939 else
3940 {
Geoff Langb1196682014-07-23 13:47:29 -04003941 context->recordError(gl::Error(GL_INVALID_VALUE));
3942 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003943 }
3944 }
3945
3946 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003947 }
3948}
3949
3950void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3951{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003952 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003953}
3954
3955void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3956{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003957 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 +00003958
Geoff Langbfdea662014-07-23 14:16:32 -04003959 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003960 if (context)
3961 {
Geoff Langb1196682014-07-23 13:47:29 -04003962 switch (face)
3963 {
3964 case GL_FRONT:
3965 case GL_BACK:
3966 case GL_FRONT_AND_BACK:
3967 break;
3968
3969 default:
3970 context->recordError(gl::Error(GL_INVALID_ENUM));
3971 return;
3972 }
3973
3974 switch (func)
3975 {
3976 case GL_NEVER:
3977 case GL_ALWAYS:
3978 case GL_LESS:
3979 case GL_LEQUAL:
3980 case GL_EQUAL:
3981 case GL_GEQUAL:
3982 case GL_GREATER:
3983 case GL_NOTEQUAL:
3984 break;
3985
3986 default:
3987 context->recordError(gl::Error(GL_INVALID_ENUM));
3988 return;
3989 }
3990
Geoff Langbfdea662014-07-23 14:16:32 -04003991 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3992 {
3993 context->getState().setStencilParams(func, ref, mask);
3994 }
3995
3996 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3997 {
3998 context->getState().setStencilBackParams(func, ref, mask);
3999 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004000 }
4001}
4002
4003void __stdcall glStencilMask(GLuint mask)
4004{
4005 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4006}
4007
4008void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
4009{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004010 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004011
Geoff Langbfdea662014-07-23 14:16:32 -04004012 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004013 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004014 {
Geoff Langb1196682014-07-23 13:47:29 -04004015 switch (face)
4016 {
4017 case GL_FRONT:
4018 case GL_BACK:
4019 case GL_FRONT_AND_BACK:
4020 break;
4021
4022 default:
4023 context->recordError(gl::Error(GL_INVALID_ENUM));
4024 return;
4025 }
4026
Geoff Langbfdea662014-07-23 14:16:32 -04004027 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4028 {
4029 context->getState().setStencilWritemask(mask);
4030 }
4031
4032 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4033 {
4034 context->getState().setStencilBackWritemask(mask);
4035 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004036 }
4037}
4038
4039void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4040{
4041 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4042}
4043
4044void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4045{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004046 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 +00004047 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004048
Geoff Langbfdea662014-07-23 14:16:32 -04004049 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004050 if (context)
4051 {
Geoff Langb1196682014-07-23 13:47:29 -04004052 switch (face)
4053 {
4054 case GL_FRONT:
4055 case GL_BACK:
4056 case GL_FRONT_AND_BACK:
4057 break;
4058
4059 default:
4060 context->recordError(gl::Error(GL_INVALID_ENUM));
4061 return;
4062 }
4063
4064 switch (fail)
4065 {
4066 case GL_ZERO:
4067 case GL_KEEP:
4068 case GL_REPLACE:
4069 case GL_INCR:
4070 case GL_DECR:
4071 case GL_INVERT:
4072 case GL_INCR_WRAP:
4073 case GL_DECR_WRAP:
4074 break;
4075
4076 default:
4077 context->recordError(gl::Error(GL_INVALID_ENUM));
4078 return;
4079 }
4080
4081 switch (zfail)
4082 {
4083 case GL_ZERO:
4084 case GL_KEEP:
4085 case GL_REPLACE:
4086 case GL_INCR:
4087 case GL_DECR:
4088 case GL_INVERT:
4089 case GL_INCR_WRAP:
4090 case GL_DECR_WRAP:
4091 break;
4092
4093 default:
4094 context->recordError(gl::Error(GL_INVALID_ENUM));
4095 return;
4096 }
4097
4098 switch (zpass)
4099 {
4100 case GL_ZERO:
4101 case GL_KEEP:
4102 case GL_REPLACE:
4103 case GL_INCR:
4104 case GL_DECR:
4105 case GL_INVERT:
4106 case GL_INCR_WRAP:
4107 case GL_DECR_WRAP:
4108 break;
4109
4110 default:
4111 context->recordError(gl::Error(GL_INVALID_ENUM));
4112 return;
4113 }
4114
Geoff Langbfdea662014-07-23 14:16:32 -04004115 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4116 {
4117 context->getState().setStencilOperations(fail, zfail, zpass);
4118 }
4119
4120 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4121 {
4122 context->getState().setStencilBackOperations(fail, zfail, zpass);
4123 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004124 }
4125}
4126
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004127GLboolean __stdcall glTestFenceNV(GLuint fence)
4128{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004129 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004130
Geoff Langbfdea662014-07-23 14:16:32 -04004131 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004132 if (context)
4133 {
4134 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4135
4136 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004137 {
Geoff Langb1196682014-07-23 13:47:29 -04004138 context->recordError(gl::Error(GL_INVALID_OPERATION));
4139 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004140 }
Geoff Langbfdea662014-07-23 14:16:32 -04004141
4142 if (fenceObject->isFence() != GL_TRUE)
4143 {
Geoff Langb1196682014-07-23 13:47:29 -04004144 context->recordError(gl::Error(GL_INVALID_OPERATION));
4145 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004146 }
4147
Geoff Lang882033e2014-09-30 11:26:07 -04004148 GLboolean result;
4149 gl::Error error = fenceObject->testFence(&result);
4150 if (error.isError())
4151 {
4152 context->recordError(error);
4153 return GL_TRUE;
4154 }
4155
4156 return result;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004157 }
Geoff Langbfdea662014-07-23 14:16:32 -04004158
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004159 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004160}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004161
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004162void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4163 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004164{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004165 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004166 "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 +00004167 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004168
Geoff Langbfdea662014-07-23 14:16:32 -04004169 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004170 if (context)
4171 {
4172 if (context->getClientVersion() < 3 &&
4173 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4174 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004175 {
Geoff Langbfdea662014-07-23 14:16:32 -04004176 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004177 }
Geoff Langbfdea662014-07-23 14:16:32 -04004178
4179 if (context->getClientVersion() >= 3 &&
4180 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4181 0, 0, 0, width, height, 1, border, format, type, pixels))
4182 {
4183 return;
4184 }
4185
4186 switch (target)
4187 {
4188 case GL_TEXTURE_2D:
4189 {
4190 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004191 gl::Error error = texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4192 if (error.isError())
4193 {
4194 context->recordError(error);
4195 return;
4196 }
Geoff Langbfdea662014-07-23 14:16:32 -04004197 }
4198 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004199
Geoff Langbfdea662014-07-23 14:16:32 -04004200 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004201 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004202 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004203 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004204 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
Geoff Langbfdea662014-07-23 14:16:32 -04004205 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4206 {
4207 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang8376cea2014-09-02 11:47:07 -04004208 gl::Error error = texture->setImage(target, level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004209 if (error.isError())
4210 {
4211 context->recordError(error);
4212 return;
4213 }
Geoff Langbfdea662014-07-23 14:16:32 -04004214 }
4215 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004216
Geoff Langbfdea662014-07-23 14:16:32 -04004217 default: UNREACHABLE();
4218 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004219 }
4220}
4221
4222void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4223{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004224 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4225
Geoff Langbfdea662014-07-23 14:16:32 -04004226 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004227 if (context)
4228 {
4229 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004230 {
Geoff Langbfdea662014-07-23 14:16:32 -04004231 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004232 }
Geoff Langbfdea662014-07-23 14:16:32 -04004233
4234 gl::Texture *texture = context->getTargetTexture(target);
4235
4236 if (!texture)
4237 {
Geoff Langb1196682014-07-23 13:47:29 -04004238 context->recordError(gl::Error(GL_INVALID_ENUM));
4239 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004240 }
4241
4242 switch (pname)
4243 {
4244 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4245 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4246 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4247 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4248 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4249 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4250 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4251 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4252 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4253 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4254 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4255 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4256 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4257 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4258 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4259 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4260 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4261 default: UNREACHABLE(); break;
4262 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004263 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004264}
4265
4266void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4267{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004268 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004269}
4270
4271void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4272{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004273 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004274
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 (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004279 {
Geoff Langbfdea662014-07-23 14:16:32 -04004280 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004281 }
Geoff Langbfdea662014-07-23 14:16:32 -04004282
4283 gl::Texture *texture = context->getTargetTexture(target);
4284
4285 if (!texture)
4286 {
Geoff Langb1196682014-07-23 13:47:29 -04004287 context->recordError(gl::Error(GL_INVALID_ENUM));
4288 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004289 }
4290
4291 switch (pname)
4292 {
4293 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4294 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4295 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4296 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4297 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4298 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4299 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4300 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4301 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4302 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4303 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4304 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4305 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4306 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4307 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4308 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4309 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4310 default: UNREACHABLE(); break;
4311 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004312 }
4313}
4314
4315void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4316{
4317 glTexParameteri(target, pname, *params);
4318}
4319
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004320void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4321{
4322 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4323 target, levels, internalformat, width, height);
4324
Geoff Langbfdea662014-07-23 14:16:32 -04004325 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004326 if (context)
4327 {
4328 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004329 {
Geoff Langb1196682014-07-23 13:47:29 -04004330 context->recordError(gl::Error(GL_INVALID_OPERATION));
4331 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004332 }
Geoff Langbfdea662014-07-23 14:16:32 -04004333
4334 if (context->getClientVersion() < 3 &&
4335 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4336 {
4337 return;
4338 }
4339
4340 if (context->getClientVersion() >= 3 &&
4341 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4342 {
4343 return;
4344 }
4345
4346 switch (target)
4347 {
4348 case GL_TEXTURE_2D:
4349 {
4350 gl::Texture2D *texture2d = context->getTexture2D();
4351 texture2d->storage(levels, internalformat, width, height);
4352 }
4353 break;
4354
4355 case GL_TEXTURE_CUBE_MAP:
4356 {
4357 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4358 textureCube->storage(levels, internalformat, width);
4359 }
4360 break;
4361
4362 default:
Geoff Langb1196682014-07-23 13:47:29 -04004363 context->recordError(gl::Error(GL_INVALID_ENUM));
4364 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004365 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004366 }
4367}
4368
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004369void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4370 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004371{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004372 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004373 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004374 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004375 target, level, xoffset, yoffset, width, height, format, type, pixels);
4376
Geoff Langbfdea662014-07-23 14:16:32 -04004377 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004378 if (context)
4379 {
4380 if (context->getClientVersion() < 3 &&
4381 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4382 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004383 {
Geoff Langbfdea662014-07-23 14:16:32 -04004384 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004385 }
Geoff Langbfdea662014-07-23 14:16:32 -04004386
4387 if (context->getClientVersion() >= 3 &&
4388 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4389 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4390 {
4391 return;
4392 }
4393
4394 // Zero sized uploads are valid but no-ops
4395 if (width == 0 || height == 0)
4396 {
4397 return;
4398 }
4399
4400 switch (target)
4401 {
4402 case GL_TEXTURE_2D:
4403 {
4404 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004405 gl::Error error = texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4406 if (error.isError())
4407 {
4408 context->recordError(error);
4409 return;
4410 }
Geoff Langbfdea662014-07-23 14:16:32 -04004411 }
4412 break;
4413
4414 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4415 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4416 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4417 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4418 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4419 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4420 {
4421 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004422 gl::Error error = texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4423 if (error.isError())
4424 {
4425 context->recordError(error);
4426 return;
4427 }
Geoff Langbfdea662014-07-23 14:16:32 -04004428 }
4429 break;
4430
4431 default:
4432 UNREACHABLE();
4433 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004434 }
4435}
4436
4437void __stdcall glUniform1f(GLint location, GLfloat x)
4438{
4439 glUniform1fv(location, 1, &x);
4440}
4441
4442void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4443{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004444 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004445
Geoff Langbfdea662014-07-23 14:16:32 -04004446 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004447 if (context)
4448 {
4449 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450 {
Geoff Langbfdea662014-07-23 14:16:32 -04004451 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452 }
Geoff Langbfdea662014-07-23 14:16:32 -04004453
4454 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4455 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004456 }
4457}
4458
4459void __stdcall glUniform1i(GLint location, GLint x)
4460{
4461 glUniform1iv(location, 1, &x);
4462}
4463
4464void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4465{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004466 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004467
Geoff Langbfdea662014-07-23 14:16:32 -04004468 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004469 if (context)
4470 {
4471 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004472 {
Geoff Langbfdea662014-07-23 14:16:32 -04004473 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004474 }
Geoff Langbfdea662014-07-23 14:16:32 -04004475
4476 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4477 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004478 }
4479}
4480
4481void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4482{
4483 GLfloat xy[2] = {x, y};
4484
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004485 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004486}
4487
4488void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4489{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004490 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004491
Geoff Langbfdea662014-07-23 14:16:32 -04004492 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004493 if (context)
4494 {
4495 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004496 {
Geoff Langbfdea662014-07-23 14:16:32 -04004497 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004498 }
Geoff Langbfdea662014-07-23 14:16:32 -04004499
4500 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4501 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004502 }
4503}
4504
4505void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4506{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004507 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004509 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004510}
4511
4512void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4513{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004514 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004515
Geoff Langbfdea662014-07-23 14:16:32 -04004516 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004517 if (context)
4518 {
4519 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004520 {
Geoff Langbfdea662014-07-23 14:16:32 -04004521 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004522 }
Geoff Langbfdea662014-07-23 14:16:32 -04004523
4524 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4525 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004526 }
4527}
4528
4529void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4530{
4531 GLfloat xyz[3] = {x, y, z};
4532
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004533 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004534}
4535
4536void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4537{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004538 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004539
Geoff Langbfdea662014-07-23 14:16:32 -04004540 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004541 if (context)
4542 {
4543 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004544 {
Geoff Langbfdea662014-07-23 14:16:32 -04004545 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004546 }
Geoff Langbfdea662014-07-23 14:16:32 -04004547
4548 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4549 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004550 }
4551}
4552
4553void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4554{
4555 GLint xyz[3] = {x, y, z};
4556
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004557 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004558}
4559
4560void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4561{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004562 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004563
Geoff Langbfdea662014-07-23 14:16:32 -04004564 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004565 if (context)
4566 {
4567 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004568 {
Geoff Langbfdea662014-07-23 14:16:32 -04004569 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004570 }
Geoff Langbfdea662014-07-23 14:16:32 -04004571
4572 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4573 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004574 }
4575}
4576
4577void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4578{
4579 GLfloat xyzw[4] = {x, y, z, w};
4580
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004581 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004582}
4583
4584void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4585{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004586 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
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 (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
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->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004598 }
4599}
4600
4601void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4602{
4603 GLint xyzw[4] = {x, y, z, w};
4604
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004605 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004606}
4607
4608void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4609{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004610 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004611
Geoff Langbfdea662014-07-23 14:16:32 -04004612 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004613 if (context)
4614 {
4615 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004616 {
Geoff Langbfdea662014-07-23 14:16:32 -04004617 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004618 }
Geoff Langbfdea662014-07-23 14:16:32 -04004619
4620 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4621 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004622 }
4623}
4624
4625void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4626{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004627 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004628 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004629
Geoff Langbfdea662014-07-23 14:16:32 -04004630 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004631 if (context)
4632 {
4633 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634 {
Geoff Langbfdea662014-07-23 14:16:32 -04004635 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004636 }
Geoff Langbfdea662014-07-23 14:16:32 -04004637
4638 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4639 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004640 }
4641}
4642
4643void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4644{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004645 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004646 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004647
Geoff Langbfdea662014-07-23 14:16:32 -04004648 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004649 if (context)
4650 {
4651 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004652 {
Geoff Langbfdea662014-07-23 14:16:32 -04004653 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004654 }
Geoff Langbfdea662014-07-23 14:16:32 -04004655
4656 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4657 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004658 }
4659}
4660
4661void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4662{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004663 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004664 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004665
Geoff Langbfdea662014-07-23 14:16:32 -04004666 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004667 if (context)
4668 {
4669 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670 {
Geoff Langbfdea662014-07-23 14:16:32 -04004671 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004672 }
Geoff Langbfdea662014-07-23 14:16:32 -04004673
4674 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4675 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004676 }
4677}
4678
4679void __stdcall glUseProgram(GLuint program)
4680{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004681 EVENT("(GLuint program = %d)", program);
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 Langbfdea662014-07-23 14:16:32 -04004686 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004687
Geoff Langbfdea662014-07-23 14:16:32 -04004688 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004689 {
Geoff Langbfdea662014-07-23 14:16:32 -04004690 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004691 {
Geoff Langb1196682014-07-23 13:47:29 -04004692 context->recordError(gl::Error(GL_INVALID_OPERATION));
4693 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004694 }
Geoff Langbfdea662014-07-23 14:16:32 -04004695 else
4696 {
Geoff Langb1196682014-07-23 13:47:29 -04004697 context->recordError(gl::Error(GL_INVALID_VALUE));
4698 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004699 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004700 }
Geoff Langbfdea662014-07-23 14:16:32 -04004701
4702 if (program != 0 && !programObject->isLinked())
4703 {
Geoff Langb1196682014-07-23 13:47:29 -04004704 context->recordError(gl::Error(GL_INVALID_OPERATION));
4705 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004706 }
4707
4708 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004709 }
4710}
4711
4712void __stdcall glValidateProgram(GLuint program)
4713{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004714 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004715
Geoff Langbfdea662014-07-23 14:16:32 -04004716 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004717 if (context)
4718 {
4719 gl::Program *programObject = context->getProgram(program);
4720
4721 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004722 {
Geoff Langbfdea662014-07-23 14:16:32 -04004723 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004724 {
Geoff Langb1196682014-07-23 13:47:29 -04004725 context->recordError(gl::Error(GL_INVALID_OPERATION));
4726 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004727 }
Geoff Langbfdea662014-07-23 14:16:32 -04004728 else
4729 {
Geoff Langb1196682014-07-23 13:47:29 -04004730 context->recordError(gl::Error(GL_INVALID_VALUE));
4731 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004732 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004733 }
Geoff Langbfdea662014-07-23 14:16:32 -04004734
Brandon Jones43a53e22014-08-28 16:23:22 -07004735 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004736 }
4737}
4738
4739void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4740{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004741 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004742
Geoff Langbfdea662014-07-23 14:16:32 -04004743 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004744 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004745 {
Geoff Langb1196682014-07-23 13:47:29 -04004746 if (index >= gl::MAX_VERTEX_ATTRIBS)
4747 {
4748 context->recordError(gl::Error(GL_INVALID_VALUE));
4749 return;
4750 }
4751
Geoff Langbfdea662014-07-23 14:16:32 -04004752 GLfloat vals[4] = { x, 0, 0, 1 };
4753 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004754 }
4755}
4756
4757void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4758{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004759 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004760
Geoff Langbfdea662014-07-23 14:16:32 -04004761 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004762 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004763 {
Geoff Langb1196682014-07-23 13:47:29 -04004764 if (index >= gl::MAX_VERTEX_ATTRIBS)
4765 {
4766 context->recordError(gl::Error(GL_INVALID_VALUE));
4767 return;
4768 }
4769
Geoff Langbfdea662014-07-23 14:16:32 -04004770 GLfloat vals[4] = { values[0], 0, 0, 1 };
4771 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004772 }
4773}
4774
4775void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004777 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004778
Geoff Langbfdea662014-07-23 14:16:32 -04004779 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004780 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004781 {
Geoff Langb1196682014-07-23 13:47:29 -04004782 if (index >= gl::MAX_VERTEX_ATTRIBS)
4783 {
4784 context->recordError(gl::Error(GL_INVALID_VALUE));
4785 return;
4786 }
4787
Geoff Langbfdea662014-07-23 14:16:32 -04004788 GLfloat vals[4] = { x, y, 0, 1 };
4789 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004790 }
4791}
4792
4793void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4794{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004795 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004796
Geoff Langbfdea662014-07-23 14:16:32 -04004797 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004798 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004799 {
Geoff Langb1196682014-07-23 13:47:29 -04004800 if (index >= gl::MAX_VERTEX_ATTRIBS)
4801 {
4802 context->recordError(gl::Error(GL_INVALID_VALUE));
4803 return;
4804 }
4805
Geoff Langbfdea662014-07-23 14:16:32 -04004806 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4807 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004808 }
4809}
4810
4811void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4812{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004813 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 +00004814
Geoff Langbfdea662014-07-23 14:16:32 -04004815 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004816 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004817 {
Geoff Langb1196682014-07-23 13:47:29 -04004818 if (index >= gl::MAX_VERTEX_ATTRIBS)
4819 {
4820 context->recordError(gl::Error(GL_INVALID_VALUE));
4821 return;
4822 }
4823
Geoff Langbfdea662014-07-23 14:16:32 -04004824 GLfloat vals[4] = { x, y, z, 1 };
4825 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004826 }
4827}
4828
4829void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4830{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004831 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004832
Geoff Langbfdea662014-07-23 14:16:32 -04004833 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004834 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004835 {
Geoff Langb1196682014-07-23 13:47:29 -04004836 if (index >= gl::MAX_VERTEX_ATTRIBS)
4837 {
4838 context->recordError(gl::Error(GL_INVALID_VALUE));
4839 return;
4840 }
4841
Geoff Langbfdea662014-07-23 14:16:32 -04004842 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4843 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004844 }
4845}
4846
4847void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4848{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004849 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 +00004850
Geoff Langbfdea662014-07-23 14:16:32 -04004851 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004852 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004853 {
Geoff Langb1196682014-07-23 13:47:29 -04004854 if (index >= gl::MAX_VERTEX_ATTRIBS)
4855 {
4856 context->recordError(gl::Error(GL_INVALID_VALUE));
4857 return;
4858 }
4859
Geoff Langbfdea662014-07-23 14:16:32 -04004860 GLfloat vals[4] = { x, y, z, w };
4861 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004862 }
4863}
4864
4865void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4866{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004867 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004868
Geoff Langbfdea662014-07-23 14:16:32 -04004869 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004870 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004871 {
Geoff Langb1196682014-07-23 13:47:29 -04004872 if (index >= gl::MAX_VERTEX_ATTRIBS)
4873 {
4874 context->recordError(gl::Error(GL_INVALID_VALUE));
4875 return;
4876 }
4877
Geoff Langbfdea662014-07-23 14:16:32 -04004878 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004879 }
4880}
4881
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004882void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4883{
4884 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4885
Geoff Langbfdea662014-07-23 14:16:32 -04004886 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004887 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004888 {
Geoff Langb1196682014-07-23 13:47:29 -04004889 if (index >= gl::MAX_VERTEX_ATTRIBS)
4890 {
4891 context->recordError(gl::Error(GL_INVALID_VALUE));
4892 return;
4893 }
4894
Geoff Langbfdea662014-07-23 14:16:32 -04004895 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004896 }
4897}
4898
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004899void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004900{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004901 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004902 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004903 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004904
Geoff Langbfdea662014-07-23 14:16:32 -04004905 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004906 if (context)
4907 {
Geoff Langb1196682014-07-23 13:47:29 -04004908 if (index >= gl::MAX_VERTEX_ATTRIBS)
4909 {
4910 context->recordError(gl::Error(GL_INVALID_VALUE));
4911 return;
4912 }
4913
4914 if (size < 1 || size > 4)
4915 {
4916 context->recordError(gl::Error(GL_INVALID_VALUE));
4917 return;
4918 }
4919
4920 switch (type)
4921 {
4922 case GL_BYTE:
4923 case GL_UNSIGNED_BYTE:
4924 case GL_SHORT:
4925 case GL_UNSIGNED_SHORT:
4926 case GL_FIXED:
4927 case GL_FLOAT:
4928 break;
4929
4930 case GL_HALF_FLOAT:
4931 case GL_INT:
4932 case GL_UNSIGNED_INT:
4933 case GL_INT_2_10_10_10_REV:
4934 case GL_UNSIGNED_INT_2_10_10_10_REV:
4935 if (context->getClientVersion() < 3)
4936 {
4937 context->recordError(gl::Error(GL_INVALID_ENUM));
4938 return;
4939 }
4940 break;
4941
4942 default:
4943 context->recordError(gl::Error(GL_INVALID_ENUM));
4944 return;
4945 }
4946
4947 if (stride < 0)
4948 {
4949 context->recordError(gl::Error(GL_INVALID_VALUE));
4950 return;
4951 }
4952
4953 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4954 {
4955 context->recordError(gl::Error(GL_INVALID_OPERATION));
4956 return;
4957 }
4958
Geoff Langbfdea662014-07-23 14:16:32 -04004959 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4960 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4961 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4962 // and the pointer argument is not NULL.
4963 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004964 {
Geoff Langb1196682014-07-23 13:47:29 -04004965 context->recordError(gl::Error(GL_INVALID_OPERATION));
4966 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004967 }
4968
Geoff Langbfdea662014-07-23 14:16:32 -04004969 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4970 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004971 }
4972}
4973
4974void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004976 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 +00004977
Geoff Langbfdea662014-07-23 14:16:32 -04004978 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004979 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004980 {
Geoff Langb1196682014-07-23 13:47:29 -04004981 if (width < 0 || height < 0)
4982 {
4983 context->recordError(gl::Error(GL_INVALID_VALUE));
4984 return;
4985 }
4986
Geoff Langbfdea662014-07-23 14:16:32 -04004987 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004988 }
4989}
4990
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004991// OpenGL ES 3.0 functions
4992
4993void __stdcall glReadBuffer(GLenum mode)
4994{
4995 EVENT("(GLenum mode = 0x%X)", mode);
4996
Geoff Langbfdea662014-07-23 14:16:32 -04004997 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004998 if (context)
4999 {
5000 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005001 {
Geoff Langb1196682014-07-23 13:47:29 -04005002 context->recordError(gl::Error(GL_INVALID_OPERATION));
5003 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005004 }
Geoff Langbfdea662014-07-23 14:16:32 -04005005
5006 // glReadBuffer
5007 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005008 }
5009}
5010
5011void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
5012{
5013 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
5014 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
5015
Geoff Langbfdea662014-07-23 14:16:32 -04005016 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005017 if (context)
5018 {
5019 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005020 {
Geoff Langb1196682014-07-23 13:47:29 -04005021 context->recordError(gl::Error(GL_INVALID_OPERATION));
5022 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005023 }
Geoff Langbfdea662014-07-23 14:16:32 -04005024
5025 // glDrawRangeElements
5026 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005027 }
5028}
5029
5030void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
5031{
5032 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
5033 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
5034 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5035 target, level, internalformat, width, height, depth, border, format, type, pixels);
5036
Geoff Langbfdea662014-07-23 14:16:32 -04005037 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005038 if (context)
5039 {
5040 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005041 {
Geoff Langb1196682014-07-23 13:47:29 -04005042 context->recordError(gl::Error(GL_INVALID_OPERATION));
5043 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005044 }
Geoff Langbfdea662014-07-23 14:16:32 -04005045
5046 // validateES3TexImageFormat sets the error code if there is an error
5047 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
5048 0, 0, 0, width, height, depth, border, format, type, pixels))
5049 {
5050 return;
5051 }
5052
5053 switch(target)
5054 {
5055 case GL_TEXTURE_3D:
5056 {
5057 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005058 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5059 if (error.isError())
5060 {
5061 context->recordError(error);
5062 return;
5063 }
Geoff Langbfdea662014-07-23 14:16:32 -04005064 }
5065 break;
5066
5067 case GL_TEXTURE_2D_ARRAY:
5068 {
5069 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005070 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5071 if (error.isError())
5072 {
5073 context->recordError(error);
5074 return;
5075 }
Geoff Langbfdea662014-07-23 14:16:32 -04005076 }
5077 break;
5078
5079 default:
Geoff Langb1196682014-07-23 13:47:29 -04005080 context->recordError(gl::Error(GL_INVALID_ENUM));
5081 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005082 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005083 }
5084}
5085
5086void __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)
5087{
5088 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5089 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5090 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5091 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
5092
Geoff Langbfdea662014-07-23 14:16:32 -04005093 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005094 if (context)
5095 {
5096 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005097 {
Geoff Langb1196682014-07-23 13:47:29 -04005098 context->recordError(gl::Error(GL_INVALID_OPERATION));
5099 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005100 }
Geoff Langbfdea662014-07-23 14:16:32 -04005101
5102 // validateES3TexImageFormat sets the error code if there is an error
5103 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5104 xoffset, yoffset, zoffset, width, height, depth, 0,
5105 format, type, pixels))
5106 {
5107 return;
5108 }
5109
5110 // Zero sized uploads are valid but no-ops
5111 if (width == 0 || height == 0 || depth == 0)
5112 {
5113 return;
5114 }
5115
5116 switch(target)
5117 {
5118 case GL_TEXTURE_3D:
5119 {
5120 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005121 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5122 if (error.isError())
5123 {
5124 context->recordError(error);
5125 return;
5126 }
Geoff Langbfdea662014-07-23 14:16:32 -04005127 }
5128 break;
5129
5130 case GL_TEXTURE_2D_ARRAY:
5131 {
5132 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005133 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5134 if (error.isError())
5135 {
5136 context->recordError(error);
5137 return;
5138 }
Geoff Langbfdea662014-07-23 14:16:32 -04005139 }
5140 break;
5141
5142 default:
Geoff Langb1196682014-07-23 13:47:29 -04005143 context->recordError(gl::Error(GL_INVALID_ENUM));
5144 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005145 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005146 }
5147}
5148
5149void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5150{
5151 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5152 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5153 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5154
Geoff Langbfdea662014-07-23 14:16:32 -04005155 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005156 if (context)
5157 {
5158 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005159 {
Geoff Langb1196682014-07-23 13:47:29 -04005160 context->recordError(gl::Error(GL_INVALID_OPERATION));
5161 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005162 }
Geoff Langbfdea662014-07-23 14:16:32 -04005163
5164 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5165 x, y, width, height, 0))
5166 {
5167 return;
5168 }
5169
5170 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5171 gl::Texture *texture = NULL;
5172 switch (target)
5173 {
5174 case GL_TEXTURE_3D:
5175 texture = context->getTexture3D();
5176 break;
5177
5178 case GL_TEXTURE_2D_ARRAY:
5179 texture = context->getTexture2DArray();
5180 break;
5181
5182 default:
Geoff Langb1196682014-07-23 13:47:29 -04005183 context->recordError(gl::Error(GL_INVALID_ENUM));
5184 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005185 }
5186
5187 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005188 }
5189}
5190
5191void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5192{
Geoff Langeef52cc2013-10-16 15:07:39 -04005193 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 +00005194 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5195 "const GLvoid* data = 0x%0.8p)",
5196 target, level, internalformat, width, height, depth, border, imageSize, data);
5197
Geoff Langbfdea662014-07-23 14:16:32 -04005198 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005199 if (context)
5200 {
5201 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005202 {
Geoff Langb1196682014-07-23 13:47:29 -04005203 context->recordError(gl::Error(GL_INVALID_OPERATION));
5204 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005205 }
Geoff Langbfdea662014-07-23 14:16:32 -04005206
Geoff Lang5d601382014-07-22 15:14:06 -04005207 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5208 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005209 {
Geoff Langb1196682014-07-23 13:47:29 -04005210 context->recordError(gl::Error(GL_INVALID_VALUE));
5211 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005212 }
5213
5214 // validateES3TexImageFormat sets the error code if there is an error
5215 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5216 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5217 {
5218 return;
5219 }
5220
5221 switch(target)
5222 {
5223 case GL_TEXTURE_3D:
5224 {
5225 gl::Texture3D *texture = context->getTexture3D();
Geoff Langb5348332014-09-02 13:16:34 -04005226 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5227 if (error.isError())
5228 {
5229 context->recordError(error);
5230 return;
5231 }
Geoff Langbfdea662014-07-23 14:16:32 -04005232 }
5233 break;
5234
5235 case GL_TEXTURE_2D_ARRAY:
5236 {
5237 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Langb5348332014-09-02 13:16:34 -04005238 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5239 if (error.isError())
5240 {
5241 context->recordError(error);
5242 return;
5243 }
Geoff Langbfdea662014-07-23 14:16:32 -04005244 }
5245 break;
5246
5247 default:
Geoff Langb1196682014-07-23 13:47:29 -04005248 context->recordError(gl::Error(GL_INVALID_ENUM));
5249 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005250 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005251 }
5252}
5253
5254void __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)
5255{
5256 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5257 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5258 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5259 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
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;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005268 }
Geoff Langbfdea662014-07-23 14:16:32 -04005269
Geoff Lang5d601382014-07-22 15:14:06 -04005270 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5271 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005272 {
Geoff Langb1196682014-07-23 13:47:29 -04005273 context->recordError(gl::Error(GL_INVALID_VALUE));
5274 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005275 }
5276
5277 if (!data)
5278 {
Geoff Langb1196682014-07-23 13:47:29 -04005279 context->recordError(gl::Error(GL_INVALID_VALUE));
5280 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005281 }
5282
5283 // validateES3TexImageFormat sets the error code if there is an error
5284 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5285 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5286 {
5287 return;
5288 }
5289
5290 // Zero sized uploads are valid but no-ops
5291 if (width == 0 || height == 0)
5292 {
5293 return;
5294 }
5295
5296 switch(target)
5297 {
5298 case GL_TEXTURE_3D:
5299 {
5300 gl::Texture3D *texture = context->getTexture3D();
Geoff Langb5348332014-09-02 13:16:34 -04005301 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5302 format, imageSize, data);
5303 if (error.isError())
5304 {
5305 context->recordError(error);
5306 return;
5307 }
Geoff Langbfdea662014-07-23 14:16:32 -04005308 }
5309 break;
5310
5311 case GL_TEXTURE_2D_ARRAY:
5312 {
5313 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Langb5348332014-09-02 13:16:34 -04005314 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5315 format, imageSize, data);
5316 if (error.isError())
5317 {
5318 context->recordError(error);
5319 return;
5320 }
Geoff Langbfdea662014-07-23 14:16:32 -04005321 }
5322 break;
5323
Geoff Langb1196682014-07-23 13:47:29 -04005324 default:
5325 context->recordError(gl::Error(GL_INVALID_ENUM));
5326 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005327 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005328 }
5329}
5330
5331void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5332{
5333 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5334
Geoff Langbfdea662014-07-23 14:16:32 -04005335 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005336 if (context)
5337 {
5338 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005339 {
Geoff Langb1196682014-07-23 13:47:29 -04005340 context->recordError(gl::Error(GL_INVALID_OPERATION));
5341 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005342 }
Geoff Langbfdea662014-07-23 14:16:32 -04005343
5344 if (n < 0)
5345 {
Geoff Langb1196682014-07-23 13:47:29 -04005346 context->recordError(gl::Error(GL_INVALID_VALUE));
5347 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005348 }
5349
5350 for (GLsizei i = 0; i < n; i++)
5351 {
5352 ids[i] = context->createQuery();
5353 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005354 }
5355}
5356
5357void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5358{
5359 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5360
Geoff Langbfdea662014-07-23 14:16:32 -04005361 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005362 if (context)
5363 {
5364 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005365 {
Geoff Langb1196682014-07-23 13:47:29 -04005366 context->recordError(gl::Error(GL_INVALID_OPERATION));
5367 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005368 }
Geoff Langbfdea662014-07-23 14:16:32 -04005369
5370 if (n < 0)
5371 {
Geoff Langb1196682014-07-23 13:47:29 -04005372 context->recordError(gl::Error(GL_INVALID_VALUE));
5373 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005374 }
5375
5376 for (GLsizei i = 0; i < n; i++)
5377 {
5378 context->deleteQuery(ids[i]);
5379 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005380 }
5381}
5382
5383GLboolean __stdcall glIsQuery(GLuint id)
5384{
5385 EVENT("(GLuint id = %u)", id);
5386
Geoff Langbfdea662014-07-23 14:16:32 -04005387 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005388 if (context)
5389 {
5390 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005391 {
Geoff Langb1196682014-07-23 13:47:29 -04005392 context->recordError(gl::Error(GL_INVALID_OPERATION));
5393 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005394 }
Geoff Langbfdea662014-07-23 14:16:32 -04005395
5396 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005397 }
5398
5399 return GL_FALSE;
5400}
5401
5402void __stdcall glBeginQuery(GLenum target, GLuint id)
5403{
5404 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5405
Geoff Langbfdea662014-07-23 14:16:32 -04005406 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005407 if (context)
5408 {
5409 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005410 {
Geoff Langb1196682014-07-23 13:47:29 -04005411 context->recordError(gl::Error(GL_INVALID_OPERATION));
5412 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005413 }
Geoff Langbfdea662014-07-23 14:16:32 -04005414
5415 if (!ValidateBeginQuery(context, target, id))
5416 {
5417 return;
5418 }
Geoff Lang5aad9672014-09-08 11:10:42 -04005419
5420 gl::Error error = context->beginQuery(target, id);
5421 if (error.isError())
5422 {
5423 context->recordError(error);
5424 return;
5425 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005426 }
5427}
5428
5429void __stdcall glEndQuery(GLenum target)
5430{
5431 EVENT("(GLenum target = 0x%X)", target);
5432
Geoff Langbfdea662014-07-23 14:16:32 -04005433 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005434 if (context)
5435 {
5436 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005437 {
Geoff Langb1196682014-07-23 13:47:29 -04005438 context->recordError(gl::Error(GL_INVALID_OPERATION));
5439 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005440 }
Geoff Langbfdea662014-07-23 14:16:32 -04005441
5442 if (!ValidateEndQuery(context, target))
5443 {
5444 return;
5445 }
5446
Geoff Lang5aad9672014-09-08 11:10:42 -04005447 gl::Error error = context->endQuery(target);
5448 if (error.isError())
5449 {
5450 context->recordError(error);
5451 return;
5452 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005453 }
5454}
5455
5456void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5457{
5458 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5459
Geoff Langbfdea662014-07-23 14:16:32 -04005460 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005461 if (context)
5462 {
5463 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005464 {
Geoff Langb1196682014-07-23 13:47:29 -04005465 context->recordError(gl::Error(GL_INVALID_OPERATION));
5466 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005467 }
Geoff Langbfdea662014-07-23 14:16:32 -04005468
5469 if (!ValidQueryType(context, target))
5470 {
Geoff Langb1196682014-07-23 13:47:29 -04005471 context->recordError(gl::Error(GL_INVALID_ENUM));
5472 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005473 }
5474
5475 switch (pname)
5476 {
5477 case GL_CURRENT_QUERY:
5478 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5479 break;
5480
5481 default:
Geoff Langb1196682014-07-23 13:47:29 -04005482 context->recordError(gl::Error(GL_INVALID_ENUM));
5483 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005484 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005485 }
5486}
5487
5488void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5489{
5490 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5491
Geoff Langbfdea662014-07-23 14:16:32 -04005492 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005493 if (context)
5494 {
5495 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005496 {
Geoff Langb1196682014-07-23 13:47:29 -04005497 context->recordError(gl::Error(GL_INVALID_OPERATION));
5498 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005499 }
Geoff Langbfdea662014-07-23 14:16:32 -04005500
5501 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5502
5503 if (!queryObject)
5504 {
Geoff Langb1196682014-07-23 13:47:29 -04005505 context->recordError(gl::Error(GL_INVALID_OPERATION));
5506 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005507 }
5508
5509 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5510 {
Geoff Langb1196682014-07-23 13:47:29 -04005511 context->recordError(gl::Error(GL_INVALID_OPERATION));
5512 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005513 }
5514
5515 switch(pname)
5516 {
Geoff Lang5aad9672014-09-08 11:10:42 -04005517 case GL_QUERY_RESULT_EXT:
5518 {
5519 gl::Error error = queryObject->getResult(params);
5520 if (error.isError())
5521 {
5522 context->recordError(error);
5523 return;
5524 }
5525 }
Geoff Langbfdea662014-07-23 14:16:32 -04005526 break;
Geoff Langb1196682014-07-23 13:47:29 -04005527
Geoff Lang5aad9672014-09-08 11:10:42 -04005528 case GL_QUERY_RESULT_AVAILABLE_EXT:
5529 {
5530 gl::Error error = queryObject->isResultAvailable(params);
5531 if (error.isError())
5532 {
5533 context->recordError(error);
5534 return;
5535 }
5536 }
Geoff Langbfdea662014-07-23 14:16:32 -04005537 break;
Geoff Langb1196682014-07-23 13:47:29 -04005538
Geoff Langbfdea662014-07-23 14:16:32 -04005539 default:
Geoff Langb1196682014-07-23 13:47:29 -04005540 context->recordError(gl::Error(GL_INVALID_ENUM));
5541 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005543 }
5544}
5545
5546GLboolean __stdcall glUnmapBuffer(GLenum target)
5547{
5548 EVENT("(GLenum target = 0x%X)", target);
5549
Geoff Langbfdea662014-07-23 14:16:32 -04005550 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005551 if (context)
5552 {
5553 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005554 {
Geoff Langb1196682014-07-23 13:47:29 -04005555 context->recordError(gl::Error(GL_INVALID_OPERATION));
5556 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005557 }
Geoff Langbfdea662014-07-23 14:16:32 -04005558
5559 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005560 }
5561
5562 return GL_FALSE;
5563}
5564
5565void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5566{
5567 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5568
Geoff Langbfdea662014-07-23 14:16:32 -04005569 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005570 if (context)
5571 {
5572 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005573 {
Geoff Langb1196682014-07-23 13:47:29 -04005574 context->recordError(gl::Error(GL_INVALID_OPERATION));
5575 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005576 }
Geoff Langbfdea662014-07-23 14:16:32 -04005577
5578 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005579 }
5580}
5581
5582void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5583{
Geoff Langbfdea662014-07-23 14:16:32 -04005584 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005585 if (context)
5586 {
5587 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005588 {
Geoff Langb1196682014-07-23 13:47:29 -04005589 context->recordError(gl::Error(GL_INVALID_OPERATION));
5590 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005591 }
Geoff Langbfdea662014-07-23 14:16:32 -04005592
5593 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005594 }
5595}
5596
5597void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5598{
5599 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5600 location, count, transpose, value);
5601
Geoff Langbfdea662014-07-23 14:16:32 -04005602 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005603 if (context)
5604 {
5605 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005606 {
Geoff Langbfdea662014-07-23 14:16:32 -04005607 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005608 }
Geoff Langbfdea662014-07-23 14:16:32 -04005609
5610 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5611 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005612 }
5613}
5614
5615void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5616{
5617 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5618 location, count, transpose, value);
5619
Geoff Langbfdea662014-07-23 14:16:32 -04005620 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005621 if (context)
5622 {
5623 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005624 {
Geoff Langbfdea662014-07-23 14:16:32 -04005625 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005626 }
Geoff Langbfdea662014-07-23 14:16:32 -04005627
5628 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5629 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005630 }
5631}
5632
5633void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5634{
5635 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5636 location, count, transpose, value);
5637
Geoff Langbfdea662014-07-23 14:16:32 -04005638 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005639 if (context)
5640 {
5641 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005642 {
Geoff Langbfdea662014-07-23 14:16:32 -04005643 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005644 }
Geoff Langbfdea662014-07-23 14:16:32 -04005645
5646 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5647 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005648 }
5649}
5650
5651void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5652{
5653 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5654 location, count, transpose, value);
5655
Geoff Langbfdea662014-07-23 14:16:32 -04005656 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005657 if (context)
5658 {
5659 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005660 {
Geoff Langbfdea662014-07-23 14:16:32 -04005661 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005662 }
Geoff Langbfdea662014-07-23 14:16:32 -04005663
5664 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5665 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005666 }
5667}
5668
5669void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5670{
5671 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5672 location, count, transpose, value);
5673
Geoff Langbfdea662014-07-23 14:16:32 -04005674 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005675 if (context)
5676 {
5677 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005678 {
Geoff Langbfdea662014-07-23 14:16:32 -04005679 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005680 }
Geoff Langbfdea662014-07-23 14:16:32 -04005681
5682 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5683 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005684 }
5685}
5686
5687void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5688{
5689 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5690 location, count, transpose, value);
5691
Geoff Langbfdea662014-07-23 14:16:32 -04005692 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005693 if (context)
5694 {
5695 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005696 {
Geoff Langbfdea662014-07-23 14:16:32 -04005697 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005698 }
Geoff Langbfdea662014-07-23 14:16:32 -04005699
5700 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5701 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005702 }
5703}
5704
5705void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5706{
5707 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5708 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5709 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5710
Geoff Langbfdea662014-07-23 14:16:32 -04005711 gl::Context *context = gl::getNonLostContext();
5712 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005713 {
Geoff Langbfdea662014-07-23 14:16:32 -04005714 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005715 {
Geoff Langb1196682014-07-23 13:47:29 -04005716 context->recordError(gl::Error(GL_INVALID_OPERATION));
5717 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005718 }
Geoff Langbfdea662014-07-23 14:16:32 -04005719
5720 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5721 dstX0, dstY0, dstX1, dstY1, mask, filter,
5722 false))
5723 {
5724 return;
5725 }
5726
Geoff Lang64839152014-08-26 16:23:25 -04005727 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5728 mask, filter);
5729 if (error.isError())
5730 {
5731 context->recordError(error);
5732 return;
5733 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005734 }
5735}
5736
5737void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5738{
5739 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5740 target, samples, internalformat, width, height);
5741
Geoff Langbfdea662014-07-23 14:16:32 -04005742 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005743 if (context)
5744 {
5745 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005746 {
Geoff Langb1196682014-07-23 13:47:29 -04005747 context->recordError(gl::Error(GL_INVALID_OPERATION));
5748 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005749 }
Geoff Langbfdea662014-07-23 14:16:32 -04005750
5751 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5752 width, height, false))
5753 {
5754 return;
5755 }
5756
5757 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005758 }
5759}
5760
5761void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5762{
5763 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5764 target, attachment, texture, level, layer);
5765
Geoff Langbfdea662014-07-23 14:16:32 -04005766 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005767 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005768 {
Geoff Langbfdea662014-07-23 14:16:32 -04005769 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5770 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005771 {
Geoff Langbfdea662014-07-23 14:16:32 -04005772 return;
5773 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005774
Geoff Langbfdea662014-07-23 14:16:32 -04005775 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5776 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005777
Geoff Langbfdea662014-07-23 14:16:32 -04005778 gl::Texture *textureObject = context->getTexture(texture);
5779 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005780
Geoff Langbfdea662014-07-23 14:16:32 -04005781 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5782 {
5783 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5784 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5785 }
5786 else
5787 {
5788 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005789 {
Geoff Langbfdea662014-07-23 14:16:32 -04005790 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5791 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5792 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005793 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005794 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005795 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005796}
5797
5798GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5799{
5800 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5801 target, offset, length, access);
5802
Geoff Langbfdea662014-07-23 14:16:32 -04005803 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005804 if (context)
5805 {
5806 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005807 {
Geoff Langb1196682014-07-23 13:47:29 -04005808 context->recordError(gl::Error(GL_INVALID_OPERATION));
5809 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005810 }
Geoff Langbfdea662014-07-23 14:16:32 -04005811
5812 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005813 }
5814
5815 return NULL;
5816}
5817
5818void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5819{
5820 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5821
Geoff Langbfdea662014-07-23 14:16:32 -04005822 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005823 if (context)
5824 {
5825 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005826 {
Geoff Langb1196682014-07-23 13:47:29 -04005827 context->recordError(gl::Error(GL_INVALID_OPERATION));
5828 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005829 }
Geoff Langbfdea662014-07-23 14:16:32 -04005830
5831 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005832 }
5833}
5834
5835void __stdcall glBindVertexArray(GLuint array)
5836{
5837 EVENT("(GLuint array = %u)", array);
5838
Geoff Langbfdea662014-07-23 14:16:32 -04005839 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005840 if (context)
5841 {
5842 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005843 {
Geoff Langb1196682014-07-23 13:47:29 -04005844 context->recordError(gl::Error(GL_INVALID_OPERATION));
5845 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005846 }
Geoff Langbfdea662014-07-23 14:16:32 -04005847
5848 gl::VertexArray *vao = context->getVertexArray(array);
5849
5850 if (!vao)
5851 {
5852 // The default VAO should always exist
5853 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005854 context->recordError(gl::Error(GL_INVALID_OPERATION));
5855 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005856 }
5857
5858 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005859 }
5860}
5861
5862void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5863{
5864 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5865
Geoff Langbfdea662014-07-23 14:16:32 -04005866 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005867 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005868 {
Geoff Langbfdea662014-07-23 14:16:32 -04005869 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005870 {
Geoff Langb1196682014-07-23 13:47:29 -04005871 context->recordError(gl::Error(GL_INVALID_OPERATION));
5872 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005873 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005874
Geoff Langbfdea662014-07-23 14:16:32 -04005875 if (n < 0)
5876 {
Geoff Langb1196682014-07-23 13:47:29 -04005877 context->recordError(gl::Error(GL_INVALID_VALUE));
5878 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005879 }
Jamie Madilld1028542013-07-02 11:57:04 -04005880
Geoff Langbfdea662014-07-23 14:16:32 -04005881 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5882 {
5883 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005884 {
Geoff Langbfdea662014-07-23 14:16:32 -04005885 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005886 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005887 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005888 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005889}
5890
5891void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5892{
5893 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5894
Geoff Langbfdea662014-07-23 14:16:32 -04005895 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005896 if (context)
5897 {
5898 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005899 {
Geoff Langb1196682014-07-23 13:47:29 -04005900 context->recordError(gl::Error(GL_INVALID_OPERATION));
5901 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005902 }
Geoff Langbfdea662014-07-23 14:16:32 -04005903
5904 if (n < 0)
5905 {
Geoff Langb1196682014-07-23 13:47:29 -04005906 context->recordError(gl::Error(GL_INVALID_VALUE));
5907 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005908 }
5909
5910 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5911 {
5912 arrays[arrayIndex] = context->createVertexArray();
5913 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005914 }
5915}
5916
5917GLboolean __stdcall glIsVertexArray(GLuint array)
5918{
5919 EVENT("(GLuint array = %u)", array);
5920
Geoff Langbfdea662014-07-23 14:16:32 -04005921 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005922 if (context)
5923 {
5924 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005925 {
Geoff Langb1196682014-07-23 13:47:29 -04005926 context->recordError(gl::Error(GL_INVALID_OPERATION));
5927 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005928 }
Geoff Langbfdea662014-07-23 14:16:32 -04005929
5930 if (array == 0)
5931 {
5932 return GL_FALSE;
5933 }
5934
5935 gl::VertexArray *vao = context->getVertexArray(array);
5936
5937 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005938 }
5939
5940 return GL_FALSE;
5941}
5942
5943void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5944{
5945 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5946 target, index, data);
5947
Geoff Langbfdea662014-07-23 14:16:32 -04005948 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005949 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005950 {
Geoff Langbfdea662014-07-23 14:16:32 -04005951 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005952 {
Geoff Langb1196682014-07-23 13:47:29 -04005953 context->recordError(gl::Error(GL_INVALID_OPERATION));
5954 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005955 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005956
Geoff Lang3a61c322014-07-10 13:01:54 -04005957 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005958 switch (target)
5959 {
5960 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5961 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5962 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005963 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5964 {
Geoff Langb1196682014-07-23 13:47:29 -04005965 context->recordError(gl::Error(GL_INVALID_VALUE));
5966 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005967 }
Geoff Langbfdea662014-07-23 14:16:32 -04005968 break;
Geoff Langb1196682014-07-23 13:47:29 -04005969
Geoff Langbfdea662014-07-23 14:16:32 -04005970 case GL_UNIFORM_BUFFER_START:
5971 case GL_UNIFORM_BUFFER_SIZE:
5972 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005973 if (index >= caps.maxCombinedUniformBlocks)
5974 {
Geoff Langb1196682014-07-23 13:47:29 -04005975 context->recordError(gl::Error(GL_INVALID_VALUE));
5976 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005977 }
Geoff Langbfdea662014-07-23 14:16:32 -04005978 break;
Geoff Langb1196682014-07-23 13:47:29 -04005979
Geoff Langbfdea662014-07-23 14:16:32 -04005980 default:
Geoff Langb1196682014-07-23 13:47:29 -04005981 context->recordError(gl::Error(GL_INVALID_ENUM));
5982 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005983 }
5984
5985 if (!(context->getIndexedIntegerv(target, index, data)))
5986 {
5987 GLenum nativeType;
5988 unsigned int numParams = 0;
5989 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005990 {
5991 context->recordError(gl::Error(GL_INVALID_ENUM));
5992 return;
5993 }
Shannon Woods15934d52013-08-19 14:28:49 -04005994
Geoff Langbfdea662014-07-23 14:16:32 -04005995 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005996 {
Geoff Langbfdea662014-07-23 14:16:32 -04005997 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005998 }
Geoff Langbfdea662014-07-23 14:16:32 -04005999
6000 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04006001 {
Geoff Langbfdea662014-07-23 14:16:32 -04006002 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
6003 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
6004 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04006005
Geoff Langbfdea662014-07-23 14:16:32 -04006006 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04006007
Geoff Langbfdea662014-07-23 14:16:32 -04006008 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04006009 {
Geoff Langbfdea662014-07-23 14:16:32 -04006010 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
6011 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04006012 }
Geoff Langbfdea662014-07-23 14:16:32 -04006013
6014 delete [] int64Params;
6015 }
6016 else
6017 {
6018 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04006019 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006021 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006022}
6023
6024void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
6025{
6026 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
6027
Geoff Langbfdea662014-07-23 14:16:32 -04006028 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006029 if (context)
6030 {
6031 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006032 {
Geoff Langb1196682014-07-23 13:47:29 -04006033 context->recordError(gl::Error(GL_INVALID_OPERATION));
6034 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006035 }
Geoff Langbfdea662014-07-23 14:16:32 -04006036
6037 switch (primitiveMode)
6038 {
6039 case GL_TRIANGLES:
6040 case GL_LINES:
6041 case GL_POINTS:
6042 break;
Geoff Langb1196682014-07-23 13:47:29 -04006043
Geoff Langbfdea662014-07-23 14:16:32 -04006044 default:
Geoff Langb1196682014-07-23 13:47:29 -04006045 context->recordError(gl::Error(GL_INVALID_ENUM));
6046 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006047 }
6048
6049 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6050 ASSERT(transformFeedback != NULL);
6051
6052 if (transformFeedback->isStarted())
6053 {
Geoff Langb1196682014-07-23 13:47:29 -04006054 context->recordError(gl::Error(GL_INVALID_OPERATION));
6055 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006056 }
6057
6058 if (transformFeedback->isPaused())
6059 {
6060 transformFeedback->resume();
6061 }
6062 else
6063 {
6064 transformFeedback->start(primitiveMode);
6065 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006066 }
6067}
6068
6069void __stdcall glEndTransformFeedback(void)
6070{
6071 EVENT("(void)");
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;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006080 }
Geoff Langbfdea662014-07-23 14:16:32 -04006081
6082 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6083 ASSERT(transformFeedback != NULL);
6084
6085 if (!transformFeedback->isStarted())
6086 {
Geoff Langb1196682014-07-23 13:47:29 -04006087 context->recordError(gl::Error(GL_INVALID_OPERATION));
6088 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006089 }
6090
6091 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006092 }
6093}
6094
6095void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
6096{
6097 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
6098 target, index, buffer, offset, size);
6099
Geoff Langbfdea662014-07-23 14:16:32 -04006100 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006101 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006102 {
Geoff Langbfdea662014-07-23 14:16:32 -04006103 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006104 {
Geoff Langb1196682014-07-23 13:47:29 -04006105 context->recordError(gl::Error(GL_INVALID_OPERATION));
6106 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006107 }
6108
Geoff Lang3a61c322014-07-10 13:01:54 -04006109 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006110 switch (target)
6111 {
6112 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006113 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006114 {
Geoff Langb1196682014-07-23 13:47:29 -04006115 context->recordError(gl::Error(GL_INVALID_VALUE));
6116 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006117 }
Geoff Langbfdea662014-07-23 14:16:32 -04006118 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006119
Geoff Langbfdea662014-07-23 14:16:32 -04006120 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006121 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006122 {
Geoff Langb1196682014-07-23 13:47:29 -04006123 context->recordError(gl::Error(GL_INVALID_VALUE));
6124 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006125 }
Geoff Langbfdea662014-07-23 14:16:32 -04006126 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006127
Geoff Langbfdea662014-07-23 14:16:32 -04006128 default:
Geoff Langb1196682014-07-23 13:47:29 -04006129 context->recordError(gl::Error(GL_INVALID_ENUM));
6130 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006131 }
6132
6133 if (buffer != 0 && size <= 0)
6134 {
Geoff Langb1196682014-07-23 13:47:29 -04006135 context->recordError(gl::Error(GL_INVALID_VALUE));
6136 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006137 }
6138
6139 switch (target)
6140 {
6141 case GL_TRANSFORM_FEEDBACK_BUFFER:
6142
6143 // size and offset must be a multiple of 4
6144 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006145 {
Geoff Langb1196682014-07-23 13:47:29 -04006146 context->recordError(gl::Error(GL_INVALID_VALUE));
6147 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006148 }
6149
Geoff Langbfdea662014-07-23 14:16:32 -04006150 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
6151 context->bindGenericTransformFeedbackBuffer(buffer);
6152 break;
6153
6154 case GL_UNIFORM_BUFFER:
6155
6156 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006157 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006158 {
Geoff Langb1196682014-07-23 13:47:29 -04006159 context->recordError(gl::Error(GL_INVALID_VALUE));
6160 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006161 }
Geoff Langbfdea662014-07-23 14:16:32 -04006162
6163 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6164 context->bindGenericUniformBuffer(buffer);
6165 break;
6166
6167 default:
6168 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006169 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006170 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006171}
6172
6173void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
6174{
6175 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6176 target, index, buffer);
6177
Geoff Langbfdea662014-07-23 14:16:32 -04006178 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006179 if (context)
6180 {
6181 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006182 {
Geoff Langb1196682014-07-23 13:47:29 -04006183 context->recordError(gl::Error(GL_INVALID_OPERATION));
6184 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006185 }
Geoff Langbfdea662014-07-23 14:16:32 -04006186
Geoff Lang3a61c322014-07-10 13:01:54 -04006187 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006188 switch (target)
6189 {
6190 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006191 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006192 {
Geoff Langb1196682014-07-23 13:47:29 -04006193 context->recordError(gl::Error(GL_INVALID_VALUE));
6194 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006195 }
6196 break;
6197
6198 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006199 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006200 {
Geoff Langb1196682014-07-23 13:47:29 -04006201 context->recordError(gl::Error(GL_INVALID_VALUE));
6202 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006203 }
6204 break;
6205
6206 default:
Geoff Langb1196682014-07-23 13:47:29 -04006207 context->recordError(gl::Error(GL_INVALID_ENUM));
6208 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006209 }
6210
6211 switch (target)
6212 {
6213 case GL_TRANSFORM_FEEDBACK_BUFFER:
6214 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6215 context->bindGenericTransformFeedbackBuffer(buffer);
6216 break;
6217
6218 case GL_UNIFORM_BUFFER:
6219 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6220 context->bindGenericUniformBuffer(buffer);
6221 break;
6222
6223 default:
6224 UNREACHABLE();
6225 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006226 }
6227}
6228
6229void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6230{
6231 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6232 program, count, varyings, bufferMode);
6233
Geoff Langbfdea662014-07-23 14:16:32 -04006234 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006235 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006236 {
Geoff Langbfdea662014-07-23 14:16:32 -04006237 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006238 {
Geoff Langb1196682014-07-23 13:47:29 -04006239 context->recordError(gl::Error(GL_INVALID_OPERATION));
6240 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006241 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006242
Geoff Langbfdea662014-07-23 14:16:32 -04006243 if (count < 0)
6244 {
Geoff Langb1196682014-07-23 13:47:29 -04006245 context->recordError(gl::Error(GL_INVALID_VALUE));
6246 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006247 }
6248
Geoff Lang05881a02014-07-10 14:05:30 -04006249 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006250 switch (bufferMode)
6251 {
6252 case GL_INTERLEAVED_ATTRIBS:
6253 break;
6254 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006255 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006256 {
Geoff Langb1196682014-07-23 13:47:29 -04006257 context->recordError(gl::Error(GL_INVALID_VALUE));
6258 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006259 }
Geoff Langbfdea662014-07-23 14:16:32 -04006260 break;
6261 default:
Geoff Langb1196682014-07-23 13:47:29 -04006262 context->recordError(gl::Error(GL_INVALID_ENUM));
6263 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006264 }
Geoff Langbfdea662014-07-23 14:16:32 -04006265
6266 if (!gl::ValidProgram(context, program))
6267 {
6268 return;
6269 }
6270
6271 gl::Program *programObject = context->getProgram(program);
6272 ASSERT(programObject);
6273
6274 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006275 }
6276}
6277
6278void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6279{
6280 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6281 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6282 program, index, bufSize, length, size, type, name);
6283
Geoff Langbfdea662014-07-23 14:16:32 -04006284 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006285 if (context)
6286 {
6287 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006288 {
Geoff Langb1196682014-07-23 13:47:29 -04006289 context->recordError(gl::Error(GL_INVALID_OPERATION));
6290 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006291 }
Geoff Langbfdea662014-07-23 14:16:32 -04006292
6293 if (bufSize < 0)
6294 {
Geoff Langb1196682014-07-23 13:47:29 -04006295 context->recordError(gl::Error(GL_INVALID_VALUE));
6296 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006297 }
6298
6299 if (!gl::ValidProgram(context, program))
6300 {
6301 return;
6302 }
6303
6304 gl::Program *programObject = context->getProgram(program);
6305 ASSERT(programObject);
6306
6307 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6308 {
Geoff Langb1196682014-07-23 13:47:29 -04006309 context->recordError(gl::Error(GL_INVALID_VALUE));
6310 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006311 }
6312
6313 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006314 }
6315}
6316
6317void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6318{
6319 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6320 index, size, type, stride, pointer);
6321
Geoff Langbfdea662014-07-23 14:16:32 -04006322 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006323 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006324 {
Geoff Langbfdea662014-07-23 14:16:32 -04006325 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006326 {
Geoff Langb1196682014-07-23 13:47:29 -04006327 context->recordError(gl::Error(GL_INVALID_OPERATION));
6328 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006329 }
6330
Geoff Langb1196682014-07-23 13:47:29 -04006331 if (index >= gl::MAX_VERTEX_ATTRIBS)
6332 {
6333 context->recordError(gl::Error(GL_INVALID_VALUE));
6334 return;
6335 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006336
Geoff Langb1196682014-07-23 13:47:29 -04006337 if (size < 1 || size > 4)
6338 {
6339 context->recordError(gl::Error(GL_INVALID_VALUE));
6340 return;
6341 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006342
Geoff Langb1196682014-07-23 13:47:29 -04006343 switch (type)
6344 {
6345 case GL_BYTE:
6346 case GL_UNSIGNED_BYTE:
6347 case GL_SHORT:
6348 case GL_UNSIGNED_SHORT:
6349 case GL_INT:
6350 case GL_UNSIGNED_INT:
6351 case GL_INT_2_10_10_10_REV:
6352 case GL_UNSIGNED_INT_2_10_10_10_REV:
6353 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006354
Geoff Langb1196682014-07-23 13:47:29 -04006355 default:
6356 context->recordError(gl::Error(GL_INVALID_ENUM));
6357 return;
6358 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006359
Geoff Langb1196682014-07-23 13:47:29 -04006360 if (stride < 0)
6361 {
6362 context->recordError(gl::Error(GL_INVALID_VALUE));
6363 return;
6364 }
Geoff Langbfdea662014-07-23 14:16:32 -04006365
Geoff Langb1196682014-07-23 13:47:29 -04006366 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6367 {
6368 context->recordError(gl::Error(GL_INVALID_OPERATION));
6369 return;
6370 }
6371
Geoff Langbfdea662014-07-23 14:16:32 -04006372 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6373 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6374 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6375 // and the pointer argument is not NULL.
6376 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006377 {
Geoff Langb1196682014-07-23 13:47:29 -04006378 context->recordError(gl::Error(GL_INVALID_OPERATION));
6379 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006380 }
6381
Geoff Langbfdea662014-07-23 14:16:32 -04006382 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6383 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006384 }
6385}
6386
6387void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6388{
6389 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6390 index, pname, params);
6391
Geoff Langbfdea662014-07-23 14:16:32 -04006392 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006393 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006394 {
Geoff Langbfdea662014-07-23 14:16:32 -04006395 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006396 {
Geoff Langb1196682014-07-23 13:47:29 -04006397 context->recordError(gl::Error(GL_INVALID_OPERATION));
6398 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006399 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006400
Geoff Langbfdea662014-07-23 14:16:32 -04006401 if (index >= gl::MAX_VERTEX_ATTRIBS)
6402 {
Geoff Langb1196682014-07-23 13:47:29 -04006403 context->recordError(gl::Error(GL_INVALID_VALUE));
6404 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006405 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006406
Geoff Langbfdea662014-07-23 14:16:32 -04006407 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006408
Geoff Langb1196682014-07-23 13:47:29 -04006409 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006410 {
6411 return;
6412 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006413
Geoff Langbfdea662014-07-23 14:16:32 -04006414 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6415 {
6416 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6417 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006418 {
Geoff Langbfdea662014-07-23 14:16:32 -04006419 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006420 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006421 }
Geoff Langbfdea662014-07-23 14:16:32 -04006422 else
6423 {
6424 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6425 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006426 }
6427}
6428
6429void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6430{
6431 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6432 index, pname, params);
6433
Geoff Langbfdea662014-07-23 14:16:32 -04006434 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006435 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006436 {
Geoff Langbfdea662014-07-23 14:16:32 -04006437 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006438 {
Geoff Langb1196682014-07-23 13:47:29 -04006439 context->recordError(gl::Error(GL_INVALID_OPERATION));
6440 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006441 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006442
Geoff Langbfdea662014-07-23 14:16:32 -04006443 if (index >= gl::MAX_VERTEX_ATTRIBS)
6444 {
Geoff Langb1196682014-07-23 13:47:29 -04006445 context->recordError(gl::Error(GL_INVALID_VALUE));
6446 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006447 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006448
Geoff Langbfdea662014-07-23 14:16:32 -04006449 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006450
Geoff Langb1196682014-07-23 13:47:29 -04006451 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006452 {
6453 return;
6454 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006455
Geoff Langbfdea662014-07-23 14:16:32 -04006456 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6457 {
6458 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6459 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006460 {
Geoff Langbfdea662014-07-23 14:16:32 -04006461 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006462 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006463 }
Geoff Langbfdea662014-07-23 14:16:32 -04006464 else
6465 {
6466 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6467 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006468 }
6469}
6470
6471void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6472{
6473 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6474 index, x, y, z, w);
6475
Geoff Langbfdea662014-07-23 14:16:32 -04006476 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006477 if (context)
6478 {
6479 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006480 {
Geoff Langb1196682014-07-23 13:47:29 -04006481 context->recordError(gl::Error(GL_INVALID_OPERATION));
6482 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006483 }
Geoff Langbfdea662014-07-23 14:16:32 -04006484
6485 if (index >= gl::MAX_VERTEX_ATTRIBS)
6486 {
Geoff Langb1196682014-07-23 13:47:29 -04006487 context->recordError(gl::Error(GL_INVALID_VALUE));
6488 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006489 }
6490
6491 GLint vals[4] = { x, y, z, w };
6492 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006493 }
6494}
6495
6496void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6497{
6498 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6499 index, x, y, z, w);
6500
Geoff Langbfdea662014-07-23 14:16:32 -04006501 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006502 if (context)
6503 {
6504 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006505 {
Geoff Langb1196682014-07-23 13:47:29 -04006506 context->recordError(gl::Error(GL_INVALID_OPERATION));
6507 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006508 }
Geoff Langbfdea662014-07-23 14:16:32 -04006509
6510 if (index >= gl::MAX_VERTEX_ATTRIBS)
6511 {
Geoff Langb1196682014-07-23 13:47:29 -04006512 context->recordError(gl::Error(GL_INVALID_VALUE));
6513 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006514 }
6515
6516 GLuint vals[4] = { x, y, z, w };
6517 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006518 }
6519}
6520
6521void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6522{
6523 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6524
Geoff Langbfdea662014-07-23 14:16:32 -04006525 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006526 if (context)
6527 {
6528 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006529 {
Geoff Langb1196682014-07-23 13:47:29 -04006530 context->recordError(gl::Error(GL_INVALID_OPERATION));
6531 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006532 }
Geoff Langbfdea662014-07-23 14:16:32 -04006533
6534 if (index >= gl::MAX_VERTEX_ATTRIBS)
6535 {
Geoff Langb1196682014-07-23 13:47:29 -04006536 context->recordError(gl::Error(GL_INVALID_VALUE));
6537 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006538 }
6539
6540 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006541 }
6542}
6543
6544void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6545{
6546 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6547
Geoff Langbfdea662014-07-23 14:16:32 -04006548 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006549 if (context)
6550 {
6551 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006552 {
Geoff Langb1196682014-07-23 13:47:29 -04006553 context->recordError(gl::Error(GL_INVALID_OPERATION));
6554 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006555 }
Geoff Langbfdea662014-07-23 14:16:32 -04006556
6557 if (index >= gl::MAX_VERTEX_ATTRIBS)
6558 {
Geoff Langb1196682014-07-23 13:47:29 -04006559 context->recordError(gl::Error(GL_INVALID_VALUE));
6560 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006561 }
6562
6563 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006564 }
6565}
6566
6567void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6568{
6569 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6570 program, location, params);
6571
Geoff Langbfdea662014-07-23 14:16:32 -04006572 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006573 if (context)
6574 {
Jamie Madill0063c512014-08-25 15:47:53 -04006575 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006576 {
Jamie Madill0063c512014-08-25 15:47:53 -04006577 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006578 }
Geoff Langbfdea662014-07-23 14:16:32 -04006579
Jamie Madilla502c742014-08-28 17:19:13 -04006580 gl::Program *programObject = context->getProgram(program);
6581 ASSERT(programObject);
6582 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006583 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006584
Jamie Madill99a1e982014-08-25 15:47:54 -04006585 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006586 }
6587}
6588
6589GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6590{
6591 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6592 program, name);
6593
Geoff Langbfdea662014-07-23 14:16:32 -04006594 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006595 if (context)
6596 {
6597 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006598 {
Geoff Langb1196682014-07-23 13:47:29 -04006599 context->recordError(gl::Error(GL_INVALID_OPERATION));
6600 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006601 }
Geoff Langbfdea662014-07-23 14:16:32 -04006602
6603 if (program == 0)
6604 {
Geoff Langb1196682014-07-23 13:47:29 -04006605 context->recordError(gl::Error(GL_INVALID_VALUE));
6606 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006607 }
6608
6609 gl::Program *programObject = context->getProgram(program);
6610
6611 if (!programObject || !programObject->isLinked())
6612 {
Geoff Langb1196682014-07-23 13:47:29 -04006613 context->recordError(gl::Error(GL_INVALID_OPERATION));
6614 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006615 }
6616
6617 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6618 if (!programBinary)
6619 {
Geoff Langb1196682014-07-23 13:47:29 -04006620 context->recordError(gl::Error(GL_INVALID_OPERATION));
6621 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006622 }
6623
6624 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006625 }
6626
6627 return 0;
6628}
6629
6630void __stdcall glUniform1ui(GLint location, GLuint v0)
6631{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006632 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006633}
6634
6635void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6636{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006637 const GLuint xy[] = { v0, v1 };
6638 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006639}
6640
6641void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6642{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006643 const GLuint xyz[] = { v0, v1, v2 };
6644 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006645}
6646
6647void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6648{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006649 const GLuint xyzw[] = { v0, v1, v2, v3 };
6650 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006651}
6652
6653void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6654{
6655 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6656 location, count, value);
6657
Geoff Langbfdea662014-07-23 14:16:32 -04006658 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006659 if (context)
6660 {
6661 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006662 {
Geoff Langbfdea662014-07-23 14:16:32 -04006663 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006664 }
Geoff Langbfdea662014-07-23 14:16:32 -04006665
6666 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6667 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006668 }
6669}
6670
6671void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6672{
6673 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6674 location, count, value);
6675
Geoff Langbfdea662014-07-23 14:16:32 -04006676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006677 if (context)
6678 {
6679 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006680 {
Geoff Langbfdea662014-07-23 14:16:32 -04006681 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006682 }
Geoff Langbfdea662014-07-23 14:16:32 -04006683
6684 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6685 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006686 }
6687}
6688
6689void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6690{
6691 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6692 location, count, value);
6693
Geoff Langbfdea662014-07-23 14:16:32 -04006694 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006695 if (context)
6696 {
6697 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006698 {
Geoff Langbfdea662014-07-23 14:16:32 -04006699 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006700 }
Geoff Langbfdea662014-07-23 14:16:32 -04006701
6702 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6703 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006704 }
6705}
6706
6707void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6708{
6709 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6710 location, count, value);
6711
Geoff Langbfdea662014-07-23 14:16:32 -04006712 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006713 if (context)
6714 {
6715 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006716 {
Geoff Langbfdea662014-07-23 14:16:32 -04006717 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006718 }
Geoff Langbfdea662014-07-23 14:16:32 -04006719
6720 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6721 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006722 }
6723}
6724
6725void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6726{
6727 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6728 buffer, drawbuffer, value);
6729
Geoff Langbfdea662014-07-23 14:16:32 -04006730 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006731 if (context)
6732 {
6733 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006734 {
Geoff Langbfdea662014-07-23 14:16:32 -04006735 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006736 }
Geoff Langbfdea662014-07-23 14:16:32 -04006737
6738 switch (buffer)
6739 {
6740 case GL_COLOR:
6741 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6742 {
Geoff Langb1196682014-07-23 13:47:29 -04006743 context->recordError(gl::Error(GL_INVALID_VALUE));
6744 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006745 }
6746 break;
Geoff Langb1196682014-07-23 13:47:29 -04006747
Geoff Langbfdea662014-07-23 14:16:32 -04006748 case GL_STENCIL:
6749 if (drawbuffer != 0)
6750 {
Geoff Langb1196682014-07-23 13:47:29 -04006751 context->recordError(gl::Error(GL_INVALID_VALUE));
6752 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006753 }
6754 break;
Geoff Langb1196682014-07-23 13:47:29 -04006755
Geoff Langbfdea662014-07-23 14:16:32 -04006756 default:
Geoff Langb1196682014-07-23 13:47:29 -04006757 context->recordError(gl::Error(GL_INVALID_ENUM));
6758 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006759 }
6760
Geoff Langcc79b8c2014-07-25 13:48:02 -04006761 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6762 if (error.isError())
6763 {
6764 context->recordError(error);
6765 return;
6766 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006767 }
6768}
6769
6770void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6771{
6772 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6773 buffer, drawbuffer, value);
6774
Geoff Langbfdea662014-07-23 14:16:32 -04006775 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006776 if (context)
6777 {
6778 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006779 {
Geoff Langbfdea662014-07-23 14:16:32 -04006780 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006781 }
Geoff Langbfdea662014-07-23 14:16:32 -04006782
6783 switch (buffer)
6784 {
6785 case GL_COLOR:
6786 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6787 {
Geoff Langb1196682014-07-23 13:47:29 -04006788 context->recordError(gl::Error(GL_INVALID_VALUE));
6789 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006790 }
6791 break;
Geoff Langb1196682014-07-23 13:47:29 -04006792
Geoff Langbfdea662014-07-23 14:16:32 -04006793 default:
Geoff Langb1196682014-07-23 13:47:29 -04006794 context->recordError(gl::Error(GL_INVALID_ENUM));
6795 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006796 }
6797
Geoff Langcc79b8c2014-07-25 13:48:02 -04006798 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6799 if (error.isError())
6800 {
6801 context->recordError(error);
6802 return;
6803 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006804 }
6805}
6806
6807void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6808{
6809 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6810 buffer, drawbuffer, value);
6811
Geoff Langbfdea662014-07-23 14:16:32 -04006812 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006813 if (context)
6814 {
6815 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006816 {
Geoff Langbfdea662014-07-23 14:16:32 -04006817 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006818 }
Geoff Langbfdea662014-07-23 14:16:32 -04006819
6820 switch (buffer)
6821 {
6822 case GL_COLOR:
6823 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6824 {
Geoff Langb1196682014-07-23 13:47:29 -04006825 context->recordError(gl::Error(GL_INVALID_VALUE));
6826 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006827 }
6828 break;
Geoff Langb1196682014-07-23 13:47:29 -04006829
Geoff Langbfdea662014-07-23 14:16:32 -04006830 case GL_DEPTH:
6831 if (drawbuffer != 0)
6832 {
Geoff Langb1196682014-07-23 13:47:29 -04006833 context->recordError(gl::Error(GL_INVALID_VALUE));
6834 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006835 }
6836 break;
Geoff Langb1196682014-07-23 13:47:29 -04006837
Geoff Langbfdea662014-07-23 14:16:32 -04006838 default:
Geoff Langb1196682014-07-23 13:47:29 -04006839 context->recordError(gl::Error(GL_INVALID_ENUM));
6840 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006841 }
6842
Geoff Langcc79b8c2014-07-25 13:48:02 -04006843 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6844 if (error.isError())
6845 {
6846 context->recordError(error);
6847 return;
6848 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006849 }
6850}
6851
6852void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6853{
6854 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6855 buffer, drawbuffer, depth, stencil);
6856
Geoff Langbfdea662014-07-23 14:16:32 -04006857 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006858 if (context)
6859 {
6860 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006861 {
Geoff Langbfdea662014-07-23 14:16:32 -04006862 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006863 }
Geoff Langbfdea662014-07-23 14:16:32 -04006864
6865 switch (buffer)
6866 {
6867 case GL_DEPTH_STENCIL:
6868 if (drawbuffer != 0)
6869 {
Geoff Langb1196682014-07-23 13:47:29 -04006870 context->recordError(gl::Error(GL_INVALID_VALUE));
6871 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006872 }
6873 break;
Geoff Langb1196682014-07-23 13:47:29 -04006874
Geoff Langbfdea662014-07-23 14:16:32 -04006875 default:
Geoff Langb1196682014-07-23 13:47:29 -04006876 context->recordError(gl::Error(GL_INVALID_ENUM));
6877 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006878 }
6879
Geoff Langcc79b8c2014-07-25 13:48:02 -04006880 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6881 if (error.isError())
6882 {
6883 context->recordError(error);
6884 return;
6885 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006886 }
6887}
6888
6889const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6890{
6891 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6892
Geoff Langbfdea662014-07-23 14:16:32 -04006893 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006894 if (context)
6895 {
6896 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006897 {
Geoff Langb1196682014-07-23 13:47:29 -04006898 context->recordError(gl::Error(GL_INVALID_OPERATION));
6899 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006900 }
Geoff Langbfdea662014-07-23 14:16:32 -04006901
6902 if (name != GL_EXTENSIONS)
6903 {
Geoff Langb1196682014-07-23 13:47:29 -04006904 context->recordError(gl::Error(GL_INVALID_ENUM));
6905 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006906 }
6907
6908 if (index >= context->getExtensionStringCount())
6909 {
Geoff Langb1196682014-07-23 13:47:29 -04006910 context->recordError(gl::Error(GL_INVALID_VALUE));
6911 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006912 }
6913
6914 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006915 }
6916
6917 return NULL;
6918}
6919
6920void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6921{
6922 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6923 readTarget, writeTarget, readOffset, writeOffset, size);
6924
Geoff Langbfdea662014-07-23 14:16:32 -04006925 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006926 if (context)
6927 {
6928 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006929 {
Geoff Langb1196682014-07-23 13:47:29 -04006930 context->recordError(gl::Error(GL_INVALID_OPERATION));
6931 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006932 }
Geoff Langbfdea662014-07-23 14:16:32 -04006933
6934 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6935 {
Geoff Langb1196682014-07-23 13:47:29 -04006936 context->recordError(gl::Error(GL_INVALID_ENUM));
6937 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006938 }
6939
6940 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6941 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6942
6943 if (!readBuffer || !writeBuffer)
6944 {
Geoff Langb1196682014-07-23 13:47:29 -04006945 context->recordError(gl::Error(GL_INVALID_OPERATION));
6946 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006947 }
6948
Jamie Madillcfaaf722014-07-31 10:47:54 -04006949 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006950 if (readBuffer->isMapped() || writeBuffer->isMapped())
6951 {
Geoff Langb1196682014-07-23 13:47:29 -04006952 context->recordError(gl::Error(GL_INVALID_OPERATION));
6953 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006954 }
6955
6956 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6957 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6958 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6959 {
Geoff Langb1196682014-07-23 13:47:29 -04006960 context->recordError(gl::Error(GL_INVALID_VALUE));
6961 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006962 }
6963
6964 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6965 {
Geoff Langb1196682014-07-23 13:47:29 -04006966 context->recordError(gl::Error(GL_INVALID_VALUE));
6967 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006968 }
6969
Geoff Langbfdea662014-07-23 14:16:32 -04006970 // if size is zero, the copy is a successful no-op
6971 if (size > 0)
6972 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006973 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6974 if (error.isError())
6975 {
6976 context->recordError(error);
6977 return;
6978 }
Geoff Langbfdea662014-07-23 14:16:32 -04006979 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006980 }
6981}
6982
6983void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6984{
6985 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6986 program, uniformCount, uniformNames, uniformIndices);
6987
Geoff Langbfdea662014-07-23 14:16:32 -04006988 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006989 if (context)
6990 {
6991 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006992 {
Geoff Langb1196682014-07-23 13:47:29 -04006993 context->recordError(gl::Error(GL_INVALID_OPERATION));
6994 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006995 }
6996
6997 if (uniformCount < 0)
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 gl::Program *programObject = context->getProgram(program);
7004
7005 if (!programObject)
7006 {
7007 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007008 {
Geoff Langb1196682014-07-23 13:47:29 -04007009 context->recordError(gl::Error(GL_INVALID_OPERATION));
7010 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007011 }
Geoff Langbfdea662014-07-23 14:16:32 -04007012 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007013 {
Geoff Langb1196682014-07-23 13:47:29 -04007014 context->recordError(gl::Error(GL_INVALID_VALUE));
7015 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007016 }
Geoff Langbfdea662014-07-23 14:16:32 -04007017 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007018
Geoff Langbfdea662014-07-23 14:16:32 -04007019 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7020 if (!programObject->isLinked() || !programBinary)
7021 {
7022 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007023 {
Geoff Langbfdea662014-07-23 14:16:32 -04007024 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007025 }
7026 }
Geoff Langbfdea662014-07-23 14:16:32 -04007027 else
7028 {
7029 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7030 {
7031 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
7032 }
7033 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007034 }
7035}
7036
7037void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
7038{
7039 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7040 program, uniformCount, uniformIndices, pname, params);
7041
Geoff Langbfdea662014-07-23 14:16:32 -04007042 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007043 if (context)
7044 {
7045 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007046 {
Geoff Langb1196682014-07-23 13:47:29 -04007047 context->recordError(gl::Error(GL_INVALID_OPERATION));
7048 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007049 }
7050
7051 if (uniformCount < 0)
7052 {
Geoff Langb1196682014-07-23 13:47:29 -04007053 context->recordError(gl::Error(GL_INVALID_VALUE));
7054 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007055 }
7056
7057 gl::Program *programObject = context->getProgram(program);
7058
7059 if (!programObject)
7060 {
7061 if (context->getShader(program))
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;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007065 }
Geoff Langbfdea662014-07-23 14:16:32 -04007066 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007067 {
Geoff Langb1196682014-07-23 13:47:29 -04007068 context->recordError(gl::Error(GL_INVALID_VALUE));
7069 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007070 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007071 }
Geoff Langbfdea662014-07-23 14:16:32 -04007072
7073 switch (pname)
7074 {
7075 case GL_UNIFORM_TYPE:
7076 case GL_UNIFORM_SIZE:
7077 case GL_UNIFORM_NAME_LENGTH:
7078 case GL_UNIFORM_BLOCK_INDEX:
7079 case GL_UNIFORM_OFFSET:
7080 case GL_UNIFORM_ARRAY_STRIDE:
7081 case GL_UNIFORM_MATRIX_STRIDE:
7082 case GL_UNIFORM_IS_ROW_MAJOR:
7083 break;
Geoff Langb1196682014-07-23 13:47:29 -04007084
Geoff Langbfdea662014-07-23 14:16:32 -04007085 default:
Geoff Langb1196682014-07-23 13:47:29 -04007086 context->recordError(gl::Error(GL_INVALID_ENUM));
7087 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007088 }
7089
7090 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7091
7092 if (!programBinary && uniformCount > 0)
7093 {
Geoff Langb1196682014-07-23 13:47:29 -04007094 context->recordError(gl::Error(GL_INVALID_VALUE));
7095 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007096 }
7097
7098 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7099 {
7100 const GLuint index = uniformIndices[uniformId];
7101
7102 if (index >= (GLuint)programBinary->getActiveUniformCount())
7103 {
Geoff Langb1196682014-07-23 13:47:29 -04007104 context->recordError(gl::Error(GL_INVALID_VALUE));
7105 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007106 }
7107 }
7108
7109 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7110 {
7111 const GLuint index = uniformIndices[uniformId];
7112 params[uniformId] = programBinary->getActiveUniformi(index, pname);
7113 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007114 }
7115}
7116
7117GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
7118{
7119 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
7120
Geoff Langbfdea662014-07-23 14:16:32 -04007121 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007122 if (context)
7123 {
7124 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007125 {
Geoff Langb1196682014-07-23 13:47:29 -04007126 context->recordError(gl::Error(GL_INVALID_OPERATION));
7127 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04007128 }
7129
7130 gl::Program *programObject = context->getProgram(program);
7131
7132 if (!programObject)
7133 {
7134 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007135 {
Geoff Langb1196682014-07-23 13:47:29 -04007136 context->recordError(gl::Error(GL_INVALID_OPERATION));
7137 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007138 }
Geoff Langbfdea662014-07-23 14:16:32 -04007139 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007140 {
Geoff Langb1196682014-07-23 13:47:29 -04007141 context->recordError(gl::Error(GL_INVALID_VALUE));
7142 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007143 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007144 }
Geoff Langbfdea662014-07-23 14:16:32 -04007145
7146 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7147 if (!programBinary)
7148 {
7149 return GL_INVALID_INDEX;
7150 }
7151
7152 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007153 }
7154
7155 return 0;
7156}
7157
7158void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
7159{
7160 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7161 program, uniformBlockIndex, pname, params);
7162
Geoff Langbfdea662014-07-23 14:16:32 -04007163 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007164 if (context)
7165 {
7166 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007167 {
Geoff Langb1196682014-07-23 13:47:29 -04007168 context->recordError(gl::Error(GL_INVALID_OPERATION));
7169 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007170 }
7171 gl::Program *programObject = context->getProgram(program);
7172
7173 if (!programObject)
7174 {
7175 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007176 {
Geoff Langb1196682014-07-23 13:47:29 -04007177 context->recordError(gl::Error(GL_INVALID_OPERATION));
7178 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007179 }
Geoff Langbfdea662014-07-23 14:16:32 -04007180 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007181 {
Geoff Langb1196682014-07-23 13:47:29 -04007182 context->recordError(gl::Error(GL_INVALID_VALUE));
7183 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007184 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007185 }
Geoff Langbfdea662014-07-23 14:16:32 -04007186
7187 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7188
7189 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7190 {
Geoff Langb1196682014-07-23 13:47:29 -04007191 context->recordError(gl::Error(GL_INVALID_VALUE));
7192 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007193 }
7194
7195 switch (pname)
7196 {
7197 case GL_UNIFORM_BLOCK_BINDING:
7198 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7199 break;
7200
7201 case GL_UNIFORM_BLOCK_DATA_SIZE:
7202 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7203 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7204 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7205 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7206 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7207 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7208 break;
7209
7210 default:
Geoff Langb1196682014-07-23 13:47:29 -04007211 context->recordError(gl::Error(GL_INVALID_ENUM));
7212 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007214 }
7215}
7216
7217void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7218{
7219 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7220 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7221
Geoff Langbfdea662014-07-23 14:16:32 -04007222 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007223 if (context)
7224 {
7225 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007226 {
Geoff Langb1196682014-07-23 13:47:29 -04007227 context->recordError(gl::Error(GL_INVALID_OPERATION));
7228 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007229 }
7230
7231 gl::Program *programObject = context->getProgram(program);
7232
7233 if (!programObject)
7234 {
7235 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007236 {
Geoff Langb1196682014-07-23 13:47:29 -04007237 context->recordError(gl::Error(GL_INVALID_OPERATION));
7238 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007239 }
Geoff Langbfdea662014-07-23 14:16:32 -04007240 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007241 {
Geoff Langb1196682014-07-23 13:47:29 -04007242 context->recordError(gl::Error(GL_INVALID_VALUE));
7243 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007244 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007245 }
Geoff Langbfdea662014-07-23 14:16:32 -04007246
7247 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7248
7249 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7250 {
Geoff Langb1196682014-07-23 13:47:29 -04007251 context->recordError(gl::Error(GL_INVALID_VALUE));
7252 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007253 }
7254
7255 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007256 }
7257}
7258
7259void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7260{
7261 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7262 program, uniformBlockIndex, uniformBlockBinding);
7263
Geoff Langbfdea662014-07-23 14:16:32 -04007264 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007265 if (context)
7266 {
7267 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007268 {
Geoff Langb1196682014-07-23 13:47:29 -04007269 context->recordError(gl::Error(GL_INVALID_OPERATION));
7270 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007271 }
7272
Geoff Lang3a61c322014-07-10 13:01:54 -04007273 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007274 {
Geoff Langb1196682014-07-23 13:47:29 -04007275 context->recordError(gl::Error(GL_INVALID_VALUE));
7276 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007277 }
7278
7279 gl::Program *programObject = context->getProgram(program);
7280
7281 if (!programObject)
7282 {
7283 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007284 {
Geoff Langb1196682014-07-23 13:47:29 -04007285 context->recordError(gl::Error(GL_INVALID_OPERATION));
7286 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007287 }
Geoff Langbfdea662014-07-23 14:16:32 -04007288 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007289 {
Geoff Langb1196682014-07-23 13:47:29 -04007290 context->recordError(gl::Error(GL_INVALID_VALUE));
7291 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007292 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007293 }
Geoff Langbfdea662014-07-23 14:16:32 -04007294
7295 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7296
7297 // if never linked, there won't be any uniform blocks
7298 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7299 {
Geoff Langb1196682014-07-23 13:47:29 -04007300 context->recordError(gl::Error(GL_INVALID_VALUE));
7301 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007302 }
7303
7304 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007305 }
7306}
7307
7308void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7309{
7310 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7311 mode, first, count, instanceCount);
7312
Geoff Langbfdea662014-07-23 14:16:32 -04007313 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007314 if (context)
7315 {
7316 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007317 {
Geoff Langb1196682014-07-23 13:47:29 -04007318 context->recordError(gl::Error(GL_INVALID_OPERATION));
7319 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007320 }
Geoff Langbfdea662014-07-23 14:16:32 -04007321
7322 // glDrawArraysInstanced
7323 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007324 }
7325}
7326
7327void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7328{
7329 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7330 mode, count, type, indices, instanceCount);
7331
Geoff Langbfdea662014-07-23 14:16:32 -04007332 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007333 if (context)
7334 {
7335 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007336 {
Geoff Langb1196682014-07-23 13:47:29 -04007337 context->recordError(gl::Error(GL_INVALID_OPERATION));
7338 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007339 }
Geoff Langbfdea662014-07-23 14:16:32 -04007340
7341 // glDrawElementsInstanced
7342 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007343 }
7344}
7345
7346GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7347{
7348 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7349
Geoff Langbfdea662014-07-23 14:16:32 -04007350 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007351 if (context)
7352 {
7353 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007354 {
Geoff Langb1196682014-07-23 13:47:29 -04007355 context->recordError(gl::Error(GL_INVALID_OPERATION));
7356 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007357 }
Geoff Langbfdea662014-07-23 14:16:32 -04007358
7359 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7360 {
Geoff Langb1196682014-07-23 13:47:29 -04007361 context->recordError(gl::Error(GL_INVALID_ENUM));
7362 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007363 }
7364
7365 if (flags != 0)
7366 {
Geoff Langb1196682014-07-23 13:47:29 -04007367 context->recordError(gl::Error(GL_INVALID_VALUE));
7368 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007369 }
7370
Geoff Lang882033e2014-09-30 11:26:07 -04007371 GLsync fenceSync = context->createFenceSync();
7372
7373 gl::FenceSync *fenceSyncObject = context->getFenceSync(fenceSync);
7374 gl::Error error = fenceSyncObject->set(condition);
7375 if (error.isError())
7376 {
7377 context->deleteFenceSync(fenceSync);
7378 context->recordError(error);
7379 return NULL;
7380 }
7381
7382 return fenceSync;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007383 }
7384
7385 return NULL;
7386}
7387
7388GLboolean __stdcall glIsSync(GLsync sync)
7389{
7390 EVENT("(GLsync sync = 0x%0.8p)", sync);
7391
Geoff Langbfdea662014-07-23 14:16:32 -04007392 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007393 if (context)
7394 {
7395 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007396 {
Geoff Langb1196682014-07-23 13:47:29 -04007397 context->recordError(gl::Error(GL_INVALID_OPERATION));
7398 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007399 }
Geoff Langbfdea662014-07-23 14:16:32 -04007400
7401 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007402 }
7403
7404 return GL_FALSE;
7405}
7406
7407void __stdcall glDeleteSync(GLsync sync)
7408{
7409 EVENT("(GLsync sync = 0x%0.8p)", sync);
7410
Geoff Langbfdea662014-07-23 14:16:32 -04007411 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007412 if (context)
7413 {
7414 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007415 {
Geoff Langb1196682014-07-23 13:47:29 -04007416 context->recordError(gl::Error(GL_INVALID_OPERATION));
7417 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007418 }
Geoff Langbfdea662014-07-23 14:16:32 -04007419
7420 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7421 {
Geoff Langb1196682014-07-23 13:47:29 -04007422 context->recordError(gl::Error(GL_INVALID_VALUE));
7423 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007424 }
7425
7426 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007427 }
7428}
7429
7430GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7431{
7432 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7433 sync, flags, timeout);
7434
Geoff Langbfdea662014-07-23 14:16:32 -04007435 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007436 if (context)
7437 {
7438 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007439 {
Geoff Langb1196682014-07-23 13:47:29 -04007440 context->recordError(gl::Error(GL_INVALID_OPERATION));
7441 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007442 }
Geoff Langbfdea662014-07-23 14:16:32 -04007443
7444 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7445 {
Geoff Langb1196682014-07-23 13:47:29 -04007446 context->recordError(gl::Error(GL_INVALID_VALUE));
7447 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007448 }
7449
7450 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7451
7452 if (!fenceSync)
7453 {
Geoff Langb1196682014-07-23 13:47:29 -04007454 context->recordError(gl::Error(GL_INVALID_VALUE));
7455 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007456 }
7457
Geoff Lang882033e2014-09-30 11:26:07 -04007458 GLenum result = GL_WAIT_FAILED;
7459 gl::Error error = fenceSync->clientWait(flags, timeout, &result);
7460 if (error.isError())
7461 {
7462 context->recordError(error);
7463 return GL_WAIT_FAILED;
7464 }
7465
7466 return result;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007467 }
7468
7469 return GL_FALSE;
7470}
7471
7472void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7473{
7474 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7475 sync, flags, timeout);
7476
Geoff Langbfdea662014-07-23 14:16:32 -04007477 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007478 if (context)
7479 {
7480 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007481 {
Geoff Langb1196682014-07-23 13:47:29 -04007482 context->recordError(gl::Error(GL_INVALID_OPERATION));
7483 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007484 }
Geoff Langbfdea662014-07-23 14:16:32 -04007485
7486 if (flags != 0)
7487 {
Geoff Langb1196682014-07-23 13:47:29 -04007488 context->recordError(gl::Error(GL_INVALID_VALUE));
7489 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007490 }
7491
7492 if (timeout != GL_TIMEOUT_IGNORED)
7493 {
Geoff Langb1196682014-07-23 13:47:29 -04007494 context->recordError(gl::Error(GL_INVALID_VALUE));
7495 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007496 }
7497
7498 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7499
7500 if (!fenceSync)
7501 {
Geoff Langb1196682014-07-23 13:47:29 -04007502 context->recordError(gl::Error(GL_INVALID_VALUE));
7503 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007504 }
7505
Geoff Lang882033e2014-09-30 11:26:07 -04007506 gl::Error error = fenceSync->serverWait();
7507 if (error.isError())
7508 {
7509 context->recordError(error);
7510 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007511 }
7512}
7513
7514void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7515{
7516 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7517 pname, params);
7518
Geoff Langbfdea662014-07-23 14:16:32 -04007519 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007520 if (context)
7521 {
7522 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007523 {
Geoff Langb1196682014-07-23 13:47:29 -04007524 context->recordError(gl::Error(GL_INVALID_OPERATION));
7525 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007526 }
Geoff Langbfdea662014-07-23 14:16:32 -04007527
7528 GLenum nativeType;
7529 unsigned int numParams = 0;
7530 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7531 {
7532 return;
7533 }
7534
7535 if (nativeType == GL_INT_64_ANGLEX)
7536 {
7537 context->getInteger64v(pname, params);
7538 }
7539 else
7540 {
7541 CastStateValues(context, nativeType, pname, numParams, params);
7542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007543 }
7544}
7545
7546void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7547{
7548 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7549 sync, pname, bufSize, length, values);
7550
Geoff Langbfdea662014-07-23 14:16:32 -04007551 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007552 if (context)
7553 {
7554 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007555 {
Geoff Langb1196682014-07-23 13:47:29 -04007556 context->recordError(gl::Error(GL_INVALID_OPERATION));
7557 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007558 }
Geoff Langbfdea662014-07-23 14:16:32 -04007559
7560 if (bufSize < 0)
7561 {
Geoff Langb1196682014-07-23 13:47:29 -04007562 context->recordError(gl::Error(GL_INVALID_VALUE));
7563 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007564 }
7565
7566 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7567
7568 if (!fenceSync)
7569 {
Geoff Langb1196682014-07-23 13:47:29 -04007570 context->recordError(gl::Error(GL_INVALID_VALUE));
7571 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007572 }
7573
7574 switch (pname)
7575 {
7576 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
Geoff Langbfdea662014-07-23 14:16:32 -04007577 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7578 case GL_SYNC_FLAGS: values[0] = 0; break;
7579
Geoff Lang882033e2014-09-30 11:26:07 -04007580 case GL_SYNC_STATUS:
7581 {
7582 gl::Error error = fenceSync->getStatus(values);
7583 if (error.isError())
7584 {
7585 context->recordError(error);
7586 return;
7587 }
7588 break;
7589 }
7590
Geoff Langbfdea662014-07-23 14:16:32 -04007591 default:
Geoff Langb1196682014-07-23 13:47:29 -04007592 context->recordError(gl::Error(GL_INVALID_ENUM));
7593 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007594 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007595 }
7596}
7597
7598void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7599{
7600 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7601 target, index, data);
7602
Geoff Langbfdea662014-07-23 14:16:32 -04007603 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007604 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007605 {
Geoff Langbfdea662014-07-23 14:16:32 -04007606 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007607 {
Geoff Langb1196682014-07-23 13:47:29 -04007608 context->recordError(gl::Error(GL_INVALID_OPERATION));
7609 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007610 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007611
Geoff Lang3a61c322014-07-10 13:01:54 -04007612 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007613 switch (target)
7614 {
7615 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7616 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7617 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007618 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7619 {
Geoff Langb1196682014-07-23 13:47:29 -04007620 context->recordError(gl::Error(GL_INVALID_VALUE));
7621 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007622 }
Geoff Langbfdea662014-07-23 14:16:32 -04007623 break;
Geoff Langb1196682014-07-23 13:47:29 -04007624
Geoff Langbfdea662014-07-23 14:16:32 -04007625 case GL_UNIFORM_BUFFER_START:
7626 case GL_UNIFORM_BUFFER_SIZE:
7627 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007628 if (index >= caps.maxUniformBufferBindings)
7629 {
Geoff Langb1196682014-07-23 13:47:29 -04007630 context->recordError(gl::Error(GL_INVALID_VALUE));
7631 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007632 }
Geoff Langbfdea662014-07-23 14:16:32 -04007633 break;
Geoff Langb1196682014-07-23 13:47:29 -04007634
Geoff Langbfdea662014-07-23 14:16:32 -04007635 default:
Geoff Langb1196682014-07-23 13:47:29 -04007636 context->recordError(gl::Error(GL_INVALID_ENUM));
7637 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007638 }
7639
7640 if (!(context->getIndexedInteger64v(target, index, data)))
7641 {
7642 GLenum nativeType;
7643 unsigned int numParams = 0;
7644 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007645 {
7646 context->recordError(gl::Error(GL_INVALID_ENUM));
7647 return;
7648 }
Shannon Woods15934d52013-08-19 14:28:49 -04007649
Geoff Langbfdea662014-07-23 14:16:32 -04007650 if (numParams == 0)
7651 return; // it is known that pname is valid, but there are no parameters to return
7652
7653 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007654 {
Geoff Langbfdea662014-07-23 14:16:32 -04007655 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007656
Geoff Langbfdea662014-07-23 14:16:32 -04007657 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007658
Geoff Langbfdea662014-07-23 14:16:32 -04007659 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007660 {
Geoff Langbfdea662014-07-23 14:16:32 -04007661 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007662 }
Geoff Langbfdea662014-07-23 14:16:32 -04007663
7664 delete [] intParams;
7665 }
7666 else
7667 {
7668 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007669 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007670 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007671 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007672}
7673
7674void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7675{
7676 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7677 target, pname, params);
7678
Geoff Langbfdea662014-07-23 14:16:32 -04007679 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007680 if (context)
7681 {
7682 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007683 {
Geoff Langb1196682014-07-23 13:47:29 -04007684 context->recordError(gl::Error(GL_INVALID_OPERATION));
7685 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007686 }
Geoff Langbfdea662014-07-23 14:16:32 -04007687
7688 if (!gl::ValidBufferTarget(context, target))
7689 {
Geoff Langb1196682014-07-23 13:47:29 -04007690 context->recordError(gl::Error(GL_INVALID_ENUM));
7691 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007692 }
7693
7694 if (!gl::ValidBufferParameter(context, pname))
7695 {
Geoff Langb1196682014-07-23 13:47:29 -04007696 context->recordError(gl::Error(GL_INVALID_ENUM));
7697 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007698 }
7699
7700 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7701
7702 if (!buffer)
7703 {
7704 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007705 context->recordError(gl::Error(GL_INVALID_OPERATION));
7706 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007707 }
7708
7709 switch (pname)
7710 {
7711 case GL_BUFFER_USAGE:
7712 *params = static_cast<GLint64>(buffer->getUsage());
7713 break;
7714 case GL_BUFFER_SIZE:
7715 *params = buffer->getSize();
7716 break;
7717 case GL_BUFFER_ACCESS_FLAGS:
7718 *params = static_cast<GLint64>(buffer->getAccessFlags());
7719 break;
7720 case GL_BUFFER_MAPPED:
7721 *params = static_cast<GLint64>(buffer->isMapped());
7722 break;
7723 case GL_BUFFER_MAP_OFFSET:
7724 *params = buffer->getMapOffset();
7725 break;
7726 case GL_BUFFER_MAP_LENGTH:
7727 *params = buffer->getMapLength();
7728 break;
7729 default: UNREACHABLE(); break;
7730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007731 }
7732}
7733
7734void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7735{
7736 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
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
7747 if (count < 0)
7748 {
Geoff Langb1196682014-07-23 13:47:29 -04007749 context->recordError(gl::Error(GL_INVALID_VALUE));
7750 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007751 }
7752
7753 for (int i = 0; i < count; i++)
7754 {
7755 samplers[i] = context->createSampler();
7756 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007757 }
7758}
7759
7760void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7761{
7762 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7763
Geoff Langbfdea662014-07-23 14:16:32 -04007764 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007765 if (context)
7766 {
7767 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007768 {
Geoff Langb1196682014-07-23 13:47:29 -04007769 context->recordError(gl::Error(GL_INVALID_OPERATION));
7770 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007771 }
Geoff Langbfdea662014-07-23 14:16:32 -04007772
7773 if (count < 0)
7774 {
Geoff Langb1196682014-07-23 13:47:29 -04007775 context->recordError(gl::Error(GL_INVALID_VALUE));
7776 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007777 }
7778
7779 for (int i = 0; i < count; i++)
7780 {
7781 context->deleteSampler(samplers[i]);
7782 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007783 }
7784}
7785
7786GLboolean __stdcall glIsSampler(GLuint sampler)
7787{
7788 EVENT("(GLuint sampler = %u)", sampler);
7789
Geoff Langbfdea662014-07-23 14:16:32 -04007790 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007791 if (context)
7792 {
7793 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007794 {
Geoff Langb1196682014-07-23 13:47:29 -04007795 context->recordError(gl::Error(GL_INVALID_OPERATION));
7796 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007797 }
Geoff Langbfdea662014-07-23 14:16:32 -04007798
7799 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007800 }
7801
7802 return GL_FALSE;
7803}
7804
7805void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7806{
7807 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7808
Geoff Langbfdea662014-07-23 14:16:32 -04007809 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007810 if (context)
7811 {
7812 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007813 {
Geoff Langb1196682014-07-23 13:47:29 -04007814 context->recordError(gl::Error(GL_INVALID_OPERATION));
7815 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007816 }
Geoff Langbfdea662014-07-23 14:16:32 -04007817
7818 if (sampler != 0 && !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
Geoff Lang3a61c322014-07-10 13:01:54 -04007824 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007825 {
Geoff Langb1196682014-07-23 13:47:29 -04007826 context->recordError(gl::Error(GL_INVALID_VALUE));
7827 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007828 }
7829
7830 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007831 }
7832}
7833
7834void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7835{
7836 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7837
Geoff Langbfdea662014-07-23 14:16:32 -04007838 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007839 if (context)
7840 {
7841 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007842 {
Geoff Langb1196682014-07-23 13:47:29 -04007843 context->recordError(gl::Error(GL_INVALID_OPERATION));
7844 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007845 }
Geoff Langbfdea662014-07-23 14:16:32 -04007846
Geoff Langb1196682014-07-23 13:47:29 -04007847 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007848 {
7849 return;
7850 }
7851
7852 if (!gl::ValidateTexParamParameters(context, pname, param))
7853 {
7854 return;
7855 }
7856
7857 if (!context->isSampler(sampler))
7858 {
Geoff Langb1196682014-07-23 13:47:29 -04007859 context->recordError(gl::Error(GL_INVALID_OPERATION));
7860 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007861 }
7862
7863 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007864 }
7865}
7866
7867void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7868{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007869 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007870}
7871
7872void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7873{
7874 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7875
Geoff Langbfdea662014-07-23 14:16:32 -04007876 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007877 if (context)
7878 {
7879 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007880 {
Geoff Langb1196682014-07-23 13:47:29 -04007881 context->recordError(gl::Error(GL_INVALID_OPERATION));
7882 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007883 }
Geoff Langbfdea662014-07-23 14:16:32 -04007884
Geoff Langb1196682014-07-23 13:47:29 -04007885 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007886 {
7887 return;
7888 }
7889
7890 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7891 {
7892 return;
7893 }
7894
7895 if (!context->isSampler(sampler))
7896 {
Geoff Langb1196682014-07-23 13:47:29 -04007897 context->recordError(gl::Error(GL_INVALID_OPERATION));
7898 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007899 }
7900
7901 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007902 }
7903}
7904
7905void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7906{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007907 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007908}
7909
7910void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7911{
7912 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7913
Geoff Langbfdea662014-07-23 14:16:32 -04007914 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007915 if (context)
7916 {
7917 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007918 {
Geoff Langb1196682014-07-23 13:47:29 -04007919 context->recordError(gl::Error(GL_INVALID_OPERATION));
7920 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007921 }
Geoff Langbfdea662014-07-23 14:16:32 -04007922
Geoff Langb1196682014-07-23 13:47:29 -04007923 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007924 {
7925 return;
7926 }
7927
7928 if (!context->isSampler(sampler))
7929 {
Geoff Langb1196682014-07-23 13:47:29 -04007930 context->recordError(gl::Error(GL_INVALID_OPERATION));
7931 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007932 }
7933
7934 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007935 }
7936}
7937
7938void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7939{
7940 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7941
Geoff Langbfdea662014-07-23 14:16:32 -04007942 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007943 if (context)
7944 {
7945 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007946 {
Geoff Langb1196682014-07-23 13:47:29 -04007947 context->recordError(gl::Error(GL_INVALID_OPERATION));
7948 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007949 }
Geoff Langbfdea662014-07-23 14:16:32 -04007950
Geoff Langb1196682014-07-23 13:47:29 -04007951 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007952 {
7953 return;
7954 }
7955
7956 if (!context->isSampler(sampler))
7957 {
Geoff Langb1196682014-07-23 13:47:29 -04007958 context->recordError(gl::Error(GL_INVALID_OPERATION));
7959 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007960 }
7961
7962 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007963 }
7964}
7965
7966void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7967{
7968 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7969
Geoff Langbfdea662014-07-23 14:16:32 -04007970 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007971 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007972 {
Geoff Langbfdea662014-07-23 14:16:32 -04007973 if (context->getClientVersion() < 3)
7974 {
Geoff Langb1196682014-07-23 13:47:29 -04007975 context->recordError(gl::Error(GL_INVALID_OPERATION));
7976 return;
7977 }
7978
7979 if (index >= gl::MAX_VERTEX_ATTRIBS)
7980 {
7981 context->recordError(gl::Error(GL_INVALID_VALUE));
7982 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007983 }
7984
7985 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007986 }
7987}
7988
7989void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7990{
7991 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7992
Geoff Langbfdea662014-07-23 14:16:32 -04007993 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007994 if (context)
7995 {
7996 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007997 {
Geoff Langb1196682014-07-23 13:47:29 -04007998 context->recordError(gl::Error(GL_INVALID_OPERATION));
7999 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008000 }
Geoff Langbfdea662014-07-23 14:16:32 -04008001
8002 switch (target)
8003 {
8004 case GL_TRANSFORM_FEEDBACK:
8005 {
8006 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
8007 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
8008 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
8009 {
Geoff Langb1196682014-07-23 13:47:29 -04008010 context->recordError(gl::Error(GL_INVALID_OPERATION));
8011 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008012 }
8013
8014 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
8015 if (context->getTransformFeedback(id) == NULL)
8016 {
Geoff Langb1196682014-07-23 13:47:29 -04008017 context->recordError(gl::Error(GL_INVALID_OPERATION));
8018 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008019 }
8020
8021 context->bindTransformFeedback(id);
8022 }
8023 break;
8024
8025 default:
Geoff Langb1196682014-07-23 13:47:29 -04008026 context->recordError(gl::Error(GL_INVALID_ENUM));
8027 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008028 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008029 }
8030}
8031
8032void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
8033{
8034 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
8035
Geoff Langbfdea662014-07-23 14:16:32 -04008036 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008037 if (context)
8038 {
8039 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008040 {
Geoff Langb1196682014-07-23 13:47:29 -04008041 context->recordError(gl::Error(GL_INVALID_OPERATION));
8042 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008043 }
Geoff Langbfdea662014-07-23 14:16:32 -04008044
8045 for (int i = 0; i < n; i++)
8046 {
8047 context->deleteTransformFeedback(ids[i]);
8048 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008049 }
8050}
8051
8052void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
8053{
8054 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8055
Geoff Langbfdea662014-07-23 14:16:32 -04008056 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008057 if (context)
8058 {
8059 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008060 {
Geoff Langb1196682014-07-23 13:47:29 -04008061 context->recordError(gl::Error(GL_INVALID_OPERATION));
8062 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008063 }
Geoff Langbfdea662014-07-23 14:16:32 -04008064
8065 for (int i = 0; i < n; i++)
8066 {
8067 ids[i] = context->createTransformFeedback();
8068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008069 }
8070}
8071
8072GLboolean __stdcall glIsTransformFeedback(GLuint id)
8073{
8074 EVENT("(GLuint id = %u)", id);
8075
Geoff Langbfdea662014-07-23 14:16:32 -04008076 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008077 if (context)
8078 {
8079 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008080 {
Geoff Langb1196682014-07-23 13:47:29 -04008081 context->recordError(gl::Error(GL_INVALID_OPERATION));
8082 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008083 }
Geoff Langbfdea662014-07-23 14:16:32 -04008084
8085 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008086 }
8087
8088 return GL_FALSE;
8089}
8090
8091void __stdcall glPauseTransformFeedback(void)
8092{
8093 EVENT("(void)");
8094
Geoff Langbfdea662014-07-23 14:16:32 -04008095 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008096 if (context)
8097 {
8098 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008099 {
Geoff Langb1196682014-07-23 13:47:29 -04008100 context->recordError(gl::Error(GL_INVALID_OPERATION));
8101 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008102 }
Geoff Langbfdea662014-07-23 14:16:32 -04008103
8104 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8105 ASSERT(transformFeedback != NULL);
8106
8107 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
8108 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
8109 {
Geoff Langb1196682014-07-23 13:47:29 -04008110 context->recordError(gl::Error(GL_INVALID_OPERATION));
8111 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008112 }
8113
8114 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008115 }
8116}
8117
8118void __stdcall glResumeTransformFeedback(void)
8119{
8120 EVENT("(void)");
8121
Geoff Langbfdea662014-07-23 14:16:32 -04008122 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008123 if (context)
8124 {
8125 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008126 {
Geoff Langb1196682014-07-23 13:47:29 -04008127 context->recordError(gl::Error(GL_INVALID_OPERATION));
8128 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008129 }
Geoff Langbfdea662014-07-23 14:16:32 -04008130
8131 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8132 ASSERT(transformFeedback != NULL);
8133
8134 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
8135 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
8136 {
Geoff Langb1196682014-07-23 13:47:29 -04008137 context->recordError(gl::Error(GL_INVALID_OPERATION));
8138 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008139 }
8140
8141 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008142 }
8143}
8144
8145void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
8146{
8147 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
8148 program, bufSize, length, binaryFormat, binary);
8149
Geoff Langbfdea662014-07-23 14:16:32 -04008150 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008151 if (context)
8152 {
8153 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008154 {
Geoff Langb1196682014-07-23 13:47:29 -04008155 context->recordError(gl::Error(GL_INVALID_OPERATION));
8156 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008157 }
Geoff Langbfdea662014-07-23 14:16:32 -04008158
8159 // glGetProgramBinary
8160 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008161 }
8162}
8163
8164void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
8165{
8166 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
8167 program, binaryFormat, binary, length);
8168
Geoff Langbfdea662014-07-23 14:16:32 -04008169 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008170 if (context)
8171 {
8172 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008173 {
Geoff Langb1196682014-07-23 13:47:29 -04008174 context->recordError(gl::Error(GL_INVALID_OPERATION));
8175 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008176 }
Geoff Langbfdea662014-07-23 14:16:32 -04008177
8178 // glProgramBinary
8179 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008180 }
8181}
8182
8183void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
8184{
8185 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
8186 program, pname, value);
8187
Geoff Langbfdea662014-07-23 14:16:32 -04008188 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008189 if (context)
8190 {
8191 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008192 {
Geoff Langb1196682014-07-23 13:47:29 -04008193 context->recordError(gl::Error(GL_INVALID_OPERATION));
8194 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008195 }
Geoff Langbfdea662014-07-23 14:16:32 -04008196
8197 // glProgramParameteri
8198 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008199 }
8200}
8201
8202void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
8203{
8204 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8205 target, numAttachments, attachments);
8206
Geoff Langbfdea662014-07-23 14:16:32 -04008207 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008208 if (context)
8209 {
8210 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008211 {
Geoff Langb1196682014-07-23 13:47:29 -04008212 context->recordError(gl::Error(GL_INVALID_OPERATION));
8213 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008214 }
Geoff Langbfdea662014-07-23 14:16:32 -04008215
8216 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8217 {
8218 return;
8219 }
8220
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008221 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8222 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8223 {
8224 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8225 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008226 }
8227}
8228
8229void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
8230{
8231 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8232 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8233 target, numAttachments, attachments, x, y, width, height);
8234
Geoff Langbfdea662014-07-23 14:16:32 -04008235 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008236 if (context)
8237 {
8238 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008239 {
Geoff Langb1196682014-07-23 13:47:29 -04008240 context->recordError(gl::Error(GL_INVALID_OPERATION));
8241 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008242 }
Geoff Langbfdea662014-07-23 14:16:32 -04008243
8244 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8245 {
8246 return;
8247 }
8248
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008249 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8250 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8251 {
8252 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008254 }
8255}
8256
8257void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8258{
8259 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8260 target, levels, internalformat, width, height);
8261
Geoff Langbfdea662014-07-23 14:16:32 -04008262 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008263 if (context)
8264 {
8265 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008266 {
Geoff Langb1196682014-07-23 13:47:29 -04008267 context->recordError(gl::Error(GL_INVALID_OPERATION));
8268 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008269 }
Geoff Langbfdea662014-07-23 14:16:32 -04008270
8271 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8272 {
8273 return;
8274 }
8275
8276 switch (target)
8277 {
8278 case GL_TEXTURE_2D:
8279 {
8280 gl::Texture2D *texture2d = context->getTexture2D();
8281 texture2d->storage(levels, internalformat, width, height);
8282 }
8283 break;
8284
8285 case GL_TEXTURE_CUBE_MAP:
8286 {
8287 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8288 textureCube->storage(levels, internalformat, width);
8289 }
8290 break;
8291
8292 default:
Geoff Langb1196682014-07-23 13:47:29 -04008293 context->recordError(gl::Error(GL_INVALID_ENUM));
8294 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008295 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008296 }
8297}
8298
8299void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8300{
8301 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8302 "GLsizei height = %d, GLsizei depth = %d)",
8303 target, levels, internalformat, width, height, depth);
8304
Geoff Langbfdea662014-07-23 14:16:32 -04008305 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008306 if (context)
8307 {
8308 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008309 {
Geoff Langb1196682014-07-23 13:47:29 -04008310 context->recordError(gl::Error(GL_INVALID_OPERATION));
8311 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008312 }
Geoff Langbfdea662014-07-23 14:16:32 -04008313
8314 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8315 {
8316 return;
8317 }
8318
8319 switch (target)
8320 {
8321 case GL_TEXTURE_3D:
8322 {
8323 gl::Texture3D *texture3d = context->getTexture3D();
8324 texture3d->storage(levels, internalformat, width, height, depth);
8325 }
8326 break;
8327
8328 case GL_TEXTURE_2D_ARRAY:
8329 {
8330 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8331 texture2darray->storage(levels, internalformat, width, height, depth);
8332 }
8333 break;
8334
8335 default:
8336 UNREACHABLE();
8337 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008338 }
8339}
8340
8341void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8342{
8343 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8344 "GLint* params = 0x%0.8p)",
8345 target, internalformat, pname, bufSize, params);
8346
Geoff Langbfdea662014-07-23 14:16:32 -04008347 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008348 if (context)
8349 {
8350 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008351 {
Geoff Langb1196682014-07-23 13:47:29 -04008352 context->recordError(gl::Error(GL_INVALID_OPERATION));
8353 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008354 }
Geoff Langbfdea662014-07-23 14:16:32 -04008355
8356 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8357 if (!formatCaps.renderable)
8358 {
Geoff Langb1196682014-07-23 13:47:29 -04008359 context->recordError(gl::Error(GL_INVALID_ENUM));
8360 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008361 }
8362
8363 if (target != GL_RENDERBUFFER)
8364 {
Geoff Langb1196682014-07-23 13:47:29 -04008365 context->recordError(gl::Error(GL_INVALID_ENUM));
8366 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008367 }
8368
8369 if (bufSize < 0)
8370 {
Geoff Langb1196682014-07-23 13:47:29 -04008371 context->recordError(gl::Error(GL_INVALID_VALUE));
8372 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008373 }
8374
8375 switch (pname)
8376 {
8377 case GL_NUM_SAMPLE_COUNTS:
8378 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008379 {
8380 *params = formatCaps.sampleCounts.size();
8381 }
Geoff Langbfdea662014-07-23 14:16:32 -04008382 break;
Geoff Langb1196682014-07-23 13:47:29 -04008383
Geoff Langbfdea662014-07-23 14:16:32 -04008384 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008385 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008386 break;
Geoff Langb1196682014-07-23 13:47:29 -04008387
Geoff Langbfdea662014-07-23 14:16:32 -04008388 default:
Geoff Langb1196682014-07-23 13:47:29 -04008389 context->recordError(gl::Error(GL_INVALID_ENUM));
8390 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008391 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008392 }
8393}
8394
8395// Extension functions
8396
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008397void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8398 GLbitfield mask, GLenum filter)
8399{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008400 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008401 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8402 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8403 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8404
Geoff Langbfdea662014-07-23 14:16:32 -04008405 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008406 if (context)
8407 {
8408 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8409 dstX0, dstY0, dstX1, dstY1, mask, filter,
8410 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008411 {
Geoff Langbfdea662014-07-23 14:16:32 -04008412 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008413 }
Geoff Langbfdea662014-07-23 14:16:32 -04008414
Geoff Lang64839152014-08-26 16:23:25 -04008415 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8416 mask, filter);
8417 if (error.isError())
8418 {
8419 context->recordError(error);
8420 return;
8421 }
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008422 }
8423}
8424
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008425void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8426 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008427{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008428 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008429 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008430 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008431 target, level, internalformat, width, height, depth, border, format, type, pixels);
8432
Geoff Langbfdea662014-07-23 14:16:32 -04008433 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008434}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008435
Geoff Langbfdea662014-07-23 14:16:32 -04008436void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008437 GLenum *binaryFormat, void *binary)
8438{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008439 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 +00008440 program, bufSize, length, binaryFormat, binary);
8441
Geoff Langbfdea662014-07-23 14:16:32 -04008442 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008443 if (context)
8444 {
8445 gl::Program *programObject = context->getProgram(program);
8446
8447 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008448 {
Geoff Langb1196682014-07-23 13:47:29 -04008449 context->recordError(gl::Error(GL_INVALID_OPERATION));
8450 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008451 }
Geoff Langbfdea662014-07-23 14:16:32 -04008452
8453 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8454
8455 if (!programBinary)
8456 {
Geoff Langb1196682014-07-23 13:47:29 -04008457 context->recordError(gl::Error(GL_INVALID_OPERATION));
8458 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008459 }
8460
Geoff Langb543aff2014-09-30 14:52:54 -04008461 gl::Error error = programBinary->save(binaryFormat, binary, bufSize, length);
8462 if (error.isError())
Geoff Langbfdea662014-07-23 14:16:32 -04008463 {
Geoff Langb543aff2014-09-30 14:52:54 -04008464 context->recordError(error);
Geoff Langb1196682014-07-23 13:47:29 -04008465 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008466 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008467 }
8468}
8469
8470void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8471 const void *binary, GLint length)
8472{
8473 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8474 program, binaryFormat, binary, length);
8475
Geoff Langbfdea662014-07-23 14:16:32 -04008476 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008477 if (context)
8478 {
Geoff Lang900013c2014-07-07 11:32:19 -04008479 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8480 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008481 {
Geoff Langb1196682014-07-23 13:47:29 -04008482 context->recordError(gl::Error(GL_INVALID_ENUM));
8483 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008484 }
Geoff Langbfdea662014-07-23 14:16:32 -04008485
8486 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008487 if (!programObject)
8488 {
Geoff Langb1196682014-07-23 13:47:29 -04008489 context->recordError(gl::Error(GL_INVALID_OPERATION));
8490 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008491 }
8492
Geoff Langb543aff2014-09-30 14:52:54 -04008493 gl::Error error = context->setProgramBinary(program, binaryFormat, binary, length);
8494 if (error.isError())
8495 {
8496 context->recordError(error);
8497 return;
8498 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008499 }
8500}
8501
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008502void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8503{
8504 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8505
Geoff Langbfdea662014-07-23 14:16:32 -04008506 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008507 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008508 {
Geoff Langbfdea662014-07-23 14:16:32 -04008509 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008510 {
Geoff Langb1196682014-07-23 13:47:29 -04008511 context->recordError(gl::Error(GL_INVALID_VALUE));
8512 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008513 }
8514
8515 if (context->getState().getDrawFramebuffer()->id() == 0)
8516 {
8517 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008518 {
Geoff Langb1196682014-07-23 13:47:29 -04008519 context->recordError(gl::Error(GL_INVALID_OPERATION));
8520 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008521 }
8522
Geoff Langbfdea662014-07-23 14:16:32 -04008523 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008524 {
Geoff Langb1196682014-07-23 13:47:29 -04008525 context->recordError(gl::Error(GL_INVALID_OPERATION));
8526 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008527 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008528 }
Geoff Langbfdea662014-07-23 14:16:32 -04008529 else
8530 {
8531 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8532 {
8533 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8534 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8535 {
Geoff Langb1196682014-07-23 13:47:29 -04008536 context->recordError(gl::Error(GL_INVALID_OPERATION));
8537 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008538 }
8539 }
8540 }
8541
8542 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8543
8544 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8545 {
8546 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8547 }
8548
8549 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8550 {
8551 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8552 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008553 }
8554}
8555
Shannon Woodsb3801742014-03-27 14:59:19 -04008556void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8557{
8558 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8559
Geoff Langbfdea662014-07-23 14:16:32 -04008560 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008561 if (context)
8562 {
8563 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008564 {
Geoff Langb1196682014-07-23 13:47:29 -04008565 context->recordError(gl::Error(GL_INVALID_ENUM));
8566 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008567 }
Geoff Langbfdea662014-07-23 14:16:32 -04008568
8569 if (pname != GL_BUFFER_MAP_POINTER)
8570 {
Geoff Langb1196682014-07-23 13:47:29 -04008571 context->recordError(gl::Error(GL_INVALID_ENUM));
8572 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008573 }
8574
8575 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8576
8577 if (!buffer || !buffer->isMapped())
8578 {
8579 *params = NULL;
8580 }
8581 else
8582 {
8583 *params = buffer->getMapPointer();
8584 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008585 }
8586}
8587
8588void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8589{
8590 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8591
Geoff Langbfdea662014-07-23 14:16:32 -04008592 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008593 if (context)
8594 {
8595 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008596 {
Geoff Langb1196682014-07-23 13:47:29 -04008597 context->recordError(gl::Error(GL_INVALID_ENUM));
8598 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008599 }
Geoff Langbfdea662014-07-23 14:16:32 -04008600
8601 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8602
8603 if (buffer == NULL)
8604 {
Geoff Langb1196682014-07-23 13:47:29 -04008605 context->recordError(gl::Error(GL_INVALID_OPERATION));
8606 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008607 }
8608
8609 if (access != GL_WRITE_ONLY_OES)
8610 {
Geoff Langb1196682014-07-23 13:47:29 -04008611 context->recordError(gl::Error(GL_INVALID_ENUM));
8612 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008613 }
8614
8615 if (buffer->isMapped())
8616 {
Geoff Langb1196682014-07-23 13:47:29 -04008617 context->recordError(gl::Error(GL_INVALID_OPERATION));
8618 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008619 }
8620
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008621 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8622 if (error.isError())
8623 {
8624 context->recordError(error);
8625 return NULL;
8626 }
8627
8628 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008629 }
8630
8631 return NULL;
8632}
8633
8634GLboolean __stdcall glUnmapBufferOES(GLenum target)
8635{
8636 EVENT("(GLenum target = 0x%X)", target);
8637
Geoff Langbfdea662014-07-23 14:16:32 -04008638 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008639 if (context)
8640 {
8641 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008642 {
Geoff Langb1196682014-07-23 13:47:29 -04008643 context->recordError(gl::Error(GL_INVALID_ENUM));
8644 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008645 }
Geoff Langbfdea662014-07-23 14:16:32 -04008646
8647 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8648
8649 if (buffer == NULL || !buffer->isMapped())
8650 {
Geoff Langb1196682014-07-23 13:47:29 -04008651 context->recordError(gl::Error(GL_INVALID_OPERATION));
8652 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008653 }
8654
8655 // TODO: detect if we had corruption. if so, throw an error and return false.
8656
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008657 gl::Error error = buffer->unmap();
8658 if (error.isError())
8659 {
8660 context->recordError(error);
8661 return GL_FALSE;
8662 }
Geoff Langbfdea662014-07-23 14:16:32 -04008663
8664 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008665 }
8666
8667 return GL_FALSE;
8668}
8669
Shannon Woods916e7692014-03-27 16:58:22 -04008670void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8671{
8672 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8673 target, offset, length, access);
8674
Geoff Langbfdea662014-07-23 14:16:32 -04008675 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008676 if (context)
8677 {
8678 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008679 {
Geoff Langb1196682014-07-23 13:47:29 -04008680 context->recordError(gl::Error(GL_INVALID_ENUM));
8681 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008682 }
Geoff Langbfdea662014-07-23 14:16:32 -04008683
8684 if (offset < 0 || length < 0)
8685 {
Geoff Langb1196682014-07-23 13:47:29 -04008686 context->recordError(gl::Error(GL_INVALID_VALUE));
8687 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008688 }
8689
8690 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8691
8692 if (buffer == NULL)
8693 {
Geoff Langb1196682014-07-23 13:47:29 -04008694 context->recordError(gl::Error(GL_INVALID_OPERATION));
8695 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008696 }
8697
8698 // Check for buffer overflow
8699 size_t offsetSize = static_cast<size_t>(offset);
8700 size_t lengthSize = static_cast<size_t>(length);
8701
8702 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8703 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8704 {
Geoff Langb1196682014-07-23 13:47:29 -04008705 context->recordError(gl::Error(GL_INVALID_VALUE));
8706 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008707 }
8708
8709 // Check for invalid bits in the mask
8710 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8711 GL_MAP_WRITE_BIT |
8712 GL_MAP_INVALIDATE_RANGE_BIT |
8713 GL_MAP_INVALIDATE_BUFFER_BIT |
8714 GL_MAP_FLUSH_EXPLICIT_BIT |
8715 GL_MAP_UNSYNCHRONIZED_BIT;
8716
8717 if (access & ~(allAccessBits))
8718 {
Geoff Langb1196682014-07-23 13:47:29 -04008719 context->recordError(gl::Error(GL_INVALID_VALUE));
8720 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008721 }
8722
8723 if (length == 0 || buffer->isMapped())
8724 {
Geoff Langb1196682014-07-23 13:47:29 -04008725 context->recordError(gl::Error(GL_INVALID_OPERATION));
8726 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008727 }
8728
8729 // Check for invalid bit combinations
8730 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8731 {
Geoff Langb1196682014-07-23 13:47:29 -04008732 context->recordError(gl::Error(GL_INVALID_OPERATION));
8733 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008734 }
8735
8736 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8737 GL_MAP_INVALIDATE_BUFFER_BIT |
8738 GL_MAP_UNSYNCHRONIZED_BIT;
8739
8740 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8741 {
Geoff Langb1196682014-07-23 13:47:29 -04008742 context->recordError(gl::Error(GL_INVALID_OPERATION));
8743 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008744 }
8745
8746 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8747 {
Geoff Langb1196682014-07-23 13:47:29 -04008748 context->recordError(gl::Error(GL_INVALID_OPERATION));
8749 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008750 }
8751
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008752 gl::Error error = buffer->mapRange(offset, length, access);
8753 if (error.isError())
8754 {
8755 context->recordError(error);
8756 return NULL;
8757 }
8758
8759 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008760 }
8761
8762 return NULL;
8763}
8764
8765void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8766{
8767 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8768
Geoff Langbfdea662014-07-23 14:16:32 -04008769 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008770 if (context)
8771 {
8772 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008773 {
Geoff Langb1196682014-07-23 13:47:29 -04008774 context->recordError(gl::Error(GL_INVALID_VALUE));
8775 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008776 }
Geoff Langbfdea662014-07-23 14:16:32 -04008777
8778 if (!gl::ValidBufferTarget(context, target))
8779 {
Geoff Langb1196682014-07-23 13:47:29 -04008780 context->recordError(gl::Error(GL_INVALID_ENUM));
8781 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008782 }
8783
8784 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8785
8786 if (buffer == NULL)
8787 {
Geoff Langb1196682014-07-23 13:47:29 -04008788 context->recordError(gl::Error(GL_INVALID_OPERATION));
8789 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008790 }
8791
8792 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8793 {
Geoff Langb1196682014-07-23 13:47:29 -04008794 context->recordError(gl::Error(GL_INVALID_OPERATION));
8795 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008796 }
8797
8798 // Check for buffer overflow
8799 size_t offsetSize = static_cast<size_t>(offset);
8800 size_t lengthSize = static_cast<size_t>(length);
8801
8802 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8803 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8804 {
Geoff Langb1196682014-07-23 13:47:29 -04008805 context->recordError(gl::Error(GL_INVALID_VALUE));
8806 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008807 }
8808
8809 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008810 }
8811}
8812
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008813__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8814{
8815 struct Extension
8816 {
8817 const char *name;
8818 __eglMustCastToProperFunctionPointerType address;
8819 };
8820
8821 static const Extension glExtensions[] =
8822 {
8823 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008824 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008825 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008826 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8827 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8828 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8829 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8830 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8831 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8832 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008833 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008834 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008835 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8836 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8837 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8838 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008839 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8840 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8841 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8842 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8843 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8844 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8845 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008846 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008847 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8848 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8849 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008850 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008851 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8852 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8853 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008854 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8855 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8856 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008857
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008858 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008859 {
8860 if (strcmp(procname, glExtensions[ext].name) == 0)
8861 {
8862 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8863 }
8864 }
8865
8866 return NULL;
8867}
8868
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008869// Non-public functions used by EGL
8870
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008871bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008872{
8873 EVENT("(egl::Surface* surface = 0x%0.8p)",
8874 surface);
8875
Geoff Langbfdea662014-07-23 14:16:32 -04008876 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008877 if (context)
8878 {
8879 gl::Texture2D *textureObject = context->getTexture2D();
8880 ASSERT(textureObject != NULL);
8881
8882 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008883 {
Geoff Langbfdea662014-07-23 14:16:32 -04008884 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008885 }
Geoff Langbfdea662014-07-23 14:16:32 -04008886
8887 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008888 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008889
8890 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008891}
8892
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008893}