blob: d41d2c23629151182303b60544f6088eeeb98510 [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:
268 context->bindTexture2D(texture);
269 return;
Geoff Langb1196682014-07-23 13:47:29 -0400270
Geoff Langbfdea662014-07-23 14:16:32 -0400271 case GL_TEXTURE_CUBE_MAP:
272 context->bindTextureCubeMap(texture);
273 return;
Geoff Langb1196682014-07-23 13:47:29 -0400274
Geoff Langbfdea662014-07-23 14:16:32 -0400275 case GL_TEXTURE_3D:
276 if (context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000277 {
Geoff Langb1196682014-07-23 13:47:29 -0400278 context->recordError(gl::Error(GL_INVALID_ENUM));
279 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000280 }
Geoff Langbfdea662014-07-23 14:16:32 -0400281 context->bindTexture3D(texture);
282 return;
Geoff Langb1196682014-07-23 13:47:29 -0400283
Geoff Langbfdea662014-07-23 14:16:32 -0400284 case GL_TEXTURE_2D_ARRAY:
285 if (context->getClientVersion() < 3)
286 {
Geoff Langb1196682014-07-23 13:47:29 -0400287 context->recordError(gl::Error(GL_INVALID_ENUM));
288 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400289 }
290 context->bindTexture2DArray(texture);
291 return;
Geoff Langb1196682014-07-23 13:47:29 -0400292
Geoff Langbfdea662014-07-23 14:16:32 -0400293 default:
Geoff Langb1196682014-07-23 13:47:29 -0400294 context->recordError(gl::Error(GL_INVALID_ENUM));
295 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000296 }
297 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000298}
299
300void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
301{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000302 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000303 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000304
Geoff Langbfdea662014-07-23 14:16:32 -0400305 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000306
Geoff Langbfdea662014-07-23 14:16:32 -0400307 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000308 {
Geoff Langbfdea662014-07-23 14:16:32 -0400309 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000310 }
311}
312
313void __stdcall glBlendEquation(GLenum mode)
314{
315 glBlendEquationSeparate(mode, mode);
316}
317
318void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
319{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000320 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000321
Geoff Langbfdea662014-07-23 14:16:32 -0400322 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400323 if (context)
324 {
Geoff Langb1196682014-07-23 13:47:29 -0400325 switch (modeRGB)
326 {
327 case GL_FUNC_ADD:
328 case GL_FUNC_SUBTRACT:
329 case GL_FUNC_REVERSE_SUBTRACT:
330 case GL_MIN:
331 case GL_MAX:
332 break;
333
334 default:
335 context->recordError(gl::Error(GL_INVALID_ENUM));
336 return;
337 }
338
339 switch (modeAlpha)
340 {
341 case GL_FUNC_ADD:
342 case GL_FUNC_SUBTRACT:
343 case GL_FUNC_REVERSE_SUBTRACT:
344 case GL_MIN:
345 case GL_MAX:
346 break;
347
348 default:
349 context->recordError(gl::Error(GL_INVALID_ENUM));
350 return;
351 }
352
Geoff Langbfdea662014-07-23 14:16:32 -0400353 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000354 }
355}
356
357void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
358{
359 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
360}
361
362void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000364 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 +0000365 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000366
Geoff Langbfdea662014-07-23 14:16:32 -0400367 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400368 if (context)
369 {
Geoff Langb1196682014-07-23 13:47:29 -0400370 switch (srcRGB)
371 {
372 case GL_ZERO:
373 case GL_ONE:
374 case GL_SRC_COLOR:
375 case GL_ONE_MINUS_SRC_COLOR:
376 case GL_DST_COLOR:
377 case GL_ONE_MINUS_DST_COLOR:
378 case GL_SRC_ALPHA:
379 case GL_ONE_MINUS_SRC_ALPHA:
380 case GL_DST_ALPHA:
381 case GL_ONE_MINUS_DST_ALPHA:
382 case GL_CONSTANT_COLOR:
383 case GL_ONE_MINUS_CONSTANT_COLOR:
384 case GL_CONSTANT_ALPHA:
385 case GL_ONE_MINUS_CONSTANT_ALPHA:
386 case GL_SRC_ALPHA_SATURATE:
387 break;
388
389 default:
390 context->recordError(gl::Error(GL_INVALID_ENUM));
391 return;
392 }
393
394 switch (dstRGB)
395 {
396 case GL_ZERO:
397 case GL_ONE:
398 case GL_SRC_COLOR:
399 case GL_ONE_MINUS_SRC_COLOR:
400 case GL_DST_COLOR:
401 case GL_ONE_MINUS_DST_COLOR:
402 case GL_SRC_ALPHA:
403 case GL_ONE_MINUS_SRC_ALPHA:
404 case GL_DST_ALPHA:
405 case GL_ONE_MINUS_DST_ALPHA:
406 case GL_CONSTANT_COLOR:
407 case GL_ONE_MINUS_CONSTANT_COLOR:
408 case GL_CONSTANT_ALPHA:
409 case GL_ONE_MINUS_CONSTANT_ALPHA:
410 break;
411
412 case GL_SRC_ALPHA_SATURATE:
413 if (context->getClientVersion() < 3)
414 {
415 context->recordError(gl::Error(GL_INVALID_ENUM));
416 return;
417 }
418 break;
419
420 default:
421 context->recordError(gl::Error(GL_INVALID_ENUM));
422 return;
423 }
424
425 switch (srcAlpha)
426 {
427 case GL_ZERO:
428 case GL_ONE:
429 case GL_SRC_COLOR:
430 case GL_ONE_MINUS_SRC_COLOR:
431 case GL_DST_COLOR:
432 case GL_ONE_MINUS_DST_COLOR:
433 case GL_SRC_ALPHA:
434 case GL_ONE_MINUS_SRC_ALPHA:
435 case GL_DST_ALPHA:
436 case GL_ONE_MINUS_DST_ALPHA:
437 case GL_CONSTANT_COLOR:
438 case GL_ONE_MINUS_CONSTANT_COLOR:
439 case GL_CONSTANT_ALPHA:
440 case GL_ONE_MINUS_CONSTANT_ALPHA:
441 case GL_SRC_ALPHA_SATURATE:
442 break;
443
444 default:
445 context->recordError(gl::Error(GL_INVALID_ENUM));
446 return;
447 }
448
449 switch (dstAlpha)
450 {
451 case GL_ZERO:
452 case GL_ONE:
453 case GL_SRC_COLOR:
454 case GL_ONE_MINUS_SRC_COLOR:
455 case GL_DST_COLOR:
456 case GL_ONE_MINUS_DST_COLOR:
457 case GL_SRC_ALPHA:
458 case GL_ONE_MINUS_SRC_ALPHA:
459 case GL_DST_ALPHA:
460 case GL_ONE_MINUS_DST_ALPHA:
461 case GL_CONSTANT_COLOR:
462 case GL_ONE_MINUS_CONSTANT_COLOR:
463 case GL_CONSTANT_ALPHA:
464 case GL_ONE_MINUS_CONSTANT_ALPHA:
465 break;
466
467 case GL_SRC_ALPHA_SATURATE:
468 if (context->getClientVersion() < 3)
469 {
470 context->recordError(gl::Error(GL_INVALID_ENUM));
471 return;
472 }
473 break;
474
475 default:
476 context->recordError(gl::Error(GL_INVALID_ENUM));
477 return;
478 }
479
480 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
481 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
482
483 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
484 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
485
486 if (constantColorUsed && constantAlphaUsed)
487 {
488 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
489 context->recordError(gl::Error(GL_INVALID_OPERATION));
490 return;
491 }
492
Geoff Langbfdea662014-07-23 14:16:32 -0400493 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000494 }
495}
496
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000497void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000498{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000499 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 +0000500 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000501
Geoff Langbfdea662014-07-23 14:16:32 -0400502 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400503 if (context)
504 {
Geoff Langb1196682014-07-23 13:47:29 -0400505 if (size < 0)
506 {
507 context->recordError(gl::Error(GL_INVALID_VALUE));
508 return;
509 }
510
511 switch (usage)
512 {
513 case GL_STREAM_DRAW:
514 case GL_STATIC_DRAW:
515 case GL_DYNAMIC_DRAW:
516 break;
517
518 case GL_STREAM_READ:
519 case GL_STREAM_COPY:
520 case GL_STATIC_READ:
521 case GL_STATIC_COPY:
522 case GL_DYNAMIC_READ:
523 case GL_DYNAMIC_COPY:
524 if (context->getClientVersion() < 3)
525 {
526 context->recordError(gl::Error(GL_INVALID_ENUM));
527 return;
528 }
529 break;
530
531 default:
532 context->recordError(gl::Error(GL_INVALID_ENUM));
533 return;
534 }
535
Geoff Langbfdea662014-07-23 14:16:32 -0400536 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000537 {
Geoff Langb1196682014-07-23 13:47:29 -0400538 context->recordError(gl::Error(GL_INVALID_ENUM));
539 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000540 }
541
Geoff Langbfdea662014-07-23 14:16:32 -0400542 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
543
544 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000545 {
Geoff Langb1196682014-07-23 13:47:29 -0400546 context->recordError(gl::Error(GL_INVALID_OPERATION));
547 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000548 }
Geoff Langbfdea662014-07-23 14:16:32 -0400549
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400550 gl::Error error = buffer->bufferData(data, size, usage);
551 if (error.isError())
552 {
553 context->recordError(error);
554 return;
555 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000556 }
557}
558
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000559void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000560{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000561 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 +0000562 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000563
Geoff Langbfdea662014-07-23 14:16:32 -0400564 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400565 if (context)
566 {
Geoff Langb1196682014-07-23 13:47:29 -0400567 if (size < 0 || offset < 0)
568 {
569 context->recordError(gl::Error(GL_INVALID_VALUE));
570 return;
571 }
572
573 if (data == NULL)
574 {
575 return;
576 }
577
Geoff Langbfdea662014-07-23 14:16:32 -0400578 if (!gl::ValidBufferTarget(context, target))
579 {
Geoff Langb1196682014-07-23 13:47:29 -0400580 context->recordError(gl::Error(GL_INVALID_ENUM));
581 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400582 }
583
584 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
585
586 if (!buffer)
587 {
Geoff Langb1196682014-07-23 13:47:29 -0400588 context->recordError(gl::Error(GL_INVALID_OPERATION));
589 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400590 }
591
592 if (buffer->isMapped())
593 {
Geoff Langb1196682014-07-23 13:47:29 -0400594 context->recordError(gl::Error(GL_INVALID_OPERATION));
595 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400596 }
597
598 // Check for possible overflow of size + offset
599 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
600 {
Geoff Langb1196682014-07-23 13:47:29 -0400601 context->recordError(gl::Error(GL_OUT_OF_MEMORY));
602 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400603 }
604
605 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000606 {
Geoff Langb1196682014-07-23 13:47:29 -0400607 context->recordError(gl::Error(GL_INVALID_VALUE));
608 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000609 }
610
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400611 gl::Error error = buffer->bufferSubData(data, size, offset);
612 if (error.isError())
613 {
614 context->recordError(error);
615 return;
616 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000617 }
618}
619
620GLenum __stdcall glCheckFramebufferStatus(GLenum target)
621{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000622 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000623
Geoff Langbfdea662014-07-23 14:16:32 -0400624 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400625 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000626 {
Geoff Langb1196682014-07-23 13:47:29 -0400627 if (!gl::ValidFramebufferTarget(target))
628 {
629 context->recordError(gl::Error(GL_INVALID_ENUM));
630 return 0;
631 }
632
Geoff Langbfdea662014-07-23 14:16:32 -0400633 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
634 ASSERT(framebuffer);
635 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000636 }
637
638 return 0;
639}
640
641void __stdcall glClear(GLbitfield mask)
642{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000643 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000644
Geoff Langbfdea662014-07-23 14:16:32 -0400645 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400646 if (context)
647 {
648 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
649
650 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000651 {
Geoff Langb1196682014-07-23 13:47:29 -0400652 context->recordError(gl::Error(GL_INVALID_FRAMEBUFFER_OPERATION));
653 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000654 }
Geoff Langbfdea662014-07-23 14:16:32 -0400655
656 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
657 {
Geoff Langb1196682014-07-23 13:47:29 -0400658 context->recordError(gl::Error(GL_INVALID_VALUE));
659 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400660 }
661
Geoff Langcc79b8c2014-07-25 13:48:02 -0400662 gl::Error error = context->clear(mask);
663 if (error.isError())
664 {
665 context->recordError(error);
666 return;
667 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000668 }
669}
670
671void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
672{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000673 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000674 red, green, blue, alpha);
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().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000680 }
681}
682
683void __stdcall glClearDepthf(GLclampf depth)
684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000685 EVENT("(GLclampf depth = %f)", depth);
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().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000691 }
692}
693
694void __stdcall glClearStencil(GLint s)
695{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000696 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000697
Geoff Langbfdea662014-07-23 14:16:32 -0400698 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400699 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000700 {
Geoff Langbfdea662014-07-23 14:16:32 -0400701 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000702 }
703}
704
705void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
706{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000707 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000708 red, green, blue, alpha);
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)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000712 {
Geoff Langbfdea662014-07-23 14:16:32 -0400713 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000714 }
715}
716
717void __stdcall glCompileShader(GLuint shader)
718{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000719 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000720
Geoff Langbfdea662014-07-23 14:16:32 -0400721 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400722 if (context)
723 {
724 gl::Shader *shaderObject = context->getShader(shader);
725
726 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000727 {
Geoff Langbfdea662014-07-23 14:16:32 -0400728 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000729 {
Geoff Langb1196682014-07-23 13:47:29 -0400730 context->recordError(gl::Error(GL_INVALID_OPERATION));
731 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000732 }
Geoff Langbfdea662014-07-23 14:16:32 -0400733 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000734 {
Geoff Langb1196682014-07-23 13:47:29 -0400735 context->recordError(gl::Error(GL_INVALID_VALUE));
736 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000737 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000738 }
Geoff Langbfdea662014-07-23 14:16:32 -0400739
740 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000741 }
Geoff Langbfdea662014-07-23 14:16:32 -0400742}
743
744void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
745 GLint border, GLsizei imageSize, const GLvoid* data)
746{
747 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
748 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
749 target, level, internalformat, width, height, border, imageSize, data);
750
751 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400752 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000753 {
Geoff Langbfdea662014-07-23 14:16:32 -0400754 if (context->getClientVersion() < 3 &&
755 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
756 0, 0, width, height, border, GL_NONE, GL_NONE, data))
757 {
758 return;
759 }
760
761 if (context->getClientVersion() >= 3 &&
762 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
763 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
764 {
765 return;
766 }
767
Geoff Lang5d601382014-07-22 15:14:06 -0400768 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
769 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400770 {
Geoff Langb1196682014-07-23 13:47:29 -0400771 context->recordError(gl::Error(GL_INVALID_VALUE));
772 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400773 }
774
775 switch (target)
776 {
777 case GL_TEXTURE_2D:
778 {
779 gl::Texture2D *texture = context->getTexture2D();
780 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
781 }
782 break;
783
784 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
785 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
786 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
787 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
788 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
789 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
790 {
791 gl::TextureCubeMap *texture = context->getTextureCubeMap();
792 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
793 }
794 break;
795
796 default:
Geoff Langb1196682014-07-23 13:47:29 -0400797 context->recordError(gl::Error(GL_INVALID_ENUM));
798 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400799 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000800 }
801}
802
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000803void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
804 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000805{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000806 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000807 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000808 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000809 target, level, xoffset, yoffset, width, height, format, imageSize, data);
810
Geoff Langbfdea662014-07-23 14:16:32 -0400811 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400812 if (context)
813 {
814 if (context->getClientVersion() < 3 &&
815 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
816 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000817 {
Geoff Langbfdea662014-07-23 14:16:32 -0400818 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000819 }
Geoff Langbfdea662014-07-23 14:16:32 -0400820
821 if (context->getClientVersion() >= 3 &&
822 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
823 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
824 {
825 return;
826 }
827
Geoff Lang5d601382014-07-22 15:14:06 -0400828 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
829 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400830 {
Geoff Langb1196682014-07-23 13:47:29 -0400831 context->recordError(gl::Error(GL_INVALID_VALUE));
832 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400833 }
834
835 switch (target)
836 {
837 case GL_TEXTURE_2D:
838 {
839 gl::Texture2D *texture = context->getTexture2D();
840 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
841 }
842 break;
843
844 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
845 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
846 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
847 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
848 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
850 {
851 gl::TextureCubeMap *texture = context->getTextureCubeMap();
852 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
853 }
854 break;
855
856 default:
Geoff Langb1196682014-07-23 13:47:29 -0400857 context->recordError(gl::Error(GL_INVALID_ENUM));
858 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400859 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000860 }
861}
862
863void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000865 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000866 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000867 target, level, internalformat, x, y, width, height, border);
868
Geoff Langbfdea662014-07-23 14:16:32 -0400869 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400870 if (context)
871 {
872 if (context->getClientVersion() < 3 &&
873 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
874 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000875 {
Geoff Langbfdea662014-07-23 14:16:32 -0400876 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000877 }
Geoff Langbfdea662014-07-23 14:16:32 -0400878
879 if (context->getClientVersion() >= 3 &&
880 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
881 0, 0, 0, x, y, width, height, border))
882 {
883 return;
884 }
885
886 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
887
888 switch (target)
889 {
890 case GL_TEXTURE_2D:
891 {
892 gl::Texture2D *texture = context->getTexture2D();
893 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
894 }
895 break;
896
897 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
898 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
899 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
900 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
901 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
902 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
903 {
904 gl::TextureCubeMap *texture = context->getTextureCubeMap();
905 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
906 }
907 break;
908
Geoff Langb1196682014-07-23 13:47:29 -0400909 default:
910 context->recordError(gl::Error(GL_INVALID_ENUM));
911 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400912 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000913 }
914}
915
916void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000918 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000919 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000920 target, level, xoffset, yoffset, x, y, width, height);
921
Geoff Langbfdea662014-07-23 14:16:32 -0400922 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400923 if (context)
924 {
925 if (context->getClientVersion() < 3 &&
926 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
927 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000928 {
Geoff Langbfdea662014-07-23 14:16:32 -0400929 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000930 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000931
Geoff Langbfdea662014-07-23 14:16:32 -0400932 if (context->getClientVersion() >= 3 &&
933 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
934 xoffset, yoffset, 0, x, y, width, height, 0))
935 {
936 return;
937 }
938
939 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
940
941 switch (target)
942 {
943 case GL_TEXTURE_2D:
944 {
945 gl::Texture2D *texture = context->getTexture2D();
946 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
947 }
948 break;
949
950 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
951 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
952 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
953 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
954 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
955 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
956 {
957 gl::TextureCubeMap *texture = context->getTextureCubeMap();
958 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
959 }
960 break;
961
962 default:
Geoff Langb1196682014-07-23 13:47:29 -0400963 context->recordError(gl::Error(GL_INVALID_ENUM));
964 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400965 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000966 }
967}
968
969GLuint __stdcall glCreateProgram(void)
970{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000971 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000972
Geoff Langbfdea662014-07-23 14:16:32 -0400973 gl::Context *context = gl::getNonLostContext();
974 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000975 {
Geoff Langbfdea662014-07-23 14:16:32 -0400976 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000977 }
978
979 return 0;
980}
981
982GLuint __stdcall glCreateShader(GLenum type)
983{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000984 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000985
Geoff Langbfdea662014-07-23 14:16:32 -0400986 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400987 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000988 {
Geoff Langbfdea662014-07-23 14:16:32 -0400989 switch (type)
990 {
991 case GL_FRAGMENT_SHADER:
992 case GL_VERTEX_SHADER:
993 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -0400994
Geoff Langbfdea662014-07-23 14:16:32 -0400995 default:
Geoff Langb1196682014-07-23 13:47:29 -0400996 context->recordError(gl::Error(GL_INVALID_ENUM));
997 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -0400998 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000999 }
1000
1001 return 0;
1002}
1003
1004void __stdcall glCullFace(GLenum mode)
1005{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001006 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001007
Geoff Langb1196682014-07-23 13:47:29 -04001008 gl::Context *context = gl::getNonLostContext();
1009 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001010 {
Geoff Langb1196682014-07-23 13:47:29 -04001011 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001012 {
Geoff Langb1196682014-07-23 13:47:29 -04001013 case GL_FRONT:
1014 case GL_BACK:
1015 case GL_FRONT_AND_BACK:
1016 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001017
Geoff Langb1196682014-07-23 13:47:29 -04001018 default:
1019 context->recordError(gl::Error(GL_INVALID_ENUM));
1020 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001021 }
Geoff Langb1196682014-07-23 13:47:29 -04001022
1023 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001024 }
1025}
1026
1027void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
1028{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001029 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001030
Geoff Langbfdea662014-07-23 14:16:32 -04001031 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001032 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001033 {
Geoff Langb1196682014-07-23 13:47:29 -04001034 if (n < 0)
1035 {
1036 context->recordError(gl::Error(GL_INVALID_VALUE));
1037 return;
1038 }
1039
Geoff Langbfdea662014-07-23 14:16:32 -04001040 for (int i = 0; i < n; i++)
1041 {
1042 context->deleteBuffer(buffers[i]);
1043 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001044 }
1045}
1046
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001047void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
1048{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001049 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001050
Geoff Langbfdea662014-07-23 14:16:32 -04001051 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001052 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001053 {
Geoff Langb1196682014-07-23 13:47:29 -04001054 if (n < 0)
1055 {
1056 context->recordError(gl::Error(GL_INVALID_VALUE));
1057 return;
1058 }
1059
Geoff Langbfdea662014-07-23 14:16:32 -04001060 for (int i = 0; i < n; i++)
1061 {
1062 context->deleteFenceNV(fences[i]);
1063 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001064 }
1065}
1066
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001067void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1068{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001069 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001070
Geoff Langbfdea662014-07-23 14:16:32 -04001071 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001072 if (context)
1073 {
Geoff Langb1196682014-07-23 13:47:29 -04001074 if (n < 0)
1075 {
1076 context->recordError(gl::Error(GL_INVALID_VALUE));
1077 return;
1078 }
1079
Geoff Langbfdea662014-07-23 14:16:32 -04001080 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001081 {
Geoff Langbfdea662014-07-23 14:16:32 -04001082 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001083 {
Geoff Langbfdea662014-07-23 14:16:32 -04001084 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001085 }
1086 }
1087 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001088}
1089
1090void __stdcall glDeleteProgram(GLuint program)
1091{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001092 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001093
Geoff Langbfdea662014-07-23 14:16:32 -04001094 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001095 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001096 {
Geoff Langb1196682014-07-23 13:47:29 -04001097 if (program == 0)
1098 {
1099 return;
1100 }
1101
Geoff Langbfdea662014-07-23 14:16:32 -04001102 if (!context->getProgram(program))
1103 {
1104 if(context->getShader(program))
1105 {
Geoff Langb1196682014-07-23 13:47:29 -04001106 context->recordError(gl::Error(GL_INVALID_OPERATION));
1107 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001108 }
1109 else
1110 {
Geoff Langb1196682014-07-23 13:47:29 -04001111 context->recordError(gl::Error(GL_INVALID_VALUE));
1112 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001113 }
1114 }
1115
1116 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001117 }
1118}
1119
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001120void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1121{
1122 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1123
Geoff Langbfdea662014-07-23 14:16:32 -04001124 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001125 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001126 {
Geoff Langb1196682014-07-23 13:47:29 -04001127 if (n < 0)
1128 {
1129 context->recordError(gl::Error(GL_INVALID_VALUE));
1130 return;
1131 }
1132
Geoff Langbfdea662014-07-23 14:16:32 -04001133 for (int i = 0; i < n; i++)
1134 {
1135 context->deleteQuery(ids[i]);
1136 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001137 }
1138}
1139
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001140void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1141{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001142 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001143
Geoff Langbfdea662014-07-23 14:16:32 -04001144 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001145 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001146 {
Geoff Langb1196682014-07-23 13:47:29 -04001147 if (n < 0)
1148 {
1149 context->recordError(gl::Error(GL_INVALID_VALUE));
1150 return;
1151 }
1152
Geoff Langbfdea662014-07-23 14:16:32 -04001153 for (int i = 0; i < n; i++)
1154 {
1155 context->deleteRenderbuffer(renderbuffers[i]);
1156 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001157 }
1158}
1159
1160void __stdcall glDeleteShader(GLuint shader)
1161{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001162 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001163
Geoff Langbfdea662014-07-23 14:16:32 -04001164 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001165 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001166 {
Geoff Langb1196682014-07-23 13:47:29 -04001167 if (shader == 0)
1168 {
1169 return;
1170 }
1171
Geoff Langbfdea662014-07-23 14:16:32 -04001172 if (!context->getShader(shader))
1173 {
1174 if(context->getProgram(shader))
1175 {
Geoff Langb1196682014-07-23 13:47:29 -04001176 context->recordError(gl::Error(GL_INVALID_OPERATION));
1177 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001178 }
1179 else
1180 {
Geoff Langb1196682014-07-23 13:47:29 -04001181 context->recordError(gl::Error(GL_INVALID_VALUE));
1182 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001183 }
1184 }
1185
1186 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001187 }
1188}
1189
1190void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1191{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001192 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001193
Geoff Langbfdea662014-07-23 14:16:32 -04001194 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001195 if (context)
1196 {
Geoff Langb1196682014-07-23 13:47:29 -04001197 if (n < 0)
1198 {
1199 context->recordError(gl::Error(GL_INVALID_VALUE));
1200 return;
1201 }
1202
Geoff Langbfdea662014-07-23 14:16:32 -04001203 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001204 {
Geoff Langbfdea662014-07-23 14:16:32 -04001205 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001206 {
Geoff Langbfdea662014-07-23 14:16:32 -04001207 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001208 }
1209 }
1210 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001211}
1212
1213void __stdcall glDepthFunc(GLenum func)
1214{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001215 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001216
Geoff Langbfdea662014-07-23 14:16:32 -04001217 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001218 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001219 {
Geoff Langb1196682014-07-23 13:47:29 -04001220 switch (func)
1221 {
1222 case GL_NEVER:
1223 case GL_ALWAYS:
1224 case GL_LESS:
1225 case GL_LEQUAL:
1226 case GL_EQUAL:
1227 case GL_GREATER:
1228 case GL_GEQUAL:
1229 case GL_NOTEQUAL:
1230 context->getState().setDepthFunc(func);
1231 break;
1232
1233 default:
1234 context->recordError(gl::Error(GL_INVALID_ENUM));
1235 return;
1236 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001237 }
1238}
1239
1240void __stdcall glDepthMask(GLboolean flag)
1241{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001242 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001243
Geoff Langbfdea662014-07-23 14:16:32 -04001244 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001245 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001246 {
Geoff Langbfdea662014-07-23 14:16:32 -04001247 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001248 }
1249}
1250
1251void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1252{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001253 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001254
Geoff Langbfdea662014-07-23 14:16:32 -04001255 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001256 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001257 {
Geoff Langbfdea662014-07-23 14:16:32 -04001258 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001259 }
1260}
1261
1262void __stdcall glDetachShader(GLuint program, GLuint shader)
1263{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001264 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001265
Geoff Langbfdea662014-07-23 14:16:32 -04001266 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001267 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001268 {
Geoff Langbfdea662014-07-23 14:16:32 -04001269 gl::Program *programObject = context->getProgram(program);
1270 gl::Shader *shaderObject = context->getShader(shader);
1271
1272 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001273 {
Geoff Langbfdea662014-07-23 14:16:32 -04001274 gl::Shader *shaderByProgramHandle;
1275 shaderByProgramHandle = context->getShader(program);
1276 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277 {
Geoff Langb1196682014-07-23 13:47:29 -04001278 context->recordError(gl::Error(GL_INVALID_VALUE));
1279 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001280 }
Geoff Langbfdea662014-07-23 14:16:32 -04001281 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001282 {
Geoff Langb1196682014-07-23 13:47:29 -04001283 context->recordError(gl::Error(GL_INVALID_OPERATION));
1284 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001285 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001286 }
Geoff Langbfdea662014-07-23 14:16:32 -04001287
1288 if (!shaderObject)
1289 {
1290 gl::Program *programByShaderHandle = context->getProgram(shader);
1291 if (!programByShaderHandle)
1292 {
Geoff Langb1196682014-07-23 13:47:29 -04001293 context->recordError(gl::Error(GL_INVALID_VALUE));
1294 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001295 }
1296 else
1297 {
Geoff Langb1196682014-07-23 13:47:29 -04001298 context->recordError(gl::Error(GL_INVALID_OPERATION));
1299 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001300 }
1301 }
1302
1303 if (!programObject->detachShader(shaderObject))
1304 {
Geoff Langb1196682014-07-23 13:47:29 -04001305 context->recordError(gl::Error(GL_INVALID_OPERATION));
1306 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001307 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001308 }
1309}
1310
1311void __stdcall glDisable(GLenum cap)
1312{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001313 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001314
Geoff Langbfdea662014-07-23 14:16:32 -04001315 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001316 if (context)
1317 {
1318 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001319 {
Geoff Langb1196682014-07-23 13:47:29 -04001320 context->recordError(gl::Error(GL_INVALID_ENUM));
1321 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001322 }
Geoff Langbfdea662014-07-23 14:16:32 -04001323
1324 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001325 }
1326}
1327
1328void __stdcall glDisableVertexAttribArray(GLuint index)
1329{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001330 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001331
Geoff Langbfdea662014-07-23 14:16:32 -04001332 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001333 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001334 {
Geoff Langb1196682014-07-23 13:47:29 -04001335 if (index >= gl::MAX_VERTEX_ATTRIBS)
1336 {
1337 context->recordError(gl::Error(GL_INVALID_VALUE));
1338 return;
1339 }
1340
Geoff Langbfdea662014-07-23 14:16:32 -04001341 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001342 }
1343}
1344
1345void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1346{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001347 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001348
Geoff Langbfdea662014-07-23 14:16:32 -04001349 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001350 if (context)
1351 {
Jamie Madill2b976812014-08-25 15:47:49 -04001352 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001353 {
Geoff Langbfdea662014-07-23 14:16:32 -04001354 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001355 }
Geoff Langbfdea662014-07-23 14:16:32 -04001356
1357 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001358 }
1359}
1360
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001361void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1362{
1363 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1364
Geoff Langbfdea662014-07-23 14:16:32 -04001365 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001366 if (context)
1367 {
1368 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001369 {
Geoff Langbfdea662014-07-23 14:16:32 -04001370 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001371 }
Geoff Langbfdea662014-07-23 14:16:32 -04001372
1373 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001374 }
1375}
1376
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001377void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001378{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001379 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 +00001380 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001381
Geoff Langbfdea662014-07-23 14:16:32 -04001382 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001383 if (context)
1384 {
Jamie Madill2b976812014-08-25 15:47:49 -04001385 rx::RangeUI indexRange;
1386 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001387 {
Geoff Langbfdea662014-07-23 14:16:32 -04001388 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001389 }
Geoff Langbfdea662014-07-23 14:16:32 -04001390
Jamie Madill2b976812014-08-25 15:47:49 -04001391 context->drawElements(mode, count, type, indices, 0, indexRange);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001392 }
1393}
1394
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001395void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1396{
1397 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1398 mode, count, type, indices, primcount);
1399
Geoff Langbfdea662014-07-23 14:16:32 -04001400 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001401 if (context)
1402 {
Jamie Madill2b976812014-08-25 15:47:49 -04001403 rx::RangeUI indexRange;
1404 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001405 {
Geoff Langbfdea662014-07-23 14:16:32 -04001406 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001407 }
Geoff Langbfdea662014-07-23 14:16:32 -04001408
Jamie Madill2b976812014-08-25 15:47:49 -04001409 context->drawElements(mode, count, type, indices, primcount, indexRange);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001410 }
1411}
1412
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001413void __stdcall glEnable(GLenum cap)
1414{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001415 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001416
Geoff Langbfdea662014-07-23 14:16:32 -04001417 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001418 if (context)
1419 {
1420 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001421 {
Geoff Langb1196682014-07-23 13:47:29 -04001422 context->recordError(gl::Error(GL_INVALID_ENUM));
1423 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001424 }
Geoff Langbfdea662014-07-23 14:16:32 -04001425
1426 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001427 }
1428}
1429
1430void __stdcall glEnableVertexAttribArray(GLuint index)
1431{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001432 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001433
Geoff Langbfdea662014-07-23 14:16:32 -04001434 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001435 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001436 {
Geoff Langb1196682014-07-23 13:47:29 -04001437 if (index >= gl::MAX_VERTEX_ATTRIBS)
1438 {
1439 context->recordError(gl::Error(GL_INVALID_VALUE));
1440 return;
1441 }
1442
Geoff Langbfdea662014-07-23 14:16:32 -04001443 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001444 }
1445}
1446
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001447void __stdcall glEndQueryEXT(GLenum target)
1448{
1449 EVENT("GLenum target = 0x%X)", target);
1450
Geoff Langbfdea662014-07-23 14:16:32 -04001451 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001452 if (context)
1453 {
1454 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001455 {
Geoff Langbfdea662014-07-23 14:16:32 -04001456 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001457 }
Geoff Langbfdea662014-07-23 14:16:32 -04001458
Geoff Lang5aad9672014-09-08 11:10:42 -04001459 gl::Error error = context->endQuery(target);
1460 if (error.isError())
1461 {
1462 context->recordError(error);
1463 return;
1464 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001465 }
1466}
1467
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001468void __stdcall glFinishFenceNV(GLuint fence)
1469{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001470 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001471
Geoff Langbfdea662014-07-23 14:16:32 -04001472 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001473 if (context)
1474 {
1475 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1476
1477 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001478 {
Geoff Langb1196682014-07-23 13:47:29 -04001479 context->recordError(gl::Error(GL_INVALID_OPERATION));
1480 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001481 }
Geoff Langbfdea662014-07-23 14:16:32 -04001482
1483 if (fenceObject->isFence() != GL_TRUE)
1484 {
Geoff Langb1196682014-07-23 13:47:29 -04001485 context->recordError(gl::Error(GL_INVALID_OPERATION));
1486 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001487 }
1488
1489 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001490 }
1491}
1492
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001493void __stdcall glFinish(void)
1494{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001495 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001496
Geoff Langbfdea662014-07-23 14:16:32 -04001497 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001498 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001499 {
Geoff Langbfdea662014-07-23 14:16:32 -04001500 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001501 }
1502}
1503
1504void __stdcall glFlush(void)
1505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001506 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001507
Geoff Langbfdea662014-07-23 14:16:32 -04001508 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001509 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001510 {
Geoff Langbfdea662014-07-23 14:16:32 -04001511 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001512 }
1513}
1514
1515void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1516{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001517 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001518 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001519
Geoff Langbfdea662014-07-23 14:16:32 -04001520 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001521 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001522 {
Geoff Langb1196682014-07-23 13:47:29 -04001523 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1524 {
1525 context->recordError(gl::Error(GL_INVALID_ENUM));
1526 return;
1527 }
1528
Geoff Langbfdea662014-07-23 14:16:32 -04001529 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1530 {
1531 return;
1532 }
1533
1534 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1535 ASSERT(framebuffer);
1536
1537 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1538 {
1539 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1540 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1541 }
1542 else
1543 {
1544 switch (attachment)
1545 {
1546 case GL_DEPTH_ATTACHMENT:
1547 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1548 break;
1549 case GL_STENCIL_ATTACHMENT:
1550 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1551 break;
1552 case GL_DEPTH_STENCIL_ATTACHMENT:
1553 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1554 break;
1555 default:
1556 UNREACHABLE();
1557 break;
1558 }
1559 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001560 }
1561}
1562
1563void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1564{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001565 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001566 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001567
Geoff Langbfdea662014-07-23 14:16:32 -04001568 gl::Context *context = gl::getNonLostContext();
1569 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001570 {
Geoff Langbfdea662014-07-23 14:16:32 -04001571 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001572 {
Geoff Langbfdea662014-07-23 14:16:32 -04001573 return;
1574 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001575
Geoff Langbfdea662014-07-23 14:16:32 -04001576 if (texture == 0)
1577 {
1578 textarget = GL_NONE;
1579 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001580
Geoff Langbfdea662014-07-23 14:16:32 -04001581 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001582
Geoff Langbfdea662014-07-23 14:16:32 -04001583 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1584 {
1585 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1586 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1587 }
1588 else
1589 {
1590 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001591 {
Geoff Langbfdea662014-07-23 14:16:32 -04001592 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1593 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1594 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001595 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001596 }
1597 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001598}
1599
1600void __stdcall glFrontFace(GLenum mode)
1601{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001602 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001603
Geoff Langb1196682014-07-23 13:47:29 -04001604 gl::Context *context = gl::getNonLostContext();
1605 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001606 {
Geoff Langb1196682014-07-23 13:47:29 -04001607 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001608 {
Geoff Langb1196682014-07-23 13:47:29 -04001609 case GL_CW:
1610 case GL_CCW:
1611 context->getState().setFrontFace(mode);
1612 break;
1613 default:
1614 context->recordError(gl::Error(GL_INVALID_ENUM));
1615 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001616 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001617 }
1618}
1619
1620void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1621{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001622 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001623
Geoff Langbfdea662014-07-23 14:16:32 -04001624 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001625 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001626 {
Geoff Langb1196682014-07-23 13:47:29 -04001627 if (n < 0)
1628 {
1629 context->recordError(gl::Error(GL_INVALID_VALUE));
1630 return;
1631 }
1632
Geoff Langbfdea662014-07-23 14:16:32 -04001633 for (int i = 0; i < n; i++)
1634 {
1635 buffers[i] = context->createBuffer();
1636 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001637 }
1638}
1639
1640void __stdcall glGenerateMipmap(GLenum target)
1641{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001642 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001643
Geoff Langbfdea662014-07-23 14:16:32 -04001644 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001645 if (context)
1646 {
1647 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001648 {
Geoff Langb1196682014-07-23 13:47:29 -04001649 context->recordError(gl::Error(GL_INVALID_ENUM));
1650 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001651 }
Geoff Langbfdea662014-07-23 14:16:32 -04001652
1653 gl::Texture *texture = context->getTargetTexture(target);
1654
1655 if (texture == NULL)
1656 {
Geoff Langb1196682014-07-23 13:47:29 -04001657 context->recordError(gl::Error(GL_INVALID_OPERATION));
1658 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001659 }
1660
1661 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1662 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001663 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001664
1665 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1666 // unsized formats or that are color renderable and filterable. Since we do not track if
1667 // the texture was created with sized or unsized format (only sized formats are stored),
1668 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1669 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1670 // textures since they're the only texture format that can be created with unsized formats
1671 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1672 // was the last version to use add them.
1673 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1674 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1675 internalFormat == GL_ALPHA8_EXT;
1676
Geoff Lang5d601382014-07-22 15:14:06 -04001677 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1678 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001679 {
Geoff Langb1196682014-07-23 13:47:29 -04001680 context->recordError(gl::Error(GL_INVALID_OPERATION));
1681 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001682 }
1683
1684 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001685 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001686 {
Geoff Langb1196682014-07-23 13:47:29 -04001687 context->recordError(gl::Error(GL_INVALID_OPERATION));
1688 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001689 }
1690
1691 // Non-power of 2 ES2 check
1692 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1693 {
1694 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001695 context->recordError(gl::Error(GL_INVALID_OPERATION));
1696 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001697 }
1698
1699 // Cube completeness check
1700 if (target == GL_TEXTURE_CUBE_MAP)
1701 {
1702 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1703 if (!textureCube->isCubeComplete())
1704 {
Geoff Langb1196682014-07-23 13:47:29 -04001705 context->recordError(gl::Error(GL_INVALID_OPERATION));
1706 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001707 }
1708 }
1709
1710 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001711 }
1712}
1713
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001714void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001716 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001717
Geoff Langbfdea662014-07-23 14:16:32 -04001718 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001719 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001720 {
Geoff Langb1196682014-07-23 13:47:29 -04001721 if (n < 0)
1722 {
1723 context->recordError(gl::Error(GL_INVALID_VALUE));
1724 return;
1725 }
1726
Geoff Langbfdea662014-07-23 14:16:32 -04001727 for (int i = 0; i < n; i++)
1728 {
1729 fences[i] = context->createFenceNV();
1730 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001731 }
1732}
1733
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001734void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1735{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001736 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001737
Geoff Langbfdea662014-07-23 14:16:32 -04001738 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001739 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001740 {
Geoff Langb1196682014-07-23 13:47:29 -04001741 if (n < 0)
1742 {
1743 context->recordError(gl::Error(GL_INVALID_VALUE));
1744 return;
1745 }
1746
Geoff Langbfdea662014-07-23 14:16:32 -04001747 for (int i = 0; i < n; i++)
1748 {
1749 framebuffers[i] = context->createFramebuffer();
1750 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001751 }
1752}
1753
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001754void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1755{
1756 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1757
Geoff Langbfdea662014-07-23 14:16:32 -04001758 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001759 if (context)
1760 {
1761 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001762 {
Geoff Langb1196682014-07-23 13:47:29 -04001763 context->recordError(gl::Error(GL_INVALID_VALUE));
1764 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001765 }
Geoff Langbfdea662014-07-23 14:16:32 -04001766
1767 for (GLsizei i = 0; i < n; i++)
1768 {
1769 ids[i] = context->createQuery();
1770 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001771 }
1772}
1773
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001774void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1775{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001776 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001777
Geoff Langbfdea662014-07-23 14:16:32 -04001778 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001779 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001780 {
Geoff Langb1196682014-07-23 13:47:29 -04001781 if (n < 0)
1782 {
1783 context->recordError(gl::Error(GL_INVALID_VALUE));
1784 return;
1785 }
1786
Geoff Langbfdea662014-07-23 14:16:32 -04001787 for (int i = 0; i < n; i++)
1788 {
1789 renderbuffers[i] = context->createRenderbuffer();
1790 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001791 }
1792}
1793
1794void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1795{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001796 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001797
Geoff Langbfdea662014-07-23 14:16:32 -04001798 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001799 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001800 {
Geoff Langb1196682014-07-23 13:47:29 -04001801 if (n < 0)
1802 {
1803 context->recordError(gl::Error(GL_INVALID_VALUE));
1804 return;
1805 }
1806
Geoff Langbfdea662014-07-23 14:16:32 -04001807 for (int i = 0; i < n; i++)
1808 {
1809 textures[i] = context->createTexture();
1810 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001811 }
1812}
1813
daniel@transgaming.com85423182010-04-22 13:35:27 +00001814void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001815{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001816 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001817 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001818 program, index, bufsize, length, size, type, name);
1819
Geoff Langbfdea662014-07-23 14:16:32 -04001820 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001821 if (context)
1822 {
Geoff Langb1196682014-07-23 13:47:29 -04001823 if (bufsize < 0)
1824 {
1825 context->recordError(gl::Error(GL_INVALID_VALUE));
1826 return;
1827 }
1828
Geoff Langbfdea662014-07-23 14:16:32 -04001829 gl::Program *programObject = context->getProgram(program);
1830
1831 if (!programObject)
1832 {
1833 if (context->getShader(program))
1834 {
Geoff Langb1196682014-07-23 13:47:29 -04001835 context->recordError(gl::Error(GL_INVALID_OPERATION));
1836 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001837 }
1838 else
1839 {
Geoff Langb1196682014-07-23 13:47:29 -04001840 context->recordError(gl::Error(GL_INVALID_VALUE));
1841 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001842 }
1843 }
1844
1845 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001846 {
Geoff Langb1196682014-07-23 13:47:29 -04001847 context->recordError(gl::Error(GL_INVALID_VALUE));
1848 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001849 }
1850
Geoff Langbfdea662014-07-23 14:16:32 -04001851 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001852 }
1853}
1854
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001855void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001856{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001857 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001858 "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 +00001859 program, index, bufsize, length, size, type, name);
1860
Geoff Langbfdea662014-07-23 14:16:32 -04001861
1862 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001863 if (context)
1864 {
Geoff Langb1196682014-07-23 13:47:29 -04001865 if (bufsize < 0)
1866 {
1867 context->recordError(gl::Error(GL_INVALID_VALUE));
1868 return;
1869 }
1870
Geoff Langbfdea662014-07-23 14:16:32 -04001871 gl::Program *programObject = context->getProgram(program);
1872
1873 if (!programObject)
1874 {
1875 if (context->getShader(program))
1876 {
Geoff Langb1196682014-07-23 13:47:29 -04001877 context->recordError(gl::Error(GL_INVALID_OPERATION));
1878 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001879 }
1880 else
1881 {
Geoff Langb1196682014-07-23 13:47:29 -04001882 context->recordError(gl::Error(GL_INVALID_VALUE));
1883 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001884 }
1885 }
1886
1887 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001888 {
Geoff Langb1196682014-07-23 13:47:29 -04001889 context->recordError(gl::Error(GL_INVALID_VALUE));
1890 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001891 }
1892
Geoff Langbfdea662014-07-23 14:16:32 -04001893 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001894 }
1895}
1896
1897void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001899 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 +00001900 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001901
Geoff Langbfdea662014-07-23 14:16:32 -04001902 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001903 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001904 {
Geoff Langb1196682014-07-23 13:47:29 -04001905 if (maxcount < 0)
1906 {
1907 context->recordError(gl::Error(GL_INVALID_VALUE));
1908 return;
1909 }
1910
Geoff Langbfdea662014-07-23 14:16:32 -04001911 gl::Program *programObject = context->getProgram(program);
1912
1913 if (!programObject)
1914 {
1915 if (context->getShader(program))
1916 {
Geoff Langb1196682014-07-23 13:47:29 -04001917 context->recordError(gl::Error(GL_INVALID_OPERATION));
1918 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001919 }
1920 else
1921 {
Geoff Langb1196682014-07-23 13:47:29 -04001922 context->recordError(gl::Error(GL_INVALID_VALUE));
1923 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001924 }
1925 }
1926
1927 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001928 }
1929}
1930
Geoff Langb1196682014-07-23 13:47:29 -04001931GLint __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001932{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001933 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001934
Geoff Langbfdea662014-07-23 14:16:32 -04001935 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001936 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001937 {
Geoff Langbfdea662014-07-23 14:16:32 -04001938 gl::Program *programObject = context->getProgram(program);
1939
1940 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001941 {
Geoff Langbfdea662014-07-23 14:16:32 -04001942 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001943 {
Geoff Langb1196682014-07-23 13:47:29 -04001944 context->recordError(gl::Error(GL_INVALID_OPERATION));
1945 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001946 }
Geoff Langbfdea662014-07-23 14:16:32 -04001947 else
1948 {
Geoff Langb1196682014-07-23 13:47:29 -04001949 context->recordError(gl::Error(GL_INVALID_VALUE));
1950 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001951 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001952 }
Geoff Langbfdea662014-07-23 14:16:32 -04001953
1954 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1955 if (!programObject->isLinked() || !programBinary)
1956 {
Geoff Langb1196682014-07-23 13:47:29 -04001957 context->recordError(gl::Error(GL_INVALID_OPERATION));
1958 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001959 }
1960
1961 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001962 }
1963
1964 return -1;
1965}
1966
1967void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1968{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001969 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001970
Geoff Langbfdea662014-07-23 14:16:32 -04001971 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001972 if (context)
1973 {
1974 GLenum nativeType;
1975 unsigned int numParams = 0;
1976 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001977 {
Geoff Langbfdea662014-07-23 14:16:32 -04001978 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979 }
Geoff Langbfdea662014-07-23 14:16:32 -04001980
1981 if (nativeType == GL_BOOL)
1982 {
1983 context->getBooleanv(pname, params);
1984 }
1985 else
1986 {
1987 CastStateValues(context, nativeType, pname, numParams, params);
1988 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001989 }
1990}
1991
1992void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1993{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001994 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 +00001995
Geoff Langbfdea662014-07-23 14:16:32 -04001996 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001997 if (context)
1998 {
1999 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002000 {
Geoff Langb1196682014-07-23 13:47:29 -04002001 context->recordError(gl::Error(GL_INVALID_ENUM));
2002 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002003 }
Geoff Langbfdea662014-07-23 14:16:32 -04002004
2005 if (!gl::ValidBufferParameter(context, pname))
2006 {
Geoff Langb1196682014-07-23 13:47:29 -04002007 context->recordError(gl::Error(GL_INVALID_ENUM));
2008 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002009 }
2010
2011 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
2012
2013 if (!buffer)
2014 {
2015 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04002016 context->recordError(gl::Error(GL_INVALID_OPERATION));
2017 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002018 }
2019
2020 switch (pname)
2021 {
2022 case GL_BUFFER_USAGE:
2023 *params = static_cast<GLint>(buffer->getUsage());
2024 break;
2025 case GL_BUFFER_SIZE:
2026 *params = gl::clampCast<GLint>(buffer->getSize());
2027 break;
2028 case GL_BUFFER_ACCESS_FLAGS:
2029 *params = buffer->getAccessFlags();
2030 break;
2031 case GL_BUFFER_MAPPED:
2032 *params = static_cast<GLint>(buffer->isMapped());
2033 break;
2034 case GL_BUFFER_MAP_OFFSET:
2035 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2036 break;
2037 case GL_BUFFER_MAP_LENGTH:
2038 *params = gl::clampCast<GLint>(buffer->getMapLength());
2039 break;
2040 default: UNREACHABLE(); break;
2041 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002042 }
2043}
2044
2045GLenum __stdcall glGetError(void)
2046{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002047 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002048
2049 gl::Context *context = gl::getContext();
2050
2051 if (context)
2052 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002053 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002054 }
2055
2056 return GL_NO_ERROR;
2057}
2058
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002059void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
2060{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002061 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002062
Geoff Langbfdea662014-07-23 14:16:32 -04002063 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002064 if (context)
2065 {
2066 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2067
2068 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002069 {
Geoff Langb1196682014-07-23 13:47:29 -04002070 context->recordError(gl::Error(GL_INVALID_OPERATION));
2071 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002072 }
Geoff Langbfdea662014-07-23 14:16:32 -04002073
2074 if (fenceObject->isFence() != GL_TRUE)
2075 {
Geoff Langb1196682014-07-23 13:47:29 -04002076 context->recordError(gl::Error(GL_INVALID_OPERATION));
2077 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002078 }
2079
2080 switch (pname)
2081 {
2082 case GL_FENCE_STATUS_NV:
2083 case GL_FENCE_CONDITION_NV:
2084 break;
2085
Geoff Langb1196682014-07-23 13:47:29 -04002086 default:
2087 context->recordError(gl::Error(GL_INVALID_ENUM));
2088 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002089 }
2090
2091 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002092 }
2093}
2094
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002095void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2096{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002097 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002098
Geoff Langbfdea662014-07-23 14:16:32 -04002099 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002100 if (context)
2101 {
2102 GLenum nativeType;
2103 unsigned int numParams = 0;
2104 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002105 {
Geoff Langbfdea662014-07-23 14:16:32 -04002106 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002107 }
Geoff Langbfdea662014-07-23 14:16:32 -04002108
2109 if (nativeType == GL_FLOAT)
2110 {
2111 context->getFloatv(pname, params);
2112 }
2113 else
2114 {
2115 CastStateValues(context, nativeType, pname, numParams, params);
2116 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002117 }
2118}
2119
2120void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002122 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 +00002123 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002124
Geoff Langbfdea662014-07-23 14:16:32 -04002125 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002126 if (context)
2127 {
2128 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002129 {
Geoff Langb1196682014-07-23 13:47:29 -04002130 context->recordError(gl::Error(GL_INVALID_ENUM));
2131 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002132 }
2133
2134 int clientVersion = context->getClientVersion();
2135
2136 switch (pname)
2137 {
2138 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2139 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2140 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2141 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2142 break;
Geoff Langb1196682014-07-23 13:47:29 -04002143
Geoff Langbfdea662014-07-23 14:16:32 -04002144 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2145 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002146 {
Geoff Langb1196682014-07-23 13:47:29 -04002147 context->recordError(gl::Error(GL_INVALID_ENUM));
2148 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002149 }
Geoff Langbfdea662014-07-23 14:16:32 -04002150 break;
Geoff Langb1196682014-07-23 13:47:29 -04002151
Geoff Langbfdea662014-07-23 14:16:32 -04002152 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2153 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2154 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2155 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2156 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2157 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2158 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2159 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2160 if (clientVersion < 3)
2161 {
Geoff Langb1196682014-07-23 13:47:29 -04002162 context->recordError(gl::Error(GL_INVALID_ENUM));
2163 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002164 }
2165 break;
Geoff Langb1196682014-07-23 13:47:29 -04002166
Geoff Langbfdea662014-07-23 14:16:32 -04002167 default:
Geoff Langb1196682014-07-23 13:47:29 -04002168 context->recordError(gl::Error(GL_INVALID_ENUM));
2169 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002170 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002171
Geoff Langbfdea662014-07-23 14:16:32 -04002172 // Determine if the attachment is a valid enum
2173 switch (attachment)
2174 {
2175 case GL_BACK:
2176 case GL_FRONT:
2177 case GL_DEPTH:
2178 case GL_STENCIL:
2179 case GL_DEPTH_STENCIL_ATTACHMENT:
2180 if (clientVersion < 3)
2181 {
Geoff Langb1196682014-07-23 13:47:29 -04002182 context->recordError(gl::Error(GL_INVALID_ENUM));
2183 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002184 }
2185 break;
2186
2187 case GL_DEPTH_ATTACHMENT:
2188 case GL_STENCIL_ATTACHMENT:
2189 break;
2190
2191 default:
2192 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2193 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2194 {
Geoff Langb1196682014-07-23 13:47:29 -04002195 context->recordError(gl::Error(GL_INVALID_ENUM));
2196 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002197 }
2198 break;
2199 }
2200
2201 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2202 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2203
2204 if (framebufferHandle == 0)
2205 {
2206 if (clientVersion < 3)
2207 {
Geoff Langb1196682014-07-23 13:47:29 -04002208 context->recordError(gl::Error(GL_INVALID_OPERATION));
2209 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002210 }
2211
2212 switch (attachment)
2213 {
2214 case GL_BACK:
2215 case GL_DEPTH:
2216 case GL_STENCIL:
2217 break;
Geoff Langb1196682014-07-23 13:47:29 -04002218
Geoff Langbfdea662014-07-23 14:16:32 -04002219 default:
Geoff Langb1196682014-07-23 13:47:29 -04002220 context->recordError(gl::Error(GL_INVALID_OPERATION));
2221 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002222 }
2223 }
2224 else
2225 {
2226 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2227 {
2228 // Valid attachment query
2229 }
2230 else
2231 {
2232 switch (attachment)
2233 {
2234 case GL_DEPTH_ATTACHMENT:
2235 case GL_STENCIL_ATTACHMENT:
2236 break;
Geoff Langb1196682014-07-23 13:47:29 -04002237
Geoff Langbfdea662014-07-23 14:16:32 -04002238 case GL_DEPTH_STENCIL_ATTACHMENT:
2239 if (framebuffer->hasValidDepthStencil())
2240 {
Geoff Langb1196682014-07-23 13:47:29 -04002241 context->recordError(gl::Error(GL_INVALID_OPERATION));
2242 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002243 }
2244 break;
Geoff Langb1196682014-07-23 13:47:29 -04002245
Geoff Langbfdea662014-07-23 14:16:32 -04002246 default:
Geoff Langb1196682014-07-23 13:47:29 -04002247 context->recordError(gl::Error(GL_INVALID_OPERATION));
2248 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002249 }
2250 }
2251 }
2252
2253 GLenum attachmentType = GL_NONE;
2254 GLuint attachmentHandle = 0;
2255 GLuint attachmentLevel = 0;
2256 GLuint attachmentLayer = 0;
2257
2258 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2259
2260 if (attachmentObject)
2261 {
2262 attachmentType = attachmentObject->type();
2263 attachmentHandle = attachmentObject->id();
2264 attachmentLevel = attachmentObject->mipLevel();
2265 attachmentLayer = attachmentObject->layer();
2266 }
2267
2268 GLenum attachmentObjectType; // Type category
2269 if (framebufferHandle == 0)
2270 {
2271 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2272 }
2273 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2274 {
2275 attachmentObjectType = attachmentType;
2276 }
2277 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2278 {
2279 attachmentObjectType = GL_TEXTURE;
2280 }
2281 else
2282 {
2283 UNREACHABLE();
2284 return;
2285 }
2286
2287 if (attachmentObjectType == GL_NONE)
2288 {
2289 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2290 // is NONE, then querying any other pname will generate INVALID_ENUM.
2291
2292 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2293 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2294 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002295
Geoff Lang646559f2013-08-15 11:08:15 -04002296 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002297 {
Geoff Lang646559f2013-08-15 11:08:15 -04002298 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002299 *params = attachmentObjectType;
2300 break;
2301
Geoff Lang646559f2013-08-15 11:08:15 -04002302 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002303 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002304 {
Geoff Langb1196682014-07-23 13:47:29 -04002305 context->recordError(gl::Error(GL_INVALID_ENUM));
2306 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002307 }
Geoff Langbfdea662014-07-23 14:16:32 -04002308 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002309 break;
2310
2311 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002312 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002313 {
Geoff Langb1196682014-07-23 13:47:29 -04002314 context->recordError(gl::Error(GL_INVALID_ENUM));
2315 return;
Geoff Lang646559f2013-08-15 11:08:15 -04002316 }
2317 else
2318 {
Geoff Langb1196682014-07-23 13:47:29 -04002319 context->recordError(gl::Error(GL_INVALID_OPERATION));
2320 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002321 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002322 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002323 }
Geoff Langbfdea662014-07-23 14:16:32 -04002324 else
2325 {
2326 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2327 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2328 ASSERT(attachmentObject != NULL);
2329
2330 switch (pname)
2331 {
2332 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2333 *params = attachmentObjectType;
2334 break;
2335
2336 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2337 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2338 {
Geoff Langb1196682014-07-23 13:47:29 -04002339 context->recordError(gl::Error(GL_INVALID_ENUM));
2340 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002341 }
2342 *params = attachmentHandle;
2343 break;
2344
2345 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2346 if (attachmentObjectType != GL_TEXTURE)
2347 {
Geoff Langb1196682014-07-23 13:47:29 -04002348 context->recordError(gl::Error(GL_INVALID_ENUM));
2349 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002350 }
2351 *params = attachmentLevel;
2352 break;
2353
2354 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2355 if (attachmentObjectType != GL_TEXTURE)
2356 {
Geoff Langb1196682014-07-23 13:47:29 -04002357 context->recordError(gl::Error(GL_INVALID_ENUM));
2358 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002359 }
2360 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2361 break;
2362
2363 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2364 *params = attachmentObject->getRedSize();
2365 break;
2366
2367 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2368 *params = attachmentObject->getGreenSize();
2369 break;
2370
2371 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2372 *params = attachmentObject->getBlueSize();
2373 break;
2374
2375 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2376 *params = attachmentObject->getAlphaSize();
2377 break;
2378
2379 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2380 *params = attachmentObject->getDepthSize();
2381 break;
2382
2383 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2384 *params = attachmentObject->getStencilSize();
2385 break;
2386
2387 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2388 if (attachment == GL_DEPTH_STENCIL)
2389 {
Geoff Langb1196682014-07-23 13:47:29 -04002390 context->recordError(gl::Error(GL_INVALID_OPERATION));
2391 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002392 }
2393 *params = attachmentObject->getComponentType();
2394 break;
2395
2396 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2397 *params = attachmentObject->getColorEncoding();
2398 break;
2399
2400 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2401 if (attachmentObjectType != GL_TEXTURE)
2402 {
Geoff Langb1196682014-07-23 13:47:29 -04002403 context->recordError(gl::Error(GL_INVALID_ENUM));
2404 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002405 }
2406 *params = attachmentLayer;
2407 break;
2408
2409 default:
2410 UNREACHABLE();
2411 break;
2412 }
2413 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002414 }
2415}
2416
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002417GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2418{
2419 EVENT("()");
2420
Geoff Langbfdea662014-07-23 14:16:32 -04002421 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002422
Geoff Langbfdea662014-07-23 14:16:32 -04002423 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002424 {
Geoff Langbfdea662014-07-23 14:16:32 -04002425 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002426 }
Geoff Langbfdea662014-07-23 14:16:32 -04002427
2428 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002429}
2430
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002431void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2432{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002433 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002434
Geoff Langbfdea662014-07-23 14:16:32 -04002435 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002436 if (context)
2437 {
2438 GLenum nativeType;
2439 unsigned int numParams = 0;
2440
2441 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442 {
Geoff Langbfdea662014-07-23 14:16:32 -04002443 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002444 }
Geoff Langbfdea662014-07-23 14:16:32 -04002445
2446 if (nativeType == GL_INT)
2447 {
2448 context->getIntegerv(pname, params);
2449 }
2450 else
2451 {
2452 CastStateValues(context, nativeType, pname, numParams, params);
2453 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002454 }
2455}
2456
2457void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2458{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002459 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460
Geoff Langbfdea662014-07-23 14:16:32 -04002461 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002462 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 {
Geoff Langbfdea662014-07-23 14:16:32 -04002464 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002465
Geoff Langbfdea662014-07-23 14:16:32 -04002466 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002467 {
Geoff Langb1196682014-07-23 13:47:29 -04002468 context->recordError(gl::Error(GL_INVALID_VALUE));
2469 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002470 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002471
Geoff Langbfdea662014-07-23 14:16:32 -04002472 if (context->getClientVersion() < 3)
2473 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002474 switch (pname)
2475 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002476 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002477 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002478 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002479 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002480 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002481 context->recordError(gl::Error(GL_INVALID_ENUM));
2482 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002483 }
2484 }
Geoff Langbfdea662014-07-23 14:16:32 -04002485
2486 switch (pname)
2487 {
2488 case GL_DELETE_STATUS:
2489 *params = programObject->isFlaggedForDeletion();
2490 return;
2491 case GL_LINK_STATUS:
2492 *params = programObject->isLinked();
2493 return;
2494 case GL_VALIDATE_STATUS:
2495 *params = programObject->isValidated();
2496 return;
2497 case GL_INFO_LOG_LENGTH:
2498 *params = programObject->getInfoLogLength();
2499 return;
2500 case GL_ATTACHED_SHADERS:
2501 *params = programObject->getAttachedShadersCount();
2502 return;
2503 case GL_ACTIVE_ATTRIBUTES:
2504 *params = programObject->getActiveAttributeCount();
2505 return;
2506 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2507 *params = programObject->getActiveAttributeMaxLength();
2508 return;
2509 case GL_ACTIVE_UNIFORMS:
2510 *params = programObject->getActiveUniformCount();
2511 return;
2512 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2513 *params = programObject->getActiveUniformMaxLength();
2514 return;
2515 case GL_PROGRAM_BINARY_LENGTH_OES:
2516 *params = programObject->getProgramBinaryLength();
2517 return;
2518 case GL_ACTIVE_UNIFORM_BLOCKS:
2519 *params = programObject->getActiveUniformBlockCount();
2520 return;
2521 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2522 *params = programObject->getActiveUniformBlockMaxLength();
2523 break;
2524 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2525 *params = programObject->getTransformFeedbackBufferMode();
2526 break;
2527 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2528 *params = programObject->getTransformFeedbackVaryingCount();
2529 break;
2530 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2531 *params = programObject->getTransformFeedbackVaryingMaxLength();
2532 break;
Geoff Langb1196682014-07-23 13:47:29 -04002533
Geoff Langbfdea662014-07-23 14:16:32 -04002534 default:
Geoff Langb1196682014-07-23 13:47:29 -04002535 context->recordError(gl::Error(GL_INVALID_ENUM));
2536 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002537 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002538 }
2539}
2540
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002541void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002542{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002543 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 +00002544 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002545
Geoff Langbfdea662014-07-23 14:16:32 -04002546 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002547 if (context)
2548 {
Geoff Langb1196682014-07-23 13:47:29 -04002549 if (bufsize < 0)
2550 {
2551 context->recordError(gl::Error(GL_INVALID_VALUE));
2552 return;
2553 }
2554
Geoff Langbfdea662014-07-23 14:16:32 -04002555 gl::Program *programObject = context->getProgram(program);
2556
2557 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002558 {
Geoff Langb1196682014-07-23 13:47:29 -04002559 context->recordError(gl::Error(GL_INVALID_VALUE));
2560 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002561 }
2562
Geoff Langbfdea662014-07-23 14:16:32 -04002563 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002564 }
2565}
2566
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002567void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2568{
2569 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2570
Geoff Langbfdea662014-07-23 14:16:32 -04002571 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002572 if (context)
2573 {
2574 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002575 {
Geoff Langb1196682014-07-23 13:47:29 -04002576 context->recordError(gl::Error(GL_INVALID_ENUM));
2577 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002578 }
Geoff Langbfdea662014-07-23 14:16:32 -04002579
2580 switch (pname)
2581 {
2582 case GL_CURRENT_QUERY_EXT:
2583 params[0] = context->getState().getActiveQueryId(target);
2584 break;
2585
2586 default:
Geoff Langb1196682014-07-23 13:47:29 -04002587 context->recordError(gl::Error(GL_INVALID_ENUM));
2588 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002589 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002590 }
2591}
2592
2593void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2594{
2595 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2596
Geoff Langbfdea662014-07-23 14:16:32 -04002597 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002598 if (context)
2599 {
2600 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2601
2602 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002603 {
Geoff Langb1196682014-07-23 13:47:29 -04002604 context->recordError(gl::Error(GL_INVALID_OPERATION));
2605 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002606 }
Geoff Langbfdea662014-07-23 14:16:32 -04002607
2608 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2609 {
Geoff Langb1196682014-07-23 13:47:29 -04002610 context->recordError(gl::Error(GL_INVALID_OPERATION));
2611 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002612 }
2613
2614 switch(pname)
2615 {
2616 case GL_QUERY_RESULT_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002617 {
2618 gl::Error error = queryObject->getResult(params);
2619 if (error.isError())
2620 {
2621 context->recordError(error);
2622 return;
2623 }
2624 }
Geoff Langbfdea662014-07-23 14:16:32 -04002625 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002626
Geoff Langbfdea662014-07-23 14:16:32 -04002627 case GL_QUERY_RESULT_AVAILABLE_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002628 {
2629 gl::Error error = queryObject->isResultAvailable(params);
2630 if (error.isError())
2631 {
2632 context->recordError(error);
2633 return;
2634 }
2635 }
Geoff Langbfdea662014-07-23 14:16:32 -04002636 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002637
Geoff Langbfdea662014-07-23 14:16:32 -04002638 default:
Geoff Langb1196682014-07-23 13:47:29 -04002639 context->recordError(gl::Error(GL_INVALID_ENUM));
2640 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002641 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002642 }
2643}
2644
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002645void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2646{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002647 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 +00002648
Geoff Langbfdea662014-07-23 14:16:32 -04002649 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002650 if (context)
2651 {
2652 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002653 {
Geoff Langb1196682014-07-23 13:47:29 -04002654 context->recordError(gl::Error(GL_INVALID_ENUM));
2655 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002656 }
Geoff Langbfdea662014-07-23 14:16:32 -04002657
2658 if (context->getState().getRenderbufferId() == 0)
2659 {
Geoff Langb1196682014-07-23 13:47:29 -04002660 context->recordError(gl::Error(GL_INVALID_OPERATION));
2661 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002662 }
2663
2664 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2665
2666 switch (pname)
2667 {
2668 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2669 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2670 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2671 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2672 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2673 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2674 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2675 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2676 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002677
Geoff Langbfdea662014-07-23 14:16:32 -04002678 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2679 if (!context->getExtensions().framebufferMultisample)
2680 {
Geoff Langb1196682014-07-23 13:47:29 -04002681 context->recordError(gl::Error(GL_INVALID_ENUM));
2682 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002683 }
2684 *params = renderbuffer->getSamples();
2685 break;
Geoff Langb1196682014-07-23 13:47:29 -04002686
Geoff Langbfdea662014-07-23 14:16:32 -04002687 default:
Geoff Langb1196682014-07-23 13:47:29 -04002688 context->recordError(gl::Error(GL_INVALID_ENUM));
2689 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002690 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002691 }
2692}
2693
2694void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2695{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002696 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002697
Geoff Langbfdea662014-07-23 14:16:32 -04002698 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002699 if (context)
2700 {
2701 gl::Shader *shaderObject = context->getShader(shader);
2702
2703 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002704 {
Geoff Langb1196682014-07-23 13:47:29 -04002705 context->recordError(gl::Error(GL_INVALID_VALUE));
2706 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002707 }
Geoff Langbfdea662014-07-23 14:16:32 -04002708
2709 switch (pname)
2710 {
2711 case GL_SHADER_TYPE:
2712 *params = shaderObject->getType();
2713 return;
2714 case GL_DELETE_STATUS:
2715 *params = shaderObject->isFlaggedForDeletion();
2716 return;
2717 case GL_COMPILE_STATUS:
2718 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2719 return;
2720 case GL_INFO_LOG_LENGTH:
2721 *params = shaderObject->getInfoLogLength();
2722 return;
2723 case GL_SHADER_SOURCE_LENGTH:
2724 *params = shaderObject->getSourceLength();
2725 return;
2726 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2727 *params = shaderObject->getTranslatedSourceLength();
2728 return;
Geoff Langb1196682014-07-23 13:47:29 -04002729
Geoff Langbfdea662014-07-23 14:16:32 -04002730 default:
Geoff Langb1196682014-07-23 13:47:29 -04002731 context->recordError(gl::Error(GL_INVALID_ENUM));
2732 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002733 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002734 }
2735}
2736
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002737void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002738{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002739 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 +00002740 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002741
Geoff Langbfdea662014-07-23 14:16:32 -04002742 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002743 if (context)
2744 {
Geoff Langb1196682014-07-23 13:47:29 -04002745 if (bufsize < 0)
2746 {
2747 context->recordError(gl::Error(GL_INVALID_VALUE));
2748 return;
2749 }
2750
Geoff Langbfdea662014-07-23 14:16:32 -04002751 gl::Shader *shaderObject = context->getShader(shader);
2752
2753 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002754 {
Geoff Langb1196682014-07-23 13:47:29 -04002755 context->recordError(gl::Error(GL_INVALID_VALUE));
2756 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002757 }
2758
Geoff Langbfdea662014-07-23 14:16:32 -04002759 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002760 }
2761}
2762
2763void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2764{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002765 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 +00002766 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002767
Geoff Langb1196682014-07-23 13:47:29 -04002768 gl::Context *context = gl::getNonLostContext();
2769 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002770 {
Geoff Langb1196682014-07-23 13:47:29 -04002771 switch (shadertype)
2772 {
2773 case GL_VERTEX_SHADER:
2774 case GL_FRAGMENT_SHADER:
2775 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002776
Geoff Langb1196682014-07-23 13:47:29 -04002777 default:
2778 context->recordError(gl::Error(GL_INVALID_ENUM));
2779 return;
2780 }
2781
2782 switch (precisiontype)
2783 {
2784 case GL_LOW_FLOAT:
2785 case GL_MEDIUM_FLOAT:
2786 case GL_HIGH_FLOAT:
2787 // Assume IEEE 754 precision
2788 range[0] = 127;
2789 range[1] = 127;
2790 *precision = 23;
2791 break;
2792
2793 case GL_LOW_INT:
2794 case GL_MEDIUM_INT:
2795 case GL_HIGH_INT:
2796 // Some (most) hardware only supports single-precision floating-point numbers,
2797 // which can accurately represent integers up to +/-16777216
2798 range[0] = 24;
2799 range[1] = 24;
2800 *precision = 0;
2801 break;
2802
2803 default:
2804 context->recordError(gl::Error(GL_INVALID_ENUM));
2805 return;
2806 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002807 }
2808}
2809
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002810void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002811{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002812 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 +00002813 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002814
Geoff Langbfdea662014-07-23 14:16:32 -04002815 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002816 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002817 {
Geoff Langb1196682014-07-23 13:47:29 -04002818 if (bufsize < 0)
2819 {
2820 context->recordError(gl::Error(GL_INVALID_VALUE));
2821 return;
2822 }
2823
Geoff Langbfdea662014-07-23 14:16:32 -04002824 gl::Shader *shaderObject = context->getShader(shader);
2825
2826 if (!shaderObject)
2827 {
Geoff Langb1196682014-07-23 13:47:29 -04002828 context->recordError(gl::Error(GL_INVALID_OPERATION));
2829 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002830 }
2831
2832 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002833 }
2834}
2835
zmo@google.coma574f782011-10-03 21:45:23 +00002836void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2837{
2838 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2839 shader, bufsize, length, source);
2840
Geoff Langbfdea662014-07-23 14:16:32 -04002841 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002842 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002843 {
Geoff Langb1196682014-07-23 13:47:29 -04002844 if (bufsize < 0)
2845 {
2846 context->recordError(gl::Error(GL_INVALID_VALUE));
2847 return;
2848 }
2849
Geoff Langbfdea662014-07-23 14:16:32 -04002850 gl::Shader *shaderObject = context->getShader(shader);
2851
2852 if (!shaderObject)
2853 {
Geoff Langb1196682014-07-23 13:47:29 -04002854 context->recordError(gl::Error(GL_INVALID_OPERATION));
2855 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002856 }
2857
2858 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002859 }
2860}
2861
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002862const GLubyte* __stdcall glGetString(GLenum name)
2863{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002864 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002865
Geoff Langbfdea662014-07-23 14:16:32 -04002866 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002867
Geoff Langbfdea662014-07-23 14:16:32 -04002868 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002869 {
Geoff Langbfdea662014-07-23 14:16:32 -04002870 case GL_VENDOR:
2871 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002872
Geoff Langbfdea662014-07-23 14:16:32 -04002873 case GL_RENDERER:
2874 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002875
Geoff Langbfdea662014-07-23 14:16:32 -04002876 case GL_VERSION:
2877 if (context->getClientVersion() == 2)
2878 {
2879 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2880 }
2881 else
2882 {
2883 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2884 }
Geoff Langb1196682014-07-23 13:47:29 -04002885
Geoff Langbfdea662014-07-23 14:16:32 -04002886 case GL_SHADING_LANGUAGE_VERSION:
2887 if (context->getClientVersion() == 2)
2888 {
2889 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2890 }
2891 else
2892 {
2893 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2894 }
Geoff Langb1196682014-07-23 13:47:29 -04002895
Geoff Langbfdea662014-07-23 14:16:32 -04002896 case GL_EXTENSIONS:
2897 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002898
Geoff Langbfdea662014-07-23 14:16:32 -04002899 default:
Geoff Langb1196682014-07-23 13:47:29 -04002900 if (context)
2901 {
2902 context->recordError(gl::Error(GL_INVALID_ENUM));
2903 }
2904 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002905 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002906}
2907
2908void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2909{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002910 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 +00002911
Geoff Langbfdea662014-07-23 14:16:32 -04002912 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002913 if (context)
2914 {
2915 gl::Texture *texture = context->getTargetTexture(target);
2916
2917 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002918 {
Geoff Langb1196682014-07-23 13:47:29 -04002919 context->recordError(gl::Error(GL_INVALID_ENUM));
2920 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002921 }
Geoff Langbfdea662014-07-23 14:16:32 -04002922
2923 switch (pname)
2924 {
2925 case GL_TEXTURE_MAG_FILTER:
2926 *params = (GLfloat)texture->getSamplerState().magFilter;
2927 break;
2928 case GL_TEXTURE_MIN_FILTER:
2929 *params = (GLfloat)texture->getSamplerState().minFilter;
2930 break;
2931 case GL_TEXTURE_WRAP_S:
2932 *params = (GLfloat)texture->getSamplerState().wrapS;
2933 break;
2934 case GL_TEXTURE_WRAP_T:
2935 *params = (GLfloat)texture->getSamplerState().wrapT;
2936 break;
2937 case GL_TEXTURE_WRAP_R:
2938 if (context->getClientVersion() < 3)
2939 {
Geoff Langb1196682014-07-23 13:47:29 -04002940 context->recordError(gl::Error(GL_INVALID_ENUM));
2941 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002942 }
2943 *params = (GLfloat)texture->getSamplerState().wrapR;
2944 break;
2945 case GL_TEXTURE_IMMUTABLE_FORMAT:
2946 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2947 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2948 break;
2949 case GL_TEXTURE_IMMUTABLE_LEVELS:
2950 if (context->getClientVersion() < 3)
2951 {
Geoff Langb1196682014-07-23 13:47:29 -04002952 context->recordError(gl::Error(GL_INVALID_ENUM));
2953 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002954 }
2955 *params = (GLfloat)texture->immutableLevelCount();
2956 break;
2957 case GL_TEXTURE_USAGE_ANGLE:
2958 *params = (GLfloat)texture->getUsage();
2959 break;
2960 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2961 if (!context->getExtensions().textureFilterAnisotropic)
2962 {
Geoff Langb1196682014-07-23 13:47:29 -04002963 context->recordError(gl::Error(GL_INVALID_ENUM));
2964 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002965 }
2966 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2967 break;
2968 case GL_TEXTURE_SWIZZLE_R:
2969 if (context->getClientVersion() < 3)
2970 {
Geoff Langb1196682014-07-23 13:47:29 -04002971 context->recordError(gl::Error(GL_INVALID_ENUM));
2972 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002973 }
2974 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2975 break;
2976 case GL_TEXTURE_SWIZZLE_G:
2977 if (context->getClientVersion() < 3)
2978 {
Geoff Langb1196682014-07-23 13:47:29 -04002979 context->recordError(gl::Error(GL_INVALID_ENUM));
2980 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002981 }
2982 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2983 break;
2984 case GL_TEXTURE_SWIZZLE_B:
2985 if (context->getClientVersion() < 3)
2986 {
Geoff Langb1196682014-07-23 13:47:29 -04002987 context->recordError(gl::Error(GL_INVALID_ENUM));
2988 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002989 }
2990 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2991 break;
2992 case GL_TEXTURE_SWIZZLE_A:
2993 if (context->getClientVersion() < 3)
2994 {
Geoff Langb1196682014-07-23 13:47:29 -04002995 context->recordError(gl::Error(GL_INVALID_ENUM));
2996 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002997 }
2998 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2999 break;
3000 case GL_TEXTURE_BASE_LEVEL:
3001 if (context->getClientVersion() < 3)
3002 {
Geoff Langb1196682014-07-23 13:47:29 -04003003 context->recordError(gl::Error(GL_INVALID_ENUM));
3004 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003005 }
3006 *params = (GLfloat)texture->getSamplerState().baseLevel;
3007 break;
3008 case GL_TEXTURE_MAX_LEVEL:
3009 if (context->getClientVersion() < 3)
3010 {
Geoff Langb1196682014-07-23 13:47:29 -04003011 context->recordError(gl::Error(GL_INVALID_ENUM));
3012 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003013 }
3014 *params = (GLfloat)texture->getSamplerState().maxLevel;
3015 break;
3016 case GL_TEXTURE_MIN_LOD:
3017 if (context->getClientVersion() < 3)
3018 {
Geoff Langb1196682014-07-23 13:47:29 -04003019 context->recordError(gl::Error(GL_INVALID_ENUM));
3020 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003021 }
3022 *params = texture->getSamplerState().minLod;
3023 break;
3024 case GL_TEXTURE_MAX_LOD:
3025 if (context->getClientVersion() < 3)
3026 {
Geoff Langb1196682014-07-23 13:47:29 -04003027 context->recordError(gl::Error(GL_INVALID_ENUM));
3028 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003029 }
3030 *params = texture->getSamplerState().maxLod;
3031 break;
Geoff Langb1196682014-07-23 13:47:29 -04003032
Geoff Langbfdea662014-07-23 14:16:32 -04003033 default:
Geoff Langb1196682014-07-23 13:47:29 -04003034 context->recordError(gl::Error(GL_INVALID_ENUM));
3035 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003036 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003037 }
3038}
3039
3040void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
3041{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003042 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 +00003043
Geoff Langbfdea662014-07-23 14:16:32 -04003044 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003045 if (context)
3046 {
3047 gl::Texture *texture = context->getTargetTexture(target);
3048
3049 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003050 {
Geoff Langb1196682014-07-23 13:47:29 -04003051 context->recordError(gl::Error(GL_INVALID_ENUM));
3052 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003053 }
Geoff Langbfdea662014-07-23 14:16:32 -04003054
3055 switch (pname)
3056 {
3057 case GL_TEXTURE_MAG_FILTER:
3058 *params = texture->getSamplerState().magFilter;
3059 break;
3060 case GL_TEXTURE_MIN_FILTER:
3061 *params = texture->getSamplerState().minFilter;
3062 break;
3063 case GL_TEXTURE_WRAP_S:
3064 *params = texture->getSamplerState().wrapS;
3065 break;
3066 case GL_TEXTURE_WRAP_T:
3067 *params = texture->getSamplerState().wrapT;
3068 break;
3069 case GL_TEXTURE_WRAP_R:
3070 if (context->getClientVersion() < 3)
3071 {
Geoff Langb1196682014-07-23 13:47:29 -04003072 context->recordError(gl::Error(GL_INVALID_ENUM));
3073 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003074 }
3075 *params = texture->getSamplerState().wrapR;
3076 break;
3077 case GL_TEXTURE_IMMUTABLE_FORMAT:
3078 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3079 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3080 break;
3081 case GL_TEXTURE_IMMUTABLE_LEVELS:
3082 if (context->getClientVersion() < 3)
3083 {
Geoff Langb1196682014-07-23 13:47:29 -04003084 context->recordError(gl::Error(GL_INVALID_ENUM));
3085 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003086 }
3087 *params = texture->immutableLevelCount();
3088 break;
3089 case GL_TEXTURE_USAGE_ANGLE:
3090 *params = texture->getUsage();
3091 break;
3092 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3093 if (!context->getExtensions().textureFilterAnisotropic)
3094 {
Geoff Langb1196682014-07-23 13:47:29 -04003095 context->recordError(gl::Error(GL_INVALID_ENUM));
3096 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003097 }
3098 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3099 break;
3100 case GL_TEXTURE_SWIZZLE_R:
3101 if (context->getClientVersion() < 3)
3102 {
Geoff Langb1196682014-07-23 13:47:29 -04003103 context->recordError(gl::Error(GL_INVALID_ENUM));
3104 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003105 }
3106 *params = texture->getSamplerState().swizzleRed;
3107 break;
3108 case GL_TEXTURE_SWIZZLE_G:
3109 if (context->getClientVersion() < 3)
3110 {
Geoff Langb1196682014-07-23 13:47:29 -04003111 context->recordError(gl::Error(GL_INVALID_ENUM));
3112 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003113 }
3114 *params = texture->getSamplerState().swizzleGreen;
3115 break;
3116 case GL_TEXTURE_SWIZZLE_B:
3117 if (context->getClientVersion() < 3)
3118 {
Geoff Langb1196682014-07-23 13:47:29 -04003119 context->recordError(gl::Error(GL_INVALID_ENUM));
3120 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003121 }
3122 *params = texture->getSamplerState().swizzleBlue;
3123 break;
3124 case GL_TEXTURE_SWIZZLE_A:
3125 if (context->getClientVersion() < 3)
3126 {
Geoff Langb1196682014-07-23 13:47:29 -04003127 context->recordError(gl::Error(GL_INVALID_ENUM));
3128 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003129 }
3130 *params = texture->getSamplerState().swizzleAlpha;
3131 break;
3132 case GL_TEXTURE_BASE_LEVEL:
3133 if (context->getClientVersion() < 3)
3134 {
Geoff Langb1196682014-07-23 13:47:29 -04003135 context->recordError(gl::Error(GL_INVALID_ENUM));
3136 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003137 }
3138 *params = texture->getSamplerState().baseLevel;
3139 break;
3140 case GL_TEXTURE_MAX_LEVEL:
3141 if (context->getClientVersion() < 3)
3142 {
Geoff Langb1196682014-07-23 13:47:29 -04003143 context->recordError(gl::Error(GL_INVALID_ENUM));
3144 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003145 }
3146 *params = texture->getSamplerState().maxLevel;
3147 break;
3148 case GL_TEXTURE_MIN_LOD:
3149 if (context->getClientVersion() < 3)
3150 {
Geoff Langb1196682014-07-23 13:47:29 -04003151 context->recordError(gl::Error(GL_INVALID_ENUM));
3152 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003153 }
3154 *params = (GLint)texture->getSamplerState().minLod;
3155 break;
3156 case GL_TEXTURE_MAX_LOD:
3157 if (context->getClientVersion() < 3)
3158 {
Geoff Langb1196682014-07-23 13:47:29 -04003159 context->recordError(gl::Error(GL_INVALID_ENUM));
3160 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003161 }
3162 *params = (GLint)texture->getSamplerState().maxLod;
3163 break;
Geoff Langb1196682014-07-23 13:47:29 -04003164
Geoff Langbfdea662014-07-23 14:16:32 -04003165 default:
Geoff Langb1196682014-07-23 13:47:29 -04003166 context->recordError(gl::Error(GL_INVALID_ENUM));
3167 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003168 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003169 }
3170}
3171
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003172void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3173{
3174 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3175 program, location, bufSize, params);
3176
Geoff Langbfdea662014-07-23 14:16:32 -04003177 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003178 if (context)
3179 {
Jamie Madill0063c512014-08-25 15:47:53 -04003180 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003181 {
Jamie Madill0063c512014-08-25 15:47:53 -04003182 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003183 }
3184
Jamie Madilla502c742014-08-28 17:19:13 -04003185 gl::Program *programObject = context->getProgram(program);
3186 ASSERT(programObject);
3187 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003188 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003189
Jamie Madill99a1e982014-08-25 15:47:54 -04003190 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003191 }
3192}
3193
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003194void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3195{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003196 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003197
Geoff Langbfdea662014-07-23 14:16:32 -04003198 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003199 if (context)
3200 {
Jamie Madill0063c512014-08-25 15:47:53 -04003201 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003202 {
Jamie Madill0063c512014-08-25 15:47:53 -04003203 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003204 }
Geoff Langbfdea662014-07-23 14:16:32 -04003205
Jamie Madilla502c742014-08-28 17:19:13 -04003206 gl::Program *programObject = context->getProgram(program);
3207 ASSERT(programObject);
3208 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003209 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003210
Jamie Madill99a1e982014-08-25 15:47:54 -04003211 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003212 }
3213}
3214
3215void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3216{
Geoff Langbfdea662014-07-23 14:16:32 -04003217 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003218 program, location, bufSize, params);
3219
Geoff Langbfdea662014-07-23 14:16:32 -04003220 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003221 if (context)
3222 {
Jamie Madill0063c512014-08-25 15:47:53 -04003223 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003224 {
Jamie Madill0063c512014-08-25 15:47:53 -04003225 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003226 }
3227
Jamie Madilla502c742014-08-28 17:19:13 -04003228 gl::Program *programObject = context->getProgram(program);
3229 ASSERT(programObject);
3230 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003231 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003232
Jamie Madill99a1e982014-08-25 15:47:54 -04003233 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003234 }
3235}
3236
3237void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3238{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003239 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003240
Geoff Langbfdea662014-07-23 14:16:32 -04003241 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003242 if (context)
3243 {
Jamie Madill0063c512014-08-25 15:47:53 -04003244 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003245 {
Jamie Madill0063c512014-08-25 15:47:53 -04003246 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003247 }
Geoff Langbfdea662014-07-23 14:16:32 -04003248
Jamie Madilla502c742014-08-28 17:19:13 -04003249 gl::Program *programObject = context->getProgram(program);
3250 ASSERT(programObject);
3251 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003252 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003253
Jamie Madill99a1e982014-08-25 15:47:54 -04003254 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003255 }
3256}
3257
Geoff Langb1196682014-07-23 13:47:29 -04003258GLint __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003259{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003260 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003261
Geoff Langbfdea662014-07-23 14:16:32 -04003262 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003263 if (context)
3264 {
Geoff Langb1196682014-07-23 13:47:29 -04003265 if (strstr(name, "gl_") == name)
3266 {
3267 return -1;
3268 }
3269
Geoff Langbfdea662014-07-23 14:16:32 -04003270 gl::Program *programObject = context->getProgram(program);
3271
3272 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003273 {
Geoff Langbfdea662014-07-23 14:16:32 -04003274 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003275 {
Geoff Langb1196682014-07-23 13:47:29 -04003276 context->recordError(gl::Error(GL_INVALID_OPERATION));
3277 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003278 }
Geoff Langbfdea662014-07-23 14:16:32 -04003279 else
3280 {
Geoff Langb1196682014-07-23 13:47:29 -04003281 context->recordError(gl::Error(GL_INVALID_VALUE));
3282 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003283 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003284 }
Geoff Langbfdea662014-07-23 14:16:32 -04003285
3286 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3287 if (!programObject->isLinked() || !programBinary)
3288 {
Geoff Langb1196682014-07-23 13:47:29 -04003289 context->recordError(gl::Error(GL_INVALID_OPERATION));
3290 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003291 }
3292
3293 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003294 }
3295
3296 return -1;
3297}
3298
3299void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3300{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003301 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003302
Geoff Langbfdea662014-07-23 14:16:32 -04003303 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003304 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003305 {
Geoff Langbfdea662014-07-23 14:16:32 -04003306 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003307 {
Geoff Langb1196682014-07-23 13:47:29 -04003308 context->recordError(gl::Error(GL_INVALID_VALUE));
3309 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003310 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003311
Geoff Langbfdea662014-07-23 14:16:32 -04003312 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003313 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003314 {
3315 return;
3316 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003317
Geoff Langbfdea662014-07-23 14:16:32 -04003318 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3319 {
3320 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3321 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003322 {
Geoff Langbfdea662014-07-23 14:16:32 -04003323 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003324 }
3325 }
Geoff Langbfdea662014-07-23 14:16:32 -04003326 else
3327 {
3328 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3329 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003330 }
3331}
3332
3333void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3334{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003335 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* 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);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003347
Geoff Langb1196682014-07-23 13:47:29 -04003348 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003349 {
3350 return;
3351 }
Jamie Madillaff71502013-07-02 11:57:05 -04003352
Geoff Langbfdea662014-07-23 14:16:32 -04003353 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3354 {
3355 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3356 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003357 {
Geoff Langbfdea662014-07-23 14:16:32 -04003358 float currentValue = currentValueData.FloatValues[i];
3359 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003360 }
3361 }
Geoff Langbfdea662014-07-23 14:16:32 -04003362 else
3363 {
3364 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3365 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003366 }
3367}
3368
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003369void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003370{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003371 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003372
Geoff Langbfdea662014-07-23 14:16:32 -04003373 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003374 if (context)
3375 {
3376 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003377 {
Geoff Langb1196682014-07-23 13:47:29 -04003378 context->recordError(gl::Error(GL_INVALID_VALUE));
3379 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003380 }
Geoff Langbfdea662014-07-23 14:16:32 -04003381
3382 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3383 {
Geoff Langb1196682014-07-23 13:47:29 -04003384 context->recordError(gl::Error(GL_INVALID_ENUM));
3385 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003386 }
3387
3388 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003389 }
3390}
3391
3392void __stdcall glHint(GLenum target, GLenum mode)
3393{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003394 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003395
Geoff Langbfdea662014-07-23 14:16:32 -04003396 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003397 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003398 {
Geoff Langb1196682014-07-23 13:47:29 -04003399 switch (mode)
3400 {
3401 case GL_FASTEST:
3402 case GL_NICEST:
3403 case GL_DONT_CARE:
3404 break;
3405
3406 default:
3407 context->recordError(gl::Error(GL_INVALID_ENUM));
3408 return;
3409 }
3410
3411 switch (target)
3412 {
3413 case GL_GENERATE_MIPMAP_HINT:
3414 context->getState().setGenerateMipmapHint(mode);
3415 break;
3416
3417 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3418 context->getState().setFragmentShaderDerivativeHint(mode);
3419 break;
3420
3421 default:
3422 context->recordError(gl::Error(GL_INVALID_ENUM));
3423 return;
3424 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003425 }
3426}
3427
3428GLboolean __stdcall glIsBuffer(GLuint buffer)
3429{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003430 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003431
Geoff Langbfdea662014-07-23 14:16:32 -04003432 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003433 if (context && buffer)
3434 {
3435 gl::Buffer *bufferObject = context->getBuffer(buffer);
3436
3437 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003438 {
Geoff Langbfdea662014-07-23 14:16:32 -04003439 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003440 }
3441 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003442
3443 return GL_FALSE;
3444}
3445
3446GLboolean __stdcall glIsEnabled(GLenum cap)
3447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003448 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449
Geoff Langbfdea662014-07-23 14:16:32 -04003450 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003451 if (context)
3452 {
3453 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003454 {
Geoff Langb1196682014-07-23 13:47:29 -04003455 context->recordError(gl::Error(GL_INVALID_ENUM));
3456 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003457 }
Geoff Langbfdea662014-07-23 14:16:32 -04003458
3459 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003460 }
3461
3462 return false;
3463}
3464
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003465GLboolean __stdcall glIsFenceNV(GLuint fence)
3466{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003467 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003468
Geoff Langbfdea662014-07-23 14:16:32 -04003469 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003470 if (context)
3471 {
3472 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3473
3474 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003475 {
Geoff Langbfdea662014-07-23 14:16:32 -04003476 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003477 }
Geoff Langbfdea662014-07-23 14:16:32 -04003478
3479 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003480 }
3481
3482 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003483}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003485GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3486{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003487 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003488
Geoff Langbfdea662014-07-23 14:16:32 -04003489 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003490 if (context && framebuffer)
3491 {
3492 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3493
3494 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003495 {
Geoff Langbfdea662014-07-23 14:16:32 -04003496 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003497 }
3498 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003499
3500 return GL_FALSE;
3501}
3502
3503GLboolean __stdcall glIsProgram(GLuint program)
3504{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003505 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003506
Geoff Langbfdea662014-07-23 14:16:32 -04003507 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003508 if (context && program)
3509 {
3510 gl::Program *programObject = context->getProgram(program);
3511
3512 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003513 {
Geoff Langbfdea662014-07-23 14:16:32 -04003514 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003515 }
3516 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003517
3518 return GL_FALSE;
3519}
3520
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003521GLboolean __stdcall glIsQueryEXT(GLuint id)
3522{
3523 EVENT("(GLuint id = %d)", id);
3524
Geoff Langbfdea662014-07-23 14:16:32 -04003525 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003526 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003527 {
Geoff Langbfdea662014-07-23 14:16:32 -04003528 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003529 }
3530
3531 return GL_FALSE;
3532}
3533
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003534GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3535{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003536 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003537
Geoff Langbfdea662014-07-23 14:16:32 -04003538 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003539 if (context && renderbuffer)
3540 {
3541 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3542
3543 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003544 {
Geoff Langbfdea662014-07-23 14:16:32 -04003545 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003546 }
3547 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003548
3549 return GL_FALSE;
3550}
3551
3552GLboolean __stdcall glIsShader(GLuint shader)
3553{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003554 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003555
Geoff Langbfdea662014-07-23 14:16:32 -04003556 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003557 if (context && shader)
3558 {
3559 gl::Shader *shaderObject = context->getShader(shader);
3560
3561 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003562 {
Geoff Langbfdea662014-07-23 14:16:32 -04003563 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003564 }
3565 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003566
3567 return GL_FALSE;
3568}
3569
3570GLboolean __stdcall glIsTexture(GLuint texture)
3571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003572 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003573
Geoff Langbfdea662014-07-23 14:16:32 -04003574 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003575 if (context && texture)
3576 {
3577 gl::Texture *textureObject = context->getTexture(texture);
3578
3579 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003580 {
Geoff Langbfdea662014-07-23 14:16:32 -04003581 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582 }
3583 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003584
3585 return GL_FALSE;
3586}
3587
3588void __stdcall glLineWidth(GLfloat width)
3589{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003590 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003591
Geoff Langbfdea662014-07-23 14:16:32 -04003592 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003593 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594 {
Geoff Langb1196682014-07-23 13:47:29 -04003595 if (width <= 0.0f)
3596 {
3597 context->recordError(gl::Error(GL_INVALID_VALUE));
3598 return;
3599 }
3600
Geoff Langbfdea662014-07-23 14:16:32 -04003601 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003602 }
3603}
3604
3605void __stdcall glLinkProgram(GLuint program)
3606{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003607 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003608
Geoff Langbfdea662014-07-23 14:16:32 -04003609 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003610 if (context)
3611 {
3612 gl::Program *programObject = context->getProgram(program);
3613
3614 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003615 {
Geoff Langbfdea662014-07-23 14:16:32 -04003616 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617 {
Geoff Langb1196682014-07-23 13:47:29 -04003618 context->recordError(gl::Error(GL_INVALID_OPERATION));
3619 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003620 }
Geoff Langbfdea662014-07-23 14:16:32 -04003621 else
3622 {
Geoff Langb1196682014-07-23 13:47:29 -04003623 context->recordError(gl::Error(GL_INVALID_VALUE));
3624 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003625 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003626 }
Geoff Langbfdea662014-07-23 14:16:32 -04003627
3628 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003629 }
3630}
3631
3632void __stdcall glPixelStorei(GLenum pname, GLint param)
3633{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003634 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003635
Geoff Langbfdea662014-07-23 14:16:32 -04003636 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003637 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003638 {
Geoff Langbfdea662014-07-23 14:16:32 -04003639 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640 {
Geoff Langbfdea662014-07-23 14:16:32 -04003641 case GL_UNPACK_ALIGNMENT:
3642 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003643 {
Geoff Langb1196682014-07-23 13:47:29 -04003644 context->recordError(gl::Error(GL_INVALID_VALUE));
3645 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003646 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003647
Geoff Langbfdea662014-07-23 14:16:32 -04003648 context->getState().setUnpackAlignment(param);
3649 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003650
Geoff Langbfdea662014-07-23 14:16:32 -04003651 case GL_PACK_ALIGNMENT:
3652 if (param != 1 && param != 2 && param != 4 && param != 8)
3653 {
Geoff Langb1196682014-07-23 13:47:29 -04003654 context->recordError(gl::Error(GL_INVALID_VALUE));
3655 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003656 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003657
Geoff Langbfdea662014-07-23 14:16:32 -04003658 context->getState().setPackAlignment(param);
3659 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003660
Geoff Langbfdea662014-07-23 14:16:32 -04003661 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3662 context->getState().setPackReverseRowOrder(param != 0);
3663 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003664
Geoff Langbfdea662014-07-23 14:16:32 -04003665 case GL_UNPACK_IMAGE_HEIGHT:
3666 case GL_UNPACK_SKIP_IMAGES:
3667 case GL_UNPACK_ROW_LENGTH:
3668 case GL_UNPACK_SKIP_ROWS:
3669 case GL_UNPACK_SKIP_PIXELS:
3670 case GL_PACK_ROW_LENGTH:
3671 case GL_PACK_SKIP_ROWS:
3672 case GL_PACK_SKIP_PIXELS:
3673 if (context->getClientVersion() < 3)
3674 {
Geoff Langb1196682014-07-23 13:47:29 -04003675 context->recordError(gl::Error(GL_INVALID_ENUM));
3676 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003677 }
Geoff Langbfdea662014-07-23 14:16:32 -04003678 UNIMPLEMENTED();
3679 break;
3680
3681 default:
Geoff Langb1196682014-07-23 13:47:29 -04003682 context->recordError(gl::Error(GL_INVALID_ENUM));
3683 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003684 }
3685 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003686}
3687
3688void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3689{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003690 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003691
Geoff Langbfdea662014-07-23 14:16:32 -04003692 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003693 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003694 {
Geoff Langbfdea662014-07-23 14:16:32 -04003695 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003696 }
3697}
3698
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003699void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3700 GLenum format, GLenum type, GLsizei bufSize,
3701 GLvoid *data)
3702{
3703 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3704 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3705 x, y, width, height, format, type, bufSize, data);
3706
Geoff Langbfdea662014-07-23 14:16:32 -04003707 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003708 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003709 {
Geoff Langb1196682014-07-23 13:47:29 -04003710 if (width < 0 || height < 0 || bufSize < 0)
3711 {
3712 context->recordError(gl::Error(GL_INVALID_VALUE));
3713 return;
3714 }
3715
Geoff Langbfdea662014-07-23 14:16:32 -04003716 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3717 format, type, &bufSize, data))
3718 {
3719 return;
3720 }
3721
Geoff Lang63d2fc72014-07-25 14:51:41 -04003722 gl::Error error = context->readPixels(x, y, width, height, format, type, &bufSize, data);
3723 if (error.isError())
3724 {
3725 context->recordError(error);
3726 return;
3727 }
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003728 }
3729}
3730
3731void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3732 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003734 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003735 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003736 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003737
Geoff Langbfdea662014-07-23 14:16:32 -04003738 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003739 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003740 {
Geoff Langb1196682014-07-23 13:47:29 -04003741 if (width < 0 || height < 0)
3742 {
3743 context->recordError(gl::Error(GL_INVALID_VALUE));
3744 return;
3745 }
3746
Geoff Langbfdea662014-07-23 14:16:32 -04003747 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3748 format, type, NULL, pixels))
3749 {
3750 return;
3751 }
3752
Geoff Lang63d2fc72014-07-25 14:51:41 -04003753 gl::Error error = context->readPixels(x, y, width, height, format, type, NULL, pixels);
3754 if (error.isError())
3755 {
3756 context->recordError(error);
3757 return;
3758 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003759 }
3760}
3761
3762void __stdcall glReleaseShaderCompiler(void)
3763{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003764 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003765
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003766 gl::Context *context = gl::getNonLostContext();
3767
3768 if (context)
3769 {
3770 context->releaseShaderCompiler();
3771 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003772}
3773
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003774void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003775{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003776 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 +00003777 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778
Geoff Langbfdea662014-07-23 14:16:32 -04003779 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003780 if (context)
3781 {
3782 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3783 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003784 {
Geoff Langbfdea662014-07-23 14:16:32 -04003785 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003786 }
Geoff Langbfdea662014-07-23 14:16:32 -04003787
3788 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789 }
3790}
3791
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003792void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3793{
3794 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3795}
3796
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003797void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3798{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003799 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003800
Geoff Langbfdea662014-07-23 14:16:32 -04003801 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003802
Geoff Langbfdea662014-07-23 14:16:32 -04003803 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003804 {
Geoff Langbfdea662014-07-23 14:16:32 -04003805 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003806 }
3807}
3808
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003809void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3810{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003811 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003812
Geoff Langbfdea662014-07-23 14:16:32 -04003813 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003814 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003815 {
Geoff Langb1196682014-07-23 13:47:29 -04003816 if (condition != GL_ALL_COMPLETED_NV)
3817 {
3818 context->recordError(gl::Error(GL_INVALID_ENUM));
3819 return;
3820 }
3821
Geoff Langbfdea662014-07-23 14:16:32 -04003822 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3823
3824 if (fenceObject == NULL)
3825 {
Geoff Langb1196682014-07-23 13:47:29 -04003826 context->recordError(gl::Error(GL_INVALID_OPERATION));
3827 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003828 }
3829
3830 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003831 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003832}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003833
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003834void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3835{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003836 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 +00003837
Geoff Langbfdea662014-07-23 14:16:32 -04003838 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003839 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003840 {
Geoff Langb1196682014-07-23 13:47:29 -04003841 if (width < 0 || height < 0)
3842 {
3843 context->recordError(gl::Error(GL_INVALID_VALUE));
3844 return;
3845 }
3846
Geoff Langbfdea662014-07-23 14:16:32 -04003847 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003848 }
3849}
3850
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003851void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003852{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003853 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003854 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003855 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003856
Geoff Lang900013c2014-07-07 11:32:19 -04003857 gl::Context* context = gl::getNonLostContext();
3858 if (context)
3859 {
3860 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3861 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3862 {
Geoff Langb1196682014-07-23 13:47:29 -04003863 context->recordError(gl::Error(GL_INVALID_ENUM));
3864 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003865 }
3866
3867 // No binary shader formats are supported.
3868 UNIMPLEMENTED();
3869 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003870}
3871
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003872void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003873{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003874 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 +00003875 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003876
Geoff Langbfdea662014-07-23 14:16:32 -04003877 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003878 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003879 {
Geoff Langb1196682014-07-23 13:47:29 -04003880 if (count < 0)
3881 {
3882 context->recordError(gl::Error(GL_INVALID_VALUE));
3883 return;
3884 }
3885
Geoff Langbfdea662014-07-23 14:16:32 -04003886 gl::Shader *shaderObject = context->getShader(shader);
3887
3888 if (!shaderObject)
3889 {
3890 if (context->getProgram(shader))
3891 {
Geoff Langb1196682014-07-23 13:47:29 -04003892 context->recordError(gl::Error(GL_INVALID_OPERATION));
3893 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003894 }
3895 else
3896 {
Geoff Langb1196682014-07-23 13:47:29 -04003897 context->recordError(gl::Error(GL_INVALID_VALUE));
3898 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003899 }
3900 }
3901
3902 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003903 }
3904}
3905
3906void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3907{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003908 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003909}
3910
3911void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3912{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003913 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 +00003914
Geoff Langbfdea662014-07-23 14:16:32 -04003915 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003916 if (context)
3917 {
Geoff Langb1196682014-07-23 13:47:29 -04003918 switch (face)
3919 {
3920 case GL_FRONT:
3921 case GL_BACK:
3922 case GL_FRONT_AND_BACK:
3923 break;
3924
3925 default:
3926 context->recordError(gl::Error(GL_INVALID_ENUM));
3927 return;
3928 }
3929
3930 switch (func)
3931 {
3932 case GL_NEVER:
3933 case GL_ALWAYS:
3934 case GL_LESS:
3935 case GL_LEQUAL:
3936 case GL_EQUAL:
3937 case GL_GEQUAL:
3938 case GL_GREATER:
3939 case GL_NOTEQUAL:
3940 break;
3941
3942 default:
3943 context->recordError(gl::Error(GL_INVALID_ENUM));
3944 return;
3945 }
3946
Geoff Langbfdea662014-07-23 14:16:32 -04003947 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3948 {
3949 context->getState().setStencilParams(func, ref, mask);
3950 }
3951
3952 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3953 {
3954 context->getState().setStencilBackParams(func, ref, mask);
3955 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003956 }
3957}
3958
3959void __stdcall glStencilMask(GLuint mask)
3960{
3961 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3962}
3963
3964void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3965{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003966 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003967
Geoff Langbfdea662014-07-23 14:16:32 -04003968 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003969 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003970 {
Geoff Langb1196682014-07-23 13:47:29 -04003971 switch (face)
3972 {
3973 case GL_FRONT:
3974 case GL_BACK:
3975 case GL_FRONT_AND_BACK:
3976 break;
3977
3978 default:
3979 context->recordError(gl::Error(GL_INVALID_ENUM));
3980 return;
3981 }
3982
Geoff Langbfdea662014-07-23 14:16:32 -04003983 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3984 {
3985 context->getState().setStencilWritemask(mask);
3986 }
3987
3988 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3989 {
3990 context->getState().setStencilBackWritemask(mask);
3991 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003992 }
3993}
3994
3995void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3996{
3997 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3998}
3999
4000void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4001{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004002 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 +00004003 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004004
Geoff Langbfdea662014-07-23 14:16:32 -04004005 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004006 if (context)
4007 {
Geoff Langb1196682014-07-23 13:47:29 -04004008 switch (face)
4009 {
4010 case GL_FRONT:
4011 case GL_BACK:
4012 case GL_FRONT_AND_BACK:
4013 break;
4014
4015 default:
4016 context->recordError(gl::Error(GL_INVALID_ENUM));
4017 return;
4018 }
4019
4020 switch (fail)
4021 {
4022 case GL_ZERO:
4023 case GL_KEEP:
4024 case GL_REPLACE:
4025 case GL_INCR:
4026 case GL_DECR:
4027 case GL_INVERT:
4028 case GL_INCR_WRAP:
4029 case GL_DECR_WRAP:
4030 break;
4031
4032 default:
4033 context->recordError(gl::Error(GL_INVALID_ENUM));
4034 return;
4035 }
4036
4037 switch (zfail)
4038 {
4039 case GL_ZERO:
4040 case GL_KEEP:
4041 case GL_REPLACE:
4042 case GL_INCR:
4043 case GL_DECR:
4044 case GL_INVERT:
4045 case GL_INCR_WRAP:
4046 case GL_DECR_WRAP:
4047 break;
4048
4049 default:
4050 context->recordError(gl::Error(GL_INVALID_ENUM));
4051 return;
4052 }
4053
4054 switch (zpass)
4055 {
4056 case GL_ZERO:
4057 case GL_KEEP:
4058 case GL_REPLACE:
4059 case GL_INCR:
4060 case GL_DECR:
4061 case GL_INVERT:
4062 case GL_INCR_WRAP:
4063 case GL_DECR_WRAP:
4064 break;
4065
4066 default:
4067 context->recordError(gl::Error(GL_INVALID_ENUM));
4068 return;
4069 }
4070
Geoff Langbfdea662014-07-23 14:16:32 -04004071 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4072 {
4073 context->getState().setStencilOperations(fail, zfail, zpass);
4074 }
4075
4076 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4077 {
4078 context->getState().setStencilBackOperations(fail, zfail, zpass);
4079 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004080 }
4081}
4082
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004083GLboolean __stdcall glTestFenceNV(GLuint fence)
4084{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004085 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004086
Geoff Langbfdea662014-07-23 14:16:32 -04004087 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004088 if (context)
4089 {
4090 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4091
4092 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004093 {
Geoff Langb1196682014-07-23 13:47:29 -04004094 context->recordError(gl::Error(GL_INVALID_OPERATION));
4095 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004096 }
Geoff Langbfdea662014-07-23 14:16:32 -04004097
4098 if (fenceObject->isFence() != GL_TRUE)
4099 {
Geoff Langb1196682014-07-23 13:47:29 -04004100 context->recordError(gl::Error(GL_INVALID_OPERATION));
4101 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004102 }
4103
4104 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004105 }
Geoff Langbfdea662014-07-23 14:16:32 -04004106
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004107 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004108}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004109
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004110void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4111 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004112{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004113 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004114 "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 +00004115 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004116
Geoff Langbfdea662014-07-23 14:16:32 -04004117 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004118 if (context)
4119 {
4120 if (context->getClientVersion() < 3 &&
4121 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4122 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004123 {
Geoff Langbfdea662014-07-23 14:16:32 -04004124 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004125 }
Geoff Langbfdea662014-07-23 14:16:32 -04004126
4127 if (context->getClientVersion() >= 3 &&
4128 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4129 0, 0, 0, width, height, 1, border, format, type, pixels))
4130 {
4131 return;
4132 }
4133
4134 switch (target)
4135 {
4136 case GL_TEXTURE_2D:
4137 {
4138 gl::Texture2D *texture = context->getTexture2D();
4139 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4140 }
4141 break;
4142 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4143 {
4144 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4145 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4146 }
4147 break;
4148 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4149 {
4150 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4151 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4152 }
4153 break;
4154 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4155 {
4156 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4157 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4158 }
4159 break;
4160 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4161 {
4162 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4163 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4164 }
4165 break;
4166 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4167 {
4168 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4169 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4170 }
4171 break;
4172 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4173 {
4174 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4175 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4176 }
4177 break;
4178 default: UNREACHABLE();
4179 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004180 }
4181}
4182
4183void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4184{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004185 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4186
Geoff Langbfdea662014-07-23 14:16:32 -04004187 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004188 if (context)
4189 {
4190 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004191 {
Geoff Langbfdea662014-07-23 14:16:32 -04004192 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004193 }
Geoff Langbfdea662014-07-23 14:16:32 -04004194
4195 gl::Texture *texture = context->getTargetTexture(target);
4196
4197 if (!texture)
4198 {
Geoff Langb1196682014-07-23 13:47:29 -04004199 context->recordError(gl::Error(GL_INVALID_ENUM));
4200 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004201 }
4202
4203 switch (pname)
4204 {
4205 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4206 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4207 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4208 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4209 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4210 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4211 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4212 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4213 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4214 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4215 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4216 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4217 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4218 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4219 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4220 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4221 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4222 default: UNREACHABLE(); break;
4223 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004224 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004225}
4226
4227void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4228{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004229 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004230}
4231
4232void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004234 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004235
Geoff Langbfdea662014-07-23 14:16:32 -04004236 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004237 if (context)
4238 {
4239 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004240 {
Geoff Langbfdea662014-07-23 14:16:32 -04004241 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004242 }
Geoff Langbfdea662014-07-23 14:16:32 -04004243
4244 gl::Texture *texture = context->getTargetTexture(target);
4245
4246 if (!texture)
4247 {
Geoff Langb1196682014-07-23 13:47:29 -04004248 context->recordError(gl::Error(GL_INVALID_ENUM));
4249 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004250 }
4251
4252 switch (pname)
4253 {
4254 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4255 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4256 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4257 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4258 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4259 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4260 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4261 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4262 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4263 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4264 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4265 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4266 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4267 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4268 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4269 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4270 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4271 default: UNREACHABLE(); break;
4272 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004273 }
4274}
4275
4276void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4277{
4278 glTexParameteri(target, pname, *params);
4279}
4280
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004281void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4282{
4283 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4284 target, levels, internalformat, width, height);
4285
Geoff Langbfdea662014-07-23 14:16:32 -04004286 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004287 if (context)
4288 {
4289 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004290 {
Geoff Langb1196682014-07-23 13:47:29 -04004291 context->recordError(gl::Error(GL_INVALID_OPERATION));
4292 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004293 }
Geoff Langbfdea662014-07-23 14:16:32 -04004294
4295 if (context->getClientVersion() < 3 &&
4296 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4297 {
4298 return;
4299 }
4300
4301 if (context->getClientVersion() >= 3 &&
4302 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4303 {
4304 return;
4305 }
4306
4307 switch (target)
4308 {
4309 case GL_TEXTURE_2D:
4310 {
4311 gl::Texture2D *texture2d = context->getTexture2D();
4312 texture2d->storage(levels, internalformat, width, height);
4313 }
4314 break;
4315
4316 case GL_TEXTURE_CUBE_MAP:
4317 {
4318 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4319 textureCube->storage(levels, internalformat, width);
4320 }
4321 break;
4322
4323 default:
Geoff Langb1196682014-07-23 13:47:29 -04004324 context->recordError(gl::Error(GL_INVALID_ENUM));
4325 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004326 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004327 }
4328}
4329
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004330void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4331 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004332{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004333 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004334 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004335 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004336 target, level, xoffset, yoffset, width, height, format, type, pixels);
4337
Geoff Langbfdea662014-07-23 14:16:32 -04004338 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004339 if (context)
4340 {
4341 if (context->getClientVersion() < 3 &&
4342 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4343 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004344 {
Geoff Langbfdea662014-07-23 14:16:32 -04004345 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004346 }
Geoff Langbfdea662014-07-23 14:16:32 -04004347
4348 if (context->getClientVersion() >= 3 &&
4349 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4350 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4351 {
4352 return;
4353 }
4354
4355 // Zero sized uploads are valid but no-ops
4356 if (width == 0 || height == 0)
4357 {
4358 return;
4359 }
4360
4361 switch (target)
4362 {
4363 case GL_TEXTURE_2D:
4364 {
4365 gl::Texture2D *texture = context->getTexture2D();
4366 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4367 }
4368 break;
4369
4370 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4371 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4372 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4373 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4374 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4375 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4376 {
4377 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4378 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4379 }
4380 break;
4381
4382 default:
4383 UNREACHABLE();
4384 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004385 }
4386}
4387
4388void __stdcall glUniform1f(GLint location, GLfloat x)
4389{
4390 glUniform1fv(location, 1, &x);
4391}
4392
4393void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4394{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004395 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004396
Geoff Langbfdea662014-07-23 14:16:32 -04004397 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004398 if (context)
4399 {
4400 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004401 {
Geoff Langbfdea662014-07-23 14:16:32 -04004402 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004403 }
Geoff Langbfdea662014-07-23 14:16:32 -04004404
4405 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4406 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004407 }
4408}
4409
4410void __stdcall glUniform1i(GLint location, GLint x)
4411{
4412 glUniform1iv(location, 1, &x);
4413}
4414
4415void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4416{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004417 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004418
Geoff Langbfdea662014-07-23 14:16:32 -04004419 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004420 if (context)
4421 {
4422 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004423 {
Geoff Langbfdea662014-07-23 14:16:32 -04004424 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004425 }
Geoff Langbfdea662014-07-23 14:16:32 -04004426
4427 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4428 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004429 }
4430}
4431
4432void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4433{
4434 GLfloat xy[2] = {x, y};
4435
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004436 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004437}
4438
4439void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4440{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004441 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442
Geoff Langbfdea662014-07-23 14:16:32 -04004443 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004444 if (context)
4445 {
4446 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004447 {
Geoff Langbfdea662014-07-23 14:16:32 -04004448 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004449 }
Geoff Langbfdea662014-07-23 14:16:32 -04004450
4451 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4452 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004453 }
4454}
4455
4456void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4457{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004458 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004459
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004460 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004461}
4462
4463void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4464{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004465 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004466
Geoff Langbfdea662014-07-23 14:16:32 -04004467 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004468 if (context)
4469 {
4470 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004471 {
Geoff Langbfdea662014-07-23 14:16:32 -04004472 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004473 }
Geoff Langbfdea662014-07-23 14:16:32 -04004474
4475 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4476 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004477 }
4478}
4479
4480void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4481{
4482 GLfloat xyz[3] = {x, y, z};
4483
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004484 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004485}
4486
4487void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4488{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004489 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490
Geoff Langbfdea662014-07-23 14:16:32 -04004491 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004492 if (context)
4493 {
4494 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004495 {
Geoff Langbfdea662014-07-23 14:16:32 -04004496 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004497 }
Geoff Langbfdea662014-07-23 14:16:32 -04004498
4499 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4500 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004501 }
4502}
4503
4504void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4505{
4506 GLint xyz[3] = {x, y, z};
4507
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004508 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004509}
4510
4511void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4512{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004513 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004514
Geoff Langbfdea662014-07-23 14:16:32 -04004515 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004516 if (context)
4517 {
4518 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004519 {
Geoff Langbfdea662014-07-23 14:16:32 -04004520 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004521 }
Geoff Langbfdea662014-07-23 14:16:32 -04004522
4523 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4524 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004525 }
4526}
4527
4528void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4529{
4530 GLfloat xyzw[4] = {x, y, z, w};
4531
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004532 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004533}
4534
4535void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4536{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004537 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004538
Geoff Langbfdea662014-07-23 14:16:32 -04004539 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004540 if (context)
4541 {
4542 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543 {
Geoff Langbfdea662014-07-23 14:16:32 -04004544 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004545 }
Geoff Langbfdea662014-07-23 14:16:32 -04004546
4547 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4548 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004549 }
4550}
4551
4552void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4553{
4554 GLint xyzw[4] = {x, y, z, w};
4555
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004556 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557}
4558
4559void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4560{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004561 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562
Geoff Langbfdea662014-07-23 14:16:32 -04004563 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004564 if (context)
4565 {
4566 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004567 {
Geoff Langbfdea662014-07-23 14:16:32 -04004568 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004569 }
Geoff Langbfdea662014-07-23 14:16:32 -04004570
4571 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4572 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573 }
4574}
4575
4576void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4577{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004578 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004579 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004580
Geoff Langbfdea662014-07-23 14:16:32 -04004581 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004582 if (context)
4583 {
4584 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004585 {
Geoff Langbfdea662014-07-23 14:16:32 -04004586 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004587 }
Geoff Langbfdea662014-07-23 14:16:32 -04004588
4589 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4590 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004591 }
4592}
4593
4594void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4595{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004596 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004597 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004598
Geoff Langbfdea662014-07-23 14:16:32 -04004599 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004600 if (context)
4601 {
4602 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004603 {
Geoff Langbfdea662014-07-23 14:16:32 -04004604 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004605 }
Geoff Langbfdea662014-07-23 14:16:32 -04004606
4607 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4608 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609 }
4610}
4611
4612void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4613{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004614 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004615 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004616
Geoff Langbfdea662014-07-23 14:16:32 -04004617 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004618 if (context)
4619 {
4620 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004621 {
Geoff Langbfdea662014-07-23 14:16:32 -04004622 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004623 }
Geoff Langbfdea662014-07-23 14:16:32 -04004624
4625 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4626 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 }
4628}
4629
4630void __stdcall glUseProgram(GLuint program)
4631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004632 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004633
Geoff Langbfdea662014-07-23 14:16:32 -04004634 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004635 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004636 {
Geoff Langbfdea662014-07-23 14:16:32 -04004637 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004638
Geoff Langbfdea662014-07-23 14:16:32 -04004639 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004640 {
Geoff Langbfdea662014-07-23 14:16:32 -04004641 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642 {
Geoff Langb1196682014-07-23 13:47:29 -04004643 context->recordError(gl::Error(GL_INVALID_OPERATION));
4644 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004645 }
Geoff Langbfdea662014-07-23 14:16:32 -04004646 else
4647 {
Geoff Langb1196682014-07-23 13:47:29 -04004648 context->recordError(gl::Error(GL_INVALID_VALUE));
4649 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004650 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004651 }
Geoff Langbfdea662014-07-23 14:16:32 -04004652
4653 if (program != 0 && !programObject->isLinked())
4654 {
Geoff Langb1196682014-07-23 13:47:29 -04004655 context->recordError(gl::Error(GL_INVALID_OPERATION));
4656 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004657 }
4658
4659 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004660 }
4661}
4662
4663void __stdcall glValidateProgram(GLuint program)
4664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004665 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004666
Geoff Langbfdea662014-07-23 14:16:32 -04004667 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004668 if (context)
4669 {
4670 gl::Program *programObject = context->getProgram(program);
4671
4672 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004673 {
Geoff Langbfdea662014-07-23 14:16:32 -04004674 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004675 {
Geoff Langb1196682014-07-23 13:47:29 -04004676 context->recordError(gl::Error(GL_INVALID_OPERATION));
4677 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004678 }
Geoff Langbfdea662014-07-23 14:16:32 -04004679 else
4680 {
Geoff Langb1196682014-07-23 13:47:29 -04004681 context->recordError(gl::Error(GL_INVALID_VALUE));
4682 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004683 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004684 }
Geoff Langbfdea662014-07-23 14:16:32 -04004685
Brandon Jones43a53e22014-08-28 16:23:22 -07004686 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004687 }
4688}
4689
4690void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4691{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004692 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004693
Geoff Langbfdea662014-07-23 14:16:32 -04004694 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004695 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004696 {
Geoff Langb1196682014-07-23 13:47:29 -04004697 if (index >= gl::MAX_VERTEX_ATTRIBS)
4698 {
4699 context->recordError(gl::Error(GL_INVALID_VALUE));
4700 return;
4701 }
4702
Geoff Langbfdea662014-07-23 14:16:32 -04004703 GLfloat vals[4] = { x, 0, 0, 1 };
4704 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004705 }
4706}
4707
4708void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4709{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004710 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004711
Geoff Langbfdea662014-07-23 14:16:32 -04004712 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004713 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004714 {
Geoff Langb1196682014-07-23 13:47:29 -04004715 if (index >= gl::MAX_VERTEX_ATTRIBS)
4716 {
4717 context->recordError(gl::Error(GL_INVALID_VALUE));
4718 return;
4719 }
4720
Geoff Langbfdea662014-07-23 14:16:32 -04004721 GLfloat vals[4] = { values[0], 0, 0, 1 };
4722 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004723 }
4724}
4725
4726void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4727{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004728 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004729
Geoff Langbfdea662014-07-23 14:16:32 -04004730 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004731 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004732 {
Geoff Langb1196682014-07-23 13:47:29 -04004733 if (index >= gl::MAX_VERTEX_ATTRIBS)
4734 {
4735 context->recordError(gl::Error(GL_INVALID_VALUE));
4736 return;
4737 }
4738
Geoff Langbfdea662014-07-23 14:16:32 -04004739 GLfloat vals[4] = { x, y, 0, 1 };
4740 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004741 }
4742}
4743
4744void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4745{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004746 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004747
Geoff Langbfdea662014-07-23 14:16:32 -04004748 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004749 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004750 {
Geoff Langb1196682014-07-23 13:47:29 -04004751 if (index >= gl::MAX_VERTEX_ATTRIBS)
4752 {
4753 context->recordError(gl::Error(GL_INVALID_VALUE));
4754 return;
4755 }
4756
Geoff Langbfdea662014-07-23 14:16:32 -04004757 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4758 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004759 }
4760}
4761
4762void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4763{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004764 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 +00004765
Geoff Langbfdea662014-07-23 14:16:32 -04004766 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004767 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004768 {
Geoff Langb1196682014-07-23 13:47:29 -04004769 if (index >= gl::MAX_VERTEX_ATTRIBS)
4770 {
4771 context->recordError(gl::Error(GL_INVALID_VALUE));
4772 return;
4773 }
4774
Geoff Langbfdea662014-07-23 14:16:32 -04004775 GLfloat vals[4] = { x, y, z, 1 };
4776 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004777 }
4778}
4779
4780void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4781{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004782 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004783
Geoff Langbfdea662014-07-23 14:16:32 -04004784 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004785 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004786 {
Geoff Langb1196682014-07-23 13:47:29 -04004787 if (index >= gl::MAX_VERTEX_ATTRIBS)
4788 {
4789 context->recordError(gl::Error(GL_INVALID_VALUE));
4790 return;
4791 }
4792
Geoff Langbfdea662014-07-23 14:16:32 -04004793 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4794 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004795 }
4796}
4797
4798void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4799{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004800 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 +00004801
Geoff Langbfdea662014-07-23 14:16:32 -04004802 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004803 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004804 {
Geoff Langb1196682014-07-23 13:47:29 -04004805 if (index >= gl::MAX_VERTEX_ATTRIBS)
4806 {
4807 context->recordError(gl::Error(GL_INVALID_VALUE));
4808 return;
4809 }
4810
Geoff Langbfdea662014-07-23 14:16:32 -04004811 GLfloat vals[4] = { x, y, z, w };
4812 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004813 }
4814}
4815
4816void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4817{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004818 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004819
Geoff Langbfdea662014-07-23 14:16:32 -04004820 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004821 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004822 {
Geoff Langb1196682014-07-23 13:47:29 -04004823 if (index >= gl::MAX_VERTEX_ATTRIBS)
4824 {
4825 context->recordError(gl::Error(GL_INVALID_VALUE));
4826 return;
4827 }
4828
Geoff Langbfdea662014-07-23 14:16:32 -04004829 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004830 }
4831}
4832
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004833void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4834{
4835 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4836
Geoff Langbfdea662014-07-23 14:16:32 -04004837 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004838 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004839 {
Geoff Langb1196682014-07-23 13:47:29 -04004840 if (index >= gl::MAX_VERTEX_ATTRIBS)
4841 {
4842 context->recordError(gl::Error(GL_INVALID_VALUE));
4843 return;
4844 }
4845
Geoff Langbfdea662014-07-23 14:16:32 -04004846 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004847 }
4848}
4849
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004850void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004851{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004852 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004853 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004854 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004855
Geoff Langbfdea662014-07-23 14:16:32 -04004856 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004857 if (context)
4858 {
Geoff Langb1196682014-07-23 13:47:29 -04004859 if (index >= gl::MAX_VERTEX_ATTRIBS)
4860 {
4861 context->recordError(gl::Error(GL_INVALID_VALUE));
4862 return;
4863 }
4864
4865 if (size < 1 || size > 4)
4866 {
4867 context->recordError(gl::Error(GL_INVALID_VALUE));
4868 return;
4869 }
4870
4871 switch (type)
4872 {
4873 case GL_BYTE:
4874 case GL_UNSIGNED_BYTE:
4875 case GL_SHORT:
4876 case GL_UNSIGNED_SHORT:
4877 case GL_FIXED:
4878 case GL_FLOAT:
4879 break;
4880
4881 case GL_HALF_FLOAT:
4882 case GL_INT:
4883 case GL_UNSIGNED_INT:
4884 case GL_INT_2_10_10_10_REV:
4885 case GL_UNSIGNED_INT_2_10_10_10_REV:
4886 if (context->getClientVersion() < 3)
4887 {
4888 context->recordError(gl::Error(GL_INVALID_ENUM));
4889 return;
4890 }
4891 break;
4892
4893 default:
4894 context->recordError(gl::Error(GL_INVALID_ENUM));
4895 return;
4896 }
4897
4898 if (stride < 0)
4899 {
4900 context->recordError(gl::Error(GL_INVALID_VALUE));
4901 return;
4902 }
4903
4904 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4905 {
4906 context->recordError(gl::Error(GL_INVALID_OPERATION));
4907 return;
4908 }
4909
Geoff Langbfdea662014-07-23 14:16:32 -04004910 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4911 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4912 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4913 // and the pointer argument is not NULL.
4914 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004915 {
Geoff Langb1196682014-07-23 13:47:29 -04004916 context->recordError(gl::Error(GL_INVALID_OPERATION));
4917 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004918 }
4919
Geoff Langbfdea662014-07-23 14:16:32 -04004920 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4921 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004922 }
4923}
4924
4925void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4926{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004927 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 +00004928
Geoff Langbfdea662014-07-23 14:16:32 -04004929 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004930 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004931 {
Geoff Langb1196682014-07-23 13:47:29 -04004932 if (width < 0 || height < 0)
4933 {
4934 context->recordError(gl::Error(GL_INVALID_VALUE));
4935 return;
4936 }
4937
Geoff Langbfdea662014-07-23 14:16:32 -04004938 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004939 }
4940}
4941
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004942// OpenGL ES 3.0 functions
4943
4944void __stdcall glReadBuffer(GLenum mode)
4945{
4946 EVENT("(GLenum mode = 0x%X)", mode);
4947
Geoff Langbfdea662014-07-23 14:16:32 -04004948 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004949 if (context)
4950 {
4951 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004952 {
Geoff Langb1196682014-07-23 13:47:29 -04004953 context->recordError(gl::Error(GL_INVALID_OPERATION));
4954 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004955 }
Geoff Langbfdea662014-07-23 14:16:32 -04004956
4957 // glReadBuffer
4958 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004959 }
4960}
4961
4962void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4963{
4964 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4965 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4966
Geoff Langbfdea662014-07-23 14:16:32 -04004967 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004968 if (context)
4969 {
4970 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004971 {
Geoff Langb1196682014-07-23 13:47:29 -04004972 context->recordError(gl::Error(GL_INVALID_OPERATION));
4973 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004974 }
Geoff Langbfdea662014-07-23 14:16:32 -04004975
4976 // glDrawRangeElements
4977 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004978 }
4979}
4980
4981void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4982{
4983 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4984 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4985 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4986 target, level, internalformat, width, height, depth, border, format, type, pixels);
4987
Geoff Langbfdea662014-07-23 14:16:32 -04004988 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004989 if (context)
4990 {
4991 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004992 {
Geoff Langb1196682014-07-23 13:47:29 -04004993 context->recordError(gl::Error(GL_INVALID_OPERATION));
4994 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004995 }
Geoff Langbfdea662014-07-23 14:16:32 -04004996
4997 // validateES3TexImageFormat sets the error code if there is an error
4998 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4999 0, 0, 0, width, height, depth, border, format, type, pixels))
5000 {
5001 return;
5002 }
5003
5004 switch(target)
5005 {
5006 case GL_TEXTURE_3D:
5007 {
5008 gl::Texture3D *texture = context->getTexture3D();
5009 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5010 }
5011 break;
5012
5013 case GL_TEXTURE_2D_ARRAY:
5014 {
5015 gl::Texture2DArray *texture = context->getTexture2DArray();
5016 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5017 }
5018 break;
5019
5020 default:
Geoff Langb1196682014-07-23 13:47:29 -04005021 context->recordError(gl::Error(GL_INVALID_ENUM));
5022 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005023 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005024 }
5025}
5026
5027void __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)
5028{
5029 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5030 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5031 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5032 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
5033
Geoff Langbfdea662014-07-23 14:16:32 -04005034 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005035 if (context)
5036 {
5037 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005038 {
Geoff Langb1196682014-07-23 13:47:29 -04005039 context->recordError(gl::Error(GL_INVALID_OPERATION));
5040 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005041 }
Geoff Langbfdea662014-07-23 14:16:32 -04005042
5043 // validateES3TexImageFormat sets the error code if there is an error
5044 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5045 xoffset, yoffset, zoffset, width, height, depth, 0,
5046 format, type, pixels))
5047 {
5048 return;
5049 }
5050
5051 // Zero sized uploads are valid but no-ops
5052 if (width == 0 || height == 0 || depth == 0)
5053 {
5054 return;
5055 }
5056
5057 switch(target)
5058 {
5059 case GL_TEXTURE_3D:
5060 {
5061 gl::Texture3D *texture = context->getTexture3D();
5062 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5063 }
5064 break;
5065
5066 case GL_TEXTURE_2D_ARRAY:
5067 {
5068 gl::Texture2DArray *texture = context->getTexture2DArray();
5069 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5070 }
5071 break;
5072
5073 default:
Geoff Langb1196682014-07-23 13:47:29 -04005074 context->recordError(gl::Error(GL_INVALID_ENUM));
5075 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005076 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005077 }
5078}
5079
5080void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5081{
5082 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5083 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5084 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5085
Geoff Langbfdea662014-07-23 14:16:32 -04005086 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005087 if (context)
5088 {
5089 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005090 {
Geoff Langb1196682014-07-23 13:47:29 -04005091 context->recordError(gl::Error(GL_INVALID_OPERATION));
5092 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005093 }
Geoff Langbfdea662014-07-23 14:16:32 -04005094
5095 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5096 x, y, width, height, 0))
5097 {
5098 return;
5099 }
5100
5101 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5102 gl::Texture *texture = NULL;
5103 switch (target)
5104 {
5105 case GL_TEXTURE_3D:
5106 texture = context->getTexture3D();
5107 break;
5108
5109 case GL_TEXTURE_2D_ARRAY:
5110 texture = context->getTexture2DArray();
5111 break;
5112
5113 default:
Geoff Langb1196682014-07-23 13:47:29 -04005114 context->recordError(gl::Error(GL_INVALID_ENUM));
5115 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005116 }
5117
5118 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005119 }
5120}
5121
5122void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5123{
Geoff Langeef52cc2013-10-16 15:07:39 -04005124 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 +00005125 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5126 "const GLvoid* data = 0x%0.8p)",
5127 target, level, internalformat, width, height, depth, border, imageSize, data);
5128
Geoff Langbfdea662014-07-23 14:16:32 -04005129 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005130 if (context)
5131 {
5132 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005133 {
Geoff Langb1196682014-07-23 13:47:29 -04005134 context->recordError(gl::Error(GL_INVALID_OPERATION));
5135 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005136 }
Geoff Langbfdea662014-07-23 14:16:32 -04005137
Geoff Lang5d601382014-07-22 15:14:06 -04005138 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5139 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005140 {
Geoff Langb1196682014-07-23 13:47:29 -04005141 context->recordError(gl::Error(GL_INVALID_VALUE));
5142 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005143 }
5144
5145 // validateES3TexImageFormat sets the error code if there is an error
5146 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5147 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5148 {
5149 return;
5150 }
5151
5152 switch(target)
5153 {
5154 case GL_TEXTURE_3D:
5155 {
5156 gl::Texture3D *texture = context->getTexture3D();
5157 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5158 }
5159 break;
5160
5161 case GL_TEXTURE_2D_ARRAY:
5162 {
5163 gl::Texture2DArray *texture = context->getTexture2DArray();
5164 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5165 }
5166 break;
5167
5168 default:
Geoff Langb1196682014-07-23 13:47:29 -04005169 context->recordError(gl::Error(GL_INVALID_ENUM));
5170 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005171 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005172 }
5173}
5174
5175void __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)
5176{
5177 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5178 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5179 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5180 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5181
Geoff Langbfdea662014-07-23 14:16:32 -04005182 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005183 if (context)
5184 {
5185 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005186 {
Geoff Langb1196682014-07-23 13:47:29 -04005187 context->recordError(gl::Error(GL_INVALID_OPERATION));
5188 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005189 }
Geoff Langbfdea662014-07-23 14:16:32 -04005190
Geoff Lang5d601382014-07-22 15:14:06 -04005191 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5192 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005193 {
Geoff Langb1196682014-07-23 13:47:29 -04005194 context->recordError(gl::Error(GL_INVALID_VALUE));
5195 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005196 }
5197
5198 if (!data)
5199 {
Geoff Langb1196682014-07-23 13:47:29 -04005200 context->recordError(gl::Error(GL_INVALID_VALUE));
5201 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005202 }
5203
5204 // validateES3TexImageFormat sets the error code if there is an error
5205 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5206 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5207 {
5208 return;
5209 }
5210
5211 // Zero sized uploads are valid but no-ops
5212 if (width == 0 || height == 0)
5213 {
5214 return;
5215 }
5216
5217 switch(target)
5218 {
5219 case GL_TEXTURE_3D:
5220 {
5221 gl::Texture3D *texture = context->getTexture3D();
5222 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5223 format, imageSize, data);
5224 }
5225 break;
5226
5227 case GL_TEXTURE_2D_ARRAY:
5228 {
5229 gl::Texture2DArray *texture = context->getTexture2DArray();
5230 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5231 format, imageSize, data);
5232 }
5233 break;
5234
Geoff Langb1196682014-07-23 13:47:29 -04005235 default:
5236 context->recordError(gl::Error(GL_INVALID_ENUM));
5237 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005238 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005239 }
5240}
5241
5242void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5243{
5244 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5245
Geoff Langbfdea662014-07-23 14:16:32 -04005246 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005247 if (context)
5248 {
5249 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005250 {
Geoff Langb1196682014-07-23 13:47:29 -04005251 context->recordError(gl::Error(GL_INVALID_OPERATION));
5252 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005253 }
Geoff Langbfdea662014-07-23 14:16:32 -04005254
5255 if (n < 0)
5256 {
Geoff Langb1196682014-07-23 13:47:29 -04005257 context->recordError(gl::Error(GL_INVALID_VALUE));
5258 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005259 }
5260
5261 for (GLsizei i = 0; i < n; i++)
5262 {
5263 ids[i] = context->createQuery();
5264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005265 }
5266}
5267
5268void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5269{
5270 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5271
Geoff Langbfdea662014-07-23 14:16:32 -04005272 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005273 if (context)
5274 {
5275 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005276 {
Geoff Langb1196682014-07-23 13:47:29 -04005277 context->recordError(gl::Error(GL_INVALID_OPERATION));
5278 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005279 }
Geoff Langbfdea662014-07-23 14:16:32 -04005280
5281 if (n < 0)
5282 {
Geoff Langb1196682014-07-23 13:47:29 -04005283 context->recordError(gl::Error(GL_INVALID_VALUE));
5284 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005285 }
5286
5287 for (GLsizei i = 0; i < n; i++)
5288 {
5289 context->deleteQuery(ids[i]);
5290 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005291 }
5292}
5293
5294GLboolean __stdcall glIsQuery(GLuint id)
5295{
5296 EVENT("(GLuint id = %u)", id);
5297
Geoff Langbfdea662014-07-23 14:16:32 -04005298 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005299 if (context)
5300 {
5301 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005302 {
Geoff Langb1196682014-07-23 13:47:29 -04005303 context->recordError(gl::Error(GL_INVALID_OPERATION));
5304 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005305 }
Geoff Langbfdea662014-07-23 14:16:32 -04005306
5307 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005308 }
5309
5310 return GL_FALSE;
5311}
5312
5313void __stdcall glBeginQuery(GLenum target, GLuint id)
5314{
5315 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5316
Geoff Langbfdea662014-07-23 14:16:32 -04005317 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005318 if (context)
5319 {
5320 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005321 {
Geoff Langb1196682014-07-23 13:47:29 -04005322 context->recordError(gl::Error(GL_INVALID_OPERATION));
5323 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005324 }
Geoff Langbfdea662014-07-23 14:16:32 -04005325
5326 if (!ValidateBeginQuery(context, target, id))
5327 {
5328 return;
5329 }
Geoff Lang5aad9672014-09-08 11:10:42 -04005330
5331 gl::Error error = context->beginQuery(target, id);
5332 if (error.isError())
5333 {
5334 context->recordError(error);
5335 return;
5336 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005337 }
5338}
5339
5340void __stdcall glEndQuery(GLenum target)
5341{
5342 EVENT("(GLenum target = 0x%X)", target);
5343
Geoff Langbfdea662014-07-23 14:16:32 -04005344 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005345 if (context)
5346 {
5347 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005348 {
Geoff Langb1196682014-07-23 13:47:29 -04005349 context->recordError(gl::Error(GL_INVALID_OPERATION));
5350 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005351 }
Geoff Langbfdea662014-07-23 14:16:32 -04005352
5353 if (!ValidateEndQuery(context, target))
5354 {
5355 return;
5356 }
5357
Geoff Lang5aad9672014-09-08 11:10:42 -04005358 gl::Error error = context->endQuery(target);
5359 if (error.isError())
5360 {
5361 context->recordError(error);
5362 return;
5363 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005364 }
5365}
5366
5367void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5368{
5369 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5370
Geoff Langbfdea662014-07-23 14:16:32 -04005371 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005372 if (context)
5373 {
5374 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005375 {
Geoff Langb1196682014-07-23 13:47:29 -04005376 context->recordError(gl::Error(GL_INVALID_OPERATION));
5377 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005378 }
Geoff Langbfdea662014-07-23 14:16:32 -04005379
5380 if (!ValidQueryType(context, target))
5381 {
Geoff Langb1196682014-07-23 13:47:29 -04005382 context->recordError(gl::Error(GL_INVALID_ENUM));
5383 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005384 }
5385
5386 switch (pname)
5387 {
5388 case GL_CURRENT_QUERY:
5389 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5390 break;
5391
5392 default:
Geoff Langb1196682014-07-23 13:47:29 -04005393 context->recordError(gl::Error(GL_INVALID_ENUM));
5394 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005395 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005396 }
5397}
5398
5399void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5400{
5401 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5402
Geoff Langbfdea662014-07-23 14:16:32 -04005403 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005404 if (context)
5405 {
5406 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005407 {
Geoff Langb1196682014-07-23 13:47:29 -04005408 context->recordError(gl::Error(GL_INVALID_OPERATION));
5409 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005410 }
Geoff Langbfdea662014-07-23 14:16:32 -04005411
5412 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5413
5414 if (!queryObject)
5415 {
Geoff Langb1196682014-07-23 13:47:29 -04005416 context->recordError(gl::Error(GL_INVALID_OPERATION));
5417 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005418 }
5419
5420 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5421 {
Geoff Langb1196682014-07-23 13:47:29 -04005422 context->recordError(gl::Error(GL_INVALID_OPERATION));
5423 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005424 }
5425
5426 switch(pname)
5427 {
Geoff Lang5aad9672014-09-08 11:10:42 -04005428 case GL_QUERY_RESULT_EXT:
5429 {
5430 gl::Error error = queryObject->getResult(params);
5431 if (error.isError())
5432 {
5433 context->recordError(error);
5434 return;
5435 }
5436 }
Geoff Langbfdea662014-07-23 14:16:32 -04005437 break;
Geoff Langb1196682014-07-23 13:47:29 -04005438
Geoff Lang5aad9672014-09-08 11:10:42 -04005439 case GL_QUERY_RESULT_AVAILABLE_EXT:
5440 {
5441 gl::Error error = queryObject->isResultAvailable(params);
5442 if (error.isError())
5443 {
5444 context->recordError(error);
5445 return;
5446 }
5447 }
Geoff Langbfdea662014-07-23 14:16:32 -04005448 break;
Geoff Langb1196682014-07-23 13:47:29 -04005449
Geoff Langbfdea662014-07-23 14:16:32 -04005450 default:
Geoff Langb1196682014-07-23 13:47:29 -04005451 context->recordError(gl::Error(GL_INVALID_ENUM));
5452 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005453 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005454 }
5455}
5456
5457GLboolean __stdcall glUnmapBuffer(GLenum target)
5458{
5459 EVENT("(GLenum target = 0x%X)", target);
5460
Geoff Langbfdea662014-07-23 14:16:32 -04005461 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005462 if (context)
5463 {
5464 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005465 {
Geoff Langb1196682014-07-23 13:47:29 -04005466 context->recordError(gl::Error(GL_INVALID_OPERATION));
5467 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005468 }
Geoff Langbfdea662014-07-23 14:16:32 -04005469
5470 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005471 }
5472
5473 return GL_FALSE;
5474}
5475
5476void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5477{
5478 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5479
Geoff Langbfdea662014-07-23 14:16:32 -04005480 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005481 if (context)
5482 {
5483 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005484 {
Geoff Langb1196682014-07-23 13:47:29 -04005485 context->recordError(gl::Error(GL_INVALID_OPERATION));
5486 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005487 }
Geoff Langbfdea662014-07-23 14:16:32 -04005488
5489 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005490 }
5491}
5492
5493void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5494{
Geoff Langbfdea662014-07-23 14:16:32 -04005495 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005496 if (context)
5497 {
5498 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005499 {
Geoff Langb1196682014-07-23 13:47:29 -04005500 context->recordError(gl::Error(GL_INVALID_OPERATION));
5501 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005502 }
Geoff Langbfdea662014-07-23 14:16:32 -04005503
5504 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005505 }
5506}
5507
5508void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5509{
5510 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5511 location, count, transpose, value);
5512
Geoff Langbfdea662014-07-23 14:16:32 -04005513 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005514 if (context)
5515 {
5516 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005517 {
Geoff Langbfdea662014-07-23 14:16:32 -04005518 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005519 }
Geoff Langbfdea662014-07-23 14:16:32 -04005520
5521 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5522 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005523 }
5524}
5525
5526void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5527{
5528 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5529 location, count, transpose, value);
5530
Geoff Langbfdea662014-07-23 14:16:32 -04005531 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005532 if (context)
5533 {
5534 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005535 {
Geoff Langbfdea662014-07-23 14:16:32 -04005536 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005537 }
Geoff Langbfdea662014-07-23 14:16:32 -04005538
5539 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5540 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005541 }
5542}
5543
5544void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5545{
5546 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5547 location, count, transpose, value);
5548
Geoff Langbfdea662014-07-23 14:16:32 -04005549 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005550 if (context)
5551 {
5552 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005553 {
Geoff Langbfdea662014-07-23 14:16:32 -04005554 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005555 }
Geoff Langbfdea662014-07-23 14:16:32 -04005556
5557 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5558 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005559 }
5560}
5561
5562void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5563{
5564 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5565 location, count, transpose, value);
5566
Geoff Langbfdea662014-07-23 14:16:32 -04005567 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005568 if (context)
5569 {
5570 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005571 {
Geoff Langbfdea662014-07-23 14:16:32 -04005572 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005573 }
Geoff Langbfdea662014-07-23 14:16:32 -04005574
5575 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5576 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005577 }
5578}
5579
5580void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5581{
5582 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5583 location, count, transpose, value);
5584
Geoff Langbfdea662014-07-23 14:16:32 -04005585 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005586 if (context)
5587 {
5588 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005589 {
Geoff Langbfdea662014-07-23 14:16:32 -04005590 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005591 }
Geoff Langbfdea662014-07-23 14:16:32 -04005592
5593 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5594 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005595 }
5596}
5597
5598void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5599{
5600 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5601 location, count, transpose, value);
5602
Geoff Langbfdea662014-07-23 14:16:32 -04005603 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005604 if (context)
5605 {
5606 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005607 {
Geoff Langbfdea662014-07-23 14:16:32 -04005608 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005609 }
Geoff Langbfdea662014-07-23 14:16:32 -04005610
5611 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5612 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005613 }
5614}
5615
5616void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5617{
5618 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5619 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5620 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5621
Geoff Langbfdea662014-07-23 14:16:32 -04005622 gl::Context *context = gl::getNonLostContext();
5623 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005624 {
Geoff Langbfdea662014-07-23 14:16:32 -04005625 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005626 {
Geoff Langb1196682014-07-23 13:47:29 -04005627 context->recordError(gl::Error(GL_INVALID_OPERATION));
5628 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005629 }
Geoff Langbfdea662014-07-23 14:16:32 -04005630
5631 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5632 dstX0, dstY0, dstX1, dstY1, mask, filter,
5633 false))
5634 {
5635 return;
5636 }
5637
5638 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5639 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005640 }
5641}
5642
5643void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5644{
5645 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5646 target, samples, internalformat, width, height);
5647
Geoff Langbfdea662014-07-23 14:16:32 -04005648 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005649 if (context)
5650 {
5651 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005652 {
Geoff Langb1196682014-07-23 13:47:29 -04005653 context->recordError(gl::Error(GL_INVALID_OPERATION));
5654 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005655 }
Geoff Langbfdea662014-07-23 14:16:32 -04005656
5657 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5658 width, height, false))
5659 {
5660 return;
5661 }
5662
5663 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005664 }
5665}
5666
5667void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5668{
5669 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5670 target, attachment, texture, level, layer);
5671
Geoff Langbfdea662014-07-23 14:16:32 -04005672 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005673 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005674 {
Geoff Langbfdea662014-07-23 14:16:32 -04005675 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5676 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005677 {
Geoff Langbfdea662014-07-23 14:16:32 -04005678 return;
5679 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005680
Geoff Langbfdea662014-07-23 14:16:32 -04005681 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5682 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005683
Geoff Langbfdea662014-07-23 14:16:32 -04005684 gl::Texture *textureObject = context->getTexture(texture);
5685 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005686
Geoff Langbfdea662014-07-23 14:16:32 -04005687 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5688 {
5689 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5690 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5691 }
5692 else
5693 {
5694 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005695 {
Geoff Langbfdea662014-07-23 14:16:32 -04005696 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5697 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5698 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005699 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005700 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005701 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005702}
5703
5704GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5705{
5706 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5707 target, offset, length, access);
5708
Geoff Langbfdea662014-07-23 14:16:32 -04005709 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005710 if (context)
5711 {
5712 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005713 {
Geoff Langb1196682014-07-23 13:47:29 -04005714 context->recordError(gl::Error(GL_INVALID_OPERATION));
5715 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005716 }
Geoff Langbfdea662014-07-23 14:16:32 -04005717
5718 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005719 }
5720
5721 return NULL;
5722}
5723
5724void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5725{
5726 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5727
Geoff Langbfdea662014-07-23 14:16:32 -04005728 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005729 if (context)
5730 {
5731 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005732 {
Geoff Langb1196682014-07-23 13:47:29 -04005733 context->recordError(gl::Error(GL_INVALID_OPERATION));
5734 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005735 }
Geoff Langbfdea662014-07-23 14:16:32 -04005736
5737 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005738 }
5739}
5740
5741void __stdcall glBindVertexArray(GLuint array)
5742{
5743 EVENT("(GLuint array = %u)", array);
5744
Geoff Langbfdea662014-07-23 14:16:32 -04005745 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005746 if (context)
5747 {
5748 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005749 {
Geoff Langb1196682014-07-23 13:47:29 -04005750 context->recordError(gl::Error(GL_INVALID_OPERATION));
5751 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005752 }
Geoff Langbfdea662014-07-23 14:16:32 -04005753
5754 gl::VertexArray *vao = context->getVertexArray(array);
5755
5756 if (!vao)
5757 {
5758 // The default VAO should always exist
5759 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005760 context->recordError(gl::Error(GL_INVALID_OPERATION));
5761 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005762 }
5763
5764 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005765 }
5766}
5767
5768void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5769{
5770 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5771
Geoff Langbfdea662014-07-23 14:16:32 -04005772 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005773 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005774 {
Geoff Langbfdea662014-07-23 14:16:32 -04005775 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005776 {
Geoff Langb1196682014-07-23 13:47:29 -04005777 context->recordError(gl::Error(GL_INVALID_OPERATION));
5778 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005779 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005780
Geoff Langbfdea662014-07-23 14:16:32 -04005781 if (n < 0)
5782 {
Geoff Langb1196682014-07-23 13:47:29 -04005783 context->recordError(gl::Error(GL_INVALID_VALUE));
5784 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005785 }
Jamie Madilld1028542013-07-02 11:57:04 -04005786
Geoff Langbfdea662014-07-23 14:16:32 -04005787 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5788 {
5789 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005790 {
Geoff Langbfdea662014-07-23 14:16:32 -04005791 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005792 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005793 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005794 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005795}
5796
5797void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5798{
5799 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5800
Geoff Langbfdea662014-07-23 14:16:32 -04005801 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005802 if (context)
5803 {
5804 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005805 {
Geoff Langb1196682014-07-23 13:47:29 -04005806 context->recordError(gl::Error(GL_INVALID_OPERATION));
5807 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005808 }
Geoff Langbfdea662014-07-23 14:16:32 -04005809
5810 if (n < 0)
5811 {
Geoff Langb1196682014-07-23 13:47:29 -04005812 context->recordError(gl::Error(GL_INVALID_VALUE));
5813 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005814 }
5815
5816 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5817 {
5818 arrays[arrayIndex] = context->createVertexArray();
5819 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005820 }
5821}
5822
5823GLboolean __stdcall glIsVertexArray(GLuint array)
5824{
5825 EVENT("(GLuint array = %u)", array);
5826
Geoff Langbfdea662014-07-23 14:16:32 -04005827 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005828 if (context)
5829 {
5830 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005831 {
Geoff Langb1196682014-07-23 13:47:29 -04005832 context->recordError(gl::Error(GL_INVALID_OPERATION));
5833 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005834 }
Geoff Langbfdea662014-07-23 14:16:32 -04005835
5836 if (array == 0)
5837 {
5838 return GL_FALSE;
5839 }
5840
5841 gl::VertexArray *vao = context->getVertexArray(array);
5842
5843 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005844 }
5845
5846 return GL_FALSE;
5847}
5848
5849void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5850{
5851 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5852 target, index, data);
5853
Geoff Langbfdea662014-07-23 14:16:32 -04005854 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005855 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005856 {
Geoff Langbfdea662014-07-23 14:16:32 -04005857 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005858 {
Geoff Langb1196682014-07-23 13:47:29 -04005859 context->recordError(gl::Error(GL_INVALID_OPERATION));
5860 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005861 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005862
Geoff Lang3a61c322014-07-10 13:01:54 -04005863 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005864 switch (target)
5865 {
5866 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5867 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5868 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005869 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5870 {
Geoff Langb1196682014-07-23 13:47:29 -04005871 context->recordError(gl::Error(GL_INVALID_VALUE));
5872 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005873 }
Geoff Langbfdea662014-07-23 14:16:32 -04005874 break;
Geoff Langb1196682014-07-23 13:47:29 -04005875
Geoff Langbfdea662014-07-23 14:16:32 -04005876 case GL_UNIFORM_BUFFER_START:
5877 case GL_UNIFORM_BUFFER_SIZE:
5878 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005879 if (index >= caps.maxCombinedUniformBlocks)
5880 {
Geoff Langb1196682014-07-23 13:47:29 -04005881 context->recordError(gl::Error(GL_INVALID_VALUE));
5882 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005883 }
Geoff Langbfdea662014-07-23 14:16:32 -04005884 break;
Geoff Langb1196682014-07-23 13:47:29 -04005885
Geoff Langbfdea662014-07-23 14:16:32 -04005886 default:
Geoff Langb1196682014-07-23 13:47:29 -04005887 context->recordError(gl::Error(GL_INVALID_ENUM));
5888 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005889 }
5890
5891 if (!(context->getIndexedIntegerv(target, index, data)))
5892 {
5893 GLenum nativeType;
5894 unsigned int numParams = 0;
5895 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005896 {
5897 context->recordError(gl::Error(GL_INVALID_ENUM));
5898 return;
5899 }
Shannon Woods15934d52013-08-19 14:28:49 -04005900
Geoff Langbfdea662014-07-23 14:16:32 -04005901 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005902 {
Geoff Langbfdea662014-07-23 14:16:32 -04005903 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005904 }
Geoff Langbfdea662014-07-23 14:16:32 -04005905
5906 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005907 {
Geoff Langbfdea662014-07-23 14:16:32 -04005908 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5909 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5910 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005911
Geoff Langbfdea662014-07-23 14:16:32 -04005912 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005913
Geoff Langbfdea662014-07-23 14:16:32 -04005914 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005915 {
Geoff Langbfdea662014-07-23 14:16:32 -04005916 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5917 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005918 }
Geoff Langbfdea662014-07-23 14:16:32 -04005919
5920 delete [] int64Params;
5921 }
5922 else
5923 {
5924 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005925 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005926 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005927 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005928}
5929
5930void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5931{
5932 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5933
Geoff Langbfdea662014-07-23 14:16:32 -04005934 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005935 if (context)
5936 {
5937 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005938 {
Geoff Langb1196682014-07-23 13:47:29 -04005939 context->recordError(gl::Error(GL_INVALID_OPERATION));
5940 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005941 }
Geoff Langbfdea662014-07-23 14:16:32 -04005942
5943 switch (primitiveMode)
5944 {
5945 case GL_TRIANGLES:
5946 case GL_LINES:
5947 case GL_POINTS:
5948 break;
Geoff Langb1196682014-07-23 13:47:29 -04005949
Geoff Langbfdea662014-07-23 14:16:32 -04005950 default:
Geoff Langb1196682014-07-23 13:47:29 -04005951 context->recordError(gl::Error(GL_INVALID_ENUM));
5952 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005953 }
5954
5955 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5956 ASSERT(transformFeedback != NULL);
5957
5958 if (transformFeedback->isStarted())
5959 {
Geoff Langb1196682014-07-23 13:47:29 -04005960 context->recordError(gl::Error(GL_INVALID_OPERATION));
5961 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005962 }
5963
5964 if (transformFeedback->isPaused())
5965 {
5966 transformFeedback->resume();
5967 }
5968 else
5969 {
5970 transformFeedback->start(primitiveMode);
5971 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005972 }
5973}
5974
5975void __stdcall glEndTransformFeedback(void)
5976{
5977 EVENT("(void)");
5978
Geoff Langbfdea662014-07-23 14:16:32 -04005979 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005980 if (context)
5981 {
5982 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005983 {
Geoff Langb1196682014-07-23 13:47:29 -04005984 context->recordError(gl::Error(GL_INVALID_OPERATION));
5985 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005986 }
Geoff Langbfdea662014-07-23 14:16:32 -04005987
5988 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5989 ASSERT(transformFeedback != NULL);
5990
5991 if (!transformFeedback->isStarted())
5992 {
Geoff Langb1196682014-07-23 13:47:29 -04005993 context->recordError(gl::Error(GL_INVALID_OPERATION));
5994 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005995 }
5996
5997 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005998 }
5999}
6000
6001void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
6002{
6003 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
6004 target, index, buffer, offset, size);
6005
Geoff Langbfdea662014-07-23 14:16:32 -04006006 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006007 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006008 {
Geoff Langbfdea662014-07-23 14:16:32 -04006009 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006010 {
Geoff Langb1196682014-07-23 13:47:29 -04006011 context->recordError(gl::Error(GL_INVALID_OPERATION));
6012 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006013 }
6014
Geoff Lang3a61c322014-07-10 13:01:54 -04006015 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006016 switch (target)
6017 {
6018 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006019 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006020 {
Geoff Langb1196682014-07-23 13:47:29 -04006021 context->recordError(gl::Error(GL_INVALID_VALUE));
6022 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006023 }
Geoff Langbfdea662014-07-23 14:16:32 -04006024 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006025
Geoff Langbfdea662014-07-23 14:16:32 -04006026 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006027 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006028 {
Geoff Langb1196682014-07-23 13:47:29 -04006029 context->recordError(gl::Error(GL_INVALID_VALUE));
6030 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006031 }
Geoff Langbfdea662014-07-23 14:16:32 -04006032 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006033
Geoff Langbfdea662014-07-23 14:16:32 -04006034 default:
Geoff Langb1196682014-07-23 13:47:29 -04006035 context->recordError(gl::Error(GL_INVALID_ENUM));
6036 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006037 }
6038
6039 if (buffer != 0 && size <= 0)
6040 {
Geoff Langb1196682014-07-23 13:47:29 -04006041 context->recordError(gl::Error(GL_INVALID_VALUE));
6042 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006043 }
6044
6045 switch (target)
6046 {
6047 case GL_TRANSFORM_FEEDBACK_BUFFER:
6048
6049 // size and offset must be a multiple of 4
6050 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006051 {
Geoff Langb1196682014-07-23 13:47:29 -04006052 context->recordError(gl::Error(GL_INVALID_VALUE));
6053 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006054 }
6055
Geoff Langbfdea662014-07-23 14:16:32 -04006056 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
6057 context->bindGenericTransformFeedbackBuffer(buffer);
6058 break;
6059
6060 case GL_UNIFORM_BUFFER:
6061
6062 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006063 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006064 {
Geoff Langb1196682014-07-23 13:47:29 -04006065 context->recordError(gl::Error(GL_INVALID_VALUE));
6066 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006067 }
Geoff Langbfdea662014-07-23 14:16:32 -04006068
6069 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6070 context->bindGenericUniformBuffer(buffer);
6071 break;
6072
6073 default:
6074 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006075 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006076 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006077}
6078
6079void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
6080{
6081 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6082 target, index, buffer);
6083
Geoff Langbfdea662014-07-23 14:16:32 -04006084 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006085 if (context)
6086 {
6087 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006088 {
Geoff Langb1196682014-07-23 13:47:29 -04006089 context->recordError(gl::Error(GL_INVALID_OPERATION));
6090 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006091 }
Geoff Langbfdea662014-07-23 14:16:32 -04006092
Geoff Lang3a61c322014-07-10 13:01:54 -04006093 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006094 switch (target)
6095 {
6096 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006097 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006098 {
Geoff Langb1196682014-07-23 13:47:29 -04006099 context->recordError(gl::Error(GL_INVALID_VALUE));
6100 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006101 }
6102 break;
6103
6104 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006105 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006106 {
Geoff Langb1196682014-07-23 13:47:29 -04006107 context->recordError(gl::Error(GL_INVALID_VALUE));
6108 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006109 }
6110 break;
6111
6112 default:
Geoff Langb1196682014-07-23 13:47:29 -04006113 context->recordError(gl::Error(GL_INVALID_ENUM));
6114 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006115 }
6116
6117 switch (target)
6118 {
6119 case GL_TRANSFORM_FEEDBACK_BUFFER:
6120 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6121 context->bindGenericTransformFeedbackBuffer(buffer);
6122 break;
6123
6124 case GL_UNIFORM_BUFFER:
6125 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6126 context->bindGenericUniformBuffer(buffer);
6127 break;
6128
6129 default:
6130 UNREACHABLE();
6131 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006132 }
6133}
6134
6135void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6136{
6137 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6138 program, count, varyings, bufferMode);
6139
Geoff Langbfdea662014-07-23 14:16:32 -04006140 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006141 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006142 {
Geoff Langbfdea662014-07-23 14:16:32 -04006143 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006144 {
Geoff Langb1196682014-07-23 13:47:29 -04006145 context->recordError(gl::Error(GL_INVALID_OPERATION));
6146 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006147 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006148
Geoff Langbfdea662014-07-23 14:16:32 -04006149 if (count < 0)
6150 {
Geoff Langb1196682014-07-23 13:47:29 -04006151 context->recordError(gl::Error(GL_INVALID_VALUE));
6152 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006153 }
6154
Geoff Lang05881a02014-07-10 14:05:30 -04006155 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006156 switch (bufferMode)
6157 {
6158 case GL_INTERLEAVED_ATTRIBS:
6159 break;
6160 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006161 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006162 {
Geoff Langb1196682014-07-23 13:47:29 -04006163 context->recordError(gl::Error(GL_INVALID_VALUE));
6164 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006165 }
Geoff Langbfdea662014-07-23 14:16:32 -04006166 break;
6167 default:
Geoff Langb1196682014-07-23 13:47:29 -04006168 context->recordError(gl::Error(GL_INVALID_ENUM));
6169 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006170 }
Geoff Langbfdea662014-07-23 14:16:32 -04006171
6172 if (!gl::ValidProgram(context, program))
6173 {
6174 return;
6175 }
6176
6177 gl::Program *programObject = context->getProgram(program);
6178 ASSERT(programObject);
6179
6180 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006181 }
6182}
6183
6184void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6185{
6186 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6187 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6188 program, index, bufSize, length, size, type, name);
6189
Geoff Langbfdea662014-07-23 14:16:32 -04006190 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006191 if (context)
6192 {
6193 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006194 {
Geoff Langb1196682014-07-23 13:47:29 -04006195 context->recordError(gl::Error(GL_INVALID_OPERATION));
6196 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006197 }
Geoff Langbfdea662014-07-23 14:16:32 -04006198
6199 if (bufSize < 0)
6200 {
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
6205 if (!gl::ValidProgram(context, program))
6206 {
6207 return;
6208 }
6209
6210 gl::Program *programObject = context->getProgram(program);
6211 ASSERT(programObject);
6212
6213 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6214 {
Geoff Langb1196682014-07-23 13:47:29 -04006215 context->recordError(gl::Error(GL_INVALID_VALUE));
6216 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006217 }
6218
6219 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006220 }
6221}
6222
6223void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6224{
6225 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6226 index, size, type, stride, pointer);
6227
Geoff Langbfdea662014-07-23 14:16:32 -04006228 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006229 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006230 {
Geoff Langbfdea662014-07-23 14:16:32 -04006231 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006232 {
Geoff Langb1196682014-07-23 13:47:29 -04006233 context->recordError(gl::Error(GL_INVALID_OPERATION));
6234 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006235 }
6236
Geoff Langb1196682014-07-23 13:47:29 -04006237 if (index >= gl::MAX_VERTEX_ATTRIBS)
6238 {
6239 context->recordError(gl::Error(GL_INVALID_VALUE));
6240 return;
6241 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006242
Geoff Langb1196682014-07-23 13:47:29 -04006243 if (size < 1 || size > 4)
6244 {
6245 context->recordError(gl::Error(GL_INVALID_VALUE));
6246 return;
6247 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006248
Geoff Langb1196682014-07-23 13:47:29 -04006249 switch (type)
6250 {
6251 case GL_BYTE:
6252 case GL_UNSIGNED_BYTE:
6253 case GL_SHORT:
6254 case GL_UNSIGNED_SHORT:
6255 case GL_INT:
6256 case GL_UNSIGNED_INT:
6257 case GL_INT_2_10_10_10_REV:
6258 case GL_UNSIGNED_INT_2_10_10_10_REV:
6259 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006260
Geoff Langb1196682014-07-23 13:47:29 -04006261 default:
6262 context->recordError(gl::Error(GL_INVALID_ENUM));
6263 return;
6264 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006265
Geoff Langb1196682014-07-23 13:47:29 -04006266 if (stride < 0)
6267 {
6268 context->recordError(gl::Error(GL_INVALID_VALUE));
6269 return;
6270 }
Geoff Langbfdea662014-07-23 14:16:32 -04006271
Geoff Langb1196682014-07-23 13:47:29 -04006272 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6273 {
6274 context->recordError(gl::Error(GL_INVALID_OPERATION));
6275 return;
6276 }
6277
Geoff Langbfdea662014-07-23 14:16:32 -04006278 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6279 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6280 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6281 // and the pointer argument is not NULL.
6282 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006283 {
Geoff Langb1196682014-07-23 13:47:29 -04006284 context->recordError(gl::Error(GL_INVALID_OPERATION));
6285 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006286 }
6287
Geoff Langbfdea662014-07-23 14:16:32 -04006288 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6289 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006290 }
6291}
6292
6293void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6294{
6295 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6296 index, pname, params);
6297
Geoff Langbfdea662014-07-23 14:16:32 -04006298 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006299 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006300 {
Geoff Langbfdea662014-07-23 14:16:32 -04006301 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006302 {
Geoff Langb1196682014-07-23 13:47:29 -04006303 context->recordError(gl::Error(GL_INVALID_OPERATION));
6304 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006305 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006306
Geoff Langbfdea662014-07-23 14:16:32 -04006307 if (index >= gl::MAX_VERTEX_ATTRIBS)
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 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006312
Geoff Langbfdea662014-07-23 14:16:32 -04006313 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006314
Geoff Langb1196682014-07-23 13:47:29 -04006315 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006316 {
6317 return;
6318 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006319
Geoff Langbfdea662014-07-23 14:16:32 -04006320 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6321 {
6322 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6323 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006324 {
Geoff Langbfdea662014-07-23 14:16:32 -04006325 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006326 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006327 }
Geoff Langbfdea662014-07-23 14:16:32 -04006328 else
6329 {
6330 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6331 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006332 }
6333}
6334
6335void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6336{
6337 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6338 index, pname, params);
6339
Geoff Langbfdea662014-07-23 14:16:32 -04006340 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006341 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006342 {
Geoff Langbfdea662014-07-23 14:16:32 -04006343 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006344 {
Geoff Langb1196682014-07-23 13:47:29 -04006345 context->recordError(gl::Error(GL_INVALID_OPERATION));
6346 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006347 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006348
Geoff Langbfdea662014-07-23 14:16:32 -04006349 if (index >= gl::MAX_VERTEX_ATTRIBS)
6350 {
Geoff Langb1196682014-07-23 13:47:29 -04006351 context->recordError(gl::Error(GL_INVALID_VALUE));
6352 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006353 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006354
Geoff Langbfdea662014-07-23 14:16:32 -04006355 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006356
Geoff Langb1196682014-07-23 13:47:29 -04006357 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006358 {
6359 return;
6360 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006361
Geoff Langbfdea662014-07-23 14:16:32 -04006362 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6363 {
6364 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6365 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006366 {
Geoff Langbfdea662014-07-23 14:16:32 -04006367 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006368 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006369 }
Geoff Langbfdea662014-07-23 14:16:32 -04006370 else
6371 {
6372 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6373 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006374 }
6375}
6376
6377void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6378{
6379 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6380 index, x, y, z, w);
6381
Geoff Langbfdea662014-07-23 14:16:32 -04006382 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006383 if (context)
6384 {
6385 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006386 {
Geoff Langb1196682014-07-23 13:47:29 -04006387 context->recordError(gl::Error(GL_INVALID_OPERATION));
6388 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006389 }
Geoff Langbfdea662014-07-23 14:16:32 -04006390
6391 if (index >= gl::MAX_VERTEX_ATTRIBS)
6392 {
Geoff Langb1196682014-07-23 13:47:29 -04006393 context->recordError(gl::Error(GL_INVALID_VALUE));
6394 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006395 }
6396
6397 GLint vals[4] = { x, y, z, w };
6398 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006399 }
6400}
6401
6402void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6403{
6404 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6405 index, x, y, z, w);
6406
Geoff Langbfdea662014-07-23 14:16:32 -04006407 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006408 if (context)
6409 {
6410 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006411 {
Geoff Langb1196682014-07-23 13:47:29 -04006412 context->recordError(gl::Error(GL_INVALID_OPERATION));
6413 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006414 }
Geoff Langbfdea662014-07-23 14:16:32 -04006415
6416 if (index >= gl::MAX_VERTEX_ATTRIBS)
6417 {
Geoff Langb1196682014-07-23 13:47:29 -04006418 context->recordError(gl::Error(GL_INVALID_VALUE));
6419 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006420 }
6421
6422 GLuint vals[4] = { x, y, z, w };
6423 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006424 }
6425}
6426
6427void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6428{
6429 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6430
Geoff Langbfdea662014-07-23 14:16:32 -04006431 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006432 if (context)
6433 {
6434 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006435 {
Geoff Langb1196682014-07-23 13:47:29 -04006436 context->recordError(gl::Error(GL_INVALID_OPERATION));
6437 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006438 }
Geoff Langbfdea662014-07-23 14:16:32 -04006439
6440 if (index >= gl::MAX_VERTEX_ATTRIBS)
6441 {
Geoff Langb1196682014-07-23 13:47:29 -04006442 context->recordError(gl::Error(GL_INVALID_VALUE));
6443 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006444 }
6445
6446 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006447 }
6448}
6449
6450void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6451{
6452 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6453
Geoff Langbfdea662014-07-23 14:16:32 -04006454 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006455 if (context)
6456 {
6457 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006458 {
Geoff Langb1196682014-07-23 13:47:29 -04006459 context->recordError(gl::Error(GL_INVALID_OPERATION));
6460 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006461 }
Geoff Langbfdea662014-07-23 14:16:32 -04006462
6463 if (index >= gl::MAX_VERTEX_ATTRIBS)
6464 {
Geoff Langb1196682014-07-23 13:47:29 -04006465 context->recordError(gl::Error(GL_INVALID_VALUE));
6466 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006467 }
6468
6469 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006470 }
6471}
6472
6473void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6474{
6475 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6476 program, location, params);
6477
Geoff Langbfdea662014-07-23 14:16:32 -04006478 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006479 if (context)
6480 {
Jamie Madill0063c512014-08-25 15:47:53 -04006481 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006482 {
Jamie Madill0063c512014-08-25 15:47:53 -04006483 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006484 }
Geoff Langbfdea662014-07-23 14:16:32 -04006485
Jamie Madilla502c742014-08-28 17:19:13 -04006486 gl::Program *programObject = context->getProgram(program);
6487 ASSERT(programObject);
6488 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006489 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006490
Jamie Madill99a1e982014-08-25 15:47:54 -04006491 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006492 }
6493}
6494
6495GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6496{
6497 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6498 program, name);
6499
Geoff Langbfdea662014-07-23 14:16:32 -04006500 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006501 if (context)
6502 {
6503 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006504 {
Geoff Langb1196682014-07-23 13:47:29 -04006505 context->recordError(gl::Error(GL_INVALID_OPERATION));
6506 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006507 }
Geoff Langbfdea662014-07-23 14:16:32 -04006508
6509 if (program == 0)
6510 {
Geoff Langb1196682014-07-23 13:47:29 -04006511 context->recordError(gl::Error(GL_INVALID_VALUE));
6512 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006513 }
6514
6515 gl::Program *programObject = context->getProgram(program);
6516
6517 if (!programObject || !programObject->isLinked())
6518 {
Geoff Langb1196682014-07-23 13:47:29 -04006519 context->recordError(gl::Error(GL_INVALID_OPERATION));
6520 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006521 }
6522
6523 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6524 if (!programBinary)
6525 {
Geoff Langb1196682014-07-23 13:47:29 -04006526 context->recordError(gl::Error(GL_INVALID_OPERATION));
6527 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006528 }
6529
6530 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006531 }
6532
6533 return 0;
6534}
6535
6536void __stdcall glUniform1ui(GLint location, GLuint v0)
6537{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006538 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006539}
6540
6541void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6542{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006543 const GLuint xy[] = { v0, v1 };
6544 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006545}
6546
6547void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6548{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006549 const GLuint xyz[] = { v0, v1, v2 };
6550 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006551}
6552
6553void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6554{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006555 const GLuint xyzw[] = { v0, v1, v2, v3 };
6556 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006557}
6558
6559void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6560{
6561 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6562 location, count, value);
6563
Geoff Langbfdea662014-07-23 14:16:32 -04006564 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006565 if (context)
6566 {
6567 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006568 {
Geoff Langbfdea662014-07-23 14:16:32 -04006569 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006570 }
Geoff Langbfdea662014-07-23 14:16:32 -04006571
6572 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6573 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006574 }
6575}
6576
6577void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6578{
6579 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6580 location, count, value);
6581
Geoff Langbfdea662014-07-23 14:16:32 -04006582 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006583 if (context)
6584 {
6585 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006586 {
Geoff Langbfdea662014-07-23 14:16:32 -04006587 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006588 }
Geoff Langbfdea662014-07-23 14:16:32 -04006589
6590 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6591 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006592 }
6593}
6594
6595void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6596{
6597 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6598 location, count, value);
6599
Geoff Langbfdea662014-07-23 14:16:32 -04006600 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006601 if (context)
6602 {
6603 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006604 {
Geoff Langbfdea662014-07-23 14:16:32 -04006605 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006606 }
Geoff Langbfdea662014-07-23 14:16:32 -04006607
6608 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6609 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006610 }
6611}
6612
6613void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6614{
6615 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6616 location, count, value);
6617
Geoff Langbfdea662014-07-23 14:16:32 -04006618 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006619 if (context)
6620 {
6621 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006622 {
Geoff Langbfdea662014-07-23 14:16:32 -04006623 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006624 }
Geoff Langbfdea662014-07-23 14:16:32 -04006625
6626 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6627 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006628 }
6629}
6630
6631void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6632{
6633 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6634 buffer, drawbuffer, value);
6635
Geoff Langbfdea662014-07-23 14:16:32 -04006636 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006637 if (context)
6638 {
6639 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006640 {
Geoff Langbfdea662014-07-23 14:16:32 -04006641 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006642 }
Geoff Langbfdea662014-07-23 14:16:32 -04006643
6644 switch (buffer)
6645 {
6646 case GL_COLOR:
6647 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6648 {
Geoff Langb1196682014-07-23 13:47:29 -04006649 context->recordError(gl::Error(GL_INVALID_VALUE));
6650 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006651 }
6652 break;
Geoff Langb1196682014-07-23 13:47:29 -04006653
Geoff Langbfdea662014-07-23 14:16:32 -04006654 case GL_STENCIL:
6655 if (drawbuffer != 0)
6656 {
Geoff Langb1196682014-07-23 13:47:29 -04006657 context->recordError(gl::Error(GL_INVALID_VALUE));
6658 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006659 }
6660 break;
Geoff Langb1196682014-07-23 13:47:29 -04006661
Geoff Langbfdea662014-07-23 14:16:32 -04006662 default:
Geoff Langb1196682014-07-23 13:47:29 -04006663 context->recordError(gl::Error(GL_INVALID_ENUM));
6664 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006665 }
6666
Geoff Langcc79b8c2014-07-25 13:48:02 -04006667 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6668 if (error.isError())
6669 {
6670 context->recordError(error);
6671 return;
6672 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006673 }
6674}
6675
6676void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6677{
6678 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6679 buffer, drawbuffer, value);
6680
Geoff Langbfdea662014-07-23 14:16:32 -04006681 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006682 if (context)
6683 {
6684 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006685 {
Geoff Langbfdea662014-07-23 14:16:32 -04006686 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006687 }
Geoff Langbfdea662014-07-23 14:16:32 -04006688
6689 switch (buffer)
6690 {
6691 case GL_COLOR:
6692 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6693 {
Geoff Langb1196682014-07-23 13:47:29 -04006694 context->recordError(gl::Error(GL_INVALID_VALUE));
6695 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006696 }
6697 break;
Geoff Langb1196682014-07-23 13:47:29 -04006698
Geoff Langbfdea662014-07-23 14:16:32 -04006699 default:
Geoff Langb1196682014-07-23 13:47:29 -04006700 context->recordError(gl::Error(GL_INVALID_ENUM));
6701 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006702 }
6703
Geoff Langcc79b8c2014-07-25 13:48:02 -04006704 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6705 if (error.isError())
6706 {
6707 context->recordError(error);
6708 return;
6709 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006710 }
6711}
6712
6713void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6714{
6715 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6716 buffer, drawbuffer, value);
6717
Geoff Langbfdea662014-07-23 14:16:32 -04006718 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006719 if (context)
6720 {
6721 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006722 {
Geoff Langbfdea662014-07-23 14:16:32 -04006723 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006724 }
Geoff Langbfdea662014-07-23 14:16:32 -04006725
6726 switch (buffer)
6727 {
6728 case GL_COLOR:
6729 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6730 {
Geoff Langb1196682014-07-23 13:47:29 -04006731 context->recordError(gl::Error(GL_INVALID_VALUE));
6732 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006733 }
6734 break;
Geoff Langb1196682014-07-23 13:47:29 -04006735
Geoff Langbfdea662014-07-23 14:16:32 -04006736 case GL_DEPTH:
6737 if (drawbuffer != 0)
6738 {
Geoff Langb1196682014-07-23 13:47:29 -04006739 context->recordError(gl::Error(GL_INVALID_VALUE));
6740 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006741 }
6742 break;
Geoff Langb1196682014-07-23 13:47:29 -04006743
Geoff Langbfdea662014-07-23 14:16:32 -04006744 default:
Geoff Langb1196682014-07-23 13:47:29 -04006745 context->recordError(gl::Error(GL_INVALID_ENUM));
6746 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006747 }
6748
Geoff Langcc79b8c2014-07-25 13:48:02 -04006749 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6750 if (error.isError())
6751 {
6752 context->recordError(error);
6753 return;
6754 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006755 }
6756}
6757
6758void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6759{
6760 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6761 buffer, drawbuffer, depth, stencil);
6762
Geoff Langbfdea662014-07-23 14:16:32 -04006763 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006764 if (context)
6765 {
6766 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006767 {
Geoff Langbfdea662014-07-23 14:16:32 -04006768 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006769 }
Geoff Langbfdea662014-07-23 14:16:32 -04006770
6771 switch (buffer)
6772 {
6773 case GL_DEPTH_STENCIL:
6774 if (drawbuffer != 0)
6775 {
Geoff Langb1196682014-07-23 13:47:29 -04006776 context->recordError(gl::Error(GL_INVALID_VALUE));
6777 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006778 }
6779 break;
Geoff Langb1196682014-07-23 13:47:29 -04006780
Geoff Langbfdea662014-07-23 14:16:32 -04006781 default:
Geoff Langb1196682014-07-23 13:47:29 -04006782 context->recordError(gl::Error(GL_INVALID_ENUM));
6783 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006784 }
6785
Geoff Langcc79b8c2014-07-25 13:48:02 -04006786 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6787 if (error.isError())
6788 {
6789 context->recordError(error);
6790 return;
6791 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006792 }
6793}
6794
6795const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6796{
6797 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6798
Geoff Langbfdea662014-07-23 14:16:32 -04006799 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006800 if (context)
6801 {
6802 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006803 {
Geoff Langb1196682014-07-23 13:47:29 -04006804 context->recordError(gl::Error(GL_INVALID_OPERATION));
6805 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006806 }
Geoff Langbfdea662014-07-23 14:16:32 -04006807
6808 if (name != GL_EXTENSIONS)
6809 {
Geoff Langb1196682014-07-23 13:47:29 -04006810 context->recordError(gl::Error(GL_INVALID_ENUM));
6811 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006812 }
6813
6814 if (index >= context->getExtensionStringCount())
6815 {
Geoff Langb1196682014-07-23 13:47:29 -04006816 context->recordError(gl::Error(GL_INVALID_VALUE));
6817 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006818 }
6819
6820 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006821 }
6822
6823 return NULL;
6824}
6825
6826void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6827{
6828 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6829 readTarget, writeTarget, readOffset, writeOffset, size);
6830
Geoff Langbfdea662014-07-23 14:16:32 -04006831 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006832 if (context)
6833 {
6834 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006835 {
Geoff Langb1196682014-07-23 13:47:29 -04006836 context->recordError(gl::Error(GL_INVALID_OPERATION));
6837 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006838 }
Geoff Langbfdea662014-07-23 14:16:32 -04006839
6840 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6841 {
Geoff Langb1196682014-07-23 13:47:29 -04006842 context->recordError(gl::Error(GL_INVALID_ENUM));
6843 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006844 }
6845
6846 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6847 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6848
6849 if (!readBuffer || !writeBuffer)
6850 {
Geoff Langb1196682014-07-23 13:47:29 -04006851 context->recordError(gl::Error(GL_INVALID_OPERATION));
6852 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006853 }
6854
Jamie Madillcfaaf722014-07-31 10:47:54 -04006855 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006856 if (readBuffer->isMapped() || writeBuffer->isMapped())
6857 {
Geoff Langb1196682014-07-23 13:47:29 -04006858 context->recordError(gl::Error(GL_INVALID_OPERATION));
6859 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006860 }
6861
6862 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6863 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6864 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6865 {
Geoff Langb1196682014-07-23 13:47:29 -04006866 context->recordError(gl::Error(GL_INVALID_VALUE));
6867 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006868 }
6869
6870 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6871 {
Geoff Langb1196682014-07-23 13:47:29 -04006872 context->recordError(gl::Error(GL_INVALID_VALUE));
6873 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006874 }
6875
Geoff Langbfdea662014-07-23 14:16:32 -04006876 // if size is zero, the copy is a successful no-op
6877 if (size > 0)
6878 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006879 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6880 if (error.isError())
6881 {
6882 context->recordError(error);
6883 return;
6884 }
Geoff Langbfdea662014-07-23 14:16:32 -04006885 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006886 }
6887}
6888
6889void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6890{
6891 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6892 program, uniformCount, uniformNames, uniformIndices);
6893
Geoff Langbfdea662014-07-23 14:16:32 -04006894 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006895 if (context)
6896 {
6897 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006898 {
Geoff Langb1196682014-07-23 13:47:29 -04006899 context->recordError(gl::Error(GL_INVALID_OPERATION));
6900 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006901 }
6902
6903 if (uniformCount < 0)
6904 {
Geoff Langb1196682014-07-23 13:47:29 -04006905 context->recordError(gl::Error(GL_INVALID_VALUE));
6906 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006907 }
6908
6909 gl::Program *programObject = context->getProgram(program);
6910
6911 if (!programObject)
6912 {
6913 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006914 {
Geoff Langb1196682014-07-23 13:47:29 -04006915 context->recordError(gl::Error(GL_INVALID_OPERATION));
6916 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006917 }
Geoff Langbfdea662014-07-23 14:16:32 -04006918 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006919 {
Geoff Langb1196682014-07-23 13:47:29 -04006920 context->recordError(gl::Error(GL_INVALID_VALUE));
6921 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006922 }
Geoff Langbfdea662014-07-23 14:16:32 -04006923 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006924
Geoff Langbfdea662014-07-23 14:16:32 -04006925 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6926 if (!programObject->isLinked() || !programBinary)
6927 {
6928 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006929 {
Geoff Langbfdea662014-07-23 14:16:32 -04006930 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006931 }
6932 }
Geoff Langbfdea662014-07-23 14:16:32 -04006933 else
6934 {
6935 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6936 {
6937 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6938 }
6939 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006940 }
6941}
6942
6943void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6944{
6945 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6946 program, uniformCount, uniformIndices, pname, params);
6947
Geoff Langbfdea662014-07-23 14:16:32 -04006948 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006949 if (context)
6950 {
6951 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006952 {
Geoff Langb1196682014-07-23 13:47:29 -04006953 context->recordError(gl::Error(GL_INVALID_OPERATION));
6954 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006955 }
6956
6957 if (uniformCount < 0)
6958 {
Geoff Langb1196682014-07-23 13:47:29 -04006959 context->recordError(gl::Error(GL_INVALID_VALUE));
6960 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006961 }
6962
6963 gl::Program *programObject = context->getProgram(program);
6964
6965 if (!programObject)
6966 {
6967 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006968 {
Geoff Langb1196682014-07-23 13:47:29 -04006969 context->recordError(gl::Error(GL_INVALID_OPERATION));
6970 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006971 }
Geoff Langbfdea662014-07-23 14:16:32 -04006972 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006973 {
Geoff Langb1196682014-07-23 13:47:29 -04006974 context->recordError(gl::Error(GL_INVALID_VALUE));
6975 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006976 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006977 }
Geoff Langbfdea662014-07-23 14:16:32 -04006978
6979 switch (pname)
6980 {
6981 case GL_UNIFORM_TYPE:
6982 case GL_UNIFORM_SIZE:
6983 case GL_UNIFORM_NAME_LENGTH:
6984 case GL_UNIFORM_BLOCK_INDEX:
6985 case GL_UNIFORM_OFFSET:
6986 case GL_UNIFORM_ARRAY_STRIDE:
6987 case GL_UNIFORM_MATRIX_STRIDE:
6988 case GL_UNIFORM_IS_ROW_MAJOR:
6989 break;
Geoff Langb1196682014-07-23 13:47:29 -04006990
Geoff Langbfdea662014-07-23 14:16:32 -04006991 default:
Geoff Langb1196682014-07-23 13:47:29 -04006992 context->recordError(gl::Error(GL_INVALID_ENUM));
6993 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006994 }
6995
6996 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6997
6998 if (!programBinary && uniformCount > 0)
6999 {
Geoff Langb1196682014-07-23 13:47:29 -04007000 context->recordError(gl::Error(GL_INVALID_VALUE));
7001 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007002 }
7003
7004 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7005 {
7006 const GLuint index = uniformIndices[uniformId];
7007
7008 if (index >= (GLuint)programBinary->getActiveUniformCount())
7009 {
Geoff Langb1196682014-07-23 13:47:29 -04007010 context->recordError(gl::Error(GL_INVALID_VALUE));
7011 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007012 }
7013 }
7014
7015 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7016 {
7017 const GLuint index = uniformIndices[uniformId];
7018 params[uniformId] = programBinary->getActiveUniformi(index, pname);
7019 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007020 }
7021}
7022
7023GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
7024{
7025 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
7026
Geoff Langbfdea662014-07-23 14:16:32 -04007027 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007028 if (context)
7029 {
7030 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007031 {
Geoff Langb1196682014-07-23 13:47:29 -04007032 context->recordError(gl::Error(GL_INVALID_OPERATION));
7033 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04007034 }
7035
7036 gl::Program *programObject = context->getProgram(program);
7037
7038 if (!programObject)
7039 {
7040 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007041 {
Geoff Langb1196682014-07-23 13:47:29 -04007042 context->recordError(gl::Error(GL_INVALID_OPERATION));
7043 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007044 }
Geoff Langbfdea662014-07-23 14:16:32 -04007045 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007046 {
Geoff Langb1196682014-07-23 13:47:29 -04007047 context->recordError(gl::Error(GL_INVALID_VALUE));
7048 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007049 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007050 }
Geoff Langbfdea662014-07-23 14:16:32 -04007051
7052 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7053 if (!programBinary)
7054 {
7055 return GL_INVALID_INDEX;
7056 }
7057
7058 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007059 }
7060
7061 return 0;
7062}
7063
7064void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
7065{
7066 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7067 program, uniformBlockIndex, pname, params);
7068
Geoff Langbfdea662014-07-23 14:16:32 -04007069 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007070 if (context)
7071 {
7072 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007073 {
Geoff Langb1196682014-07-23 13:47:29 -04007074 context->recordError(gl::Error(GL_INVALID_OPERATION));
7075 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007076 }
7077 gl::Program *programObject = context->getProgram(program);
7078
7079 if (!programObject)
7080 {
7081 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007082 {
Geoff Langb1196682014-07-23 13:47:29 -04007083 context->recordError(gl::Error(GL_INVALID_OPERATION));
7084 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007085 }
Geoff Langbfdea662014-07-23 14:16:32 -04007086 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007087 {
Geoff Langb1196682014-07-23 13:47:29 -04007088 context->recordError(gl::Error(GL_INVALID_VALUE));
7089 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007090 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007091 }
Geoff Langbfdea662014-07-23 14:16:32 -04007092
7093 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7094
7095 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7096 {
Geoff Langb1196682014-07-23 13:47:29 -04007097 context->recordError(gl::Error(GL_INVALID_VALUE));
7098 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007099 }
7100
7101 switch (pname)
7102 {
7103 case GL_UNIFORM_BLOCK_BINDING:
7104 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7105 break;
7106
7107 case GL_UNIFORM_BLOCK_DATA_SIZE:
7108 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7109 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7110 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7111 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7112 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7113 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7114 break;
7115
7116 default:
Geoff Langb1196682014-07-23 13:47:29 -04007117 context->recordError(gl::Error(GL_INVALID_ENUM));
7118 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007119 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007120 }
7121}
7122
7123void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7124{
7125 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7126 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7127
Geoff Langbfdea662014-07-23 14:16:32 -04007128 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007129 if (context)
7130 {
7131 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007132 {
Geoff Langb1196682014-07-23 13:47:29 -04007133 context->recordError(gl::Error(GL_INVALID_OPERATION));
7134 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007135 }
7136
7137 gl::Program *programObject = context->getProgram(program);
7138
7139 if (!programObject)
7140 {
7141 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007142 {
Geoff Langb1196682014-07-23 13:47:29 -04007143 context->recordError(gl::Error(GL_INVALID_OPERATION));
7144 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007145 }
Geoff Langbfdea662014-07-23 14:16:32 -04007146 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007147 {
Geoff Langb1196682014-07-23 13:47:29 -04007148 context->recordError(gl::Error(GL_INVALID_VALUE));
7149 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007150 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007151 }
Geoff Langbfdea662014-07-23 14:16:32 -04007152
7153 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7154
7155 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7156 {
Geoff Langb1196682014-07-23 13:47:29 -04007157 context->recordError(gl::Error(GL_INVALID_VALUE));
7158 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007159 }
7160
7161 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007162 }
7163}
7164
7165void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7166{
7167 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7168 program, uniformBlockIndex, uniformBlockBinding);
7169
Geoff Langbfdea662014-07-23 14:16:32 -04007170 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007171 if (context)
7172 {
7173 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007174 {
Geoff Langb1196682014-07-23 13:47:29 -04007175 context->recordError(gl::Error(GL_INVALID_OPERATION));
7176 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007177 }
7178
Geoff Lang3a61c322014-07-10 13:01:54 -04007179 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007180 {
Geoff Langb1196682014-07-23 13:47:29 -04007181 context->recordError(gl::Error(GL_INVALID_VALUE));
7182 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007183 }
7184
7185 gl::Program *programObject = context->getProgram(program);
7186
7187 if (!programObject)
7188 {
7189 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007190 {
Geoff Langb1196682014-07-23 13:47:29 -04007191 context->recordError(gl::Error(GL_INVALID_OPERATION));
7192 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007193 }
Geoff Langbfdea662014-07-23 14:16:32 -04007194 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007195 {
Geoff Langb1196682014-07-23 13:47:29 -04007196 context->recordError(gl::Error(GL_INVALID_VALUE));
7197 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007198 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007199 }
Geoff Langbfdea662014-07-23 14:16:32 -04007200
7201 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7202
7203 // if never linked, there won't be any uniform blocks
7204 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7205 {
Geoff Langb1196682014-07-23 13:47:29 -04007206 context->recordError(gl::Error(GL_INVALID_VALUE));
7207 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007208 }
7209
7210 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007211 }
7212}
7213
7214void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7215{
7216 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7217 mode, first, count, instanceCount);
7218
Geoff Langbfdea662014-07-23 14:16:32 -04007219 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007220 if (context)
7221 {
7222 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007223 {
Geoff Langb1196682014-07-23 13:47:29 -04007224 context->recordError(gl::Error(GL_INVALID_OPERATION));
7225 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007226 }
Geoff Langbfdea662014-07-23 14:16:32 -04007227
7228 // glDrawArraysInstanced
7229 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007230 }
7231}
7232
7233void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7234{
7235 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7236 mode, count, type, indices, instanceCount);
7237
Geoff Langbfdea662014-07-23 14:16:32 -04007238 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007239 if (context)
7240 {
7241 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007242 {
Geoff Langb1196682014-07-23 13:47:29 -04007243 context->recordError(gl::Error(GL_INVALID_OPERATION));
7244 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007245 }
Geoff Langbfdea662014-07-23 14:16:32 -04007246
7247 // glDrawElementsInstanced
7248 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007249 }
7250}
7251
7252GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7253{
7254 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7255
Geoff Langbfdea662014-07-23 14:16:32 -04007256 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007257 if (context)
7258 {
7259 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007260 {
Geoff Langb1196682014-07-23 13:47:29 -04007261 context->recordError(gl::Error(GL_INVALID_OPERATION));
7262 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007263 }
Geoff Langbfdea662014-07-23 14:16:32 -04007264
7265 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7266 {
Geoff Langb1196682014-07-23 13:47:29 -04007267 context->recordError(gl::Error(GL_INVALID_ENUM));
7268 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007269 }
7270
7271 if (flags != 0)
7272 {
Geoff Langb1196682014-07-23 13:47:29 -04007273 context->recordError(gl::Error(GL_INVALID_VALUE));
7274 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007275 }
7276
7277 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007278 }
7279
7280 return NULL;
7281}
7282
7283GLboolean __stdcall glIsSync(GLsync sync)
7284{
7285 EVENT("(GLsync sync = 0x%0.8p)", sync);
7286
Geoff Langbfdea662014-07-23 14:16:32 -04007287 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007288 if (context)
7289 {
7290 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007291 {
Geoff Langb1196682014-07-23 13:47:29 -04007292 context->recordError(gl::Error(GL_INVALID_OPERATION));
7293 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007294 }
Geoff Langbfdea662014-07-23 14:16:32 -04007295
7296 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007297 }
7298
7299 return GL_FALSE;
7300}
7301
7302void __stdcall glDeleteSync(GLsync sync)
7303{
7304 EVENT("(GLsync sync = 0x%0.8p)", sync);
7305
Geoff Langbfdea662014-07-23 14:16:32 -04007306 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007307 if (context)
7308 {
7309 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007310 {
Geoff Langb1196682014-07-23 13:47:29 -04007311 context->recordError(gl::Error(GL_INVALID_OPERATION));
7312 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007313 }
Geoff Langbfdea662014-07-23 14:16:32 -04007314
7315 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7316 {
Geoff Langb1196682014-07-23 13:47:29 -04007317 context->recordError(gl::Error(GL_INVALID_VALUE));
7318 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007319 }
7320
7321 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007322 }
7323}
7324
7325GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7326{
7327 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7328 sync, flags, timeout);
7329
Geoff Langbfdea662014-07-23 14:16:32 -04007330 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007331 if (context)
7332 {
7333 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007334 {
Geoff Langb1196682014-07-23 13:47:29 -04007335 context->recordError(gl::Error(GL_INVALID_OPERATION));
7336 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007337 }
Geoff Langbfdea662014-07-23 14:16:32 -04007338
7339 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7340 {
Geoff Langb1196682014-07-23 13:47:29 -04007341 context->recordError(gl::Error(GL_INVALID_VALUE));
7342 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007343 }
7344
7345 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7346
7347 if (!fenceSync)
7348 {
Geoff Langb1196682014-07-23 13:47:29 -04007349 context->recordError(gl::Error(GL_INVALID_VALUE));
7350 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007351 }
7352
7353 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007354 }
7355
7356 return GL_FALSE;
7357}
7358
7359void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7360{
7361 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7362 sync, flags, timeout);
7363
Geoff Langbfdea662014-07-23 14:16:32 -04007364 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007365 if (context)
7366 {
7367 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007368 {
Geoff Langb1196682014-07-23 13:47:29 -04007369 context->recordError(gl::Error(GL_INVALID_OPERATION));
7370 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007371 }
Geoff Langbfdea662014-07-23 14:16:32 -04007372
7373 if (flags != 0)
7374 {
Geoff Langb1196682014-07-23 13:47:29 -04007375 context->recordError(gl::Error(GL_INVALID_VALUE));
7376 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007377 }
7378
7379 if (timeout != GL_TIMEOUT_IGNORED)
7380 {
Geoff Langb1196682014-07-23 13:47:29 -04007381 context->recordError(gl::Error(GL_INVALID_VALUE));
7382 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007383 }
7384
7385 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7386
7387 if (!fenceSync)
7388 {
Geoff Langb1196682014-07-23 13:47:29 -04007389 context->recordError(gl::Error(GL_INVALID_VALUE));
7390 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007391 }
7392
7393 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007394 }
7395}
7396
7397void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7398{
7399 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7400 pname, params);
7401
Geoff Langbfdea662014-07-23 14:16:32 -04007402 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007403 if (context)
7404 {
7405 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007406 {
Geoff Langb1196682014-07-23 13:47:29 -04007407 context->recordError(gl::Error(GL_INVALID_OPERATION));
7408 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007409 }
Geoff Langbfdea662014-07-23 14:16:32 -04007410
7411 GLenum nativeType;
7412 unsigned int numParams = 0;
7413 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7414 {
7415 return;
7416 }
7417
7418 if (nativeType == GL_INT_64_ANGLEX)
7419 {
7420 context->getInteger64v(pname, params);
7421 }
7422 else
7423 {
7424 CastStateValues(context, nativeType, pname, numParams, params);
7425 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007426 }
7427}
7428
7429void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7430{
7431 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7432 sync, pname, bufSize, length, values);
7433
Geoff Langbfdea662014-07-23 14:16:32 -04007434 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007435 if (context)
7436 {
7437 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007438 {
Geoff Langb1196682014-07-23 13:47:29 -04007439 context->recordError(gl::Error(GL_INVALID_OPERATION));
7440 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007441 }
Geoff Langbfdea662014-07-23 14:16:32 -04007442
7443 if (bufSize < 0)
7444 {
Geoff Langb1196682014-07-23 13:47:29 -04007445 context->recordError(gl::Error(GL_INVALID_VALUE));
7446 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007447 }
7448
7449 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7450
7451 if (!fenceSync)
7452 {
Geoff Langb1196682014-07-23 13:47:29 -04007453 context->recordError(gl::Error(GL_INVALID_VALUE));
7454 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007455 }
7456
7457 switch (pname)
7458 {
7459 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7460 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7461 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7462 case GL_SYNC_FLAGS: values[0] = 0; break;
7463
7464 default:
Geoff Langb1196682014-07-23 13:47:29 -04007465 context->recordError(gl::Error(GL_INVALID_ENUM));
7466 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007467 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007468 }
7469}
7470
7471void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7472{
7473 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7474 target, index, data);
7475
Geoff Langbfdea662014-07-23 14:16:32 -04007476 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007477 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007478 {
Geoff Langbfdea662014-07-23 14:16:32 -04007479 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007480 {
Geoff Langb1196682014-07-23 13:47:29 -04007481 context->recordError(gl::Error(GL_INVALID_OPERATION));
7482 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007483 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007484
Geoff Lang3a61c322014-07-10 13:01:54 -04007485 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007486 switch (target)
7487 {
7488 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7489 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7490 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007491 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7492 {
Geoff Langb1196682014-07-23 13:47:29 -04007493 context->recordError(gl::Error(GL_INVALID_VALUE));
7494 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007495 }
Geoff Langbfdea662014-07-23 14:16:32 -04007496 break;
Geoff Langb1196682014-07-23 13:47:29 -04007497
Geoff Langbfdea662014-07-23 14:16:32 -04007498 case GL_UNIFORM_BUFFER_START:
7499 case GL_UNIFORM_BUFFER_SIZE:
7500 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007501 if (index >= caps.maxUniformBufferBindings)
7502 {
Geoff Langb1196682014-07-23 13:47:29 -04007503 context->recordError(gl::Error(GL_INVALID_VALUE));
7504 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007505 }
Geoff Langbfdea662014-07-23 14:16:32 -04007506 break;
Geoff Langb1196682014-07-23 13:47:29 -04007507
Geoff Langbfdea662014-07-23 14:16:32 -04007508 default:
Geoff Langb1196682014-07-23 13:47:29 -04007509 context->recordError(gl::Error(GL_INVALID_ENUM));
7510 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007511 }
7512
7513 if (!(context->getIndexedInteger64v(target, index, data)))
7514 {
7515 GLenum nativeType;
7516 unsigned int numParams = 0;
7517 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007518 {
7519 context->recordError(gl::Error(GL_INVALID_ENUM));
7520 return;
7521 }
Shannon Woods15934d52013-08-19 14:28:49 -04007522
Geoff Langbfdea662014-07-23 14:16:32 -04007523 if (numParams == 0)
7524 return; // it is known that pname is valid, but there are no parameters to return
7525
7526 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007527 {
Geoff Langbfdea662014-07-23 14:16:32 -04007528 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007529
Geoff Langbfdea662014-07-23 14:16:32 -04007530 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007531
Geoff Langbfdea662014-07-23 14:16:32 -04007532 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007533 {
Geoff Langbfdea662014-07-23 14:16:32 -04007534 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007535 }
Geoff Langbfdea662014-07-23 14:16:32 -04007536
7537 delete [] intParams;
7538 }
7539 else
7540 {
7541 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007542 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007543 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007544 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007545}
7546
7547void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7548{
7549 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7550 target, pname, params);
7551
Geoff Langbfdea662014-07-23 14:16:32 -04007552 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007553 if (context)
7554 {
7555 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007556 {
Geoff Langb1196682014-07-23 13:47:29 -04007557 context->recordError(gl::Error(GL_INVALID_OPERATION));
7558 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007559 }
Geoff Langbfdea662014-07-23 14:16:32 -04007560
7561 if (!gl::ValidBufferTarget(context, target))
7562 {
Geoff Langb1196682014-07-23 13:47:29 -04007563 context->recordError(gl::Error(GL_INVALID_ENUM));
7564 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007565 }
7566
7567 if (!gl::ValidBufferParameter(context, pname))
7568 {
Geoff Langb1196682014-07-23 13:47:29 -04007569 context->recordError(gl::Error(GL_INVALID_ENUM));
7570 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007571 }
7572
7573 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7574
7575 if (!buffer)
7576 {
7577 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007578 context->recordError(gl::Error(GL_INVALID_OPERATION));
7579 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007580 }
7581
7582 switch (pname)
7583 {
7584 case GL_BUFFER_USAGE:
7585 *params = static_cast<GLint64>(buffer->getUsage());
7586 break;
7587 case GL_BUFFER_SIZE:
7588 *params = buffer->getSize();
7589 break;
7590 case GL_BUFFER_ACCESS_FLAGS:
7591 *params = static_cast<GLint64>(buffer->getAccessFlags());
7592 break;
7593 case GL_BUFFER_MAPPED:
7594 *params = static_cast<GLint64>(buffer->isMapped());
7595 break;
7596 case GL_BUFFER_MAP_OFFSET:
7597 *params = buffer->getMapOffset();
7598 break;
7599 case GL_BUFFER_MAP_LENGTH:
7600 *params = buffer->getMapLength();
7601 break;
7602 default: UNREACHABLE(); break;
7603 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007604 }
7605}
7606
7607void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7608{
7609 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7610
Geoff Langbfdea662014-07-23 14:16:32 -04007611 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007612 if (context)
7613 {
7614 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007615 {
Geoff Langb1196682014-07-23 13:47:29 -04007616 context->recordError(gl::Error(GL_INVALID_OPERATION));
7617 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007618 }
Geoff Langbfdea662014-07-23 14:16:32 -04007619
7620 if (count < 0)
7621 {
Geoff Langb1196682014-07-23 13:47:29 -04007622 context->recordError(gl::Error(GL_INVALID_VALUE));
7623 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007624 }
7625
7626 for (int i = 0; i < count; i++)
7627 {
7628 samplers[i] = context->createSampler();
7629 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007630 }
7631}
7632
7633void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7634{
7635 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7636
Geoff Langbfdea662014-07-23 14:16:32 -04007637 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007638 if (context)
7639 {
7640 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007641 {
Geoff Langb1196682014-07-23 13:47:29 -04007642 context->recordError(gl::Error(GL_INVALID_OPERATION));
7643 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007644 }
Geoff Langbfdea662014-07-23 14:16:32 -04007645
7646 if (count < 0)
7647 {
Geoff Langb1196682014-07-23 13:47:29 -04007648 context->recordError(gl::Error(GL_INVALID_VALUE));
7649 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007650 }
7651
7652 for (int i = 0; i < count; i++)
7653 {
7654 context->deleteSampler(samplers[i]);
7655 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007656 }
7657}
7658
7659GLboolean __stdcall glIsSampler(GLuint sampler)
7660{
7661 EVENT("(GLuint sampler = %u)", sampler);
7662
Geoff Langbfdea662014-07-23 14:16:32 -04007663 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007664 if (context)
7665 {
7666 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007667 {
Geoff Langb1196682014-07-23 13:47:29 -04007668 context->recordError(gl::Error(GL_INVALID_OPERATION));
7669 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007670 }
Geoff Langbfdea662014-07-23 14:16:32 -04007671
7672 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007673 }
7674
7675 return GL_FALSE;
7676}
7677
7678void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7679{
7680 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7681
Geoff Langbfdea662014-07-23 14:16:32 -04007682 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007683 if (context)
7684 {
7685 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007686 {
Geoff Langb1196682014-07-23 13:47:29 -04007687 context->recordError(gl::Error(GL_INVALID_OPERATION));
7688 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007689 }
Geoff Langbfdea662014-07-23 14:16:32 -04007690
7691 if (sampler != 0 && !context->isSampler(sampler))
7692 {
Geoff Langb1196682014-07-23 13:47:29 -04007693 context->recordError(gl::Error(GL_INVALID_OPERATION));
7694 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007695 }
7696
Geoff Lang3a61c322014-07-10 13:01:54 -04007697 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007698 {
Geoff Langb1196682014-07-23 13:47:29 -04007699 context->recordError(gl::Error(GL_INVALID_VALUE));
7700 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007701 }
7702
7703 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007704 }
7705}
7706
7707void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7708{
7709 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7710
Geoff Langbfdea662014-07-23 14:16:32 -04007711 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007712 if (context)
7713 {
7714 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007715 {
Geoff Langb1196682014-07-23 13:47:29 -04007716 context->recordError(gl::Error(GL_INVALID_OPERATION));
7717 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007718 }
Geoff Langbfdea662014-07-23 14:16:32 -04007719
Geoff Langb1196682014-07-23 13:47:29 -04007720 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007721 {
7722 return;
7723 }
7724
7725 if (!gl::ValidateTexParamParameters(context, pname, param))
7726 {
7727 return;
7728 }
7729
7730 if (!context->isSampler(sampler))
7731 {
Geoff Langb1196682014-07-23 13:47:29 -04007732 context->recordError(gl::Error(GL_INVALID_OPERATION));
7733 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007734 }
7735
7736 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007737 }
7738}
7739
7740void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7741{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007742 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007743}
7744
7745void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7746{
7747 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7748
Geoff Langbfdea662014-07-23 14:16:32 -04007749 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007750 if (context)
7751 {
7752 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007753 {
Geoff Langb1196682014-07-23 13:47:29 -04007754 context->recordError(gl::Error(GL_INVALID_OPERATION));
7755 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007756 }
Geoff Langbfdea662014-07-23 14:16:32 -04007757
Geoff Langb1196682014-07-23 13:47:29 -04007758 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007759 {
7760 return;
7761 }
7762
7763 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7764 {
7765 return;
7766 }
7767
7768 if (!context->isSampler(sampler))
7769 {
Geoff Langb1196682014-07-23 13:47:29 -04007770 context->recordError(gl::Error(GL_INVALID_OPERATION));
7771 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007772 }
7773
7774 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007775 }
7776}
7777
7778void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7779{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007780 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007781}
7782
7783void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7784{
7785 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7786
Geoff Langbfdea662014-07-23 14:16:32 -04007787 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007788 if (context)
7789 {
7790 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007791 {
Geoff Langb1196682014-07-23 13:47:29 -04007792 context->recordError(gl::Error(GL_INVALID_OPERATION));
7793 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007794 }
Geoff Langbfdea662014-07-23 14:16:32 -04007795
Geoff Langb1196682014-07-23 13:47:29 -04007796 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007797 {
7798 return;
7799 }
7800
7801 if (!context->isSampler(sampler))
7802 {
Geoff Langb1196682014-07-23 13:47:29 -04007803 context->recordError(gl::Error(GL_INVALID_OPERATION));
7804 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007805 }
7806
7807 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007808 }
7809}
7810
7811void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7812{
7813 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7814
Geoff Langbfdea662014-07-23 14:16:32 -04007815 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007816 if (context)
7817 {
7818 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007819 {
Geoff Langb1196682014-07-23 13:47:29 -04007820 context->recordError(gl::Error(GL_INVALID_OPERATION));
7821 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007822 }
Geoff Langbfdea662014-07-23 14:16:32 -04007823
Geoff Langb1196682014-07-23 13:47:29 -04007824 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007825 {
7826 return;
7827 }
7828
7829 if (!context->isSampler(sampler))
7830 {
Geoff Langb1196682014-07-23 13:47:29 -04007831 context->recordError(gl::Error(GL_INVALID_OPERATION));
7832 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007833 }
7834
7835 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007836 }
7837}
7838
7839void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7840{
7841 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7842
Geoff Langbfdea662014-07-23 14:16:32 -04007843 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007844 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007845 {
Geoff Langbfdea662014-07-23 14:16:32 -04007846 if (context->getClientVersion() < 3)
7847 {
Geoff Langb1196682014-07-23 13:47:29 -04007848 context->recordError(gl::Error(GL_INVALID_OPERATION));
7849 return;
7850 }
7851
7852 if (index >= gl::MAX_VERTEX_ATTRIBS)
7853 {
7854 context->recordError(gl::Error(GL_INVALID_VALUE));
7855 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007856 }
7857
7858 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007859 }
7860}
7861
7862void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7863{
7864 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7865
Geoff Langbfdea662014-07-23 14:16:32 -04007866 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007867 if (context)
7868 {
7869 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007870 {
Geoff Langb1196682014-07-23 13:47:29 -04007871 context->recordError(gl::Error(GL_INVALID_OPERATION));
7872 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007873 }
Geoff Langbfdea662014-07-23 14:16:32 -04007874
7875 switch (target)
7876 {
7877 case GL_TRANSFORM_FEEDBACK:
7878 {
7879 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7880 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7881 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7882 {
Geoff Langb1196682014-07-23 13:47:29 -04007883 context->recordError(gl::Error(GL_INVALID_OPERATION));
7884 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007885 }
7886
7887 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7888 if (context->getTransformFeedback(id) == NULL)
7889 {
Geoff Langb1196682014-07-23 13:47:29 -04007890 context->recordError(gl::Error(GL_INVALID_OPERATION));
7891 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007892 }
7893
7894 context->bindTransformFeedback(id);
7895 }
7896 break;
7897
7898 default:
Geoff Langb1196682014-07-23 13:47:29 -04007899 context->recordError(gl::Error(GL_INVALID_ENUM));
7900 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007901 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007902 }
7903}
7904
7905void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7906{
7907 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7908
Geoff Langbfdea662014-07-23 14:16:32 -04007909 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007910 if (context)
7911 {
7912 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007913 {
Geoff Langb1196682014-07-23 13:47:29 -04007914 context->recordError(gl::Error(GL_INVALID_OPERATION));
7915 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007916 }
Geoff Langbfdea662014-07-23 14:16:32 -04007917
7918 for (int i = 0; i < n; i++)
7919 {
7920 context->deleteTransformFeedback(ids[i]);
7921 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007922 }
7923}
7924
7925void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7926{
7927 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7928
Geoff Langbfdea662014-07-23 14:16:32 -04007929 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007930 if (context)
7931 {
7932 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007933 {
Geoff Langb1196682014-07-23 13:47:29 -04007934 context->recordError(gl::Error(GL_INVALID_OPERATION));
7935 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007936 }
Geoff Langbfdea662014-07-23 14:16:32 -04007937
7938 for (int i = 0; i < n; i++)
7939 {
7940 ids[i] = context->createTransformFeedback();
7941 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007942 }
7943}
7944
7945GLboolean __stdcall glIsTransformFeedback(GLuint id)
7946{
7947 EVENT("(GLuint id = %u)", id);
7948
Geoff Langbfdea662014-07-23 14:16:32 -04007949 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007950 if (context)
7951 {
7952 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007953 {
Geoff Langb1196682014-07-23 13:47:29 -04007954 context->recordError(gl::Error(GL_INVALID_OPERATION));
7955 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007956 }
Geoff Langbfdea662014-07-23 14:16:32 -04007957
7958 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007959 }
7960
7961 return GL_FALSE;
7962}
7963
7964void __stdcall glPauseTransformFeedback(void)
7965{
7966 EVENT("(void)");
7967
Geoff Langbfdea662014-07-23 14:16:32 -04007968 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007969 if (context)
7970 {
7971 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007972 {
Geoff Langb1196682014-07-23 13:47:29 -04007973 context->recordError(gl::Error(GL_INVALID_OPERATION));
7974 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007975 }
Geoff Langbfdea662014-07-23 14:16:32 -04007976
7977 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7978 ASSERT(transformFeedback != NULL);
7979
7980 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7981 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7982 {
Geoff Langb1196682014-07-23 13:47:29 -04007983 context->recordError(gl::Error(GL_INVALID_OPERATION));
7984 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007985 }
7986
7987 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007988 }
7989}
7990
7991void __stdcall glResumeTransformFeedback(void)
7992{
7993 EVENT("(void)");
7994
Geoff Langbfdea662014-07-23 14:16:32 -04007995 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007996 if (context)
7997 {
7998 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007999 {
Geoff Langb1196682014-07-23 13:47:29 -04008000 context->recordError(gl::Error(GL_INVALID_OPERATION));
8001 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008002 }
Geoff Langbfdea662014-07-23 14:16:32 -04008003
8004 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8005 ASSERT(transformFeedback != NULL);
8006
8007 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
8008 if (!transformFeedback->isStarted() || !transformFeedback->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 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008015 }
8016}
8017
8018void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
8019{
8020 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
8021 program, bufSize, length, binaryFormat, binary);
8022
Geoff Langbfdea662014-07-23 14:16:32 -04008023 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008024 if (context)
8025 {
8026 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008027 {
Geoff Langb1196682014-07-23 13:47:29 -04008028 context->recordError(gl::Error(GL_INVALID_OPERATION));
8029 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008030 }
Geoff Langbfdea662014-07-23 14:16:32 -04008031
8032 // glGetProgramBinary
8033 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008034 }
8035}
8036
8037void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
8038{
8039 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
8040 program, binaryFormat, binary, length);
8041
Geoff Langbfdea662014-07-23 14:16:32 -04008042 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008043 if (context)
8044 {
8045 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008046 {
Geoff Langb1196682014-07-23 13:47:29 -04008047 context->recordError(gl::Error(GL_INVALID_OPERATION));
8048 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008049 }
Geoff Langbfdea662014-07-23 14:16:32 -04008050
8051 // glProgramBinary
8052 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008053 }
8054}
8055
8056void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
8057{
8058 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
8059 program, pname, value);
8060
Geoff Langbfdea662014-07-23 14:16:32 -04008061 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008062 if (context)
8063 {
8064 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008065 {
Geoff Langb1196682014-07-23 13:47:29 -04008066 context->recordError(gl::Error(GL_INVALID_OPERATION));
8067 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008068 }
Geoff Langbfdea662014-07-23 14:16:32 -04008069
8070 // glProgramParameteri
8071 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008072 }
8073}
8074
8075void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
8076{
8077 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8078 target, numAttachments, attachments);
8079
Geoff Langbfdea662014-07-23 14:16:32 -04008080 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008081 if (context)
8082 {
8083 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008084 {
Geoff Langb1196682014-07-23 13:47:29 -04008085 context->recordError(gl::Error(GL_INVALID_OPERATION));
8086 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008087 }
Geoff Langbfdea662014-07-23 14:16:32 -04008088
8089 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8090 {
8091 return;
8092 }
8093
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008094 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8095 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8096 {
8097 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8098 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008099 }
8100}
8101
8102void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
8103{
8104 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8105 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8106 target, numAttachments, attachments, x, y, width, height);
8107
Geoff Langbfdea662014-07-23 14:16:32 -04008108 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008109 if (context)
8110 {
8111 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008112 {
Geoff Langb1196682014-07-23 13:47:29 -04008113 context->recordError(gl::Error(GL_INVALID_OPERATION));
8114 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008115 }
Geoff Langbfdea662014-07-23 14:16:32 -04008116
8117 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8118 {
8119 return;
8120 }
8121
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008122 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8123 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8124 {
8125 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8126 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008127 }
8128}
8129
8130void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8131{
8132 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8133 target, levels, internalformat, width, height);
8134
Geoff Langbfdea662014-07-23 14:16:32 -04008135 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008136 if (context)
8137 {
8138 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008139 {
Geoff Langb1196682014-07-23 13:47:29 -04008140 context->recordError(gl::Error(GL_INVALID_OPERATION));
8141 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008142 }
Geoff Langbfdea662014-07-23 14:16:32 -04008143
8144 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8145 {
8146 return;
8147 }
8148
8149 switch (target)
8150 {
8151 case GL_TEXTURE_2D:
8152 {
8153 gl::Texture2D *texture2d = context->getTexture2D();
8154 texture2d->storage(levels, internalformat, width, height);
8155 }
8156 break;
8157
8158 case GL_TEXTURE_CUBE_MAP:
8159 {
8160 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8161 textureCube->storage(levels, internalformat, width);
8162 }
8163 break;
8164
8165 default:
Geoff Langb1196682014-07-23 13:47:29 -04008166 context->recordError(gl::Error(GL_INVALID_ENUM));
8167 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008168 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008169 }
8170}
8171
8172void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8173{
8174 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8175 "GLsizei height = %d, GLsizei depth = %d)",
8176 target, levels, internalformat, width, height, depth);
8177
Geoff Langbfdea662014-07-23 14:16:32 -04008178 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008179 if (context)
8180 {
8181 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008182 {
Geoff Langb1196682014-07-23 13:47:29 -04008183 context->recordError(gl::Error(GL_INVALID_OPERATION));
8184 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008185 }
Geoff Langbfdea662014-07-23 14:16:32 -04008186
8187 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8188 {
8189 return;
8190 }
8191
8192 switch (target)
8193 {
8194 case GL_TEXTURE_3D:
8195 {
8196 gl::Texture3D *texture3d = context->getTexture3D();
8197 texture3d->storage(levels, internalformat, width, height, depth);
8198 }
8199 break;
8200
8201 case GL_TEXTURE_2D_ARRAY:
8202 {
8203 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8204 texture2darray->storage(levels, internalformat, width, height, depth);
8205 }
8206 break;
8207
8208 default:
8209 UNREACHABLE();
8210 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008211 }
8212}
8213
8214void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8215{
8216 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8217 "GLint* params = 0x%0.8p)",
8218 target, internalformat, pname, bufSize, params);
8219
Geoff Langbfdea662014-07-23 14:16:32 -04008220 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008221 if (context)
8222 {
8223 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008224 {
Geoff Langb1196682014-07-23 13:47:29 -04008225 context->recordError(gl::Error(GL_INVALID_OPERATION));
8226 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008227 }
Geoff Langbfdea662014-07-23 14:16:32 -04008228
8229 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8230 if (!formatCaps.renderable)
8231 {
Geoff Langb1196682014-07-23 13:47:29 -04008232 context->recordError(gl::Error(GL_INVALID_ENUM));
8233 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008234 }
8235
8236 if (target != GL_RENDERBUFFER)
8237 {
Geoff Langb1196682014-07-23 13:47:29 -04008238 context->recordError(gl::Error(GL_INVALID_ENUM));
8239 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008240 }
8241
8242 if (bufSize < 0)
8243 {
Geoff Langb1196682014-07-23 13:47:29 -04008244 context->recordError(gl::Error(GL_INVALID_VALUE));
8245 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008246 }
8247
8248 switch (pname)
8249 {
8250 case GL_NUM_SAMPLE_COUNTS:
8251 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008252 {
8253 *params = formatCaps.sampleCounts.size();
8254 }
Geoff Langbfdea662014-07-23 14:16:32 -04008255 break;
Geoff Langb1196682014-07-23 13:47:29 -04008256
Geoff Langbfdea662014-07-23 14:16:32 -04008257 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008258 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008259 break;
Geoff Langb1196682014-07-23 13:47:29 -04008260
Geoff Langbfdea662014-07-23 14:16:32 -04008261 default:
Geoff Langb1196682014-07-23 13:47:29 -04008262 context->recordError(gl::Error(GL_INVALID_ENUM));
8263 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008265 }
8266}
8267
8268// Extension functions
8269
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008270void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8271 GLbitfield mask, GLenum filter)
8272{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008273 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008274 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8275 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8276 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8277
Geoff Langbfdea662014-07-23 14:16:32 -04008278 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008279 if (context)
8280 {
8281 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8282 dstX0, dstY0, dstX1, dstY1, mask, filter,
8283 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008284 {
Geoff Langbfdea662014-07-23 14:16:32 -04008285 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008286 }
Geoff Langbfdea662014-07-23 14:16:32 -04008287
8288 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8289 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008290 }
8291}
8292
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008293void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8294 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008295{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008296 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008297 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008298 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008299 target, level, internalformat, width, height, depth, border, format, type, pixels);
8300
Geoff Langbfdea662014-07-23 14:16:32 -04008301 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008302}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008303
Geoff Langbfdea662014-07-23 14:16:32 -04008304void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008305 GLenum *binaryFormat, void *binary)
8306{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008307 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 +00008308 program, bufSize, length, binaryFormat, binary);
8309
Geoff Langbfdea662014-07-23 14:16:32 -04008310 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008311 if (context)
8312 {
8313 gl::Program *programObject = context->getProgram(program);
8314
8315 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008316 {
Geoff Langb1196682014-07-23 13:47:29 -04008317 context->recordError(gl::Error(GL_INVALID_OPERATION));
8318 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008319 }
Geoff Langbfdea662014-07-23 14:16:32 -04008320
8321 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8322
8323 if (!programBinary)
8324 {
Geoff Langb1196682014-07-23 13:47:29 -04008325 context->recordError(gl::Error(GL_INVALID_OPERATION));
8326 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008327 }
8328
Geoff Lang900013c2014-07-07 11:32:19 -04008329 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04008330 {
Geoff Langb1196682014-07-23 13:47:29 -04008331 context->recordError(gl::Error(GL_INVALID_OPERATION));
8332 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008333 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008334 }
8335}
8336
8337void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8338 const void *binary, GLint length)
8339{
8340 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8341 program, binaryFormat, binary, length);
8342
Geoff Langbfdea662014-07-23 14:16:32 -04008343 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008344 if (context)
8345 {
Geoff Lang900013c2014-07-07 11:32:19 -04008346 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8347 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008348 {
Geoff Langb1196682014-07-23 13:47:29 -04008349 context->recordError(gl::Error(GL_INVALID_ENUM));
8350 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008351 }
Geoff Langbfdea662014-07-23 14:16:32 -04008352
8353 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008354 if (!programObject)
8355 {
Geoff Langb1196682014-07-23 13:47:29 -04008356 context->recordError(gl::Error(GL_INVALID_OPERATION));
8357 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008358 }
8359
Geoff Lang900013c2014-07-07 11:32:19 -04008360 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008361 }
8362}
8363
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008364void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8365{
8366 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8367
Geoff Langbfdea662014-07-23 14:16:32 -04008368 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008369 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008370 {
Geoff Langbfdea662014-07-23 14:16:32 -04008371 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008372 {
Geoff Langb1196682014-07-23 13:47:29 -04008373 context->recordError(gl::Error(GL_INVALID_VALUE));
8374 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008375 }
8376
8377 if (context->getState().getDrawFramebuffer()->id() == 0)
8378 {
8379 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008380 {
Geoff Langb1196682014-07-23 13:47:29 -04008381 context->recordError(gl::Error(GL_INVALID_OPERATION));
8382 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008383 }
8384
Geoff Langbfdea662014-07-23 14:16:32 -04008385 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008386 {
Geoff Langb1196682014-07-23 13:47:29 -04008387 context->recordError(gl::Error(GL_INVALID_OPERATION));
8388 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008389 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008390 }
Geoff Langbfdea662014-07-23 14:16:32 -04008391 else
8392 {
8393 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8394 {
8395 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8396 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8397 {
Geoff Langb1196682014-07-23 13:47:29 -04008398 context->recordError(gl::Error(GL_INVALID_OPERATION));
8399 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008400 }
8401 }
8402 }
8403
8404 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8405
8406 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8407 {
8408 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8409 }
8410
8411 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8412 {
8413 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8414 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008415 }
8416}
8417
Shannon Woodsb3801742014-03-27 14:59:19 -04008418void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8419{
8420 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8421
Geoff Langbfdea662014-07-23 14:16:32 -04008422 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008423 if (context)
8424 {
8425 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008426 {
Geoff Langb1196682014-07-23 13:47:29 -04008427 context->recordError(gl::Error(GL_INVALID_ENUM));
8428 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008429 }
Geoff Langbfdea662014-07-23 14:16:32 -04008430
8431 if (pname != GL_BUFFER_MAP_POINTER)
8432 {
Geoff Langb1196682014-07-23 13:47:29 -04008433 context->recordError(gl::Error(GL_INVALID_ENUM));
8434 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008435 }
8436
8437 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8438
8439 if (!buffer || !buffer->isMapped())
8440 {
8441 *params = NULL;
8442 }
8443 else
8444 {
8445 *params = buffer->getMapPointer();
8446 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008447 }
8448}
8449
8450void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8451{
8452 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8453
Geoff Langbfdea662014-07-23 14:16:32 -04008454 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008455 if (context)
8456 {
8457 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008458 {
Geoff Langb1196682014-07-23 13:47:29 -04008459 context->recordError(gl::Error(GL_INVALID_ENUM));
8460 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008461 }
Geoff Langbfdea662014-07-23 14:16:32 -04008462
8463 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8464
8465 if (buffer == NULL)
8466 {
Geoff Langb1196682014-07-23 13:47:29 -04008467 context->recordError(gl::Error(GL_INVALID_OPERATION));
8468 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008469 }
8470
8471 if (access != GL_WRITE_ONLY_OES)
8472 {
Geoff Langb1196682014-07-23 13:47:29 -04008473 context->recordError(gl::Error(GL_INVALID_ENUM));
8474 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008475 }
8476
8477 if (buffer->isMapped())
8478 {
Geoff Langb1196682014-07-23 13:47:29 -04008479 context->recordError(gl::Error(GL_INVALID_OPERATION));
8480 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008481 }
8482
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008483 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8484 if (error.isError())
8485 {
8486 context->recordError(error);
8487 return NULL;
8488 }
8489
8490 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008491 }
8492
8493 return NULL;
8494}
8495
8496GLboolean __stdcall glUnmapBufferOES(GLenum target)
8497{
8498 EVENT("(GLenum target = 0x%X)", target);
8499
Geoff Langbfdea662014-07-23 14:16:32 -04008500 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008501 if (context)
8502 {
8503 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008504 {
Geoff Langb1196682014-07-23 13:47:29 -04008505 context->recordError(gl::Error(GL_INVALID_ENUM));
8506 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008507 }
Geoff Langbfdea662014-07-23 14:16:32 -04008508
8509 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8510
8511 if (buffer == NULL || !buffer->isMapped())
8512 {
Geoff Langb1196682014-07-23 13:47:29 -04008513 context->recordError(gl::Error(GL_INVALID_OPERATION));
8514 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008515 }
8516
8517 // TODO: detect if we had corruption. if so, throw an error and return false.
8518
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008519 gl::Error error = buffer->unmap();
8520 if (error.isError())
8521 {
8522 context->recordError(error);
8523 return GL_FALSE;
8524 }
Geoff Langbfdea662014-07-23 14:16:32 -04008525
8526 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008527 }
8528
8529 return GL_FALSE;
8530}
8531
Shannon Woods916e7692014-03-27 16:58:22 -04008532void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8533{
8534 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8535 target, offset, length, access);
8536
Geoff Langbfdea662014-07-23 14:16:32 -04008537 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008538 if (context)
8539 {
8540 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008541 {
Geoff Langb1196682014-07-23 13:47:29 -04008542 context->recordError(gl::Error(GL_INVALID_ENUM));
8543 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008544 }
Geoff Langbfdea662014-07-23 14:16:32 -04008545
8546 if (offset < 0 || length < 0)
8547 {
Geoff Langb1196682014-07-23 13:47:29 -04008548 context->recordError(gl::Error(GL_INVALID_VALUE));
8549 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008550 }
8551
8552 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8553
8554 if (buffer == NULL)
8555 {
Geoff Langb1196682014-07-23 13:47:29 -04008556 context->recordError(gl::Error(GL_INVALID_OPERATION));
8557 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008558 }
8559
8560 // Check for buffer overflow
8561 size_t offsetSize = static_cast<size_t>(offset);
8562 size_t lengthSize = static_cast<size_t>(length);
8563
8564 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8565 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8566 {
Geoff Langb1196682014-07-23 13:47:29 -04008567 context->recordError(gl::Error(GL_INVALID_VALUE));
8568 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008569 }
8570
8571 // Check for invalid bits in the mask
8572 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8573 GL_MAP_WRITE_BIT |
8574 GL_MAP_INVALIDATE_RANGE_BIT |
8575 GL_MAP_INVALIDATE_BUFFER_BIT |
8576 GL_MAP_FLUSH_EXPLICIT_BIT |
8577 GL_MAP_UNSYNCHRONIZED_BIT;
8578
8579 if (access & ~(allAccessBits))
8580 {
Geoff Langb1196682014-07-23 13:47:29 -04008581 context->recordError(gl::Error(GL_INVALID_VALUE));
8582 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008583 }
8584
8585 if (length == 0 || buffer->isMapped())
8586 {
Geoff Langb1196682014-07-23 13:47:29 -04008587 context->recordError(gl::Error(GL_INVALID_OPERATION));
8588 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008589 }
8590
8591 // Check for invalid bit combinations
8592 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8593 {
Geoff Langb1196682014-07-23 13:47:29 -04008594 context->recordError(gl::Error(GL_INVALID_OPERATION));
8595 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008596 }
8597
8598 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8599 GL_MAP_INVALIDATE_BUFFER_BIT |
8600 GL_MAP_UNSYNCHRONIZED_BIT;
8601
8602 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8603 {
Geoff Langb1196682014-07-23 13:47:29 -04008604 context->recordError(gl::Error(GL_INVALID_OPERATION));
8605 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008606 }
8607
8608 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8609 {
Geoff Langb1196682014-07-23 13:47:29 -04008610 context->recordError(gl::Error(GL_INVALID_OPERATION));
8611 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008612 }
8613
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008614 gl::Error error = buffer->mapRange(offset, length, access);
8615 if (error.isError())
8616 {
8617 context->recordError(error);
8618 return NULL;
8619 }
8620
8621 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008622 }
8623
8624 return NULL;
8625}
8626
8627void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8628{
8629 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8630
Geoff Langbfdea662014-07-23 14:16:32 -04008631 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008632 if (context)
8633 {
8634 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008635 {
Geoff Langb1196682014-07-23 13:47:29 -04008636 context->recordError(gl::Error(GL_INVALID_VALUE));
8637 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008638 }
Geoff Langbfdea662014-07-23 14:16:32 -04008639
8640 if (!gl::ValidBufferTarget(context, target))
8641 {
Geoff Langb1196682014-07-23 13:47:29 -04008642 context->recordError(gl::Error(GL_INVALID_ENUM));
8643 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008644 }
8645
8646 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8647
8648 if (buffer == NULL)
8649 {
Geoff Langb1196682014-07-23 13:47:29 -04008650 context->recordError(gl::Error(GL_INVALID_OPERATION));
8651 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008652 }
8653
8654 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8655 {
Geoff Langb1196682014-07-23 13:47:29 -04008656 context->recordError(gl::Error(GL_INVALID_OPERATION));
8657 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008658 }
8659
8660 // Check for buffer overflow
8661 size_t offsetSize = static_cast<size_t>(offset);
8662 size_t lengthSize = static_cast<size_t>(length);
8663
8664 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8665 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8666 {
Geoff Langb1196682014-07-23 13:47:29 -04008667 context->recordError(gl::Error(GL_INVALID_VALUE));
8668 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008669 }
8670
8671 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008672 }
8673}
8674
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008675__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8676{
8677 struct Extension
8678 {
8679 const char *name;
8680 __eglMustCastToProperFunctionPointerType address;
8681 };
8682
8683 static const Extension glExtensions[] =
8684 {
8685 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008686 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008687 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008688 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8689 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8690 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8691 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8692 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8693 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8694 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008695 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008696 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008697 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8698 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8699 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8700 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008701 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8702 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8703 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8704 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8705 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8706 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8707 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008708 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008709 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8710 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8711 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008712 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008713 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8714 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8715 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008716 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8717 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8718 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008719
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008720 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008721 {
8722 if (strcmp(procname, glExtensions[ext].name) == 0)
8723 {
8724 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8725 }
8726 }
8727
8728 return NULL;
8729}
8730
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008731// Non-public functions used by EGL
8732
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008733bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008734{
8735 EVENT("(egl::Surface* surface = 0x%0.8p)",
8736 surface);
8737
Geoff Langbfdea662014-07-23 14:16:32 -04008738 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008739 if (context)
8740 {
8741 gl::Texture2D *textureObject = context->getTexture2D();
8742 ASSERT(textureObject != NULL);
8743
8744 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008745 {
Geoff Langbfdea662014-07-23 14:16:32 -04008746 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008747 }
Geoff Langbfdea662014-07-23 14:16:32 -04008748
8749 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008750 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008751
8752 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008753}
8754
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008755}