blob: 28e3d28f1f77909139c69fa5fef7341611682664 [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
113 context->beginQuery(target, id);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000114 }
115}
116
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000117void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000118{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000119 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120
Geoff Langbfdea662014-07-23 14:16:32 -0400121 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400122 if (context)
123 {
Geoff Langb1196682014-07-23 13:47:29 -0400124 if (index >= gl::MAX_VERTEX_ATTRIBS)
125 {
126 context->recordError(gl::Error(GL_INVALID_VALUE));
127 return;
128 }
129
Geoff Langbfdea662014-07-23 14:16:32 -0400130 gl::Program *programObject = context->getProgram(program);
131
132 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000133 {
Geoff Langbfdea662014-07-23 14:16:32 -0400134 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000135 {
Geoff Langb1196682014-07-23 13:47:29 -0400136 context->recordError(gl::Error(GL_INVALID_OPERATION));
137 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000138 }
Geoff Langbfdea662014-07-23 14:16:32 -0400139 else
140 {
Geoff Langb1196682014-07-23 13:47:29 -0400141 context->recordError(gl::Error(GL_INVALID_VALUE));
142 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400143 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000144 }
Geoff Langbfdea662014-07-23 14:16:32 -0400145
146 if (strncmp(name, "gl_", 3) == 0)
147 {
Geoff Langb1196682014-07-23 13:47:29 -0400148 context->recordError(gl::Error(GL_INVALID_OPERATION));
149 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400150 }
151
152 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000153 }
154}
155
156void __stdcall glBindBuffer(GLenum target, GLuint buffer)
157{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000158 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159
Geoff Langbfdea662014-07-23 14:16:32 -0400160 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400161 if (context)
162 {
163 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000164 {
Geoff Langb1196682014-07-23 13:47:29 -0400165 context->recordError(gl::Error(GL_INVALID_ENUM));
166 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000167 }
Geoff Langbfdea662014-07-23 14:16:32 -0400168
169 switch (target)
170 {
171 case GL_ARRAY_BUFFER:
172 context->bindArrayBuffer(buffer);
173 return;
174 case GL_ELEMENT_ARRAY_BUFFER:
175 context->bindElementArrayBuffer(buffer);
176 return;
177 case GL_COPY_READ_BUFFER:
178 context->bindCopyReadBuffer(buffer);
179 return;
180 case GL_COPY_WRITE_BUFFER:
181 context->bindCopyWriteBuffer(buffer);
182 return;
183 case GL_PIXEL_PACK_BUFFER:
184 context->bindPixelPackBuffer(buffer);
185 return;
186 case GL_PIXEL_UNPACK_BUFFER:
187 context->bindPixelUnpackBuffer(buffer);
188 return;
189 case GL_UNIFORM_BUFFER:
190 context->bindGenericUniformBuffer(buffer);
191 return;
192 case GL_TRANSFORM_FEEDBACK_BUFFER:
193 context->bindGenericTransformFeedbackBuffer(buffer);
194 return;
Geoff Langb1196682014-07-23 13:47:29 -0400195
Geoff Langbfdea662014-07-23 14:16:32 -0400196 default:
Geoff Langb1196682014-07-23 13:47:29 -0400197 context->recordError(gl::Error(GL_INVALID_ENUM));
198 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400199 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000200 }
201}
202
203void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
204{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000205 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000206
Geoff Langbfdea662014-07-23 14:16:32 -0400207 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400208 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000209 {
Geoff Langb1196682014-07-23 13:47:29 -0400210 if (!gl::ValidFramebufferTarget(target))
211 {
212 context->recordError(gl::Error(GL_INVALID_ENUM));
213 return;
214 }
215
Geoff Langbfdea662014-07-23 14:16:32 -0400216 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
217 {
218 context->bindReadFramebuffer(framebuffer);
219 }
220
221 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
222 {
223 context->bindDrawFramebuffer(framebuffer);
224 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000225 }
226}
227
228void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
229{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000230 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000231
Geoff Langbfdea662014-07-23 14:16:32 -0400232 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400233 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000234 {
Geoff Langb1196682014-07-23 13:47:29 -0400235 if (target != GL_RENDERBUFFER)
236 {
237 context->recordError(gl::Error(GL_INVALID_ENUM));
238 return;
239 }
240
Geoff Langbfdea662014-07-23 14:16:32 -0400241 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000242 }
243}
244
245void __stdcall glBindTexture(GLenum target, GLuint texture)
246{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000247 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000248
Geoff Langbfdea662014-07-23 14:16:32 -0400249 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400250 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000251 {
Geoff Langbfdea662014-07-23 14:16:32 -0400252 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000253
Geoff Langbfdea662014-07-23 14:16:32 -0400254 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000255 {
Geoff Langb1196682014-07-23 13:47:29 -0400256 context->recordError(gl::Error(GL_INVALID_OPERATION));
257 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400258 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000259
Geoff Langbfdea662014-07-23 14:16:32 -0400260 switch (target)
261 {
262 case GL_TEXTURE_2D:
263 context->bindTexture2D(texture);
264 return;
Geoff Langb1196682014-07-23 13:47:29 -0400265
Geoff Langbfdea662014-07-23 14:16:32 -0400266 case GL_TEXTURE_CUBE_MAP:
267 context->bindTextureCubeMap(texture);
268 return;
Geoff Langb1196682014-07-23 13:47:29 -0400269
Geoff Langbfdea662014-07-23 14:16:32 -0400270 case GL_TEXTURE_3D:
271 if (context->getClientVersion() < 3)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000272 {
Geoff Langb1196682014-07-23 13:47:29 -0400273 context->recordError(gl::Error(GL_INVALID_ENUM));
274 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000275 }
Geoff Langbfdea662014-07-23 14:16:32 -0400276 context->bindTexture3D(texture);
277 return;
Geoff Langb1196682014-07-23 13:47:29 -0400278
Geoff Langbfdea662014-07-23 14:16:32 -0400279 case GL_TEXTURE_2D_ARRAY:
280 if (context->getClientVersion() < 3)
281 {
Geoff Langb1196682014-07-23 13:47:29 -0400282 context->recordError(gl::Error(GL_INVALID_ENUM));
283 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400284 }
285 context->bindTexture2DArray(texture);
286 return;
Geoff Langb1196682014-07-23 13:47:29 -0400287
Geoff Langbfdea662014-07-23 14:16:32 -0400288 default:
Geoff Langb1196682014-07-23 13:47:29 -0400289 context->recordError(gl::Error(GL_INVALID_ENUM));
290 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000291 }
292 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000293}
294
295void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
296{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000297 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000298 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000299
Geoff Langbfdea662014-07-23 14:16:32 -0400300 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000301
Geoff Langbfdea662014-07-23 14:16:32 -0400302 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000303 {
Geoff Langbfdea662014-07-23 14:16:32 -0400304 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000305 }
306}
307
308void __stdcall glBlendEquation(GLenum mode)
309{
310 glBlendEquationSeparate(mode, mode);
311}
312
313void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
314{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000315 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000316
Geoff Langbfdea662014-07-23 14:16:32 -0400317 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400318 if (context)
319 {
Geoff Langb1196682014-07-23 13:47:29 -0400320 switch (modeRGB)
321 {
322 case GL_FUNC_ADD:
323 case GL_FUNC_SUBTRACT:
324 case GL_FUNC_REVERSE_SUBTRACT:
325 case GL_MIN:
326 case GL_MAX:
327 break;
328
329 default:
330 context->recordError(gl::Error(GL_INVALID_ENUM));
331 return;
332 }
333
334 switch (modeAlpha)
335 {
336 case GL_FUNC_ADD:
337 case GL_FUNC_SUBTRACT:
338 case GL_FUNC_REVERSE_SUBTRACT:
339 case GL_MIN:
340 case GL_MAX:
341 break;
342
343 default:
344 context->recordError(gl::Error(GL_INVALID_ENUM));
345 return;
346 }
347
Geoff Langbfdea662014-07-23 14:16:32 -0400348 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000349 }
350}
351
352void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
353{
354 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
355}
356
357void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
358{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000359 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 +0000360 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000361
Geoff Langbfdea662014-07-23 14:16:32 -0400362 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400363 if (context)
364 {
Geoff Langb1196682014-07-23 13:47:29 -0400365 switch (srcRGB)
366 {
367 case GL_ZERO:
368 case GL_ONE:
369 case GL_SRC_COLOR:
370 case GL_ONE_MINUS_SRC_COLOR:
371 case GL_DST_COLOR:
372 case GL_ONE_MINUS_DST_COLOR:
373 case GL_SRC_ALPHA:
374 case GL_ONE_MINUS_SRC_ALPHA:
375 case GL_DST_ALPHA:
376 case GL_ONE_MINUS_DST_ALPHA:
377 case GL_CONSTANT_COLOR:
378 case GL_ONE_MINUS_CONSTANT_COLOR:
379 case GL_CONSTANT_ALPHA:
380 case GL_ONE_MINUS_CONSTANT_ALPHA:
381 case GL_SRC_ALPHA_SATURATE:
382 break;
383
384 default:
385 context->recordError(gl::Error(GL_INVALID_ENUM));
386 return;
387 }
388
389 switch (dstRGB)
390 {
391 case GL_ZERO:
392 case GL_ONE:
393 case GL_SRC_COLOR:
394 case GL_ONE_MINUS_SRC_COLOR:
395 case GL_DST_COLOR:
396 case GL_ONE_MINUS_DST_COLOR:
397 case GL_SRC_ALPHA:
398 case GL_ONE_MINUS_SRC_ALPHA:
399 case GL_DST_ALPHA:
400 case GL_ONE_MINUS_DST_ALPHA:
401 case GL_CONSTANT_COLOR:
402 case GL_ONE_MINUS_CONSTANT_COLOR:
403 case GL_CONSTANT_ALPHA:
404 case GL_ONE_MINUS_CONSTANT_ALPHA:
405 break;
406
407 case GL_SRC_ALPHA_SATURATE:
408 if (context->getClientVersion() < 3)
409 {
410 context->recordError(gl::Error(GL_INVALID_ENUM));
411 return;
412 }
413 break;
414
415 default:
416 context->recordError(gl::Error(GL_INVALID_ENUM));
417 return;
418 }
419
420 switch (srcAlpha)
421 {
422 case GL_ZERO:
423 case GL_ONE:
424 case GL_SRC_COLOR:
425 case GL_ONE_MINUS_SRC_COLOR:
426 case GL_DST_COLOR:
427 case GL_ONE_MINUS_DST_COLOR:
428 case GL_SRC_ALPHA:
429 case GL_ONE_MINUS_SRC_ALPHA:
430 case GL_DST_ALPHA:
431 case GL_ONE_MINUS_DST_ALPHA:
432 case GL_CONSTANT_COLOR:
433 case GL_ONE_MINUS_CONSTANT_COLOR:
434 case GL_CONSTANT_ALPHA:
435 case GL_ONE_MINUS_CONSTANT_ALPHA:
436 case GL_SRC_ALPHA_SATURATE:
437 break;
438
439 default:
440 context->recordError(gl::Error(GL_INVALID_ENUM));
441 return;
442 }
443
444 switch (dstAlpha)
445 {
446 case GL_ZERO:
447 case GL_ONE:
448 case GL_SRC_COLOR:
449 case GL_ONE_MINUS_SRC_COLOR:
450 case GL_DST_COLOR:
451 case GL_ONE_MINUS_DST_COLOR:
452 case GL_SRC_ALPHA:
453 case GL_ONE_MINUS_SRC_ALPHA:
454 case GL_DST_ALPHA:
455 case GL_ONE_MINUS_DST_ALPHA:
456 case GL_CONSTANT_COLOR:
457 case GL_ONE_MINUS_CONSTANT_COLOR:
458 case GL_CONSTANT_ALPHA:
459 case GL_ONE_MINUS_CONSTANT_ALPHA:
460 break;
461
462 case GL_SRC_ALPHA_SATURATE:
463 if (context->getClientVersion() < 3)
464 {
465 context->recordError(gl::Error(GL_INVALID_ENUM));
466 return;
467 }
468 break;
469
470 default:
471 context->recordError(gl::Error(GL_INVALID_ENUM));
472 return;
473 }
474
475 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
476 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
477
478 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
479 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
480
481 if (constantColorUsed && constantAlphaUsed)
482 {
483 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
484 context->recordError(gl::Error(GL_INVALID_OPERATION));
485 return;
486 }
487
Geoff Langbfdea662014-07-23 14:16:32 -0400488 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000489 }
490}
491
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000492void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000493{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000494 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 +0000495 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000496
Geoff Langbfdea662014-07-23 14:16:32 -0400497 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400498 if (context)
499 {
Geoff Langb1196682014-07-23 13:47:29 -0400500 if (size < 0)
501 {
502 context->recordError(gl::Error(GL_INVALID_VALUE));
503 return;
504 }
505
506 switch (usage)
507 {
508 case GL_STREAM_DRAW:
509 case GL_STATIC_DRAW:
510 case GL_DYNAMIC_DRAW:
511 break;
512
513 case GL_STREAM_READ:
514 case GL_STREAM_COPY:
515 case GL_STATIC_READ:
516 case GL_STATIC_COPY:
517 case GL_DYNAMIC_READ:
518 case GL_DYNAMIC_COPY:
519 if (context->getClientVersion() < 3)
520 {
521 context->recordError(gl::Error(GL_INVALID_ENUM));
522 return;
523 }
524 break;
525
526 default:
527 context->recordError(gl::Error(GL_INVALID_ENUM));
528 return;
529 }
530
Geoff Langbfdea662014-07-23 14:16:32 -0400531 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000532 {
Geoff Langb1196682014-07-23 13:47:29 -0400533 context->recordError(gl::Error(GL_INVALID_ENUM));
534 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000535 }
536
Geoff Langbfdea662014-07-23 14:16:32 -0400537 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
538
539 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000540 {
Geoff Langb1196682014-07-23 13:47:29 -0400541 context->recordError(gl::Error(GL_INVALID_OPERATION));
542 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000543 }
Geoff Langbfdea662014-07-23 14:16:32 -0400544
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400545 gl::Error error = buffer->bufferData(data, size, usage);
546 if (error.isError())
547 {
548 context->recordError(error);
549 return;
550 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000551 }
552}
553
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000554void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000555{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000556 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 +0000557 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000558
Geoff Langbfdea662014-07-23 14:16:32 -0400559 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400560 if (context)
561 {
Geoff Langb1196682014-07-23 13:47:29 -0400562 if (size < 0 || offset < 0)
563 {
564 context->recordError(gl::Error(GL_INVALID_VALUE));
565 return;
566 }
567
568 if (data == NULL)
569 {
570 return;
571 }
572
Geoff Langbfdea662014-07-23 14:16:32 -0400573 if (!gl::ValidBufferTarget(context, target))
574 {
Geoff Langb1196682014-07-23 13:47:29 -0400575 context->recordError(gl::Error(GL_INVALID_ENUM));
576 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400577 }
578
579 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
580
581 if (!buffer)
582 {
Geoff Langb1196682014-07-23 13:47:29 -0400583 context->recordError(gl::Error(GL_INVALID_OPERATION));
584 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400585 }
586
587 if (buffer->isMapped())
588 {
Geoff Langb1196682014-07-23 13:47:29 -0400589 context->recordError(gl::Error(GL_INVALID_OPERATION));
590 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400591 }
592
593 // Check for possible overflow of size + offset
594 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
595 {
Geoff Langb1196682014-07-23 13:47:29 -0400596 context->recordError(gl::Error(GL_OUT_OF_MEMORY));
597 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400598 }
599
600 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000601 {
Geoff Langb1196682014-07-23 13:47:29 -0400602 context->recordError(gl::Error(GL_INVALID_VALUE));
603 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000604 }
605
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400606 gl::Error error = buffer->bufferSubData(data, size, offset);
607 if (error.isError())
608 {
609 context->recordError(error);
610 return;
611 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000612 }
613}
614
615GLenum __stdcall glCheckFramebufferStatus(GLenum target)
616{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000617 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000618
Geoff Langbfdea662014-07-23 14:16:32 -0400619 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400620 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000621 {
Geoff Langb1196682014-07-23 13:47:29 -0400622 if (!gl::ValidFramebufferTarget(target))
623 {
624 context->recordError(gl::Error(GL_INVALID_ENUM));
625 return 0;
626 }
627
Geoff Langbfdea662014-07-23 14:16:32 -0400628 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
629 ASSERT(framebuffer);
630 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000631 }
632
633 return 0;
634}
635
636void __stdcall glClear(GLbitfield mask)
637{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000638 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000639
Geoff Langbfdea662014-07-23 14:16:32 -0400640 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400641 if (context)
642 {
643 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
644
645 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000646 {
Geoff Langb1196682014-07-23 13:47:29 -0400647 context->recordError(gl::Error(GL_INVALID_FRAMEBUFFER_OPERATION));
648 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000649 }
Geoff Langbfdea662014-07-23 14:16:32 -0400650
651 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
652 {
Geoff Langb1196682014-07-23 13:47:29 -0400653 context->recordError(gl::Error(GL_INVALID_VALUE));
654 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400655 }
656
Geoff Langcc79b8c2014-07-25 13:48:02 -0400657 gl::Error error = context->clear(mask);
658 if (error.isError())
659 {
660 context->recordError(error);
661 return;
662 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000663 }
664}
665
666void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
667{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000668 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000669 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000670
Geoff Langbfdea662014-07-23 14:16:32 -0400671 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400672 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000673 {
Geoff Langbfdea662014-07-23 14:16:32 -0400674 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000675 }
676}
677
678void __stdcall glClearDepthf(GLclampf depth)
679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000680 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000681
Geoff Langbfdea662014-07-23 14:16:32 -0400682 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400683 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000684 {
Geoff Langbfdea662014-07-23 14:16:32 -0400685 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000686 }
687}
688
689void __stdcall glClearStencil(GLint s)
690{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000691 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000692
Geoff Langbfdea662014-07-23 14:16:32 -0400693 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400694 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000695 {
Geoff Langbfdea662014-07-23 14:16:32 -0400696 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000697 }
698}
699
700void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
701{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000702 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000703 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000704
Geoff Langbfdea662014-07-23 14:16:32 -0400705 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400706 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000707 {
Geoff Langbfdea662014-07-23 14:16:32 -0400708 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000709 }
710}
711
712void __stdcall glCompileShader(GLuint shader)
713{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000714 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000715
Geoff Langbfdea662014-07-23 14:16:32 -0400716 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400717 if (context)
718 {
719 gl::Shader *shaderObject = context->getShader(shader);
720
721 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000722 {
Geoff Langbfdea662014-07-23 14:16:32 -0400723 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000724 {
Geoff Langb1196682014-07-23 13:47:29 -0400725 context->recordError(gl::Error(GL_INVALID_OPERATION));
726 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000727 }
Geoff Langbfdea662014-07-23 14:16:32 -0400728 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000729 {
Geoff Langb1196682014-07-23 13:47:29 -0400730 context->recordError(gl::Error(GL_INVALID_VALUE));
731 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000732 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000733 }
Geoff Langbfdea662014-07-23 14:16:32 -0400734
735 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000736 }
Geoff Langbfdea662014-07-23 14:16:32 -0400737}
738
739void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
740 GLint border, GLsizei imageSize, const GLvoid* data)
741{
742 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
743 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
744 target, level, internalformat, width, height, border, imageSize, data);
745
746 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400747 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000748 {
Geoff Langbfdea662014-07-23 14:16:32 -0400749 if (context->getClientVersion() < 3 &&
750 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
751 0, 0, width, height, border, GL_NONE, GL_NONE, data))
752 {
753 return;
754 }
755
756 if (context->getClientVersion() >= 3 &&
757 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
758 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
759 {
760 return;
761 }
762
Geoff Lang5d601382014-07-22 15:14:06 -0400763 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
764 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400765 {
Geoff Langb1196682014-07-23 13:47:29 -0400766 context->recordError(gl::Error(GL_INVALID_VALUE));
767 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400768 }
769
770 switch (target)
771 {
772 case GL_TEXTURE_2D:
773 {
774 gl::Texture2D *texture = context->getTexture2D();
775 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
776 }
777 break;
778
779 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
780 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
781 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
782 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
783 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
784 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
785 {
786 gl::TextureCubeMap *texture = context->getTextureCubeMap();
787 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
788 }
789 break;
790
791 default:
Geoff Langb1196682014-07-23 13:47:29 -0400792 context->recordError(gl::Error(GL_INVALID_ENUM));
793 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400794 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000795 }
796}
797
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000798void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
799 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000800{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000801 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000802 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000803 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000804 target, level, xoffset, yoffset, width, height, format, imageSize, data);
805
Geoff Langbfdea662014-07-23 14:16:32 -0400806 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400807 if (context)
808 {
809 if (context->getClientVersion() < 3 &&
810 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
811 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000812 {
Geoff Langbfdea662014-07-23 14:16:32 -0400813 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000814 }
Geoff Langbfdea662014-07-23 14:16:32 -0400815
816 if (context->getClientVersion() >= 3 &&
817 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
818 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
819 {
820 return;
821 }
822
Geoff Lang5d601382014-07-22 15:14:06 -0400823 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
824 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400825 {
Geoff Langb1196682014-07-23 13:47:29 -0400826 context->recordError(gl::Error(GL_INVALID_VALUE));
827 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400828 }
829
830 switch (target)
831 {
832 case GL_TEXTURE_2D:
833 {
834 gl::Texture2D *texture = context->getTexture2D();
835 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
836 }
837 break;
838
839 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
840 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
841 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
842 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
843 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
844 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
845 {
846 gl::TextureCubeMap *texture = context->getTextureCubeMap();
847 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
848 }
849 break;
850
851 default:
Geoff Langb1196682014-07-23 13:47:29 -0400852 context->recordError(gl::Error(GL_INVALID_ENUM));
853 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400854 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000855 }
856}
857
858void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
859{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000860 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000861 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000862 target, level, internalformat, x, y, width, height, border);
863
Geoff Langbfdea662014-07-23 14:16:32 -0400864 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400865 if (context)
866 {
867 if (context->getClientVersion() < 3 &&
868 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
869 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000870 {
Geoff Langbfdea662014-07-23 14:16:32 -0400871 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000872 }
Geoff Langbfdea662014-07-23 14:16:32 -0400873
874 if (context->getClientVersion() >= 3 &&
875 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
876 0, 0, 0, x, y, width, height, border))
877 {
878 return;
879 }
880
881 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
882
883 switch (target)
884 {
885 case GL_TEXTURE_2D:
886 {
887 gl::Texture2D *texture = context->getTexture2D();
888 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
889 }
890 break;
891
892 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
893 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
894 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
895 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
896 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
897 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
898 {
899 gl::TextureCubeMap *texture = context->getTextureCubeMap();
900 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
901 }
902 break;
903
Geoff Langb1196682014-07-23 13:47:29 -0400904 default:
905 context->recordError(gl::Error(GL_INVALID_ENUM));
906 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400907 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000908 }
909}
910
911void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
912{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000913 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000914 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000915 target, level, xoffset, yoffset, x, y, width, height);
916
Geoff Langbfdea662014-07-23 14:16:32 -0400917 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400918 if (context)
919 {
920 if (context->getClientVersion() < 3 &&
921 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
922 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000923 {
Geoff Langbfdea662014-07-23 14:16:32 -0400924 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000925 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000926
Geoff Langbfdea662014-07-23 14:16:32 -0400927 if (context->getClientVersion() >= 3 &&
928 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
929 xoffset, yoffset, 0, x, y, width, height, 0))
930 {
931 return;
932 }
933
934 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
935
936 switch (target)
937 {
938 case GL_TEXTURE_2D:
939 {
940 gl::Texture2D *texture = context->getTexture2D();
941 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
942 }
943 break;
944
945 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
946 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
947 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
948 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
949 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
950 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
951 {
952 gl::TextureCubeMap *texture = context->getTextureCubeMap();
953 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
954 }
955 break;
956
957 default:
Geoff Langb1196682014-07-23 13:47:29 -0400958 context->recordError(gl::Error(GL_INVALID_ENUM));
959 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400960 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000961 }
962}
963
964GLuint __stdcall glCreateProgram(void)
965{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000966 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000967
Geoff Langbfdea662014-07-23 14:16:32 -0400968 gl::Context *context = gl::getNonLostContext();
969 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000970 {
Geoff Langbfdea662014-07-23 14:16:32 -0400971 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000972 }
973
974 return 0;
975}
976
977GLuint __stdcall glCreateShader(GLenum type)
978{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000979 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000980
Geoff Langbfdea662014-07-23 14:16:32 -0400981 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400982 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000983 {
Geoff Langbfdea662014-07-23 14:16:32 -0400984 switch (type)
985 {
986 case GL_FRAGMENT_SHADER:
987 case GL_VERTEX_SHADER:
988 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -0400989
Geoff Langbfdea662014-07-23 14:16:32 -0400990 default:
Geoff Langb1196682014-07-23 13:47:29 -0400991 context->recordError(gl::Error(GL_INVALID_ENUM));
992 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -0400993 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000994 }
995
996 return 0;
997}
998
999void __stdcall glCullFace(GLenum mode)
1000{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001001 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001002
Geoff Langb1196682014-07-23 13:47:29 -04001003 gl::Context *context = gl::getNonLostContext();
1004 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001005 {
Geoff Langb1196682014-07-23 13:47:29 -04001006 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001007 {
Geoff Langb1196682014-07-23 13:47:29 -04001008 case GL_FRONT:
1009 case GL_BACK:
1010 case GL_FRONT_AND_BACK:
1011 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001012
Geoff Langb1196682014-07-23 13:47:29 -04001013 default:
1014 context->recordError(gl::Error(GL_INVALID_ENUM));
1015 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001016 }
Geoff Langb1196682014-07-23 13:47:29 -04001017
1018 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001019 }
1020}
1021
1022void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
1023{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001024 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001025
Geoff Langbfdea662014-07-23 14:16:32 -04001026 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001027 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001028 {
Geoff Langb1196682014-07-23 13:47:29 -04001029 if (n < 0)
1030 {
1031 context->recordError(gl::Error(GL_INVALID_VALUE));
1032 return;
1033 }
1034
Geoff Langbfdea662014-07-23 14:16:32 -04001035 for (int i = 0; i < n; i++)
1036 {
1037 context->deleteBuffer(buffers[i]);
1038 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001039 }
1040}
1041
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001042void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
1043{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001044 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001045
Geoff Langbfdea662014-07-23 14:16:32 -04001046 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001047 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001048 {
Geoff Langb1196682014-07-23 13:47:29 -04001049 if (n < 0)
1050 {
1051 context->recordError(gl::Error(GL_INVALID_VALUE));
1052 return;
1053 }
1054
Geoff Langbfdea662014-07-23 14:16:32 -04001055 for (int i = 0; i < n; i++)
1056 {
1057 context->deleteFenceNV(fences[i]);
1058 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001059 }
1060}
1061
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001062void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1063{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001064 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001065
Geoff Langbfdea662014-07-23 14:16:32 -04001066 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001067 if (context)
1068 {
Geoff Langb1196682014-07-23 13:47:29 -04001069 if (n < 0)
1070 {
1071 context->recordError(gl::Error(GL_INVALID_VALUE));
1072 return;
1073 }
1074
Geoff Langbfdea662014-07-23 14:16:32 -04001075 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001076 {
Geoff Langbfdea662014-07-23 14:16:32 -04001077 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001078 {
Geoff Langbfdea662014-07-23 14:16:32 -04001079 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001080 }
1081 }
1082 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001083}
1084
1085void __stdcall glDeleteProgram(GLuint program)
1086{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001087 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001088
Geoff Langbfdea662014-07-23 14:16:32 -04001089 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001090 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001091 {
Geoff Langb1196682014-07-23 13:47:29 -04001092 if (program == 0)
1093 {
1094 return;
1095 }
1096
Geoff Langbfdea662014-07-23 14:16:32 -04001097 if (!context->getProgram(program))
1098 {
1099 if(context->getShader(program))
1100 {
Geoff Langb1196682014-07-23 13:47:29 -04001101 context->recordError(gl::Error(GL_INVALID_OPERATION));
1102 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001103 }
1104 else
1105 {
Geoff Langb1196682014-07-23 13:47:29 -04001106 context->recordError(gl::Error(GL_INVALID_VALUE));
1107 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001108 }
1109 }
1110
1111 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001112 }
1113}
1114
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001115void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1116{
1117 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1118
Geoff Langbfdea662014-07-23 14:16:32 -04001119 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001120 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001121 {
Geoff Langb1196682014-07-23 13:47:29 -04001122 if (n < 0)
1123 {
1124 context->recordError(gl::Error(GL_INVALID_VALUE));
1125 return;
1126 }
1127
Geoff Langbfdea662014-07-23 14:16:32 -04001128 for (int i = 0; i < n; i++)
1129 {
1130 context->deleteQuery(ids[i]);
1131 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001132 }
1133}
1134
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001135void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001137 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001138
Geoff Langbfdea662014-07-23 14:16:32 -04001139 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001140 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001141 {
Geoff Langb1196682014-07-23 13:47:29 -04001142 if (n < 0)
1143 {
1144 context->recordError(gl::Error(GL_INVALID_VALUE));
1145 return;
1146 }
1147
Geoff Langbfdea662014-07-23 14:16:32 -04001148 for (int i = 0; i < n; i++)
1149 {
1150 context->deleteRenderbuffer(renderbuffers[i]);
1151 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001152 }
1153}
1154
1155void __stdcall glDeleteShader(GLuint shader)
1156{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001157 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001158
Geoff Langbfdea662014-07-23 14:16:32 -04001159 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001160 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001161 {
Geoff Langb1196682014-07-23 13:47:29 -04001162 if (shader == 0)
1163 {
1164 return;
1165 }
1166
Geoff Langbfdea662014-07-23 14:16:32 -04001167 if (!context->getShader(shader))
1168 {
1169 if(context->getProgram(shader))
1170 {
Geoff Langb1196682014-07-23 13:47:29 -04001171 context->recordError(gl::Error(GL_INVALID_OPERATION));
1172 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001173 }
1174 else
1175 {
Geoff Langb1196682014-07-23 13:47:29 -04001176 context->recordError(gl::Error(GL_INVALID_VALUE));
1177 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001178 }
1179 }
1180
1181 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001182 }
1183}
1184
1185void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1186{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001187 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001188
Geoff Langbfdea662014-07-23 14:16:32 -04001189 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001190 if (context)
1191 {
Geoff Langb1196682014-07-23 13:47:29 -04001192 if (n < 0)
1193 {
1194 context->recordError(gl::Error(GL_INVALID_VALUE));
1195 return;
1196 }
1197
Geoff Langbfdea662014-07-23 14:16:32 -04001198 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001199 {
Geoff Langbfdea662014-07-23 14:16:32 -04001200 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001201 {
Geoff Langbfdea662014-07-23 14:16:32 -04001202 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001203 }
1204 }
1205 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001206}
1207
1208void __stdcall glDepthFunc(GLenum func)
1209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001210 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001211
Geoff Langbfdea662014-07-23 14:16:32 -04001212 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001213 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001214 {
Geoff Langb1196682014-07-23 13:47:29 -04001215 switch (func)
1216 {
1217 case GL_NEVER:
1218 case GL_ALWAYS:
1219 case GL_LESS:
1220 case GL_LEQUAL:
1221 case GL_EQUAL:
1222 case GL_GREATER:
1223 case GL_GEQUAL:
1224 case GL_NOTEQUAL:
1225 context->getState().setDepthFunc(func);
1226 break;
1227
1228 default:
1229 context->recordError(gl::Error(GL_INVALID_ENUM));
1230 return;
1231 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001232 }
1233}
1234
1235void __stdcall glDepthMask(GLboolean flag)
1236{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001237 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001238
Geoff Langbfdea662014-07-23 14:16:32 -04001239 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001240 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001241 {
Geoff Langbfdea662014-07-23 14:16:32 -04001242 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001243 }
1244}
1245
1246void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1247{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001248 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001249
Geoff Langbfdea662014-07-23 14:16:32 -04001250 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001251 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001252 {
Geoff Langbfdea662014-07-23 14:16:32 -04001253 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001254 }
1255}
1256
1257void __stdcall glDetachShader(GLuint program, GLuint shader)
1258{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001259 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001260
Geoff Langbfdea662014-07-23 14:16:32 -04001261 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001262 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001263 {
Geoff Langbfdea662014-07-23 14:16:32 -04001264 gl::Program *programObject = context->getProgram(program);
1265 gl::Shader *shaderObject = context->getShader(shader);
1266
1267 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001268 {
Geoff Langbfdea662014-07-23 14:16:32 -04001269 gl::Shader *shaderByProgramHandle;
1270 shaderByProgramHandle = context->getShader(program);
1271 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001272 {
Geoff Langb1196682014-07-23 13:47:29 -04001273 context->recordError(gl::Error(GL_INVALID_VALUE));
1274 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001275 }
Geoff Langbfdea662014-07-23 14:16:32 -04001276 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277 {
Geoff Langb1196682014-07-23 13:47:29 -04001278 context->recordError(gl::Error(GL_INVALID_OPERATION));
1279 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001280 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001281 }
Geoff Langbfdea662014-07-23 14:16:32 -04001282
1283 if (!shaderObject)
1284 {
1285 gl::Program *programByShaderHandle = context->getProgram(shader);
1286 if (!programByShaderHandle)
1287 {
Geoff Langb1196682014-07-23 13:47:29 -04001288 context->recordError(gl::Error(GL_INVALID_VALUE));
1289 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001290 }
1291 else
1292 {
Geoff Langb1196682014-07-23 13:47:29 -04001293 context->recordError(gl::Error(GL_INVALID_OPERATION));
1294 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001295 }
1296 }
1297
1298 if (!programObject->detachShader(shaderObject))
1299 {
Geoff Langb1196682014-07-23 13:47:29 -04001300 context->recordError(gl::Error(GL_INVALID_OPERATION));
1301 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001302 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001303 }
1304}
1305
1306void __stdcall glDisable(GLenum cap)
1307{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001308 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001309
Geoff Langbfdea662014-07-23 14:16:32 -04001310 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001311 if (context)
1312 {
1313 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001314 {
Geoff Langb1196682014-07-23 13:47:29 -04001315 context->recordError(gl::Error(GL_INVALID_ENUM));
1316 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001317 }
Geoff Langbfdea662014-07-23 14:16:32 -04001318
1319 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001320 }
1321}
1322
1323void __stdcall glDisableVertexAttribArray(GLuint index)
1324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001325 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001326
Geoff Langbfdea662014-07-23 14:16:32 -04001327 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001328 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001329 {
Geoff Langb1196682014-07-23 13:47:29 -04001330 if (index >= gl::MAX_VERTEX_ATTRIBS)
1331 {
1332 context->recordError(gl::Error(GL_INVALID_VALUE));
1333 return;
1334 }
1335
Geoff Langbfdea662014-07-23 14:16:32 -04001336 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001337 }
1338}
1339
1340void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1341{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001342 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001343
Geoff Langbfdea662014-07-23 14:16:32 -04001344 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001345 if (context)
1346 {
Jamie Madill2b976812014-08-25 15:47:49 -04001347 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001348 {
Geoff Langbfdea662014-07-23 14:16:32 -04001349 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001350 }
Geoff Langbfdea662014-07-23 14:16:32 -04001351
1352 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001353 }
1354}
1355
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001356void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1357{
1358 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1359
Geoff Langbfdea662014-07-23 14:16:32 -04001360 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001361 if (context)
1362 {
1363 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001364 {
Geoff Langbfdea662014-07-23 14:16:32 -04001365 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001366 }
Geoff Langbfdea662014-07-23 14:16:32 -04001367
1368 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001369 }
1370}
1371
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001372void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001373{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001374 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 +00001375 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001376
Geoff Langbfdea662014-07-23 14:16:32 -04001377 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001378 if (context)
1379 {
Jamie Madill2b976812014-08-25 15:47:49 -04001380 rx::RangeUI indexRange;
1381 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001382 {
Geoff Langbfdea662014-07-23 14:16:32 -04001383 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001384 }
Geoff Langbfdea662014-07-23 14:16:32 -04001385
Jamie Madill2b976812014-08-25 15:47:49 -04001386 context->drawElements(mode, count, type, indices, 0, indexRange);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001387 }
1388}
1389
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001390void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1391{
1392 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1393 mode, count, type, indices, primcount);
1394
Geoff Langbfdea662014-07-23 14:16:32 -04001395 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001396 if (context)
1397 {
Jamie Madill2b976812014-08-25 15:47:49 -04001398 rx::RangeUI indexRange;
1399 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001400 {
Geoff Langbfdea662014-07-23 14:16:32 -04001401 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001402 }
Geoff Langbfdea662014-07-23 14:16:32 -04001403
Jamie Madill2b976812014-08-25 15:47:49 -04001404 context->drawElements(mode, count, type, indices, primcount, indexRange);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001405 }
1406}
1407
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001408void __stdcall glEnable(GLenum cap)
1409{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001410 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001411
Geoff Langbfdea662014-07-23 14:16:32 -04001412 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001413 if (context)
1414 {
1415 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001416 {
Geoff Langb1196682014-07-23 13:47:29 -04001417 context->recordError(gl::Error(GL_INVALID_ENUM));
1418 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001419 }
Geoff Langbfdea662014-07-23 14:16:32 -04001420
1421 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001422 }
1423}
1424
1425void __stdcall glEnableVertexAttribArray(GLuint index)
1426{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001427 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001428
Geoff Langbfdea662014-07-23 14:16:32 -04001429 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001430 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001431 {
Geoff Langb1196682014-07-23 13:47:29 -04001432 if (index >= gl::MAX_VERTEX_ATTRIBS)
1433 {
1434 context->recordError(gl::Error(GL_INVALID_VALUE));
1435 return;
1436 }
1437
Geoff Langbfdea662014-07-23 14:16:32 -04001438 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001439 }
1440}
1441
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001442void __stdcall glEndQueryEXT(GLenum target)
1443{
1444 EVENT("GLenum target = 0x%X)", target);
1445
Geoff Langbfdea662014-07-23 14:16:32 -04001446 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001447 if (context)
1448 {
1449 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001450 {
Geoff Langbfdea662014-07-23 14:16:32 -04001451 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001452 }
Geoff Langbfdea662014-07-23 14:16:32 -04001453
1454 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001455 }
1456}
1457
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001458void __stdcall glFinishFenceNV(GLuint fence)
1459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001460 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001461
Geoff Langbfdea662014-07-23 14:16:32 -04001462 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001463 if (context)
1464 {
1465 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1466
1467 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001468 {
Geoff Langb1196682014-07-23 13:47:29 -04001469 context->recordError(gl::Error(GL_INVALID_OPERATION));
1470 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001471 }
Geoff Langbfdea662014-07-23 14:16:32 -04001472
1473 if (fenceObject->isFence() != GL_TRUE)
1474 {
Geoff Langb1196682014-07-23 13:47:29 -04001475 context->recordError(gl::Error(GL_INVALID_OPERATION));
1476 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001477 }
1478
1479 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001480 }
1481}
1482
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001483void __stdcall glFinish(void)
1484{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001485 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001486
Geoff Langbfdea662014-07-23 14:16:32 -04001487 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001488 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001489 {
Geoff Langbfdea662014-07-23 14:16:32 -04001490 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001491 }
1492}
1493
1494void __stdcall glFlush(void)
1495{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001496 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001497
Geoff Langbfdea662014-07-23 14:16:32 -04001498 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001499 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001500 {
Geoff Langbfdea662014-07-23 14:16:32 -04001501 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001502 }
1503}
1504
1505void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1506{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001507 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001508 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001509
Geoff Langbfdea662014-07-23 14:16:32 -04001510 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001511 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001512 {
Geoff Langb1196682014-07-23 13:47:29 -04001513 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1514 {
1515 context->recordError(gl::Error(GL_INVALID_ENUM));
1516 return;
1517 }
1518
Geoff Langbfdea662014-07-23 14:16:32 -04001519 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1520 {
1521 return;
1522 }
1523
1524 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1525 ASSERT(framebuffer);
1526
1527 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1528 {
1529 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1530 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1531 }
1532 else
1533 {
1534 switch (attachment)
1535 {
1536 case GL_DEPTH_ATTACHMENT:
1537 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1538 break;
1539 case GL_STENCIL_ATTACHMENT:
1540 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1541 break;
1542 case GL_DEPTH_STENCIL_ATTACHMENT:
1543 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1544 break;
1545 default:
1546 UNREACHABLE();
1547 break;
1548 }
1549 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001550 }
1551}
1552
1553void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1554{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001555 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001556 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001557
Geoff Langbfdea662014-07-23 14:16:32 -04001558 gl::Context *context = gl::getNonLostContext();
1559 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001560 {
Geoff Langbfdea662014-07-23 14:16:32 -04001561 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001562 {
Geoff Langbfdea662014-07-23 14:16:32 -04001563 return;
1564 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001565
Geoff Langbfdea662014-07-23 14:16:32 -04001566 if (texture == 0)
1567 {
1568 textarget = GL_NONE;
1569 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001570
Geoff Langbfdea662014-07-23 14:16:32 -04001571 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001572
Geoff Langbfdea662014-07-23 14:16:32 -04001573 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1574 {
1575 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1576 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1577 }
1578 else
1579 {
1580 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001581 {
Geoff Langbfdea662014-07-23 14:16:32 -04001582 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1583 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1584 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001585 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001586 }
1587 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001588}
1589
1590void __stdcall glFrontFace(GLenum mode)
1591{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001592 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001593
Geoff Langb1196682014-07-23 13:47:29 -04001594 gl::Context *context = gl::getNonLostContext();
1595 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001596 {
Geoff Langb1196682014-07-23 13:47:29 -04001597 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001598 {
Geoff Langb1196682014-07-23 13:47:29 -04001599 case GL_CW:
1600 case GL_CCW:
1601 context->getState().setFrontFace(mode);
1602 break;
1603 default:
1604 context->recordError(gl::Error(GL_INVALID_ENUM));
1605 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001606 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001607 }
1608}
1609
1610void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1611{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001612 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001613
Geoff Langbfdea662014-07-23 14:16:32 -04001614 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001615 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001616 {
Geoff Langb1196682014-07-23 13:47:29 -04001617 if (n < 0)
1618 {
1619 context->recordError(gl::Error(GL_INVALID_VALUE));
1620 return;
1621 }
1622
Geoff Langbfdea662014-07-23 14:16:32 -04001623 for (int i = 0; i < n; i++)
1624 {
1625 buffers[i] = context->createBuffer();
1626 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001627 }
1628}
1629
1630void __stdcall glGenerateMipmap(GLenum target)
1631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001632 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001633
Geoff Langbfdea662014-07-23 14:16:32 -04001634 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001635 if (context)
1636 {
1637 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001638 {
Geoff Langb1196682014-07-23 13:47:29 -04001639 context->recordError(gl::Error(GL_INVALID_ENUM));
1640 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001641 }
Geoff Langbfdea662014-07-23 14:16:32 -04001642
1643 gl::Texture *texture = context->getTargetTexture(target);
1644
1645 if (texture == NULL)
1646 {
Geoff Langb1196682014-07-23 13:47:29 -04001647 context->recordError(gl::Error(GL_INVALID_OPERATION));
1648 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001649 }
1650
1651 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1652 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001653 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001654
1655 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1656 // unsized formats or that are color renderable and filterable. Since we do not track if
1657 // the texture was created with sized or unsized format (only sized formats are stored),
1658 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1659 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1660 // textures since they're the only texture format that can be created with unsized formats
1661 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1662 // was the last version to use add them.
1663 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1664 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1665 internalFormat == GL_ALPHA8_EXT;
1666
Geoff Lang5d601382014-07-22 15:14:06 -04001667 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1668 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001669 {
Geoff Langb1196682014-07-23 13:47:29 -04001670 context->recordError(gl::Error(GL_INVALID_OPERATION));
1671 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001672 }
1673
1674 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001675 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001676 {
Geoff Langb1196682014-07-23 13:47:29 -04001677 context->recordError(gl::Error(GL_INVALID_OPERATION));
1678 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001679 }
1680
1681 // Non-power of 2 ES2 check
1682 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1683 {
1684 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001685 context->recordError(gl::Error(GL_INVALID_OPERATION));
1686 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001687 }
1688
1689 // Cube completeness check
1690 if (target == GL_TEXTURE_CUBE_MAP)
1691 {
1692 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1693 if (!textureCube->isCubeComplete())
1694 {
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
1700 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001701 }
1702}
1703
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001704void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1705{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001706 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001707
Geoff Langbfdea662014-07-23 14:16:32 -04001708 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001709 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001710 {
Geoff Langb1196682014-07-23 13:47:29 -04001711 if (n < 0)
1712 {
1713 context->recordError(gl::Error(GL_INVALID_VALUE));
1714 return;
1715 }
1716
Geoff Langbfdea662014-07-23 14:16:32 -04001717 for (int i = 0; i < n; i++)
1718 {
1719 fences[i] = context->createFenceNV();
1720 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001721 }
1722}
1723
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001724void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1725{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001726 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001727
Geoff Langbfdea662014-07-23 14:16:32 -04001728 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001729 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001730 {
Geoff Langb1196682014-07-23 13:47:29 -04001731 if (n < 0)
1732 {
1733 context->recordError(gl::Error(GL_INVALID_VALUE));
1734 return;
1735 }
1736
Geoff Langbfdea662014-07-23 14:16:32 -04001737 for (int i = 0; i < n; i++)
1738 {
1739 framebuffers[i] = context->createFramebuffer();
1740 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001741 }
1742}
1743
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001744void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1745{
1746 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1747
Geoff Langbfdea662014-07-23 14:16:32 -04001748 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001749 if (context)
1750 {
1751 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001752 {
Geoff Langb1196682014-07-23 13:47:29 -04001753 context->recordError(gl::Error(GL_INVALID_VALUE));
1754 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001755 }
Geoff Langbfdea662014-07-23 14:16:32 -04001756
1757 for (GLsizei i = 0; i < n; i++)
1758 {
1759 ids[i] = context->createQuery();
1760 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001761 }
1762}
1763
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001764void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1765{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001766 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001767
Geoff Langbfdea662014-07-23 14:16:32 -04001768 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001769 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001770 {
Geoff Langb1196682014-07-23 13:47:29 -04001771 if (n < 0)
1772 {
1773 context->recordError(gl::Error(GL_INVALID_VALUE));
1774 return;
1775 }
1776
Geoff Langbfdea662014-07-23 14:16:32 -04001777 for (int i = 0; i < n; i++)
1778 {
1779 renderbuffers[i] = context->createRenderbuffer();
1780 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001781 }
1782}
1783
1784void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1785{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001786 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001787
Geoff Langbfdea662014-07-23 14:16:32 -04001788 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001789 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001790 {
Geoff Langb1196682014-07-23 13:47:29 -04001791 if (n < 0)
1792 {
1793 context->recordError(gl::Error(GL_INVALID_VALUE));
1794 return;
1795 }
1796
Geoff Langbfdea662014-07-23 14:16:32 -04001797 for (int i = 0; i < n; i++)
1798 {
1799 textures[i] = context->createTexture();
1800 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001801 }
1802}
1803
daniel@transgaming.com85423182010-04-22 13:35:27 +00001804void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001805{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001806 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001807 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001808 program, index, bufsize, length, size, type, name);
1809
Geoff Langbfdea662014-07-23 14:16:32 -04001810 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001811 if (context)
1812 {
Geoff Langb1196682014-07-23 13:47:29 -04001813 if (bufsize < 0)
1814 {
1815 context->recordError(gl::Error(GL_INVALID_VALUE));
1816 return;
1817 }
1818
Geoff Langbfdea662014-07-23 14:16:32 -04001819 gl::Program *programObject = context->getProgram(program);
1820
1821 if (!programObject)
1822 {
1823 if (context->getShader(program))
1824 {
Geoff Langb1196682014-07-23 13:47:29 -04001825 context->recordError(gl::Error(GL_INVALID_OPERATION));
1826 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001827 }
1828 else
1829 {
Geoff Langb1196682014-07-23 13:47:29 -04001830 context->recordError(gl::Error(GL_INVALID_VALUE));
1831 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001832 }
1833 }
1834
1835 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001836 {
Geoff Langb1196682014-07-23 13:47:29 -04001837 context->recordError(gl::Error(GL_INVALID_VALUE));
1838 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001839 }
1840
Geoff Langbfdea662014-07-23 14:16:32 -04001841 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001842 }
1843}
1844
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001845void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001846{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001847 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001848 "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 +00001849 program, index, bufsize, length, size, type, name);
1850
Geoff Langbfdea662014-07-23 14:16:32 -04001851
1852 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001853 if (context)
1854 {
Geoff Langb1196682014-07-23 13:47:29 -04001855 if (bufsize < 0)
1856 {
1857 context->recordError(gl::Error(GL_INVALID_VALUE));
1858 return;
1859 }
1860
Geoff Langbfdea662014-07-23 14:16:32 -04001861 gl::Program *programObject = context->getProgram(program);
1862
1863 if (!programObject)
1864 {
1865 if (context->getShader(program))
1866 {
Geoff Langb1196682014-07-23 13:47:29 -04001867 context->recordError(gl::Error(GL_INVALID_OPERATION));
1868 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001869 }
1870 else
1871 {
Geoff Langb1196682014-07-23 13:47:29 -04001872 context->recordError(gl::Error(GL_INVALID_VALUE));
1873 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001874 }
1875 }
1876
1877 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001878 {
Geoff Langb1196682014-07-23 13:47:29 -04001879 context->recordError(gl::Error(GL_INVALID_VALUE));
1880 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001881 }
1882
Geoff Langbfdea662014-07-23 14:16:32 -04001883 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001884 }
1885}
1886
1887void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1888{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001889 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 +00001890 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001891
Geoff Langbfdea662014-07-23 14:16:32 -04001892 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001893 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001894 {
Geoff Langb1196682014-07-23 13:47:29 -04001895 if (maxcount < 0)
1896 {
1897 context->recordError(gl::Error(GL_INVALID_VALUE));
1898 return;
1899 }
1900
Geoff Langbfdea662014-07-23 14:16:32 -04001901 gl::Program *programObject = context->getProgram(program);
1902
1903 if (!programObject)
1904 {
1905 if (context->getShader(program))
1906 {
Geoff Langb1196682014-07-23 13:47:29 -04001907 context->recordError(gl::Error(GL_INVALID_OPERATION));
1908 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001909 }
1910 else
1911 {
Geoff Langb1196682014-07-23 13:47:29 -04001912 context->recordError(gl::Error(GL_INVALID_VALUE));
1913 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001914 }
1915 }
1916
1917 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001918 }
1919}
1920
Geoff Langb1196682014-07-23 13:47:29 -04001921GLint __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001922{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001923 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001924
Geoff Langbfdea662014-07-23 14:16:32 -04001925 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001926 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001927 {
Geoff Langbfdea662014-07-23 14:16:32 -04001928 gl::Program *programObject = context->getProgram(program);
1929
1930 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001931 {
Geoff Langbfdea662014-07-23 14:16:32 -04001932 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001933 {
Geoff Langb1196682014-07-23 13:47:29 -04001934 context->recordError(gl::Error(GL_INVALID_OPERATION));
1935 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001936 }
Geoff Langbfdea662014-07-23 14:16:32 -04001937 else
1938 {
Geoff Langb1196682014-07-23 13:47:29 -04001939 context->recordError(gl::Error(GL_INVALID_VALUE));
1940 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001941 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001942 }
Geoff Langbfdea662014-07-23 14:16:32 -04001943
1944 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1945 if (!programObject->isLinked() || !programBinary)
1946 {
Geoff Langb1196682014-07-23 13:47:29 -04001947 context->recordError(gl::Error(GL_INVALID_OPERATION));
1948 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001949 }
1950
1951 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001952 }
1953
1954 return -1;
1955}
1956
1957void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1958{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001959 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001960
Geoff Langbfdea662014-07-23 14:16:32 -04001961 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001962 if (context)
1963 {
1964 GLenum nativeType;
1965 unsigned int numParams = 0;
1966 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001967 {
Geoff Langbfdea662014-07-23 14:16:32 -04001968 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001969 }
Geoff Langbfdea662014-07-23 14:16:32 -04001970
1971 if (nativeType == GL_BOOL)
1972 {
1973 context->getBooleanv(pname, params);
1974 }
1975 else
1976 {
1977 CastStateValues(context, nativeType, pname, numParams, params);
1978 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979 }
1980}
1981
1982void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1983{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001984 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 +00001985
Geoff Langbfdea662014-07-23 14:16:32 -04001986 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001987 if (context)
1988 {
1989 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001990 {
Geoff Langb1196682014-07-23 13:47:29 -04001991 context->recordError(gl::Error(GL_INVALID_ENUM));
1992 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001993 }
Geoff Langbfdea662014-07-23 14:16:32 -04001994
1995 if (!gl::ValidBufferParameter(context, pname))
1996 {
Geoff Langb1196682014-07-23 13:47:29 -04001997 context->recordError(gl::Error(GL_INVALID_ENUM));
1998 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001999 }
2000
2001 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
2002
2003 if (!buffer)
2004 {
2005 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04002006 context->recordError(gl::Error(GL_INVALID_OPERATION));
2007 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002008 }
2009
2010 switch (pname)
2011 {
2012 case GL_BUFFER_USAGE:
2013 *params = static_cast<GLint>(buffer->getUsage());
2014 break;
2015 case GL_BUFFER_SIZE:
2016 *params = gl::clampCast<GLint>(buffer->getSize());
2017 break;
2018 case GL_BUFFER_ACCESS_FLAGS:
2019 *params = buffer->getAccessFlags();
2020 break;
2021 case GL_BUFFER_MAPPED:
2022 *params = static_cast<GLint>(buffer->isMapped());
2023 break;
2024 case GL_BUFFER_MAP_OFFSET:
2025 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2026 break;
2027 case GL_BUFFER_MAP_LENGTH:
2028 *params = gl::clampCast<GLint>(buffer->getMapLength());
2029 break;
2030 default: UNREACHABLE(); break;
2031 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002032 }
2033}
2034
2035GLenum __stdcall glGetError(void)
2036{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002037 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002038
2039 gl::Context *context = gl::getContext();
2040
2041 if (context)
2042 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002043 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002044 }
2045
2046 return GL_NO_ERROR;
2047}
2048
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002049void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
2050{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002051 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002052
Geoff Langbfdea662014-07-23 14:16:32 -04002053 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002054 if (context)
2055 {
2056 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2057
2058 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002059 {
Geoff Langb1196682014-07-23 13:47:29 -04002060 context->recordError(gl::Error(GL_INVALID_OPERATION));
2061 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002062 }
Geoff Langbfdea662014-07-23 14:16:32 -04002063
2064 if (fenceObject->isFence() != GL_TRUE)
2065 {
Geoff Langb1196682014-07-23 13:47:29 -04002066 context->recordError(gl::Error(GL_INVALID_OPERATION));
2067 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002068 }
2069
2070 switch (pname)
2071 {
2072 case GL_FENCE_STATUS_NV:
2073 case GL_FENCE_CONDITION_NV:
2074 break;
2075
Geoff Langb1196682014-07-23 13:47:29 -04002076 default:
2077 context->recordError(gl::Error(GL_INVALID_ENUM));
2078 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002079 }
2080
2081 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002082 }
2083}
2084
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002085void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2086{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002087 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002088
Geoff Langbfdea662014-07-23 14:16:32 -04002089 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002090 if (context)
2091 {
2092 GLenum nativeType;
2093 unsigned int numParams = 0;
2094 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002095 {
Geoff Langbfdea662014-07-23 14:16:32 -04002096 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002097 }
Geoff Langbfdea662014-07-23 14:16:32 -04002098
2099 if (nativeType == GL_FLOAT)
2100 {
2101 context->getFloatv(pname, params);
2102 }
2103 else
2104 {
2105 CastStateValues(context, nativeType, pname, numParams, params);
2106 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002107 }
2108}
2109
2110void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2111{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002112 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 +00002113 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002114
Geoff Langbfdea662014-07-23 14:16:32 -04002115 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002116 if (context)
2117 {
2118 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002119 {
Geoff Langb1196682014-07-23 13:47:29 -04002120 context->recordError(gl::Error(GL_INVALID_ENUM));
2121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002122 }
2123
2124 int clientVersion = context->getClientVersion();
2125
2126 switch (pname)
2127 {
2128 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2129 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2130 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2131 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2132 break;
Geoff Langb1196682014-07-23 13:47:29 -04002133
Geoff Langbfdea662014-07-23 14:16:32 -04002134 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2135 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002136 {
Geoff Langb1196682014-07-23 13:47:29 -04002137 context->recordError(gl::Error(GL_INVALID_ENUM));
2138 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002139 }
Geoff Langbfdea662014-07-23 14:16:32 -04002140 break;
Geoff Langb1196682014-07-23 13:47:29 -04002141
Geoff Langbfdea662014-07-23 14:16:32 -04002142 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2143 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2144 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2145 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2146 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2147 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2148 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2149 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2150 if (clientVersion < 3)
2151 {
Geoff Langb1196682014-07-23 13:47:29 -04002152 context->recordError(gl::Error(GL_INVALID_ENUM));
2153 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002154 }
2155 break;
Geoff Langb1196682014-07-23 13:47:29 -04002156
Geoff Langbfdea662014-07-23 14:16:32 -04002157 default:
Geoff Langb1196682014-07-23 13:47:29 -04002158 context->recordError(gl::Error(GL_INVALID_ENUM));
2159 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002160 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002161
Geoff Langbfdea662014-07-23 14:16:32 -04002162 // Determine if the attachment is a valid enum
2163 switch (attachment)
2164 {
2165 case GL_BACK:
2166 case GL_FRONT:
2167 case GL_DEPTH:
2168 case GL_STENCIL:
2169 case GL_DEPTH_STENCIL_ATTACHMENT:
2170 if (clientVersion < 3)
2171 {
Geoff Langb1196682014-07-23 13:47:29 -04002172 context->recordError(gl::Error(GL_INVALID_ENUM));
2173 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002174 }
2175 break;
2176
2177 case GL_DEPTH_ATTACHMENT:
2178 case GL_STENCIL_ATTACHMENT:
2179 break;
2180
2181 default:
2182 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2183 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2184 {
Geoff Langb1196682014-07-23 13:47:29 -04002185 context->recordError(gl::Error(GL_INVALID_ENUM));
2186 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002187 }
2188 break;
2189 }
2190
2191 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2192 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2193
2194 if (framebufferHandle == 0)
2195 {
2196 if (clientVersion < 3)
2197 {
Geoff Langb1196682014-07-23 13:47:29 -04002198 context->recordError(gl::Error(GL_INVALID_OPERATION));
2199 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002200 }
2201
2202 switch (attachment)
2203 {
2204 case GL_BACK:
2205 case GL_DEPTH:
2206 case GL_STENCIL:
2207 break;
Geoff Langb1196682014-07-23 13:47:29 -04002208
Geoff Langbfdea662014-07-23 14:16:32 -04002209 default:
Geoff Langb1196682014-07-23 13:47:29 -04002210 context->recordError(gl::Error(GL_INVALID_OPERATION));
2211 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002212 }
2213 }
2214 else
2215 {
2216 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2217 {
2218 // Valid attachment query
2219 }
2220 else
2221 {
2222 switch (attachment)
2223 {
2224 case GL_DEPTH_ATTACHMENT:
2225 case GL_STENCIL_ATTACHMENT:
2226 break;
Geoff Langb1196682014-07-23 13:47:29 -04002227
Geoff Langbfdea662014-07-23 14:16:32 -04002228 case GL_DEPTH_STENCIL_ATTACHMENT:
2229 if (framebuffer->hasValidDepthStencil())
2230 {
Geoff Langb1196682014-07-23 13:47:29 -04002231 context->recordError(gl::Error(GL_INVALID_OPERATION));
2232 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002233 }
2234 break;
Geoff Langb1196682014-07-23 13:47:29 -04002235
Geoff Langbfdea662014-07-23 14:16:32 -04002236 default:
Geoff Langb1196682014-07-23 13:47:29 -04002237 context->recordError(gl::Error(GL_INVALID_OPERATION));
2238 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002239 }
2240 }
2241 }
2242
2243 GLenum attachmentType = GL_NONE;
2244 GLuint attachmentHandle = 0;
2245 GLuint attachmentLevel = 0;
2246 GLuint attachmentLayer = 0;
2247
2248 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2249
2250 if (attachmentObject)
2251 {
2252 attachmentType = attachmentObject->type();
2253 attachmentHandle = attachmentObject->id();
2254 attachmentLevel = attachmentObject->mipLevel();
2255 attachmentLayer = attachmentObject->layer();
2256 }
2257
2258 GLenum attachmentObjectType; // Type category
2259 if (framebufferHandle == 0)
2260 {
2261 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2262 }
2263 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2264 {
2265 attachmentObjectType = attachmentType;
2266 }
2267 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2268 {
2269 attachmentObjectType = GL_TEXTURE;
2270 }
2271 else
2272 {
2273 UNREACHABLE();
2274 return;
2275 }
2276
2277 if (attachmentObjectType == GL_NONE)
2278 {
2279 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2280 // is NONE, then querying any other pname will generate INVALID_ENUM.
2281
2282 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2283 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2284 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002285
Geoff Lang646559f2013-08-15 11:08:15 -04002286 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002287 {
Geoff Lang646559f2013-08-15 11:08:15 -04002288 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002289 *params = attachmentObjectType;
2290 break;
2291
Geoff Lang646559f2013-08-15 11:08:15 -04002292 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002293 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002294 {
Geoff Langb1196682014-07-23 13:47:29 -04002295 context->recordError(gl::Error(GL_INVALID_ENUM));
2296 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002297 }
Geoff Langbfdea662014-07-23 14:16:32 -04002298 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002299 break;
2300
2301 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002302 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002303 {
Geoff Langb1196682014-07-23 13:47:29 -04002304 context->recordError(gl::Error(GL_INVALID_ENUM));
2305 return;
Geoff Lang646559f2013-08-15 11:08:15 -04002306 }
2307 else
2308 {
Geoff Langb1196682014-07-23 13:47:29 -04002309 context->recordError(gl::Error(GL_INVALID_OPERATION));
2310 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002311 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002312 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002313 }
Geoff Langbfdea662014-07-23 14:16:32 -04002314 else
2315 {
2316 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2317 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2318 ASSERT(attachmentObject != NULL);
2319
2320 switch (pname)
2321 {
2322 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2323 *params = attachmentObjectType;
2324 break;
2325
2326 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2327 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2328 {
Geoff Langb1196682014-07-23 13:47:29 -04002329 context->recordError(gl::Error(GL_INVALID_ENUM));
2330 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002331 }
2332 *params = attachmentHandle;
2333 break;
2334
2335 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2336 if (attachmentObjectType != GL_TEXTURE)
2337 {
Geoff Langb1196682014-07-23 13:47:29 -04002338 context->recordError(gl::Error(GL_INVALID_ENUM));
2339 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002340 }
2341 *params = attachmentLevel;
2342 break;
2343
2344 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2345 if (attachmentObjectType != GL_TEXTURE)
2346 {
Geoff Langb1196682014-07-23 13:47:29 -04002347 context->recordError(gl::Error(GL_INVALID_ENUM));
2348 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002349 }
2350 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2351 break;
2352
2353 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2354 *params = attachmentObject->getRedSize();
2355 break;
2356
2357 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2358 *params = attachmentObject->getGreenSize();
2359 break;
2360
2361 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2362 *params = attachmentObject->getBlueSize();
2363 break;
2364
2365 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2366 *params = attachmentObject->getAlphaSize();
2367 break;
2368
2369 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2370 *params = attachmentObject->getDepthSize();
2371 break;
2372
2373 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2374 *params = attachmentObject->getStencilSize();
2375 break;
2376
2377 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2378 if (attachment == GL_DEPTH_STENCIL)
2379 {
Geoff Langb1196682014-07-23 13:47:29 -04002380 context->recordError(gl::Error(GL_INVALID_OPERATION));
2381 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002382 }
2383 *params = attachmentObject->getComponentType();
2384 break;
2385
2386 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2387 *params = attachmentObject->getColorEncoding();
2388 break;
2389
2390 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2391 if (attachmentObjectType != GL_TEXTURE)
2392 {
Geoff Langb1196682014-07-23 13:47:29 -04002393 context->recordError(gl::Error(GL_INVALID_ENUM));
2394 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002395 }
2396 *params = attachmentLayer;
2397 break;
2398
2399 default:
2400 UNREACHABLE();
2401 break;
2402 }
2403 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002404 }
2405}
2406
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002407GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2408{
2409 EVENT("()");
2410
Geoff Langbfdea662014-07-23 14:16:32 -04002411 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002412
Geoff Langbfdea662014-07-23 14:16:32 -04002413 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002414 {
Geoff Langbfdea662014-07-23 14:16:32 -04002415 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002416 }
Geoff Langbfdea662014-07-23 14:16:32 -04002417
2418 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002419}
2420
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002421void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2422{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002423 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002424
Geoff Langbfdea662014-07-23 14:16:32 -04002425 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002426 if (context)
2427 {
2428 GLenum nativeType;
2429 unsigned int numParams = 0;
2430
2431 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002432 {
Geoff Langbfdea662014-07-23 14:16:32 -04002433 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002434 }
Geoff Langbfdea662014-07-23 14:16:32 -04002435
2436 if (nativeType == GL_INT)
2437 {
2438 context->getIntegerv(pname, params);
2439 }
2440 else
2441 {
2442 CastStateValues(context, nativeType, pname, numParams, params);
2443 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002444 }
2445}
2446
2447void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2448{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002449 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002450
Geoff Langbfdea662014-07-23 14:16:32 -04002451 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002452 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002453 {
Geoff Langbfdea662014-07-23 14:16:32 -04002454 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002455
Geoff Langbfdea662014-07-23 14:16:32 -04002456 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002457 {
Geoff Langb1196682014-07-23 13:47:29 -04002458 context->recordError(gl::Error(GL_INVALID_VALUE));
2459 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002460 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002461
Geoff Langbfdea662014-07-23 14:16:32 -04002462 if (context->getClientVersion() < 3)
2463 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002464 switch (pname)
2465 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002466 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002467 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002468 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002469 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002470 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002471 context->recordError(gl::Error(GL_INVALID_ENUM));
2472 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002473 }
2474 }
Geoff Langbfdea662014-07-23 14:16:32 -04002475
2476 switch (pname)
2477 {
2478 case GL_DELETE_STATUS:
2479 *params = programObject->isFlaggedForDeletion();
2480 return;
2481 case GL_LINK_STATUS:
2482 *params = programObject->isLinked();
2483 return;
2484 case GL_VALIDATE_STATUS:
2485 *params = programObject->isValidated();
2486 return;
2487 case GL_INFO_LOG_LENGTH:
2488 *params = programObject->getInfoLogLength();
2489 return;
2490 case GL_ATTACHED_SHADERS:
2491 *params = programObject->getAttachedShadersCount();
2492 return;
2493 case GL_ACTIVE_ATTRIBUTES:
2494 *params = programObject->getActiveAttributeCount();
2495 return;
2496 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2497 *params = programObject->getActiveAttributeMaxLength();
2498 return;
2499 case GL_ACTIVE_UNIFORMS:
2500 *params = programObject->getActiveUniformCount();
2501 return;
2502 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2503 *params = programObject->getActiveUniformMaxLength();
2504 return;
2505 case GL_PROGRAM_BINARY_LENGTH_OES:
2506 *params = programObject->getProgramBinaryLength();
2507 return;
2508 case GL_ACTIVE_UNIFORM_BLOCKS:
2509 *params = programObject->getActiveUniformBlockCount();
2510 return;
2511 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2512 *params = programObject->getActiveUniformBlockMaxLength();
2513 break;
2514 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2515 *params = programObject->getTransformFeedbackBufferMode();
2516 break;
2517 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2518 *params = programObject->getTransformFeedbackVaryingCount();
2519 break;
2520 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2521 *params = programObject->getTransformFeedbackVaryingMaxLength();
2522 break;
Geoff Langb1196682014-07-23 13:47:29 -04002523
Geoff Langbfdea662014-07-23 14:16:32 -04002524 default:
Geoff Langb1196682014-07-23 13:47:29 -04002525 context->recordError(gl::Error(GL_INVALID_ENUM));
2526 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002527 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002528 }
2529}
2530
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002531void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002532{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002533 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 +00002534 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002535
Geoff Langbfdea662014-07-23 14:16:32 -04002536 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002537 if (context)
2538 {
Geoff Langb1196682014-07-23 13:47:29 -04002539 if (bufsize < 0)
2540 {
2541 context->recordError(gl::Error(GL_INVALID_VALUE));
2542 return;
2543 }
2544
Geoff Langbfdea662014-07-23 14:16:32 -04002545 gl::Program *programObject = context->getProgram(program);
2546
2547 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002548 {
Geoff Langb1196682014-07-23 13:47:29 -04002549 context->recordError(gl::Error(GL_INVALID_VALUE));
2550 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002551 }
2552
Geoff Langbfdea662014-07-23 14:16:32 -04002553 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002554 }
2555}
2556
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002557void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2558{
2559 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2560
Geoff Langbfdea662014-07-23 14:16:32 -04002561 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002562 if (context)
2563 {
2564 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002565 {
Geoff Langb1196682014-07-23 13:47:29 -04002566 context->recordError(gl::Error(GL_INVALID_ENUM));
2567 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002568 }
Geoff Langbfdea662014-07-23 14:16:32 -04002569
2570 switch (pname)
2571 {
2572 case GL_CURRENT_QUERY_EXT:
2573 params[0] = context->getState().getActiveQueryId(target);
2574 break;
2575
2576 default:
Geoff Langb1196682014-07-23 13:47:29 -04002577 context->recordError(gl::Error(GL_INVALID_ENUM));
2578 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002579 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002580 }
2581}
2582
2583void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2584{
2585 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2586
Geoff Langbfdea662014-07-23 14:16:32 -04002587 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002588 if (context)
2589 {
2590 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2591
2592 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002593 {
Geoff Langb1196682014-07-23 13:47:29 -04002594 context->recordError(gl::Error(GL_INVALID_OPERATION));
2595 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002596 }
Geoff Langbfdea662014-07-23 14:16:32 -04002597
2598 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2599 {
Geoff Langb1196682014-07-23 13:47:29 -04002600 context->recordError(gl::Error(GL_INVALID_OPERATION));
2601 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002602 }
2603
2604 switch(pname)
2605 {
2606 case GL_QUERY_RESULT_EXT:
2607 params[0] = queryObject->getResult();
2608 break;
2609 case GL_QUERY_RESULT_AVAILABLE_EXT:
2610 params[0] = queryObject->isResultAvailable();
2611 break;
2612 default:
Geoff Langb1196682014-07-23 13:47:29 -04002613 context->recordError(gl::Error(GL_INVALID_ENUM));
2614 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002615 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002616 }
2617}
2618
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002619void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2620{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002621 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 +00002622
Geoff Langbfdea662014-07-23 14:16:32 -04002623 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002624 if (context)
2625 {
2626 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002627 {
Geoff Langb1196682014-07-23 13:47:29 -04002628 context->recordError(gl::Error(GL_INVALID_ENUM));
2629 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002630 }
Geoff Langbfdea662014-07-23 14:16:32 -04002631
2632 if (context->getState().getRenderbufferId() == 0)
2633 {
Geoff Langb1196682014-07-23 13:47:29 -04002634 context->recordError(gl::Error(GL_INVALID_OPERATION));
2635 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002636 }
2637
2638 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2639
2640 switch (pname)
2641 {
2642 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2643 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2644 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2645 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2646 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2647 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2648 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2649 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2650 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002651
Geoff Langbfdea662014-07-23 14:16:32 -04002652 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2653 if (!context->getExtensions().framebufferMultisample)
2654 {
Geoff Langb1196682014-07-23 13:47:29 -04002655 context->recordError(gl::Error(GL_INVALID_ENUM));
2656 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002657 }
2658 *params = renderbuffer->getSamples();
2659 break;
Geoff Langb1196682014-07-23 13:47:29 -04002660
Geoff Langbfdea662014-07-23 14:16:32 -04002661 default:
Geoff Langb1196682014-07-23 13:47:29 -04002662 context->recordError(gl::Error(GL_INVALID_ENUM));
2663 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002664 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002665 }
2666}
2667
2668void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2669{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002670 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002671
Geoff Langbfdea662014-07-23 14:16:32 -04002672 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002673 if (context)
2674 {
2675 gl::Shader *shaderObject = context->getShader(shader);
2676
2677 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002678 {
Geoff Langb1196682014-07-23 13:47:29 -04002679 context->recordError(gl::Error(GL_INVALID_VALUE));
2680 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002681 }
Geoff Langbfdea662014-07-23 14:16:32 -04002682
2683 switch (pname)
2684 {
2685 case GL_SHADER_TYPE:
2686 *params = shaderObject->getType();
2687 return;
2688 case GL_DELETE_STATUS:
2689 *params = shaderObject->isFlaggedForDeletion();
2690 return;
2691 case GL_COMPILE_STATUS:
2692 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2693 return;
2694 case GL_INFO_LOG_LENGTH:
2695 *params = shaderObject->getInfoLogLength();
2696 return;
2697 case GL_SHADER_SOURCE_LENGTH:
2698 *params = shaderObject->getSourceLength();
2699 return;
2700 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2701 *params = shaderObject->getTranslatedSourceLength();
2702 return;
Geoff Langb1196682014-07-23 13:47:29 -04002703
Geoff Langbfdea662014-07-23 14:16:32 -04002704 default:
Geoff Langb1196682014-07-23 13:47:29 -04002705 context->recordError(gl::Error(GL_INVALID_ENUM));
2706 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002707 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002708 }
2709}
2710
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002711void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002712{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002713 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 +00002714 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002715
Geoff Langbfdea662014-07-23 14:16:32 -04002716 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002717 if (context)
2718 {
Geoff Langb1196682014-07-23 13:47:29 -04002719 if (bufsize < 0)
2720 {
2721 context->recordError(gl::Error(GL_INVALID_VALUE));
2722 return;
2723 }
2724
Geoff Langbfdea662014-07-23 14:16:32 -04002725 gl::Shader *shaderObject = context->getShader(shader);
2726
2727 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002728 {
Geoff Langb1196682014-07-23 13:47:29 -04002729 context->recordError(gl::Error(GL_INVALID_VALUE));
2730 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002731 }
2732
Geoff Langbfdea662014-07-23 14:16:32 -04002733 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002734 }
2735}
2736
2737void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2738{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002739 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 +00002740 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002741
Geoff Langb1196682014-07-23 13:47:29 -04002742 gl::Context *context = gl::getNonLostContext();
2743 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002744 {
Geoff Langb1196682014-07-23 13:47:29 -04002745 switch (shadertype)
2746 {
2747 case GL_VERTEX_SHADER:
2748 case GL_FRAGMENT_SHADER:
2749 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002750
Geoff Langb1196682014-07-23 13:47:29 -04002751 default:
2752 context->recordError(gl::Error(GL_INVALID_ENUM));
2753 return;
2754 }
2755
2756 switch (precisiontype)
2757 {
2758 case GL_LOW_FLOAT:
2759 case GL_MEDIUM_FLOAT:
2760 case GL_HIGH_FLOAT:
2761 // Assume IEEE 754 precision
2762 range[0] = 127;
2763 range[1] = 127;
2764 *precision = 23;
2765 break;
2766
2767 case GL_LOW_INT:
2768 case GL_MEDIUM_INT:
2769 case GL_HIGH_INT:
2770 // Some (most) hardware only supports single-precision floating-point numbers,
2771 // which can accurately represent integers up to +/-16777216
2772 range[0] = 24;
2773 range[1] = 24;
2774 *precision = 0;
2775 break;
2776
2777 default:
2778 context->recordError(gl::Error(GL_INVALID_ENUM));
2779 return;
2780 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002781 }
2782}
2783
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002784void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002785{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002786 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 +00002787 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002788
Geoff Langbfdea662014-07-23 14:16:32 -04002789 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002790 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002791 {
Geoff Langb1196682014-07-23 13:47:29 -04002792 if (bufsize < 0)
2793 {
2794 context->recordError(gl::Error(GL_INVALID_VALUE));
2795 return;
2796 }
2797
Geoff Langbfdea662014-07-23 14:16:32 -04002798 gl::Shader *shaderObject = context->getShader(shader);
2799
2800 if (!shaderObject)
2801 {
Geoff Langb1196682014-07-23 13:47:29 -04002802 context->recordError(gl::Error(GL_INVALID_OPERATION));
2803 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002804 }
2805
2806 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002807 }
2808}
2809
zmo@google.coma574f782011-10-03 21:45:23 +00002810void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2811{
2812 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2813 shader, bufsize, length, source);
2814
Geoff Langbfdea662014-07-23 14:16:32 -04002815 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002816 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +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->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002833 }
2834}
2835
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002836const GLubyte* __stdcall glGetString(GLenum name)
2837{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002838 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002839
Geoff Langbfdea662014-07-23 14:16:32 -04002840 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002841
Geoff Langbfdea662014-07-23 14:16:32 -04002842 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843 {
Geoff Langbfdea662014-07-23 14:16:32 -04002844 case GL_VENDOR:
2845 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002846
Geoff Langbfdea662014-07-23 14:16:32 -04002847 case GL_RENDERER:
2848 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002849
Geoff Langbfdea662014-07-23 14:16:32 -04002850 case GL_VERSION:
2851 if (context->getClientVersion() == 2)
2852 {
2853 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2854 }
2855 else
2856 {
2857 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2858 }
Geoff Langb1196682014-07-23 13:47:29 -04002859
Geoff Langbfdea662014-07-23 14:16:32 -04002860 case GL_SHADING_LANGUAGE_VERSION:
2861 if (context->getClientVersion() == 2)
2862 {
2863 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2864 }
2865 else
2866 {
2867 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2868 }
Geoff Langb1196682014-07-23 13:47:29 -04002869
Geoff Langbfdea662014-07-23 14:16:32 -04002870 case GL_EXTENSIONS:
2871 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002872
Geoff Langbfdea662014-07-23 14:16:32 -04002873 default:
Geoff Langb1196682014-07-23 13:47:29 -04002874 if (context)
2875 {
2876 context->recordError(gl::Error(GL_INVALID_ENUM));
2877 }
2878 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002879 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002880}
2881
2882void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2883{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002884 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 +00002885
Geoff Langbfdea662014-07-23 14:16:32 -04002886 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002887 if (context)
2888 {
2889 gl::Texture *texture = context->getTargetTexture(target);
2890
2891 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002892 {
Geoff Langb1196682014-07-23 13:47:29 -04002893 context->recordError(gl::Error(GL_INVALID_ENUM));
2894 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002895 }
Geoff Langbfdea662014-07-23 14:16:32 -04002896
2897 switch (pname)
2898 {
2899 case GL_TEXTURE_MAG_FILTER:
2900 *params = (GLfloat)texture->getSamplerState().magFilter;
2901 break;
2902 case GL_TEXTURE_MIN_FILTER:
2903 *params = (GLfloat)texture->getSamplerState().minFilter;
2904 break;
2905 case GL_TEXTURE_WRAP_S:
2906 *params = (GLfloat)texture->getSamplerState().wrapS;
2907 break;
2908 case GL_TEXTURE_WRAP_T:
2909 *params = (GLfloat)texture->getSamplerState().wrapT;
2910 break;
2911 case GL_TEXTURE_WRAP_R:
2912 if (context->getClientVersion() < 3)
2913 {
Geoff Langb1196682014-07-23 13:47:29 -04002914 context->recordError(gl::Error(GL_INVALID_ENUM));
2915 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002916 }
2917 *params = (GLfloat)texture->getSamplerState().wrapR;
2918 break;
2919 case GL_TEXTURE_IMMUTABLE_FORMAT:
2920 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2921 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2922 break;
2923 case GL_TEXTURE_IMMUTABLE_LEVELS:
2924 if (context->getClientVersion() < 3)
2925 {
Geoff Langb1196682014-07-23 13:47:29 -04002926 context->recordError(gl::Error(GL_INVALID_ENUM));
2927 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002928 }
2929 *params = (GLfloat)texture->immutableLevelCount();
2930 break;
2931 case GL_TEXTURE_USAGE_ANGLE:
2932 *params = (GLfloat)texture->getUsage();
2933 break;
2934 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2935 if (!context->getExtensions().textureFilterAnisotropic)
2936 {
Geoff Langb1196682014-07-23 13:47:29 -04002937 context->recordError(gl::Error(GL_INVALID_ENUM));
2938 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002939 }
2940 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2941 break;
2942 case GL_TEXTURE_SWIZZLE_R:
2943 if (context->getClientVersion() < 3)
2944 {
Geoff Langb1196682014-07-23 13:47:29 -04002945 context->recordError(gl::Error(GL_INVALID_ENUM));
2946 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002947 }
2948 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2949 break;
2950 case GL_TEXTURE_SWIZZLE_G:
2951 if (context->getClientVersion() < 3)
2952 {
Geoff Langb1196682014-07-23 13:47:29 -04002953 context->recordError(gl::Error(GL_INVALID_ENUM));
2954 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002955 }
2956 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2957 break;
2958 case GL_TEXTURE_SWIZZLE_B:
2959 if (context->getClientVersion() < 3)
2960 {
Geoff Langb1196682014-07-23 13:47:29 -04002961 context->recordError(gl::Error(GL_INVALID_ENUM));
2962 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002963 }
2964 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2965 break;
2966 case GL_TEXTURE_SWIZZLE_A:
2967 if (context->getClientVersion() < 3)
2968 {
Geoff Langb1196682014-07-23 13:47:29 -04002969 context->recordError(gl::Error(GL_INVALID_ENUM));
2970 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002971 }
2972 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2973 break;
2974 case GL_TEXTURE_BASE_LEVEL:
2975 if (context->getClientVersion() < 3)
2976 {
Geoff Langb1196682014-07-23 13:47:29 -04002977 context->recordError(gl::Error(GL_INVALID_ENUM));
2978 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002979 }
2980 *params = (GLfloat)texture->getSamplerState().baseLevel;
2981 break;
2982 case GL_TEXTURE_MAX_LEVEL:
2983 if (context->getClientVersion() < 3)
2984 {
Geoff Langb1196682014-07-23 13:47:29 -04002985 context->recordError(gl::Error(GL_INVALID_ENUM));
2986 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002987 }
2988 *params = (GLfloat)texture->getSamplerState().maxLevel;
2989 break;
2990 case GL_TEXTURE_MIN_LOD:
2991 if (context->getClientVersion() < 3)
2992 {
Geoff Langb1196682014-07-23 13:47:29 -04002993 context->recordError(gl::Error(GL_INVALID_ENUM));
2994 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002995 }
2996 *params = texture->getSamplerState().minLod;
2997 break;
2998 case GL_TEXTURE_MAX_LOD:
2999 if (context->getClientVersion() < 3)
3000 {
Geoff Langb1196682014-07-23 13:47:29 -04003001 context->recordError(gl::Error(GL_INVALID_ENUM));
3002 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003003 }
3004 *params = texture->getSamplerState().maxLod;
3005 break;
Geoff Langb1196682014-07-23 13:47:29 -04003006
Geoff Langbfdea662014-07-23 14:16:32 -04003007 default:
Geoff Langb1196682014-07-23 13:47:29 -04003008 context->recordError(gl::Error(GL_INVALID_ENUM));
3009 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003010 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003011 }
3012}
3013
3014void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
3015{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003016 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 +00003017
Geoff Langbfdea662014-07-23 14:16:32 -04003018 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003019 if (context)
3020 {
3021 gl::Texture *texture = context->getTargetTexture(target);
3022
3023 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003024 {
Geoff Langb1196682014-07-23 13:47:29 -04003025 context->recordError(gl::Error(GL_INVALID_ENUM));
3026 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003027 }
Geoff Langbfdea662014-07-23 14:16:32 -04003028
3029 switch (pname)
3030 {
3031 case GL_TEXTURE_MAG_FILTER:
3032 *params = texture->getSamplerState().magFilter;
3033 break;
3034 case GL_TEXTURE_MIN_FILTER:
3035 *params = texture->getSamplerState().minFilter;
3036 break;
3037 case GL_TEXTURE_WRAP_S:
3038 *params = texture->getSamplerState().wrapS;
3039 break;
3040 case GL_TEXTURE_WRAP_T:
3041 *params = texture->getSamplerState().wrapT;
3042 break;
3043 case GL_TEXTURE_WRAP_R:
3044 if (context->getClientVersion() < 3)
3045 {
Geoff Langb1196682014-07-23 13:47:29 -04003046 context->recordError(gl::Error(GL_INVALID_ENUM));
3047 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003048 }
3049 *params = texture->getSamplerState().wrapR;
3050 break;
3051 case GL_TEXTURE_IMMUTABLE_FORMAT:
3052 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3053 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3054 break;
3055 case GL_TEXTURE_IMMUTABLE_LEVELS:
3056 if (context->getClientVersion() < 3)
3057 {
Geoff Langb1196682014-07-23 13:47:29 -04003058 context->recordError(gl::Error(GL_INVALID_ENUM));
3059 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003060 }
3061 *params = texture->immutableLevelCount();
3062 break;
3063 case GL_TEXTURE_USAGE_ANGLE:
3064 *params = texture->getUsage();
3065 break;
3066 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3067 if (!context->getExtensions().textureFilterAnisotropic)
3068 {
Geoff Langb1196682014-07-23 13:47:29 -04003069 context->recordError(gl::Error(GL_INVALID_ENUM));
3070 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003071 }
3072 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3073 break;
3074 case GL_TEXTURE_SWIZZLE_R:
3075 if (context->getClientVersion() < 3)
3076 {
Geoff Langb1196682014-07-23 13:47:29 -04003077 context->recordError(gl::Error(GL_INVALID_ENUM));
3078 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003079 }
3080 *params = texture->getSamplerState().swizzleRed;
3081 break;
3082 case GL_TEXTURE_SWIZZLE_G:
3083 if (context->getClientVersion() < 3)
3084 {
Geoff Langb1196682014-07-23 13:47:29 -04003085 context->recordError(gl::Error(GL_INVALID_ENUM));
3086 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003087 }
3088 *params = texture->getSamplerState().swizzleGreen;
3089 break;
3090 case GL_TEXTURE_SWIZZLE_B:
3091 if (context->getClientVersion() < 3)
3092 {
Geoff Langb1196682014-07-23 13:47:29 -04003093 context->recordError(gl::Error(GL_INVALID_ENUM));
3094 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003095 }
3096 *params = texture->getSamplerState().swizzleBlue;
3097 break;
3098 case GL_TEXTURE_SWIZZLE_A:
3099 if (context->getClientVersion() < 3)
3100 {
Geoff Langb1196682014-07-23 13:47:29 -04003101 context->recordError(gl::Error(GL_INVALID_ENUM));
3102 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003103 }
3104 *params = texture->getSamplerState().swizzleAlpha;
3105 break;
3106 case GL_TEXTURE_BASE_LEVEL:
3107 if (context->getClientVersion() < 3)
3108 {
Geoff Langb1196682014-07-23 13:47:29 -04003109 context->recordError(gl::Error(GL_INVALID_ENUM));
3110 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003111 }
3112 *params = texture->getSamplerState().baseLevel;
3113 break;
3114 case GL_TEXTURE_MAX_LEVEL:
3115 if (context->getClientVersion() < 3)
3116 {
Geoff Langb1196682014-07-23 13:47:29 -04003117 context->recordError(gl::Error(GL_INVALID_ENUM));
3118 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003119 }
3120 *params = texture->getSamplerState().maxLevel;
3121 break;
3122 case GL_TEXTURE_MIN_LOD:
3123 if (context->getClientVersion() < 3)
3124 {
Geoff Langb1196682014-07-23 13:47:29 -04003125 context->recordError(gl::Error(GL_INVALID_ENUM));
3126 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003127 }
3128 *params = (GLint)texture->getSamplerState().minLod;
3129 break;
3130 case GL_TEXTURE_MAX_LOD:
3131 if (context->getClientVersion() < 3)
3132 {
Geoff Langb1196682014-07-23 13:47:29 -04003133 context->recordError(gl::Error(GL_INVALID_ENUM));
3134 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003135 }
3136 *params = (GLint)texture->getSamplerState().maxLod;
3137 break;
Geoff Langb1196682014-07-23 13:47:29 -04003138
Geoff Langbfdea662014-07-23 14:16:32 -04003139 default:
Geoff Langb1196682014-07-23 13:47:29 -04003140 context->recordError(gl::Error(GL_INVALID_ENUM));
3141 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003142 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003143 }
3144}
3145
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003146void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3147{
3148 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3149 program, location, bufSize, params);
3150
Geoff Langbfdea662014-07-23 14:16:32 -04003151 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003152 if (context)
3153 {
Jamie Madill0063c512014-08-25 15:47:53 -04003154 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003155 {
Jamie Madill0063c512014-08-25 15:47:53 -04003156 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003157 }
3158
Jamie Madilla502c742014-08-28 17:19:13 -04003159 gl::Program *programObject = context->getProgram(program);
3160 ASSERT(programObject);
3161 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003162 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003163
Jamie Madill99a1e982014-08-25 15:47:54 -04003164 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003165 }
3166}
3167
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003168void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3169{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003170 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003171
Geoff Langbfdea662014-07-23 14:16:32 -04003172 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003173 if (context)
3174 {
Jamie Madill0063c512014-08-25 15:47:53 -04003175 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003176 {
Jamie Madill0063c512014-08-25 15:47:53 -04003177 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003178 }
Geoff Langbfdea662014-07-23 14:16:32 -04003179
Jamie Madilla502c742014-08-28 17:19:13 -04003180 gl::Program *programObject = context->getProgram(program);
3181 ASSERT(programObject);
3182 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003183 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003184
Jamie Madill99a1e982014-08-25 15:47:54 -04003185 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003186 }
3187}
3188
3189void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3190{
Geoff Langbfdea662014-07-23 14:16:32 -04003191 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003192 program, location, bufSize, params);
3193
Geoff Langbfdea662014-07-23 14:16:32 -04003194 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003195 if (context)
3196 {
Jamie Madill0063c512014-08-25 15:47:53 -04003197 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003198 {
Jamie Madill0063c512014-08-25 15:47:53 -04003199 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003200 }
3201
Jamie Madilla502c742014-08-28 17:19:13 -04003202 gl::Program *programObject = context->getProgram(program);
3203 ASSERT(programObject);
3204 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003205 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003206
Jamie Madill99a1e982014-08-25 15:47:54 -04003207 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208 }
3209}
3210
3211void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3212{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003213 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003214
Geoff Langbfdea662014-07-23 14:16:32 -04003215 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003216 if (context)
3217 {
Jamie Madill0063c512014-08-25 15:47:53 -04003218 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003219 {
Jamie Madill0063c512014-08-25 15:47:53 -04003220 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003221 }
Geoff Langbfdea662014-07-23 14:16:32 -04003222
Jamie Madilla502c742014-08-28 17:19:13 -04003223 gl::Program *programObject = context->getProgram(program);
3224 ASSERT(programObject);
3225 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003226 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003227
Jamie Madill99a1e982014-08-25 15:47:54 -04003228 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229 }
3230}
3231
Geoff Langb1196682014-07-23 13:47:29 -04003232GLint __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003234 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003235
Geoff Langbfdea662014-07-23 14:16:32 -04003236 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003237 if (context)
3238 {
Geoff Langb1196682014-07-23 13:47:29 -04003239 if (strstr(name, "gl_") == name)
3240 {
3241 return -1;
3242 }
3243
Geoff Langbfdea662014-07-23 14:16:32 -04003244 gl::Program *programObject = context->getProgram(program);
3245
3246 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003247 {
Geoff Langbfdea662014-07-23 14:16:32 -04003248 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003249 {
Geoff Langb1196682014-07-23 13:47:29 -04003250 context->recordError(gl::Error(GL_INVALID_OPERATION));
3251 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003252 }
Geoff Langbfdea662014-07-23 14:16:32 -04003253 else
3254 {
Geoff Langb1196682014-07-23 13:47:29 -04003255 context->recordError(gl::Error(GL_INVALID_VALUE));
3256 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003257 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003258 }
Geoff Langbfdea662014-07-23 14:16:32 -04003259
3260 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3261 if (!programObject->isLinked() || !programBinary)
3262 {
Geoff Langb1196682014-07-23 13:47:29 -04003263 context->recordError(gl::Error(GL_INVALID_OPERATION));
3264 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003265 }
3266
3267 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268 }
3269
3270 return -1;
3271}
3272
3273void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3274{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003275 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003276
Geoff Langbfdea662014-07-23 14:16:32 -04003277 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003278 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003279 {
Geoff Langbfdea662014-07-23 14:16:32 -04003280 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003281 {
Geoff Langb1196682014-07-23 13:47:29 -04003282 context->recordError(gl::Error(GL_INVALID_VALUE));
3283 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003284 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003285
Geoff Langbfdea662014-07-23 14:16:32 -04003286 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003287 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003288 {
3289 return;
3290 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003291
Geoff Langbfdea662014-07-23 14:16:32 -04003292 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3293 {
3294 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3295 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003296 {
Geoff Langbfdea662014-07-23 14:16:32 -04003297 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003298 }
3299 }
Geoff Langbfdea662014-07-23 14:16:32 -04003300 else
3301 {
3302 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3303 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003304 }
3305}
3306
3307void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3308{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003309 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003310
Geoff Langbfdea662014-07-23 14:16:32 -04003311 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003312 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003313 {
Geoff Langbfdea662014-07-23 14:16:32 -04003314 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003315 {
Geoff Langb1196682014-07-23 13:47:29 -04003316 context->recordError(gl::Error(GL_INVALID_VALUE));
3317 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003318 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003319
Geoff Langbfdea662014-07-23 14:16:32 -04003320 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003321
Geoff Langb1196682014-07-23 13:47:29 -04003322 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003323 {
3324 return;
3325 }
Jamie Madillaff71502013-07-02 11:57:05 -04003326
Geoff Langbfdea662014-07-23 14:16:32 -04003327 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3328 {
3329 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3330 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003331 {
Geoff Langbfdea662014-07-23 14:16:32 -04003332 float currentValue = currentValueData.FloatValues[i];
3333 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003334 }
3335 }
Geoff Langbfdea662014-07-23 14:16:32 -04003336 else
3337 {
3338 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3339 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003340 }
3341}
3342
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003343void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003344{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003345 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003346
Geoff Langbfdea662014-07-23 14:16:32 -04003347 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003348 if (context)
3349 {
3350 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003351 {
Geoff Langb1196682014-07-23 13:47:29 -04003352 context->recordError(gl::Error(GL_INVALID_VALUE));
3353 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003354 }
Geoff Langbfdea662014-07-23 14:16:32 -04003355
3356 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3357 {
Geoff Langb1196682014-07-23 13:47:29 -04003358 context->recordError(gl::Error(GL_INVALID_ENUM));
3359 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003360 }
3361
3362 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003363 }
3364}
3365
3366void __stdcall glHint(GLenum target, GLenum mode)
3367{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003368 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003369
Geoff Langbfdea662014-07-23 14:16:32 -04003370 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003371 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003372 {
Geoff Langb1196682014-07-23 13:47:29 -04003373 switch (mode)
3374 {
3375 case GL_FASTEST:
3376 case GL_NICEST:
3377 case GL_DONT_CARE:
3378 break;
3379
3380 default:
3381 context->recordError(gl::Error(GL_INVALID_ENUM));
3382 return;
3383 }
3384
3385 switch (target)
3386 {
3387 case GL_GENERATE_MIPMAP_HINT:
3388 context->getState().setGenerateMipmapHint(mode);
3389 break;
3390
3391 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3392 context->getState().setFragmentShaderDerivativeHint(mode);
3393 break;
3394
3395 default:
3396 context->recordError(gl::Error(GL_INVALID_ENUM));
3397 return;
3398 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003399 }
3400}
3401
3402GLboolean __stdcall glIsBuffer(GLuint buffer)
3403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003404 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003405
Geoff Langbfdea662014-07-23 14:16:32 -04003406 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003407 if (context && buffer)
3408 {
3409 gl::Buffer *bufferObject = context->getBuffer(buffer);
3410
3411 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003412 {
Geoff Langbfdea662014-07-23 14:16:32 -04003413 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003414 }
3415 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003416
3417 return GL_FALSE;
3418}
3419
3420GLboolean __stdcall glIsEnabled(GLenum cap)
3421{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003422 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003423
Geoff Langbfdea662014-07-23 14:16:32 -04003424 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003425 if (context)
3426 {
3427 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428 {
Geoff Langb1196682014-07-23 13:47:29 -04003429 context->recordError(gl::Error(GL_INVALID_ENUM));
3430 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003431 }
Geoff Langbfdea662014-07-23 14:16:32 -04003432
3433 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003434 }
3435
3436 return false;
3437}
3438
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003439GLboolean __stdcall glIsFenceNV(GLuint fence)
3440{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003441 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003442
Geoff Langbfdea662014-07-23 14:16:32 -04003443 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003444 if (context)
3445 {
3446 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3447
3448 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003449 {
Geoff Langbfdea662014-07-23 14:16:32 -04003450 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003451 }
Geoff Langbfdea662014-07-23 14:16:32 -04003452
3453 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003454 }
3455
3456 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003457}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003458
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003459GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003461 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003462
Geoff Langbfdea662014-07-23 14:16:32 -04003463 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003464 if (context && framebuffer)
3465 {
3466 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3467
3468 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003469 {
Geoff Langbfdea662014-07-23 14:16:32 -04003470 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003471 }
3472 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003473
3474 return GL_FALSE;
3475}
3476
3477GLboolean __stdcall glIsProgram(GLuint program)
3478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003479 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003480
Geoff Langbfdea662014-07-23 14:16:32 -04003481 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003482 if (context && program)
3483 {
3484 gl::Program *programObject = context->getProgram(program);
3485
3486 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003487 {
Geoff Langbfdea662014-07-23 14:16:32 -04003488 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003489 }
3490 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003491
3492 return GL_FALSE;
3493}
3494
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003495GLboolean __stdcall glIsQueryEXT(GLuint id)
3496{
3497 EVENT("(GLuint id = %d)", id);
3498
Geoff Langbfdea662014-07-23 14:16:32 -04003499 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003500 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003501 {
Geoff Langbfdea662014-07-23 14:16:32 -04003502 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003503 }
3504
3505 return GL_FALSE;
3506}
3507
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003508GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3509{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003510 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003511
Geoff Langbfdea662014-07-23 14:16:32 -04003512 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003513 if (context && renderbuffer)
3514 {
3515 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3516
3517 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003518 {
Geoff Langbfdea662014-07-23 14:16:32 -04003519 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003520 }
3521 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003522
3523 return GL_FALSE;
3524}
3525
3526GLboolean __stdcall glIsShader(GLuint shader)
3527{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003528 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003529
Geoff Langbfdea662014-07-23 14:16:32 -04003530 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003531 if (context && shader)
3532 {
3533 gl::Shader *shaderObject = context->getShader(shader);
3534
3535 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003536 {
Geoff Langbfdea662014-07-23 14:16:32 -04003537 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003538 }
3539 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003540
3541 return GL_FALSE;
3542}
3543
3544GLboolean __stdcall glIsTexture(GLuint texture)
3545{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003546 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003547
Geoff Langbfdea662014-07-23 14:16:32 -04003548 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003549 if (context && texture)
3550 {
3551 gl::Texture *textureObject = context->getTexture(texture);
3552
3553 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003554 {
Geoff Langbfdea662014-07-23 14:16:32 -04003555 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003556 }
3557 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003558
3559 return GL_FALSE;
3560}
3561
3562void __stdcall glLineWidth(GLfloat width)
3563{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003564 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003565
Geoff Langbfdea662014-07-23 14:16:32 -04003566 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003567 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568 {
Geoff Langb1196682014-07-23 13:47:29 -04003569 if (width <= 0.0f)
3570 {
3571 context->recordError(gl::Error(GL_INVALID_VALUE));
3572 return;
3573 }
3574
Geoff Langbfdea662014-07-23 14:16:32 -04003575 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003576 }
3577}
3578
3579void __stdcall glLinkProgram(GLuint program)
3580{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003581 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582
Geoff Langbfdea662014-07-23 14:16:32 -04003583 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003584 if (context)
3585 {
3586 gl::Program *programObject = context->getProgram(program);
3587
3588 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003589 {
Geoff Langbfdea662014-07-23 14:16:32 -04003590 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003591 {
Geoff Langb1196682014-07-23 13:47:29 -04003592 context->recordError(gl::Error(GL_INVALID_OPERATION));
3593 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594 }
Geoff Langbfdea662014-07-23 14:16:32 -04003595 else
3596 {
Geoff Langb1196682014-07-23 13:47:29 -04003597 context->recordError(gl::Error(GL_INVALID_VALUE));
3598 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003599 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003600 }
Geoff Langbfdea662014-07-23 14:16:32 -04003601
3602 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003603 }
3604}
3605
3606void __stdcall glPixelStorei(GLenum pname, GLint param)
3607{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003608 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003609
Geoff Langbfdea662014-07-23 14:16:32 -04003610 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003611 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003612 {
Geoff Langbfdea662014-07-23 14:16:32 -04003613 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003614 {
Geoff Langbfdea662014-07-23 14:16:32 -04003615 case GL_UNPACK_ALIGNMENT:
3616 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003617 {
Geoff Langb1196682014-07-23 13:47:29 -04003618 context->recordError(gl::Error(GL_INVALID_VALUE));
3619 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003620 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003621
Geoff Langbfdea662014-07-23 14:16:32 -04003622 context->getState().setUnpackAlignment(param);
3623 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003624
Geoff Langbfdea662014-07-23 14:16:32 -04003625 case GL_PACK_ALIGNMENT:
3626 if (param != 1 && param != 2 && param != 4 && param != 8)
3627 {
Geoff Langb1196682014-07-23 13:47:29 -04003628 context->recordError(gl::Error(GL_INVALID_VALUE));
3629 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003630 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003631
Geoff Langbfdea662014-07-23 14:16:32 -04003632 context->getState().setPackAlignment(param);
3633 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003634
Geoff Langbfdea662014-07-23 14:16:32 -04003635 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3636 context->getState().setPackReverseRowOrder(param != 0);
3637 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003638
Geoff Langbfdea662014-07-23 14:16:32 -04003639 case GL_UNPACK_IMAGE_HEIGHT:
3640 case GL_UNPACK_SKIP_IMAGES:
3641 case GL_UNPACK_ROW_LENGTH:
3642 case GL_UNPACK_SKIP_ROWS:
3643 case GL_UNPACK_SKIP_PIXELS:
3644 case GL_PACK_ROW_LENGTH:
3645 case GL_PACK_SKIP_ROWS:
3646 case GL_PACK_SKIP_PIXELS:
3647 if (context->getClientVersion() < 3)
3648 {
Geoff Langb1196682014-07-23 13:47:29 -04003649 context->recordError(gl::Error(GL_INVALID_ENUM));
3650 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003651 }
Geoff Langbfdea662014-07-23 14:16:32 -04003652 UNIMPLEMENTED();
3653 break;
3654
3655 default:
Geoff Langb1196682014-07-23 13:47:29 -04003656 context->recordError(gl::Error(GL_INVALID_ENUM));
3657 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003658 }
3659 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003660}
3661
3662void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3663{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003664 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003665
Geoff Langbfdea662014-07-23 14:16:32 -04003666 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003667 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003668 {
Geoff Langbfdea662014-07-23 14:16:32 -04003669 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670 }
3671}
3672
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003673void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3674 GLenum format, GLenum type, GLsizei bufSize,
3675 GLvoid *data)
3676{
3677 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3678 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3679 x, y, width, height, format, type, bufSize, data);
3680
Geoff Langbfdea662014-07-23 14:16:32 -04003681 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003682 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003683 {
Geoff Langb1196682014-07-23 13:47:29 -04003684 if (width < 0 || height < 0 || bufSize < 0)
3685 {
3686 context->recordError(gl::Error(GL_INVALID_VALUE));
3687 return;
3688 }
3689
Geoff Langbfdea662014-07-23 14:16:32 -04003690 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3691 format, type, &bufSize, data))
3692 {
3693 return;
3694 }
3695
Geoff Lang63d2fc72014-07-25 14:51:41 -04003696 gl::Error error = context->readPixels(x, y, width, height, format, type, &bufSize, data);
3697 if (error.isError())
3698 {
3699 context->recordError(error);
3700 return;
3701 }
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003702 }
3703}
3704
3705void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3706 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003707{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003708 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003709 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003710 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003711
Geoff Langbfdea662014-07-23 14:16:32 -04003712 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003713 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003714 {
Geoff Langb1196682014-07-23 13:47:29 -04003715 if (width < 0 || height < 0)
3716 {
3717 context->recordError(gl::Error(GL_INVALID_VALUE));
3718 return;
3719 }
3720
Geoff Langbfdea662014-07-23 14:16:32 -04003721 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3722 format, type, NULL, pixels))
3723 {
3724 return;
3725 }
3726
Geoff Lang63d2fc72014-07-25 14:51:41 -04003727 gl::Error error = context->readPixels(x, y, width, height, format, type, NULL, pixels);
3728 if (error.isError())
3729 {
3730 context->recordError(error);
3731 return;
3732 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733 }
3734}
3735
3736void __stdcall glReleaseShaderCompiler(void)
3737{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003738 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003739
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003740 gl::Context *context = gl::getNonLostContext();
3741
3742 if (context)
3743 {
3744 context->releaseShaderCompiler();
3745 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003746}
3747
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003748void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003749{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003750 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 +00003751 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003752
Geoff Langbfdea662014-07-23 14:16:32 -04003753 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003754 if (context)
3755 {
3756 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3757 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003758 {
Geoff Langbfdea662014-07-23 14:16:32 -04003759 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003760 }
Geoff Langbfdea662014-07-23 14:16:32 -04003761
3762 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003763 }
3764}
3765
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003766void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3767{
3768 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3769}
3770
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003771void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3772{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003773 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003774
Geoff Langbfdea662014-07-23 14:16:32 -04003775 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003776
Geoff Langbfdea662014-07-23 14:16:32 -04003777 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778 {
Geoff Langbfdea662014-07-23 14:16:32 -04003779 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003780 }
3781}
3782
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003783void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3784{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003785 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003786
Geoff Langbfdea662014-07-23 14:16:32 -04003787 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003788 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003789 {
Geoff Langb1196682014-07-23 13:47:29 -04003790 if (condition != GL_ALL_COMPLETED_NV)
3791 {
3792 context->recordError(gl::Error(GL_INVALID_ENUM));
3793 return;
3794 }
3795
Geoff Langbfdea662014-07-23 14:16:32 -04003796 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3797
3798 if (fenceObject == NULL)
3799 {
Geoff Langb1196682014-07-23 13:47:29 -04003800 context->recordError(gl::Error(GL_INVALID_OPERATION));
3801 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003802 }
3803
3804 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003805 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003806}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003807
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003808void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3809{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003810 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 +00003811
Geoff Langbfdea662014-07-23 14:16:32 -04003812 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003813 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003814 {
Geoff Langb1196682014-07-23 13:47:29 -04003815 if (width < 0 || height < 0)
3816 {
3817 context->recordError(gl::Error(GL_INVALID_VALUE));
3818 return;
3819 }
3820
Geoff Langbfdea662014-07-23 14:16:32 -04003821 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003822 }
3823}
3824
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003825void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003826{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003827 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003828 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003829 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003830
Geoff Lang900013c2014-07-07 11:32:19 -04003831 gl::Context* context = gl::getNonLostContext();
3832 if (context)
3833 {
3834 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3835 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3836 {
Geoff Langb1196682014-07-23 13:47:29 -04003837 context->recordError(gl::Error(GL_INVALID_ENUM));
3838 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003839 }
3840
3841 // No binary shader formats are supported.
3842 UNIMPLEMENTED();
3843 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003844}
3845
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003846void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003847{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003848 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 +00003849 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003850
Geoff Langbfdea662014-07-23 14:16:32 -04003851 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003852 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003853 {
Geoff Langb1196682014-07-23 13:47:29 -04003854 if (count < 0)
3855 {
3856 context->recordError(gl::Error(GL_INVALID_VALUE));
3857 return;
3858 }
3859
Geoff Langbfdea662014-07-23 14:16:32 -04003860 gl::Shader *shaderObject = context->getShader(shader);
3861
3862 if (!shaderObject)
3863 {
3864 if (context->getProgram(shader))
3865 {
Geoff Langb1196682014-07-23 13:47:29 -04003866 context->recordError(gl::Error(GL_INVALID_OPERATION));
3867 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003868 }
3869 else
3870 {
Geoff Langb1196682014-07-23 13:47:29 -04003871 context->recordError(gl::Error(GL_INVALID_VALUE));
3872 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003873 }
3874 }
3875
3876 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003877 }
3878}
3879
3880void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3881{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003882 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003883}
3884
3885void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3886{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003887 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 +00003888
Geoff Langbfdea662014-07-23 14:16:32 -04003889 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003890 if (context)
3891 {
Geoff Langb1196682014-07-23 13:47:29 -04003892 switch (face)
3893 {
3894 case GL_FRONT:
3895 case GL_BACK:
3896 case GL_FRONT_AND_BACK:
3897 break;
3898
3899 default:
3900 context->recordError(gl::Error(GL_INVALID_ENUM));
3901 return;
3902 }
3903
3904 switch (func)
3905 {
3906 case GL_NEVER:
3907 case GL_ALWAYS:
3908 case GL_LESS:
3909 case GL_LEQUAL:
3910 case GL_EQUAL:
3911 case GL_GEQUAL:
3912 case GL_GREATER:
3913 case GL_NOTEQUAL:
3914 break;
3915
3916 default:
3917 context->recordError(gl::Error(GL_INVALID_ENUM));
3918 return;
3919 }
3920
Geoff Langbfdea662014-07-23 14:16:32 -04003921 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3922 {
3923 context->getState().setStencilParams(func, ref, mask);
3924 }
3925
3926 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3927 {
3928 context->getState().setStencilBackParams(func, ref, mask);
3929 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003930 }
3931}
3932
3933void __stdcall glStencilMask(GLuint mask)
3934{
3935 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3936}
3937
3938void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3939{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003940 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003941
Geoff Langbfdea662014-07-23 14:16:32 -04003942 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003943 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003944 {
Geoff Langb1196682014-07-23 13:47:29 -04003945 switch (face)
3946 {
3947 case GL_FRONT:
3948 case GL_BACK:
3949 case GL_FRONT_AND_BACK:
3950 break;
3951
3952 default:
3953 context->recordError(gl::Error(GL_INVALID_ENUM));
3954 return;
3955 }
3956
Geoff Langbfdea662014-07-23 14:16:32 -04003957 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3958 {
3959 context->getState().setStencilWritemask(mask);
3960 }
3961
3962 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3963 {
3964 context->getState().setStencilBackWritemask(mask);
3965 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003966 }
3967}
3968
3969void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3970{
3971 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3972}
3973
3974void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003976 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 +00003977 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003978
Geoff Langbfdea662014-07-23 14:16:32 -04003979 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003980 if (context)
3981 {
Geoff Langb1196682014-07-23 13:47:29 -04003982 switch (face)
3983 {
3984 case GL_FRONT:
3985 case GL_BACK:
3986 case GL_FRONT_AND_BACK:
3987 break;
3988
3989 default:
3990 context->recordError(gl::Error(GL_INVALID_ENUM));
3991 return;
3992 }
3993
3994 switch (fail)
3995 {
3996 case GL_ZERO:
3997 case GL_KEEP:
3998 case GL_REPLACE:
3999 case GL_INCR:
4000 case GL_DECR:
4001 case GL_INVERT:
4002 case GL_INCR_WRAP:
4003 case GL_DECR_WRAP:
4004 break;
4005
4006 default:
4007 context->recordError(gl::Error(GL_INVALID_ENUM));
4008 return;
4009 }
4010
4011 switch (zfail)
4012 {
4013 case GL_ZERO:
4014 case GL_KEEP:
4015 case GL_REPLACE:
4016 case GL_INCR:
4017 case GL_DECR:
4018 case GL_INVERT:
4019 case GL_INCR_WRAP:
4020 case GL_DECR_WRAP:
4021 break;
4022
4023 default:
4024 context->recordError(gl::Error(GL_INVALID_ENUM));
4025 return;
4026 }
4027
4028 switch (zpass)
4029 {
4030 case GL_ZERO:
4031 case GL_KEEP:
4032 case GL_REPLACE:
4033 case GL_INCR:
4034 case GL_DECR:
4035 case GL_INVERT:
4036 case GL_INCR_WRAP:
4037 case GL_DECR_WRAP:
4038 break;
4039
4040 default:
4041 context->recordError(gl::Error(GL_INVALID_ENUM));
4042 return;
4043 }
4044
Geoff Langbfdea662014-07-23 14:16:32 -04004045 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4046 {
4047 context->getState().setStencilOperations(fail, zfail, zpass);
4048 }
4049
4050 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4051 {
4052 context->getState().setStencilBackOperations(fail, zfail, zpass);
4053 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004054 }
4055}
4056
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004057GLboolean __stdcall glTestFenceNV(GLuint fence)
4058{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004059 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004060
Geoff Langbfdea662014-07-23 14:16:32 -04004061 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004062 if (context)
4063 {
4064 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4065
4066 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004067 {
Geoff Langb1196682014-07-23 13:47:29 -04004068 context->recordError(gl::Error(GL_INVALID_OPERATION));
4069 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004070 }
Geoff Langbfdea662014-07-23 14:16:32 -04004071
4072 if (fenceObject->isFence() != GL_TRUE)
4073 {
Geoff Langb1196682014-07-23 13:47:29 -04004074 context->recordError(gl::Error(GL_INVALID_OPERATION));
4075 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004076 }
4077
4078 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004079 }
Geoff Langbfdea662014-07-23 14:16:32 -04004080
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004081 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004082}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004083
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004084void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4085 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004086{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004087 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004088 "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 +00004089 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004090
Geoff Langbfdea662014-07-23 14:16:32 -04004091 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004092 if (context)
4093 {
4094 if (context->getClientVersion() < 3 &&
4095 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4096 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004097 {
Geoff Langbfdea662014-07-23 14:16:32 -04004098 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004099 }
Geoff Langbfdea662014-07-23 14:16:32 -04004100
4101 if (context->getClientVersion() >= 3 &&
4102 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4103 0, 0, 0, width, height, 1, border, format, type, pixels))
4104 {
4105 return;
4106 }
4107
4108 switch (target)
4109 {
4110 case GL_TEXTURE_2D:
4111 {
4112 gl::Texture2D *texture = context->getTexture2D();
4113 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4114 }
4115 break;
4116 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4117 {
4118 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4119 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4120 }
4121 break;
4122 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4123 {
4124 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4125 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4126 }
4127 break;
4128 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4129 {
4130 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4131 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4132 }
4133 break;
4134 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4135 {
4136 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4137 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4138 }
4139 break;
4140 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4141 {
4142 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4143 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4144 }
4145 break;
4146 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4147 {
4148 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4149 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4150 }
4151 break;
4152 default: UNREACHABLE();
4153 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004154 }
4155}
4156
4157void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4158{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004159 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4160
Geoff Langbfdea662014-07-23 14:16:32 -04004161 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004162 if (context)
4163 {
4164 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004165 {
Geoff Langbfdea662014-07-23 14:16:32 -04004166 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004167 }
Geoff Langbfdea662014-07-23 14:16:32 -04004168
4169 gl::Texture *texture = context->getTargetTexture(target);
4170
4171 if (!texture)
4172 {
Geoff Langb1196682014-07-23 13:47:29 -04004173 context->recordError(gl::Error(GL_INVALID_ENUM));
4174 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004175 }
4176
4177 switch (pname)
4178 {
4179 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4180 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4181 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4182 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4183 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4184 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4185 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4186 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4187 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4188 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4189 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4190 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4191 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4192 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4193 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4194 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4195 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4196 default: UNREACHABLE(); break;
4197 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004198 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004199}
4200
4201void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4202{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004203 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004204}
4205
4206void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4207{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004208 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004209
Geoff Langbfdea662014-07-23 14:16:32 -04004210 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004211 if (context)
4212 {
4213 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004214 {
Geoff Langbfdea662014-07-23 14:16:32 -04004215 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004216 }
Geoff Langbfdea662014-07-23 14:16:32 -04004217
4218 gl::Texture *texture = context->getTargetTexture(target);
4219
4220 if (!texture)
4221 {
Geoff Langb1196682014-07-23 13:47:29 -04004222 context->recordError(gl::Error(GL_INVALID_ENUM));
4223 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004224 }
4225
4226 switch (pname)
4227 {
4228 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4229 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4230 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4231 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4232 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4233 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4234 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4235 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4236 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4237 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4238 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4239 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4240 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4241 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4242 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4243 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4244 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4245 default: UNREACHABLE(); break;
4246 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004247 }
4248}
4249
4250void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4251{
4252 glTexParameteri(target, pname, *params);
4253}
4254
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004255void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4256{
4257 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4258 target, levels, internalformat, width, height);
4259
Geoff Langbfdea662014-07-23 14:16:32 -04004260 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004261 if (context)
4262 {
4263 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004264 {
Geoff Langb1196682014-07-23 13:47:29 -04004265 context->recordError(gl::Error(GL_INVALID_OPERATION));
4266 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004267 }
Geoff Langbfdea662014-07-23 14:16:32 -04004268
4269 if (context->getClientVersion() < 3 &&
4270 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4271 {
4272 return;
4273 }
4274
4275 if (context->getClientVersion() >= 3 &&
4276 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4277 {
4278 return;
4279 }
4280
4281 switch (target)
4282 {
4283 case GL_TEXTURE_2D:
4284 {
4285 gl::Texture2D *texture2d = context->getTexture2D();
4286 texture2d->storage(levels, internalformat, width, height);
4287 }
4288 break;
4289
4290 case GL_TEXTURE_CUBE_MAP:
4291 {
4292 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4293 textureCube->storage(levels, internalformat, width);
4294 }
4295 break;
4296
4297 default:
Geoff Langb1196682014-07-23 13:47:29 -04004298 context->recordError(gl::Error(GL_INVALID_ENUM));
4299 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004300 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004301 }
4302}
4303
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004304void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4305 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004306{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004307 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004308 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004309 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004310 target, level, xoffset, yoffset, width, height, format, type, pixels);
4311
Geoff Langbfdea662014-07-23 14:16:32 -04004312 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004313 if (context)
4314 {
4315 if (context->getClientVersion() < 3 &&
4316 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4317 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004318 {
Geoff Langbfdea662014-07-23 14:16:32 -04004319 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004320 }
Geoff Langbfdea662014-07-23 14:16:32 -04004321
4322 if (context->getClientVersion() >= 3 &&
4323 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4324 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4325 {
4326 return;
4327 }
4328
4329 // Zero sized uploads are valid but no-ops
4330 if (width == 0 || height == 0)
4331 {
4332 return;
4333 }
4334
4335 switch (target)
4336 {
4337 case GL_TEXTURE_2D:
4338 {
4339 gl::Texture2D *texture = context->getTexture2D();
4340 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4341 }
4342 break;
4343
4344 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4345 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4346 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4347 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4348 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4349 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4350 {
4351 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4352 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4353 }
4354 break;
4355
4356 default:
4357 UNREACHABLE();
4358 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004359 }
4360}
4361
4362void __stdcall glUniform1f(GLint location, GLfloat x)
4363{
4364 glUniform1fv(location, 1, &x);
4365}
4366
4367void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4368{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004369 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004370
Geoff Langbfdea662014-07-23 14:16:32 -04004371 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004372 if (context)
4373 {
4374 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004375 {
Geoff Langbfdea662014-07-23 14:16:32 -04004376 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004377 }
Geoff Langbfdea662014-07-23 14:16:32 -04004378
4379 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4380 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004381 }
4382}
4383
4384void __stdcall glUniform1i(GLint location, GLint x)
4385{
4386 glUniform1iv(location, 1, &x);
4387}
4388
4389void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4390{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004391 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004392
Geoff Langbfdea662014-07-23 14:16:32 -04004393 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004394 if (context)
4395 {
4396 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004397 {
Geoff Langbfdea662014-07-23 14:16:32 -04004398 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004399 }
Geoff Langbfdea662014-07-23 14:16:32 -04004400
4401 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4402 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004403 }
4404}
4405
4406void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4407{
4408 GLfloat xy[2] = {x, y};
4409
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004410 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004411}
4412
4413void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4414{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004415 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004416
Geoff Langbfdea662014-07-23 14:16:32 -04004417 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004418 if (context)
4419 {
4420 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004421 {
Geoff Langbfdea662014-07-23 14:16:32 -04004422 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004423 }
Geoff Langbfdea662014-07-23 14:16:32 -04004424
4425 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4426 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004427 }
4428}
4429
4430void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4431{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004432 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004433
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004434 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004435}
4436
4437void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4438{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004439 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004440
Geoff Langbfdea662014-07-23 14:16:32 -04004441 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004442 if (context)
4443 {
4444 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004445 {
Geoff Langbfdea662014-07-23 14:16:32 -04004446 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004447 }
Geoff Langbfdea662014-07-23 14:16:32 -04004448
4449 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4450 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004451 }
4452}
4453
4454void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4455{
4456 GLfloat xyz[3] = {x, y, z};
4457
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004458 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004459}
4460
4461void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4462{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004463 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004464
Geoff Langbfdea662014-07-23 14:16:32 -04004465 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004466 if (context)
4467 {
4468 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004469 {
Geoff Langbfdea662014-07-23 14:16:32 -04004470 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004471 }
Geoff Langbfdea662014-07-23 14:16:32 -04004472
4473 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4474 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004475 }
4476}
4477
4478void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4479{
4480 GLint xyz[3] = {x, y, z};
4481
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004482 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004483}
4484
4485void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4486{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004487 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004488
Geoff Langbfdea662014-07-23 14:16:32 -04004489 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004490 if (context)
4491 {
4492 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004493 {
Geoff Langbfdea662014-07-23 14:16:32 -04004494 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004495 }
Geoff Langbfdea662014-07-23 14:16:32 -04004496
4497 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4498 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004499 }
4500}
4501
4502void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4503{
4504 GLfloat xyzw[4] = {x, y, z, w};
4505
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004506 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004507}
4508
4509void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4510{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004511 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004512
Geoff Langbfdea662014-07-23 14:16:32 -04004513 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004514 if (context)
4515 {
4516 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004517 {
Geoff Langbfdea662014-07-23 14:16:32 -04004518 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004519 }
Geoff Langbfdea662014-07-23 14:16:32 -04004520
4521 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4522 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004523 }
4524}
4525
4526void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4527{
4528 GLint xyzw[4] = {x, y, z, w};
4529
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004530 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004531}
4532
4533void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4534{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004535 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004536
Geoff Langbfdea662014-07-23 14:16:32 -04004537 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004538 if (context)
4539 {
4540 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004541 {
Geoff Langbfdea662014-07-23 14:16:32 -04004542 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004543 }
Geoff Langbfdea662014-07-23 14:16:32 -04004544
4545 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4546 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004547 }
4548}
4549
4550void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4551{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004552 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004553 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004554
Geoff Langbfdea662014-07-23 14:16:32 -04004555 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004556 if (context)
4557 {
4558 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004559 {
Geoff Langbfdea662014-07-23 14:16:32 -04004560 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004561 }
Geoff Langbfdea662014-07-23 14:16:32 -04004562
4563 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4564 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004565 }
4566}
4567
4568void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4569{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004570 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004571 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004572
Geoff Langbfdea662014-07-23 14:16:32 -04004573 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004574 if (context)
4575 {
4576 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004577 {
Geoff Langbfdea662014-07-23 14:16:32 -04004578 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004579 }
Geoff Langbfdea662014-07-23 14:16:32 -04004580
4581 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4582 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004583 }
4584}
4585
4586void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4587{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004588 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004589 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004590
Geoff Langbfdea662014-07-23 14:16:32 -04004591 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004592 if (context)
4593 {
4594 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004595 {
Geoff Langbfdea662014-07-23 14:16:32 -04004596 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004597 }
Geoff Langbfdea662014-07-23 14:16:32 -04004598
4599 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4600 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004601 }
4602}
4603
4604void __stdcall glUseProgram(GLuint program)
4605{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004606 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004607
Geoff Langbfdea662014-07-23 14:16:32 -04004608 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004609 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004610 {
Geoff Langbfdea662014-07-23 14:16:32 -04004611 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004612
Geoff Langbfdea662014-07-23 14:16:32 -04004613 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004614 {
Geoff Langbfdea662014-07-23 14:16:32 -04004615 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004616 {
Geoff Langb1196682014-07-23 13:47:29 -04004617 context->recordError(gl::Error(GL_INVALID_OPERATION));
4618 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619 }
Geoff Langbfdea662014-07-23 14:16:32 -04004620 else
4621 {
Geoff Langb1196682014-07-23 13:47:29 -04004622 context->recordError(gl::Error(GL_INVALID_VALUE));
4623 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004624 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004625 }
Geoff Langbfdea662014-07-23 14:16:32 -04004626
4627 if (program != 0 && !programObject->isLinked())
4628 {
Geoff Langb1196682014-07-23 13:47:29 -04004629 context->recordError(gl::Error(GL_INVALID_OPERATION));
4630 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004631 }
4632
4633 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634 }
4635}
4636
4637void __stdcall glValidateProgram(GLuint program)
4638{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004639 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004640
Geoff Langbfdea662014-07-23 14:16:32 -04004641 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004642 if (context)
4643 {
4644 gl::Program *programObject = context->getProgram(program);
4645
4646 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004647 {
Geoff Langbfdea662014-07-23 14:16:32 -04004648 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004649 {
Geoff Langb1196682014-07-23 13:47:29 -04004650 context->recordError(gl::Error(GL_INVALID_OPERATION));
4651 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004652 }
Geoff Langbfdea662014-07-23 14:16:32 -04004653 else
4654 {
Geoff Langb1196682014-07-23 13:47:29 -04004655 context->recordError(gl::Error(GL_INVALID_VALUE));
4656 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004657 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004658 }
Geoff Langbfdea662014-07-23 14:16:32 -04004659
Brandon Jones43a53e22014-08-28 16:23:22 -07004660 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004661 }
4662}
4663
4664void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4665{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004666 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004667
Geoff Langbfdea662014-07-23 14:16:32 -04004668 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004669 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670 {
Geoff Langb1196682014-07-23 13:47:29 -04004671 if (index >= gl::MAX_VERTEX_ATTRIBS)
4672 {
4673 context->recordError(gl::Error(GL_INVALID_VALUE));
4674 return;
4675 }
4676
Geoff Langbfdea662014-07-23 14:16:32 -04004677 GLfloat vals[4] = { x, 0, 0, 1 };
4678 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004679 }
4680}
4681
4682void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4683{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004684 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004685
Geoff Langbfdea662014-07-23 14:16:32 -04004686 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004687 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004688 {
Geoff Langb1196682014-07-23 13:47:29 -04004689 if (index >= gl::MAX_VERTEX_ATTRIBS)
4690 {
4691 context->recordError(gl::Error(GL_INVALID_VALUE));
4692 return;
4693 }
4694
Geoff Langbfdea662014-07-23 14:16:32 -04004695 GLfloat vals[4] = { values[0], 0, 0, 1 };
4696 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004697 }
4698}
4699
4700void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4701{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004702 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004703
Geoff Langbfdea662014-07-23 14:16:32 -04004704 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004705 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004706 {
Geoff Langb1196682014-07-23 13:47:29 -04004707 if (index >= gl::MAX_VERTEX_ATTRIBS)
4708 {
4709 context->recordError(gl::Error(GL_INVALID_VALUE));
4710 return;
4711 }
4712
Geoff Langbfdea662014-07-23 14:16:32 -04004713 GLfloat vals[4] = { x, y, 0, 1 };
4714 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004715 }
4716}
4717
4718void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4719{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004720 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004721
Geoff Langbfdea662014-07-23 14:16:32 -04004722 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004723 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004724 {
Geoff Langb1196682014-07-23 13:47:29 -04004725 if (index >= gl::MAX_VERTEX_ATTRIBS)
4726 {
4727 context->recordError(gl::Error(GL_INVALID_VALUE));
4728 return;
4729 }
4730
Geoff Langbfdea662014-07-23 14:16:32 -04004731 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4732 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004733 }
4734}
4735
4736void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4737{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004738 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 +00004739
Geoff Langbfdea662014-07-23 14:16:32 -04004740 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004741 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004742 {
Geoff Langb1196682014-07-23 13:47:29 -04004743 if (index >= gl::MAX_VERTEX_ATTRIBS)
4744 {
4745 context->recordError(gl::Error(GL_INVALID_VALUE));
4746 return;
4747 }
4748
Geoff Langbfdea662014-07-23 14:16:32 -04004749 GLfloat vals[4] = { x, y, z, 1 };
4750 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004751 }
4752}
4753
4754void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4755{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004756 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004757
Geoff Langbfdea662014-07-23 14:16:32 -04004758 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004759 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004760 {
Geoff Langb1196682014-07-23 13:47:29 -04004761 if (index >= gl::MAX_VERTEX_ATTRIBS)
4762 {
4763 context->recordError(gl::Error(GL_INVALID_VALUE));
4764 return;
4765 }
4766
Geoff Langbfdea662014-07-23 14:16:32 -04004767 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4768 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004769 }
4770}
4771
4772void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4773{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004774 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 +00004775
Geoff Langbfdea662014-07-23 14:16:32 -04004776 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004777 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004778 {
Geoff Langb1196682014-07-23 13:47:29 -04004779 if (index >= gl::MAX_VERTEX_ATTRIBS)
4780 {
4781 context->recordError(gl::Error(GL_INVALID_VALUE));
4782 return;
4783 }
4784
Geoff Langbfdea662014-07-23 14:16:32 -04004785 GLfloat vals[4] = { x, y, z, w };
4786 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004787 }
4788}
4789
4790void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4791{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004792 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004793
Geoff Langbfdea662014-07-23 14:16:32 -04004794 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004795 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004796 {
Geoff Langb1196682014-07-23 13:47:29 -04004797 if (index >= gl::MAX_VERTEX_ATTRIBS)
4798 {
4799 context->recordError(gl::Error(GL_INVALID_VALUE));
4800 return;
4801 }
4802
Geoff Langbfdea662014-07-23 14:16:32 -04004803 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004804 }
4805}
4806
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004807void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4808{
4809 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4810
Geoff Langbfdea662014-07-23 14:16:32 -04004811 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004812 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004813 {
Geoff Langb1196682014-07-23 13:47:29 -04004814 if (index >= gl::MAX_VERTEX_ATTRIBS)
4815 {
4816 context->recordError(gl::Error(GL_INVALID_VALUE));
4817 return;
4818 }
4819
Geoff Langbfdea662014-07-23 14:16:32 -04004820 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004821 }
4822}
4823
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004824void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004825{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004826 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004827 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004828 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004829
Geoff Langbfdea662014-07-23 14:16:32 -04004830 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004831 if (context)
4832 {
Geoff Langb1196682014-07-23 13:47:29 -04004833 if (index >= gl::MAX_VERTEX_ATTRIBS)
4834 {
4835 context->recordError(gl::Error(GL_INVALID_VALUE));
4836 return;
4837 }
4838
4839 if (size < 1 || size > 4)
4840 {
4841 context->recordError(gl::Error(GL_INVALID_VALUE));
4842 return;
4843 }
4844
4845 switch (type)
4846 {
4847 case GL_BYTE:
4848 case GL_UNSIGNED_BYTE:
4849 case GL_SHORT:
4850 case GL_UNSIGNED_SHORT:
4851 case GL_FIXED:
4852 case GL_FLOAT:
4853 break;
4854
4855 case GL_HALF_FLOAT:
4856 case GL_INT:
4857 case GL_UNSIGNED_INT:
4858 case GL_INT_2_10_10_10_REV:
4859 case GL_UNSIGNED_INT_2_10_10_10_REV:
4860 if (context->getClientVersion() < 3)
4861 {
4862 context->recordError(gl::Error(GL_INVALID_ENUM));
4863 return;
4864 }
4865 break;
4866
4867 default:
4868 context->recordError(gl::Error(GL_INVALID_ENUM));
4869 return;
4870 }
4871
4872 if (stride < 0)
4873 {
4874 context->recordError(gl::Error(GL_INVALID_VALUE));
4875 return;
4876 }
4877
4878 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4879 {
4880 context->recordError(gl::Error(GL_INVALID_OPERATION));
4881 return;
4882 }
4883
Geoff Langbfdea662014-07-23 14:16:32 -04004884 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4885 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4886 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4887 // and the pointer argument is not NULL.
4888 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004889 {
Geoff Langb1196682014-07-23 13:47:29 -04004890 context->recordError(gl::Error(GL_INVALID_OPERATION));
4891 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004892 }
4893
Geoff Langbfdea662014-07-23 14:16:32 -04004894 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4895 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004896 }
4897}
4898
4899void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4900{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004901 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 +00004902
Geoff Langbfdea662014-07-23 14:16:32 -04004903 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004904 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004905 {
Geoff Langb1196682014-07-23 13:47:29 -04004906 if (width < 0 || height < 0)
4907 {
4908 context->recordError(gl::Error(GL_INVALID_VALUE));
4909 return;
4910 }
4911
Geoff Langbfdea662014-07-23 14:16:32 -04004912 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004913 }
4914}
4915
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004916// OpenGL ES 3.0 functions
4917
4918void __stdcall glReadBuffer(GLenum mode)
4919{
4920 EVENT("(GLenum mode = 0x%X)", mode);
4921
Geoff Langbfdea662014-07-23 14:16:32 -04004922 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004923 if (context)
4924 {
4925 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004926 {
Geoff Langb1196682014-07-23 13:47:29 -04004927 context->recordError(gl::Error(GL_INVALID_OPERATION));
4928 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004929 }
Geoff Langbfdea662014-07-23 14:16:32 -04004930
4931 // glReadBuffer
4932 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004933 }
4934}
4935
4936void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4937{
4938 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4939 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4940
Geoff Langbfdea662014-07-23 14:16:32 -04004941 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004942 if (context)
4943 {
4944 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004945 {
Geoff Langb1196682014-07-23 13:47:29 -04004946 context->recordError(gl::Error(GL_INVALID_OPERATION));
4947 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004948 }
Geoff Langbfdea662014-07-23 14:16:32 -04004949
4950 // glDrawRangeElements
4951 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004952 }
4953}
4954
4955void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4956{
4957 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4958 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4959 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4960 target, level, internalformat, width, height, depth, border, format, type, pixels);
4961
Geoff Langbfdea662014-07-23 14:16:32 -04004962 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004963 if (context)
4964 {
4965 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004966 {
Geoff Langb1196682014-07-23 13:47:29 -04004967 context->recordError(gl::Error(GL_INVALID_OPERATION));
4968 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004969 }
Geoff Langbfdea662014-07-23 14:16:32 -04004970
4971 // validateES3TexImageFormat sets the error code if there is an error
4972 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4973 0, 0, 0, width, height, depth, border, format, type, pixels))
4974 {
4975 return;
4976 }
4977
4978 switch(target)
4979 {
4980 case GL_TEXTURE_3D:
4981 {
4982 gl::Texture3D *texture = context->getTexture3D();
4983 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4984 }
4985 break;
4986
4987 case GL_TEXTURE_2D_ARRAY:
4988 {
4989 gl::Texture2DArray *texture = context->getTexture2DArray();
4990 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4991 }
4992 break;
4993
4994 default:
Geoff Langb1196682014-07-23 13:47:29 -04004995 context->recordError(gl::Error(GL_INVALID_ENUM));
4996 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004997 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004998 }
4999}
5000
5001void __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)
5002{
5003 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5004 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5005 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5006 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
5007
Geoff Langbfdea662014-07-23 14:16:32 -04005008 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005009 if (context)
5010 {
5011 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005012 {
Geoff Langb1196682014-07-23 13:47:29 -04005013 context->recordError(gl::Error(GL_INVALID_OPERATION));
5014 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005015 }
Geoff Langbfdea662014-07-23 14:16:32 -04005016
5017 // validateES3TexImageFormat sets the error code if there is an error
5018 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5019 xoffset, yoffset, zoffset, width, height, depth, 0,
5020 format, type, pixels))
5021 {
5022 return;
5023 }
5024
5025 // Zero sized uploads are valid but no-ops
5026 if (width == 0 || height == 0 || depth == 0)
5027 {
5028 return;
5029 }
5030
5031 switch(target)
5032 {
5033 case GL_TEXTURE_3D:
5034 {
5035 gl::Texture3D *texture = context->getTexture3D();
5036 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5037 }
5038 break;
5039
5040 case GL_TEXTURE_2D_ARRAY:
5041 {
5042 gl::Texture2DArray *texture = context->getTexture2DArray();
5043 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5044 }
5045 break;
5046
5047 default:
Geoff Langb1196682014-07-23 13:47:29 -04005048 context->recordError(gl::Error(GL_INVALID_ENUM));
5049 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005050 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005051 }
5052}
5053
5054void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5055{
5056 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5057 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5058 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5059
Geoff Langbfdea662014-07-23 14:16:32 -04005060 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005061 if (context)
5062 {
5063 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005064 {
Geoff Langb1196682014-07-23 13:47:29 -04005065 context->recordError(gl::Error(GL_INVALID_OPERATION));
5066 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005067 }
Geoff Langbfdea662014-07-23 14:16:32 -04005068
5069 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5070 x, y, width, height, 0))
5071 {
5072 return;
5073 }
5074
5075 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5076 gl::Texture *texture = NULL;
5077 switch (target)
5078 {
5079 case GL_TEXTURE_3D:
5080 texture = context->getTexture3D();
5081 break;
5082
5083 case GL_TEXTURE_2D_ARRAY:
5084 texture = context->getTexture2DArray();
5085 break;
5086
5087 default:
Geoff Langb1196682014-07-23 13:47:29 -04005088 context->recordError(gl::Error(GL_INVALID_ENUM));
5089 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005090 }
5091
5092 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005093 }
5094}
5095
5096void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5097{
Geoff Langeef52cc2013-10-16 15:07:39 -04005098 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 +00005099 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5100 "const GLvoid* data = 0x%0.8p)",
5101 target, level, internalformat, width, height, depth, border, imageSize, data);
5102
Geoff Langbfdea662014-07-23 14:16:32 -04005103 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005104 if (context)
5105 {
5106 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005107 {
Geoff Langb1196682014-07-23 13:47:29 -04005108 context->recordError(gl::Error(GL_INVALID_OPERATION));
5109 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005110 }
Geoff Langbfdea662014-07-23 14:16:32 -04005111
Geoff Lang5d601382014-07-22 15:14:06 -04005112 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5113 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005114 {
Geoff Langb1196682014-07-23 13:47:29 -04005115 context->recordError(gl::Error(GL_INVALID_VALUE));
5116 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005117 }
5118
5119 // validateES3TexImageFormat sets the error code if there is an error
5120 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5121 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5122 {
5123 return;
5124 }
5125
5126 switch(target)
5127 {
5128 case GL_TEXTURE_3D:
5129 {
5130 gl::Texture3D *texture = context->getTexture3D();
5131 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5132 }
5133 break;
5134
5135 case GL_TEXTURE_2D_ARRAY:
5136 {
5137 gl::Texture2DArray *texture = context->getTexture2DArray();
5138 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5139 }
5140 break;
5141
5142 default:
Geoff Langb1196682014-07-23 13:47:29 -04005143 context->recordError(gl::Error(GL_INVALID_ENUM));
5144 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005145 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005146 }
5147}
5148
5149void __stdcall glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
5150{
5151 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5152 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5153 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5154 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5155
Geoff Langbfdea662014-07-23 14:16:32 -04005156 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005157 if (context)
5158 {
5159 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005160 {
Geoff Langb1196682014-07-23 13:47:29 -04005161 context->recordError(gl::Error(GL_INVALID_OPERATION));
5162 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005163 }
Geoff Langbfdea662014-07-23 14:16:32 -04005164
Geoff Lang5d601382014-07-22 15:14:06 -04005165 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5166 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005167 {
Geoff Langb1196682014-07-23 13:47:29 -04005168 context->recordError(gl::Error(GL_INVALID_VALUE));
5169 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005170 }
5171
5172 if (!data)
5173 {
Geoff Langb1196682014-07-23 13:47:29 -04005174 context->recordError(gl::Error(GL_INVALID_VALUE));
5175 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005176 }
5177
5178 // validateES3TexImageFormat sets the error code if there is an error
5179 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5180 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5181 {
5182 return;
5183 }
5184
5185 // Zero sized uploads are valid but no-ops
5186 if (width == 0 || height == 0)
5187 {
5188 return;
5189 }
5190
5191 switch(target)
5192 {
5193 case GL_TEXTURE_3D:
5194 {
5195 gl::Texture3D *texture = context->getTexture3D();
5196 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5197 format, imageSize, data);
5198 }
5199 break;
5200
5201 case GL_TEXTURE_2D_ARRAY:
5202 {
5203 gl::Texture2DArray *texture = context->getTexture2DArray();
5204 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5205 format, imageSize, data);
5206 }
5207 break;
5208
Geoff Langb1196682014-07-23 13:47:29 -04005209 default:
5210 context->recordError(gl::Error(GL_INVALID_ENUM));
5211 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005212 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005213 }
5214}
5215
5216void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5217{
5218 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5219
Geoff Langbfdea662014-07-23 14:16:32 -04005220 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005221 if (context)
5222 {
5223 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005224 {
Geoff Langb1196682014-07-23 13:47:29 -04005225 context->recordError(gl::Error(GL_INVALID_OPERATION));
5226 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005227 }
Geoff Langbfdea662014-07-23 14:16:32 -04005228
5229 if (n < 0)
5230 {
Geoff Langb1196682014-07-23 13:47:29 -04005231 context->recordError(gl::Error(GL_INVALID_VALUE));
5232 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005233 }
5234
5235 for (GLsizei i = 0; i < n; i++)
5236 {
5237 ids[i] = context->createQuery();
5238 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005239 }
5240}
5241
5242void __stdcall glDeleteQueries(GLsizei n, const 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 context->deleteQuery(ids[i]);
5264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005265 }
5266}
5267
5268GLboolean __stdcall glIsQuery(GLuint id)
5269{
5270 EVENT("(GLuint id = %u)", id);
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 GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005279 }
Geoff Langbfdea662014-07-23 14:16:32 -04005280
5281 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005282 }
5283
5284 return GL_FALSE;
5285}
5286
5287void __stdcall glBeginQuery(GLenum target, GLuint id)
5288{
5289 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5290
Geoff Langbfdea662014-07-23 14:16:32 -04005291 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005292 if (context)
5293 {
5294 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005295 {
Geoff Langb1196682014-07-23 13:47:29 -04005296 context->recordError(gl::Error(GL_INVALID_OPERATION));
5297 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005298 }
Geoff Langbfdea662014-07-23 14:16:32 -04005299
5300 if (!ValidateBeginQuery(context, target, id))
5301 {
5302 return;
5303 }
5304 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005305 }
5306}
5307
5308void __stdcall glEndQuery(GLenum target)
5309{
5310 EVENT("(GLenum target = 0x%X)", target);
5311
Geoff Langbfdea662014-07-23 14:16:32 -04005312 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005313 if (context)
5314 {
5315 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005316 {
Geoff Langb1196682014-07-23 13:47:29 -04005317 context->recordError(gl::Error(GL_INVALID_OPERATION));
5318 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005319 }
Geoff Langbfdea662014-07-23 14:16:32 -04005320
5321 if (!ValidateEndQuery(context, target))
5322 {
5323 return;
5324 }
5325
5326 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005327 }
5328}
5329
5330void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5331{
5332 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5333
Geoff Langbfdea662014-07-23 14:16:32 -04005334 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005335 if (context)
5336 {
5337 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005338 {
Geoff Langb1196682014-07-23 13:47:29 -04005339 context->recordError(gl::Error(GL_INVALID_OPERATION));
5340 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005341 }
Geoff Langbfdea662014-07-23 14:16:32 -04005342
5343 if (!ValidQueryType(context, target))
5344 {
Geoff Langb1196682014-07-23 13:47:29 -04005345 context->recordError(gl::Error(GL_INVALID_ENUM));
5346 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005347 }
5348
5349 switch (pname)
5350 {
5351 case GL_CURRENT_QUERY:
5352 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5353 break;
5354
5355 default:
Geoff Langb1196682014-07-23 13:47:29 -04005356 context->recordError(gl::Error(GL_INVALID_ENUM));
5357 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005358 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005359 }
5360}
5361
5362void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5363{
5364 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5365
Geoff Langbfdea662014-07-23 14:16:32 -04005366 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005367 if (context)
5368 {
5369 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005370 {
Geoff Langb1196682014-07-23 13:47:29 -04005371 context->recordError(gl::Error(GL_INVALID_OPERATION));
5372 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005373 }
Geoff Langbfdea662014-07-23 14:16:32 -04005374
5375 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5376
5377 if (!queryObject)
5378 {
Geoff Langb1196682014-07-23 13:47:29 -04005379 context->recordError(gl::Error(GL_INVALID_OPERATION));
5380 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005381 }
5382
5383 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5384 {
Geoff Langb1196682014-07-23 13:47:29 -04005385 context->recordError(gl::Error(GL_INVALID_OPERATION));
5386 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005387 }
5388
5389 switch(pname)
5390 {
5391 case GL_QUERY_RESULT:
5392 params[0] = queryObject->getResult();
5393 break;
Geoff Langb1196682014-07-23 13:47:29 -04005394
Geoff Langbfdea662014-07-23 14:16:32 -04005395 case GL_QUERY_RESULT_AVAILABLE:
5396 params[0] = queryObject->isResultAvailable();
5397 break;
Geoff Langb1196682014-07-23 13:47:29 -04005398
Geoff Langbfdea662014-07-23 14:16:32 -04005399 default:
Geoff Langb1196682014-07-23 13:47:29 -04005400 context->recordError(gl::Error(GL_INVALID_ENUM));
5401 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005402 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005403 }
5404}
5405
5406GLboolean __stdcall glUnmapBuffer(GLenum target)
5407{
5408 EVENT("(GLenum target = 0x%X)", target);
5409
Geoff Langbfdea662014-07-23 14:16:32 -04005410 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005411 if (context)
5412 {
5413 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005414 {
Geoff Langb1196682014-07-23 13:47:29 -04005415 context->recordError(gl::Error(GL_INVALID_OPERATION));
5416 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005417 }
Geoff Langbfdea662014-07-23 14:16:32 -04005418
5419 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005420 }
5421
5422 return GL_FALSE;
5423}
5424
5425void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5426{
5427 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5428
Geoff Langbfdea662014-07-23 14:16:32 -04005429 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005430 if (context)
5431 {
5432 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005433 {
Geoff Langb1196682014-07-23 13:47:29 -04005434 context->recordError(gl::Error(GL_INVALID_OPERATION));
5435 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005436 }
Geoff Langbfdea662014-07-23 14:16:32 -04005437
5438 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005439 }
5440}
5441
5442void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5443{
Geoff Langbfdea662014-07-23 14:16:32 -04005444 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005445 if (context)
5446 {
5447 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005448 {
Geoff Langb1196682014-07-23 13:47:29 -04005449 context->recordError(gl::Error(GL_INVALID_OPERATION));
5450 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005451 }
Geoff Langbfdea662014-07-23 14:16:32 -04005452
5453 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005454 }
5455}
5456
5457void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5458{
5459 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5460 location, count, transpose, value);
5461
Geoff Langbfdea662014-07-23 14:16:32 -04005462 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005463 if (context)
5464 {
5465 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005466 {
Geoff Langbfdea662014-07-23 14:16:32 -04005467 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005468 }
Geoff Langbfdea662014-07-23 14:16:32 -04005469
5470 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5471 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005472 }
5473}
5474
5475void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5476{
5477 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5478 location, count, transpose, value);
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 (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005484 {
Geoff Langbfdea662014-07-23 14:16:32 -04005485 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005486 }
Geoff Langbfdea662014-07-23 14:16:32 -04005487
5488 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5489 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005490 }
5491}
5492
5493void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5494{
5495 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5496 location, count, transpose, value);
5497
Geoff Langbfdea662014-07-23 14:16:32 -04005498 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005499 if (context)
5500 {
5501 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005502 {
Geoff Langbfdea662014-07-23 14:16:32 -04005503 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005504 }
Geoff Langbfdea662014-07-23 14:16:32 -04005505
5506 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5507 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005508 }
5509}
5510
5511void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5512{
5513 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5514 location, count, transpose, value);
5515
Geoff Langbfdea662014-07-23 14:16:32 -04005516 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005517 if (context)
5518 {
5519 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005520 {
Geoff Langbfdea662014-07-23 14:16:32 -04005521 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005522 }
Geoff Langbfdea662014-07-23 14:16:32 -04005523
5524 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5525 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005526 }
5527}
5528
5529void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5530{
5531 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5532 location, count, transpose, value);
5533
Geoff Langbfdea662014-07-23 14:16:32 -04005534 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005535 if (context)
5536 {
5537 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005538 {
Geoff Langbfdea662014-07-23 14:16:32 -04005539 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005540 }
Geoff Langbfdea662014-07-23 14:16:32 -04005541
5542 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5543 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005544 }
5545}
5546
5547void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5548{
5549 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5550 location, count, transpose, value);
5551
Geoff Langbfdea662014-07-23 14:16:32 -04005552 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005553 if (context)
5554 {
5555 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005556 {
Geoff Langbfdea662014-07-23 14:16:32 -04005557 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005558 }
Geoff Langbfdea662014-07-23 14:16:32 -04005559
5560 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5561 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005562 }
5563}
5564
5565void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5566{
5567 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5568 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5569 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5570
Geoff Langbfdea662014-07-23 14:16:32 -04005571 gl::Context *context = gl::getNonLostContext();
5572 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005573 {
Geoff Langbfdea662014-07-23 14:16:32 -04005574 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005575 {
Geoff Langb1196682014-07-23 13:47:29 -04005576 context->recordError(gl::Error(GL_INVALID_OPERATION));
5577 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005578 }
Geoff Langbfdea662014-07-23 14:16:32 -04005579
5580 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5581 dstX0, dstY0, dstX1, dstY1, mask, filter,
5582 false))
5583 {
5584 return;
5585 }
5586
5587 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5588 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005589 }
5590}
5591
5592void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5593{
5594 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5595 target, samples, internalformat, width, height);
5596
Geoff Langbfdea662014-07-23 14:16:32 -04005597 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005598 if (context)
5599 {
5600 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005601 {
Geoff Langb1196682014-07-23 13:47:29 -04005602 context->recordError(gl::Error(GL_INVALID_OPERATION));
5603 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005604 }
Geoff Langbfdea662014-07-23 14:16:32 -04005605
5606 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5607 width, height, false))
5608 {
5609 return;
5610 }
5611
5612 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005613 }
5614}
5615
5616void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5617{
5618 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5619 target, attachment, texture, level, layer);
5620
Geoff Langbfdea662014-07-23 14:16:32 -04005621 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005622 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005623 {
Geoff Langbfdea662014-07-23 14:16:32 -04005624 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5625 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005626 {
Geoff Langbfdea662014-07-23 14:16:32 -04005627 return;
5628 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005629
Geoff Langbfdea662014-07-23 14:16:32 -04005630 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5631 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005632
Geoff Langbfdea662014-07-23 14:16:32 -04005633 gl::Texture *textureObject = context->getTexture(texture);
5634 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005635
Geoff Langbfdea662014-07-23 14:16:32 -04005636 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5637 {
5638 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5639 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5640 }
5641 else
5642 {
5643 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005644 {
Geoff Langbfdea662014-07-23 14:16:32 -04005645 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5646 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5647 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005648 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005649 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005650 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005651}
5652
5653GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5654{
5655 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5656 target, offset, length, access);
5657
Geoff Langbfdea662014-07-23 14:16:32 -04005658 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005659 if (context)
5660 {
5661 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005662 {
Geoff Langb1196682014-07-23 13:47:29 -04005663 context->recordError(gl::Error(GL_INVALID_OPERATION));
5664 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005665 }
Geoff Langbfdea662014-07-23 14:16:32 -04005666
5667 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005668 }
5669
5670 return NULL;
5671}
5672
5673void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5674{
5675 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5676
Geoff Langbfdea662014-07-23 14:16:32 -04005677 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005678 if (context)
5679 {
5680 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005681 {
Geoff Langb1196682014-07-23 13:47:29 -04005682 context->recordError(gl::Error(GL_INVALID_OPERATION));
5683 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005684 }
Geoff Langbfdea662014-07-23 14:16:32 -04005685
5686 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005687 }
5688}
5689
5690void __stdcall glBindVertexArray(GLuint array)
5691{
5692 EVENT("(GLuint array = %u)", array);
5693
Geoff Langbfdea662014-07-23 14:16:32 -04005694 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005695 if (context)
5696 {
5697 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005698 {
Geoff Langb1196682014-07-23 13:47:29 -04005699 context->recordError(gl::Error(GL_INVALID_OPERATION));
5700 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005701 }
Geoff Langbfdea662014-07-23 14:16:32 -04005702
5703 gl::VertexArray *vao = context->getVertexArray(array);
5704
5705 if (!vao)
5706 {
5707 // The default VAO should always exist
5708 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005709 context->recordError(gl::Error(GL_INVALID_OPERATION));
5710 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005711 }
5712
5713 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005714 }
5715}
5716
5717void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5718{
5719 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5720
Geoff Langbfdea662014-07-23 14:16:32 -04005721 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005722 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005723 {
Geoff Langbfdea662014-07-23 14:16:32 -04005724 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005725 {
Geoff Langb1196682014-07-23 13:47:29 -04005726 context->recordError(gl::Error(GL_INVALID_OPERATION));
5727 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005728 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005729
Geoff Langbfdea662014-07-23 14:16:32 -04005730 if (n < 0)
5731 {
Geoff Langb1196682014-07-23 13:47:29 -04005732 context->recordError(gl::Error(GL_INVALID_VALUE));
5733 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005734 }
Jamie Madilld1028542013-07-02 11:57:04 -04005735
Geoff Langbfdea662014-07-23 14:16:32 -04005736 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5737 {
5738 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005739 {
Geoff Langbfdea662014-07-23 14:16:32 -04005740 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005741 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005742 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005744}
5745
5746void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5747{
5748 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5749
Geoff Langbfdea662014-07-23 14:16:32 -04005750 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005751 if (context)
5752 {
5753 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005754 {
Geoff Langb1196682014-07-23 13:47:29 -04005755 context->recordError(gl::Error(GL_INVALID_OPERATION));
5756 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005757 }
Geoff Langbfdea662014-07-23 14:16:32 -04005758
5759 if (n < 0)
5760 {
Geoff Langb1196682014-07-23 13:47:29 -04005761 context->recordError(gl::Error(GL_INVALID_VALUE));
5762 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005763 }
5764
5765 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5766 {
5767 arrays[arrayIndex] = context->createVertexArray();
5768 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005769 }
5770}
5771
5772GLboolean __stdcall glIsVertexArray(GLuint array)
5773{
5774 EVENT("(GLuint array = %u)", array);
5775
Geoff Langbfdea662014-07-23 14:16:32 -04005776 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005777 if (context)
5778 {
5779 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005780 {
Geoff Langb1196682014-07-23 13:47:29 -04005781 context->recordError(gl::Error(GL_INVALID_OPERATION));
5782 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005783 }
Geoff Langbfdea662014-07-23 14:16:32 -04005784
5785 if (array == 0)
5786 {
5787 return GL_FALSE;
5788 }
5789
5790 gl::VertexArray *vao = context->getVertexArray(array);
5791
5792 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005793 }
5794
5795 return GL_FALSE;
5796}
5797
5798void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5799{
5800 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5801 target, index, data);
5802
Geoff Langbfdea662014-07-23 14:16:32 -04005803 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005804 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005805 {
Geoff Langbfdea662014-07-23 14:16:32 -04005806 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005807 {
Geoff Langb1196682014-07-23 13:47:29 -04005808 context->recordError(gl::Error(GL_INVALID_OPERATION));
5809 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005810 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005811
Geoff Lang3a61c322014-07-10 13:01:54 -04005812 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005813 switch (target)
5814 {
5815 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5816 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5817 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005818 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5819 {
Geoff Langb1196682014-07-23 13:47:29 -04005820 context->recordError(gl::Error(GL_INVALID_VALUE));
5821 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005822 }
Geoff Langbfdea662014-07-23 14:16:32 -04005823 break;
Geoff Langb1196682014-07-23 13:47:29 -04005824
Geoff Langbfdea662014-07-23 14:16:32 -04005825 case GL_UNIFORM_BUFFER_START:
5826 case GL_UNIFORM_BUFFER_SIZE:
5827 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005828 if (index >= caps.maxCombinedUniformBlocks)
5829 {
Geoff Langb1196682014-07-23 13:47:29 -04005830 context->recordError(gl::Error(GL_INVALID_VALUE));
5831 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005832 }
Geoff Langbfdea662014-07-23 14:16:32 -04005833 break;
Geoff Langb1196682014-07-23 13:47:29 -04005834
Geoff Langbfdea662014-07-23 14:16:32 -04005835 default:
Geoff Langb1196682014-07-23 13:47:29 -04005836 context->recordError(gl::Error(GL_INVALID_ENUM));
5837 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005838 }
5839
5840 if (!(context->getIndexedIntegerv(target, index, data)))
5841 {
5842 GLenum nativeType;
5843 unsigned int numParams = 0;
5844 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005845 {
5846 context->recordError(gl::Error(GL_INVALID_ENUM));
5847 return;
5848 }
Shannon Woods15934d52013-08-19 14:28:49 -04005849
Geoff Langbfdea662014-07-23 14:16:32 -04005850 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005851 {
Geoff Langbfdea662014-07-23 14:16:32 -04005852 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005853 }
Geoff Langbfdea662014-07-23 14:16:32 -04005854
5855 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005856 {
Geoff Langbfdea662014-07-23 14:16:32 -04005857 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5858 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5859 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005860
Geoff Langbfdea662014-07-23 14:16:32 -04005861 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005862
Geoff Langbfdea662014-07-23 14:16:32 -04005863 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005864 {
Geoff Langbfdea662014-07-23 14:16:32 -04005865 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5866 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005867 }
Geoff Langbfdea662014-07-23 14:16:32 -04005868
5869 delete [] int64Params;
5870 }
5871 else
5872 {
5873 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005874 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005875 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005876 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005877}
5878
5879void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5880{
5881 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5882
Geoff Langbfdea662014-07-23 14:16:32 -04005883 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005884 if (context)
5885 {
5886 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005887 {
Geoff Langb1196682014-07-23 13:47:29 -04005888 context->recordError(gl::Error(GL_INVALID_OPERATION));
5889 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005890 }
Geoff Langbfdea662014-07-23 14:16:32 -04005891
5892 switch (primitiveMode)
5893 {
5894 case GL_TRIANGLES:
5895 case GL_LINES:
5896 case GL_POINTS:
5897 break;
Geoff Langb1196682014-07-23 13:47:29 -04005898
Geoff Langbfdea662014-07-23 14:16:32 -04005899 default:
Geoff Langb1196682014-07-23 13:47:29 -04005900 context->recordError(gl::Error(GL_INVALID_ENUM));
5901 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005902 }
5903
5904 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5905 ASSERT(transformFeedback != NULL);
5906
5907 if (transformFeedback->isStarted())
5908 {
Geoff Langb1196682014-07-23 13:47:29 -04005909 context->recordError(gl::Error(GL_INVALID_OPERATION));
5910 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005911 }
5912
5913 if (transformFeedback->isPaused())
5914 {
5915 transformFeedback->resume();
5916 }
5917 else
5918 {
5919 transformFeedback->start(primitiveMode);
5920 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005921 }
5922}
5923
5924void __stdcall glEndTransformFeedback(void)
5925{
5926 EVENT("(void)");
5927
Geoff Langbfdea662014-07-23 14:16:32 -04005928 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005929 if (context)
5930 {
5931 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005932 {
Geoff Langb1196682014-07-23 13:47:29 -04005933 context->recordError(gl::Error(GL_INVALID_OPERATION));
5934 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005935 }
Geoff Langbfdea662014-07-23 14:16:32 -04005936
5937 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5938 ASSERT(transformFeedback != NULL);
5939
5940 if (!transformFeedback->isStarted())
5941 {
Geoff Langb1196682014-07-23 13:47:29 -04005942 context->recordError(gl::Error(GL_INVALID_OPERATION));
5943 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005944 }
5945
5946 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005947 }
5948}
5949
5950void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5951{
5952 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5953 target, index, buffer, offset, size);
5954
Geoff Langbfdea662014-07-23 14:16:32 -04005955 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005956 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005957 {
Geoff Langbfdea662014-07-23 14:16:32 -04005958 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005959 {
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
Geoff Lang3a61c322014-07-10 13:01:54 -04005964 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005965 switch (target)
5966 {
5967 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04005968 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005969 {
Geoff Langb1196682014-07-23 13:47:29 -04005970 context->recordError(gl::Error(GL_INVALID_VALUE));
5971 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005972 }
Geoff Langbfdea662014-07-23 14:16:32 -04005973 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005974
Geoff Langbfdea662014-07-23 14:16:32 -04005975 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04005976 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005977 {
Geoff Langb1196682014-07-23 13:47:29 -04005978 context->recordError(gl::Error(GL_INVALID_VALUE));
5979 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005980 }
Geoff Langbfdea662014-07-23 14:16:32 -04005981 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005982
Geoff Langbfdea662014-07-23 14:16:32 -04005983 default:
Geoff Langb1196682014-07-23 13:47:29 -04005984 context->recordError(gl::Error(GL_INVALID_ENUM));
5985 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005986 }
5987
5988 if (buffer != 0 && size <= 0)
5989 {
Geoff Langb1196682014-07-23 13:47:29 -04005990 context->recordError(gl::Error(GL_INVALID_VALUE));
5991 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005992 }
5993
5994 switch (target)
5995 {
5996 case GL_TRANSFORM_FEEDBACK_BUFFER:
5997
5998 // size and offset must be a multiple of 4
5999 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006000 {
Geoff Langb1196682014-07-23 13:47:29 -04006001 context->recordError(gl::Error(GL_INVALID_VALUE));
6002 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006003 }
6004
Geoff Langbfdea662014-07-23 14:16:32 -04006005 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
6006 context->bindGenericTransformFeedbackBuffer(buffer);
6007 break;
6008
6009 case GL_UNIFORM_BUFFER:
6010
6011 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006012 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006013 {
Geoff Langb1196682014-07-23 13:47:29 -04006014 context->recordError(gl::Error(GL_INVALID_VALUE));
6015 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006016 }
Geoff Langbfdea662014-07-23 14:16:32 -04006017
6018 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6019 context->bindGenericUniformBuffer(buffer);
6020 break;
6021
6022 default:
6023 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006024 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006025 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006026}
6027
6028void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
6029{
6030 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6031 target, index, buffer);
6032
Geoff Langbfdea662014-07-23 14:16:32 -04006033 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006034 if (context)
6035 {
6036 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006037 {
Geoff Langb1196682014-07-23 13:47:29 -04006038 context->recordError(gl::Error(GL_INVALID_OPERATION));
6039 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006040 }
Geoff Langbfdea662014-07-23 14:16:32 -04006041
Geoff Lang3a61c322014-07-10 13:01:54 -04006042 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006043 switch (target)
6044 {
6045 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006046 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006047 {
Geoff Langb1196682014-07-23 13:47:29 -04006048 context->recordError(gl::Error(GL_INVALID_VALUE));
6049 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006050 }
6051 break;
6052
6053 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006054 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006055 {
Geoff Langb1196682014-07-23 13:47:29 -04006056 context->recordError(gl::Error(GL_INVALID_VALUE));
6057 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006058 }
6059 break;
6060
6061 default:
Geoff Langb1196682014-07-23 13:47:29 -04006062 context->recordError(gl::Error(GL_INVALID_ENUM));
6063 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006064 }
6065
6066 switch (target)
6067 {
6068 case GL_TRANSFORM_FEEDBACK_BUFFER:
6069 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6070 context->bindGenericTransformFeedbackBuffer(buffer);
6071 break;
6072
6073 case GL_UNIFORM_BUFFER:
6074 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6075 context->bindGenericUniformBuffer(buffer);
6076 break;
6077
6078 default:
6079 UNREACHABLE();
6080 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006081 }
6082}
6083
6084void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6085{
6086 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6087 program, count, varyings, bufferMode);
6088
Geoff Langbfdea662014-07-23 14:16:32 -04006089 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006090 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006091 {
Geoff Langbfdea662014-07-23 14:16:32 -04006092 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006093 {
Geoff Langb1196682014-07-23 13:47:29 -04006094 context->recordError(gl::Error(GL_INVALID_OPERATION));
6095 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006096 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006097
Geoff Langbfdea662014-07-23 14:16:32 -04006098 if (count < 0)
6099 {
Geoff Langb1196682014-07-23 13:47:29 -04006100 context->recordError(gl::Error(GL_INVALID_VALUE));
6101 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006102 }
6103
Geoff Lang05881a02014-07-10 14:05:30 -04006104 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006105 switch (bufferMode)
6106 {
6107 case GL_INTERLEAVED_ATTRIBS:
6108 break;
6109 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006110 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006111 {
Geoff Langb1196682014-07-23 13:47:29 -04006112 context->recordError(gl::Error(GL_INVALID_VALUE));
6113 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006114 }
Geoff Langbfdea662014-07-23 14:16:32 -04006115 break;
6116 default:
Geoff Langb1196682014-07-23 13:47:29 -04006117 context->recordError(gl::Error(GL_INVALID_ENUM));
6118 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006119 }
Geoff Langbfdea662014-07-23 14:16:32 -04006120
6121 if (!gl::ValidProgram(context, program))
6122 {
6123 return;
6124 }
6125
6126 gl::Program *programObject = context->getProgram(program);
6127 ASSERT(programObject);
6128
6129 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006130 }
6131}
6132
6133void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6134{
6135 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6136 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6137 program, index, bufSize, length, size, type, name);
6138
Geoff Langbfdea662014-07-23 14:16:32 -04006139 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006140 if (context)
6141 {
6142 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006143 {
Geoff Langb1196682014-07-23 13:47:29 -04006144 context->recordError(gl::Error(GL_INVALID_OPERATION));
6145 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006146 }
Geoff Langbfdea662014-07-23 14:16:32 -04006147
6148 if (bufSize < 0)
6149 {
Geoff Langb1196682014-07-23 13:47:29 -04006150 context->recordError(gl::Error(GL_INVALID_VALUE));
6151 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006152 }
6153
6154 if (!gl::ValidProgram(context, program))
6155 {
6156 return;
6157 }
6158
6159 gl::Program *programObject = context->getProgram(program);
6160 ASSERT(programObject);
6161
6162 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6163 {
Geoff Langb1196682014-07-23 13:47:29 -04006164 context->recordError(gl::Error(GL_INVALID_VALUE));
6165 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006166 }
6167
6168 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006169 }
6170}
6171
6172void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6173{
6174 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6175 index, size, type, stride, pointer);
6176
Geoff Langbfdea662014-07-23 14:16:32 -04006177 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006178 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006179 {
Geoff Langbfdea662014-07-23 14:16:32 -04006180 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006181 {
Geoff Langb1196682014-07-23 13:47:29 -04006182 context->recordError(gl::Error(GL_INVALID_OPERATION));
6183 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006184 }
6185
Geoff Langb1196682014-07-23 13:47:29 -04006186 if (index >= gl::MAX_VERTEX_ATTRIBS)
6187 {
6188 context->recordError(gl::Error(GL_INVALID_VALUE));
6189 return;
6190 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006191
Geoff Langb1196682014-07-23 13:47:29 -04006192 if (size < 1 || size > 4)
6193 {
6194 context->recordError(gl::Error(GL_INVALID_VALUE));
6195 return;
6196 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006197
Geoff Langb1196682014-07-23 13:47:29 -04006198 switch (type)
6199 {
6200 case GL_BYTE:
6201 case GL_UNSIGNED_BYTE:
6202 case GL_SHORT:
6203 case GL_UNSIGNED_SHORT:
6204 case GL_INT:
6205 case GL_UNSIGNED_INT:
6206 case GL_INT_2_10_10_10_REV:
6207 case GL_UNSIGNED_INT_2_10_10_10_REV:
6208 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006209
Geoff Langb1196682014-07-23 13:47:29 -04006210 default:
6211 context->recordError(gl::Error(GL_INVALID_ENUM));
6212 return;
6213 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006214
Geoff Langb1196682014-07-23 13:47:29 -04006215 if (stride < 0)
6216 {
6217 context->recordError(gl::Error(GL_INVALID_VALUE));
6218 return;
6219 }
Geoff Langbfdea662014-07-23 14:16:32 -04006220
Geoff Langb1196682014-07-23 13:47:29 -04006221 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6222 {
6223 context->recordError(gl::Error(GL_INVALID_OPERATION));
6224 return;
6225 }
6226
Geoff Langbfdea662014-07-23 14:16:32 -04006227 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6228 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6229 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6230 // and the pointer argument is not NULL.
6231 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006232 {
Geoff Langb1196682014-07-23 13:47:29 -04006233 context->recordError(gl::Error(GL_INVALID_OPERATION));
6234 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006235 }
6236
Geoff Langbfdea662014-07-23 14:16:32 -04006237 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6238 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006239 }
6240}
6241
6242void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6243{
6244 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6245 index, pname, params);
6246
Geoff Langbfdea662014-07-23 14:16:32 -04006247 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006248 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006249 {
Geoff Langbfdea662014-07-23 14:16:32 -04006250 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006251 {
Geoff Langb1196682014-07-23 13:47:29 -04006252 context->recordError(gl::Error(GL_INVALID_OPERATION));
6253 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006254 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006255
Geoff Langbfdea662014-07-23 14:16:32 -04006256 if (index >= gl::MAX_VERTEX_ATTRIBS)
6257 {
Geoff Langb1196682014-07-23 13:47:29 -04006258 context->recordError(gl::Error(GL_INVALID_VALUE));
6259 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006260 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006261
Geoff Langbfdea662014-07-23 14:16:32 -04006262 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006263
Geoff Langb1196682014-07-23 13:47:29 -04006264 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006265 {
6266 return;
6267 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006268
Geoff Langbfdea662014-07-23 14:16:32 -04006269 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6270 {
6271 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6272 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006273 {
Geoff Langbfdea662014-07-23 14:16:32 -04006274 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006275 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006276 }
Geoff Langbfdea662014-07-23 14:16:32 -04006277 else
6278 {
6279 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6280 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006281 }
6282}
6283
6284void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6285{
6286 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6287 index, pname, params);
6288
Geoff Langbfdea662014-07-23 14:16:32 -04006289 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006290 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006291 {
Geoff Langbfdea662014-07-23 14:16:32 -04006292 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006293 {
Geoff Langb1196682014-07-23 13:47:29 -04006294 context->recordError(gl::Error(GL_INVALID_OPERATION));
6295 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006296 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006297
Geoff Langbfdea662014-07-23 14:16:32 -04006298 if (index >= gl::MAX_VERTEX_ATTRIBS)
6299 {
Geoff Langb1196682014-07-23 13:47:29 -04006300 context->recordError(gl::Error(GL_INVALID_VALUE));
6301 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006302 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006303
Geoff Langbfdea662014-07-23 14:16:32 -04006304 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006305
Geoff Langb1196682014-07-23 13:47:29 -04006306 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006307 {
6308 return;
6309 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006310
Geoff Langbfdea662014-07-23 14:16:32 -04006311 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6312 {
6313 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6314 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006315 {
Geoff Langbfdea662014-07-23 14:16:32 -04006316 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006317 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006318 }
Geoff Langbfdea662014-07-23 14:16:32 -04006319 else
6320 {
6321 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6322 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006323 }
6324}
6325
6326void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6327{
6328 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6329 index, x, y, z, w);
6330
Geoff Langbfdea662014-07-23 14:16:32 -04006331 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006332 if (context)
6333 {
6334 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006335 {
Geoff Langb1196682014-07-23 13:47:29 -04006336 context->recordError(gl::Error(GL_INVALID_OPERATION));
6337 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006338 }
Geoff Langbfdea662014-07-23 14:16:32 -04006339
6340 if (index >= gl::MAX_VERTEX_ATTRIBS)
6341 {
Geoff Langb1196682014-07-23 13:47:29 -04006342 context->recordError(gl::Error(GL_INVALID_VALUE));
6343 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006344 }
6345
6346 GLint vals[4] = { x, y, z, w };
6347 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006348 }
6349}
6350
6351void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6352{
6353 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6354 index, x, y, z, w);
6355
Geoff Langbfdea662014-07-23 14:16:32 -04006356 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006357 if (context)
6358 {
6359 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006360 {
Geoff Langb1196682014-07-23 13:47:29 -04006361 context->recordError(gl::Error(GL_INVALID_OPERATION));
6362 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006363 }
Geoff Langbfdea662014-07-23 14:16:32 -04006364
6365 if (index >= gl::MAX_VERTEX_ATTRIBS)
6366 {
Geoff Langb1196682014-07-23 13:47:29 -04006367 context->recordError(gl::Error(GL_INVALID_VALUE));
6368 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006369 }
6370
6371 GLuint vals[4] = { x, y, z, w };
6372 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006373 }
6374}
6375
6376void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6377{
6378 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6379
Geoff Langbfdea662014-07-23 14:16:32 -04006380 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006381 if (context)
6382 {
6383 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006384 {
Geoff Langb1196682014-07-23 13:47:29 -04006385 context->recordError(gl::Error(GL_INVALID_OPERATION));
6386 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006387 }
Geoff Langbfdea662014-07-23 14:16:32 -04006388
6389 if (index >= gl::MAX_VERTEX_ATTRIBS)
6390 {
Geoff Langb1196682014-07-23 13:47:29 -04006391 context->recordError(gl::Error(GL_INVALID_VALUE));
6392 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006393 }
6394
6395 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006396 }
6397}
6398
6399void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6400{
6401 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6402
Geoff Langbfdea662014-07-23 14:16:32 -04006403 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006404 if (context)
6405 {
6406 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006407 {
Geoff Langb1196682014-07-23 13:47:29 -04006408 context->recordError(gl::Error(GL_INVALID_OPERATION));
6409 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006410 }
Geoff Langbfdea662014-07-23 14:16:32 -04006411
6412 if (index >= gl::MAX_VERTEX_ATTRIBS)
6413 {
Geoff Langb1196682014-07-23 13:47:29 -04006414 context->recordError(gl::Error(GL_INVALID_VALUE));
6415 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006416 }
6417
6418 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006419 }
6420}
6421
6422void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6423{
6424 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6425 program, location, params);
6426
Geoff Langbfdea662014-07-23 14:16:32 -04006427 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006428 if (context)
6429 {
Jamie Madill0063c512014-08-25 15:47:53 -04006430 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006431 {
Jamie Madill0063c512014-08-25 15:47:53 -04006432 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006433 }
Geoff Langbfdea662014-07-23 14:16:32 -04006434
Jamie Madilla502c742014-08-28 17:19:13 -04006435 gl::Program *programObject = context->getProgram(program);
6436 ASSERT(programObject);
6437 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006438 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006439
Jamie Madill99a1e982014-08-25 15:47:54 -04006440 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006441 }
6442}
6443
6444GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6445{
6446 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6447 program, name);
6448
Geoff Langbfdea662014-07-23 14:16:32 -04006449 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006450 if (context)
6451 {
6452 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006453 {
Geoff Langb1196682014-07-23 13:47:29 -04006454 context->recordError(gl::Error(GL_INVALID_OPERATION));
6455 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006456 }
Geoff Langbfdea662014-07-23 14:16:32 -04006457
6458 if (program == 0)
6459 {
Geoff Langb1196682014-07-23 13:47:29 -04006460 context->recordError(gl::Error(GL_INVALID_VALUE));
6461 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006462 }
6463
6464 gl::Program *programObject = context->getProgram(program);
6465
6466 if (!programObject || !programObject->isLinked())
6467 {
Geoff Langb1196682014-07-23 13:47:29 -04006468 context->recordError(gl::Error(GL_INVALID_OPERATION));
6469 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006470 }
6471
6472 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6473 if (!programBinary)
6474 {
Geoff Langb1196682014-07-23 13:47:29 -04006475 context->recordError(gl::Error(GL_INVALID_OPERATION));
6476 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006477 }
6478
6479 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006480 }
6481
6482 return 0;
6483}
6484
6485void __stdcall glUniform1ui(GLint location, GLuint v0)
6486{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006487 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006488}
6489
6490void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6491{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006492 const GLuint xy[] = { v0, v1 };
6493 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006494}
6495
6496void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6497{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006498 const GLuint xyz[] = { v0, v1, v2 };
6499 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006500}
6501
6502void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6503{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006504 const GLuint xyzw[] = { v0, v1, v2, v3 };
6505 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006506}
6507
6508void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6509{
6510 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6511 location, count, value);
6512
Geoff Langbfdea662014-07-23 14:16:32 -04006513 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006514 if (context)
6515 {
6516 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006517 {
Geoff Langbfdea662014-07-23 14:16:32 -04006518 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006519 }
Geoff Langbfdea662014-07-23 14:16:32 -04006520
6521 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6522 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006523 }
6524}
6525
6526void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6527{
6528 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6529 location, count, value);
6530
Geoff Langbfdea662014-07-23 14:16:32 -04006531 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006532 if (context)
6533 {
6534 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006535 {
Geoff Langbfdea662014-07-23 14:16:32 -04006536 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006537 }
Geoff Langbfdea662014-07-23 14:16:32 -04006538
6539 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6540 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006541 }
6542}
6543
6544void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6545{
6546 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6547 location, count, value);
6548
Geoff Langbfdea662014-07-23 14:16:32 -04006549 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006550 if (context)
6551 {
6552 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006553 {
Geoff Langbfdea662014-07-23 14:16:32 -04006554 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006555 }
Geoff Langbfdea662014-07-23 14:16:32 -04006556
6557 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6558 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006559 }
6560}
6561
6562void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6563{
6564 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6565 location, count, value);
6566
Geoff Langbfdea662014-07-23 14:16:32 -04006567 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006568 if (context)
6569 {
6570 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006571 {
Geoff Langbfdea662014-07-23 14:16:32 -04006572 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006573 }
Geoff Langbfdea662014-07-23 14:16:32 -04006574
6575 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6576 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006577 }
6578}
6579
6580void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6581{
6582 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6583 buffer, drawbuffer, value);
6584
Geoff Langbfdea662014-07-23 14:16:32 -04006585 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006586 if (context)
6587 {
6588 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006589 {
Geoff Langbfdea662014-07-23 14:16:32 -04006590 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006591 }
Geoff Langbfdea662014-07-23 14:16:32 -04006592
6593 switch (buffer)
6594 {
6595 case GL_COLOR:
6596 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6597 {
Geoff Langb1196682014-07-23 13:47:29 -04006598 context->recordError(gl::Error(GL_INVALID_VALUE));
6599 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006600 }
6601 break;
Geoff Langb1196682014-07-23 13:47:29 -04006602
Geoff Langbfdea662014-07-23 14:16:32 -04006603 case GL_STENCIL:
6604 if (drawbuffer != 0)
6605 {
Geoff Langb1196682014-07-23 13:47:29 -04006606 context->recordError(gl::Error(GL_INVALID_VALUE));
6607 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006608 }
6609 break;
Geoff Langb1196682014-07-23 13:47:29 -04006610
Geoff Langbfdea662014-07-23 14:16:32 -04006611 default:
Geoff Langb1196682014-07-23 13:47:29 -04006612 context->recordError(gl::Error(GL_INVALID_ENUM));
6613 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006614 }
6615
Geoff Langcc79b8c2014-07-25 13:48:02 -04006616 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6617 if (error.isError())
6618 {
6619 context->recordError(error);
6620 return;
6621 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006622 }
6623}
6624
6625void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6626{
6627 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6628 buffer, drawbuffer, value);
6629
Geoff Langbfdea662014-07-23 14:16:32 -04006630 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006631 if (context)
6632 {
6633 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006634 {
Geoff Langbfdea662014-07-23 14:16:32 -04006635 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006636 }
Geoff Langbfdea662014-07-23 14:16:32 -04006637
6638 switch (buffer)
6639 {
6640 case GL_COLOR:
6641 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6642 {
Geoff Langb1196682014-07-23 13:47:29 -04006643 context->recordError(gl::Error(GL_INVALID_VALUE));
6644 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006645 }
6646 break;
Geoff Langb1196682014-07-23 13:47:29 -04006647
Geoff Langbfdea662014-07-23 14:16:32 -04006648 default:
Geoff Langb1196682014-07-23 13:47:29 -04006649 context->recordError(gl::Error(GL_INVALID_ENUM));
6650 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006651 }
6652
Geoff Langcc79b8c2014-07-25 13:48:02 -04006653 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6654 if (error.isError())
6655 {
6656 context->recordError(error);
6657 return;
6658 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006659 }
6660}
6661
6662void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6663{
6664 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6665 buffer, drawbuffer, value);
6666
Geoff Langbfdea662014-07-23 14:16:32 -04006667 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006668 if (context)
6669 {
6670 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006671 {
Geoff Langbfdea662014-07-23 14:16:32 -04006672 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006673 }
Geoff Langbfdea662014-07-23 14:16:32 -04006674
6675 switch (buffer)
6676 {
6677 case GL_COLOR:
6678 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6679 {
Geoff Langb1196682014-07-23 13:47:29 -04006680 context->recordError(gl::Error(GL_INVALID_VALUE));
6681 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006682 }
6683 break;
Geoff Langb1196682014-07-23 13:47:29 -04006684
Geoff Langbfdea662014-07-23 14:16:32 -04006685 case GL_DEPTH:
6686 if (drawbuffer != 0)
6687 {
Geoff Langb1196682014-07-23 13:47:29 -04006688 context->recordError(gl::Error(GL_INVALID_VALUE));
6689 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006690 }
6691 break;
Geoff Langb1196682014-07-23 13:47:29 -04006692
Geoff Langbfdea662014-07-23 14:16:32 -04006693 default:
Geoff Langb1196682014-07-23 13:47:29 -04006694 context->recordError(gl::Error(GL_INVALID_ENUM));
6695 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006696 }
6697
Geoff Langcc79b8c2014-07-25 13:48:02 -04006698 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6699 if (error.isError())
6700 {
6701 context->recordError(error);
6702 return;
6703 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006704 }
6705}
6706
6707void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6708{
6709 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6710 buffer, drawbuffer, depth, stencil);
6711
Geoff Langbfdea662014-07-23 14:16:32 -04006712 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006713 if (context)
6714 {
6715 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006716 {
Geoff Langbfdea662014-07-23 14:16:32 -04006717 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006718 }
Geoff Langbfdea662014-07-23 14:16:32 -04006719
6720 switch (buffer)
6721 {
6722 case GL_DEPTH_STENCIL:
6723 if (drawbuffer != 0)
6724 {
Geoff Langb1196682014-07-23 13:47:29 -04006725 context->recordError(gl::Error(GL_INVALID_VALUE));
6726 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006727 }
6728 break;
Geoff Langb1196682014-07-23 13:47:29 -04006729
Geoff Langbfdea662014-07-23 14:16:32 -04006730 default:
Geoff Langb1196682014-07-23 13:47:29 -04006731 context->recordError(gl::Error(GL_INVALID_ENUM));
6732 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006733 }
6734
Geoff Langcc79b8c2014-07-25 13:48:02 -04006735 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6736 if (error.isError())
6737 {
6738 context->recordError(error);
6739 return;
6740 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006741 }
6742}
6743
6744const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6745{
6746 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6747
Geoff Langbfdea662014-07-23 14:16:32 -04006748 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006749 if (context)
6750 {
6751 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006752 {
Geoff Langb1196682014-07-23 13:47:29 -04006753 context->recordError(gl::Error(GL_INVALID_OPERATION));
6754 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006755 }
Geoff Langbfdea662014-07-23 14:16:32 -04006756
6757 if (name != GL_EXTENSIONS)
6758 {
Geoff Langb1196682014-07-23 13:47:29 -04006759 context->recordError(gl::Error(GL_INVALID_ENUM));
6760 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006761 }
6762
6763 if (index >= context->getExtensionStringCount())
6764 {
Geoff Langb1196682014-07-23 13:47:29 -04006765 context->recordError(gl::Error(GL_INVALID_VALUE));
6766 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006767 }
6768
6769 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006770 }
6771
6772 return NULL;
6773}
6774
6775void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6776{
6777 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6778 readTarget, writeTarget, readOffset, writeOffset, size);
6779
Geoff Langbfdea662014-07-23 14:16:32 -04006780 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006781 if (context)
6782 {
6783 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006784 {
Geoff Langb1196682014-07-23 13:47:29 -04006785 context->recordError(gl::Error(GL_INVALID_OPERATION));
6786 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006787 }
Geoff Langbfdea662014-07-23 14:16:32 -04006788
6789 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6790 {
Geoff Langb1196682014-07-23 13:47:29 -04006791 context->recordError(gl::Error(GL_INVALID_ENUM));
6792 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006793 }
6794
6795 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6796 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6797
6798 if (!readBuffer || !writeBuffer)
6799 {
Geoff Langb1196682014-07-23 13:47:29 -04006800 context->recordError(gl::Error(GL_INVALID_OPERATION));
6801 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006802 }
6803
Jamie Madillcfaaf722014-07-31 10:47:54 -04006804 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006805 if (readBuffer->isMapped() || writeBuffer->isMapped())
6806 {
Geoff Langb1196682014-07-23 13:47:29 -04006807 context->recordError(gl::Error(GL_INVALID_OPERATION));
6808 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006809 }
6810
6811 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6812 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6813 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6814 {
Geoff Langb1196682014-07-23 13:47:29 -04006815 context->recordError(gl::Error(GL_INVALID_VALUE));
6816 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006817 }
6818
6819 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6820 {
Geoff Langb1196682014-07-23 13:47:29 -04006821 context->recordError(gl::Error(GL_INVALID_VALUE));
6822 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006823 }
6824
Geoff Langbfdea662014-07-23 14:16:32 -04006825 // if size is zero, the copy is a successful no-op
6826 if (size > 0)
6827 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006828 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6829 if (error.isError())
6830 {
6831 context->recordError(error);
6832 return;
6833 }
Geoff Langbfdea662014-07-23 14:16:32 -04006834 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006835 }
6836}
6837
6838void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6839{
6840 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6841 program, uniformCount, uniformNames, uniformIndices);
6842
Geoff Langbfdea662014-07-23 14:16:32 -04006843 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006844 if (context)
6845 {
6846 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006847 {
Geoff Langb1196682014-07-23 13:47:29 -04006848 context->recordError(gl::Error(GL_INVALID_OPERATION));
6849 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006850 }
6851
6852 if (uniformCount < 0)
6853 {
Geoff Langb1196682014-07-23 13:47:29 -04006854 context->recordError(gl::Error(GL_INVALID_VALUE));
6855 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006856 }
6857
6858 gl::Program *programObject = context->getProgram(program);
6859
6860 if (!programObject)
6861 {
6862 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006863 {
Geoff Langb1196682014-07-23 13:47:29 -04006864 context->recordError(gl::Error(GL_INVALID_OPERATION));
6865 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006866 }
Geoff Langbfdea662014-07-23 14:16:32 -04006867 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006868 {
Geoff Langb1196682014-07-23 13:47:29 -04006869 context->recordError(gl::Error(GL_INVALID_VALUE));
6870 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006871 }
Geoff Langbfdea662014-07-23 14:16:32 -04006872 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006873
Geoff Langbfdea662014-07-23 14:16:32 -04006874 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6875 if (!programObject->isLinked() || !programBinary)
6876 {
6877 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006878 {
Geoff Langbfdea662014-07-23 14:16:32 -04006879 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006880 }
6881 }
Geoff Langbfdea662014-07-23 14:16:32 -04006882 else
6883 {
6884 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6885 {
6886 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6887 }
6888 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006889 }
6890}
6891
6892void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6893{
6894 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6895 program, uniformCount, uniformIndices, pname, params);
6896
Geoff Langbfdea662014-07-23 14:16:32 -04006897 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006898 if (context)
6899 {
6900 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006901 {
Geoff Langb1196682014-07-23 13:47:29 -04006902 context->recordError(gl::Error(GL_INVALID_OPERATION));
6903 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006904 }
6905
6906 if (uniformCount < 0)
6907 {
Geoff Langb1196682014-07-23 13:47:29 -04006908 context->recordError(gl::Error(GL_INVALID_VALUE));
6909 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006910 }
6911
6912 gl::Program *programObject = context->getProgram(program);
6913
6914 if (!programObject)
6915 {
6916 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006917 {
Geoff Langb1196682014-07-23 13:47:29 -04006918 context->recordError(gl::Error(GL_INVALID_OPERATION));
6919 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006920 }
Geoff Langbfdea662014-07-23 14:16:32 -04006921 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006922 {
Geoff Langb1196682014-07-23 13:47:29 -04006923 context->recordError(gl::Error(GL_INVALID_VALUE));
6924 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006925 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006926 }
Geoff Langbfdea662014-07-23 14:16:32 -04006927
6928 switch (pname)
6929 {
6930 case GL_UNIFORM_TYPE:
6931 case GL_UNIFORM_SIZE:
6932 case GL_UNIFORM_NAME_LENGTH:
6933 case GL_UNIFORM_BLOCK_INDEX:
6934 case GL_UNIFORM_OFFSET:
6935 case GL_UNIFORM_ARRAY_STRIDE:
6936 case GL_UNIFORM_MATRIX_STRIDE:
6937 case GL_UNIFORM_IS_ROW_MAJOR:
6938 break;
Geoff Langb1196682014-07-23 13:47:29 -04006939
Geoff Langbfdea662014-07-23 14:16:32 -04006940 default:
Geoff Langb1196682014-07-23 13:47:29 -04006941 context->recordError(gl::Error(GL_INVALID_ENUM));
6942 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006943 }
6944
6945 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6946
6947 if (!programBinary && uniformCount > 0)
6948 {
Geoff Langb1196682014-07-23 13:47:29 -04006949 context->recordError(gl::Error(GL_INVALID_VALUE));
6950 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006951 }
6952
6953 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6954 {
6955 const GLuint index = uniformIndices[uniformId];
6956
6957 if (index >= (GLuint)programBinary->getActiveUniformCount())
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
6964 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6965 {
6966 const GLuint index = uniformIndices[uniformId];
6967 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6968 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006969 }
6970}
6971
6972GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6973{
6974 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6975
Geoff Langbfdea662014-07-23 14:16:32 -04006976 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006977 if (context)
6978 {
6979 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006980 {
Geoff Langb1196682014-07-23 13:47:29 -04006981 context->recordError(gl::Error(GL_INVALID_OPERATION));
6982 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04006983 }
6984
6985 gl::Program *programObject = context->getProgram(program);
6986
6987 if (!programObject)
6988 {
6989 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006990 {
Geoff Langb1196682014-07-23 13:47:29 -04006991 context->recordError(gl::Error(GL_INVALID_OPERATION));
6992 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006993 }
Geoff Langbfdea662014-07-23 14:16:32 -04006994 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006995 {
Geoff Langb1196682014-07-23 13:47:29 -04006996 context->recordError(gl::Error(GL_INVALID_VALUE));
6997 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006998 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006999 }
Geoff Langbfdea662014-07-23 14:16:32 -04007000
7001 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7002 if (!programBinary)
7003 {
7004 return GL_INVALID_INDEX;
7005 }
7006
7007 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007008 }
7009
7010 return 0;
7011}
7012
7013void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
7014{
7015 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7016 program, uniformBlockIndex, pname, params);
7017
Geoff Langbfdea662014-07-23 14:16:32 -04007018 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007019 if (context)
7020 {
7021 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007022 {
Geoff Langb1196682014-07-23 13:47:29 -04007023 context->recordError(gl::Error(GL_INVALID_OPERATION));
7024 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007025 }
7026 gl::Program *programObject = context->getProgram(program);
7027
7028 if (!programObject)
7029 {
7030 if (context->getShader(program))
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;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007034 }
Geoff Langbfdea662014-07-23 14:16:32 -04007035 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007036 {
Geoff Langb1196682014-07-23 13:47:29 -04007037 context->recordError(gl::Error(GL_INVALID_VALUE));
7038 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007039 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007040 }
Geoff Langbfdea662014-07-23 14:16:32 -04007041
7042 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7043
7044 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7045 {
Geoff Langb1196682014-07-23 13:47:29 -04007046 context->recordError(gl::Error(GL_INVALID_VALUE));
7047 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007048 }
7049
7050 switch (pname)
7051 {
7052 case GL_UNIFORM_BLOCK_BINDING:
7053 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7054 break;
7055
7056 case GL_UNIFORM_BLOCK_DATA_SIZE:
7057 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7058 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7059 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7060 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7061 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7062 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7063 break;
7064
7065 default:
Geoff Langb1196682014-07-23 13:47:29 -04007066 context->recordError(gl::Error(GL_INVALID_ENUM));
7067 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007069 }
7070}
7071
7072void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7073{
7074 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7075 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7076
Geoff Langbfdea662014-07-23 14:16:32 -04007077 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007078 if (context)
7079 {
7080 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007081 {
Geoff Langb1196682014-07-23 13:47:29 -04007082 context->recordError(gl::Error(GL_INVALID_OPERATION));
7083 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007084 }
7085
7086 gl::Program *programObject = context->getProgram(program);
7087
7088 if (!programObject)
7089 {
7090 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007091 {
Geoff Langb1196682014-07-23 13:47:29 -04007092 context->recordError(gl::Error(GL_INVALID_OPERATION));
7093 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007094 }
Geoff Langbfdea662014-07-23 14:16:32 -04007095 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007096 {
Geoff Langb1196682014-07-23 13:47:29 -04007097 context->recordError(gl::Error(GL_INVALID_VALUE));
7098 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007099 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007100 }
Geoff Langbfdea662014-07-23 14:16:32 -04007101
7102 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7103
7104 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7105 {
Geoff Langb1196682014-07-23 13:47:29 -04007106 context->recordError(gl::Error(GL_INVALID_VALUE));
7107 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007108 }
7109
7110 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007111 }
7112}
7113
7114void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7115{
7116 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7117 program, uniformBlockIndex, uniformBlockBinding);
7118
Geoff Langbfdea662014-07-23 14:16:32 -04007119 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007120 if (context)
7121 {
7122 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007123 {
Geoff Langb1196682014-07-23 13:47:29 -04007124 context->recordError(gl::Error(GL_INVALID_OPERATION));
7125 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007126 }
7127
Geoff Lang3a61c322014-07-10 13:01:54 -04007128 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007129 {
Geoff Langb1196682014-07-23 13:47:29 -04007130 context->recordError(gl::Error(GL_INVALID_VALUE));
7131 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007132 }
7133
7134 gl::Program *programObject = context->getProgram(program);
7135
7136 if (!programObject)
7137 {
7138 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007139 {
Geoff Langb1196682014-07-23 13:47:29 -04007140 context->recordError(gl::Error(GL_INVALID_OPERATION));
7141 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007142 }
Geoff Langbfdea662014-07-23 14:16:32 -04007143 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007144 {
Geoff Langb1196682014-07-23 13:47:29 -04007145 context->recordError(gl::Error(GL_INVALID_VALUE));
7146 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007147 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007148 }
Geoff Langbfdea662014-07-23 14:16:32 -04007149
7150 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7151
7152 // if never linked, there won't be any uniform blocks
7153 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7154 {
Geoff Langb1196682014-07-23 13:47:29 -04007155 context->recordError(gl::Error(GL_INVALID_VALUE));
7156 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007157 }
7158
7159 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007160 }
7161}
7162
7163void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7164{
7165 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7166 mode, first, count, instanceCount);
7167
Geoff Langbfdea662014-07-23 14:16:32 -04007168 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007169 if (context)
7170 {
7171 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007172 {
Geoff Langb1196682014-07-23 13:47:29 -04007173 context->recordError(gl::Error(GL_INVALID_OPERATION));
7174 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007175 }
Geoff Langbfdea662014-07-23 14:16:32 -04007176
7177 // glDrawArraysInstanced
7178 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007179 }
7180}
7181
7182void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7183{
7184 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7185 mode, count, type, indices, instanceCount);
7186
Geoff Langbfdea662014-07-23 14:16:32 -04007187 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007188 if (context)
7189 {
7190 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007191 {
Geoff Langb1196682014-07-23 13:47:29 -04007192 context->recordError(gl::Error(GL_INVALID_OPERATION));
7193 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007194 }
Geoff Langbfdea662014-07-23 14:16:32 -04007195
7196 // glDrawElementsInstanced
7197 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007198 }
7199}
7200
7201GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7202{
7203 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7204
Geoff Langbfdea662014-07-23 14:16:32 -04007205 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007206 if (context)
7207 {
7208 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007209 {
Geoff Langb1196682014-07-23 13:47:29 -04007210 context->recordError(gl::Error(GL_INVALID_OPERATION));
7211 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007212 }
Geoff Langbfdea662014-07-23 14:16:32 -04007213
7214 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7215 {
Geoff Langb1196682014-07-23 13:47:29 -04007216 context->recordError(gl::Error(GL_INVALID_ENUM));
7217 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007218 }
7219
7220 if (flags != 0)
7221 {
Geoff Langb1196682014-07-23 13:47:29 -04007222 context->recordError(gl::Error(GL_INVALID_VALUE));
7223 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007224 }
7225
7226 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007227 }
7228
7229 return NULL;
7230}
7231
7232GLboolean __stdcall glIsSync(GLsync sync)
7233{
7234 EVENT("(GLsync sync = 0x%0.8p)", sync);
7235
Geoff Langbfdea662014-07-23 14:16:32 -04007236 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007237 if (context)
7238 {
7239 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007240 {
Geoff Langb1196682014-07-23 13:47:29 -04007241 context->recordError(gl::Error(GL_INVALID_OPERATION));
7242 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007243 }
Geoff Langbfdea662014-07-23 14:16:32 -04007244
7245 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007246 }
7247
7248 return GL_FALSE;
7249}
7250
7251void __stdcall glDeleteSync(GLsync sync)
7252{
7253 EVENT("(GLsync sync = 0x%0.8p)", sync);
7254
Geoff Langbfdea662014-07-23 14:16:32 -04007255 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007256 if (context)
7257 {
7258 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007259 {
Geoff Langb1196682014-07-23 13:47:29 -04007260 context->recordError(gl::Error(GL_INVALID_OPERATION));
7261 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007262 }
Geoff Langbfdea662014-07-23 14:16:32 -04007263
7264 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7265 {
Geoff Langb1196682014-07-23 13:47:29 -04007266 context->recordError(gl::Error(GL_INVALID_VALUE));
7267 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007268 }
7269
7270 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007271 }
7272}
7273
7274GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7275{
7276 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7277 sync, flags, timeout);
7278
Geoff Langbfdea662014-07-23 14:16:32 -04007279 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007280 if (context)
7281 {
7282 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007283 {
Geoff Langb1196682014-07-23 13:47:29 -04007284 context->recordError(gl::Error(GL_INVALID_OPERATION));
7285 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007286 }
Geoff Langbfdea662014-07-23 14:16:32 -04007287
7288 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7289 {
Geoff Langb1196682014-07-23 13:47:29 -04007290 context->recordError(gl::Error(GL_INVALID_VALUE));
7291 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007292 }
7293
7294 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7295
7296 if (!fenceSync)
7297 {
Geoff Langb1196682014-07-23 13:47:29 -04007298 context->recordError(gl::Error(GL_INVALID_VALUE));
7299 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007300 }
7301
7302 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007303 }
7304
7305 return GL_FALSE;
7306}
7307
7308void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7309{
7310 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7311 sync, flags, timeout);
7312
Geoff Langbfdea662014-07-23 14:16:32 -04007313 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007314 if (context)
7315 {
7316 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007317 {
Geoff Langb1196682014-07-23 13:47:29 -04007318 context->recordError(gl::Error(GL_INVALID_OPERATION));
7319 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007320 }
Geoff Langbfdea662014-07-23 14:16:32 -04007321
7322 if (flags != 0)
7323 {
Geoff Langb1196682014-07-23 13:47:29 -04007324 context->recordError(gl::Error(GL_INVALID_VALUE));
7325 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007326 }
7327
7328 if (timeout != GL_TIMEOUT_IGNORED)
7329 {
Geoff Langb1196682014-07-23 13:47:29 -04007330 context->recordError(gl::Error(GL_INVALID_VALUE));
7331 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007332 }
7333
7334 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7335
7336 if (!fenceSync)
7337 {
Geoff Langb1196682014-07-23 13:47:29 -04007338 context->recordError(gl::Error(GL_INVALID_VALUE));
7339 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007340 }
7341
7342 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007343 }
7344}
7345
7346void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7347{
7348 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7349 pname, params);
7350
Geoff Langbfdea662014-07-23 14:16:32 -04007351 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007352 if (context)
7353 {
7354 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007355 {
Geoff Langb1196682014-07-23 13:47:29 -04007356 context->recordError(gl::Error(GL_INVALID_OPERATION));
7357 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007358 }
Geoff Langbfdea662014-07-23 14:16:32 -04007359
7360 GLenum nativeType;
7361 unsigned int numParams = 0;
7362 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7363 {
7364 return;
7365 }
7366
7367 if (nativeType == GL_INT_64_ANGLEX)
7368 {
7369 context->getInteger64v(pname, params);
7370 }
7371 else
7372 {
7373 CastStateValues(context, nativeType, pname, numParams, params);
7374 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007375 }
7376}
7377
7378void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7379{
7380 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7381 sync, pname, bufSize, length, values);
7382
Geoff Langbfdea662014-07-23 14:16:32 -04007383 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007384 if (context)
7385 {
7386 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007387 {
Geoff Langb1196682014-07-23 13:47:29 -04007388 context->recordError(gl::Error(GL_INVALID_OPERATION));
7389 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007390 }
Geoff Langbfdea662014-07-23 14:16:32 -04007391
7392 if (bufSize < 0)
7393 {
Geoff Langb1196682014-07-23 13:47:29 -04007394 context->recordError(gl::Error(GL_INVALID_VALUE));
7395 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007396 }
7397
7398 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7399
7400 if (!fenceSync)
7401 {
Geoff Langb1196682014-07-23 13:47:29 -04007402 context->recordError(gl::Error(GL_INVALID_VALUE));
7403 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007404 }
7405
7406 switch (pname)
7407 {
7408 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7409 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7410 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7411 case GL_SYNC_FLAGS: values[0] = 0; break;
7412
7413 default:
Geoff Langb1196682014-07-23 13:47:29 -04007414 context->recordError(gl::Error(GL_INVALID_ENUM));
7415 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007416 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007417 }
7418}
7419
7420void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7421{
7422 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7423 target, index, data);
7424
Geoff Langbfdea662014-07-23 14:16:32 -04007425 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007426 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007427 {
Geoff Langbfdea662014-07-23 14:16:32 -04007428 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007429 {
Geoff Langb1196682014-07-23 13:47:29 -04007430 context->recordError(gl::Error(GL_INVALID_OPERATION));
7431 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007432 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007433
Geoff Lang3a61c322014-07-10 13:01:54 -04007434 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007435 switch (target)
7436 {
7437 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7438 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7439 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007440 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7441 {
Geoff Langb1196682014-07-23 13:47:29 -04007442 context->recordError(gl::Error(GL_INVALID_VALUE));
7443 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007444 }
Geoff Langbfdea662014-07-23 14:16:32 -04007445 break;
Geoff Langb1196682014-07-23 13:47:29 -04007446
Geoff Langbfdea662014-07-23 14:16:32 -04007447 case GL_UNIFORM_BUFFER_START:
7448 case GL_UNIFORM_BUFFER_SIZE:
7449 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007450 if (index >= caps.maxUniformBufferBindings)
7451 {
Geoff Langb1196682014-07-23 13:47:29 -04007452 context->recordError(gl::Error(GL_INVALID_VALUE));
7453 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007454 }
Geoff Langbfdea662014-07-23 14:16:32 -04007455 break;
Geoff Langb1196682014-07-23 13:47:29 -04007456
Geoff Langbfdea662014-07-23 14:16:32 -04007457 default:
Geoff Langb1196682014-07-23 13:47:29 -04007458 context->recordError(gl::Error(GL_INVALID_ENUM));
7459 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007460 }
7461
7462 if (!(context->getIndexedInteger64v(target, index, data)))
7463 {
7464 GLenum nativeType;
7465 unsigned int numParams = 0;
7466 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007467 {
7468 context->recordError(gl::Error(GL_INVALID_ENUM));
7469 return;
7470 }
Shannon Woods15934d52013-08-19 14:28:49 -04007471
Geoff Langbfdea662014-07-23 14:16:32 -04007472 if (numParams == 0)
7473 return; // it is known that pname is valid, but there are no parameters to return
7474
7475 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007476 {
Geoff Langbfdea662014-07-23 14:16:32 -04007477 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007478
Geoff Langbfdea662014-07-23 14:16:32 -04007479 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007480
Geoff Langbfdea662014-07-23 14:16:32 -04007481 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007482 {
Geoff Langbfdea662014-07-23 14:16:32 -04007483 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007484 }
Geoff Langbfdea662014-07-23 14:16:32 -04007485
7486 delete [] intParams;
7487 }
7488 else
7489 {
7490 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007491 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007492 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007493 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007494}
7495
7496void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7497{
7498 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7499 target, pname, params);
7500
Geoff Langbfdea662014-07-23 14:16:32 -04007501 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007502 if (context)
7503 {
7504 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007505 {
Geoff Langb1196682014-07-23 13:47:29 -04007506 context->recordError(gl::Error(GL_INVALID_OPERATION));
7507 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007508 }
Geoff Langbfdea662014-07-23 14:16:32 -04007509
7510 if (!gl::ValidBufferTarget(context, target))
7511 {
Geoff Langb1196682014-07-23 13:47:29 -04007512 context->recordError(gl::Error(GL_INVALID_ENUM));
7513 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007514 }
7515
7516 if (!gl::ValidBufferParameter(context, pname))
7517 {
Geoff Langb1196682014-07-23 13:47:29 -04007518 context->recordError(gl::Error(GL_INVALID_ENUM));
7519 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007520 }
7521
7522 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7523
7524 if (!buffer)
7525 {
7526 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007527 context->recordError(gl::Error(GL_INVALID_OPERATION));
7528 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007529 }
7530
7531 switch (pname)
7532 {
7533 case GL_BUFFER_USAGE:
7534 *params = static_cast<GLint64>(buffer->getUsage());
7535 break;
7536 case GL_BUFFER_SIZE:
7537 *params = buffer->getSize();
7538 break;
7539 case GL_BUFFER_ACCESS_FLAGS:
7540 *params = static_cast<GLint64>(buffer->getAccessFlags());
7541 break;
7542 case GL_BUFFER_MAPPED:
7543 *params = static_cast<GLint64>(buffer->isMapped());
7544 break;
7545 case GL_BUFFER_MAP_OFFSET:
7546 *params = buffer->getMapOffset();
7547 break;
7548 case GL_BUFFER_MAP_LENGTH:
7549 *params = buffer->getMapLength();
7550 break;
7551 default: UNREACHABLE(); break;
7552 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007553 }
7554}
7555
7556void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7557{
7558 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7559
Geoff Langbfdea662014-07-23 14:16:32 -04007560 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007561 if (context)
7562 {
7563 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007564 {
Geoff Langb1196682014-07-23 13:47:29 -04007565 context->recordError(gl::Error(GL_INVALID_OPERATION));
7566 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007567 }
Geoff Langbfdea662014-07-23 14:16:32 -04007568
7569 if (count < 0)
7570 {
Geoff Langb1196682014-07-23 13:47:29 -04007571 context->recordError(gl::Error(GL_INVALID_VALUE));
7572 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007573 }
7574
7575 for (int i = 0; i < count; i++)
7576 {
7577 samplers[i] = context->createSampler();
7578 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007579 }
7580}
7581
7582void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7583{
7584 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7585
Geoff Langbfdea662014-07-23 14:16:32 -04007586 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007587 if (context)
7588 {
7589 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007590 {
Geoff Langb1196682014-07-23 13:47:29 -04007591 context->recordError(gl::Error(GL_INVALID_OPERATION));
7592 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007593 }
Geoff Langbfdea662014-07-23 14:16:32 -04007594
7595 if (count < 0)
7596 {
Geoff Langb1196682014-07-23 13:47:29 -04007597 context->recordError(gl::Error(GL_INVALID_VALUE));
7598 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007599 }
7600
7601 for (int i = 0; i < count; i++)
7602 {
7603 context->deleteSampler(samplers[i]);
7604 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007605 }
7606}
7607
7608GLboolean __stdcall glIsSampler(GLuint sampler)
7609{
7610 EVENT("(GLuint sampler = %u)", sampler);
7611
Geoff Langbfdea662014-07-23 14:16:32 -04007612 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007613 if (context)
7614 {
7615 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007616 {
Geoff Langb1196682014-07-23 13:47:29 -04007617 context->recordError(gl::Error(GL_INVALID_OPERATION));
7618 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007619 }
Geoff Langbfdea662014-07-23 14:16:32 -04007620
7621 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007622 }
7623
7624 return GL_FALSE;
7625}
7626
7627void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7628{
7629 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7630
Geoff Langbfdea662014-07-23 14:16:32 -04007631 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007632 if (context)
7633 {
7634 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007635 {
Geoff Langb1196682014-07-23 13:47:29 -04007636 context->recordError(gl::Error(GL_INVALID_OPERATION));
7637 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007638 }
Geoff Langbfdea662014-07-23 14:16:32 -04007639
7640 if (sampler != 0 && !context->isSampler(sampler))
7641 {
Geoff Langb1196682014-07-23 13:47:29 -04007642 context->recordError(gl::Error(GL_INVALID_OPERATION));
7643 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007644 }
7645
Geoff Lang3a61c322014-07-10 13:01:54 -04007646 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007647 {
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 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007653 }
7654}
7655
7656void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7657{
7658 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7659
Geoff Langbfdea662014-07-23 14:16:32 -04007660 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007661 if (context)
7662 {
7663 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007664 {
Geoff Langb1196682014-07-23 13:47:29 -04007665 context->recordError(gl::Error(GL_INVALID_OPERATION));
7666 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007667 }
Geoff Langbfdea662014-07-23 14:16:32 -04007668
Geoff Langb1196682014-07-23 13:47:29 -04007669 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007670 {
7671 return;
7672 }
7673
7674 if (!gl::ValidateTexParamParameters(context, pname, param))
7675 {
7676 return;
7677 }
7678
7679 if (!context->isSampler(sampler))
7680 {
Geoff Langb1196682014-07-23 13:47:29 -04007681 context->recordError(gl::Error(GL_INVALID_OPERATION));
7682 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007683 }
7684
7685 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007686 }
7687}
7688
7689void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7690{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007691 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007692}
7693
7694void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7695{
7696 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7697
Geoff Langbfdea662014-07-23 14:16:32 -04007698 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007699 if (context)
7700 {
7701 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007702 {
Geoff Langb1196682014-07-23 13:47:29 -04007703 context->recordError(gl::Error(GL_INVALID_OPERATION));
7704 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007705 }
Geoff Langbfdea662014-07-23 14:16:32 -04007706
Geoff Langb1196682014-07-23 13:47:29 -04007707 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007708 {
7709 return;
7710 }
7711
7712 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7713 {
7714 return;
7715 }
7716
7717 if (!context->isSampler(sampler))
7718 {
Geoff Langb1196682014-07-23 13:47:29 -04007719 context->recordError(gl::Error(GL_INVALID_OPERATION));
7720 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007721 }
7722
7723 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007724 }
7725}
7726
7727void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7728{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007729 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007730}
7731
7732void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7733{
7734 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7735
Geoff Langbfdea662014-07-23 14:16:32 -04007736 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007737 if (context)
7738 {
7739 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007740 {
Geoff Langb1196682014-07-23 13:47:29 -04007741 context->recordError(gl::Error(GL_INVALID_OPERATION));
7742 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007743 }
Geoff Langbfdea662014-07-23 14:16:32 -04007744
Geoff Langb1196682014-07-23 13:47:29 -04007745 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007746 {
7747 return;
7748 }
7749
7750 if (!context->isSampler(sampler))
7751 {
Geoff Langb1196682014-07-23 13:47:29 -04007752 context->recordError(gl::Error(GL_INVALID_OPERATION));
7753 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007754 }
7755
7756 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007757 }
7758}
7759
7760void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7761{
7762 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7763
Geoff Langbfdea662014-07-23 14:16:32 -04007764 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007765 if (context)
7766 {
7767 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007768 {
Geoff Langb1196682014-07-23 13:47:29 -04007769 context->recordError(gl::Error(GL_INVALID_OPERATION));
7770 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007771 }
Geoff Langbfdea662014-07-23 14:16:32 -04007772
Geoff Langb1196682014-07-23 13:47:29 -04007773 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007774 {
7775 return;
7776 }
7777
7778 if (!context->isSampler(sampler))
7779 {
Geoff Langb1196682014-07-23 13:47:29 -04007780 context->recordError(gl::Error(GL_INVALID_OPERATION));
7781 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007782 }
7783
7784 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007785 }
7786}
7787
7788void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7789{
7790 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7791
Geoff Langbfdea662014-07-23 14:16:32 -04007792 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007793 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007794 {
Geoff Langbfdea662014-07-23 14:16:32 -04007795 if (context->getClientVersion() < 3)
7796 {
Geoff Langb1196682014-07-23 13:47:29 -04007797 context->recordError(gl::Error(GL_INVALID_OPERATION));
7798 return;
7799 }
7800
7801 if (index >= gl::MAX_VERTEX_ATTRIBS)
7802 {
7803 context->recordError(gl::Error(GL_INVALID_VALUE));
7804 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007805 }
7806
7807 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007808 }
7809}
7810
7811void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7812{
7813 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
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
7824 switch (target)
7825 {
7826 case GL_TRANSFORM_FEEDBACK:
7827 {
7828 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7829 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7830 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7831 {
Geoff Langb1196682014-07-23 13:47:29 -04007832 context->recordError(gl::Error(GL_INVALID_OPERATION));
7833 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007834 }
7835
7836 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7837 if (context->getTransformFeedback(id) == NULL)
7838 {
Geoff Langb1196682014-07-23 13:47:29 -04007839 context->recordError(gl::Error(GL_INVALID_OPERATION));
7840 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007841 }
7842
7843 context->bindTransformFeedback(id);
7844 }
7845 break;
7846
7847 default:
Geoff Langb1196682014-07-23 13:47:29 -04007848 context->recordError(gl::Error(GL_INVALID_ENUM));
7849 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007850 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007851 }
7852}
7853
7854void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7855{
7856 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7857
Geoff Langbfdea662014-07-23 14:16:32 -04007858 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007859 if (context)
7860 {
7861 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007862 {
Geoff Langb1196682014-07-23 13:47:29 -04007863 context->recordError(gl::Error(GL_INVALID_OPERATION));
7864 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007865 }
Geoff Langbfdea662014-07-23 14:16:32 -04007866
7867 for (int i = 0; i < n; i++)
7868 {
7869 context->deleteTransformFeedback(ids[i]);
7870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007871 }
7872}
7873
7874void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7875{
7876 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7877
Geoff Langbfdea662014-07-23 14:16:32 -04007878 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007879 if (context)
7880 {
7881 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007882 {
Geoff Langb1196682014-07-23 13:47:29 -04007883 context->recordError(gl::Error(GL_INVALID_OPERATION));
7884 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007885 }
Geoff Langbfdea662014-07-23 14:16:32 -04007886
7887 for (int i = 0; i < n; i++)
7888 {
7889 ids[i] = context->createTransformFeedback();
7890 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007891 }
7892}
7893
7894GLboolean __stdcall glIsTransformFeedback(GLuint id)
7895{
7896 EVENT("(GLuint id = %u)", id);
7897
Geoff Langbfdea662014-07-23 14:16:32 -04007898 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007899 if (context)
7900 {
7901 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007902 {
Geoff Langb1196682014-07-23 13:47:29 -04007903 context->recordError(gl::Error(GL_INVALID_OPERATION));
7904 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007905 }
Geoff Langbfdea662014-07-23 14:16:32 -04007906
7907 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007908 }
7909
7910 return GL_FALSE;
7911}
7912
7913void __stdcall glPauseTransformFeedback(void)
7914{
7915 EVENT("(void)");
7916
Geoff Langbfdea662014-07-23 14:16:32 -04007917 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007918 if (context)
7919 {
7920 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007921 {
Geoff Langb1196682014-07-23 13:47:29 -04007922 context->recordError(gl::Error(GL_INVALID_OPERATION));
7923 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007924 }
Geoff Langbfdea662014-07-23 14:16:32 -04007925
7926 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7927 ASSERT(transformFeedback != NULL);
7928
7929 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7930 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7931 {
Geoff Langb1196682014-07-23 13:47:29 -04007932 context->recordError(gl::Error(GL_INVALID_OPERATION));
7933 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007934 }
7935
7936 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007937 }
7938}
7939
7940void __stdcall glResumeTransformFeedback(void)
7941{
7942 EVENT("(void)");
7943
Geoff Langbfdea662014-07-23 14:16:32 -04007944 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007945 if (context)
7946 {
7947 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007948 {
Geoff Langb1196682014-07-23 13:47:29 -04007949 context->recordError(gl::Error(GL_INVALID_OPERATION));
7950 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007951 }
Geoff Langbfdea662014-07-23 14:16:32 -04007952
7953 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7954 ASSERT(transformFeedback != NULL);
7955
7956 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7957 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7958 {
Geoff Langb1196682014-07-23 13:47:29 -04007959 context->recordError(gl::Error(GL_INVALID_OPERATION));
7960 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007961 }
7962
7963 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007964 }
7965}
7966
7967void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7968{
7969 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7970 program, bufSize, length, binaryFormat, binary);
7971
Geoff Langbfdea662014-07-23 14:16:32 -04007972 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007973 if (context)
7974 {
7975 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007976 {
Geoff Langb1196682014-07-23 13:47:29 -04007977 context->recordError(gl::Error(GL_INVALID_OPERATION));
7978 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007979 }
Geoff Langbfdea662014-07-23 14:16:32 -04007980
7981 // glGetProgramBinary
7982 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007983 }
7984}
7985
7986void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7987{
7988 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7989 program, binaryFormat, binary, length);
7990
Geoff Langbfdea662014-07-23 14:16:32 -04007991 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007992 if (context)
7993 {
7994 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007995 {
Geoff Langb1196682014-07-23 13:47:29 -04007996 context->recordError(gl::Error(GL_INVALID_OPERATION));
7997 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007998 }
Geoff Langbfdea662014-07-23 14:16:32 -04007999
8000 // glProgramBinary
8001 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008002 }
8003}
8004
8005void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
8006{
8007 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
8008 program, pname, value);
8009
Geoff Langbfdea662014-07-23 14:16:32 -04008010 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008011 if (context)
8012 {
8013 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008014 {
Geoff Langb1196682014-07-23 13:47:29 -04008015 context->recordError(gl::Error(GL_INVALID_OPERATION));
8016 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008017 }
Geoff Langbfdea662014-07-23 14:16:32 -04008018
8019 // glProgramParameteri
8020 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008021 }
8022}
8023
8024void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
8025{
8026 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8027 target, numAttachments, attachments);
8028
Geoff Langbfdea662014-07-23 14:16:32 -04008029 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008030 if (context)
8031 {
8032 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008033 {
Geoff Langb1196682014-07-23 13:47:29 -04008034 context->recordError(gl::Error(GL_INVALID_OPERATION));
8035 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008036 }
Geoff Langbfdea662014-07-23 14:16:32 -04008037
8038 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8039 {
8040 return;
8041 }
8042
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008043 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8044 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8045 {
8046 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8047 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008048 }
8049}
8050
8051void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
8052{
8053 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8054 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8055 target, numAttachments, attachments, x, y, width, height);
8056
Geoff Langbfdea662014-07-23 14:16:32 -04008057 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008058 if (context)
8059 {
8060 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008061 {
Geoff Langb1196682014-07-23 13:47:29 -04008062 context->recordError(gl::Error(GL_INVALID_OPERATION));
8063 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008064 }
Geoff Langbfdea662014-07-23 14:16:32 -04008065
8066 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8067 {
8068 return;
8069 }
8070
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008071 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8072 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8073 {
8074 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8075 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008076 }
8077}
8078
8079void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8080{
8081 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8082 target, levels, internalformat, width, height);
8083
Geoff Langbfdea662014-07-23 14:16:32 -04008084 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008085 if (context)
8086 {
8087 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008088 {
Geoff Langb1196682014-07-23 13:47:29 -04008089 context->recordError(gl::Error(GL_INVALID_OPERATION));
8090 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008091 }
Geoff Langbfdea662014-07-23 14:16:32 -04008092
8093 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8094 {
8095 return;
8096 }
8097
8098 switch (target)
8099 {
8100 case GL_TEXTURE_2D:
8101 {
8102 gl::Texture2D *texture2d = context->getTexture2D();
8103 texture2d->storage(levels, internalformat, width, height);
8104 }
8105 break;
8106
8107 case GL_TEXTURE_CUBE_MAP:
8108 {
8109 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8110 textureCube->storage(levels, internalformat, width);
8111 }
8112 break;
8113
8114 default:
Geoff Langb1196682014-07-23 13:47:29 -04008115 context->recordError(gl::Error(GL_INVALID_ENUM));
8116 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008117 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008118 }
8119}
8120
8121void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8122{
8123 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8124 "GLsizei height = %d, GLsizei depth = %d)",
8125 target, levels, internalformat, width, height, depth);
8126
Geoff Langbfdea662014-07-23 14:16:32 -04008127 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008128 if (context)
8129 {
8130 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008131 {
Geoff Langb1196682014-07-23 13:47:29 -04008132 context->recordError(gl::Error(GL_INVALID_OPERATION));
8133 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008134 }
Geoff Langbfdea662014-07-23 14:16:32 -04008135
8136 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8137 {
8138 return;
8139 }
8140
8141 switch (target)
8142 {
8143 case GL_TEXTURE_3D:
8144 {
8145 gl::Texture3D *texture3d = context->getTexture3D();
8146 texture3d->storage(levels, internalformat, width, height, depth);
8147 }
8148 break;
8149
8150 case GL_TEXTURE_2D_ARRAY:
8151 {
8152 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8153 texture2darray->storage(levels, internalformat, width, height, depth);
8154 }
8155 break;
8156
8157 default:
8158 UNREACHABLE();
8159 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008160 }
8161}
8162
8163void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8164{
8165 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8166 "GLint* params = 0x%0.8p)",
8167 target, internalformat, pname, bufSize, params);
8168
Geoff Langbfdea662014-07-23 14:16:32 -04008169 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008170 if (context)
8171 {
8172 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008173 {
Geoff Langb1196682014-07-23 13:47:29 -04008174 context->recordError(gl::Error(GL_INVALID_OPERATION));
8175 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008176 }
Geoff Langbfdea662014-07-23 14:16:32 -04008177
8178 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8179 if (!formatCaps.renderable)
8180 {
Geoff Langb1196682014-07-23 13:47:29 -04008181 context->recordError(gl::Error(GL_INVALID_ENUM));
8182 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008183 }
8184
8185 if (target != GL_RENDERBUFFER)
8186 {
Geoff Langb1196682014-07-23 13:47:29 -04008187 context->recordError(gl::Error(GL_INVALID_ENUM));
8188 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008189 }
8190
8191 if (bufSize < 0)
8192 {
Geoff Langb1196682014-07-23 13:47:29 -04008193 context->recordError(gl::Error(GL_INVALID_VALUE));
8194 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008195 }
8196
8197 switch (pname)
8198 {
8199 case GL_NUM_SAMPLE_COUNTS:
8200 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008201 {
8202 *params = formatCaps.sampleCounts.size();
8203 }
Geoff Langbfdea662014-07-23 14:16:32 -04008204 break;
Geoff Langb1196682014-07-23 13:47:29 -04008205
Geoff Langbfdea662014-07-23 14:16:32 -04008206 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008207 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008208 break;
Geoff Langb1196682014-07-23 13:47:29 -04008209
Geoff Langbfdea662014-07-23 14:16:32 -04008210 default:
Geoff Langb1196682014-07-23 13:47:29 -04008211 context->recordError(gl::Error(GL_INVALID_ENUM));
8212 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008214 }
8215}
8216
8217// Extension functions
8218
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008219void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8220 GLbitfield mask, GLenum filter)
8221{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008222 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008223 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8224 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8225 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8226
Geoff Langbfdea662014-07-23 14:16:32 -04008227 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008228 if (context)
8229 {
8230 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8231 dstX0, dstY0, dstX1, dstY1, mask, filter,
8232 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008233 {
Geoff Langbfdea662014-07-23 14:16:32 -04008234 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008235 }
Geoff Langbfdea662014-07-23 14:16:32 -04008236
8237 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8238 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008239 }
8240}
8241
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008242void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8243 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008244{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008245 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008246 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008247 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008248 target, level, internalformat, width, height, depth, border, format, type, pixels);
8249
Geoff Langbfdea662014-07-23 14:16:32 -04008250 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008251}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008252
Geoff Langbfdea662014-07-23 14:16:32 -04008253void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008254 GLenum *binaryFormat, void *binary)
8255{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008256 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 +00008257 program, bufSize, length, binaryFormat, binary);
8258
Geoff Langbfdea662014-07-23 14:16:32 -04008259 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008260 if (context)
8261 {
8262 gl::Program *programObject = context->getProgram(program);
8263
8264 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008265 {
Geoff Langb1196682014-07-23 13:47:29 -04008266 context->recordError(gl::Error(GL_INVALID_OPERATION));
8267 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008268 }
Geoff Langbfdea662014-07-23 14:16:32 -04008269
8270 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8271
8272 if (!programBinary)
8273 {
Geoff Langb1196682014-07-23 13:47:29 -04008274 context->recordError(gl::Error(GL_INVALID_OPERATION));
8275 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008276 }
8277
Geoff Lang900013c2014-07-07 11:32:19 -04008278 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04008279 {
Geoff Langb1196682014-07-23 13:47:29 -04008280 context->recordError(gl::Error(GL_INVALID_OPERATION));
8281 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008282 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008283 }
8284}
8285
8286void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8287 const void *binary, GLint length)
8288{
8289 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8290 program, binaryFormat, binary, length);
8291
Geoff Langbfdea662014-07-23 14:16:32 -04008292 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008293 if (context)
8294 {
Geoff Lang900013c2014-07-07 11:32:19 -04008295 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8296 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008297 {
Geoff Langb1196682014-07-23 13:47:29 -04008298 context->recordError(gl::Error(GL_INVALID_ENUM));
8299 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008300 }
Geoff Langbfdea662014-07-23 14:16:32 -04008301
8302 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008303 if (!programObject)
8304 {
Geoff Langb1196682014-07-23 13:47:29 -04008305 context->recordError(gl::Error(GL_INVALID_OPERATION));
8306 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008307 }
8308
Geoff Lang900013c2014-07-07 11:32:19 -04008309 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008310 }
8311}
8312
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008313void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8314{
8315 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8316
Geoff Langbfdea662014-07-23 14:16:32 -04008317 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008318 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008319 {
Geoff Langbfdea662014-07-23 14:16:32 -04008320 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008321 {
Geoff Langb1196682014-07-23 13:47:29 -04008322 context->recordError(gl::Error(GL_INVALID_VALUE));
8323 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008324 }
8325
8326 if (context->getState().getDrawFramebuffer()->id() == 0)
8327 {
8328 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008329 {
Geoff Langb1196682014-07-23 13:47:29 -04008330 context->recordError(gl::Error(GL_INVALID_OPERATION));
8331 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008332 }
8333
Geoff Langbfdea662014-07-23 14:16:32 -04008334 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008335 {
Geoff Langb1196682014-07-23 13:47:29 -04008336 context->recordError(gl::Error(GL_INVALID_OPERATION));
8337 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008338 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008339 }
Geoff Langbfdea662014-07-23 14:16:32 -04008340 else
8341 {
8342 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8343 {
8344 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8345 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8346 {
Geoff Langb1196682014-07-23 13:47:29 -04008347 context->recordError(gl::Error(GL_INVALID_OPERATION));
8348 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008349 }
8350 }
8351 }
8352
8353 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8354
8355 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8356 {
8357 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8358 }
8359
8360 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8361 {
8362 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8363 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008364 }
8365}
8366
Shannon Woodsb3801742014-03-27 14:59:19 -04008367void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8368{
8369 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8370
Geoff Langbfdea662014-07-23 14:16:32 -04008371 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008372 if (context)
8373 {
8374 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008375 {
Geoff Langb1196682014-07-23 13:47:29 -04008376 context->recordError(gl::Error(GL_INVALID_ENUM));
8377 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008378 }
Geoff Langbfdea662014-07-23 14:16:32 -04008379
8380 if (pname != GL_BUFFER_MAP_POINTER)
8381 {
Geoff Langb1196682014-07-23 13:47:29 -04008382 context->recordError(gl::Error(GL_INVALID_ENUM));
8383 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008384 }
8385
8386 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8387
8388 if (!buffer || !buffer->isMapped())
8389 {
8390 *params = NULL;
8391 }
8392 else
8393 {
8394 *params = buffer->getMapPointer();
8395 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008396 }
8397}
8398
8399void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8400{
8401 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8402
Geoff Langbfdea662014-07-23 14:16:32 -04008403 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008404 if (context)
8405 {
8406 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008407 {
Geoff Langb1196682014-07-23 13:47:29 -04008408 context->recordError(gl::Error(GL_INVALID_ENUM));
8409 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008410 }
Geoff Langbfdea662014-07-23 14:16:32 -04008411
8412 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8413
8414 if (buffer == NULL)
8415 {
Geoff Langb1196682014-07-23 13:47:29 -04008416 context->recordError(gl::Error(GL_INVALID_OPERATION));
8417 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008418 }
8419
8420 if (access != GL_WRITE_ONLY_OES)
8421 {
Geoff Langb1196682014-07-23 13:47:29 -04008422 context->recordError(gl::Error(GL_INVALID_ENUM));
8423 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008424 }
8425
8426 if (buffer->isMapped())
8427 {
Geoff Langb1196682014-07-23 13:47:29 -04008428 context->recordError(gl::Error(GL_INVALID_OPERATION));
8429 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008430 }
8431
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008432 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8433 if (error.isError())
8434 {
8435 context->recordError(error);
8436 return NULL;
8437 }
8438
8439 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008440 }
8441
8442 return NULL;
8443}
8444
8445GLboolean __stdcall glUnmapBufferOES(GLenum target)
8446{
8447 EVENT("(GLenum target = 0x%X)", target);
8448
Geoff Langbfdea662014-07-23 14:16:32 -04008449 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008450 if (context)
8451 {
8452 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008453 {
Geoff Langb1196682014-07-23 13:47:29 -04008454 context->recordError(gl::Error(GL_INVALID_ENUM));
8455 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008456 }
Geoff Langbfdea662014-07-23 14:16:32 -04008457
8458 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8459
8460 if (buffer == NULL || !buffer->isMapped())
8461 {
Geoff Langb1196682014-07-23 13:47:29 -04008462 context->recordError(gl::Error(GL_INVALID_OPERATION));
8463 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008464 }
8465
8466 // TODO: detect if we had corruption. if so, throw an error and return false.
8467
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008468 gl::Error error = buffer->unmap();
8469 if (error.isError())
8470 {
8471 context->recordError(error);
8472 return GL_FALSE;
8473 }
Geoff Langbfdea662014-07-23 14:16:32 -04008474
8475 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008476 }
8477
8478 return GL_FALSE;
8479}
8480
Shannon Woods916e7692014-03-27 16:58:22 -04008481void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8482{
8483 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8484 target, offset, length, access);
8485
Geoff Langbfdea662014-07-23 14:16:32 -04008486 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008487 if (context)
8488 {
8489 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008490 {
Geoff Langb1196682014-07-23 13:47:29 -04008491 context->recordError(gl::Error(GL_INVALID_ENUM));
8492 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008493 }
Geoff Langbfdea662014-07-23 14:16:32 -04008494
8495 if (offset < 0 || length < 0)
8496 {
Geoff Langb1196682014-07-23 13:47:29 -04008497 context->recordError(gl::Error(GL_INVALID_VALUE));
8498 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008499 }
8500
8501 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8502
8503 if (buffer == NULL)
8504 {
Geoff Langb1196682014-07-23 13:47:29 -04008505 context->recordError(gl::Error(GL_INVALID_OPERATION));
8506 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008507 }
8508
8509 // Check for buffer overflow
8510 size_t offsetSize = static_cast<size_t>(offset);
8511 size_t lengthSize = static_cast<size_t>(length);
8512
8513 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8514 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8515 {
Geoff Langb1196682014-07-23 13:47:29 -04008516 context->recordError(gl::Error(GL_INVALID_VALUE));
8517 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008518 }
8519
8520 // Check for invalid bits in the mask
8521 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8522 GL_MAP_WRITE_BIT |
8523 GL_MAP_INVALIDATE_RANGE_BIT |
8524 GL_MAP_INVALIDATE_BUFFER_BIT |
8525 GL_MAP_FLUSH_EXPLICIT_BIT |
8526 GL_MAP_UNSYNCHRONIZED_BIT;
8527
8528 if (access & ~(allAccessBits))
8529 {
Geoff Langb1196682014-07-23 13:47:29 -04008530 context->recordError(gl::Error(GL_INVALID_VALUE));
8531 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008532 }
8533
8534 if (length == 0 || buffer->isMapped())
8535 {
Geoff Langb1196682014-07-23 13:47:29 -04008536 context->recordError(gl::Error(GL_INVALID_OPERATION));
8537 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008538 }
8539
8540 // Check for invalid bit combinations
8541 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8542 {
Geoff Langb1196682014-07-23 13:47:29 -04008543 context->recordError(gl::Error(GL_INVALID_OPERATION));
8544 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008545 }
8546
8547 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8548 GL_MAP_INVALIDATE_BUFFER_BIT |
8549 GL_MAP_UNSYNCHRONIZED_BIT;
8550
8551 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8552 {
Geoff Langb1196682014-07-23 13:47:29 -04008553 context->recordError(gl::Error(GL_INVALID_OPERATION));
8554 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008555 }
8556
8557 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8558 {
Geoff Langb1196682014-07-23 13:47:29 -04008559 context->recordError(gl::Error(GL_INVALID_OPERATION));
8560 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008561 }
8562
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008563 gl::Error error = buffer->mapRange(offset, length, access);
8564 if (error.isError())
8565 {
8566 context->recordError(error);
8567 return NULL;
8568 }
8569
8570 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008571 }
8572
8573 return NULL;
8574}
8575
8576void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8577{
8578 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8579
Geoff Langbfdea662014-07-23 14:16:32 -04008580 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008581 if (context)
8582 {
8583 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008584 {
Geoff Langb1196682014-07-23 13:47:29 -04008585 context->recordError(gl::Error(GL_INVALID_VALUE));
8586 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008587 }
Geoff Langbfdea662014-07-23 14:16:32 -04008588
8589 if (!gl::ValidBufferTarget(context, target))
8590 {
Geoff Langb1196682014-07-23 13:47:29 -04008591 context->recordError(gl::Error(GL_INVALID_ENUM));
8592 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008593 }
8594
8595 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8596
8597 if (buffer == NULL)
8598 {
Geoff Langb1196682014-07-23 13:47:29 -04008599 context->recordError(gl::Error(GL_INVALID_OPERATION));
8600 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008601 }
8602
8603 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8604 {
Geoff Langb1196682014-07-23 13:47:29 -04008605 context->recordError(gl::Error(GL_INVALID_OPERATION));
8606 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008607 }
8608
8609 // Check for buffer overflow
8610 size_t offsetSize = static_cast<size_t>(offset);
8611 size_t lengthSize = static_cast<size_t>(length);
8612
8613 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8614 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8615 {
Geoff Langb1196682014-07-23 13:47:29 -04008616 context->recordError(gl::Error(GL_INVALID_VALUE));
8617 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008618 }
8619
8620 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008621 }
8622}
8623
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008624__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8625{
8626 struct Extension
8627 {
8628 const char *name;
8629 __eglMustCastToProperFunctionPointerType address;
8630 };
8631
8632 static const Extension glExtensions[] =
8633 {
8634 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008635 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008636 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008637 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8638 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8639 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8640 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8641 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8642 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8643 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008644 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008645 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008646 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8647 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8648 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8649 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008650 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8651 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8652 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8653 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8654 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8655 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8656 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008657 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008658 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8659 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8660 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008661 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008662 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8663 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8664 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008665 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8666 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8667 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008668
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008669 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008670 {
8671 if (strcmp(procname, glExtensions[ext].name) == 0)
8672 {
8673 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8674 }
8675 }
8676
8677 return NULL;
8678}
8679
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008680// Non-public functions used by EGL
8681
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008682bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008683{
8684 EVENT("(egl::Surface* surface = 0x%0.8p)",
8685 surface);
8686
Geoff Langbfdea662014-07-23 14:16:32 -04008687 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008688 if (context)
8689 {
8690 gl::Texture2D *textureObject = context->getTexture2D();
8691 ASSERT(textureObject != NULL);
8692
8693 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008694 {
Geoff Langbfdea662014-07-23 14:16:32 -04008695 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008696 }
Geoff Langbfdea662014-07-23 14:16:32 -04008697
8698 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008699 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008700
8701 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008702}
8703
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008704}