blob: 9b48f8b3eff48f0cababaa6bf3122adf928498b3 [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
3696 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003697 }
3698}
3699
3700void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3701 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003702{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003703 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003704 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003705 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003706
Geoff Langbfdea662014-07-23 14:16:32 -04003707 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003708 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003709 {
Geoff Langb1196682014-07-23 13:47:29 -04003710 if (width < 0 || height < 0)
3711 {
3712 context->recordError(gl::Error(GL_INVALID_VALUE));
3713 return;
3714 }
3715
Geoff Langbfdea662014-07-23 14:16:32 -04003716 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3717 format, type, NULL, pixels))
3718 {
3719 return;
3720 }
3721
3722 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003723 }
3724}
3725
3726void __stdcall glReleaseShaderCompiler(void)
3727{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003728 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003729
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003730 gl::Context *context = gl::getNonLostContext();
3731
3732 if (context)
3733 {
3734 context->releaseShaderCompiler();
3735 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003736}
3737
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003738void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003739{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003740 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 +00003741 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003742
Geoff Langbfdea662014-07-23 14:16:32 -04003743 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003744 if (context)
3745 {
3746 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3747 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003748 {
Geoff Langbfdea662014-07-23 14:16:32 -04003749 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003750 }
Geoff Langbfdea662014-07-23 14:16:32 -04003751
3752 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003753 }
3754}
3755
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003756void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3757{
3758 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3759}
3760
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003761void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3762{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003763 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003764
Geoff Langbfdea662014-07-23 14:16:32 -04003765 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003766
Geoff Langbfdea662014-07-23 14:16:32 -04003767 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003768 {
Geoff Langbfdea662014-07-23 14:16:32 -04003769 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003770 }
3771}
3772
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003773void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3774{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003775 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003776
Geoff Langbfdea662014-07-23 14:16:32 -04003777 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003778 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003779 {
Geoff Langb1196682014-07-23 13:47:29 -04003780 if (condition != GL_ALL_COMPLETED_NV)
3781 {
3782 context->recordError(gl::Error(GL_INVALID_ENUM));
3783 return;
3784 }
3785
Geoff Langbfdea662014-07-23 14:16:32 -04003786 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3787
3788 if (fenceObject == NULL)
3789 {
Geoff Langb1196682014-07-23 13:47:29 -04003790 context->recordError(gl::Error(GL_INVALID_OPERATION));
3791 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003792 }
3793
3794 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003795 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003796}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003797
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003798void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3799{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003800 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 +00003801
Geoff Langbfdea662014-07-23 14:16:32 -04003802 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003803 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003804 {
Geoff Langb1196682014-07-23 13:47:29 -04003805 if (width < 0 || height < 0)
3806 {
3807 context->recordError(gl::Error(GL_INVALID_VALUE));
3808 return;
3809 }
3810
Geoff Langbfdea662014-07-23 14:16:32 -04003811 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003812 }
3813}
3814
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003815void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003816{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003817 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003818 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003819 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003820
Geoff Lang900013c2014-07-07 11:32:19 -04003821 gl::Context* context = gl::getNonLostContext();
3822 if (context)
3823 {
3824 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3825 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3826 {
Geoff Langb1196682014-07-23 13:47:29 -04003827 context->recordError(gl::Error(GL_INVALID_ENUM));
3828 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003829 }
3830
3831 // No binary shader formats are supported.
3832 UNIMPLEMENTED();
3833 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003834}
3835
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003836void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003837{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003838 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 +00003839 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003840
Geoff Langbfdea662014-07-23 14:16:32 -04003841 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003842 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003843 {
Geoff Langb1196682014-07-23 13:47:29 -04003844 if (count < 0)
3845 {
3846 context->recordError(gl::Error(GL_INVALID_VALUE));
3847 return;
3848 }
3849
Geoff Langbfdea662014-07-23 14:16:32 -04003850 gl::Shader *shaderObject = context->getShader(shader);
3851
3852 if (!shaderObject)
3853 {
3854 if (context->getProgram(shader))
3855 {
Geoff Langb1196682014-07-23 13:47:29 -04003856 context->recordError(gl::Error(GL_INVALID_OPERATION));
3857 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003858 }
3859 else
3860 {
Geoff Langb1196682014-07-23 13:47:29 -04003861 context->recordError(gl::Error(GL_INVALID_VALUE));
3862 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003863 }
3864 }
3865
3866 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003867 }
3868}
3869
3870void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3871{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003872 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003873}
3874
3875void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3876{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003877 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 +00003878
Geoff Langbfdea662014-07-23 14:16:32 -04003879 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003880 if (context)
3881 {
Geoff Langb1196682014-07-23 13:47:29 -04003882 switch (face)
3883 {
3884 case GL_FRONT:
3885 case GL_BACK:
3886 case GL_FRONT_AND_BACK:
3887 break;
3888
3889 default:
3890 context->recordError(gl::Error(GL_INVALID_ENUM));
3891 return;
3892 }
3893
3894 switch (func)
3895 {
3896 case GL_NEVER:
3897 case GL_ALWAYS:
3898 case GL_LESS:
3899 case GL_LEQUAL:
3900 case GL_EQUAL:
3901 case GL_GEQUAL:
3902 case GL_GREATER:
3903 case GL_NOTEQUAL:
3904 break;
3905
3906 default:
3907 context->recordError(gl::Error(GL_INVALID_ENUM));
3908 return;
3909 }
3910
Geoff Langbfdea662014-07-23 14:16:32 -04003911 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3912 {
3913 context->getState().setStencilParams(func, ref, mask);
3914 }
3915
3916 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3917 {
3918 context->getState().setStencilBackParams(func, ref, mask);
3919 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920 }
3921}
3922
3923void __stdcall glStencilMask(GLuint mask)
3924{
3925 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3926}
3927
3928void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3929{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003930 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003931
Geoff Langbfdea662014-07-23 14:16:32 -04003932 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003933 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003934 {
Geoff Langb1196682014-07-23 13:47:29 -04003935 switch (face)
3936 {
3937 case GL_FRONT:
3938 case GL_BACK:
3939 case GL_FRONT_AND_BACK:
3940 break;
3941
3942 default:
3943 context->recordError(gl::Error(GL_INVALID_ENUM));
3944 return;
3945 }
3946
Geoff Langbfdea662014-07-23 14:16:32 -04003947 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3948 {
3949 context->getState().setStencilWritemask(mask);
3950 }
3951
3952 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3953 {
3954 context->getState().setStencilBackWritemask(mask);
3955 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003956 }
3957}
3958
3959void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3960{
3961 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3962}
3963
3964void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3965{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003966 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 +00003967 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003968
Geoff Langbfdea662014-07-23 14:16:32 -04003969 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003970 if (context)
3971 {
Geoff Langb1196682014-07-23 13:47:29 -04003972 switch (face)
3973 {
3974 case GL_FRONT:
3975 case GL_BACK:
3976 case GL_FRONT_AND_BACK:
3977 break;
3978
3979 default:
3980 context->recordError(gl::Error(GL_INVALID_ENUM));
3981 return;
3982 }
3983
3984 switch (fail)
3985 {
3986 case GL_ZERO:
3987 case GL_KEEP:
3988 case GL_REPLACE:
3989 case GL_INCR:
3990 case GL_DECR:
3991 case GL_INVERT:
3992 case GL_INCR_WRAP:
3993 case GL_DECR_WRAP:
3994 break;
3995
3996 default:
3997 context->recordError(gl::Error(GL_INVALID_ENUM));
3998 return;
3999 }
4000
4001 switch (zfail)
4002 {
4003 case GL_ZERO:
4004 case GL_KEEP:
4005 case GL_REPLACE:
4006 case GL_INCR:
4007 case GL_DECR:
4008 case GL_INVERT:
4009 case GL_INCR_WRAP:
4010 case GL_DECR_WRAP:
4011 break;
4012
4013 default:
4014 context->recordError(gl::Error(GL_INVALID_ENUM));
4015 return;
4016 }
4017
4018 switch (zpass)
4019 {
4020 case GL_ZERO:
4021 case GL_KEEP:
4022 case GL_REPLACE:
4023 case GL_INCR:
4024 case GL_DECR:
4025 case GL_INVERT:
4026 case GL_INCR_WRAP:
4027 case GL_DECR_WRAP:
4028 break;
4029
4030 default:
4031 context->recordError(gl::Error(GL_INVALID_ENUM));
4032 return;
4033 }
4034
Geoff Langbfdea662014-07-23 14:16:32 -04004035 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4036 {
4037 context->getState().setStencilOperations(fail, zfail, zpass);
4038 }
4039
4040 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4041 {
4042 context->getState().setStencilBackOperations(fail, zfail, zpass);
4043 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004044 }
4045}
4046
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004047GLboolean __stdcall glTestFenceNV(GLuint fence)
4048{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004049 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004050
Geoff Langbfdea662014-07-23 14:16:32 -04004051 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004052 if (context)
4053 {
4054 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4055
4056 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004057 {
Geoff Langb1196682014-07-23 13:47:29 -04004058 context->recordError(gl::Error(GL_INVALID_OPERATION));
4059 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004060 }
Geoff Langbfdea662014-07-23 14:16:32 -04004061
4062 if (fenceObject->isFence() != GL_TRUE)
4063 {
Geoff Langb1196682014-07-23 13:47:29 -04004064 context->recordError(gl::Error(GL_INVALID_OPERATION));
4065 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004066 }
4067
4068 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004069 }
Geoff Langbfdea662014-07-23 14:16:32 -04004070
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004071 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004072}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004073
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004074void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4075 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004076{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004077 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004078 "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 +00004079 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004080
Geoff Langbfdea662014-07-23 14:16:32 -04004081 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004082 if (context)
4083 {
4084 if (context->getClientVersion() < 3 &&
4085 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4086 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004087 {
Geoff Langbfdea662014-07-23 14:16:32 -04004088 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004089 }
Geoff Langbfdea662014-07-23 14:16:32 -04004090
4091 if (context->getClientVersion() >= 3 &&
4092 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4093 0, 0, 0, width, height, 1, border, format, type, pixels))
4094 {
4095 return;
4096 }
4097
4098 switch (target)
4099 {
4100 case GL_TEXTURE_2D:
4101 {
4102 gl::Texture2D *texture = context->getTexture2D();
4103 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4104 }
4105 break;
4106 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4107 {
4108 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4109 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4110 }
4111 break;
4112 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4113 {
4114 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4115 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4116 }
4117 break;
4118 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4119 {
4120 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4121 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4122 }
4123 break;
4124 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4125 {
4126 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4127 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4128 }
4129 break;
4130 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4131 {
4132 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4133 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4134 }
4135 break;
4136 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4137 {
4138 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4139 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4140 }
4141 break;
4142 default: UNREACHABLE();
4143 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004144 }
4145}
4146
4147void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4148{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004149 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4150
Geoff Langbfdea662014-07-23 14:16:32 -04004151 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004152 if (context)
4153 {
4154 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004155 {
Geoff Langbfdea662014-07-23 14:16:32 -04004156 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004157 }
Geoff Langbfdea662014-07-23 14:16:32 -04004158
4159 gl::Texture *texture = context->getTargetTexture(target);
4160
4161 if (!texture)
4162 {
Geoff Langb1196682014-07-23 13:47:29 -04004163 context->recordError(gl::Error(GL_INVALID_ENUM));
4164 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004165 }
4166
4167 switch (pname)
4168 {
4169 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4170 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4171 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4172 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4173 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4174 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4175 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4176 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4177 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4178 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4179 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4180 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4181 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4182 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4183 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4184 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4185 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4186 default: UNREACHABLE(); break;
4187 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004188 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004189}
4190
4191void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4192{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004193 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004194}
4195
4196void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4197{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004198 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004199
Geoff Langbfdea662014-07-23 14:16:32 -04004200 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004201 if (context)
4202 {
4203 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004204 {
Geoff Langbfdea662014-07-23 14:16:32 -04004205 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004206 }
Geoff Langbfdea662014-07-23 14:16:32 -04004207
4208 gl::Texture *texture = context->getTargetTexture(target);
4209
4210 if (!texture)
4211 {
Geoff Langb1196682014-07-23 13:47:29 -04004212 context->recordError(gl::Error(GL_INVALID_ENUM));
4213 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004214 }
4215
4216 switch (pname)
4217 {
4218 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4219 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4220 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4221 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4222 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4223 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4224 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4225 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4226 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4227 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4228 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4229 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4230 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4231 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4232 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4233 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4234 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4235 default: UNREACHABLE(); break;
4236 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004237 }
4238}
4239
4240void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4241{
4242 glTexParameteri(target, pname, *params);
4243}
4244
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004245void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4246{
4247 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4248 target, levels, internalformat, width, height);
4249
Geoff Langbfdea662014-07-23 14:16:32 -04004250 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004251 if (context)
4252 {
4253 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004254 {
Geoff Langb1196682014-07-23 13:47:29 -04004255 context->recordError(gl::Error(GL_INVALID_OPERATION));
4256 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004257 }
Geoff Langbfdea662014-07-23 14:16:32 -04004258
4259 if (context->getClientVersion() < 3 &&
4260 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4261 {
4262 return;
4263 }
4264
4265 if (context->getClientVersion() >= 3 &&
4266 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4267 {
4268 return;
4269 }
4270
4271 switch (target)
4272 {
4273 case GL_TEXTURE_2D:
4274 {
4275 gl::Texture2D *texture2d = context->getTexture2D();
4276 texture2d->storage(levels, internalformat, width, height);
4277 }
4278 break;
4279
4280 case GL_TEXTURE_CUBE_MAP:
4281 {
4282 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4283 textureCube->storage(levels, internalformat, width);
4284 }
4285 break;
4286
4287 default:
Geoff Langb1196682014-07-23 13:47:29 -04004288 context->recordError(gl::Error(GL_INVALID_ENUM));
4289 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004290 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004291 }
4292}
4293
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004294void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4295 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004296{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004297 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004298 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004299 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004300 target, level, xoffset, yoffset, width, height, format, type, pixels);
4301
Geoff Langbfdea662014-07-23 14:16:32 -04004302 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004303 if (context)
4304 {
4305 if (context->getClientVersion() < 3 &&
4306 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4307 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004308 {
Geoff Langbfdea662014-07-23 14:16:32 -04004309 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004310 }
Geoff Langbfdea662014-07-23 14:16:32 -04004311
4312 if (context->getClientVersion() >= 3 &&
4313 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4314 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4315 {
4316 return;
4317 }
4318
4319 // Zero sized uploads are valid but no-ops
4320 if (width == 0 || height == 0)
4321 {
4322 return;
4323 }
4324
4325 switch (target)
4326 {
4327 case GL_TEXTURE_2D:
4328 {
4329 gl::Texture2D *texture = context->getTexture2D();
4330 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4331 }
4332 break;
4333
4334 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4335 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4336 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4337 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4338 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4339 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4340 {
4341 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4342 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4343 }
4344 break;
4345
4346 default:
4347 UNREACHABLE();
4348 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004349 }
4350}
4351
4352void __stdcall glUniform1f(GLint location, GLfloat x)
4353{
4354 glUniform1fv(location, 1, &x);
4355}
4356
4357void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4358{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004359 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004360
Geoff Langbfdea662014-07-23 14:16:32 -04004361 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004362 if (context)
4363 {
4364 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004365 {
Geoff Langbfdea662014-07-23 14:16:32 -04004366 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004367 }
Geoff Langbfdea662014-07-23 14:16:32 -04004368
4369 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4370 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004371 }
4372}
4373
4374void __stdcall glUniform1i(GLint location, GLint x)
4375{
4376 glUniform1iv(location, 1, &x);
4377}
4378
4379void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4380{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004381 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004382
Geoff Langbfdea662014-07-23 14:16:32 -04004383 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004384 if (context)
4385 {
4386 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004387 {
Geoff Langbfdea662014-07-23 14:16:32 -04004388 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004389 }
Geoff Langbfdea662014-07-23 14:16:32 -04004390
4391 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4392 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004393 }
4394}
4395
4396void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4397{
4398 GLfloat xy[2] = {x, y};
4399
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004400 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004401}
4402
4403void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4404{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004405 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004406
Geoff Langbfdea662014-07-23 14:16:32 -04004407 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004408 if (context)
4409 {
4410 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004411 {
Geoff Langbfdea662014-07-23 14:16:32 -04004412 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004413 }
Geoff Langbfdea662014-07-23 14:16:32 -04004414
4415 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4416 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004417 }
4418}
4419
4420void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4421{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004422 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004423
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004424 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004425}
4426
4427void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4428{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004429 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004430
Geoff Langbfdea662014-07-23 14:16:32 -04004431 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004432 if (context)
4433 {
4434 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004435 {
Geoff Langbfdea662014-07-23 14:16:32 -04004436 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004437 }
Geoff Langbfdea662014-07-23 14:16:32 -04004438
4439 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4440 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004441 }
4442}
4443
4444void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4445{
4446 GLfloat xyz[3] = {x, y, z};
4447
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004448 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004449}
4450
4451void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4452{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004453 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454
Geoff Langbfdea662014-07-23 14:16:32 -04004455 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004456 if (context)
4457 {
4458 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004459 {
Geoff Langbfdea662014-07-23 14:16:32 -04004460 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004461 }
Geoff Langbfdea662014-07-23 14:16:32 -04004462
4463 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4464 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004465 }
4466}
4467
4468void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4469{
4470 GLint xyz[3] = {x, y, z};
4471
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004472 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004473}
4474
4475void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4476{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004477 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004478
Geoff Langbfdea662014-07-23 14:16:32 -04004479 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004480 if (context)
4481 {
4482 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004483 {
Geoff Langbfdea662014-07-23 14:16:32 -04004484 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004485 }
Geoff Langbfdea662014-07-23 14:16:32 -04004486
4487 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4488 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004489 }
4490}
4491
4492void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4493{
4494 GLfloat xyzw[4] = {x, y, z, w};
4495
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004496 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004497}
4498
4499void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4500{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004501 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004502
Geoff Langbfdea662014-07-23 14:16:32 -04004503 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004504 if (context)
4505 {
4506 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004507 {
Geoff Langbfdea662014-07-23 14:16:32 -04004508 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004509 }
Geoff Langbfdea662014-07-23 14:16:32 -04004510
4511 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4512 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004513 }
4514}
4515
4516void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4517{
4518 GLint xyzw[4] = {x, y, z, w};
4519
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004520 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004521}
4522
4523void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4524{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004525 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004526
Geoff Langbfdea662014-07-23 14:16:32 -04004527 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004528 if (context)
4529 {
4530 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004531 {
Geoff Langbfdea662014-07-23 14:16:32 -04004532 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004533 }
Geoff Langbfdea662014-07-23 14:16:32 -04004534
4535 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4536 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004537 }
4538}
4539
4540void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4541{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004542 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004543 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004544
Geoff Langbfdea662014-07-23 14:16:32 -04004545 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004546 if (context)
4547 {
4548 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004549 {
Geoff Langbfdea662014-07-23 14:16:32 -04004550 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004551 }
Geoff Langbfdea662014-07-23 14:16:32 -04004552
4553 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4554 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555 }
4556}
4557
4558void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4559{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004560 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004561 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562
Geoff Langbfdea662014-07-23 14:16:32 -04004563 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004564 if (context)
4565 {
4566 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004567 {
Geoff Langbfdea662014-07-23 14:16:32 -04004568 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004569 }
Geoff Langbfdea662014-07-23 14:16:32 -04004570
4571 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4572 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573 }
4574}
4575
4576void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4577{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004578 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004579 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004580
Geoff Langbfdea662014-07-23 14:16:32 -04004581 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004582 if (context)
4583 {
4584 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004585 {
Geoff Langbfdea662014-07-23 14:16:32 -04004586 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004587 }
Geoff Langbfdea662014-07-23 14:16:32 -04004588
4589 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4590 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004591 }
4592}
4593
4594void __stdcall glUseProgram(GLuint program)
4595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004596 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004597
Geoff Langbfdea662014-07-23 14:16:32 -04004598 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004599 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004600 {
Geoff Langbfdea662014-07-23 14:16:32 -04004601 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004602
Geoff Langbfdea662014-07-23 14:16:32 -04004603 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004604 {
Geoff Langbfdea662014-07-23 14:16:32 -04004605 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004606 {
Geoff Langb1196682014-07-23 13:47:29 -04004607 context->recordError(gl::Error(GL_INVALID_OPERATION));
4608 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609 }
Geoff Langbfdea662014-07-23 14:16:32 -04004610 else
4611 {
Geoff Langb1196682014-07-23 13:47:29 -04004612 context->recordError(gl::Error(GL_INVALID_VALUE));
4613 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004614 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004615 }
Geoff Langbfdea662014-07-23 14:16:32 -04004616
4617 if (program != 0 && !programObject->isLinked())
4618 {
Geoff Langb1196682014-07-23 13:47:29 -04004619 context->recordError(gl::Error(GL_INVALID_OPERATION));
4620 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004621 }
4622
4623 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004624 }
4625}
4626
4627void __stdcall glValidateProgram(GLuint program)
4628{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004629 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004630
Geoff Langbfdea662014-07-23 14:16:32 -04004631 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004632 if (context)
4633 {
4634 gl::Program *programObject = context->getProgram(program);
4635
4636 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004637 {
Geoff Langbfdea662014-07-23 14:16:32 -04004638 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004639 {
Geoff Langb1196682014-07-23 13:47:29 -04004640 context->recordError(gl::Error(GL_INVALID_OPERATION));
4641 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004642 }
Geoff Langbfdea662014-07-23 14:16:32 -04004643 else
4644 {
Geoff Langb1196682014-07-23 13:47:29 -04004645 context->recordError(gl::Error(GL_INVALID_VALUE));
4646 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004647 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004648 }
Geoff Langbfdea662014-07-23 14:16:32 -04004649
Brandon Jones43a53e22014-08-28 16:23:22 -07004650 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004651 }
4652}
4653
4654void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004656 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004657
Geoff Langbfdea662014-07-23 14:16:32 -04004658 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004659 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004660 {
Geoff Langb1196682014-07-23 13:47:29 -04004661 if (index >= gl::MAX_VERTEX_ATTRIBS)
4662 {
4663 context->recordError(gl::Error(GL_INVALID_VALUE));
4664 return;
4665 }
4666
Geoff Langbfdea662014-07-23 14:16:32 -04004667 GLfloat vals[4] = { x, 0, 0, 1 };
4668 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004669 }
4670}
4671
4672void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4673{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004674 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004675
Geoff Langbfdea662014-07-23 14:16:32 -04004676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004677 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004678 {
Geoff Langb1196682014-07-23 13:47:29 -04004679 if (index >= gl::MAX_VERTEX_ATTRIBS)
4680 {
4681 context->recordError(gl::Error(GL_INVALID_VALUE));
4682 return;
4683 }
4684
Geoff Langbfdea662014-07-23 14:16:32 -04004685 GLfloat vals[4] = { values[0], 0, 0, 1 };
4686 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004687 }
4688}
4689
4690void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4691{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004692 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004693
Geoff Langbfdea662014-07-23 14:16:32 -04004694 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004695 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004696 {
Geoff Langb1196682014-07-23 13:47:29 -04004697 if (index >= gl::MAX_VERTEX_ATTRIBS)
4698 {
4699 context->recordError(gl::Error(GL_INVALID_VALUE));
4700 return;
4701 }
4702
Geoff Langbfdea662014-07-23 14:16:32 -04004703 GLfloat vals[4] = { x, y, 0, 1 };
4704 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004705 }
4706}
4707
4708void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4709{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004710 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004711
Geoff Langbfdea662014-07-23 14:16:32 -04004712 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004713 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004714 {
Geoff Langb1196682014-07-23 13:47:29 -04004715 if (index >= gl::MAX_VERTEX_ATTRIBS)
4716 {
4717 context->recordError(gl::Error(GL_INVALID_VALUE));
4718 return;
4719 }
4720
Geoff Langbfdea662014-07-23 14:16:32 -04004721 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4722 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004723 }
4724}
4725
4726void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4727{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004728 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 +00004729
Geoff Langbfdea662014-07-23 14:16:32 -04004730 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004731 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004732 {
Geoff Langb1196682014-07-23 13:47:29 -04004733 if (index >= gl::MAX_VERTEX_ATTRIBS)
4734 {
4735 context->recordError(gl::Error(GL_INVALID_VALUE));
4736 return;
4737 }
4738
Geoff Langbfdea662014-07-23 14:16:32 -04004739 GLfloat vals[4] = { x, y, z, 1 };
4740 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004741 }
4742}
4743
4744void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4745{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004746 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004747
Geoff Langbfdea662014-07-23 14:16:32 -04004748 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004749 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004750 {
Geoff Langb1196682014-07-23 13:47:29 -04004751 if (index >= gl::MAX_VERTEX_ATTRIBS)
4752 {
4753 context->recordError(gl::Error(GL_INVALID_VALUE));
4754 return;
4755 }
4756
Geoff Langbfdea662014-07-23 14:16:32 -04004757 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4758 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004759 }
4760}
4761
4762void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4763{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004764 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 +00004765
Geoff Langbfdea662014-07-23 14:16:32 -04004766 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004767 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004768 {
Geoff Langb1196682014-07-23 13:47:29 -04004769 if (index >= gl::MAX_VERTEX_ATTRIBS)
4770 {
4771 context->recordError(gl::Error(GL_INVALID_VALUE));
4772 return;
4773 }
4774
Geoff Langbfdea662014-07-23 14:16:32 -04004775 GLfloat vals[4] = { x, y, z, w };
4776 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004777 }
4778}
4779
4780void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4781{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004782 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004783
Geoff Langbfdea662014-07-23 14:16:32 -04004784 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004785 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004786 {
Geoff Langb1196682014-07-23 13:47:29 -04004787 if (index >= gl::MAX_VERTEX_ATTRIBS)
4788 {
4789 context->recordError(gl::Error(GL_INVALID_VALUE));
4790 return;
4791 }
4792
Geoff Langbfdea662014-07-23 14:16:32 -04004793 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004794 }
4795}
4796
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004797void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4798{
4799 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4800
Geoff Langbfdea662014-07-23 14:16:32 -04004801 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004802 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004803 {
Geoff Langb1196682014-07-23 13:47:29 -04004804 if (index >= gl::MAX_VERTEX_ATTRIBS)
4805 {
4806 context->recordError(gl::Error(GL_INVALID_VALUE));
4807 return;
4808 }
4809
Geoff Langbfdea662014-07-23 14:16:32 -04004810 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004811 }
4812}
4813
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004814void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004815{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004816 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004817 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004818 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004819
Geoff Langbfdea662014-07-23 14:16:32 -04004820 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004821 if (context)
4822 {
Geoff Langb1196682014-07-23 13:47:29 -04004823 if (index >= gl::MAX_VERTEX_ATTRIBS)
4824 {
4825 context->recordError(gl::Error(GL_INVALID_VALUE));
4826 return;
4827 }
4828
4829 if (size < 1 || size > 4)
4830 {
4831 context->recordError(gl::Error(GL_INVALID_VALUE));
4832 return;
4833 }
4834
4835 switch (type)
4836 {
4837 case GL_BYTE:
4838 case GL_UNSIGNED_BYTE:
4839 case GL_SHORT:
4840 case GL_UNSIGNED_SHORT:
4841 case GL_FIXED:
4842 case GL_FLOAT:
4843 break;
4844
4845 case GL_HALF_FLOAT:
4846 case GL_INT:
4847 case GL_UNSIGNED_INT:
4848 case GL_INT_2_10_10_10_REV:
4849 case GL_UNSIGNED_INT_2_10_10_10_REV:
4850 if (context->getClientVersion() < 3)
4851 {
4852 context->recordError(gl::Error(GL_INVALID_ENUM));
4853 return;
4854 }
4855 break;
4856
4857 default:
4858 context->recordError(gl::Error(GL_INVALID_ENUM));
4859 return;
4860 }
4861
4862 if (stride < 0)
4863 {
4864 context->recordError(gl::Error(GL_INVALID_VALUE));
4865 return;
4866 }
4867
4868 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4869 {
4870 context->recordError(gl::Error(GL_INVALID_OPERATION));
4871 return;
4872 }
4873
Geoff Langbfdea662014-07-23 14:16:32 -04004874 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4875 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4876 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4877 // and the pointer argument is not NULL.
4878 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004879 {
Geoff Langb1196682014-07-23 13:47:29 -04004880 context->recordError(gl::Error(GL_INVALID_OPERATION));
4881 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004882 }
4883
Geoff Langbfdea662014-07-23 14:16:32 -04004884 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4885 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004886 }
4887}
4888
4889void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4890{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004891 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 +00004892
Geoff Langbfdea662014-07-23 14:16:32 -04004893 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004894 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004895 {
Geoff Langb1196682014-07-23 13:47:29 -04004896 if (width < 0 || height < 0)
4897 {
4898 context->recordError(gl::Error(GL_INVALID_VALUE));
4899 return;
4900 }
4901
Geoff Langbfdea662014-07-23 14:16:32 -04004902 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004903 }
4904}
4905
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004906// OpenGL ES 3.0 functions
4907
4908void __stdcall glReadBuffer(GLenum mode)
4909{
4910 EVENT("(GLenum mode = 0x%X)", mode);
4911
Geoff Langbfdea662014-07-23 14:16:32 -04004912 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004913 if (context)
4914 {
4915 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004916 {
Geoff Langb1196682014-07-23 13:47:29 -04004917 context->recordError(gl::Error(GL_INVALID_OPERATION));
4918 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004919 }
Geoff Langbfdea662014-07-23 14:16:32 -04004920
4921 // glReadBuffer
4922 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004923 }
4924}
4925
4926void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4927{
4928 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4929 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4930
Geoff Langbfdea662014-07-23 14:16:32 -04004931 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004932 if (context)
4933 {
4934 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004935 {
Geoff Langb1196682014-07-23 13:47:29 -04004936 context->recordError(gl::Error(GL_INVALID_OPERATION));
4937 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004938 }
Geoff Langbfdea662014-07-23 14:16:32 -04004939
4940 // glDrawRangeElements
4941 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004942 }
4943}
4944
4945void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4946{
4947 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4948 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4949 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4950 target, level, internalformat, width, height, depth, border, format, type, pixels);
4951
Geoff Langbfdea662014-07-23 14:16:32 -04004952 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004953 if (context)
4954 {
4955 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004956 {
Geoff Langb1196682014-07-23 13:47:29 -04004957 context->recordError(gl::Error(GL_INVALID_OPERATION));
4958 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004959 }
Geoff Langbfdea662014-07-23 14:16:32 -04004960
4961 // validateES3TexImageFormat sets the error code if there is an error
4962 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4963 0, 0, 0, width, height, depth, border, format, type, pixels))
4964 {
4965 return;
4966 }
4967
4968 switch(target)
4969 {
4970 case GL_TEXTURE_3D:
4971 {
4972 gl::Texture3D *texture = context->getTexture3D();
4973 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4974 }
4975 break;
4976
4977 case GL_TEXTURE_2D_ARRAY:
4978 {
4979 gl::Texture2DArray *texture = context->getTexture2DArray();
4980 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4981 }
4982 break;
4983
4984 default:
Geoff Langb1196682014-07-23 13:47:29 -04004985 context->recordError(gl::Error(GL_INVALID_ENUM));
4986 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004987 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004988 }
4989}
4990
4991void __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)
4992{
4993 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4994 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4995 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4996 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4997
Geoff Langbfdea662014-07-23 14:16:32 -04004998 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004999 if (context)
5000 {
5001 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005002 {
Geoff Langb1196682014-07-23 13:47:29 -04005003 context->recordError(gl::Error(GL_INVALID_OPERATION));
5004 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005005 }
Geoff Langbfdea662014-07-23 14:16:32 -04005006
5007 // validateES3TexImageFormat sets the error code if there is an error
5008 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5009 xoffset, yoffset, zoffset, width, height, depth, 0,
5010 format, type, pixels))
5011 {
5012 return;
5013 }
5014
5015 // Zero sized uploads are valid but no-ops
5016 if (width == 0 || height == 0 || depth == 0)
5017 {
5018 return;
5019 }
5020
5021 switch(target)
5022 {
5023 case GL_TEXTURE_3D:
5024 {
5025 gl::Texture3D *texture = context->getTexture3D();
5026 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5027 }
5028 break;
5029
5030 case GL_TEXTURE_2D_ARRAY:
5031 {
5032 gl::Texture2DArray *texture = context->getTexture2DArray();
5033 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5034 }
5035 break;
5036
5037 default:
Geoff Langb1196682014-07-23 13:47:29 -04005038 context->recordError(gl::Error(GL_INVALID_ENUM));
5039 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005040 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005041 }
5042}
5043
5044void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5045{
5046 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5047 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5048 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5049
Geoff Langbfdea662014-07-23 14:16:32 -04005050 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005051 if (context)
5052 {
5053 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005054 {
Geoff Langb1196682014-07-23 13:47:29 -04005055 context->recordError(gl::Error(GL_INVALID_OPERATION));
5056 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005057 }
Geoff Langbfdea662014-07-23 14:16:32 -04005058
5059 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5060 x, y, width, height, 0))
5061 {
5062 return;
5063 }
5064
5065 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5066 gl::Texture *texture = NULL;
5067 switch (target)
5068 {
5069 case GL_TEXTURE_3D:
5070 texture = context->getTexture3D();
5071 break;
5072
5073 case GL_TEXTURE_2D_ARRAY:
5074 texture = context->getTexture2DArray();
5075 break;
5076
5077 default:
Geoff Langb1196682014-07-23 13:47:29 -04005078 context->recordError(gl::Error(GL_INVALID_ENUM));
5079 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005080 }
5081
5082 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005083 }
5084}
5085
5086void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5087{
Geoff Langeef52cc2013-10-16 15:07:39 -04005088 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 +00005089 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5090 "const GLvoid* data = 0x%0.8p)",
5091 target, level, internalformat, width, height, depth, border, imageSize, data);
5092
Geoff Langbfdea662014-07-23 14:16:32 -04005093 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005094 if (context)
5095 {
5096 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005097 {
Geoff Langb1196682014-07-23 13:47:29 -04005098 context->recordError(gl::Error(GL_INVALID_OPERATION));
5099 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005100 }
Geoff Langbfdea662014-07-23 14:16:32 -04005101
Geoff Lang5d601382014-07-22 15:14:06 -04005102 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5103 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005104 {
Geoff Langb1196682014-07-23 13:47:29 -04005105 context->recordError(gl::Error(GL_INVALID_VALUE));
5106 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005107 }
5108
5109 // validateES3TexImageFormat sets the error code if there is an error
5110 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5111 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5112 {
5113 return;
5114 }
5115
5116 switch(target)
5117 {
5118 case GL_TEXTURE_3D:
5119 {
5120 gl::Texture3D *texture = context->getTexture3D();
5121 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5122 }
5123 break;
5124
5125 case GL_TEXTURE_2D_ARRAY:
5126 {
5127 gl::Texture2DArray *texture = context->getTexture2DArray();
5128 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5129 }
5130 break;
5131
5132 default:
Geoff Langb1196682014-07-23 13:47:29 -04005133 context->recordError(gl::Error(GL_INVALID_ENUM));
5134 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005135 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005136 }
5137}
5138
5139void __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)
5140{
5141 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5142 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5143 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5144 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5145
Geoff Langbfdea662014-07-23 14:16:32 -04005146 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005147 if (context)
5148 {
5149 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005150 {
Geoff Langb1196682014-07-23 13:47:29 -04005151 context->recordError(gl::Error(GL_INVALID_OPERATION));
5152 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005153 }
Geoff Langbfdea662014-07-23 14:16:32 -04005154
Geoff Lang5d601382014-07-22 15:14:06 -04005155 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5156 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005157 {
Geoff Langb1196682014-07-23 13:47:29 -04005158 context->recordError(gl::Error(GL_INVALID_VALUE));
5159 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005160 }
5161
5162 if (!data)
5163 {
Geoff Langb1196682014-07-23 13:47:29 -04005164 context->recordError(gl::Error(GL_INVALID_VALUE));
5165 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005166 }
5167
5168 // validateES3TexImageFormat sets the error code if there is an error
5169 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5170 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5171 {
5172 return;
5173 }
5174
5175 // Zero sized uploads are valid but no-ops
5176 if (width == 0 || height == 0)
5177 {
5178 return;
5179 }
5180
5181 switch(target)
5182 {
5183 case GL_TEXTURE_3D:
5184 {
5185 gl::Texture3D *texture = context->getTexture3D();
5186 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5187 format, imageSize, data);
5188 }
5189 break;
5190
5191 case GL_TEXTURE_2D_ARRAY:
5192 {
5193 gl::Texture2DArray *texture = context->getTexture2DArray();
5194 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5195 format, imageSize, data);
5196 }
5197 break;
5198
Geoff Langb1196682014-07-23 13:47:29 -04005199 default:
5200 context->recordError(gl::Error(GL_INVALID_ENUM));
5201 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005202 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005203 }
5204}
5205
5206void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5207{
5208 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5209
Geoff Langbfdea662014-07-23 14:16:32 -04005210 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005211 if (context)
5212 {
5213 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005214 {
Geoff Langb1196682014-07-23 13:47:29 -04005215 context->recordError(gl::Error(GL_INVALID_OPERATION));
5216 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005217 }
Geoff Langbfdea662014-07-23 14:16:32 -04005218
5219 if (n < 0)
5220 {
Geoff Langb1196682014-07-23 13:47:29 -04005221 context->recordError(gl::Error(GL_INVALID_VALUE));
5222 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005223 }
5224
5225 for (GLsizei i = 0; i < n; i++)
5226 {
5227 ids[i] = context->createQuery();
5228 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005229 }
5230}
5231
5232void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5233{
5234 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5235
Geoff Langbfdea662014-07-23 14:16:32 -04005236 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005237 if (context)
5238 {
5239 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005240 {
Geoff Langb1196682014-07-23 13:47:29 -04005241 context->recordError(gl::Error(GL_INVALID_OPERATION));
5242 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005243 }
Geoff Langbfdea662014-07-23 14:16:32 -04005244
5245 if (n < 0)
5246 {
Geoff Langb1196682014-07-23 13:47:29 -04005247 context->recordError(gl::Error(GL_INVALID_VALUE));
5248 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005249 }
5250
5251 for (GLsizei i = 0; i < n; i++)
5252 {
5253 context->deleteQuery(ids[i]);
5254 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005255 }
5256}
5257
5258GLboolean __stdcall glIsQuery(GLuint id)
5259{
5260 EVENT("(GLuint id = %u)", id);
5261
Geoff Langbfdea662014-07-23 14:16:32 -04005262 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005263 if (context)
5264 {
5265 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005266 {
Geoff Langb1196682014-07-23 13:47:29 -04005267 context->recordError(gl::Error(GL_INVALID_OPERATION));
5268 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005269 }
Geoff Langbfdea662014-07-23 14:16:32 -04005270
5271 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005272 }
5273
5274 return GL_FALSE;
5275}
5276
5277void __stdcall glBeginQuery(GLenum target, GLuint id)
5278{
5279 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5280
Geoff Langbfdea662014-07-23 14:16:32 -04005281 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005282 if (context)
5283 {
5284 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005285 {
Geoff Langb1196682014-07-23 13:47:29 -04005286 context->recordError(gl::Error(GL_INVALID_OPERATION));
5287 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005288 }
Geoff Langbfdea662014-07-23 14:16:32 -04005289
5290 if (!ValidateBeginQuery(context, target, id))
5291 {
5292 return;
5293 }
5294 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005295 }
5296}
5297
5298void __stdcall glEndQuery(GLenum target)
5299{
5300 EVENT("(GLenum target = 0x%X)", target);
5301
Geoff Langbfdea662014-07-23 14:16:32 -04005302 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005303 if (context)
5304 {
5305 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005306 {
Geoff Langb1196682014-07-23 13:47:29 -04005307 context->recordError(gl::Error(GL_INVALID_OPERATION));
5308 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005309 }
Geoff Langbfdea662014-07-23 14:16:32 -04005310
5311 if (!ValidateEndQuery(context, target))
5312 {
5313 return;
5314 }
5315
5316 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005317 }
5318}
5319
5320void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5321{
5322 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5323
Geoff Langbfdea662014-07-23 14:16:32 -04005324 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005325 if (context)
5326 {
5327 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005328 {
Geoff Langb1196682014-07-23 13:47:29 -04005329 context->recordError(gl::Error(GL_INVALID_OPERATION));
5330 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005331 }
Geoff Langbfdea662014-07-23 14:16:32 -04005332
5333 if (!ValidQueryType(context, target))
5334 {
Geoff Langb1196682014-07-23 13:47:29 -04005335 context->recordError(gl::Error(GL_INVALID_ENUM));
5336 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005337 }
5338
5339 switch (pname)
5340 {
5341 case GL_CURRENT_QUERY:
5342 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5343 break;
5344
5345 default:
Geoff Langb1196682014-07-23 13:47:29 -04005346 context->recordError(gl::Error(GL_INVALID_ENUM));
5347 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005348 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005349 }
5350}
5351
5352void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5353{
5354 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5355
Geoff Langbfdea662014-07-23 14:16:32 -04005356 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005357 if (context)
5358 {
5359 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005360 {
Geoff Langb1196682014-07-23 13:47:29 -04005361 context->recordError(gl::Error(GL_INVALID_OPERATION));
5362 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005363 }
Geoff Langbfdea662014-07-23 14:16:32 -04005364
5365 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5366
5367 if (!queryObject)
5368 {
Geoff Langb1196682014-07-23 13:47:29 -04005369 context->recordError(gl::Error(GL_INVALID_OPERATION));
5370 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005371 }
5372
5373 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5374 {
Geoff Langb1196682014-07-23 13:47:29 -04005375 context->recordError(gl::Error(GL_INVALID_OPERATION));
5376 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005377 }
5378
5379 switch(pname)
5380 {
5381 case GL_QUERY_RESULT:
5382 params[0] = queryObject->getResult();
5383 break;
Geoff Langb1196682014-07-23 13:47:29 -04005384
Geoff Langbfdea662014-07-23 14:16:32 -04005385 case GL_QUERY_RESULT_AVAILABLE:
5386 params[0] = queryObject->isResultAvailable();
5387 break;
Geoff Langb1196682014-07-23 13:47:29 -04005388
Geoff Langbfdea662014-07-23 14:16:32 -04005389 default:
Geoff Langb1196682014-07-23 13:47:29 -04005390 context->recordError(gl::Error(GL_INVALID_ENUM));
5391 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005392 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005393 }
5394}
5395
5396GLboolean __stdcall glUnmapBuffer(GLenum target)
5397{
5398 EVENT("(GLenum target = 0x%X)", target);
5399
Geoff Langbfdea662014-07-23 14:16:32 -04005400 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005401 if (context)
5402 {
5403 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005404 {
Geoff Langb1196682014-07-23 13:47:29 -04005405 context->recordError(gl::Error(GL_INVALID_OPERATION));
5406 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005407 }
Geoff Langbfdea662014-07-23 14:16:32 -04005408
5409 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005410 }
5411
5412 return GL_FALSE;
5413}
5414
5415void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5416{
5417 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5418
Geoff Langbfdea662014-07-23 14:16:32 -04005419 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005420 if (context)
5421 {
5422 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005423 {
Geoff Langb1196682014-07-23 13:47:29 -04005424 context->recordError(gl::Error(GL_INVALID_OPERATION));
5425 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005426 }
Geoff Langbfdea662014-07-23 14:16:32 -04005427
5428 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005429 }
5430}
5431
5432void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5433{
Geoff Langbfdea662014-07-23 14:16:32 -04005434 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005435 if (context)
5436 {
5437 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005438 {
Geoff Langb1196682014-07-23 13:47:29 -04005439 context->recordError(gl::Error(GL_INVALID_OPERATION));
5440 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005441 }
Geoff Langbfdea662014-07-23 14:16:32 -04005442
5443 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005444 }
5445}
5446
5447void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5448{
5449 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5450 location, count, transpose, value);
5451
Geoff Langbfdea662014-07-23 14:16:32 -04005452 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005453 if (context)
5454 {
5455 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005456 {
Geoff Langbfdea662014-07-23 14:16:32 -04005457 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005458 }
Geoff Langbfdea662014-07-23 14:16:32 -04005459
5460 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5461 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005462 }
5463}
5464
5465void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5466{
5467 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5468 location, count, transpose, value);
5469
Geoff Langbfdea662014-07-23 14:16:32 -04005470 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005471 if (context)
5472 {
5473 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005474 {
Geoff Langbfdea662014-07-23 14:16:32 -04005475 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005476 }
Geoff Langbfdea662014-07-23 14:16:32 -04005477
5478 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5479 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005480 }
5481}
5482
5483void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5484{
5485 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5486 location, count, transpose, value);
5487
Geoff Langbfdea662014-07-23 14:16:32 -04005488 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005489 if (context)
5490 {
5491 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005492 {
Geoff Langbfdea662014-07-23 14:16:32 -04005493 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005494 }
Geoff Langbfdea662014-07-23 14:16:32 -04005495
5496 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5497 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005498 }
5499}
5500
5501void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5502{
5503 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5504 location, count, transpose, value);
5505
Geoff Langbfdea662014-07-23 14:16:32 -04005506 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005507 if (context)
5508 {
5509 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005510 {
Geoff Langbfdea662014-07-23 14:16:32 -04005511 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005512 }
Geoff Langbfdea662014-07-23 14:16:32 -04005513
5514 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5515 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005516 }
5517}
5518
5519void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5520{
5521 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5522 location, count, transpose, value);
5523
Geoff Langbfdea662014-07-23 14:16:32 -04005524 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005525 if (context)
5526 {
5527 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005528 {
Geoff Langbfdea662014-07-23 14:16:32 -04005529 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005530 }
Geoff Langbfdea662014-07-23 14:16:32 -04005531
5532 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5533 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005534 }
5535}
5536
5537void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5538{
5539 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5540 location, count, transpose, value);
5541
Geoff Langbfdea662014-07-23 14:16:32 -04005542 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005543 if (context)
5544 {
5545 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005546 {
Geoff Langbfdea662014-07-23 14:16:32 -04005547 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005548 }
Geoff Langbfdea662014-07-23 14:16:32 -04005549
5550 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5551 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005552 }
5553}
5554
5555void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5556{
5557 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5558 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5559 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5560
Geoff Langbfdea662014-07-23 14:16:32 -04005561 gl::Context *context = gl::getNonLostContext();
5562 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005563 {
Geoff Langbfdea662014-07-23 14:16:32 -04005564 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005565 {
Geoff Langb1196682014-07-23 13:47:29 -04005566 context->recordError(gl::Error(GL_INVALID_OPERATION));
5567 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005568 }
Geoff Langbfdea662014-07-23 14:16:32 -04005569
5570 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5571 dstX0, dstY0, dstX1, dstY1, mask, filter,
5572 false))
5573 {
5574 return;
5575 }
5576
5577 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5578 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005579 }
5580}
5581
5582void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5583{
5584 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5585 target, samples, internalformat, width, height);
5586
Geoff Langbfdea662014-07-23 14:16:32 -04005587 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005588 if (context)
5589 {
5590 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005591 {
Geoff Langb1196682014-07-23 13:47:29 -04005592 context->recordError(gl::Error(GL_INVALID_OPERATION));
5593 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005594 }
Geoff Langbfdea662014-07-23 14:16:32 -04005595
5596 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5597 width, height, false))
5598 {
5599 return;
5600 }
5601
5602 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005603 }
5604}
5605
5606void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5607{
5608 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5609 target, attachment, texture, level, layer);
5610
Geoff Langbfdea662014-07-23 14:16:32 -04005611 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005612 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005613 {
Geoff Langbfdea662014-07-23 14:16:32 -04005614 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5615 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005616 {
Geoff Langbfdea662014-07-23 14:16:32 -04005617 return;
5618 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005619
Geoff Langbfdea662014-07-23 14:16:32 -04005620 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5621 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005622
Geoff Langbfdea662014-07-23 14:16:32 -04005623 gl::Texture *textureObject = context->getTexture(texture);
5624 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005625
Geoff Langbfdea662014-07-23 14:16:32 -04005626 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5627 {
5628 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5629 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5630 }
5631 else
5632 {
5633 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005634 {
Geoff Langbfdea662014-07-23 14:16:32 -04005635 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5636 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5637 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005638 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005639 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005640 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005641}
5642
5643GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5644{
5645 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5646 target, offset, length, access);
5647
Geoff Langbfdea662014-07-23 14:16:32 -04005648 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005649 if (context)
5650 {
5651 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005652 {
Geoff Langb1196682014-07-23 13:47:29 -04005653 context->recordError(gl::Error(GL_INVALID_OPERATION));
5654 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005655 }
Geoff Langbfdea662014-07-23 14:16:32 -04005656
5657 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005658 }
5659
5660 return NULL;
5661}
5662
5663void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5664{
5665 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5666
Geoff Langbfdea662014-07-23 14:16:32 -04005667 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005668 if (context)
5669 {
5670 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005671 {
Geoff Langb1196682014-07-23 13:47:29 -04005672 context->recordError(gl::Error(GL_INVALID_OPERATION));
5673 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005674 }
Geoff Langbfdea662014-07-23 14:16:32 -04005675
5676 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005677 }
5678}
5679
5680void __stdcall glBindVertexArray(GLuint array)
5681{
5682 EVENT("(GLuint array = %u)", array);
5683
Geoff Langbfdea662014-07-23 14:16:32 -04005684 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005685 if (context)
5686 {
5687 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005688 {
Geoff Langb1196682014-07-23 13:47:29 -04005689 context->recordError(gl::Error(GL_INVALID_OPERATION));
5690 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005691 }
Geoff Langbfdea662014-07-23 14:16:32 -04005692
5693 gl::VertexArray *vao = context->getVertexArray(array);
5694
5695 if (!vao)
5696 {
5697 // The default VAO should always exist
5698 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005699 context->recordError(gl::Error(GL_INVALID_OPERATION));
5700 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005701 }
5702
5703 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005704 }
5705}
5706
5707void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5708{
5709 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5710
Geoff Langbfdea662014-07-23 14:16:32 -04005711 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005712 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005713 {
Geoff Langbfdea662014-07-23 14:16:32 -04005714 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005715 {
Geoff Langb1196682014-07-23 13:47:29 -04005716 context->recordError(gl::Error(GL_INVALID_OPERATION));
5717 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005718 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005719
Geoff Langbfdea662014-07-23 14:16:32 -04005720 if (n < 0)
5721 {
Geoff Langb1196682014-07-23 13:47:29 -04005722 context->recordError(gl::Error(GL_INVALID_VALUE));
5723 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005724 }
Jamie Madilld1028542013-07-02 11:57:04 -04005725
Geoff Langbfdea662014-07-23 14:16:32 -04005726 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5727 {
5728 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005729 {
Geoff Langbfdea662014-07-23 14:16:32 -04005730 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005731 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005732 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005733 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005734}
5735
5736void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5737{
5738 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5739
Geoff Langbfdea662014-07-23 14:16:32 -04005740 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005741 if (context)
5742 {
5743 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005744 {
Geoff Langb1196682014-07-23 13:47:29 -04005745 context->recordError(gl::Error(GL_INVALID_OPERATION));
5746 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005747 }
Geoff Langbfdea662014-07-23 14:16:32 -04005748
5749 if (n < 0)
5750 {
Geoff Langb1196682014-07-23 13:47:29 -04005751 context->recordError(gl::Error(GL_INVALID_VALUE));
5752 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005753 }
5754
5755 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5756 {
5757 arrays[arrayIndex] = context->createVertexArray();
5758 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005759 }
5760}
5761
5762GLboolean __stdcall glIsVertexArray(GLuint array)
5763{
5764 EVENT("(GLuint array = %u)", array);
5765
Geoff Langbfdea662014-07-23 14:16:32 -04005766 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005767 if (context)
5768 {
5769 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005770 {
Geoff Langb1196682014-07-23 13:47:29 -04005771 context->recordError(gl::Error(GL_INVALID_OPERATION));
5772 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005773 }
Geoff Langbfdea662014-07-23 14:16:32 -04005774
5775 if (array == 0)
5776 {
5777 return GL_FALSE;
5778 }
5779
5780 gl::VertexArray *vao = context->getVertexArray(array);
5781
5782 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005783 }
5784
5785 return GL_FALSE;
5786}
5787
5788void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5789{
5790 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5791 target, index, data);
5792
Geoff Langbfdea662014-07-23 14:16:32 -04005793 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005794 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005795 {
Geoff Langbfdea662014-07-23 14:16:32 -04005796 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005797 {
Geoff Langb1196682014-07-23 13:47:29 -04005798 context->recordError(gl::Error(GL_INVALID_OPERATION));
5799 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005800 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005801
Geoff Lang3a61c322014-07-10 13:01:54 -04005802 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005803 switch (target)
5804 {
5805 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5806 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5807 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005808 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5809 {
Geoff Langb1196682014-07-23 13:47:29 -04005810 context->recordError(gl::Error(GL_INVALID_VALUE));
5811 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005812 }
Geoff Langbfdea662014-07-23 14:16:32 -04005813 break;
Geoff Langb1196682014-07-23 13:47:29 -04005814
Geoff Langbfdea662014-07-23 14:16:32 -04005815 case GL_UNIFORM_BUFFER_START:
5816 case GL_UNIFORM_BUFFER_SIZE:
5817 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005818 if (index >= caps.maxCombinedUniformBlocks)
5819 {
Geoff Langb1196682014-07-23 13:47:29 -04005820 context->recordError(gl::Error(GL_INVALID_VALUE));
5821 return;
Geoff Lang3a61c322014-07-10 13:01:54 -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 default:
Geoff Langb1196682014-07-23 13:47:29 -04005826 context->recordError(gl::Error(GL_INVALID_ENUM));
5827 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005828 }
5829
5830 if (!(context->getIndexedIntegerv(target, index, data)))
5831 {
5832 GLenum nativeType;
5833 unsigned int numParams = 0;
5834 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005835 {
5836 context->recordError(gl::Error(GL_INVALID_ENUM));
5837 return;
5838 }
Shannon Woods15934d52013-08-19 14:28:49 -04005839
Geoff Langbfdea662014-07-23 14:16:32 -04005840 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005841 {
Geoff Langbfdea662014-07-23 14:16:32 -04005842 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005843 }
Geoff Langbfdea662014-07-23 14:16:32 -04005844
5845 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005846 {
Geoff Langbfdea662014-07-23 14:16:32 -04005847 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5848 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5849 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005850
Geoff Langbfdea662014-07-23 14:16:32 -04005851 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005852
Geoff Langbfdea662014-07-23 14:16:32 -04005853 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005854 {
Geoff Langbfdea662014-07-23 14:16:32 -04005855 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5856 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005857 }
Geoff Langbfdea662014-07-23 14:16:32 -04005858
5859 delete [] int64Params;
5860 }
5861 else
5862 {
5863 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005864 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005865 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005866 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005867}
5868
5869void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5870{
5871 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5872
Geoff Langbfdea662014-07-23 14:16:32 -04005873 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005874 if (context)
5875 {
5876 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005877 {
Geoff Langb1196682014-07-23 13:47:29 -04005878 context->recordError(gl::Error(GL_INVALID_OPERATION));
5879 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005880 }
Geoff Langbfdea662014-07-23 14:16:32 -04005881
5882 switch (primitiveMode)
5883 {
5884 case GL_TRIANGLES:
5885 case GL_LINES:
5886 case GL_POINTS:
5887 break;
Geoff Langb1196682014-07-23 13:47:29 -04005888
Geoff Langbfdea662014-07-23 14:16:32 -04005889 default:
Geoff Langb1196682014-07-23 13:47:29 -04005890 context->recordError(gl::Error(GL_INVALID_ENUM));
5891 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005892 }
5893
5894 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5895 ASSERT(transformFeedback != NULL);
5896
5897 if (transformFeedback->isStarted())
5898 {
Geoff Langb1196682014-07-23 13:47:29 -04005899 context->recordError(gl::Error(GL_INVALID_OPERATION));
5900 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005901 }
5902
5903 if (transformFeedback->isPaused())
5904 {
5905 transformFeedback->resume();
5906 }
5907 else
5908 {
5909 transformFeedback->start(primitiveMode);
5910 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005911 }
5912}
5913
5914void __stdcall glEndTransformFeedback(void)
5915{
5916 EVENT("(void)");
5917
Geoff Langbfdea662014-07-23 14:16:32 -04005918 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005919 if (context)
5920 {
5921 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005922 {
Geoff Langb1196682014-07-23 13:47:29 -04005923 context->recordError(gl::Error(GL_INVALID_OPERATION));
5924 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005925 }
Geoff Langbfdea662014-07-23 14:16:32 -04005926
5927 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5928 ASSERT(transformFeedback != NULL);
5929
5930 if (!transformFeedback->isStarted())
5931 {
Geoff Langb1196682014-07-23 13:47:29 -04005932 context->recordError(gl::Error(GL_INVALID_OPERATION));
5933 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005934 }
5935
5936 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005937 }
5938}
5939
5940void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5941{
5942 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5943 target, index, buffer, offset, size);
5944
Geoff Langbfdea662014-07-23 14:16:32 -04005945 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005946 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005947 {
Geoff Langbfdea662014-07-23 14:16:32 -04005948 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005949 {
Geoff Langb1196682014-07-23 13:47:29 -04005950 context->recordError(gl::Error(GL_INVALID_OPERATION));
5951 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005952 }
5953
Geoff Lang3a61c322014-07-10 13:01:54 -04005954 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005955 switch (target)
5956 {
5957 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04005958 if (index >= caps.maxTransformFeedbackSeparateAttributes)
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_VALUE));
5961 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005962 }
Geoff Langbfdea662014-07-23 14:16:32 -04005963 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005964
Geoff Langbfdea662014-07-23 14:16:32 -04005965 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04005966 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005967 {
Geoff Langb1196682014-07-23 13:47:29 -04005968 context->recordError(gl::Error(GL_INVALID_VALUE));
5969 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005970 }
Geoff Langbfdea662014-07-23 14:16:32 -04005971 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005972
Geoff Langbfdea662014-07-23 14:16:32 -04005973 default:
Geoff Langb1196682014-07-23 13:47:29 -04005974 context->recordError(gl::Error(GL_INVALID_ENUM));
5975 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005976 }
5977
5978 if (buffer != 0 && size <= 0)
5979 {
Geoff Langb1196682014-07-23 13:47:29 -04005980 context->recordError(gl::Error(GL_INVALID_VALUE));
5981 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005982 }
5983
5984 switch (target)
5985 {
5986 case GL_TRANSFORM_FEEDBACK_BUFFER:
5987
5988 // size and offset must be a multiple of 4
5989 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005990 {
Geoff Langb1196682014-07-23 13:47:29 -04005991 context->recordError(gl::Error(GL_INVALID_VALUE));
5992 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005993 }
5994
Geoff Langbfdea662014-07-23 14:16:32 -04005995 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5996 context->bindGenericTransformFeedbackBuffer(buffer);
5997 break;
5998
5999 case GL_UNIFORM_BUFFER:
6000
6001 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006002 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006003 {
Geoff Langb1196682014-07-23 13:47:29 -04006004 context->recordError(gl::Error(GL_INVALID_VALUE));
6005 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006006 }
Geoff Langbfdea662014-07-23 14:16:32 -04006007
6008 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6009 context->bindGenericUniformBuffer(buffer);
6010 break;
6011
6012 default:
6013 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006014 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006015 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006016}
6017
6018void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
6019{
6020 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6021 target, index, buffer);
6022
Geoff Langbfdea662014-07-23 14:16:32 -04006023 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006024 if (context)
6025 {
6026 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006027 {
Geoff Langb1196682014-07-23 13:47:29 -04006028 context->recordError(gl::Error(GL_INVALID_OPERATION));
6029 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006030 }
Geoff Langbfdea662014-07-23 14:16:32 -04006031
Geoff Lang3a61c322014-07-10 13:01:54 -04006032 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006033 switch (target)
6034 {
6035 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006036 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006037 {
Geoff Langb1196682014-07-23 13:47:29 -04006038 context->recordError(gl::Error(GL_INVALID_VALUE));
6039 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006040 }
6041 break;
6042
6043 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006044 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006045 {
Geoff Langb1196682014-07-23 13:47:29 -04006046 context->recordError(gl::Error(GL_INVALID_VALUE));
6047 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006048 }
6049 break;
6050
6051 default:
Geoff Langb1196682014-07-23 13:47:29 -04006052 context->recordError(gl::Error(GL_INVALID_ENUM));
6053 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006054 }
6055
6056 switch (target)
6057 {
6058 case GL_TRANSFORM_FEEDBACK_BUFFER:
6059 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6060 context->bindGenericTransformFeedbackBuffer(buffer);
6061 break;
6062
6063 case GL_UNIFORM_BUFFER:
6064 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6065 context->bindGenericUniformBuffer(buffer);
6066 break;
6067
6068 default:
6069 UNREACHABLE();
6070 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006071 }
6072}
6073
6074void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6075{
6076 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6077 program, count, varyings, bufferMode);
6078
Geoff Langbfdea662014-07-23 14:16:32 -04006079 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006080 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006081 {
Geoff Langbfdea662014-07-23 14:16:32 -04006082 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006083 {
Geoff Langb1196682014-07-23 13:47:29 -04006084 context->recordError(gl::Error(GL_INVALID_OPERATION));
6085 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006086 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006087
Geoff Langbfdea662014-07-23 14:16:32 -04006088 if (count < 0)
6089 {
Geoff Langb1196682014-07-23 13:47:29 -04006090 context->recordError(gl::Error(GL_INVALID_VALUE));
6091 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006092 }
6093
Geoff Lang05881a02014-07-10 14:05:30 -04006094 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006095 switch (bufferMode)
6096 {
6097 case GL_INTERLEAVED_ATTRIBS:
6098 break;
6099 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006100 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006101 {
Geoff Langb1196682014-07-23 13:47:29 -04006102 context->recordError(gl::Error(GL_INVALID_VALUE));
6103 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006104 }
Geoff Langbfdea662014-07-23 14:16:32 -04006105 break;
6106 default:
Geoff Langb1196682014-07-23 13:47:29 -04006107 context->recordError(gl::Error(GL_INVALID_ENUM));
6108 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006109 }
Geoff Langbfdea662014-07-23 14:16:32 -04006110
6111 if (!gl::ValidProgram(context, program))
6112 {
6113 return;
6114 }
6115
6116 gl::Program *programObject = context->getProgram(program);
6117 ASSERT(programObject);
6118
6119 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006120 }
6121}
6122
6123void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6124{
6125 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6126 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6127 program, index, bufSize, length, size, type, name);
6128
Geoff Langbfdea662014-07-23 14:16:32 -04006129 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006130 if (context)
6131 {
6132 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006133 {
Geoff Langb1196682014-07-23 13:47:29 -04006134 context->recordError(gl::Error(GL_INVALID_OPERATION));
6135 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006136 }
Geoff Langbfdea662014-07-23 14:16:32 -04006137
6138 if (bufSize < 0)
6139 {
Geoff Langb1196682014-07-23 13:47:29 -04006140 context->recordError(gl::Error(GL_INVALID_VALUE));
6141 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006142 }
6143
6144 if (!gl::ValidProgram(context, program))
6145 {
6146 return;
6147 }
6148
6149 gl::Program *programObject = context->getProgram(program);
6150 ASSERT(programObject);
6151
6152 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6153 {
Geoff Langb1196682014-07-23 13:47:29 -04006154 context->recordError(gl::Error(GL_INVALID_VALUE));
6155 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006156 }
6157
6158 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006159 }
6160}
6161
6162void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6163{
6164 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6165 index, size, type, stride, pointer);
6166
Geoff Langbfdea662014-07-23 14:16:32 -04006167 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006168 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006169 {
Geoff Langbfdea662014-07-23 14:16:32 -04006170 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006171 {
Geoff Langb1196682014-07-23 13:47:29 -04006172 context->recordError(gl::Error(GL_INVALID_OPERATION));
6173 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006174 }
6175
Geoff Langb1196682014-07-23 13:47:29 -04006176 if (index >= gl::MAX_VERTEX_ATTRIBS)
6177 {
6178 context->recordError(gl::Error(GL_INVALID_VALUE));
6179 return;
6180 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006181
Geoff Langb1196682014-07-23 13:47:29 -04006182 if (size < 1 || size > 4)
6183 {
6184 context->recordError(gl::Error(GL_INVALID_VALUE));
6185 return;
6186 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006187
Geoff Langb1196682014-07-23 13:47:29 -04006188 switch (type)
6189 {
6190 case GL_BYTE:
6191 case GL_UNSIGNED_BYTE:
6192 case GL_SHORT:
6193 case GL_UNSIGNED_SHORT:
6194 case GL_INT:
6195 case GL_UNSIGNED_INT:
6196 case GL_INT_2_10_10_10_REV:
6197 case GL_UNSIGNED_INT_2_10_10_10_REV:
6198 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006199
Geoff Langb1196682014-07-23 13:47:29 -04006200 default:
6201 context->recordError(gl::Error(GL_INVALID_ENUM));
6202 return;
6203 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006204
Geoff Langb1196682014-07-23 13:47:29 -04006205 if (stride < 0)
6206 {
6207 context->recordError(gl::Error(GL_INVALID_VALUE));
6208 return;
6209 }
Geoff Langbfdea662014-07-23 14:16:32 -04006210
Geoff Langb1196682014-07-23 13:47:29 -04006211 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6212 {
6213 context->recordError(gl::Error(GL_INVALID_OPERATION));
6214 return;
6215 }
6216
Geoff Langbfdea662014-07-23 14:16:32 -04006217 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6218 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6219 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6220 // and the pointer argument is not NULL.
6221 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006222 {
Geoff Langb1196682014-07-23 13:47:29 -04006223 context->recordError(gl::Error(GL_INVALID_OPERATION));
6224 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006225 }
6226
Geoff Langbfdea662014-07-23 14:16:32 -04006227 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6228 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006229 }
6230}
6231
6232void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6233{
6234 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6235 index, pname, params);
6236
Geoff Langbfdea662014-07-23 14:16:32 -04006237 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006238 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006239 {
Geoff Langbfdea662014-07-23 14:16:32 -04006240 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006241 {
Geoff Langb1196682014-07-23 13:47:29 -04006242 context->recordError(gl::Error(GL_INVALID_OPERATION));
6243 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006244 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006245
Geoff Langbfdea662014-07-23 14:16:32 -04006246 if (index >= gl::MAX_VERTEX_ATTRIBS)
6247 {
Geoff Langb1196682014-07-23 13:47:29 -04006248 context->recordError(gl::Error(GL_INVALID_VALUE));
6249 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006250 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006251
Geoff Langbfdea662014-07-23 14:16:32 -04006252 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006253
Geoff Langb1196682014-07-23 13:47:29 -04006254 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006255 {
6256 return;
6257 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006258
Geoff Langbfdea662014-07-23 14:16:32 -04006259 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6260 {
6261 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6262 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006263 {
Geoff Langbfdea662014-07-23 14:16:32 -04006264 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006265 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006266 }
Geoff Langbfdea662014-07-23 14:16:32 -04006267 else
6268 {
6269 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6270 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006271 }
6272}
6273
6274void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6275{
6276 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6277 index, pname, params);
6278
Geoff Langbfdea662014-07-23 14:16:32 -04006279 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006280 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006281 {
Geoff Langbfdea662014-07-23 14:16:32 -04006282 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006283 {
Geoff Langb1196682014-07-23 13:47:29 -04006284 context->recordError(gl::Error(GL_INVALID_OPERATION));
6285 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006286 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006287
Geoff Langbfdea662014-07-23 14:16:32 -04006288 if (index >= gl::MAX_VERTEX_ATTRIBS)
6289 {
Geoff Langb1196682014-07-23 13:47:29 -04006290 context->recordError(gl::Error(GL_INVALID_VALUE));
6291 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006292 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006293
Geoff Langbfdea662014-07-23 14:16:32 -04006294 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006295
Geoff Langb1196682014-07-23 13:47:29 -04006296 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006297 {
6298 return;
6299 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006300
Geoff Langbfdea662014-07-23 14:16:32 -04006301 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6302 {
6303 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6304 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006305 {
Geoff Langbfdea662014-07-23 14:16:32 -04006306 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006307 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006308 }
Geoff Langbfdea662014-07-23 14:16:32 -04006309 else
6310 {
6311 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6312 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006313 }
6314}
6315
6316void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6317{
6318 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6319 index, x, y, z, w);
6320
Geoff Langbfdea662014-07-23 14:16:32 -04006321 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006322 if (context)
6323 {
6324 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006325 {
Geoff Langb1196682014-07-23 13:47:29 -04006326 context->recordError(gl::Error(GL_INVALID_OPERATION));
6327 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006328 }
Geoff Langbfdea662014-07-23 14:16:32 -04006329
6330 if (index >= gl::MAX_VERTEX_ATTRIBS)
6331 {
Geoff Langb1196682014-07-23 13:47:29 -04006332 context->recordError(gl::Error(GL_INVALID_VALUE));
6333 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006334 }
6335
6336 GLint vals[4] = { x, y, z, w };
6337 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006338 }
6339}
6340
6341void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6342{
6343 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6344 index, x, y, z, w);
6345
Geoff Langbfdea662014-07-23 14:16:32 -04006346 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006347 if (context)
6348 {
6349 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006350 {
Geoff Langb1196682014-07-23 13:47:29 -04006351 context->recordError(gl::Error(GL_INVALID_OPERATION));
6352 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006353 }
Geoff Langbfdea662014-07-23 14:16:32 -04006354
6355 if (index >= gl::MAX_VERTEX_ATTRIBS)
6356 {
Geoff Langb1196682014-07-23 13:47:29 -04006357 context->recordError(gl::Error(GL_INVALID_VALUE));
6358 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006359 }
6360
6361 GLuint vals[4] = { x, y, z, w };
6362 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006363 }
6364}
6365
6366void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6367{
6368 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6369
Geoff Langbfdea662014-07-23 14:16:32 -04006370 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006371 if (context)
6372 {
6373 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006374 {
Geoff Langb1196682014-07-23 13:47:29 -04006375 context->recordError(gl::Error(GL_INVALID_OPERATION));
6376 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006377 }
Geoff Langbfdea662014-07-23 14:16:32 -04006378
6379 if (index >= gl::MAX_VERTEX_ATTRIBS)
6380 {
Geoff Langb1196682014-07-23 13:47:29 -04006381 context->recordError(gl::Error(GL_INVALID_VALUE));
6382 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006383 }
6384
6385 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006386 }
6387}
6388
6389void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6390{
6391 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6392
Geoff Langbfdea662014-07-23 14:16:32 -04006393 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006394 if (context)
6395 {
6396 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006397 {
Geoff Langb1196682014-07-23 13:47:29 -04006398 context->recordError(gl::Error(GL_INVALID_OPERATION));
6399 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006400 }
Geoff Langbfdea662014-07-23 14:16:32 -04006401
6402 if (index >= gl::MAX_VERTEX_ATTRIBS)
6403 {
Geoff Langb1196682014-07-23 13:47:29 -04006404 context->recordError(gl::Error(GL_INVALID_VALUE));
6405 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006406 }
6407
6408 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006409 }
6410}
6411
6412void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6413{
6414 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6415 program, location, params);
6416
Geoff Langbfdea662014-07-23 14:16:32 -04006417 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006418 if (context)
6419 {
Jamie Madill0063c512014-08-25 15:47:53 -04006420 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006421 {
Jamie Madill0063c512014-08-25 15:47:53 -04006422 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006423 }
Geoff Langbfdea662014-07-23 14:16:32 -04006424
Jamie Madilla502c742014-08-28 17:19:13 -04006425 gl::Program *programObject = context->getProgram(program);
6426 ASSERT(programObject);
6427 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006428 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006429
Jamie Madill99a1e982014-08-25 15:47:54 -04006430 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006431 }
6432}
6433
6434GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6435{
6436 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6437 program, name);
6438
Geoff Langbfdea662014-07-23 14:16:32 -04006439 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006440 if (context)
6441 {
6442 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006443 {
Geoff Langb1196682014-07-23 13:47:29 -04006444 context->recordError(gl::Error(GL_INVALID_OPERATION));
6445 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006446 }
Geoff Langbfdea662014-07-23 14:16:32 -04006447
6448 if (program == 0)
6449 {
Geoff Langb1196682014-07-23 13:47:29 -04006450 context->recordError(gl::Error(GL_INVALID_VALUE));
6451 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006452 }
6453
6454 gl::Program *programObject = context->getProgram(program);
6455
6456 if (!programObject || !programObject->isLinked())
6457 {
Geoff Langb1196682014-07-23 13:47:29 -04006458 context->recordError(gl::Error(GL_INVALID_OPERATION));
6459 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006460 }
6461
6462 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6463 if (!programBinary)
6464 {
Geoff Langb1196682014-07-23 13:47:29 -04006465 context->recordError(gl::Error(GL_INVALID_OPERATION));
6466 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006467 }
6468
6469 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006470 }
6471
6472 return 0;
6473}
6474
6475void __stdcall glUniform1ui(GLint location, GLuint v0)
6476{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006477 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006478}
6479
6480void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6481{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006482 const GLuint xy[] = { v0, v1 };
6483 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006484}
6485
6486void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6487{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006488 const GLuint xyz[] = { v0, v1, v2 };
6489 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006490}
6491
6492void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6493{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006494 const GLuint xyzw[] = { v0, v1, v2, v3 };
6495 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006496}
6497
6498void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6499{
6500 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6501 location, count, value);
6502
Geoff Langbfdea662014-07-23 14:16:32 -04006503 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006504 if (context)
6505 {
6506 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006507 {
Geoff Langbfdea662014-07-23 14:16:32 -04006508 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006509 }
Geoff Langbfdea662014-07-23 14:16:32 -04006510
6511 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6512 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006513 }
6514}
6515
6516void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6517{
6518 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6519 location, count, value);
6520
Geoff Langbfdea662014-07-23 14:16:32 -04006521 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006522 if (context)
6523 {
6524 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006525 {
Geoff Langbfdea662014-07-23 14:16:32 -04006526 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006527 }
Geoff Langbfdea662014-07-23 14:16:32 -04006528
6529 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6530 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006531 }
6532}
6533
6534void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6535{
6536 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6537 location, count, value);
6538
Geoff Langbfdea662014-07-23 14:16:32 -04006539 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006540 if (context)
6541 {
6542 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006543 {
Geoff Langbfdea662014-07-23 14:16:32 -04006544 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006545 }
Geoff Langbfdea662014-07-23 14:16:32 -04006546
6547 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6548 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006549 }
6550}
6551
6552void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6553{
6554 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6555 location, count, value);
6556
Geoff Langbfdea662014-07-23 14:16:32 -04006557 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006558 if (context)
6559 {
6560 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006561 {
Geoff Langbfdea662014-07-23 14:16:32 -04006562 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006563 }
Geoff Langbfdea662014-07-23 14:16:32 -04006564
6565 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6566 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006567 }
6568}
6569
6570void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6571{
6572 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6573 buffer, drawbuffer, value);
6574
Geoff Langbfdea662014-07-23 14:16:32 -04006575 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006576 if (context)
6577 {
6578 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006579 {
Geoff Langbfdea662014-07-23 14:16:32 -04006580 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006581 }
Geoff Langbfdea662014-07-23 14:16:32 -04006582
6583 switch (buffer)
6584 {
6585 case GL_COLOR:
6586 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6587 {
Geoff Langb1196682014-07-23 13:47:29 -04006588 context->recordError(gl::Error(GL_INVALID_VALUE));
6589 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006590 }
6591 break;
Geoff Langb1196682014-07-23 13:47:29 -04006592
Geoff Langbfdea662014-07-23 14:16:32 -04006593 case GL_STENCIL:
6594 if (drawbuffer != 0)
6595 {
Geoff Langb1196682014-07-23 13:47:29 -04006596 context->recordError(gl::Error(GL_INVALID_VALUE));
6597 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006598 }
6599 break;
Geoff Langb1196682014-07-23 13:47:29 -04006600
Geoff Langbfdea662014-07-23 14:16:32 -04006601 default:
Geoff Langb1196682014-07-23 13:47:29 -04006602 context->recordError(gl::Error(GL_INVALID_ENUM));
6603 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006604 }
6605
Geoff Langcc79b8c2014-07-25 13:48:02 -04006606 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6607 if (error.isError())
6608 {
6609 context->recordError(error);
6610 return;
6611 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006612 }
6613}
6614
6615void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6616{
6617 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6618 buffer, drawbuffer, value);
6619
Geoff Langbfdea662014-07-23 14:16:32 -04006620 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006621 if (context)
6622 {
6623 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006624 {
Geoff Langbfdea662014-07-23 14:16:32 -04006625 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006626 }
Geoff Langbfdea662014-07-23 14:16:32 -04006627
6628 switch (buffer)
6629 {
6630 case GL_COLOR:
6631 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6632 {
Geoff Langb1196682014-07-23 13:47:29 -04006633 context->recordError(gl::Error(GL_INVALID_VALUE));
6634 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006635 }
6636 break;
Geoff Langb1196682014-07-23 13:47:29 -04006637
Geoff Langbfdea662014-07-23 14:16:32 -04006638 default:
Geoff Langb1196682014-07-23 13:47:29 -04006639 context->recordError(gl::Error(GL_INVALID_ENUM));
6640 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006641 }
6642
Geoff Langcc79b8c2014-07-25 13:48:02 -04006643 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6644 if (error.isError())
6645 {
6646 context->recordError(error);
6647 return;
6648 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006649 }
6650}
6651
6652void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6653{
6654 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6655 buffer, drawbuffer, value);
6656
Geoff Langbfdea662014-07-23 14:16:32 -04006657 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006658 if (context)
6659 {
6660 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006661 {
Geoff Langbfdea662014-07-23 14:16:32 -04006662 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006663 }
Geoff Langbfdea662014-07-23 14:16:32 -04006664
6665 switch (buffer)
6666 {
6667 case GL_COLOR:
6668 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6669 {
Geoff Langb1196682014-07-23 13:47:29 -04006670 context->recordError(gl::Error(GL_INVALID_VALUE));
6671 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006672 }
6673 break;
Geoff Langb1196682014-07-23 13:47:29 -04006674
Geoff Langbfdea662014-07-23 14:16:32 -04006675 case GL_DEPTH:
6676 if (drawbuffer != 0)
6677 {
Geoff Langb1196682014-07-23 13:47:29 -04006678 context->recordError(gl::Error(GL_INVALID_VALUE));
6679 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006680 }
6681 break;
Geoff Langb1196682014-07-23 13:47:29 -04006682
Geoff Langbfdea662014-07-23 14:16:32 -04006683 default:
Geoff Langb1196682014-07-23 13:47:29 -04006684 context->recordError(gl::Error(GL_INVALID_ENUM));
6685 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006686 }
6687
Geoff Langcc79b8c2014-07-25 13:48:02 -04006688 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6689 if (error.isError())
6690 {
6691 context->recordError(error);
6692 return;
6693 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006694 }
6695}
6696
6697void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6698{
6699 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6700 buffer, drawbuffer, depth, stencil);
6701
Geoff Langbfdea662014-07-23 14:16:32 -04006702 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006703 if (context)
6704 {
6705 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006706 {
Geoff Langbfdea662014-07-23 14:16:32 -04006707 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006708 }
Geoff Langbfdea662014-07-23 14:16:32 -04006709
6710 switch (buffer)
6711 {
6712 case GL_DEPTH_STENCIL:
6713 if (drawbuffer != 0)
6714 {
Geoff Langb1196682014-07-23 13:47:29 -04006715 context->recordError(gl::Error(GL_INVALID_VALUE));
6716 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006717 }
6718 break;
Geoff Langb1196682014-07-23 13:47:29 -04006719
Geoff Langbfdea662014-07-23 14:16:32 -04006720 default:
Geoff Langb1196682014-07-23 13:47:29 -04006721 context->recordError(gl::Error(GL_INVALID_ENUM));
6722 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006723 }
6724
Geoff Langcc79b8c2014-07-25 13:48:02 -04006725 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6726 if (error.isError())
6727 {
6728 context->recordError(error);
6729 return;
6730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006731 }
6732}
6733
6734const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6735{
6736 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6737
Geoff Langbfdea662014-07-23 14:16:32 -04006738 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006739 if (context)
6740 {
6741 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006742 {
Geoff Langb1196682014-07-23 13:47:29 -04006743 context->recordError(gl::Error(GL_INVALID_OPERATION));
6744 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006745 }
Geoff Langbfdea662014-07-23 14:16:32 -04006746
6747 if (name != GL_EXTENSIONS)
6748 {
Geoff Langb1196682014-07-23 13:47:29 -04006749 context->recordError(gl::Error(GL_INVALID_ENUM));
6750 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006751 }
6752
6753 if (index >= context->getExtensionStringCount())
6754 {
Geoff Langb1196682014-07-23 13:47:29 -04006755 context->recordError(gl::Error(GL_INVALID_VALUE));
6756 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006757 }
6758
6759 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006760 }
6761
6762 return NULL;
6763}
6764
6765void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6766{
6767 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6768 readTarget, writeTarget, readOffset, writeOffset, size);
6769
Geoff Langbfdea662014-07-23 14:16:32 -04006770 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006771 if (context)
6772 {
6773 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006774 {
Geoff Langb1196682014-07-23 13:47:29 -04006775 context->recordError(gl::Error(GL_INVALID_OPERATION));
6776 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006777 }
Geoff Langbfdea662014-07-23 14:16:32 -04006778
6779 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6780 {
Geoff Langb1196682014-07-23 13:47:29 -04006781 context->recordError(gl::Error(GL_INVALID_ENUM));
6782 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006783 }
6784
6785 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6786 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6787
6788 if (!readBuffer || !writeBuffer)
6789 {
Geoff Langb1196682014-07-23 13:47:29 -04006790 context->recordError(gl::Error(GL_INVALID_OPERATION));
6791 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006792 }
6793
Jamie Madillcfaaf722014-07-31 10:47:54 -04006794 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006795 if (readBuffer->isMapped() || writeBuffer->isMapped())
6796 {
Geoff Langb1196682014-07-23 13:47:29 -04006797 context->recordError(gl::Error(GL_INVALID_OPERATION));
6798 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006799 }
6800
6801 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6802 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6803 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6804 {
Geoff Langb1196682014-07-23 13:47:29 -04006805 context->recordError(gl::Error(GL_INVALID_VALUE));
6806 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006807 }
6808
6809 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6810 {
Geoff Langb1196682014-07-23 13:47:29 -04006811 context->recordError(gl::Error(GL_INVALID_VALUE));
6812 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006813 }
6814
Geoff Langbfdea662014-07-23 14:16:32 -04006815 // if size is zero, the copy is a successful no-op
6816 if (size > 0)
6817 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006818 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6819 if (error.isError())
6820 {
6821 context->recordError(error);
6822 return;
6823 }
Geoff Langbfdea662014-07-23 14:16:32 -04006824 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006825 }
6826}
6827
6828void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6829{
6830 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6831 program, uniformCount, uniformNames, uniformIndices);
6832
Geoff Langbfdea662014-07-23 14:16:32 -04006833 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006834 if (context)
6835 {
6836 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006837 {
Geoff Langb1196682014-07-23 13:47:29 -04006838 context->recordError(gl::Error(GL_INVALID_OPERATION));
6839 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006840 }
6841
6842 if (uniformCount < 0)
6843 {
Geoff Langb1196682014-07-23 13:47:29 -04006844 context->recordError(gl::Error(GL_INVALID_VALUE));
6845 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006846 }
6847
6848 gl::Program *programObject = context->getProgram(program);
6849
6850 if (!programObject)
6851 {
6852 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006853 {
Geoff Langb1196682014-07-23 13:47:29 -04006854 context->recordError(gl::Error(GL_INVALID_OPERATION));
6855 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006856 }
Geoff Langbfdea662014-07-23 14:16:32 -04006857 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006858 {
Geoff Langb1196682014-07-23 13:47:29 -04006859 context->recordError(gl::Error(GL_INVALID_VALUE));
6860 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006861 }
Geoff Langbfdea662014-07-23 14:16:32 -04006862 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006863
Geoff Langbfdea662014-07-23 14:16:32 -04006864 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6865 if (!programObject->isLinked() || !programBinary)
6866 {
6867 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006868 {
Geoff Langbfdea662014-07-23 14:16:32 -04006869 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006870 }
6871 }
Geoff Langbfdea662014-07-23 14:16:32 -04006872 else
6873 {
6874 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6875 {
6876 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6877 }
6878 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006879 }
6880}
6881
6882void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6883{
6884 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6885 program, uniformCount, uniformIndices, pname, params);
6886
Geoff Langbfdea662014-07-23 14:16:32 -04006887 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006888 if (context)
6889 {
6890 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006891 {
Geoff Langb1196682014-07-23 13:47:29 -04006892 context->recordError(gl::Error(GL_INVALID_OPERATION));
6893 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006894 }
6895
6896 if (uniformCount < 0)
6897 {
Geoff Langb1196682014-07-23 13:47:29 -04006898 context->recordError(gl::Error(GL_INVALID_VALUE));
6899 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006900 }
6901
6902 gl::Program *programObject = context->getProgram(program);
6903
6904 if (!programObject)
6905 {
6906 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006907 {
Geoff Langb1196682014-07-23 13:47:29 -04006908 context->recordError(gl::Error(GL_INVALID_OPERATION));
6909 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006910 }
Geoff Langbfdea662014-07-23 14:16:32 -04006911 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006912 {
Geoff Langb1196682014-07-23 13:47:29 -04006913 context->recordError(gl::Error(GL_INVALID_VALUE));
6914 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006915 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006916 }
Geoff Langbfdea662014-07-23 14:16:32 -04006917
6918 switch (pname)
6919 {
6920 case GL_UNIFORM_TYPE:
6921 case GL_UNIFORM_SIZE:
6922 case GL_UNIFORM_NAME_LENGTH:
6923 case GL_UNIFORM_BLOCK_INDEX:
6924 case GL_UNIFORM_OFFSET:
6925 case GL_UNIFORM_ARRAY_STRIDE:
6926 case GL_UNIFORM_MATRIX_STRIDE:
6927 case GL_UNIFORM_IS_ROW_MAJOR:
6928 break;
Geoff Langb1196682014-07-23 13:47:29 -04006929
Geoff Langbfdea662014-07-23 14:16:32 -04006930 default:
Geoff Langb1196682014-07-23 13:47:29 -04006931 context->recordError(gl::Error(GL_INVALID_ENUM));
6932 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006933 }
6934
6935 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6936
6937 if (!programBinary && uniformCount > 0)
6938 {
Geoff Langb1196682014-07-23 13:47:29 -04006939 context->recordError(gl::Error(GL_INVALID_VALUE));
6940 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006941 }
6942
6943 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6944 {
6945 const GLuint index = uniformIndices[uniformId];
6946
6947 if (index >= (GLuint)programBinary->getActiveUniformCount())
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
6954 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6955 {
6956 const GLuint index = uniformIndices[uniformId];
6957 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6958 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006959 }
6960}
6961
6962GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6963{
6964 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6965
Geoff Langbfdea662014-07-23 14:16:32 -04006966 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006967 if (context)
6968 {
6969 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006970 {
Geoff Langb1196682014-07-23 13:47:29 -04006971 context->recordError(gl::Error(GL_INVALID_OPERATION));
6972 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04006973 }
6974
6975 gl::Program *programObject = context->getProgram(program);
6976
6977 if (!programObject)
6978 {
6979 if (context->getShader(program))
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;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006983 }
Geoff Langbfdea662014-07-23 14:16:32 -04006984 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006985 {
Geoff Langb1196682014-07-23 13:47:29 -04006986 context->recordError(gl::Error(GL_INVALID_VALUE));
6987 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006988 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006989 }
Geoff Langbfdea662014-07-23 14:16:32 -04006990
6991 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6992 if (!programBinary)
6993 {
6994 return GL_INVALID_INDEX;
6995 }
6996
6997 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006998 }
6999
7000 return 0;
7001}
7002
7003void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
7004{
7005 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7006 program, uniformBlockIndex, pname, params);
7007
Geoff Langbfdea662014-07-23 14:16:32 -04007008 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007009 if (context)
7010 {
7011 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007012 {
Geoff Langb1196682014-07-23 13:47:29 -04007013 context->recordError(gl::Error(GL_INVALID_OPERATION));
7014 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007015 }
7016 gl::Program *programObject = context->getProgram(program);
7017
7018 if (!programObject)
7019 {
7020 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007021 {
Geoff Langb1196682014-07-23 13:47:29 -04007022 context->recordError(gl::Error(GL_INVALID_OPERATION));
7023 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007024 }
Geoff Langbfdea662014-07-23 14:16:32 -04007025 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007026 {
Geoff Langb1196682014-07-23 13:47:29 -04007027 context->recordError(gl::Error(GL_INVALID_VALUE));
7028 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007029 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007030 }
Geoff Langbfdea662014-07-23 14:16:32 -04007031
7032 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7033
7034 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7035 {
Geoff Langb1196682014-07-23 13:47:29 -04007036 context->recordError(gl::Error(GL_INVALID_VALUE));
7037 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007038 }
7039
7040 switch (pname)
7041 {
7042 case GL_UNIFORM_BLOCK_BINDING:
7043 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7044 break;
7045
7046 case GL_UNIFORM_BLOCK_DATA_SIZE:
7047 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7048 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7049 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7050 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7051 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7052 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7053 break;
7054
7055 default:
Geoff Langb1196682014-07-23 13:47:29 -04007056 context->recordError(gl::Error(GL_INVALID_ENUM));
7057 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007058 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007059 }
7060}
7061
7062void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7063{
7064 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7065 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7066
Geoff Langbfdea662014-07-23 14:16:32 -04007067 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007068 if (context)
7069 {
7070 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007071 {
Geoff Langb1196682014-07-23 13:47:29 -04007072 context->recordError(gl::Error(GL_INVALID_OPERATION));
7073 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007074 }
7075
7076 gl::Program *programObject = context->getProgram(program);
7077
7078 if (!programObject)
7079 {
7080 if (context->getShader(program))
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;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007084 }
Geoff Langbfdea662014-07-23 14:16:32 -04007085 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007086 {
Geoff Langb1196682014-07-23 13:47:29 -04007087 context->recordError(gl::Error(GL_INVALID_VALUE));
7088 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007089 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007090 }
Geoff Langbfdea662014-07-23 14:16:32 -04007091
7092 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7093
7094 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7095 {
Geoff Langb1196682014-07-23 13:47:29 -04007096 context->recordError(gl::Error(GL_INVALID_VALUE));
7097 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007098 }
7099
7100 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007101 }
7102}
7103
7104void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7105{
7106 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7107 program, uniformBlockIndex, uniformBlockBinding);
7108
Geoff Langbfdea662014-07-23 14:16:32 -04007109 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007110 if (context)
7111 {
7112 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007113 {
Geoff Langb1196682014-07-23 13:47:29 -04007114 context->recordError(gl::Error(GL_INVALID_OPERATION));
7115 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007116 }
7117
Geoff Lang3a61c322014-07-10 13:01:54 -04007118 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007119 {
Geoff Langb1196682014-07-23 13:47:29 -04007120 context->recordError(gl::Error(GL_INVALID_VALUE));
7121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007122 }
7123
7124 gl::Program *programObject = context->getProgram(program);
7125
7126 if (!programObject)
7127 {
7128 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007129 {
Geoff Langb1196682014-07-23 13:47:29 -04007130 context->recordError(gl::Error(GL_INVALID_OPERATION));
7131 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007132 }
Geoff Langbfdea662014-07-23 14:16:32 -04007133 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007134 {
Geoff Langb1196682014-07-23 13:47:29 -04007135 context->recordError(gl::Error(GL_INVALID_VALUE));
7136 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007137 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007138 }
Geoff Langbfdea662014-07-23 14:16:32 -04007139
7140 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7141
7142 // if never linked, there won't be any uniform blocks
7143 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7144 {
Geoff Langb1196682014-07-23 13:47:29 -04007145 context->recordError(gl::Error(GL_INVALID_VALUE));
7146 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007147 }
7148
7149 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007150 }
7151}
7152
7153void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7154{
7155 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7156 mode, first, count, instanceCount);
7157
Geoff Langbfdea662014-07-23 14:16:32 -04007158 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007159 if (context)
7160 {
7161 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007162 {
Geoff Langb1196682014-07-23 13:47:29 -04007163 context->recordError(gl::Error(GL_INVALID_OPERATION));
7164 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007165 }
Geoff Langbfdea662014-07-23 14:16:32 -04007166
7167 // glDrawArraysInstanced
7168 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007169 }
7170}
7171
7172void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7173{
7174 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7175 mode, count, type, indices, instanceCount);
7176
Geoff Langbfdea662014-07-23 14:16:32 -04007177 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007178 if (context)
7179 {
7180 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007181 {
Geoff Langb1196682014-07-23 13:47:29 -04007182 context->recordError(gl::Error(GL_INVALID_OPERATION));
7183 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007184 }
Geoff Langbfdea662014-07-23 14:16:32 -04007185
7186 // glDrawElementsInstanced
7187 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007188 }
7189}
7190
7191GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7192{
7193 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7194
Geoff Langbfdea662014-07-23 14:16:32 -04007195 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007196 if (context)
7197 {
7198 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007199 {
Geoff Langb1196682014-07-23 13:47:29 -04007200 context->recordError(gl::Error(GL_INVALID_OPERATION));
7201 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007202 }
Geoff Langbfdea662014-07-23 14:16:32 -04007203
7204 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7205 {
Geoff Langb1196682014-07-23 13:47:29 -04007206 context->recordError(gl::Error(GL_INVALID_ENUM));
7207 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007208 }
7209
7210 if (flags != 0)
7211 {
Geoff Langb1196682014-07-23 13:47:29 -04007212 context->recordError(gl::Error(GL_INVALID_VALUE));
7213 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007214 }
7215
7216 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007217 }
7218
7219 return NULL;
7220}
7221
7222GLboolean __stdcall glIsSync(GLsync sync)
7223{
7224 EVENT("(GLsync sync = 0x%0.8p)", sync);
7225
Geoff Langbfdea662014-07-23 14:16:32 -04007226 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007227 if (context)
7228 {
7229 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007230 {
Geoff Langb1196682014-07-23 13:47:29 -04007231 context->recordError(gl::Error(GL_INVALID_OPERATION));
7232 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007233 }
Geoff Langbfdea662014-07-23 14:16:32 -04007234
7235 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007236 }
7237
7238 return GL_FALSE;
7239}
7240
7241void __stdcall glDeleteSync(GLsync sync)
7242{
7243 EVENT("(GLsync sync = 0x%0.8p)", sync);
7244
Geoff Langbfdea662014-07-23 14:16:32 -04007245 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007246 if (context)
7247 {
7248 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007249 {
Geoff Langb1196682014-07-23 13:47:29 -04007250 context->recordError(gl::Error(GL_INVALID_OPERATION));
7251 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007252 }
Geoff Langbfdea662014-07-23 14:16:32 -04007253
7254 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7255 {
Geoff Langb1196682014-07-23 13:47:29 -04007256 context->recordError(gl::Error(GL_INVALID_VALUE));
7257 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007258 }
7259
7260 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007261 }
7262}
7263
7264GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7265{
7266 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7267 sync, flags, timeout);
7268
Geoff Langbfdea662014-07-23 14:16:32 -04007269 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007270 if (context)
7271 {
7272 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007273 {
Geoff Langb1196682014-07-23 13:47:29 -04007274 context->recordError(gl::Error(GL_INVALID_OPERATION));
7275 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007276 }
Geoff Langbfdea662014-07-23 14:16:32 -04007277
7278 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7279 {
Geoff Langb1196682014-07-23 13:47:29 -04007280 context->recordError(gl::Error(GL_INVALID_VALUE));
7281 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007282 }
7283
7284 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7285
7286 if (!fenceSync)
7287 {
Geoff Langb1196682014-07-23 13:47:29 -04007288 context->recordError(gl::Error(GL_INVALID_VALUE));
7289 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007290 }
7291
7292 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007293 }
7294
7295 return GL_FALSE;
7296}
7297
7298void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7299{
7300 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7301 sync, flags, timeout);
7302
Geoff Langbfdea662014-07-23 14:16:32 -04007303 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007304 if (context)
7305 {
7306 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007307 {
Geoff Langb1196682014-07-23 13:47:29 -04007308 context->recordError(gl::Error(GL_INVALID_OPERATION));
7309 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007310 }
Geoff Langbfdea662014-07-23 14:16:32 -04007311
7312 if (flags != 0)
7313 {
Geoff Langb1196682014-07-23 13:47:29 -04007314 context->recordError(gl::Error(GL_INVALID_VALUE));
7315 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007316 }
7317
7318 if (timeout != GL_TIMEOUT_IGNORED)
7319 {
Geoff Langb1196682014-07-23 13:47:29 -04007320 context->recordError(gl::Error(GL_INVALID_VALUE));
7321 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007322 }
7323
7324 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7325
7326 if (!fenceSync)
7327 {
Geoff Langb1196682014-07-23 13:47:29 -04007328 context->recordError(gl::Error(GL_INVALID_VALUE));
7329 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007330 }
7331
7332 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007333 }
7334}
7335
7336void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7337{
7338 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7339 pname, params);
7340
Geoff Langbfdea662014-07-23 14:16:32 -04007341 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007342 if (context)
7343 {
7344 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007345 {
Geoff Langb1196682014-07-23 13:47:29 -04007346 context->recordError(gl::Error(GL_INVALID_OPERATION));
7347 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007348 }
Geoff Langbfdea662014-07-23 14:16:32 -04007349
7350 GLenum nativeType;
7351 unsigned int numParams = 0;
7352 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7353 {
7354 return;
7355 }
7356
7357 if (nativeType == GL_INT_64_ANGLEX)
7358 {
7359 context->getInteger64v(pname, params);
7360 }
7361 else
7362 {
7363 CastStateValues(context, nativeType, pname, numParams, params);
7364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007365 }
7366}
7367
7368void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7369{
7370 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7371 sync, pname, bufSize, length, values);
7372
Geoff Langbfdea662014-07-23 14:16:32 -04007373 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007374 if (context)
7375 {
7376 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007377 {
Geoff Langb1196682014-07-23 13:47:29 -04007378 context->recordError(gl::Error(GL_INVALID_OPERATION));
7379 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007380 }
Geoff Langbfdea662014-07-23 14:16:32 -04007381
7382 if (bufSize < 0)
7383 {
Geoff Langb1196682014-07-23 13:47:29 -04007384 context->recordError(gl::Error(GL_INVALID_VALUE));
7385 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007386 }
7387
7388 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7389
7390 if (!fenceSync)
7391 {
Geoff Langb1196682014-07-23 13:47:29 -04007392 context->recordError(gl::Error(GL_INVALID_VALUE));
7393 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007394 }
7395
7396 switch (pname)
7397 {
7398 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7399 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7400 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7401 case GL_SYNC_FLAGS: values[0] = 0; break;
7402
7403 default:
Geoff Langb1196682014-07-23 13:47:29 -04007404 context->recordError(gl::Error(GL_INVALID_ENUM));
7405 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007406 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007407 }
7408}
7409
7410void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7411{
7412 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7413 target, index, data);
7414
Geoff Langbfdea662014-07-23 14:16:32 -04007415 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007416 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007417 {
Geoff Langbfdea662014-07-23 14:16:32 -04007418 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007419 {
Geoff Langb1196682014-07-23 13:47:29 -04007420 context->recordError(gl::Error(GL_INVALID_OPERATION));
7421 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007422 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007423
Geoff Lang3a61c322014-07-10 13:01:54 -04007424 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007425 switch (target)
7426 {
7427 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7428 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7429 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007430 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7431 {
Geoff Langb1196682014-07-23 13:47:29 -04007432 context->recordError(gl::Error(GL_INVALID_VALUE));
7433 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007434 }
Geoff Langbfdea662014-07-23 14:16:32 -04007435 break;
Geoff Langb1196682014-07-23 13:47:29 -04007436
Geoff Langbfdea662014-07-23 14:16:32 -04007437 case GL_UNIFORM_BUFFER_START:
7438 case GL_UNIFORM_BUFFER_SIZE:
7439 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007440 if (index >= caps.maxUniformBufferBindings)
7441 {
Geoff Langb1196682014-07-23 13:47:29 -04007442 context->recordError(gl::Error(GL_INVALID_VALUE));
7443 return;
Geoff Lang3a61c322014-07-10 13:01:54 -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 default:
Geoff Langb1196682014-07-23 13:47:29 -04007448 context->recordError(gl::Error(GL_INVALID_ENUM));
7449 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007450 }
7451
7452 if (!(context->getIndexedInteger64v(target, index, data)))
7453 {
7454 GLenum nativeType;
7455 unsigned int numParams = 0;
7456 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007457 {
7458 context->recordError(gl::Error(GL_INVALID_ENUM));
7459 return;
7460 }
Shannon Woods15934d52013-08-19 14:28:49 -04007461
Geoff Langbfdea662014-07-23 14:16:32 -04007462 if (numParams == 0)
7463 return; // it is known that pname is valid, but there are no parameters to return
7464
7465 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007466 {
Geoff Langbfdea662014-07-23 14:16:32 -04007467 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007468
Geoff Langbfdea662014-07-23 14:16:32 -04007469 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007470
Geoff Langbfdea662014-07-23 14:16:32 -04007471 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007472 {
Geoff Langbfdea662014-07-23 14:16:32 -04007473 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007474 }
Geoff Langbfdea662014-07-23 14:16:32 -04007475
7476 delete [] intParams;
7477 }
7478 else
7479 {
7480 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007481 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007482 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007483 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007484}
7485
7486void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7487{
7488 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7489 target, pname, params);
7490
Geoff Langbfdea662014-07-23 14:16:32 -04007491 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007492 if (context)
7493 {
7494 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007495 {
Geoff Langb1196682014-07-23 13:47:29 -04007496 context->recordError(gl::Error(GL_INVALID_OPERATION));
7497 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007498 }
Geoff Langbfdea662014-07-23 14:16:32 -04007499
7500 if (!gl::ValidBufferTarget(context, target))
7501 {
Geoff Langb1196682014-07-23 13:47:29 -04007502 context->recordError(gl::Error(GL_INVALID_ENUM));
7503 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007504 }
7505
7506 if (!gl::ValidBufferParameter(context, pname))
7507 {
Geoff Langb1196682014-07-23 13:47:29 -04007508 context->recordError(gl::Error(GL_INVALID_ENUM));
7509 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007510 }
7511
7512 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7513
7514 if (!buffer)
7515 {
7516 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007517 context->recordError(gl::Error(GL_INVALID_OPERATION));
7518 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007519 }
7520
7521 switch (pname)
7522 {
7523 case GL_BUFFER_USAGE:
7524 *params = static_cast<GLint64>(buffer->getUsage());
7525 break;
7526 case GL_BUFFER_SIZE:
7527 *params = buffer->getSize();
7528 break;
7529 case GL_BUFFER_ACCESS_FLAGS:
7530 *params = static_cast<GLint64>(buffer->getAccessFlags());
7531 break;
7532 case GL_BUFFER_MAPPED:
7533 *params = static_cast<GLint64>(buffer->isMapped());
7534 break;
7535 case GL_BUFFER_MAP_OFFSET:
7536 *params = buffer->getMapOffset();
7537 break;
7538 case GL_BUFFER_MAP_LENGTH:
7539 *params = buffer->getMapLength();
7540 break;
7541 default: UNREACHABLE(); break;
7542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007543 }
7544}
7545
7546void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7547{
7548 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7549
Geoff Langbfdea662014-07-23 14:16:32 -04007550 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007551 if (context)
7552 {
7553 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007554 {
Geoff Langb1196682014-07-23 13:47:29 -04007555 context->recordError(gl::Error(GL_INVALID_OPERATION));
7556 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007557 }
Geoff Langbfdea662014-07-23 14:16:32 -04007558
7559 if (count < 0)
7560 {
Geoff Langb1196682014-07-23 13:47:29 -04007561 context->recordError(gl::Error(GL_INVALID_VALUE));
7562 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007563 }
7564
7565 for (int i = 0; i < count; i++)
7566 {
7567 samplers[i] = context->createSampler();
7568 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007569 }
7570}
7571
7572void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7573{
7574 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7575
Geoff Langbfdea662014-07-23 14:16:32 -04007576 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007577 if (context)
7578 {
7579 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007580 {
Geoff Langb1196682014-07-23 13:47:29 -04007581 context->recordError(gl::Error(GL_INVALID_OPERATION));
7582 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007583 }
Geoff Langbfdea662014-07-23 14:16:32 -04007584
7585 if (count < 0)
7586 {
Geoff Langb1196682014-07-23 13:47:29 -04007587 context->recordError(gl::Error(GL_INVALID_VALUE));
7588 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007589 }
7590
7591 for (int i = 0; i < count; i++)
7592 {
7593 context->deleteSampler(samplers[i]);
7594 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007595 }
7596}
7597
7598GLboolean __stdcall glIsSampler(GLuint sampler)
7599{
7600 EVENT("(GLuint sampler = %u)", sampler);
7601
Geoff Langbfdea662014-07-23 14:16:32 -04007602 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007603 if (context)
7604 {
7605 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007606 {
Geoff Langb1196682014-07-23 13:47:29 -04007607 context->recordError(gl::Error(GL_INVALID_OPERATION));
7608 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007609 }
Geoff Langbfdea662014-07-23 14:16:32 -04007610
7611 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007612 }
7613
7614 return GL_FALSE;
7615}
7616
7617void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7618{
7619 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7620
Geoff Langbfdea662014-07-23 14:16:32 -04007621 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007622 if (context)
7623 {
7624 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007625 {
Geoff Langb1196682014-07-23 13:47:29 -04007626 context->recordError(gl::Error(GL_INVALID_OPERATION));
7627 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007628 }
Geoff Langbfdea662014-07-23 14:16:32 -04007629
7630 if (sampler != 0 && !context->isSampler(sampler))
7631 {
Geoff Langb1196682014-07-23 13:47:29 -04007632 context->recordError(gl::Error(GL_INVALID_OPERATION));
7633 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007634 }
7635
Geoff Lang3a61c322014-07-10 13:01:54 -04007636 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007637 {
Geoff Langb1196682014-07-23 13:47:29 -04007638 context->recordError(gl::Error(GL_INVALID_VALUE));
7639 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007640 }
7641
7642 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007643 }
7644}
7645
7646void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7647{
7648 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7649
Geoff Langbfdea662014-07-23 14:16:32 -04007650 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007651 if (context)
7652 {
7653 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007654 {
Geoff Langb1196682014-07-23 13:47:29 -04007655 context->recordError(gl::Error(GL_INVALID_OPERATION));
7656 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007657 }
Geoff Langbfdea662014-07-23 14:16:32 -04007658
Geoff Langb1196682014-07-23 13:47:29 -04007659 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007660 {
7661 return;
7662 }
7663
7664 if (!gl::ValidateTexParamParameters(context, pname, param))
7665 {
7666 return;
7667 }
7668
7669 if (!context->isSampler(sampler))
7670 {
Geoff Langb1196682014-07-23 13:47:29 -04007671 context->recordError(gl::Error(GL_INVALID_OPERATION));
7672 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007673 }
7674
7675 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007676 }
7677}
7678
7679void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7680{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007681 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007682}
7683
7684void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7685{
7686 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7687
Geoff Langbfdea662014-07-23 14:16:32 -04007688 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007689 if (context)
7690 {
7691 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007692 {
Geoff Langb1196682014-07-23 13:47:29 -04007693 context->recordError(gl::Error(GL_INVALID_OPERATION));
7694 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007695 }
Geoff Langbfdea662014-07-23 14:16:32 -04007696
Geoff Langb1196682014-07-23 13:47:29 -04007697 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007698 {
7699 return;
7700 }
7701
7702 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7703 {
7704 return;
7705 }
7706
7707 if (!context->isSampler(sampler))
7708 {
Geoff Langb1196682014-07-23 13:47:29 -04007709 context->recordError(gl::Error(GL_INVALID_OPERATION));
7710 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007711 }
7712
7713 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007714 }
7715}
7716
7717void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7718{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007719 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007720}
7721
7722void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7723{
7724 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7725
Geoff Langbfdea662014-07-23 14:16:32 -04007726 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007727 if (context)
7728 {
7729 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007730 {
Geoff Langb1196682014-07-23 13:47:29 -04007731 context->recordError(gl::Error(GL_INVALID_OPERATION));
7732 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007733 }
Geoff Langbfdea662014-07-23 14:16:32 -04007734
Geoff Langb1196682014-07-23 13:47:29 -04007735 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007736 {
7737 return;
7738 }
7739
7740 if (!context->isSampler(sampler))
7741 {
Geoff Langb1196682014-07-23 13:47:29 -04007742 context->recordError(gl::Error(GL_INVALID_OPERATION));
7743 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007744 }
7745
7746 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007747 }
7748}
7749
7750void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7751{
7752 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7753
Geoff Langbfdea662014-07-23 14:16:32 -04007754 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007755 if (context)
7756 {
7757 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007758 {
Geoff Langb1196682014-07-23 13:47:29 -04007759 context->recordError(gl::Error(GL_INVALID_OPERATION));
7760 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007761 }
Geoff Langbfdea662014-07-23 14:16:32 -04007762
Geoff Langb1196682014-07-23 13:47:29 -04007763 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007764 {
7765 return;
7766 }
7767
7768 if (!context->isSampler(sampler))
7769 {
Geoff Langb1196682014-07-23 13:47:29 -04007770 context->recordError(gl::Error(GL_INVALID_OPERATION));
7771 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007772 }
7773
7774 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007775 }
7776}
7777
7778void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7779{
7780 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7781
Geoff Langbfdea662014-07-23 14:16:32 -04007782 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007783 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007784 {
Geoff Langbfdea662014-07-23 14:16:32 -04007785 if (context->getClientVersion() < 3)
7786 {
Geoff Langb1196682014-07-23 13:47:29 -04007787 context->recordError(gl::Error(GL_INVALID_OPERATION));
7788 return;
7789 }
7790
7791 if (index >= gl::MAX_VERTEX_ATTRIBS)
7792 {
7793 context->recordError(gl::Error(GL_INVALID_VALUE));
7794 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007795 }
7796
7797 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007798 }
7799}
7800
7801void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7802{
7803 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7804
Geoff Langbfdea662014-07-23 14:16:32 -04007805 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007806 if (context)
7807 {
7808 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007809 {
Geoff Langb1196682014-07-23 13:47:29 -04007810 context->recordError(gl::Error(GL_INVALID_OPERATION));
7811 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007812 }
Geoff Langbfdea662014-07-23 14:16:32 -04007813
7814 switch (target)
7815 {
7816 case GL_TRANSFORM_FEEDBACK:
7817 {
7818 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7819 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7820 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7821 {
Geoff Langb1196682014-07-23 13:47:29 -04007822 context->recordError(gl::Error(GL_INVALID_OPERATION));
7823 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007824 }
7825
7826 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7827 if (context->getTransformFeedback(id) == NULL)
7828 {
Geoff Langb1196682014-07-23 13:47:29 -04007829 context->recordError(gl::Error(GL_INVALID_OPERATION));
7830 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007831 }
7832
7833 context->bindTransformFeedback(id);
7834 }
7835 break;
7836
7837 default:
Geoff Langb1196682014-07-23 13:47:29 -04007838 context->recordError(gl::Error(GL_INVALID_ENUM));
7839 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007840 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007841 }
7842}
7843
7844void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7845{
7846 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7847
Geoff Langbfdea662014-07-23 14:16:32 -04007848 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007849 if (context)
7850 {
7851 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007852 {
Geoff Langb1196682014-07-23 13:47:29 -04007853 context->recordError(gl::Error(GL_INVALID_OPERATION));
7854 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007855 }
Geoff Langbfdea662014-07-23 14:16:32 -04007856
7857 for (int i = 0; i < n; i++)
7858 {
7859 context->deleteTransformFeedback(ids[i]);
7860 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007861 }
7862}
7863
7864void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7865{
7866 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7867
Geoff Langbfdea662014-07-23 14:16:32 -04007868 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007869 if (context)
7870 {
7871 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007872 {
Geoff Langb1196682014-07-23 13:47:29 -04007873 context->recordError(gl::Error(GL_INVALID_OPERATION));
7874 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007875 }
Geoff Langbfdea662014-07-23 14:16:32 -04007876
7877 for (int i = 0; i < n; i++)
7878 {
7879 ids[i] = context->createTransformFeedback();
7880 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007881 }
7882}
7883
7884GLboolean __stdcall glIsTransformFeedback(GLuint id)
7885{
7886 EVENT("(GLuint id = %u)", id);
7887
Geoff Langbfdea662014-07-23 14:16:32 -04007888 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007889 if (context)
7890 {
7891 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007892 {
Geoff Langb1196682014-07-23 13:47:29 -04007893 context->recordError(gl::Error(GL_INVALID_OPERATION));
7894 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007895 }
Geoff Langbfdea662014-07-23 14:16:32 -04007896
7897 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007898 }
7899
7900 return GL_FALSE;
7901}
7902
7903void __stdcall glPauseTransformFeedback(void)
7904{
7905 EVENT("(void)");
7906
Geoff Langbfdea662014-07-23 14:16:32 -04007907 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007908 if (context)
7909 {
7910 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007911 {
Geoff Langb1196682014-07-23 13:47:29 -04007912 context->recordError(gl::Error(GL_INVALID_OPERATION));
7913 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007914 }
Geoff Langbfdea662014-07-23 14:16:32 -04007915
7916 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7917 ASSERT(transformFeedback != NULL);
7918
7919 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7920 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7921 {
Geoff Langb1196682014-07-23 13:47:29 -04007922 context->recordError(gl::Error(GL_INVALID_OPERATION));
7923 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007924 }
7925
7926 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007927 }
7928}
7929
7930void __stdcall glResumeTransformFeedback(void)
7931{
7932 EVENT("(void)");
7933
Geoff Langbfdea662014-07-23 14:16:32 -04007934 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007935 if (context)
7936 {
7937 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007938 {
Geoff Langb1196682014-07-23 13:47:29 -04007939 context->recordError(gl::Error(GL_INVALID_OPERATION));
7940 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007941 }
Geoff Langbfdea662014-07-23 14:16:32 -04007942
7943 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7944 ASSERT(transformFeedback != NULL);
7945
7946 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7947 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7948 {
Geoff Langb1196682014-07-23 13:47:29 -04007949 context->recordError(gl::Error(GL_INVALID_OPERATION));
7950 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007951 }
7952
7953 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007954 }
7955}
7956
7957void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7958{
7959 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7960 program, bufSize, length, binaryFormat, binary);
7961
Geoff Langbfdea662014-07-23 14:16:32 -04007962 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007963 if (context)
7964 {
7965 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007966 {
Geoff Langb1196682014-07-23 13:47:29 -04007967 context->recordError(gl::Error(GL_INVALID_OPERATION));
7968 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007969 }
Geoff Langbfdea662014-07-23 14:16:32 -04007970
7971 // glGetProgramBinary
7972 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007973 }
7974}
7975
7976void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7977{
7978 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7979 program, binaryFormat, binary, length);
7980
Geoff Langbfdea662014-07-23 14:16:32 -04007981 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007982 if (context)
7983 {
7984 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007985 {
Geoff Langb1196682014-07-23 13:47:29 -04007986 context->recordError(gl::Error(GL_INVALID_OPERATION));
7987 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007988 }
Geoff Langbfdea662014-07-23 14:16:32 -04007989
7990 // glProgramBinary
7991 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007992 }
7993}
7994
7995void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7996{
7997 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7998 program, pname, value);
7999
Geoff Langbfdea662014-07-23 14:16:32 -04008000 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008001 if (context)
8002 {
8003 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008004 {
Geoff Langb1196682014-07-23 13:47:29 -04008005 context->recordError(gl::Error(GL_INVALID_OPERATION));
8006 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008007 }
Geoff Langbfdea662014-07-23 14:16:32 -04008008
8009 // glProgramParameteri
8010 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008011 }
8012}
8013
8014void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
8015{
8016 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8017 target, numAttachments, attachments);
8018
Geoff Langbfdea662014-07-23 14:16:32 -04008019 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008020 if (context)
8021 {
8022 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008023 {
Geoff Langb1196682014-07-23 13:47:29 -04008024 context->recordError(gl::Error(GL_INVALID_OPERATION));
8025 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008026 }
Geoff Langbfdea662014-07-23 14:16:32 -04008027
8028 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8029 {
8030 return;
8031 }
8032
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008033 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8034 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8035 {
8036 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8037 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008038 }
8039}
8040
8041void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
8042{
8043 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8044 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8045 target, numAttachments, attachments, x, y, width, height);
8046
Geoff Langbfdea662014-07-23 14:16:32 -04008047 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008048 if (context)
8049 {
8050 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008051 {
Geoff Langb1196682014-07-23 13:47:29 -04008052 context->recordError(gl::Error(GL_INVALID_OPERATION));
8053 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008054 }
Geoff Langbfdea662014-07-23 14:16:32 -04008055
8056 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8057 {
8058 return;
8059 }
8060
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008061 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8062 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8063 {
8064 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8065 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008066 }
8067}
8068
8069void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8070{
8071 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8072 target, levels, internalformat, width, height);
8073
Geoff Langbfdea662014-07-23 14:16:32 -04008074 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008075 if (context)
8076 {
8077 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008078 {
Geoff Langb1196682014-07-23 13:47:29 -04008079 context->recordError(gl::Error(GL_INVALID_OPERATION));
8080 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008081 }
Geoff Langbfdea662014-07-23 14:16:32 -04008082
8083 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8084 {
8085 return;
8086 }
8087
8088 switch (target)
8089 {
8090 case GL_TEXTURE_2D:
8091 {
8092 gl::Texture2D *texture2d = context->getTexture2D();
8093 texture2d->storage(levels, internalformat, width, height);
8094 }
8095 break;
8096
8097 case GL_TEXTURE_CUBE_MAP:
8098 {
8099 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8100 textureCube->storage(levels, internalformat, width);
8101 }
8102 break;
8103
8104 default:
Geoff Langb1196682014-07-23 13:47:29 -04008105 context->recordError(gl::Error(GL_INVALID_ENUM));
8106 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008107 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008108 }
8109}
8110
8111void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8112{
8113 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8114 "GLsizei height = %d, GLsizei depth = %d)",
8115 target, levels, internalformat, width, height, depth);
8116
Geoff Langbfdea662014-07-23 14:16:32 -04008117 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008118 if (context)
8119 {
8120 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008121 {
Geoff Langb1196682014-07-23 13:47:29 -04008122 context->recordError(gl::Error(GL_INVALID_OPERATION));
8123 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008124 }
Geoff Langbfdea662014-07-23 14:16:32 -04008125
8126 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8127 {
8128 return;
8129 }
8130
8131 switch (target)
8132 {
8133 case GL_TEXTURE_3D:
8134 {
8135 gl::Texture3D *texture3d = context->getTexture3D();
8136 texture3d->storage(levels, internalformat, width, height, depth);
8137 }
8138 break;
8139
8140 case GL_TEXTURE_2D_ARRAY:
8141 {
8142 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8143 texture2darray->storage(levels, internalformat, width, height, depth);
8144 }
8145 break;
8146
8147 default:
8148 UNREACHABLE();
8149 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008150 }
8151}
8152
8153void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8154{
8155 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8156 "GLint* params = 0x%0.8p)",
8157 target, internalformat, pname, bufSize, params);
8158
Geoff Langbfdea662014-07-23 14:16:32 -04008159 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008160 if (context)
8161 {
8162 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008163 {
Geoff Langb1196682014-07-23 13:47:29 -04008164 context->recordError(gl::Error(GL_INVALID_OPERATION));
8165 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008166 }
Geoff Langbfdea662014-07-23 14:16:32 -04008167
8168 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8169 if (!formatCaps.renderable)
8170 {
Geoff Langb1196682014-07-23 13:47:29 -04008171 context->recordError(gl::Error(GL_INVALID_ENUM));
8172 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008173 }
8174
8175 if (target != GL_RENDERBUFFER)
8176 {
Geoff Langb1196682014-07-23 13:47:29 -04008177 context->recordError(gl::Error(GL_INVALID_ENUM));
8178 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008179 }
8180
8181 if (bufSize < 0)
8182 {
Geoff Langb1196682014-07-23 13:47:29 -04008183 context->recordError(gl::Error(GL_INVALID_VALUE));
8184 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008185 }
8186
8187 switch (pname)
8188 {
8189 case GL_NUM_SAMPLE_COUNTS:
8190 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008191 {
8192 *params = formatCaps.sampleCounts.size();
8193 }
Geoff Langbfdea662014-07-23 14:16:32 -04008194 break;
Geoff Langb1196682014-07-23 13:47:29 -04008195
Geoff Langbfdea662014-07-23 14:16:32 -04008196 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008197 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008198 break;
Geoff Langb1196682014-07-23 13:47:29 -04008199
Geoff Langbfdea662014-07-23 14:16:32 -04008200 default:
Geoff Langb1196682014-07-23 13:47:29 -04008201 context->recordError(gl::Error(GL_INVALID_ENUM));
8202 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008203 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008204 }
8205}
8206
8207// Extension functions
8208
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008209void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8210 GLbitfield mask, GLenum filter)
8211{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008212 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008213 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8214 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8215 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8216
Geoff Langbfdea662014-07-23 14:16:32 -04008217 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008218 if (context)
8219 {
8220 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8221 dstX0, dstY0, dstX1, dstY1, mask, filter,
8222 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008223 {
Geoff Langbfdea662014-07-23 14:16:32 -04008224 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008225 }
Geoff Langbfdea662014-07-23 14:16:32 -04008226
8227 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8228 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008229 }
8230}
8231
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008232void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8233 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008234{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008235 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008236 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008237 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008238 target, level, internalformat, width, height, depth, border, format, type, pixels);
8239
Geoff Langbfdea662014-07-23 14:16:32 -04008240 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008241}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008242
Geoff Langbfdea662014-07-23 14:16:32 -04008243void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008244 GLenum *binaryFormat, void *binary)
8245{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008246 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 +00008247 program, bufSize, length, binaryFormat, binary);
8248
Geoff Langbfdea662014-07-23 14:16:32 -04008249 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008250 if (context)
8251 {
8252 gl::Program *programObject = context->getProgram(program);
8253
8254 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008255 {
Geoff Langb1196682014-07-23 13:47:29 -04008256 context->recordError(gl::Error(GL_INVALID_OPERATION));
8257 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008258 }
Geoff Langbfdea662014-07-23 14:16:32 -04008259
8260 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8261
8262 if (!programBinary)
8263 {
Geoff Langb1196682014-07-23 13:47:29 -04008264 context->recordError(gl::Error(GL_INVALID_OPERATION));
8265 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008266 }
8267
Geoff Lang900013c2014-07-07 11:32:19 -04008268 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04008269 {
Geoff Langb1196682014-07-23 13:47:29 -04008270 context->recordError(gl::Error(GL_INVALID_OPERATION));
8271 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008272 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008273 }
8274}
8275
8276void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8277 const void *binary, GLint length)
8278{
8279 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8280 program, binaryFormat, binary, length);
8281
Geoff Langbfdea662014-07-23 14:16:32 -04008282 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008283 if (context)
8284 {
Geoff Lang900013c2014-07-07 11:32:19 -04008285 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8286 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008287 {
Geoff Langb1196682014-07-23 13:47:29 -04008288 context->recordError(gl::Error(GL_INVALID_ENUM));
8289 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008290 }
Geoff Langbfdea662014-07-23 14:16:32 -04008291
8292 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008293 if (!programObject)
8294 {
Geoff Langb1196682014-07-23 13:47:29 -04008295 context->recordError(gl::Error(GL_INVALID_OPERATION));
8296 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008297 }
8298
Geoff Lang900013c2014-07-07 11:32:19 -04008299 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008300 }
8301}
8302
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008303void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8304{
8305 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8306
Geoff Langbfdea662014-07-23 14:16:32 -04008307 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008308 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008309 {
Geoff Langbfdea662014-07-23 14:16:32 -04008310 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008311 {
Geoff Langb1196682014-07-23 13:47:29 -04008312 context->recordError(gl::Error(GL_INVALID_VALUE));
8313 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008314 }
8315
8316 if (context->getState().getDrawFramebuffer()->id() == 0)
8317 {
8318 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008319 {
Geoff Langb1196682014-07-23 13:47:29 -04008320 context->recordError(gl::Error(GL_INVALID_OPERATION));
8321 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008322 }
8323
Geoff Langbfdea662014-07-23 14:16:32 -04008324 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008325 {
Geoff Langb1196682014-07-23 13:47:29 -04008326 context->recordError(gl::Error(GL_INVALID_OPERATION));
8327 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008328 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008329 }
Geoff Langbfdea662014-07-23 14:16:32 -04008330 else
8331 {
8332 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8333 {
8334 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8335 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8336 {
Geoff Langb1196682014-07-23 13:47:29 -04008337 context->recordError(gl::Error(GL_INVALID_OPERATION));
8338 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008339 }
8340 }
8341 }
8342
8343 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8344
8345 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8346 {
8347 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8348 }
8349
8350 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8351 {
8352 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8353 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008354 }
8355}
8356
Shannon Woodsb3801742014-03-27 14:59:19 -04008357void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8358{
8359 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8360
Geoff Langbfdea662014-07-23 14:16:32 -04008361 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008362 if (context)
8363 {
8364 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008365 {
Geoff Langb1196682014-07-23 13:47:29 -04008366 context->recordError(gl::Error(GL_INVALID_ENUM));
8367 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008368 }
Geoff Langbfdea662014-07-23 14:16:32 -04008369
8370 if (pname != GL_BUFFER_MAP_POINTER)
8371 {
Geoff Langb1196682014-07-23 13:47:29 -04008372 context->recordError(gl::Error(GL_INVALID_ENUM));
8373 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008374 }
8375
8376 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8377
8378 if (!buffer || !buffer->isMapped())
8379 {
8380 *params = NULL;
8381 }
8382 else
8383 {
8384 *params = buffer->getMapPointer();
8385 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008386 }
8387}
8388
8389void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8390{
8391 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8392
Geoff Langbfdea662014-07-23 14:16:32 -04008393 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008394 if (context)
8395 {
8396 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008397 {
Geoff Langb1196682014-07-23 13:47:29 -04008398 context->recordError(gl::Error(GL_INVALID_ENUM));
8399 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008400 }
Geoff Langbfdea662014-07-23 14:16:32 -04008401
8402 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8403
8404 if (buffer == NULL)
8405 {
Geoff Langb1196682014-07-23 13:47:29 -04008406 context->recordError(gl::Error(GL_INVALID_OPERATION));
8407 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008408 }
8409
8410 if (access != GL_WRITE_ONLY_OES)
8411 {
Geoff Langb1196682014-07-23 13:47:29 -04008412 context->recordError(gl::Error(GL_INVALID_ENUM));
8413 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008414 }
8415
8416 if (buffer->isMapped())
8417 {
Geoff Langb1196682014-07-23 13:47:29 -04008418 context->recordError(gl::Error(GL_INVALID_OPERATION));
8419 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008420 }
8421
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008422 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8423 if (error.isError())
8424 {
8425 context->recordError(error);
8426 return NULL;
8427 }
8428
8429 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008430 }
8431
8432 return NULL;
8433}
8434
8435GLboolean __stdcall glUnmapBufferOES(GLenum target)
8436{
8437 EVENT("(GLenum target = 0x%X)", target);
8438
Geoff Langbfdea662014-07-23 14:16:32 -04008439 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008440 if (context)
8441 {
8442 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008443 {
Geoff Langb1196682014-07-23 13:47:29 -04008444 context->recordError(gl::Error(GL_INVALID_ENUM));
8445 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008446 }
Geoff Langbfdea662014-07-23 14:16:32 -04008447
8448 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8449
8450 if (buffer == NULL || !buffer->isMapped())
8451 {
Geoff Langb1196682014-07-23 13:47:29 -04008452 context->recordError(gl::Error(GL_INVALID_OPERATION));
8453 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008454 }
8455
8456 // TODO: detect if we had corruption. if so, throw an error and return false.
8457
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008458 gl::Error error = buffer->unmap();
8459 if (error.isError())
8460 {
8461 context->recordError(error);
8462 return GL_FALSE;
8463 }
Geoff Langbfdea662014-07-23 14:16:32 -04008464
8465 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008466 }
8467
8468 return GL_FALSE;
8469}
8470
Shannon Woods916e7692014-03-27 16:58:22 -04008471void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8472{
8473 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8474 target, offset, length, access);
8475
Geoff Langbfdea662014-07-23 14:16:32 -04008476 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008477 if (context)
8478 {
8479 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008480 {
Geoff Langb1196682014-07-23 13:47:29 -04008481 context->recordError(gl::Error(GL_INVALID_ENUM));
8482 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008483 }
Geoff Langbfdea662014-07-23 14:16:32 -04008484
8485 if (offset < 0 || length < 0)
8486 {
Geoff Langb1196682014-07-23 13:47:29 -04008487 context->recordError(gl::Error(GL_INVALID_VALUE));
8488 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008489 }
8490
8491 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8492
8493 if (buffer == NULL)
8494 {
Geoff Langb1196682014-07-23 13:47:29 -04008495 context->recordError(gl::Error(GL_INVALID_OPERATION));
8496 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008497 }
8498
8499 // Check for buffer overflow
8500 size_t offsetSize = static_cast<size_t>(offset);
8501 size_t lengthSize = static_cast<size_t>(length);
8502
8503 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8504 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8505 {
Geoff Langb1196682014-07-23 13:47:29 -04008506 context->recordError(gl::Error(GL_INVALID_VALUE));
8507 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008508 }
8509
8510 // Check for invalid bits in the mask
8511 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8512 GL_MAP_WRITE_BIT |
8513 GL_MAP_INVALIDATE_RANGE_BIT |
8514 GL_MAP_INVALIDATE_BUFFER_BIT |
8515 GL_MAP_FLUSH_EXPLICIT_BIT |
8516 GL_MAP_UNSYNCHRONIZED_BIT;
8517
8518 if (access & ~(allAccessBits))
8519 {
Geoff Langb1196682014-07-23 13:47:29 -04008520 context->recordError(gl::Error(GL_INVALID_VALUE));
8521 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008522 }
8523
8524 if (length == 0 || buffer->isMapped())
8525 {
Geoff Langb1196682014-07-23 13:47:29 -04008526 context->recordError(gl::Error(GL_INVALID_OPERATION));
8527 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008528 }
8529
8530 // Check for invalid bit combinations
8531 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8532 {
Geoff Langb1196682014-07-23 13:47:29 -04008533 context->recordError(gl::Error(GL_INVALID_OPERATION));
8534 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008535 }
8536
8537 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8538 GL_MAP_INVALIDATE_BUFFER_BIT |
8539 GL_MAP_UNSYNCHRONIZED_BIT;
8540
8541 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 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 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8548 {
Geoff Langb1196682014-07-23 13:47:29 -04008549 context->recordError(gl::Error(GL_INVALID_OPERATION));
8550 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008551 }
8552
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008553 gl::Error error = buffer->mapRange(offset, length, access);
8554 if (error.isError())
8555 {
8556 context->recordError(error);
8557 return NULL;
8558 }
8559
8560 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008561 }
8562
8563 return NULL;
8564}
8565
8566void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8567{
8568 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8569
Geoff Langbfdea662014-07-23 14:16:32 -04008570 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008571 if (context)
8572 {
8573 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008574 {
Geoff Langb1196682014-07-23 13:47:29 -04008575 context->recordError(gl::Error(GL_INVALID_VALUE));
8576 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008577 }
Geoff Langbfdea662014-07-23 14:16:32 -04008578
8579 if (!gl::ValidBufferTarget(context, target))
8580 {
Geoff Langb1196682014-07-23 13:47:29 -04008581 context->recordError(gl::Error(GL_INVALID_ENUM));
8582 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008583 }
8584
8585 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8586
8587 if (buffer == NULL)
8588 {
Geoff Langb1196682014-07-23 13:47:29 -04008589 context->recordError(gl::Error(GL_INVALID_OPERATION));
8590 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008591 }
8592
8593 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8594 {
Geoff Langb1196682014-07-23 13:47:29 -04008595 context->recordError(gl::Error(GL_INVALID_OPERATION));
8596 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008597 }
8598
8599 // Check for buffer overflow
8600 size_t offsetSize = static_cast<size_t>(offset);
8601 size_t lengthSize = static_cast<size_t>(length);
8602
8603 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8604 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8605 {
Geoff Langb1196682014-07-23 13:47:29 -04008606 context->recordError(gl::Error(GL_INVALID_VALUE));
8607 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008608 }
8609
8610 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008611 }
8612}
8613
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008614__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8615{
8616 struct Extension
8617 {
8618 const char *name;
8619 __eglMustCastToProperFunctionPointerType address;
8620 };
8621
8622 static const Extension glExtensions[] =
8623 {
8624 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008625 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008626 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008627 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8628 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8629 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8630 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8631 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8632 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8633 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008634 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008635 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008636 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8637 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8638 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8639 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008640 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8641 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8642 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8643 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8644 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8645 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8646 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008647 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008648 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8649 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8650 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008651 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008652 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8653 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8654 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008655 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8656 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8657 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008658
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008659 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008660 {
8661 if (strcmp(procname, glExtensions[ext].name) == 0)
8662 {
8663 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8664 }
8665 }
8666
8667 return NULL;
8668}
8669
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008670// Non-public functions used by EGL
8671
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008672bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008673{
8674 EVENT("(egl::Surface* surface = 0x%0.8p)",
8675 surface);
8676
Geoff Langbfdea662014-07-23 14:16:32 -04008677 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008678 if (context)
8679 {
8680 gl::Texture2D *textureObject = context->getTexture2D();
8681 ASSERT(textureObject != NULL);
8682
8683 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008684 {
Geoff Langbfdea662014-07-23 14:16:32 -04008685 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008686 }
Geoff Langbfdea662014-07-23 14:16:32 -04008687
8688 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008689 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008690
8691 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008692}
8693
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008694}