blob: e0443da75e309280975fd94e237cd208e77f509a [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
657 context->clear(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000658 }
659}
660
661void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
662{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000663 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000664 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000665
Geoff Langbfdea662014-07-23 14:16:32 -0400666 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400667 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000668 {
Geoff Langbfdea662014-07-23 14:16:32 -0400669 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000670 }
671}
672
673void __stdcall glClearDepthf(GLclampf depth)
674{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000675 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000676
Geoff Langbfdea662014-07-23 14:16:32 -0400677 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400678 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000679 {
Geoff Langbfdea662014-07-23 14:16:32 -0400680 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000681 }
682}
683
684void __stdcall glClearStencil(GLint s)
685{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000686 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000687
Geoff Langbfdea662014-07-23 14:16:32 -0400688 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400689 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000690 {
Geoff Langbfdea662014-07-23 14:16:32 -0400691 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000692 }
693}
694
695void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
696{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000697 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000698 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000699
Geoff Langbfdea662014-07-23 14:16:32 -0400700 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400701 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000702 {
Geoff Langbfdea662014-07-23 14:16:32 -0400703 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000704 }
705}
706
707void __stdcall glCompileShader(GLuint shader)
708{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000709 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000710
Geoff Langbfdea662014-07-23 14:16:32 -0400711 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400712 if (context)
713 {
714 gl::Shader *shaderObject = context->getShader(shader);
715
716 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000717 {
Geoff Langbfdea662014-07-23 14:16:32 -0400718 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000719 {
Geoff Langb1196682014-07-23 13:47:29 -0400720 context->recordError(gl::Error(GL_INVALID_OPERATION));
721 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000722 }
Geoff Langbfdea662014-07-23 14:16:32 -0400723 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000724 {
Geoff Langb1196682014-07-23 13:47:29 -0400725 context->recordError(gl::Error(GL_INVALID_VALUE));
726 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000727 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000728 }
Geoff Langbfdea662014-07-23 14:16:32 -0400729
730 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000731 }
Geoff Langbfdea662014-07-23 14:16:32 -0400732}
733
734void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
735 GLint border, GLsizei imageSize, const GLvoid* data)
736{
737 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
738 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
739 target, level, internalformat, width, height, border, imageSize, data);
740
741 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400742 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000743 {
Geoff Langbfdea662014-07-23 14:16:32 -0400744 if (context->getClientVersion() < 3 &&
745 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
746 0, 0, width, height, border, GL_NONE, GL_NONE, data))
747 {
748 return;
749 }
750
751 if (context->getClientVersion() >= 3 &&
752 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
753 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
754 {
755 return;
756 }
757
Geoff Lang5d601382014-07-22 15:14:06 -0400758 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
759 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400760 {
Geoff Langb1196682014-07-23 13:47:29 -0400761 context->recordError(gl::Error(GL_INVALID_VALUE));
762 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400763 }
764
765 switch (target)
766 {
767 case GL_TEXTURE_2D:
768 {
769 gl::Texture2D *texture = context->getTexture2D();
770 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
771 }
772 break;
773
774 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
775 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
776 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
777 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
778 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
779 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
780 {
781 gl::TextureCubeMap *texture = context->getTextureCubeMap();
782 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
783 }
784 break;
785
786 default:
Geoff Langb1196682014-07-23 13:47:29 -0400787 context->recordError(gl::Error(GL_INVALID_ENUM));
788 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400789 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000790 }
791}
792
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000793void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
794 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000795{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000796 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000797 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000798 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000799 target, level, xoffset, yoffset, width, height, format, imageSize, data);
800
Geoff Langbfdea662014-07-23 14:16:32 -0400801 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400802 if (context)
803 {
804 if (context->getClientVersion() < 3 &&
805 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
806 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000807 {
Geoff Langbfdea662014-07-23 14:16:32 -0400808 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000809 }
Geoff Langbfdea662014-07-23 14:16:32 -0400810
811 if (context->getClientVersion() >= 3 &&
812 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
813 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
814 {
815 return;
816 }
817
Geoff Lang5d601382014-07-22 15:14:06 -0400818 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
819 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400820 {
Geoff Langb1196682014-07-23 13:47:29 -0400821 context->recordError(gl::Error(GL_INVALID_VALUE));
822 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400823 }
824
825 switch (target)
826 {
827 case GL_TEXTURE_2D:
828 {
829 gl::Texture2D *texture = context->getTexture2D();
830 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
831 }
832 break;
833
834 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
835 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
836 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
837 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
838 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
839 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
840 {
841 gl::TextureCubeMap *texture = context->getTextureCubeMap();
842 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
843 }
844 break;
845
846 default:
Geoff Langb1196682014-07-23 13:47:29 -0400847 context->recordError(gl::Error(GL_INVALID_ENUM));
848 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400849 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000850 }
851}
852
853void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
854{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000855 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000856 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000857 target, level, internalformat, x, y, width, height, border);
858
Geoff Langbfdea662014-07-23 14:16:32 -0400859 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400860 if (context)
861 {
862 if (context->getClientVersion() < 3 &&
863 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
864 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000865 {
Geoff Langbfdea662014-07-23 14:16:32 -0400866 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000867 }
Geoff Langbfdea662014-07-23 14:16:32 -0400868
869 if (context->getClientVersion() >= 3 &&
870 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
871 0, 0, 0, x, y, width, height, border))
872 {
873 return;
874 }
875
876 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
877
878 switch (target)
879 {
880 case GL_TEXTURE_2D:
881 {
882 gl::Texture2D *texture = context->getTexture2D();
883 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
884 }
885 break;
886
887 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
888 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
889 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
890 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
891 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
892 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
893 {
894 gl::TextureCubeMap *texture = context->getTextureCubeMap();
895 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
896 }
897 break;
898
Geoff Langb1196682014-07-23 13:47:29 -0400899 default:
900 context->recordError(gl::Error(GL_INVALID_ENUM));
901 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400902 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000903 }
904}
905
906void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
907{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000908 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000909 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000910 target, level, xoffset, yoffset, x, y, width, height);
911
Geoff Langbfdea662014-07-23 14:16:32 -0400912 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400913 if (context)
914 {
915 if (context->getClientVersion() < 3 &&
916 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
917 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000918 {
Geoff Langbfdea662014-07-23 14:16:32 -0400919 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000920 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000921
Geoff Langbfdea662014-07-23 14:16:32 -0400922 if (context->getClientVersion() >= 3 &&
923 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
924 xoffset, yoffset, 0, x, y, width, height, 0))
925 {
926 return;
927 }
928
929 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
930
931 switch (target)
932 {
933 case GL_TEXTURE_2D:
934 {
935 gl::Texture2D *texture = context->getTexture2D();
936 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
937 }
938 break;
939
940 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
941 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
942 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
943 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
944 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
945 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
946 {
947 gl::TextureCubeMap *texture = context->getTextureCubeMap();
948 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
949 }
950 break;
951
952 default:
Geoff Langb1196682014-07-23 13:47:29 -0400953 context->recordError(gl::Error(GL_INVALID_ENUM));
954 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400955 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000956 }
957}
958
959GLuint __stdcall glCreateProgram(void)
960{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000961 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000962
Geoff Langbfdea662014-07-23 14:16:32 -0400963 gl::Context *context = gl::getNonLostContext();
964 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000965 {
Geoff Langbfdea662014-07-23 14:16:32 -0400966 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000967 }
968
969 return 0;
970}
971
972GLuint __stdcall glCreateShader(GLenum type)
973{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000974 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000975
Geoff Langbfdea662014-07-23 14:16:32 -0400976 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400977 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000978 {
Geoff Langbfdea662014-07-23 14:16:32 -0400979 switch (type)
980 {
981 case GL_FRAGMENT_SHADER:
982 case GL_VERTEX_SHADER:
983 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -0400984
Geoff Langbfdea662014-07-23 14:16:32 -0400985 default:
Geoff Langb1196682014-07-23 13:47:29 -0400986 context->recordError(gl::Error(GL_INVALID_ENUM));
987 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -0400988 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000989 }
990
991 return 0;
992}
993
994void __stdcall glCullFace(GLenum mode)
995{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000996 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000997
Geoff Langb1196682014-07-23 13:47:29 -0400998 gl::Context *context = gl::getNonLostContext();
999 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001000 {
Geoff Langb1196682014-07-23 13:47:29 -04001001 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001002 {
Geoff Langb1196682014-07-23 13:47:29 -04001003 case GL_FRONT:
1004 case GL_BACK:
1005 case GL_FRONT_AND_BACK:
1006 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001007
Geoff Langb1196682014-07-23 13:47:29 -04001008 default:
1009 context->recordError(gl::Error(GL_INVALID_ENUM));
1010 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001011 }
Geoff Langb1196682014-07-23 13:47:29 -04001012
1013 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001014 }
1015}
1016
1017void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
1018{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001019 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001020
Geoff Langbfdea662014-07-23 14:16:32 -04001021 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001022 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001023 {
Geoff Langb1196682014-07-23 13:47:29 -04001024 if (n < 0)
1025 {
1026 context->recordError(gl::Error(GL_INVALID_VALUE));
1027 return;
1028 }
1029
Geoff Langbfdea662014-07-23 14:16:32 -04001030 for (int i = 0; i < n; i++)
1031 {
1032 context->deleteBuffer(buffers[i]);
1033 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001034 }
1035}
1036
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001037void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
1038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001039 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001040
Geoff Langbfdea662014-07-23 14:16:32 -04001041 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001042 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001043 {
Geoff Langb1196682014-07-23 13:47:29 -04001044 if (n < 0)
1045 {
1046 context->recordError(gl::Error(GL_INVALID_VALUE));
1047 return;
1048 }
1049
Geoff Langbfdea662014-07-23 14:16:32 -04001050 for (int i = 0; i < n; i++)
1051 {
1052 context->deleteFenceNV(fences[i]);
1053 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001054 }
1055}
1056
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001057void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1058{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001059 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001060
Geoff Langbfdea662014-07-23 14:16:32 -04001061 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001062 if (context)
1063 {
Geoff Langb1196682014-07-23 13:47:29 -04001064 if (n < 0)
1065 {
1066 context->recordError(gl::Error(GL_INVALID_VALUE));
1067 return;
1068 }
1069
Geoff Langbfdea662014-07-23 14:16:32 -04001070 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001071 {
Geoff Langbfdea662014-07-23 14:16:32 -04001072 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001073 {
Geoff Langbfdea662014-07-23 14:16:32 -04001074 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001075 }
1076 }
1077 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001078}
1079
1080void __stdcall glDeleteProgram(GLuint program)
1081{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001082 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001083
Geoff Langbfdea662014-07-23 14:16:32 -04001084 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001085 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001086 {
Geoff Langb1196682014-07-23 13:47:29 -04001087 if (program == 0)
1088 {
1089 return;
1090 }
1091
Geoff Langbfdea662014-07-23 14:16:32 -04001092 if (!context->getProgram(program))
1093 {
1094 if(context->getShader(program))
1095 {
Geoff Langb1196682014-07-23 13:47:29 -04001096 context->recordError(gl::Error(GL_INVALID_OPERATION));
1097 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001098 }
1099 else
1100 {
Geoff Langb1196682014-07-23 13:47:29 -04001101 context->recordError(gl::Error(GL_INVALID_VALUE));
1102 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001103 }
1104 }
1105
1106 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001107 }
1108}
1109
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001110void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1111{
1112 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1113
Geoff Langbfdea662014-07-23 14:16:32 -04001114 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001115 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001116 {
Geoff Langb1196682014-07-23 13:47:29 -04001117 if (n < 0)
1118 {
1119 context->recordError(gl::Error(GL_INVALID_VALUE));
1120 return;
1121 }
1122
Geoff Langbfdea662014-07-23 14:16:32 -04001123 for (int i = 0; i < n; i++)
1124 {
1125 context->deleteQuery(ids[i]);
1126 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001127 }
1128}
1129
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001130void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1131{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001132 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001133
Geoff Langbfdea662014-07-23 14:16:32 -04001134 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001135 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001136 {
Geoff Langb1196682014-07-23 13:47:29 -04001137 if (n < 0)
1138 {
1139 context->recordError(gl::Error(GL_INVALID_VALUE));
1140 return;
1141 }
1142
Geoff Langbfdea662014-07-23 14:16:32 -04001143 for (int i = 0; i < n; i++)
1144 {
1145 context->deleteRenderbuffer(renderbuffers[i]);
1146 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001147 }
1148}
1149
1150void __stdcall glDeleteShader(GLuint shader)
1151{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001152 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001153
Geoff Langbfdea662014-07-23 14:16:32 -04001154 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001155 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001156 {
Geoff Langb1196682014-07-23 13:47:29 -04001157 if (shader == 0)
1158 {
1159 return;
1160 }
1161
Geoff Langbfdea662014-07-23 14:16:32 -04001162 if (!context->getShader(shader))
1163 {
1164 if(context->getProgram(shader))
1165 {
Geoff Langb1196682014-07-23 13:47:29 -04001166 context->recordError(gl::Error(GL_INVALID_OPERATION));
1167 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001168 }
1169 else
1170 {
Geoff Langb1196682014-07-23 13:47:29 -04001171 context->recordError(gl::Error(GL_INVALID_VALUE));
1172 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001173 }
1174 }
1175
1176 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001177 }
1178}
1179
1180void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1181{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001182 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001183
Geoff Langbfdea662014-07-23 14:16:32 -04001184 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001185 if (context)
1186 {
Geoff Langb1196682014-07-23 13:47:29 -04001187 if (n < 0)
1188 {
1189 context->recordError(gl::Error(GL_INVALID_VALUE));
1190 return;
1191 }
1192
Geoff Langbfdea662014-07-23 14:16:32 -04001193 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001194 {
Geoff Langbfdea662014-07-23 14:16:32 -04001195 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001196 {
Geoff Langbfdea662014-07-23 14:16:32 -04001197 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001198 }
1199 }
1200 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001201}
1202
1203void __stdcall glDepthFunc(GLenum func)
1204{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001205 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001206
Geoff Langbfdea662014-07-23 14:16:32 -04001207 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001208 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001209 {
Geoff Langb1196682014-07-23 13:47:29 -04001210 switch (func)
1211 {
1212 case GL_NEVER:
1213 case GL_ALWAYS:
1214 case GL_LESS:
1215 case GL_LEQUAL:
1216 case GL_EQUAL:
1217 case GL_GREATER:
1218 case GL_GEQUAL:
1219 case GL_NOTEQUAL:
1220 context->getState().setDepthFunc(func);
1221 break;
1222
1223 default:
1224 context->recordError(gl::Error(GL_INVALID_ENUM));
1225 return;
1226 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001227 }
1228}
1229
1230void __stdcall glDepthMask(GLboolean flag)
1231{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001232 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001233
Geoff Langbfdea662014-07-23 14:16:32 -04001234 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001235 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001236 {
Geoff Langbfdea662014-07-23 14:16:32 -04001237 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001238 }
1239}
1240
1241void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1242{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001243 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001244
Geoff Langbfdea662014-07-23 14:16:32 -04001245 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001246 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001247 {
Geoff Langbfdea662014-07-23 14:16:32 -04001248 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001249 }
1250}
1251
1252void __stdcall glDetachShader(GLuint program, GLuint shader)
1253{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001254 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001255
Geoff Langbfdea662014-07-23 14:16:32 -04001256 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001257 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001258 {
Geoff Langbfdea662014-07-23 14:16:32 -04001259 gl::Program *programObject = context->getProgram(program);
1260 gl::Shader *shaderObject = context->getShader(shader);
1261
1262 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001263 {
Geoff Langbfdea662014-07-23 14:16:32 -04001264 gl::Shader *shaderByProgramHandle;
1265 shaderByProgramHandle = context->getShader(program);
1266 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001267 {
Geoff Langb1196682014-07-23 13:47:29 -04001268 context->recordError(gl::Error(GL_INVALID_VALUE));
1269 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001270 }
Geoff Langbfdea662014-07-23 14:16:32 -04001271 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001272 {
Geoff Langb1196682014-07-23 13:47:29 -04001273 context->recordError(gl::Error(GL_INVALID_OPERATION));
1274 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001275 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001276 }
Geoff Langbfdea662014-07-23 14:16:32 -04001277
1278 if (!shaderObject)
1279 {
1280 gl::Program *programByShaderHandle = context->getProgram(shader);
1281 if (!programByShaderHandle)
1282 {
Geoff Langb1196682014-07-23 13:47:29 -04001283 context->recordError(gl::Error(GL_INVALID_VALUE));
1284 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001285 }
1286 else
1287 {
Geoff Langb1196682014-07-23 13:47:29 -04001288 context->recordError(gl::Error(GL_INVALID_OPERATION));
1289 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001290 }
1291 }
1292
1293 if (!programObject->detachShader(shaderObject))
1294 {
Geoff Langb1196682014-07-23 13:47:29 -04001295 context->recordError(gl::Error(GL_INVALID_OPERATION));
1296 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001297 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001298 }
1299}
1300
1301void __stdcall glDisable(GLenum cap)
1302{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001303 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001304
Geoff Langbfdea662014-07-23 14:16:32 -04001305 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001306 if (context)
1307 {
1308 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001309 {
Geoff Langb1196682014-07-23 13:47:29 -04001310 context->recordError(gl::Error(GL_INVALID_ENUM));
1311 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001312 }
Geoff Langbfdea662014-07-23 14:16:32 -04001313
1314 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001315 }
1316}
1317
1318void __stdcall glDisableVertexAttribArray(GLuint index)
1319{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001320 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001321
Geoff Langbfdea662014-07-23 14:16:32 -04001322 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001323 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001324 {
Geoff Langb1196682014-07-23 13:47:29 -04001325 if (index >= gl::MAX_VERTEX_ATTRIBS)
1326 {
1327 context->recordError(gl::Error(GL_INVALID_VALUE));
1328 return;
1329 }
1330
Geoff Langbfdea662014-07-23 14:16:32 -04001331 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001332 }
1333}
1334
1335void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1336{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001337 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001338
Geoff Langbfdea662014-07-23 14:16:32 -04001339 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001340 if (context)
1341 {
Jamie Madill2b976812014-08-25 15:47:49 -04001342 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001343 {
Geoff Langbfdea662014-07-23 14:16:32 -04001344 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001345 }
Geoff Langbfdea662014-07-23 14:16:32 -04001346
1347 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001348 }
1349}
1350
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001351void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1352{
1353 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1354
Geoff Langbfdea662014-07-23 14:16:32 -04001355 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001356 if (context)
1357 {
1358 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001359 {
Geoff Langbfdea662014-07-23 14:16:32 -04001360 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001361 }
Geoff Langbfdea662014-07-23 14:16:32 -04001362
1363 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001364 }
1365}
1366
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001367void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001368{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001369 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 +00001370 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001371
Geoff Langbfdea662014-07-23 14:16:32 -04001372 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001373 if (context)
1374 {
Jamie Madill2b976812014-08-25 15:47:49 -04001375 rx::RangeUI indexRange;
1376 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001377 {
Geoff Langbfdea662014-07-23 14:16:32 -04001378 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001379 }
Geoff Langbfdea662014-07-23 14:16:32 -04001380
Jamie Madill2b976812014-08-25 15:47:49 -04001381 context->drawElements(mode, count, type, indices, 0, indexRange);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001382 }
1383}
1384
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001385void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1386{
1387 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1388 mode, count, type, indices, primcount);
1389
Geoff Langbfdea662014-07-23 14:16:32 -04001390 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001391 if (context)
1392 {
Jamie Madill2b976812014-08-25 15:47:49 -04001393 rx::RangeUI indexRange;
1394 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001395 {
Geoff Langbfdea662014-07-23 14:16:32 -04001396 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001397 }
Geoff Langbfdea662014-07-23 14:16:32 -04001398
Jamie Madill2b976812014-08-25 15:47:49 -04001399 context->drawElements(mode, count, type, indices, primcount, indexRange);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001400 }
1401}
1402
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001403void __stdcall glEnable(GLenum cap)
1404{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001405 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001406
Geoff Langbfdea662014-07-23 14:16:32 -04001407 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001408 if (context)
1409 {
1410 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001411 {
Geoff Langb1196682014-07-23 13:47:29 -04001412 context->recordError(gl::Error(GL_INVALID_ENUM));
1413 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001414 }
Geoff Langbfdea662014-07-23 14:16:32 -04001415
1416 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001417 }
1418}
1419
1420void __stdcall glEnableVertexAttribArray(GLuint index)
1421{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001422 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001423
Geoff Langbfdea662014-07-23 14:16:32 -04001424 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001425 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001426 {
Geoff Langb1196682014-07-23 13:47:29 -04001427 if (index >= gl::MAX_VERTEX_ATTRIBS)
1428 {
1429 context->recordError(gl::Error(GL_INVALID_VALUE));
1430 return;
1431 }
1432
Geoff Langbfdea662014-07-23 14:16:32 -04001433 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001434 }
1435}
1436
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001437void __stdcall glEndQueryEXT(GLenum target)
1438{
1439 EVENT("GLenum target = 0x%X)", target);
1440
Geoff Langbfdea662014-07-23 14:16:32 -04001441 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001442 if (context)
1443 {
1444 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001445 {
Geoff Langbfdea662014-07-23 14:16:32 -04001446 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001447 }
Geoff Langbfdea662014-07-23 14:16:32 -04001448
1449 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001450 }
1451}
1452
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001453void __stdcall glFinishFenceNV(GLuint fence)
1454{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001455 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001456
Geoff Langbfdea662014-07-23 14:16:32 -04001457 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001458 if (context)
1459 {
1460 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1461
1462 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001463 {
Geoff Langb1196682014-07-23 13:47:29 -04001464 context->recordError(gl::Error(GL_INVALID_OPERATION));
1465 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001466 }
Geoff Langbfdea662014-07-23 14:16:32 -04001467
1468 if (fenceObject->isFence() != GL_TRUE)
1469 {
Geoff Langb1196682014-07-23 13:47:29 -04001470 context->recordError(gl::Error(GL_INVALID_OPERATION));
1471 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001472 }
1473
1474 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001475 }
1476}
1477
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001478void __stdcall glFinish(void)
1479{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001480 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001481
Geoff Langbfdea662014-07-23 14:16:32 -04001482 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001483 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001484 {
Geoff Langbfdea662014-07-23 14:16:32 -04001485 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001486 }
1487}
1488
1489void __stdcall glFlush(void)
1490{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001491 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001492
Geoff Langbfdea662014-07-23 14:16:32 -04001493 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001494 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001495 {
Geoff Langbfdea662014-07-23 14:16:32 -04001496 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001497 }
1498}
1499
1500void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1501{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001502 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001503 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001504
Geoff Langbfdea662014-07-23 14:16:32 -04001505 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001506 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001507 {
Geoff Langb1196682014-07-23 13:47:29 -04001508 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1509 {
1510 context->recordError(gl::Error(GL_INVALID_ENUM));
1511 return;
1512 }
1513
Geoff Langbfdea662014-07-23 14:16:32 -04001514 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1515 {
1516 return;
1517 }
1518
1519 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1520 ASSERT(framebuffer);
1521
1522 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1523 {
1524 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1525 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1526 }
1527 else
1528 {
1529 switch (attachment)
1530 {
1531 case GL_DEPTH_ATTACHMENT:
1532 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1533 break;
1534 case GL_STENCIL_ATTACHMENT:
1535 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1536 break;
1537 case GL_DEPTH_STENCIL_ATTACHMENT:
1538 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1539 break;
1540 default:
1541 UNREACHABLE();
1542 break;
1543 }
1544 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001545 }
1546}
1547
1548void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1549{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001550 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001551 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001552
Geoff Langbfdea662014-07-23 14:16:32 -04001553 gl::Context *context = gl::getNonLostContext();
1554 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001555 {
Geoff Langbfdea662014-07-23 14:16:32 -04001556 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001557 {
Geoff Langbfdea662014-07-23 14:16:32 -04001558 return;
1559 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001560
Geoff Langbfdea662014-07-23 14:16:32 -04001561 if (texture == 0)
1562 {
1563 textarget = GL_NONE;
1564 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001565
Geoff Langbfdea662014-07-23 14:16:32 -04001566 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001567
Geoff Langbfdea662014-07-23 14:16:32 -04001568 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1569 {
1570 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1571 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1572 }
1573 else
1574 {
1575 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001576 {
Geoff Langbfdea662014-07-23 14:16:32 -04001577 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1578 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1579 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001580 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001581 }
1582 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001583}
1584
1585void __stdcall glFrontFace(GLenum mode)
1586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001587 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001588
Geoff Langb1196682014-07-23 13:47:29 -04001589 gl::Context *context = gl::getNonLostContext();
1590 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001591 {
Geoff Langb1196682014-07-23 13:47:29 -04001592 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001593 {
Geoff Langb1196682014-07-23 13:47:29 -04001594 case GL_CW:
1595 case GL_CCW:
1596 context->getState().setFrontFace(mode);
1597 break;
1598 default:
1599 context->recordError(gl::Error(GL_INVALID_ENUM));
1600 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001601 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001602 }
1603}
1604
1605void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1606{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001607 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001608
Geoff Langbfdea662014-07-23 14:16:32 -04001609 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001610 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001611 {
Geoff Langb1196682014-07-23 13:47:29 -04001612 if (n < 0)
1613 {
1614 context->recordError(gl::Error(GL_INVALID_VALUE));
1615 return;
1616 }
1617
Geoff Langbfdea662014-07-23 14:16:32 -04001618 for (int i = 0; i < n; i++)
1619 {
1620 buffers[i] = context->createBuffer();
1621 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001622 }
1623}
1624
1625void __stdcall glGenerateMipmap(GLenum target)
1626{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001627 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001628
Geoff Langbfdea662014-07-23 14:16:32 -04001629 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001630 if (context)
1631 {
1632 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001633 {
Geoff Langb1196682014-07-23 13:47:29 -04001634 context->recordError(gl::Error(GL_INVALID_ENUM));
1635 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001636 }
Geoff Langbfdea662014-07-23 14:16:32 -04001637
1638 gl::Texture *texture = context->getTargetTexture(target);
1639
1640 if (texture == NULL)
1641 {
Geoff Langb1196682014-07-23 13:47:29 -04001642 context->recordError(gl::Error(GL_INVALID_OPERATION));
1643 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001644 }
1645
1646 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1647 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001648 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001649
1650 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1651 // unsized formats or that are color renderable and filterable. Since we do not track if
1652 // the texture was created with sized or unsized format (only sized formats are stored),
1653 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1654 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1655 // textures since they're the only texture format that can be created with unsized formats
1656 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1657 // was the last version to use add them.
1658 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1659 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1660 internalFormat == GL_ALPHA8_EXT;
1661
Geoff Lang5d601382014-07-22 15:14:06 -04001662 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1663 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001664 {
Geoff Langb1196682014-07-23 13:47:29 -04001665 context->recordError(gl::Error(GL_INVALID_OPERATION));
1666 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001667 }
1668
1669 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001670 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001671 {
Geoff Langb1196682014-07-23 13:47:29 -04001672 context->recordError(gl::Error(GL_INVALID_OPERATION));
1673 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001674 }
1675
1676 // Non-power of 2 ES2 check
1677 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1678 {
1679 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001680 context->recordError(gl::Error(GL_INVALID_OPERATION));
1681 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001682 }
1683
1684 // Cube completeness check
1685 if (target == GL_TEXTURE_CUBE_MAP)
1686 {
1687 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1688 if (!textureCube->isCubeComplete())
1689 {
Geoff Langb1196682014-07-23 13:47:29 -04001690 context->recordError(gl::Error(GL_INVALID_OPERATION));
1691 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001692 }
1693 }
1694
1695 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001696 }
1697}
1698
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001699void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1700{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001701 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001702
Geoff Langbfdea662014-07-23 14:16:32 -04001703 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001704 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001705 {
Geoff Langb1196682014-07-23 13:47:29 -04001706 if (n < 0)
1707 {
1708 context->recordError(gl::Error(GL_INVALID_VALUE));
1709 return;
1710 }
1711
Geoff Langbfdea662014-07-23 14:16:32 -04001712 for (int i = 0; i < n; i++)
1713 {
1714 fences[i] = context->createFenceNV();
1715 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001716 }
1717}
1718
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001719void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1720{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001721 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001722
Geoff Langbfdea662014-07-23 14:16:32 -04001723 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001724 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001725 {
Geoff Langb1196682014-07-23 13:47:29 -04001726 if (n < 0)
1727 {
1728 context->recordError(gl::Error(GL_INVALID_VALUE));
1729 return;
1730 }
1731
Geoff Langbfdea662014-07-23 14:16:32 -04001732 for (int i = 0; i < n; i++)
1733 {
1734 framebuffers[i] = context->createFramebuffer();
1735 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001736 }
1737}
1738
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001739void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1740{
1741 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1742
Geoff Langbfdea662014-07-23 14:16:32 -04001743 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001744 if (context)
1745 {
1746 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001747 {
Geoff Langb1196682014-07-23 13:47:29 -04001748 context->recordError(gl::Error(GL_INVALID_VALUE));
1749 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001750 }
Geoff Langbfdea662014-07-23 14:16:32 -04001751
1752 for (GLsizei i = 0; i < n; i++)
1753 {
1754 ids[i] = context->createQuery();
1755 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001756 }
1757}
1758
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001759void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1760{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001761 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001762
Geoff Langbfdea662014-07-23 14:16:32 -04001763 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001764 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001765 {
Geoff Langb1196682014-07-23 13:47:29 -04001766 if (n < 0)
1767 {
1768 context->recordError(gl::Error(GL_INVALID_VALUE));
1769 return;
1770 }
1771
Geoff Langbfdea662014-07-23 14:16:32 -04001772 for (int i = 0; i < n; i++)
1773 {
1774 renderbuffers[i] = context->createRenderbuffer();
1775 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001776 }
1777}
1778
1779void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1780{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001781 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001782
Geoff Langbfdea662014-07-23 14:16:32 -04001783 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001784 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001785 {
Geoff Langb1196682014-07-23 13:47:29 -04001786 if (n < 0)
1787 {
1788 context->recordError(gl::Error(GL_INVALID_VALUE));
1789 return;
1790 }
1791
Geoff Langbfdea662014-07-23 14:16:32 -04001792 for (int i = 0; i < n; i++)
1793 {
1794 textures[i] = context->createTexture();
1795 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001796 }
1797}
1798
daniel@transgaming.com85423182010-04-22 13:35:27 +00001799void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001800{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001801 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001802 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001803 program, index, bufsize, length, size, type, name);
1804
Geoff Langbfdea662014-07-23 14:16:32 -04001805 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001806 if (context)
1807 {
Geoff Langb1196682014-07-23 13:47:29 -04001808 if (bufsize < 0)
1809 {
1810 context->recordError(gl::Error(GL_INVALID_VALUE));
1811 return;
1812 }
1813
Geoff Langbfdea662014-07-23 14:16:32 -04001814 gl::Program *programObject = context->getProgram(program);
1815
1816 if (!programObject)
1817 {
1818 if (context->getShader(program))
1819 {
Geoff Langb1196682014-07-23 13:47:29 -04001820 context->recordError(gl::Error(GL_INVALID_OPERATION));
1821 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001822 }
1823 else
1824 {
Geoff Langb1196682014-07-23 13:47:29 -04001825 context->recordError(gl::Error(GL_INVALID_VALUE));
1826 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001827 }
1828 }
1829
1830 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001831 {
Geoff Langb1196682014-07-23 13:47:29 -04001832 context->recordError(gl::Error(GL_INVALID_VALUE));
1833 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001834 }
1835
Geoff Langbfdea662014-07-23 14:16:32 -04001836 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001837 }
1838}
1839
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001840void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001841{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001842 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001843 "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 +00001844 program, index, bufsize, length, size, type, name);
1845
Geoff Langbfdea662014-07-23 14:16:32 -04001846
1847 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001848 if (context)
1849 {
Geoff Langb1196682014-07-23 13:47:29 -04001850 if (bufsize < 0)
1851 {
1852 context->recordError(gl::Error(GL_INVALID_VALUE));
1853 return;
1854 }
1855
Geoff Langbfdea662014-07-23 14:16:32 -04001856 gl::Program *programObject = context->getProgram(program);
1857
1858 if (!programObject)
1859 {
1860 if (context->getShader(program))
1861 {
Geoff Langb1196682014-07-23 13:47:29 -04001862 context->recordError(gl::Error(GL_INVALID_OPERATION));
1863 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001864 }
1865 else
1866 {
Geoff Langb1196682014-07-23 13:47:29 -04001867 context->recordError(gl::Error(GL_INVALID_VALUE));
1868 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001869 }
1870 }
1871
1872 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001873 {
Geoff Langb1196682014-07-23 13:47:29 -04001874 context->recordError(gl::Error(GL_INVALID_VALUE));
1875 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001876 }
1877
Geoff Langbfdea662014-07-23 14:16:32 -04001878 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001879 }
1880}
1881
1882void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1883{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001884 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 +00001885 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001886
Geoff Langbfdea662014-07-23 14:16:32 -04001887 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001888 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001889 {
Geoff Langb1196682014-07-23 13:47:29 -04001890 if (maxcount < 0)
1891 {
1892 context->recordError(gl::Error(GL_INVALID_VALUE));
1893 return;
1894 }
1895
Geoff Langbfdea662014-07-23 14:16:32 -04001896 gl::Program *programObject = context->getProgram(program);
1897
1898 if (!programObject)
1899 {
1900 if (context->getShader(program))
1901 {
Geoff Langb1196682014-07-23 13:47:29 -04001902 context->recordError(gl::Error(GL_INVALID_OPERATION));
1903 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001904 }
1905 else
1906 {
Geoff Langb1196682014-07-23 13:47:29 -04001907 context->recordError(gl::Error(GL_INVALID_VALUE));
1908 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001909 }
1910 }
1911
1912 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001913 }
1914}
1915
Geoff Langb1196682014-07-23 13:47:29 -04001916GLint __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001918 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001919
Geoff Langbfdea662014-07-23 14:16:32 -04001920 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001921 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001922 {
Geoff Langbfdea662014-07-23 14:16:32 -04001923 gl::Program *programObject = context->getProgram(program);
1924
1925 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001926 {
Geoff Langbfdea662014-07-23 14:16:32 -04001927 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001928 {
Geoff Langb1196682014-07-23 13:47:29 -04001929 context->recordError(gl::Error(GL_INVALID_OPERATION));
1930 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001931 }
Geoff Langbfdea662014-07-23 14:16:32 -04001932 else
1933 {
Geoff Langb1196682014-07-23 13:47:29 -04001934 context->recordError(gl::Error(GL_INVALID_VALUE));
1935 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001936 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001937 }
Geoff Langbfdea662014-07-23 14:16:32 -04001938
1939 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1940 if (!programObject->isLinked() || !programBinary)
1941 {
Geoff Langb1196682014-07-23 13:47:29 -04001942 context->recordError(gl::Error(GL_INVALID_OPERATION));
1943 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001944 }
1945
1946 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001947 }
1948
1949 return -1;
1950}
1951
1952void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1953{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001954 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001955
Geoff Langbfdea662014-07-23 14:16:32 -04001956 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001957 if (context)
1958 {
1959 GLenum nativeType;
1960 unsigned int numParams = 0;
1961 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001962 {
Geoff Langbfdea662014-07-23 14:16:32 -04001963 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001964 }
Geoff Langbfdea662014-07-23 14:16:32 -04001965
1966 if (nativeType == GL_BOOL)
1967 {
1968 context->getBooleanv(pname, params);
1969 }
1970 else
1971 {
1972 CastStateValues(context, nativeType, pname, numParams, params);
1973 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001974 }
1975}
1976
1977void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1978{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001979 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 +00001980
Geoff Langbfdea662014-07-23 14:16:32 -04001981 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001982 if (context)
1983 {
1984 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001985 {
Geoff Langb1196682014-07-23 13:47:29 -04001986 context->recordError(gl::Error(GL_INVALID_ENUM));
1987 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001988 }
Geoff Langbfdea662014-07-23 14:16:32 -04001989
1990 if (!gl::ValidBufferParameter(context, pname))
1991 {
Geoff Langb1196682014-07-23 13:47:29 -04001992 context->recordError(gl::Error(GL_INVALID_ENUM));
1993 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001994 }
1995
1996 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
1997
1998 if (!buffer)
1999 {
2000 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04002001 context->recordError(gl::Error(GL_INVALID_OPERATION));
2002 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002003 }
2004
2005 switch (pname)
2006 {
2007 case GL_BUFFER_USAGE:
2008 *params = static_cast<GLint>(buffer->getUsage());
2009 break;
2010 case GL_BUFFER_SIZE:
2011 *params = gl::clampCast<GLint>(buffer->getSize());
2012 break;
2013 case GL_BUFFER_ACCESS_FLAGS:
2014 *params = buffer->getAccessFlags();
2015 break;
2016 case GL_BUFFER_MAPPED:
2017 *params = static_cast<GLint>(buffer->isMapped());
2018 break;
2019 case GL_BUFFER_MAP_OFFSET:
2020 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2021 break;
2022 case GL_BUFFER_MAP_LENGTH:
2023 *params = gl::clampCast<GLint>(buffer->getMapLength());
2024 break;
2025 default: UNREACHABLE(); break;
2026 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002027 }
2028}
2029
2030GLenum __stdcall glGetError(void)
2031{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002032 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002033
2034 gl::Context *context = gl::getContext();
2035
2036 if (context)
2037 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002038 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002039 }
2040
2041 return GL_NO_ERROR;
2042}
2043
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002044void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
2045{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002046 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002047
Geoff Langbfdea662014-07-23 14:16:32 -04002048 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002049 if (context)
2050 {
2051 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2052
2053 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002054 {
Geoff Langb1196682014-07-23 13:47:29 -04002055 context->recordError(gl::Error(GL_INVALID_OPERATION));
2056 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002057 }
Geoff Langbfdea662014-07-23 14:16:32 -04002058
2059 if (fenceObject->isFence() != GL_TRUE)
2060 {
Geoff Langb1196682014-07-23 13:47:29 -04002061 context->recordError(gl::Error(GL_INVALID_OPERATION));
2062 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002063 }
2064
2065 switch (pname)
2066 {
2067 case GL_FENCE_STATUS_NV:
2068 case GL_FENCE_CONDITION_NV:
2069 break;
2070
Geoff Langb1196682014-07-23 13:47:29 -04002071 default:
2072 context->recordError(gl::Error(GL_INVALID_ENUM));
2073 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002074 }
2075
2076 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002077 }
2078}
2079
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002080void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2081{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002082 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002083
Geoff Langbfdea662014-07-23 14:16:32 -04002084 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002085 if (context)
2086 {
2087 GLenum nativeType;
2088 unsigned int numParams = 0;
2089 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002090 {
Geoff Langbfdea662014-07-23 14:16:32 -04002091 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002092 }
Geoff Langbfdea662014-07-23 14:16:32 -04002093
2094 if (nativeType == GL_FLOAT)
2095 {
2096 context->getFloatv(pname, params);
2097 }
2098 else
2099 {
2100 CastStateValues(context, nativeType, pname, numParams, params);
2101 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002102 }
2103}
2104
2105void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2106{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002107 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 +00002108 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002109
Geoff Langbfdea662014-07-23 14:16:32 -04002110 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002111 if (context)
2112 {
2113 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002114 {
Geoff Langb1196682014-07-23 13:47:29 -04002115 context->recordError(gl::Error(GL_INVALID_ENUM));
2116 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002117 }
2118
2119 int clientVersion = context->getClientVersion();
2120
2121 switch (pname)
2122 {
2123 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2124 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2125 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2126 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2127 break;
Geoff Langb1196682014-07-23 13:47:29 -04002128
Geoff Langbfdea662014-07-23 14:16:32 -04002129 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2130 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002131 {
Geoff Langb1196682014-07-23 13:47:29 -04002132 context->recordError(gl::Error(GL_INVALID_ENUM));
2133 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002134 }
Geoff Langbfdea662014-07-23 14:16:32 -04002135 break;
Geoff Langb1196682014-07-23 13:47:29 -04002136
Geoff Langbfdea662014-07-23 14:16:32 -04002137 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2138 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2139 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2140 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2141 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2142 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2143 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2144 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2145 if (clientVersion < 3)
2146 {
Geoff Langb1196682014-07-23 13:47:29 -04002147 context->recordError(gl::Error(GL_INVALID_ENUM));
2148 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002149 }
2150 break;
Geoff Langb1196682014-07-23 13:47:29 -04002151
Geoff Langbfdea662014-07-23 14:16:32 -04002152 default:
Geoff Langb1196682014-07-23 13:47:29 -04002153 context->recordError(gl::Error(GL_INVALID_ENUM));
2154 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002155 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002156
Geoff Langbfdea662014-07-23 14:16:32 -04002157 // Determine if the attachment is a valid enum
2158 switch (attachment)
2159 {
2160 case GL_BACK:
2161 case GL_FRONT:
2162 case GL_DEPTH:
2163 case GL_STENCIL:
2164 case GL_DEPTH_STENCIL_ATTACHMENT:
2165 if (clientVersion < 3)
2166 {
Geoff Langb1196682014-07-23 13:47:29 -04002167 context->recordError(gl::Error(GL_INVALID_ENUM));
2168 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002169 }
2170 break;
2171
2172 case GL_DEPTH_ATTACHMENT:
2173 case GL_STENCIL_ATTACHMENT:
2174 break;
2175
2176 default:
2177 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2178 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2179 {
Geoff Langb1196682014-07-23 13:47:29 -04002180 context->recordError(gl::Error(GL_INVALID_ENUM));
2181 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002182 }
2183 break;
2184 }
2185
2186 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2187 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2188
2189 if (framebufferHandle == 0)
2190 {
2191 if (clientVersion < 3)
2192 {
Geoff Langb1196682014-07-23 13:47:29 -04002193 context->recordError(gl::Error(GL_INVALID_OPERATION));
2194 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002195 }
2196
2197 switch (attachment)
2198 {
2199 case GL_BACK:
2200 case GL_DEPTH:
2201 case GL_STENCIL:
2202 break;
Geoff Langb1196682014-07-23 13:47:29 -04002203
Geoff Langbfdea662014-07-23 14:16:32 -04002204 default:
Geoff Langb1196682014-07-23 13:47:29 -04002205 context->recordError(gl::Error(GL_INVALID_OPERATION));
2206 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002207 }
2208 }
2209 else
2210 {
2211 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2212 {
2213 // Valid attachment query
2214 }
2215 else
2216 {
2217 switch (attachment)
2218 {
2219 case GL_DEPTH_ATTACHMENT:
2220 case GL_STENCIL_ATTACHMENT:
2221 break;
Geoff Langb1196682014-07-23 13:47:29 -04002222
Geoff Langbfdea662014-07-23 14:16:32 -04002223 case GL_DEPTH_STENCIL_ATTACHMENT:
2224 if (framebuffer->hasValidDepthStencil())
2225 {
Geoff Langb1196682014-07-23 13:47:29 -04002226 context->recordError(gl::Error(GL_INVALID_OPERATION));
2227 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002228 }
2229 break;
Geoff Langb1196682014-07-23 13:47:29 -04002230
Geoff Langbfdea662014-07-23 14:16:32 -04002231 default:
Geoff Langb1196682014-07-23 13:47:29 -04002232 context->recordError(gl::Error(GL_INVALID_OPERATION));
2233 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002234 }
2235 }
2236 }
2237
2238 GLenum attachmentType = GL_NONE;
2239 GLuint attachmentHandle = 0;
2240 GLuint attachmentLevel = 0;
2241 GLuint attachmentLayer = 0;
2242
2243 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2244
2245 if (attachmentObject)
2246 {
2247 attachmentType = attachmentObject->type();
2248 attachmentHandle = attachmentObject->id();
2249 attachmentLevel = attachmentObject->mipLevel();
2250 attachmentLayer = attachmentObject->layer();
2251 }
2252
2253 GLenum attachmentObjectType; // Type category
2254 if (framebufferHandle == 0)
2255 {
2256 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2257 }
2258 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2259 {
2260 attachmentObjectType = attachmentType;
2261 }
2262 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2263 {
2264 attachmentObjectType = GL_TEXTURE;
2265 }
2266 else
2267 {
2268 UNREACHABLE();
2269 return;
2270 }
2271
2272 if (attachmentObjectType == GL_NONE)
2273 {
2274 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2275 // is NONE, then querying any other pname will generate INVALID_ENUM.
2276
2277 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2278 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2279 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002280
Geoff Lang646559f2013-08-15 11:08:15 -04002281 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002282 {
Geoff Lang646559f2013-08-15 11:08:15 -04002283 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002284 *params = attachmentObjectType;
2285 break;
2286
Geoff Lang646559f2013-08-15 11:08:15 -04002287 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002288 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002289 {
Geoff Langb1196682014-07-23 13:47:29 -04002290 context->recordError(gl::Error(GL_INVALID_ENUM));
2291 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002292 }
Geoff Langbfdea662014-07-23 14:16:32 -04002293 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002294 break;
2295
2296 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002297 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002298 {
Geoff Langb1196682014-07-23 13:47:29 -04002299 context->recordError(gl::Error(GL_INVALID_ENUM));
2300 return;
Geoff Lang646559f2013-08-15 11:08:15 -04002301 }
2302 else
2303 {
Geoff Langb1196682014-07-23 13:47:29 -04002304 context->recordError(gl::Error(GL_INVALID_OPERATION));
2305 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002306 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002307 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002308 }
Geoff Langbfdea662014-07-23 14:16:32 -04002309 else
2310 {
2311 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2312 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2313 ASSERT(attachmentObject != NULL);
2314
2315 switch (pname)
2316 {
2317 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2318 *params = attachmentObjectType;
2319 break;
2320
2321 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2322 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2323 {
Geoff Langb1196682014-07-23 13:47:29 -04002324 context->recordError(gl::Error(GL_INVALID_ENUM));
2325 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002326 }
2327 *params = attachmentHandle;
2328 break;
2329
2330 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2331 if (attachmentObjectType != GL_TEXTURE)
2332 {
Geoff Langb1196682014-07-23 13:47:29 -04002333 context->recordError(gl::Error(GL_INVALID_ENUM));
2334 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002335 }
2336 *params = attachmentLevel;
2337 break;
2338
2339 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2340 if (attachmentObjectType != GL_TEXTURE)
2341 {
Geoff Langb1196682014-07-23 13:47:29 -04002342 context->recordError(gl::Error(GL_INVALID_ENUM));
2343 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002344 }
2345 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2346 break;
2347
2348 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2349 *params = attachmentObject->getRedSize();
2350 break;
2351
2352 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2353 *params = attachmentObject->getGreenSize();
2354 break;
2355
2356 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2357 *params = attachmentObject->getBlueSize();
2358 break;
2359
2360 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2361 *params = attachmentObject->getAlphaSize();
2362 break;
2363
2364 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2365 *params = attachmentObject->getDepthSize();
2366 break;
2367
2368 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2369 *params = attachmentObject->getStencilSize();
2370 break;
2371
2372 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2373 if (attachment == GL_DEPTH_STENCIL)
2374 {
Geoff Langb1196682014-07-23 13:47:29 -04002375 context->recordError(gl::Error(GL_INVALID_OPERATION));
2376 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002377 }
2378 *params = attachmentObject->getComponentType();
2379 break;
2380
2381 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2382 *params = attachmentObject->getColorEncoding();
2383 break;
2384
2385 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2386 if (attachmentObjectType != GL_TEXTURE)
2387 {
Geoff Langb1196682014-07-23 13:47:29 -04002388 context->recordError(gl::Error(GL_INVALID_ENUM));
2389 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002390 }
2391 *params = attachmentLayer;
2392 break;
2393
2394 default:
2395 UNREACHABLE();
2396 break;
2397 }
2398 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002399 }
2400}
2401
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002402GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2403{
2404 EVENT("()");
2405
Geoff Langbfdea662014-07-23 14:16:32 -04002406 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002407
Geoff Langbfdea662014-07-23 14:16:32 -04002408 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002409 {
Geoff Langbfdea662014-07-23 14:16:32 -04002410 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002411 }
Geoff Langbfdea662014-07-23 14:16:32 -04002412
2413 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002414}
2415
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002416void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2417{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002418 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002419
Geoff Langbfdea662014-07-23 14:16:32 -04002420 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002421 if (context)
2422 {
2423 GLenum nativeType;
2424 unsigned int numParams = 0;
2425
2426 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002427 {
Geoff Langbfdea662014-07-23 14:16:32 -04002428 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002429 }
Geoff Langbfdea662014-07-23 14:16:32 -04002430
2431 if (nativeType == GL_INT)
2432 {
2433 context->getIntegerv(pname, params);
2434 }
2435 else
2436 {
2437 CastStateValues(context, nativeType, pname, numParams, params);
2438 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002439 }
2440}
2441
2442void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2443{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002444 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002445
Geoff Langbfdea662014-07-23 14:16:32 -04002446 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002447 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002448 {
Geoff Langbfdea662014-07-23 14:16:32 -04002449 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002450
Geoff Langbfdea662014-07-23 14:16:32 -04002451 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002452 {
Geoff Langb1196682014-07-23 13:47:29 -04002453 context->recordError(gl::Error(GL_INVALID_VALUE));
2454 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002455 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002456
Geoff Langbfdea662014-07-23 14:16:32 -04002457 if (context->getClientVersion() < 3)
2458 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002459 switch (pname)
2460 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002461 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002462 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002463 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002464 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002465 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002466 context->recordError(gl::Error(GL_INVALID_ENUM));
2467 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002468 }
2469 }
Geoff Langbfdea662014-07-23 14:16:32 -04002470
2471 switch (pname)
2472 {
2473 case GL_DELETE_STATUS:
2474 *params = programObject->isFlaggedForDeletion();
2475 return;
2476 case GL_LINK_STATUS:
2477 *params = programObject->isLinked();
2478 return;
2479 case GL_VALIDATE_STATUS:
2480 *params = programObject->isValidated();
2481 return;
2482 case GL_INFO_LOG_LENGTH:
2483 *params = programObject->getInfoLogLength();
2484 return;
2485 case GL_ATTACHED_SHADERS:
2486 *params = programObject->getAttachedShadersCount();
2487 return;
2488 case GL_ACTIVE_ATTRIBUTES:
2489 *params = programObject->getActiveAttributeCount();
2490 return;
2491 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2492 *params = programObject->getActiveAttributeMaxLength();
2493 return;
2494 case GL_ACTIVE_UNIFORMS:
2495 *params = programObject->getActiveUniformCount();
2496 return;
2497 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2498 *params = programObject->getActiveUniformMaxLength();
2499 return;
2500 case GL_PROGRAM_BINARY_LENGTH_OES:
2501 *params = programObject->getProgramBinaryLength();
2502 return;
2503 case GL_ACTIVE_UNIFORM_BLOCKS:
2504 *params = programObject->getActiveUniformBlockCount();
2505 return;
2506 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2507 *params = programObject->getActiveUniformBlockMaxLength();
2508 break;
2509 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2510 *params = programObject->getTransformFeedbackBufferMode();
2511 break;
2512 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2513 *params = programObject->getTransformFeedbackVaryingCount();
2514 break;
2515 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2516 *params = programObject->getTransformFeedbackVaryingMaxLength();
2517 break;
Geoff Langb1196682014-07-23 13:47:29 -04002518
Geoff Langbfdea662014-07-23 14:16:32 -04002519 default:
Geoff Langb1196682014-07-23 13:47:29 -04002520 context->recordError(gl::Error(GL_INVALID_ENUM));
2521 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002522 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002523 }
2524}
2525
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002526void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002527{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002528 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 +00002529 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002530
Geoff Langbfdea662014-07-23 14:16:32 -04002531 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002532 if (context)
2533 {
Geoff Langb1196682014-07-23 13:47:29 -04002534 if (bufsize < 0)
2535 {
2536 context->recordError(gl::Error(GL_INVALID_VALUE));
2537 return;
2538 }
2539
Geoff Langbfdea662014-07-23 14:16:32 -04002540 gl::Program *programObject = context->getProgram(program);
2541
2542 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002543 {
Geoff Langb1196682014-07-23 13:47:29 -04002544 context->recordError(gl::Error(GL_INVALID_VALUE));
2545 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002546 }
2547
Geoff Langbfdea662014-07-23 14:16:32 -04002548 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002549 }
2550}
2551
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002552void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2553{
2554 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2555
Geoff Langbfdea662014-07-23 14:16:32 -04002556 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002557 if (context)
2558 {
2559 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002560 {
Geoff Langb1196682014-07-23 13:47:29 -04002561 context->recordError(gl::Error(GL_INVALID_ENUM));
2562 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002563 }
Geoff Langbfdea662014-07-23 14:16:32 -04002564
2565 switch (pname)
2566 {
2567 case GL_CURRENT_QUERY_EXT:
2568 params[0] = context->getState().getActiveQueryId(target);
2569 break;
2570
2571 default:
Geoff Langb1196682014-07-23 13:47:29 -04002572 context->recordError(gl::Error(GL_INVALID_ENUM));
2573 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002574 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002575 }
2576}
2577
2578void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2579{
2580 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2581
Geoff Langbfdea662014-07-23 14:16:32 -04002582 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002583 if (context)
2584 {
2585 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2586
2587 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002588 {
Geoff Langb1196682014-07-23 13:47:29 -04002589 context->recordError(gl::Error(GL_INVALID_OPERATION));
2590 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002591 }
Geoff Langbfdea662014-07-23 14:16:32 -04002592
2593 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2594 {
Geoff Langb1196682014-07-23 13:47:29 -04002595 context->recordError(gl::Error(GL_INVALID_OPERATION));
2596 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002597 }
2598
2599 switch(pname)
2600 {
2601 case GL_QUERY_RESULT_EXT:
2602 params[0] = queryObject->getResult();
2603 break;
2604 case GL_QUERY_RESULT_AVAILABLE_EXT:
2605 params[0] = queryObject->isResultAvailable();
2606 break;
2607 default:
Geoff Langb1196682014-07-23 13:47:29 -04002608 context->recordError(gl::Error(GL_INVALID_ENUM));
2609 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002610 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002611 }
2612}
2613
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002614void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2615{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002616 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 +00002617
Geoff Langbfdea662014-07-23 14:16:32 -04002618 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002619 if (context)
2620 {
2621 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002622 {
Geoff Langb1196682014-07-23 13:47:29 -04002623 context->recordError(gl::Error(GL_INVALID_ENUM));
2624 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002625 }
Geoff Langbfdea662014-07-23 14:16:32 -04002626
2627 if (context->getState().getRenderbufferId() == 0)
2628 {
Geoff Langb1196682014-07-23 13:47:29 -04002629 context->recordError(gl::Error(GL_INVALID_OPERATION));
2630 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002631 }
2632
2633 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2634
2635 switch (pname)
2636 {
2637 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2638 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2639 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2640 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2641 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2642 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2643 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2644 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2645 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002646
Geoff Langbfdea662014-07-23 14:16:32 -04002647 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2648 if (!context->getExtensions().framebufferMultisample)
2649 {
Geoff Langb1196682014-07-23 13:47:29 -04002650 context->recordError(gl::Error(GL_INVALID_ENUM));
2651 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002652 }
2653 *params = renderbuffer->getSamples();
2654 break;
Geoff Langb1196682014-07-23 13:47:29 -04002655
Geoff Langbfdea662014-07-23 14:16:32 -04002656 default:
Geoff Langb1196682014-07-23 13:47:29 -04002657 context->recordError(gl::Error(GL_INVALID_ENUM));
2658 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002659 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002660 }
2661}
2662
2663void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002665 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002666
Geoff Langbfdea662014-07-23 14:16:32 -04002667 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002668 if (context)
2669 {
2670 gl::Shader *shaderObject = context->getShader(shader);
2671
2672 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002673 {
Geoff Langb1196682014-07-23 13:47:29 -04002674 context->recordError(gl::Error(GL_INVALID_VALUE));
2675 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002676 }
Geoff Langbfdea662014-07-23 14:16:32 -04002677
2678 switch (pname)
2679 {
2680 case GL_SHADER_TYPE:
2681 *params = shaderObject->getType();
2682 return;
2683 case GL_DELETE_STATUS:
2684 *params = shaderObject->isFlaggedForDeletion();
2685 return;
2686 case GL_COMPILE_STATUS:
2687 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2688 return;
2689 case GL_INFO_LOG_LENGTH:
2690 *params = shaderObject->getInfoLogLength();
2691 return;
2692 case GL_SHADER_SOURCE_LENGTH:
2693 *params = shaderObject->getSourceLength();
2694 return;
2695 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2696 *params = shaderObject->getTranslatedSourceLength();
2697 return;
Geoff Langb1196682014-07-23 13:47:29 -04002698
Geoff Langbfdea662014-07-23 14:16:32 -04002699 default:
Geoff Langb1196682014-07-23 13:47:29 -04002700 context->recordError(gl::Error(GL_INVALID_ENUM));
2701 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002702 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002703 }
2704}
2705
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002706void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002707{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002708 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 +00002709 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002710
Geoff Langbfdea662014-07-23 14:16:32 -04002711 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002712 if (context)
2713 {
Geoff Langb1196682014-07-23 13:47:29 -04002714 if (bufsize < 0)
2715 {
2716 context->recordError(gl::Error(GL_INVALID_VALUE));
2717 return;
2718 }
2719
Geoff Langbfdea662014-07-23 14:16:32 -04002720 gl::Shader *shaderObject = context->getShader(shader);
2721
2722 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002723 {
Geoff Langb1196682014-07-23 13:47:29 -04002724 context->recordError(gl::Error(GL_INVALID_VALUE));
2725 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726 }
2727
Geoff Langbfdea662014-07-23 14:16:32 -04002728 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002729 }
2730}
2731
2732void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2733{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002734 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 +00002735 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002736
Geoff Langb1196682014-07-23 13:47:29 -04002737 gl::Context *context = gl::getNonLostContext();
2738 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002739 {
Geoff Langb1196682014-07-23 13:47:29 -04002740 switch (shadertype)
2741 {
2742 case GL_VERTEX_SHADER:
2743 case GL_FRAGMENT_SHADER:
2744 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002745
Geoff Langb1196682014-07-23 13:47:29 -04002746 default:
2747 context->recordError(gl::Error(GL_INVALID_ENUM));
2748 return;
2749 }
2750
2751 switch (precisiontype)
2752 {
2753 case GL_LOW_FLOAT:
2754 case GL_MEDIUM_FLOAT:
2755 case GL_HIGH_FLOAT:
2756 // Assume IEEE 754 precision
2757 range[0] = 127;
2758 range[1] = 127;
2759 *precision = 23;
2760 break;
2761
2762 case GL_LOW_INT:
2763 case GL_MEDIUM_INT:
2764 case GL_HIGH_INT:
2765 // Some (most) hardware only supports single-precision floating-point numbers,
2766 // which can accurately represent integers up to +/-16777216
2767 range[0] = 24;
2768 range[1] = 24;
2769 *precision = 0;
2770 break;
2771
2772 default:
2773 context->recordError(gl::Error(GL_INVALID_ENUM));
2774 return;
2775 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002776 }
2777}
2778
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002779void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002780{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002781 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 +00002782 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002783
Geoff Langbfdea662014-07-23 14:16:32 -04002784 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002785 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002786 {
Geoff Langb1196682014-07-23 13:47:29 -04002787 if (bufsize < 0)
2788 {
2789 context->recordError(gl::Error(GL_INVALID_VALUE));
2790 return;
2791 }
2792
Geoff Langbfdea662014-07-23 14:16:32 -04002793 gl::Shader *shaderObject = context->getShader(shader);
2794
2795 if (!shaderObject)
2796 {
Geoff Langb1196682014-07-23 13:47:29 -04002797 context->recordError(gl::Error(GL_INVALID_OPERATION));
2798 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002799 }
2800
2801 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002802 }
2803}
2804
zmo@google.coma574f782011-10-03 21:45:23 +00002805void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2806{
2807 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2808 shader, bufsize, length, source);
2809
Geoff Langbfdea662014-07-23 14:16:32 -04002810 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002811 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002812 {
Geoff Langb1196682014-07-23 13:47:29 -04002813 if (bufsize < 0)
2814 {
2815 context->recordError(gl::Error(GL_INVALID_VALUE));
2816 return;
2817 }
2818
Geoff Langbfdea662014-07-23 14:16:32 -04002819 gl::Shader *shaderObject = context->getShader(shader);
2820
2821 if (!shaderObject)
2822 {
Geoff Langb1196682014-07-23 13:47:29 -04002823 context->recordError(gl::Error(GL_INVALID_OPERATION));
2824 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002825 }
2826
2827 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002828 }
2829}
2830
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002831const GLubyte* __stdcall glGetString(GLenum name)
2832{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002833 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002834
Geoff Langbfdea662014-07-23 14:16:32 -04002835 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002836
Geoff Langbfdea662014-07-23 14:16:32 -04002837 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002838 {
Geoff Langbfdea662014-07-23 14:16:32 -04002839 case GL_VENDOR:
2840 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002841
Geoff Langbfdea662014-07-23 14:16:32 -04002842 case GL_RENDERER:
2843 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002844
Geoff Langbfdea662014-07-23 14:16:32 -04002845 case GL_VERSION:
2846 if (context->getClientVersion() == 2)
2847 {
2848 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2849 }
2850 else
2851 {
2852 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2853 }
Geoff Langb1196682014-07-23 13:47:29 -04002854
Geoff Langbfdea662014-07-23 14:16:32 -04002855 case GL_SHADING_LANGUAGE_VERSION:
2856 if (context->getClientVersion() == 2)
2857 {
2858 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2859 }
2860 else
2861 {
2862 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2863 }
Geoff Langb1196682014-07-23 13:47:29 -04002864
Geoff Langbfdea662014-07-23 14:16:32 -04002865 case GL_EXTENSIONS:
2866 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002867
Geoff Langbfdea662014-07-23 14:16:32 -04002868 default:
Geoff Langb1196682014-07-23 13:47:29 -04002869 if (context)
2870 {
2871 context->recordError(gl::Error(GL_INVALID_ENUM));
2872 }
2873 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002874 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002875}
2876
2877void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2878{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002879 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 +00002880
Geoff Langbfdea662014-07-23 14:16:32 -04002881 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002882 if (context)
2883 {
2884 gl::Texture *texture = context->getTargetTexture(target);
2885
2886 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002887 {
Geoff Langb1196682014-07-23 13:47:29 -04002888 context->recordError(gl::Error(GL_INVALID_ENUM));
2889 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002890 }
Geoff Langbfdea662014-07-23 14:16:32 -04002891
2892 switch (pname)
2893 {
2894 case GL_TEXTURE_MAG_FILTER:
2895 *params = (GLfloat)texture->getSamplerState().magFilter;
2896 break;
2897 case GL_TEXTURE_MIN_FILTER:
2898 *params = (GLfloat)texture->getSamplerState().minFilter;
2899 break;
2900 case GL_TEXTURE_WRAP_S:
2901 *params = (GLfloat)texture->getSamplerState().wrapS;
2902 break;
2903 case GL_TEXTURE_WRAP_T:
2904 *params = (GLfloat)texture->getSamplerState().wrapT;
2905 break;
2906 case GL_TEXTURE_WRAP_R:
2907 if (context->getClientVersion() < 3)
2908 {
Geoff Langb1196682014-07-23 13:47:29 -04002909 context->recordError(gl::Error(GL_INVALID_ENUM));
2910 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002911 }
2912 *params = (GLfloat)texture->getSamplerState().wrapR;
2913 break;
2914 case GL_TEXTURE_IMMUTABLE_FORMAT:
2915 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2916 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2917 break;
2918 case GL_TEXTURE_IMMUTABLE_LEVELS:
2919 if (context->getClientVersion() < 3)
2920 {
Geoff Langb1196682014-07-23 13:47:29 -04002921 context->recordError(gl::Error(GL_INVALID_ENUM));
2922 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002923 }
2924 *params = (GLfloat)texture->immutableLevelCount();
2925 break;
2926 case GL_TEXTURE_USAGE_ANGLE:
2927 *params = (GLfloat)texture->getUsage();
2928 break;
2929 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2930 if (!context->getExtensions().textureFilterAnisotropic)
2931 {
Geoff Langb1196682014-07-23 13:47:29 -04002932 context->recordError(gl::Error(GL_INVALID_ENUM));
2933 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002934 }
2935 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2936 break;
2937 case GL_TEXTURE_SWIZZLE_R:
2938 if (context->getClientVersion() < 3)
2939 {
Geoff Langb1196682014-07-23 13:47:29 -04002940 context->recordError(gl::Error(GL_INVALID_ENUM));
2941 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002942 }
2943 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2944 break;
2945 case GL_TEXTURE_SWIZZLE_G:
2946 if (context->getClientVersion() < 3)
2947 {
Geoff Langb1196682014-07-23 13:47:29 -04002948 context->recordError(gl::Error(GL_INVALID_ENUM));
2949 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002950 }
2951 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2952 break;
2953 case GL_TEXTURE_SWIZZLE_B:
2954 if (context->getClientVersion() < 3)
2955 {
Geoff Langb1196682014-07-23 13:47:29 -04002956 context->recordError(gl::Error(GL_INVALID_ENUM));
2957 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002958 }
2959 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2960 break;
2961 case GL_TEXTURE_SWIZZLE_A:
2962 if (context->getClientVersion() < 3)
2963 {
Geoff Langb1196682014-07-23 13:47:29 -04002964 context->recordError(gl::Error(GL_INVALID_ENUM));
2965 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002966 }
2967 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2968 break;
2969 case GL_TEXTURE_BASE_LEVEL:
2970 if (context->getClientVersion() < 3)
2971 {
Geoff Langb1196682014-07-23 13:47:29 -04002972 context->recordError(gl::Error(GL_INVALID_ENUM));
2973 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002974 }
2975 *params = (GLfloat)texture->getSamplerState().baseLevel;
2976 break;
2977 case GL_TEXTURE_MAX_LEVEL:
2978 if (context->getClientVersion() < 3)
2979 {
Geoff Langb1196682014-07-23 13:47:29 -04002980 context->recordError(gl::Error(GL_INVALID_ENUM));
2981 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002982 }
2983 *params = (GLfloat)texture->getSamplerState().maxLevel;
2984 break;
2985 case GL_TEXTURE_MIN_LOD:
2986 if (context->getClientVersion() < 3)
2987 {
Geoff Langb1196682014-07-23 13:47:29 -04002988 context->recordError(gl::Error(GL_INVALID_ENUM));
2989 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002990 }
2991 *params = texture->getSamplerState().minLod;
2992 break;
2993 case GL_TEXTURE_MAX_LOD:
2994 if (context->getClientVersion() < 3)
2995 {
Geoff Langb1196682014-07-23 13:47:29 -04002996 context->recordError(gl::Error(GL_INVALID_ENUM));
2997 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002998 }
2999 *params = texture->getSamplerState().maxLod;
3000 break;
Geoff Langb1196682014-07-23 13:47:29 -04003001
Geoff Langbfdea662014-07-23 14:16:32 -04003002 default:
Geoff Langb1196682014-07-23 13:47:29 -04003003 context->recordError(gl::Error(GL_INVALID_ENUM));
3004 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003005 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003006 }
3007}
3008
3009void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
3010{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003011 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 +00003012
Geoff Langbfdea662014-07-23 14:16:32 -04003013 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003014 if (context)
3015 {
3016 gl::Texture *texture = context->getTargetTexture(target);
3017
3018 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003019 {
Geoff Langb1196682014-07-23 13:47:29 -04003020 context->recordError(gl::Error(GL_INVALID_ENUM));
3021 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003022 }
Geoff Langbfdea662014-07-23 14:16:32 -04003023
3024 switch (pname)
3025 {
3026 case GL_TEXTURE_MAG_FILTER:
3027 *params = texture->getSamplerState().magFilter;
3028 break;
3029 case GL_TEXTURE_MIN_FILTER:
3030 *params = texture->getSamplerState().minFilter;
3031 break;
3032 case GL_TEXTURE_WRAP_S:
3033 *params = texture->getSamplerState().wrapS;
3034 break;
3035 case GL_TEXTURE_WRAP_T:
3036 *params = texture->getSamplerState().wrapT;
3037 break;
3038 case GL_TEXTURE_WRAP_R:
3039 if (context->getClientVersion() < 3)
3040 {
Geoff Langb1196682014-07-23 13:47:29 -04003041 context->recordError(gl::Error(GL_INVALID_ENUM));
3042 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003043 }
3044 *params = texture->getSamplerState().wrapR;
3045 break;
3046 case GL_TEXTURE_IMMUTABLE_FORMAT:
3047 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3048 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3049 break;
3050 case GL_TEXTURE_IMMUTABLE_LEVELS:
3051 if (context->getClientVersion() < 3)
3052 {
Geoff Langb1196682014-07-23 13:47:29 -04003053 context->recordError(gl::Error(GL_INVALID_ENUM));
3054 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003055 }
3056 *params = texture->immutableLevelCount();
3057 break;
3058 case GL_TEXTURE_USAGE_ANGLE:
3059 *params = texture->getUsage();
3060 break;
3061 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3062 if (!context->getExtensions().textureFilterAnisotropic)
3063 {
Geoff Langb1196682014-07-23 13:47:29 -04003064 context->recordError(gl::Error(GL_INVALID_ENUM));
3065 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003066 }
3067 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3068 break;
3069 case GL_TEXTURE_SWIZZLE_R:
3070 if (context->getClientVersion() < 3)
3071 {
Geoff Langb1196682014-07-23 13:47:29 -04003072 context->recordError(gl::Error(GL_INVALID_ENUM));
3073 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003074 }
3075 *params = texture->getSamplerState().swizzleRed;
3076 break;
3077 case GL_TEXTURE_SWIZZLE_G:
3078 if (context->getClientVersion() < 3)
3079 {
Geoff Langb1196682014-07-23 13:47:29 -04003080 context->recordError(gl::Error(GL_INVALID_ENUM));
3081 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003082 }
3083 *params = texture->getSamplerState().swizzleGreen;
3084 break;
3085 case GL_TEXTURE_SWIZZLE_B:
3086 if (context->getClientVersion() < 3)
3087 {
Geoff Langb1196682014-07-23 13:47:29 -04003088 context->recordError(gl::Error(GL_INVALID_ENUM));
3089 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003090 }
3091 *params = texture->getSamplerState().swizzleBlue;
3092 break;
3093 case GL_TEXTURE_SWIZZLE_A:
3094 if (context->getClientVersion() < 3)
3095 {
Geoff Langb1196682014-07-23 13:47:29 -04003096 context->recordError(gl::Error(GL_INVALID_ENUM));
3097 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003098 }
3099 *params = texture->getSamplerState().swizzleAlpha;
3100 break;
3101 case GL_TEXTURE_BASE_LEVEL:
3102 if (context->getClientVersion() < 3)
3103 {
Geoff Langb1196682014-07-23 13:47:29 -04003104 context->recordError(gl::Error(GL_INVALID_ENUM));
3105 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003106 }
3107 *params = texture->getSamplerState().baseLevel;
3108 break;
3109 case GL_TEXTURE_MAX_LEVEL:
3110 if (context->getClientVersion() < 3)
3111 {
Geoff Langb1196682014-07-23 13:47:29 -04003112 context->recordError(gl::Error(GL_INVALID_ENUM));
3113 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003114 }
3115 *params = texture->getSamplerState().maxLevel;
3116 break;
3117 case GL_TEXTURE_MIN_LOD:
3118 if (context->getClientVersion() < 3)
3119 {
Geoff Langb1196682014-07-23 13:47:29 -04003120 context->recordError(gl::Error(GL_INVALID_ENUM));
3121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003122 }
3123 *params = (GLint)texture->getSamplerState().minLod;
3124 break;
3125 case GL_TEXTURE_MAX_LOD:
3126 if (context->getClientVersion() < 3)
3127 {
Geoff Langb1196682014-07-23 13:47:29 -04003128 context->recordError(gl::Error(GL_INVALID_ENUM));
3129 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003130 }
3131 *params = (GLint)texture->getSamplerState().maxLod;
3132 break;
Geoff Langb1196682014-07-23 13:47:29 -04003133
Geoff Langbfdea662014-07-23 14:16:32 -04003134 default:
Geoff Langb1196682014-07-23 13:47:29 -04003135 context->recordError(gl::Error(GL_INVALID_ENUM));
3136 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003137 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003138 }
3139}
3140
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003141void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3142{
3143 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3144 program, location, bufSize, params);
3145
Geoff Langbfdea662014-07-23 14:16:32 -04003146 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003147 if (context)
3148 {
Jamie Madill0063c512014-08-25 15:47:53 -04003149 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003150 {
Jamie Madill0063c512014-08-25 15:47:53 -04003151 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003152 }
3153
Jamie Madilla502c742014-08-28 17:19:13 -04003154 gl::Program *programObject = context->getProgram(program);
3155 ASSERT(programObject);
3156 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003157 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003158
Jamie Madill99a1e982014-08-25 15:47:54 -04003159 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003160 }
3161}
3162
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003163void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3164{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003165 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003166
Geoff Langbfdea662014-07-23 14:16:32 -04003167 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003168 if (context)
3169 {
Jamie Madill0063c512014-08-25 15:47:53 -04003170 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003171 {
Jamie Madill0063c512014-08-25 15:47:53 -04003172 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003173 }
Geoff Langbfdea662014-07-23 14:16:32 -04003174
Jamie Madilla502c742014-08-28 17:19:13 -04003175 gl::Program *programObject = context->getProgram(program);
3176 ASSERT(programObject);
3177 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003178 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003179
Jamie Madill99a1e982014-08-25 15:47:54 -04003180 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003181 }
3182}
3183
3184void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3185{
Geoff Langbfdea662014-07-23 14:16:32 -04003186 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003187 program, location, bufSize, params);
3188
Geoff Langbfdea662014-07-23 14:16:32 -04003189 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003190 if (context)
3191 {
Jamie Madill0063c512014-08-25 15:47:53 -04003192 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003193 {
Jamie Madill0063c512014-08-25 15:47:53 -04003194 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003195 }
3196
Jamie Madilla502c742014-08-28 17:19:13 -04003197 gl::Program *programObject = context->getProgram(program);
3198 ASSERT(programObject);
3199 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003200 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003201
Jamie Madill99a1e982014-08-25 15:47:54 -04003202 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003203 }
3204}
3205
3206void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3207{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003208 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003209
Geoff Langbfdea662014-07-23 14:16:32 -04003210 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003211 if (context)
3212 {
Jamie Madill0063c512014-08-25 15:47:53 -04003213 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003214 {
Jamie Madill0063c512014-08-25 15:47:53 -04003215 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003216 }
Geoff Langbfdea662014-07-23 14:16:32 -04003217
Jamie Madilla502c742014-08-28 17:19:13 -04003218 gl::Program *programObject = context->getProgram(program);
3219 ASSERT(programObject);
3220 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003221 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003222
Jamie Madill99a1e982014-08-25 15:47:54 -04003223 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003224 }
3225}
3226
Geoff Langb1196682014-07-23 13:47:29 -04003227GLint __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003228{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003229 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003230
Geoff Langbfdea662014-07-23 14:16:32 -04003231 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003232 if (context)
3233 {
Geoff Langb1196682014-07-23 13:47:29 -04003234 if (strstr(name, "gl_") == name)
3235 {
3236 return -1;
3237 }
3238
Geoff Langbfdea662014-07-23 14:16:32 -04003239 gl::Program *programObject = context->getProgram(program);
3240
3241 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003242 {
Geoff Langbfdea662014-07-23 14:16:32 -04003243 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003244 {
Geoff Langb1196682014-07-23 13:47:29 -04003245 context->recordError(gl::Error(GL_INVALID_OPERATION));
3246 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003247 }
Geoff Langbfdea662014-07-23 14:16:32 -04003248 else
3249 {
Geoff Langb1196682014-07-23 13:47:29 -04003250 context->recordError(gl::Error(GL_INVALID_VALUE));
3251 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003252 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003253 }
Geoff Langbfdea662014-07-23 14:16:32 -04003254
3255 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3256 if (!programObject->isLinked() || !programBinary)
3257 {
Geoff Langb1196682014-07-23 13:47:29 -04003258 context->recordError(gl::Error(GL_INVALID_OPERATION));
3259 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003260 }
3261
3262 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003263 }
3264
3265 return -1;
3266}
3267
3268void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3269{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003270 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003271
Geoff Langbfdea662014-07-23 14:16:32 -04003272 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003273 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003274 {
Geoff Langbfdea662014-07-23 14:16:32 -04003275 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003276 {
Geoff Langb1196682014-07-23 13:47:29 -04003277 context->recordError(gl::Error(GL_INVALID_VALUE));
3278 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003279 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003280
Geoff Langbfdea662014-07-23 14:16:32 -04003281 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003282 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003283 {
3284 return;
3285 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003286
Geoff Langbfdea662014-07-23 14:16:32 -04003287 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3288 {
3289 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3290 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003291 {
Geoff Langbfdea662014-07-23 14:16:32 -04003292 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003293 }
3294 }
Geoff Langbfdea662014-07-23 14:16:32 -04003295 else
3296 {
3297 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3298 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003299 }
3300}
3301
3302void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3303{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003304 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003305
Geoff Langbfdea662014-07-23 14:16:32 -04003306 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003307 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003308 {
Geoff Langbfdea662014-07-23 14:16:32 -04003309 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003310 {
Geoff Langb1196682014-07-23 13:47:29 -04003311 context->recordError(gl::Error(GL_INVALID_VALUE));
3312 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003313 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003314
Geoff Langbfdea662014-07-23 14:16:32 -04003315 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003316
Geoff Langb1196682014-07-23 13:47:29 -04003317 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003318 {
3319 return;
3320 }
Jamie Madillaff71502013-07-02 11:57:05 -04003321
Geoff Langbfdea662014-07-23 14:16:32 -04003322 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3323 {
3324 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3325 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003326 {
Geoff Langbfdea662014-07-23 14:16:32 -04003327 float currentValue = currentValueData.FloatValues[i];
3328 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003329 }
3330 }
Geoff Langbfdea662014-07-23 14:16:32 -04003331 else
3332 {
3333 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3334 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003335 }
3336}
3337
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003338void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003339{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003340 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003341
Geoff Langbfdea662014-07-23 14:16:32 -04003342 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003343 if (context)
3344 {
3345 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003346 {
Geoff Langb1196682014-07-23 13:47:29 -04003347 context->recordError(gl::Error(GL_INVALID_VALUE));
3348 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003349 }
Geoff Langbfdea662014-07-23 14:16:32 -04003350
3351 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3352 {
Geoff Langb1196682014-07-23 13:47:29 -04003353 context->recordError(gl::Error(GL_INVALID_ENUM));
3354 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003355 }
3356
3357 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003358 }
3359}
3360
3361void __stdcall glHint(GLenum target, GLenum mode)
3362{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003363 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364
Geoff Langbfdea662014-07-23 14:16:32 -04003365 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003366 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003367 {
Geoff Langb1196682014-07-23 13:47:29 -04003368 switch (mode)
3369 {
3370 case GL_FASTEST:
3371 case GL_NICEST:
3372 case GL_DONT_CARE:
3373 break;
3374
3375 default:
3376 context->recordError(gl::Error(GL_INVALID_ENUM));
3377 return;
3378 }
3379
3380 switch (target)
3381 {
3382 case GL_GENERATE_MIPMAP_HINT:
3383 context->getState().setGenerateMipmapHint(mode);
3384 break;
3385
3386 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3387 context->getState().setFragmentShaderDerivativeHint(mode);
3388 break;
3389
3390 default:
3391 context->recordError(gl::Error(GL_INVALID_ENUM));
3392 return;
3393 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003394 }
3395}
3396
3397GLboolean __stdcall glIsBuffer(GLuint buffer)
3398{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003399 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003400
Geoff Langbfdea662014-07-23 14:16:32 -04003401 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003402 if (context && buffer)
3403 {
3404 gl::Buffer *bufferObject = context->getBuffer(buffer);
3405
3406 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003407 {
Geoff Langbfdea662014-07-23 14:16:32 -04003408 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003409 }
3410 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003411
3412 return GL_FALSE;
3413}
3414
3415GLboolean __stdcall glIsEnabled(GLenum cap)
3416{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003417 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418
Geoff Langbfdea662014-07-23 14:16:32 -04003419 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003420 if (context)
3421 {
3422 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003423 {
Geoff Langb1196682014-07-23 13:47:29 -04003424 context->recordError(gl::Error(GL_INVALID_ENUM));
3425 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003426 }
Geoff Langbfdea662014-07-23 14:16:32 -04003427
3428 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003429 }
3430
3431 return false;
3432}
3433
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003434GLboolean __stdcall glIsFenceNV(GLuint fence)
3435{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003436 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003437
Geoff Langbfdea662014-07-23 14:16:32 -04003438 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003439 if (context)
3440 {
3441 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3442
3443 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003444 {
Geoff Langbfdea662014-07-23 14:16:32 -04003445 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003446 }
Geoff Langbfdea662014-07-23 14:16:32 -04003447
3448 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003449 }
3450
3451 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003452}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003453
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003454GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3455{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003456 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003457
Geoff Langbfdea662014-07-23 14:16:32 -04003458 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003459 if (context && framebuffer)
3460 {
3461 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3462
3463 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003464 {
Geoff Langbfdea662014-07-23 14:16:32 -04003465 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466 }
3467 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468
3469 return GL_FALSE;
3470}
3471
3472GLboolean __stdcall glIsProgram(GLuint program)
3473{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003474 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003475
Geoff Langbfdea662014-07-23 14:16:32 -04003476 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003477 if (context && program)
3478 {
3479 gl::Program *programObject = context->getProgram(program);
3480
3481 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003482 {
Geoff Langbfdea662014-07-23 14:16:32 -04003483 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003484 }
3485 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003486
3487 return GL_FALSE;
3488}
3489
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003490GLboolean __stdcall glIsQueryEXT(GLuint id)
3491{
3492 EVENT("(GLuint id = %d)", id);
3493
Geoff Langbfdea662014-07-23 14:16:32 -04003494 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003495 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003496 {
Geoff Langbfdea662014-07-23 14:16:32 -04003497 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003498 }
3499
3500 return GL_FALSE;
3501}
3502
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003503GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3504{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003505 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003506
Geoff Langbfdea662014-07-23 14:16:32 -04003507 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003508 if (context && renderbuffer)
3509 {
3510 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3511
3512 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003513 {
Geoff Langbfdea662014-07-23 14:16:32 -04003514 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003515 }
3516 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003517
3518 return GL_FALSE;
3519}
3520
3521GLboolean __stdcall glIsShader(GLuint shader)
3522{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003523 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003524
Geoff Langbfdea662014-07-23 14:16:32 -04003525 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003526 if (context && shader)
3527 {
3528 gl::Shader *shaderObject = context->getShader(shader);
3529
3530 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003531 {
Geoff Langbfdea662014-07-23 14:16:32 -04003532 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003533 }
3534 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003535
3536 return GL_FALSE;
3537}
3538
3539GLboolean __stdcall glIsTexture(GLuint texture)
3540{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003541 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003542
Geoff Langbfdea662014-07-23 14:16:32 -04003543 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003544 if (context && texture)
3545 {
3546 gl::Texture *textureObject = context->getTexture(texture);
3547
3548 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003549 {
Geoff Langbfdea662014-07-23 14:16:32 -04003550 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003551 }
3552 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003553
3554 return GL_FALSE;
3555}
3556
3557void __stdcall glLineWidth(GLfloat width)
3558{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003559 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003560
Geoff Langbfdea662014-07-23 14:16:32 -04003561 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003562 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003563 {
Geoff Langb1196682014-07-23 13:47:29 -04003564 if (width <= 0.0f)
3565 {
3566 context->recordError(gl::Error(GL_INVALID_VALUE));
3567 return;
3568 }
3569
Geoff Langbfdea662014-07-23 14:16:32 -04003570 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571 }
3572}
3573
3574void __stdcall glLinkProgram(GLuint program)
3575{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003576 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003577
Geoff Langbfdea662014-07-23 14:16:32 -04003578 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003579 if (context)
3580 {
3581 gl::Program *programObject = context->getProgram(program);
3582
3583 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003584 {
Geoff Langbfdea662014-07-23 14:16:32 -04003585 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003586 {
Geoff Langb1196682014-07-23 13:47:29 -04003587 context->recordError(gl::Error(GL_INVALID_OPERATION));
3588 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003589 }
Geoff Langbfdea662014-07-23 14:16:32 -04003590 else
3591 {
Geoff Langb1196682014-07-23 13:47:29 -04003592 context->recordError(gl::Error(GL_INVALID_VALUE));
3593 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003594 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003595 }
Geoff Langbfdea662014-07-23 14:16:32 -04003596
3597 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598 }
3599}
3600
3601void __stdcall glPixelStorei(GLenum pname, GLint param)
3602{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003603 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003604
Geoff Langbfdea662014-07-23 14:16:32 -04003605 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003606 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003607 {
Geoff Langbfdea662014-07-23 14:16:32 -04003608 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003609 {
Geoff Langbfdea662014-07-23 14:16:32 -04003610 case GL_UNPACK_ALIGNMENT:
3611 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003612 {
Geoff Langb1196682014-07-23 13:47:29 -04003613 context->recordError(gl::Error(GL_INVALID_VALUE));
3614 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003615 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003616
Geoff Langbfdea662014-07-23 14:16:32 -04003617 context->getState().setUnpackAlignment(param);
3618 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003619
Geoff Langbfdea662014-07-23 14:16:32 -04003620 case GL_PACK_ALIGNMENT:
3621 if (param != 1 && param != 2 && param != 4 && param != 8)
3622 {
Geoff Langb1196682014-07-23 13:47:29 -04003623 context->recordError(gl::Error(GL_INVALID_VALUE));
3624 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003625 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003626
Geoff Langbfdea662014-07-23 14:16:32 -04003627 context->getState().setPackAlignment(param);
3628 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003629
Geoff Langbfdea662014-07-23 14:16:32 -04003630 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3631 context->getState().setPackReverseRowOrder(param != 0);
3632 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003633
Geoff Langbfdea662014-07-23 14:16:32 -04003634 case GL_UNPACK_IMAGE_HEIGHT:
3635 case GL_UNPACK_SKIP_IMAGES:
3636 case GL_UNPACK_ROW_LENGTH:
3637 case GL_UNPACK_SKIP_ROWS:
3638 case GL_UNPACK_SKIP_PIXELS:
3639 case GL_PACK_ROW_LENGTH:
3640 case GL_PACK_SKIP_ROWS:
3641 case GL_PACK_SKIP_PIXELS:
3642 if (context->getClientVersion() < 3)
3643 {
Geoff Langb1196682014-07-23 13:47:29 -04003644 context->recordError(gl::Error(GL_INVALID_ENUM));
3645 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003646 }
Geoff Langbfdea662014-07-23 14:16:32 -04003647 UNIMPLEMENTED();
3648 break;
3649
3650 default:
Geoff Langb1196682014-07-23 13:47:29 -04003651 context->recordError(gl::Error(GL_INVALID_ENUM));
3652 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003653 }
3654 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003655}
3656
3657void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3658{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003659 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003660
Geoff Langbfdea662014-07-23 14:16:32 -04003661 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003662 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003663 {
Geoff Langbfdea662014-07-23 14:16:32 -04003664 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003665 }
3666}
3667
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003668void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3669 GLenum format, GLenum type, GLsizei bufSize,
3670 GLvoid *data)
3671{
3672 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3673 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3674 x, y, width, height, format, type, bufSize, data);
3675
Geoff Langbfdea662014-07-23 14:16:32 -04003676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003677 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003678 {
Geoff Langb1196682014-07-23 13:47:29 -04003679 if (width < 0 || height < 0 || bufSize < 0)
3680 {
3681 context->recordError(gl::Error(GL_INVALID_VALUE));
3682 return;
3683 }
3684
Geoff Langbfdea662014-07-23 14:16:32 -04003685 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3686 format, type, &bufSize, data))
3687 {
3688 return;
3689 }
3690
3691 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003692 }
3693}
3694
3695void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3696 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003698 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003699 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003700 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003701
Geoff Langbfdea662014-07-23 14:16:32 -04003702 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003703 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003704 {
Geoff Langb1196682014-07-23 13:47:29 -04003705 if (width < 0 || height < 0)
3706 {
3707 context->recordError(gl::Error(GL_INVALID_VALUE));
3708 return;
3709 }
3710
Geoff Langbfdea662014-07-23 14:16:32 -04003711 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3712 format, type, NULL, pixels))
3713 {
3714 return;
3715 }
3716
3717 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003718 }
3719}
3720
3721void __stdcall glReleaseShaderCompiler(void)
3722{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003723 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003724
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003725 gl::Context *context = gl::getNonLostContext();
3726
3727 if (context)
3728 {
3729 context->releaseShaderCompiler();
3730 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003731}
3732
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003733void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003734{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003735 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 +00003736 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003737
Geoff Langbfdea662014-07-23 14:16:32 -04003738 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003739 if (context)
3740 {
3741 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3742 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743 {
Geoff Langbfdea662014-07-23 14:16:32 -04003744 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003745 }
Geoff Langbfdea662014-07-23 14:16:32 -04003746
3747 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003748 }
3749}
3750
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003751void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3752{
3753 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3754}
3755
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003756void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3757{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003758 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003759
Geoff Langbfdea662014-07-23 14:16:32 -04003760 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003761
Geoff Langbfdea662014-07-23 14:16:32 -04003762 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003763 {
Geoff Langbfdea662014-07-23 14:16:32 -04003764 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003765 }
3766}
3767
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003768void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3769{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003770 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003771
Geoff Langbfdea662014-07-23 14:16:32 -04003772 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003773 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003774 {
Geoff Langb1196682014-07-23 13:47:29 -04003775 if (condition != GL_ALL_COMPLETED_NV)
3776 {
3777 context->recordError(gl::Error(GL_INVALID_ENUM));
3778 return;
3779 }
3780
Geoff Langbfdea662014-07-23 14:16:32 -04003781 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3782
3783 if (fenceObject == NULL)
3784 {
Geoff Langb1196682014-07-23 13:47:29 -04003785 context->recordError(gl::Error(GL_INVALID_OPERATION));
3786 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003787 }
3788
3789 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003790 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003791}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003792
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003793void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3794{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003795 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 +00003796
Geoff Langbfdea662014-07-23 14:16:32 -04003797 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003798 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003799 {
Geoff Langb1196682014-07-23 13:47:29 -04003800 if (width < 0 || height < 0)
3801 {
3802 context->recordError(gl::Error(GL_INVALID_VALUE));
3803 return;
3804 }
3805
Geoff Langbfdea662014-07-23 14:16:32 -04003806 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003807 }
3808}
3809
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003810void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003811{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003812 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003813 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003814 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003815
Geoff Lang900013c2014-07-07 11:32:19 -04003816 gl::Context* context = gl::getNonLostContext();
3817 if (context)
3818 {
3819 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3820 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3821 {
Geoff Langb1196682014-07-23 13:47:29 -04003822 context->recordError(gl::Error(GL_INVALID_ENUM));
3823 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003824 }
3825
3826 // No binary shader formats are supported.
3827 UNIMPLEMENTED();
3828 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003829}
3830
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003831void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003832{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003833 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 +00003834 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003835
Geoff Langbfdea662014-07-23 14:16:32 -04003836 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003837 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838 {
Geoff Langb1196682014-07-23 13:47:29 -04003839 if (count < 0)
3840 {
3841 context->recordError(gl::Error(GL_INVALID_VALUE));
3842 return;
3843 }
3844
Geoff Langbfdea662014-07-23 14:16:32 -04003845 gl::Shader *shaderObject = context->getShader(shader);
3846
3847 if (!shaderObject)
3848 {
3849 if (context->getProgram(shader))
3850 {
Geoff Langb1196682014-07-23 13:47:29 -04003851 context->recordError(gl::Error(GL_INVALID_OPERATION));
3852 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003853 }
3854 else
3855 {
Geoff Langb1196682014-07-23 13:47:29 -04003856 context->recordError(gl::Error(GL_INVALID_VALUE));
3857 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003858 }
3859 }
3860
3861 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003862 }
3863}
3864
3865void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3866{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003867 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003868}
3869
3870void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3871{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003872 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 +00003873
Geoff Langbfdea662014-07-23 14:16:32 -04003874 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003875 if (context)
3876 {
Geoff Langb1196682014-07-23 13:47:29 -04003877 switch (face)
3878 {
3879 case GL_FRONT:
3880 case GL_BACK:
3881 case GL_FRONT_AND_BACK:
3882 break;
3883
3884 default:
3885 context->recordError(gl::Error(GL_INVALID_ENUM));
3886 return;
3887 }
3888
3889 switch (func)
3890 {
3891 case GL_NEVER:
3892 case GL_ALWAYS:
3893 case GL_LESS:
3894 case GL_LEQUAL:
3895 case GL_EQUAL:
3896 case GL_GEQUAL:
3897 case GL_GREATER:
3898 case GL_NOTEQUAL:
3899 break;
3900
3901 default:
3902 context->recordError(gl::Error(GL_INVALID_ENUM));
3903 return;
3904 }
3905
Geoff Langbfdea662014-07-23 14:16:32 -04003906 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3907 {
3908 context->getState().setStencilParams(func, ref, mask);
3909 }
3910
3911 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3912 {
3913 context->getState().setStencilBackParams(func, ref, mask);
3914 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003915 }
3916}
3917
3918void __stdcall glStencilMask(GLuint mask)
3919{
3920 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3921}
3922
3923void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003925 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003926
Geoff Langbfdea662014-07-23 14:16:32 -04003927 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003928 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003929 {
Geoff Langb1196682014-07-23 13:47:29 -04003930 switch (face)
3931 {
3932 case GL_FRONT:
3933 case GL_BACK:
3934 case GL_FRONT_AND_BACK:
3935 break;
3936
3937 default:
3938 context->recordError(gl::Error(GL_INVALID_ENUM));
3939 return;
3940 }
3941
Geoff Langbfdea662014-07-23 14:16:32 -04003942 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3943 {
3944 context->getState().setStencilWritemask(mask);
3945 }
3946
3947 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3948 {
3949 context->getState().setStencilBackWritemask(mask);
3950 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003951 }
3952}
3953
3954void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3955{
3956 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3957}
3958
3959void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3960{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003961 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 +00003962 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003963
Geoff Langbfdea662014-07-23 14:16:32 -04003964 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003965 if (context)
3966 {
Geoff Langb1196682014-07-23 13:47:29 -04003967 switch (face)
3968 {
3969 case GL_FRONT:
3970 case GL_BACK:
3971 case GL_FRONT_AND_BACK:
3972 break;
3973
3974 default:
3975 context->recordError(gl::Error(GL_INVALID_ENUM));
3976 return;
3977 }
3978
3979 switch (fail)
3980 {
3981 case GL_ZERO:
3982 case GL_KEEP:
3983 case GL_REPLACE:
3984 case GL_INCR:
3985 case GL_DECR:
3986 case GL_INVERT:
3987 case GL_INCR_WRAP:
3988 case GL_DECR_WRAP:
3989 break;
3990
3991 default:
3992 context->recordError(gl::Error(GL_INVALID_ENUM));
3993 return;
3994 }
3995
3996 switch (zfail)
3997 {
3998 case GL_ZERO:
3999 case GL_KEEP:
4000 case GL_REPLACE:
4001 case GL_INCR:
4002 case GL_DECR:
4003 case GL_INVERT:
4004 case GL_INCR_WRAP:
4005 case GL_DECR_WRAP:
4006 break;
4007
4008 default:
4009 context->recordError(gl::Error(GL_INVALID_ENUM));
4010 return;
4011 }
4012
4013 switch (zpass)
4014 {
4015 case GL_ZERO:
4016 case GL_KEEP:
4017 case GL_REPLACE:
4018 case GL_INCR:
4019 case GL_DECR:
4020 case GL_INVERT:
4021 case GL_INCR_WRAP:
4022 case GL_DECR_WRAP:
4023 break;
4024
4025 default:
4026 context->recordError(gl::Error(GL_INVALID_ENUM));
4027 return;
4028 }
4029
Geoff Langbfdea662014-07-23 14:16:32 -04004030 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4031 {
4032 context->getState().setStencilOperations(fail, zfail, zpass);
4033 }
4034
4035 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4036 {
4037 context->getState().setStencilBackOperations(fail, zfail, zpass);
4038 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004039 }
4040}
4041
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004042GLboolean __stdcall glTestFenceNV(GLuint fence)
4043{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004044 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004045
Geoff Langbfdea662014-07-23 14:16:32 -04004046 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004047 if (context)
4048 {
4049 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4050
4051 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004052 {
Geoff Langb1196682014-07-23 13:47:29 -04004053 context->recordError(gl::Error(GL_INVALID_OPERATION));
4054 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004055 }
Geoff Langbfdea662014-07-23 14:16:32 -04004056
4057 if (fenceObject->isFence() != GL_TRUE)
4058 {
Geoff Langb1196682014-07-23 13:47:29 -04004059 context->recordError(gl::Error(GL_INVALID_OPERATION));
4060 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004061 }
4062
4063 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004064 }
Geoff Langbfdea662014-07-23 14:16:32 -04004065
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004066 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004067}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004068
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004069void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4070 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004071{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004072 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004073 "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 +00004074 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004075
Geoff Langbfdea662014-07-23 14:16:32 -04004076 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004077 if (context)
4078 {
4079 if (context->getClientVersion() < 3 &&
4080 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4081 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082 {
Geoff Langbfdea662014-07-23 14:16:32 -04004083 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004084 }
Geoff Langbfdea662014-07-23 14:16:32 -04004085
4086 if (context->getClientVersion() >= 3 &&
4087 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4088 0, 0, 0, width, height, 1, border, format, type, pixels))
4089 {
4090 return;
4091 }
4092
4093 switch (target)
4094 {
4095 case GL_TEXTURE_2D:
4096 {
4097 gl::Texture2D *texture = context->getTexture2D();
4098 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4099 }
4100 break;
4101 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4102 {
4103 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4104 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4105 }
4106 break;
4107 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4108 {
4109 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4110 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4111 }
4112 break;
4113 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4114 {
4115 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4116 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4117 }
4118 break;
4119 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4120 {
4121 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4122 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4123 }
4124 break;
4125 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4126 {
4127 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4128 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4129 }
4130 break;
4131 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4132 {
4133 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4134 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4135 }
4136 break;
4137 default: UNREACHABLE();
4138 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004139 }
4140}
4141
4142void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4143{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004144 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4145
Geoff Langbfdea662014-07-23 14:16:32 -04004146 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004147 if (context)
4148 {
4149 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004150 {
Geoff Langbfdea662014-07-23 14:16:32 -04004151 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004152 }
Geoff Langbfdea662014-07-23 14:16:32 -04004153
4154 gl::Texture *texture = context->getTargetTexture(target);
4155
4156 if (!texture)
4157 {
Geoff Langb1196682014-07-23 13:47:29 -04004158 context->recordError(gl::Error(GL_INVALID_ENUM));
4159 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004160 }
4161
4162 switch (pname)
4163 {
4164 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4165 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4166 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4167 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4168 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4169 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4170 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4171 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4172 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4173 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4174 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4175 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4176 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4177 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4178 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4179 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4180 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4181 default: UNREACHABLE(); break;
4182 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004183 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004184}
4185
4186void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4187{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004188 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004189}
4190
4191void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4192{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004193 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004194
Geoff Langbfdea662014-07-23 14:16:32 -04004195 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004196 if (context)
4197 {
4198 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004199 {
Geoff Langbfdea662014-07-23 14:16:32 -04004200 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004201 }
Geoff Langbfdea662014-07-23 14:16:32 -04004202
4203 gl::Texture *texture = context->getTargetTexture(target);
4204
4205 if (!texture)
4206 {
Geoff Langb1196682014-07-23 13:47:29 -04004207 context->recordError(gl::Error(GL_INVALID_ENUM));
4208 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004209 }
4210
4211 switch (pname)
4212 {
4213 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4214 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4215 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4216 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4217 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4218 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4219 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4220 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4221 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4222 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4223 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4224 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4225 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4226 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4227 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4228 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4229 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4230 default: UNREACHABLE(); break;
4231 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004232 }
4233}
4234
4235void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4236{
4237 glTexParameteri(target, pname, *params);
4238}
4239
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004240void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4241{
4242 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4243 target, levels, internalformat, width, height);
4244
Geoff Langbfdea662014-07-23 14:16:32 -04004245 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004246 if (context)
4247 {
4248 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004249 {
Geoff Langb1196682014-07-23 13:47:29 -04004250 context->recordError(gl::Error(GL_INVALID_OPERATION));
4251 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004252 }
Geoff Langbfdea662014-07-23 14:16:32 -04004253
4254 if (context->getClientVersion() < 3 &&
4255 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4256 {
4257 return;
4258 }
4259
4260 if (context->getClientVersion() >= 3 &&
4261 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4262 {
4263 return;
4264 }
4265
4266 switch (target)
4267 {
4268 case GL_TEXTURE_2D:
4269 {
4270 gl::Texture2D *texture2d = context->getTexture2D();
4271 texture2d->storage(levels, internalformat, width, height);
4272 }
4273 break;
4274
4275 case GL_TEXTURE_CUBE_MAP:
4276 {
4277 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4278 textureCube->storage(levels, internalformat, width);
4279 }
4280 break;
4281
4282 default:
Geoff Langb1196682014-07-23 13:47:29 -04004283 context->recordError(gl::Error(GL_INVALID_ENUM));
4284 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004285 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004286 }
4287}
4288
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004289void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4290 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004292 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004293 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004294 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004295 target, level, xoffset, yoffset, width, height, format, type, pixels);
4296
Geoff Langbfdea662014-07-23 14:16:32 -04004297 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004298 if (context)
4299 {
4300 if (context->getClientVersion() < 3 &&
4301 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4302 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004303 {
Geoff Langbfdea662014-07-23 14:16:32 -04004304 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004305 }
Geoff Langbfdea662014-07-23 14:16:32 -04004306
4307 if (context->getClientVersion() >= 3 &&
4308 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4309 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4310 {
4311 return;
4312 }
4313
4314 // Zero sized uploads are valid but no-ops
4315 if (width == 0 || height == 0)
4316 {
4317 return;
4318 }
4319
4320 switch (target)
4321 {
4322 case GL_TEXTURE_2D:
4323 {
4324 gl::Texture2D *texture = context->getTexture2D();
4325 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4326 }
4327 break;
4328
4329 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4330 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4331 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4332 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4333 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4334 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4335 {
4336 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4337 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4338 }
4339 break;
4340
4341 default:
4342 UNREACHABLE();
4343 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004344 }
4345}
4346
4347void __stdcall glUniform1f(GLint location, GLfloat x)
4348{
4349 glUniform1fv(location, 1, &x);
4350}
4351
4352void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4353{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004354 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004355
Geoff Langbfdea662014-07-23 14:16:32 -04004356 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004357 if (context)
4358 {
4359 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004360 {
Geoff Langbfdea662014-07-23 14:16:32 -04004361 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004362 }
Geoff Langbfdea662014-07-23 14:16:32 -04004363
4364 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4365 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004366 }
4367}
4368
4369void __stdcall glUniform1i(GLint location, GLint x)
4370{
4371 glUniform1iv(location, 1, &x);
4372}
4373
4374void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4375{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004376 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004377
Geoff Langbfdea662014-07-23 14:16:32 -04004378 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004379 if (context)
4380 {
4381 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004382 {
Geoff Langbfdea662014-07-23 14:16:32 -04004383 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004384 }
Geoff Langbfdea662014-07-23 14:16:32 -04004385
4386 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4387 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004388 }
4389}
4390
4391void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4392{
4393 GLfloat xy[2] = {x, y};
4394
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004395 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004396}
4397
4398void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4399{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004400 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004401
Geoff Langbfdea662014-07-23 14:16:32 -04004402 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004403 if (context)
4404 {
4405 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004406 {
Geoff Langbfdea662014-07-23 14:16:32 -04004407 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004408 }
Geoff Langbfdea662014-07-23 14:16:32 -04004409
4410 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4411 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004412 }
4413}
4414
4415void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4416{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004417 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004418
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004419 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004420}
4421
4422void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4423{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004424 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004425
Geoff Langbfdea662014-07-23 14:16:32 -04004426 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004427 if (context)
4428 {
4429 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004430 {
Geoff Langbfdea662014-07-23 14:16:32 -04004431 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004432 }
Geoff Langbfdea662014-07-23 14:16:32 -04004433
4434 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4435 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004436 }
4437}
4438
4439void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4440{
4441 GLfloat xyz[3] = {x, y, z};
4442
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004443 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004444}
4445
4446void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004448 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004449
Geoff Langbfdea662014-07-23 14:16:32 -04004450 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004451 if (context)
4452 {
4453 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454 {
Geoff Langbfdea662014-07-23 14:16:32 -04004455 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004456 }
Geoff Langbfdea662014-07-23 14:16:32 -04004457
4458 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4459 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004460 }
4461}
4462
4463void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4464{
4465 GLint xyz[3] = {x, y, z};
4466
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004467 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004468}
4469
4470void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4471{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004472 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004473
Geoff Langbfdea662014-07-23 14:16:32 -04004474 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004475 if (context)
4476 {
4477 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004478 {
Geoff Langbfdea662014-07-23 14:16:32 -04004479 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004480 }
Geoff Langbfdea662014-07-23 14:16:32 -04004481
4482 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4483 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004484 }
4485}
4486
4487void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4488{
4489 GLfloat xyzw[4] = {x, y, z, w};
4490
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004491 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004492}
4493
4494void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4495{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004496 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004497
Geoff Langbfdea662014-07-23 14:16:32 -04004498 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004499 if (context)
4500 {
4501 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004502 {
Geoff Langbfdea662014-07-23 14:16:32 -04004503 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004504 }
Geoff Langbfdea662014-07-23 14:16:32 -04004505
4506 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4507 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508 }
4509}
4510
4511void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4512{
4513 GLint xyzw[4] = {x, y, z, w};
4514
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004515 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004516}
4517
4518void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4519{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004520 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004521
Geoff Langbfdea662014-07-23 14:16:32 -04004522 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004523 if (context)
4524 {
4525 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004526 {
Geoff Langbfdea662014-07-23 14:16:32 -04004527 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004528 }
Geoff Langbfdea662014-07-23 14:16:32 -04004529
4530 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4531 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004532 }
4533}
4534
4535void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4536{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004537 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004538 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004539
Geoff Langbfdea662014-07-23 14:16:32 -04004540 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004541 if (context)
4542 {
4543 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004544 {
Geoff Langbfdea662014-07-23 14:16:32 -04004545 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004546 }
Geoff Langbfdea662014-07-23 14:16:32 -04004547
4548 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4549 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004550 }
4551}
4552
4553void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4554{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004555 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004556 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557
Geoff Langbfdea662014-07-23 14:16:32 -04004558 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004559 if (context)
4560 {
4561 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562 {
Geoff Langbfdea662014-07-23 14:16:32 -04004563 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004564 }
Geoff Langbfdea662014-07-23 14:16:32 -04004565
4566 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4567 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004568 }
4569}
4570
4571void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4572{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004573 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004574 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004575
Geoff Langbfdea662014-07-23 14:16:32 -04004576 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004577 if (context)
4578 {
4579 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004580 {
Geoff Langbfdea662014-07-23 14:16:32 -04004581 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004582 }
Geoff Langbfdea662014-07-23 14:16:32 -04004583
4584 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4585 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004586 }
4587}
4588
4589void __stdcall glUseProgram(GLuint program)
4590{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004591 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004592
Geoff Langbfdea662014-07-23 14:16:32 -04004593 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004594 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004595 {
Geoff Langbfdea662014-07-23 14:16:32 -04004596 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004597
Geoff Langbfdea662014-07-23 14:16:32 -04004598 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004599 {
Geoff Langbfdea662014-07-23 14:16:32 -04004600 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004601 {
Geoff Langb1196682014-07-23 13:47:29 -04004602 context->recordError(gl::Error(GL_INVALID_OPERATION));
4603 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004604 }
Geoff Langbfdea662014-07-23 14:16:32 -04004605 else
4606 {
Geoff Langb1196682014-07-23 13:47:29 -04004607 context->recordError(gl::Error(GL_INVALID_VALUE));
4608 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004609 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004610 }
Geoff Langbfdea662014-07-23 14:16:32 -04004611
4612 if (program != 0 && !programObject->isLinked())
4613 {
Geoff Langb1196682014-07-23 13:47:29 -04004614 context->recordError(gl::Error(GL_INVALID_OPERATION));
4615 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004616 }
4617
4618 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619 }
4620}
4621
4622void __stdcall glValidateProgram(GLuint program)
4623{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004624 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004625
Geoff Langbfdea662014-07-23 14:16:32 -04004626 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004627 if (context)
4628 {
4629 gl::Program *programObject = context->getProgram(program);
4630
4631 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004632 {
Geoff Langbfdea662014-07-23 14:16:32 -04004633 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004634 {
Geoff Langb1196682014-07-23 13:47:29 -04004635 context->recordError(gl::Error(GL_INVALID_OPERATION));
4636 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004637 }
Geoff Langbfdea662014-07-23 14:16:32 -04004638 else
4639 {
Geoff Langb1196682014-07-23 13:47:29 -04004640 context->recordError(gl::Error(GL_INVALID_VALUE));
4641 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004642 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004643 }
Geoff Langbfdea662014-07-23 14:16:32 -04004644
Brandon Jones43a53e22014-08-28 16:23:22 -07004645 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004646 }
4647}
4648
4649void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4650{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004651 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004652
Geoff Langbfdea662014-07-23 14:16:32 -04004653 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004654 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004655 {
Geoff Langb1196682014-07-23 13:47:29 -04004656 if (index >= gl::MAX_VERTEX_ATTRIBS)
4657 {
4658 context->recordError(gl::Error(GL_INVALID_VALUE));
4659 return;
4660 }
4661
Geoff Langbfdea662014-07-23 14:16:32 -04004662 GLfloat vals[4] = { x, 0, 0, 1 };
4663 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004664 }
4665}
4666
4667void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4668{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004669 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670
Geoff Langbfdea662014-07-23 14:16:32 -04004671 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004672 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004673 {
Geoff Langb1196682014-07-23 13:47:29 -04004674 if (index >= gl::MAX_VERTEX_ATTRIBS)
4675 {
4676 context->recordError(gl::Error(GL_INVALID_VALUE));
4677 return;
4678 }
4679
Geoff Langbfdea662014-07-23 14:16:32 -04004680 GLfloat vals[4] = { values[0], 0, 0, 1 };
4681 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004682 }
4683}
4684
4685void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4686{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004687 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004688
Geoff Langbfdea662014-07-23 14:16:32 -04004689 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004690 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004691 {
Geoff Langb1196682014-07-23 13:47:29 -04004692 if (index >= gl::MAX_VERTEX_ATTRIBS)
4693 {
4694 context->recordError(gl::Error(GL_INVALID_VALUE));
4695 return;
4696 }
4697
Geoff Langbfdea662014-07-23 14:16:32 -04004698 GLfloat vals[4] = { x, y, 0, 1 };
4699 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004700 }
4701}
4702
4703void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4704{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004705 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004706
Geoff Langbfdea662014-07-23 14:16:32 -04004707 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004708 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004709 {
Geoff Langb1196682014-07-23 13:47:29 -04004710 if (index >= gl::MAX_VERTEX_ATTRIBS)
4711 {
4712 context->recordError(gl::Error(GL_INVALID_VALUE));
4713 return;
4714 }
4715
Geoff Langbfdea662014-07-23 14:16:32 -04004716 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4717 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004718 }
4719}
4720
4721void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4722{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004723 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 +00004724
Geoff Langbfdea662014-07-23 14:16:32 -04004725 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004726 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004727 {
Geoff Langb1196682014-07-23 13:47:29 -04004728 if (index >= gl::MAX_VERTEX_ATTRIBS)
4729 {
4730 context->recordError(gl::Error(GL_INVALID_VALUE));
4731 return;
4732 }
4733
Geoff Langbfdea662014-07-23 14:16:32 -04004734 GLfloat vals[4] = { x, y, z, 1 };
4735 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004736 }
4737}
4738
4739void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4740{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004741 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004742
Geoff Langbfdea662014-07-23 14:16:32 -04004743 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004744 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004745 {
Geoff Langb1196682014-07-23 13:47:29 -04004746 if (index >= gl::MAX_VERTEX_ATTRIBS)
4747 {
4748 context->recordError(gl::Error(GL_INVALID_VALUE));
4749 return;
4750 }
4751
Geoff Langbfdea662014-07-23 14:16:32 -04004752 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4753 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004754 }
4755}
4756
4757void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4758{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004759 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 +00004760
Geoff Langbfdea662014-07-23 14:16:32 -04004761 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004762 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004763 {
Geoff Langb1196682014-07-23 13:47:29 -04004764 if (index >= gl::MAX_VERTEX_ATTRIBS)
4765 {
4766 context->recordError(gl::Error(GL_INVALID_VALUE));
4767 return;
4768 }
4769
Geoff Langbfdea662014-07-23 14:16:32 -04004770 GLfloat vals[4] = { x, y, z, w };
4771 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004772 }
4773}
4774
4775void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004777 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004778
Geoff Langbfdea662014-07-23 14:16:32 -04004779 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004780 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004781 {
Geoff Langb1196682014-07-23 13:47:29 -04004782 if (index >= gl::MAX_VERTEX_ATTRIBS)
4783 {
4784 context->recordError(gl::Error(GL_INVALID_VALUE));
4785 return;
4786 }
4787
Geoff Langbfdea662014-07-23 14:16:32 -04004788 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004789 }
4790}
4791
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004792void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4793{
4794 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4795
Geoff Langbfdea662014-07-23 14:16:32 -04004796 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004797 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004798 {
Geoff Langb1196682014-07-23 13:47:29 -04004799 if (index >= gl::MAX_VERTEX_ATTRIBS)
4800 {
4801 context->recordError(gl::Error(GL_INVALID_VALUE));
4802 return;
4803 }
4804
Geoff Langbfdea662014-07-23 14:16:32 -04004805 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004806 }
4807}
4808
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004809void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004810{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004811 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004812 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004813 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004814
Geoff Langbfdea662014-07-23 14:16:32 -04004815 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004816 if (context)
4817 {
Geoff Langb1196682014-07-23 13:47:29 -04004818 if (index >= gl::MAX_VERTEX_ATTRIBS)
4819 {
4820 context->recordError(gl::Error(GL_INVALID_VALUE));
4821 return;
4822 }
4823
4824 if (size < 1 || size > 4)
4825 {
4826 context->recordError(gl::Error(GL_INVALID_VALUE));
4827 return;
4828 }
4829
4830 switch (type)
4831 {
4832 case GL_BYTE:
4833 case GL_UNSIGNED_BYTE:
4834 case GL_SHORT:
4835 case GL_UNSIGNED_SHORT:
4836 case GL_FIXED:
4837 case GL_FLOAT:
4838 break;
4839
4840 case GL_HALF_FLOAT:
4841 case GL_INT:
4842 case GL_UNSIGNED_INT:
4843 case GL_INT_2_10_10_10_REV:
4844 case GL_UNSIGNED_INT_2_10_10_10_REV:
4845 if (context->getClientVersion() < 3)
4846 {
4847 context->recordError(gl::Error(GL_INVALID_ENUM));
4848 return;
4849 }
4850 break;
4851
4852 default:
4853 context->recordError(gl::Error(GL_INVALID_ENUM));
4854 return;
4855 }
4856
4857 if (stride < 0)
4858 {
4859 context->recordError(gl::Error(GL_INVALID_VALUE));
4860 return;
4861 }
4862
4863 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4864 {
4865 context->recordError(gl::Error(GL_INVALID_OPERATION));
4866 return;
4867 }
4868
Geoff Langbfdea662014-07-23 14:16:32 -04004869 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4870 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4871 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4872 // and the pointer argument is not NULL.
4873 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004874 {
Geoff Langb1196682014-07-23 13:47:29 -04004875 context->recordError(gl::Error(GL_INVALID_OPERATION));
4876 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004877 }
4878
Geoff Langbfdea662014-07-23 14:16:32 -04004879 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4880 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004881 }
4882}
4883
4884void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4885{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004886 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 +00004887
Geoff Langbfdea662014-07-23 14:16:32 -04004888 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004889 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004890 {
Geoff Langb1196682014-07-23 13:47:29 -04004891 if (width < 0 || height < 0)
4892 {
4893 context->recordError(gl::Error(GL_INVALID_VALUE));
4894 return;
4895 }
4896
Geoff Langbfdea662014-07-23 14:16:32 -04004897 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004898 }
4899}
4900
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004901// OpenGL ES 3.0 functions
4902
4903void __stdcall glReadBuffer(GLenum mode)
4904{
4905 EVENT("(GLenum mode = 0x%X)", mode);
4906
Geoff Langbfdea662014-07-23 14:16:32 -04004907 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004908 if (context)
4909 {
4910 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004911 {
Geoff Langb1196682014-07-23 13:47:29 -04004912 context->recordError(gl::Error(GL_INVALID_OPERATION));
4913 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004914 }
Geoff Langbfdea662014-07-23 14:16:32 -04004915
4916 // glReadBuffer
4917 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004918 }
4919}
4920
4921void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4922{
4923 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4924 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4925
Geoff Langbfdea662014-07-23 14:16:32 -04004926 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004927 if (context)
4928 {
4929 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004930 {
Geoff Langb1196682014-07-23 13:47:29 -04004931 context->recordError(gl::Error(GL_INVALID_OPERATION));
4932 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004933 }
Geoff Langbfdea662014-07-23 14:16:32 -04004934
4935 // glDrawRangeElements
4936 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004937 }
4938}
4939
4940void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4941{
4942 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4943 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4944 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4945 target, level, internalformat, width, height, depth, border, format, type, pixels);
4946
Geoff Langbfdea662014-07-23 14:16:32 -04004947 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004948 if (context)
4949 {
4950 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004951 {
Geoff Langb1196682014-07-23 13:47:29 -04004952 context->recordError(gl::Error(GL_INVALID_OPERATION));
4953 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004954 }
Geoff Langbfdea662014-07-23 14:16:32 -04004955
4956 // validateES3TexImageFormat sets the error code if there is an error
4957 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4958 0, 0, 0, width, height, depth, border, format, type, pixels))
4959 {
4960 return;
4961 }
4962
4963 switch(target)
4964 {
4965 case GL_TEXTURE_3D:
4966 {
4967 gl::Texture3D *texture = context->getTexture3D();
4968 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4969 }
4970 break;
4971
4972 case GL_TEXTURE_2D_ARRAY:
4973 {
4974 gl::Texture2DArray *texture = context->getTexture2DArray();
4975 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4976 }
4977 break;
4978
4979 default:
Geoff Langb1196682014-07-23 13:47:29 -04004980 context->recordError(gl::Error(GL_INVALID_ENUM));
4981 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004982 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004983 }
4984}
4985
4986void __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)
4987{
4988 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4989 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4990 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4991 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4992
Geoff Langbfdea662014-07-23 14:16:32 -04004993 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004994 if (context)
4995 {
4996 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004997 {
Geoff Langb1196682014-07-23 13:47:29 -04004998 context->recordError(gl::Error(GL_INVALID_OPERATION));
4999 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005000 }
Geoff Langbfdea662014-07-23 14:16:32 -04005001
5002 // validateES3TexImageFormat sets the error code if there is an error
5003 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5004 xoffset, yoffset, zoffset, width, height, depth, 0,
5005 format, type, pixels))
5006 {
5007 return;
5008 }
5009
5010 // Zero sized uploads are valid but no-ops
5011 if (width == 0 || height == 0 || depth == 0)
5012 {
5013 return;
5014 }
5015
5016 switch(target)
5017 {
5018 case GL_TEXTURE_3D:
5019 {
5020 gl::Texture3D *texture = context->getTexture3D();
5021 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5022 }
5023 break;
5024
5025 case GL_TEXTURE_2D_ARRAY:
5026 {
5027 gl::Texture2DArray *texture = context->getTexture2DArray();
5028 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5029 }
5030 break;
5031
5032 default:
Geoff Langb1196682014-07-23 13:47:29 -04005033 context->recordError(gl::Error(GL_INVALID_ENUM));
5034 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005035 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005036 }
5037}
5038
5039void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5040{
5041 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5042 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5043 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5044
Geoff Langbfdea662014-07-23 14:16:32 -04005045 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005046 if (context)
5047 {
5048 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005049 {
Geoff Langb1196682014-07-23 13:47:29 -04005050 context->recordError(gl::Error(GL_INVALID_OPERATION));
5051 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005052 }
Geoff Langbfdea662014-07-23 14:16:32 -04005053
5054 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5055 x, y, width, height, 0))
5056 {
5057 return;
5058 }
5059
5060 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5061 gl::Texture *texture = NULL;
5062 switch (target)
5063 {
5064 case GL_TEXTURE_3D:
5065 texture = context->getTexture3D();
5066 break;
5067
5068 case GL_TEXTURE_2D_ARRAY:
5069 texture = context->getTexture2DArray();
5070 break;
5071
5072 default:
Geoff Langb1196682014-07-23 13:47:29 -04005073 context->recordError(gl::Error(GL_INVALID_ENUM));
5074 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005075 }
5076
5077 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005078 }
5079}
5080
5081void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5082{
Geoff Langeef52cc2013-10-16 15:07:39 -04005083 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 +00005084 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5085 "const GLvoid* data = 0x%0.8p)",
5086 target, level, internalformat, width, height, depth, border, imageSize, data);
5087
Geoff Langbfdea662014-07-23 14:16:32 -04005088 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005089 if (context)
5090 {
5091 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005092 {
Geoff Langb1196682014-07-23 13:47:29 -04005093 context->recordError(gl::Error(GL_INVALID_OPERATION));
5094 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005095 }
Geoff Langbfdea662014-07-23 14:16:32 -04005096
Geoff Lang5d601382014-07-22 15:14:06 -04005097 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5098 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005099 {
Geoff Langb1196682014-07-23 13:47:29 -04005100 context->recordError(gl::Error(GL_INVALID_VALUE));
5101 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005102 }
5103
5104 // validateES3TexImageFormat sets the error code if there is an error
5105 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5106 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5107 {
5108 return;
5109 }
5110
5111 switch(target)
5112 {
5113 case GL_TEXTURE_3D:
5114 {
5115 gl::Texture3D *texture = context->getTexture3D();
5116 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5117 }
5118 break;
5119
5120 case GL_TEXTURE_2D_ARRAY:
5121 {
5122 gl::Texture2DArray *texture = context->getTexture2DArray();
5123 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5124 }
5125 break;
5126
5127 default:
Geoff Langb1196682014-07-23 13:47:29 -04005128 context->recordError(gl::Error(GL_INVALID_ENUM));
5129 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005130 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005131 }
5132}
5133
5134void __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)
5135{
5136 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5137 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5138 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5139 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5140
Geoff Langbfdea662014-07-23 14:16:32 -04005141 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005142 if (context)
5143 {
5144 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005145 {
Geoff Langb1196682014-07-23 13:47:29 -04005146 context->recordError(gl::Error(GL_INVALID_OPERATION));
5147 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005148 }
Geoff Langbfdea662014-07-23 14:16:32 -04005149
Geoff Lang5d601382014-07-22 15:14:06 -04005150 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5151 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005152 {
Geoff Langb1196682014-07-23 13:47:29 -04005153 context->recordError(gl::Error(GL_INVALID_VALUE));
5154 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005155 }
5156
5157 if (!data)
5158 {
Geoff Langb1196682014-07-23 13:47:29 -04005159 context->recordError(gl::Error(GL_INVALID_VALUE));
5160 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005161 }
5162
5163 // validateES3TexImageFormat sets the error code if there is an error
5164 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5165 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5166 {
5167 return;
5168 }
5169
5170 // Zero sized uploads are valid but no-ops
5171 if (width == 0 || height == 0)
5172 {
5173 return;
5174 }
5175
5176 switch(target)
5177 {
5178 case GL_TEXTURE_3D:
5179 {
5180 gl::Texture3D *texture = context->getTexture3D();
5181 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5182 format, imageSize, data);
5183 }
5184 break;
5185
5186 case GL_TEXTURE_2D_ARRAY:
5187 {
5188 gl::Texture2DArray *texture = context->getTexture2DArray();
5189 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5190 format, imageSize, data);
5191 }
5192 break;
5193
Geoff Langb1196682014-07-23 13:47:29 -04005194 default:
5195 context->recordError(gl::Error(GL_INVALID_ENUM));
5196 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005197 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005198 }
5199}
5200
5201void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5202{
5203 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5204
Geoff Langbfdea662014-07-23 14:16:32 -04005205 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005206 if (context)
5207 {
5208 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005209 {
Geoff Langb1196682014-07-23 13:47:29 -04005210 context->recordError(gl::Error(GL_INVALID_OPERATION));
5211 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005212 }
Geoff Langbfdea662014-07-23 14:16:32 -04005213
5214 if (n < 0)
5215 {
Geoff Langb1196682014-07-23 13:47:29 -04005216 context->recordError(gl::Error(GL_INVALID_VALUE));
5217 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005218 }
5219
5220 for (GLsizei i = 0; i < n; i++)
5221 {
5222 ids[i] = context->createQuery();
5223 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005224 }
5225}
5226
5227void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5228{
5229 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5230
Geoff Langbfdea662014-07-23 14:16:32 -04005231 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005232 if (context)
5233 {
5234 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005235 {
Geoff Langb1196682014-07-23 13:47:29 -04005236 context->recordError(gl::Error(GL_INVALID_OPERATION));
5237 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005238 }
Geoff Langbfdea662014-07-23 14:16:32 -04005239
5240 if (n < 0)
5241 {
Geoff Langb1196682014-07-23 13:47:29 -04005242 context->recordError(gl::Error(GL_INVALID_VALUE));
5243 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005244 }
5245
5246 for (GLsizei i = 0; i < n; i++)
5247 {
5248 context->deleteQuery(ids[i]);
5249 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005250 }
5251}
5252
5253GLboolean __stdcall glIsQuery(GLuint id)
5254{
5255 EVENT("(GLuint id = %u)", id);
5256
Geoff Langbfdea662014-07-23 14:16:32 -04005257 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005258 if (context)
5259 {
5260 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005261 {
Geoff Langb1196682014-07-23 13:47:29 -04005262 context->recordError(gl::Error(GL_INVALID_OPERATION));
5263 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005264 }
Geoff Langbfdea662014-07-23 14:16:32 -04005265
5266 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005267 }
5268
5269 return GL_FALSE;
5270}
5271
5272void __stdcall glBeginQuery(GLenum target, GLuint id)
5273{
5274 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5275
Geoff Langbfdea662014-07-23 14:16:32 -04005276 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005277 if (context)
5278 {
5279 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005280 {
Geoff Langb1196682014-07-23 13:47:29 -04005281 context->recordError(gl::Error(GL_INVALID_OPERATION));
5282 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005283 }
Geoff Langbfdea662014-07-23 14:16:32 -04005284
5285 if (!ValidateBeginQuery(context, target, id))
5286 {
5287 return;
5288 }
5289 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005290 }
5291}
5292
5293void __stdcall glEndQuery(GLenum target)
5294{
5295 EVENT("(GLenum target = 0x%X)", target);
5296
Geoff Langbfdea662014-07-23 14:16:32 -04005297 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005298 if (context)
5299 {
5300 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005301 {
Geoff Langb1196682014-07-23 13:47:29 -04005302 context->recordError(gl::Error(GL_INVALID_OPERATION));
5303 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005304 }
Geoff Langbfdea662014-07-23 14:16:32 -04005305
5306 if (!ValidateEndQuery(context, target))
5307 {
5308 return;
5309 }
5310
5311 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005312 }
5313}
5314
5315void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5316{
5317 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5318
Geoff Langbfdea662014-07-23 14:16:32 -04005319 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005320 if (context)
5321 {
5322 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005323 {
Geoff Langb1196682014-07-23 13:47:29 -04005324 context->recordError(gl::Error(GL_INVALID_OPERATION));
5325 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005326 }
Geoff Langbfdea662014-07-23 14:16:32 -04005327
5328 if (!ValidQueryType(context, target))
5329 {
Geoff Langb1196682014-07-23 13:47:29 -04005330 context->recordError(gl::Error(GL_INVALID_ENUM));
5331 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005332 }
5333
5334 switch (pname)
5335 {
5336 case GL_CURRENT_QUERY:
5337 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5338 break;
5339
5340 default:
Geoff Langb1196682014-07-23 13:47:29 -04005341 context->recordError(gl::Error(GL_INVALID_ENUM));
5342 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005343 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005344 }
5345}
5346
5347void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5348{
5349 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5350
Geoff Langbfdea662014-07-23 14:16:32 -04005351 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005352 if (context)
5353 {
5354 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005355 {
Geoff Langb1196682014-07-23 13:47:29 -04005356 context->recordError(gl::Error(GL_INVALID_OPERATION));
5357 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005358 }
Geoff Langbfdea662014-07-23 14:16:32 -04005359
5360 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5361
5362 if (!queryObject)
5363 {
Geoff Langb1196682014-07-23 13:47:29 -04005364 context->recordError(gl::Error(GL_INVALID_OPERATION));
5365 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005366 }
5367
5368 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5369 {
Geoff Langb1196682014-07-23 13:47:29 -04005370 context->recordError(gl::Error(GL_INVALID_OPERATION));
5371 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005372 }
5373
5374 switch(pname)
5375 {
5376 case GL_QUERY_RESULT:
5377 params[0] = queryObject->getResult();
5378 break;
Geoff Langb1196682014-07-23 13:47:29 -04005379
Geoff Langbfdea662014-07-23 14:16:32 -04005380 case GL_QUERY_RESULT_AVAILABLE:
5381 params[0] = queryObject->isResultAvailable();
5382 break;
Geoff Langb1196682014-07-23 13:47:29 -04005383
Geoff Langbfdea662014-07-23 14:16:32 -04005384 default:
Geoff Langb1196682014-07-23 13:47:29 -04005385 context->recordError(gl::Error(GL_INVALID_ENUM));
5386 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005387 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005388 }
5389}
5390
5391GLboolean __stdcall glUnmapBuffer(GLenum target)
5392{
5393 EVENT("(GLenum target = 0x%X)", target);
5394
Geoff Langbfdea662014-07-23 14:16:32 -04005395 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005396 if (context)
5397 {
5398 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005399 {
Geoff Langb1196682014-07-23 13:47:29 -04005400 context->recordError(gl::Error(GL_INVALID_OPERATION));
5401 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005402 }
Geoff Langbfdea662014-07-23 14:16:32 -04005403
5404 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005405 }
5406
5407 return GL_FALSE;
5408}
5409
5410void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5411{
5412 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5413
Geoff Langbfdea662014-07-23 14:16:32 -04005414 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005415 if (context)
5416 {
5417 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005418 {
Geoff Langb1196682014-07-23 13:47:29 -04005419 context->recordError(gl::Error(GL_INVALID_OPERATION));
5420 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005421 }
Geoff Langbfdea662014-07-23 14:16:32 -04005422
5423 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005424 }
5425}
5426
5427void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5428{
Geoff Langbfdea662014-07-23 14:16:32 -04005429 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005430 if (context)
5431 {
5432 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005433 {
Geoff Langb1196682014-07-23 13:47:29 -04005434 context->recordError(gl::Error(GL_INVALID_OPERATION));
5435 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005436 }
Geoff Langbfdea662014-07-23 14:16:32 -04005437
5438 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005439 }
5440}
5441
5442void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5443{
5444 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5445 location, count, transpose, value);
5446
Geoff Langbfdea662014-07-23 14:16:32 -04005447 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005448 if (context)
5449 {
5450 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005451 {
Geoff Langbfdea662014-07-23 14:16:32 -04005452 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005453 }
Geoff Langbfdea662014-07-23 14:16:32 -04005454
5455 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5456 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005457 }
5458}
5459
5460void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5461{
5462 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5463 location, count, transpose, value);
5464
Geoff Langbfdea662014-07-23 14:16:32 -04005465 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005466 if (context)
5467 {
5468 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005469 {
Geoff Langbfdea662014-07-23 14:16:32 -04005470 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005471 }
Geoff Langbfdea662014-07-23 14:16:32 -04005472
5473 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5474 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005475 }
5476}
5477
5478void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5479{
5480 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5481 location, count, transpose, value);
5482
Geoff Langbfdea662014-07-23 14:16:32 -04005483 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005484 if (context)
5485 {
5486 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005487 {
Geoff Langbfdea662014-07-23 14:16:32 -04005488 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005489 }
Geoff Langbfdea662014-07-23 14:16:32 -04005490
5491 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5492 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005493 }
5494}
5495
5496void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5497{
5498 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5499 location, count, transpose, value);
5500
Geoff Langbfdea662014-07-23 14:16:32 -04005501 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005502 if (context)
5503 {
5504 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005505 {
Geoff Langbfdea662014-07-23 14:16:32 -04005506 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005507 }
Geoff Langbfdea662014-07-23 14:16:32 -04005508
5509 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5510 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005511 }
5512}
5513
5514void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5515{
5516 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5517 location, count, transpose, value);
5518
Geoff Langbfdea662014-07-23 14:16:32 -04005519 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005520 if (context)
5521 {
5522 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005523 {
Geoff Langbfdea662014-07-23 14:16:32 -04005524 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005525 }
Geoff Langbfdea662014-07-23 14:16:32 -04005526
5527 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5528 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005529 }
5530}
5531
5532void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5533{
5534 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5535 location, count, transpose, value);
5536
Geoff Langbfdea662014-07-23 14:16:32 -04005537 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005538 if (context)
5539 {
5540 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005541 {
Geoff Langbfdea662014-07-23 14:16:32 -04005542 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005543 }
Geoff Langbfdea662014-07-23 14:16:32 -04005544
5545 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5546 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005547 }
5548}
5549
5550void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5551{
5552 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5553 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5554 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5555
Geoff Langbfdea662014-07-23 14:16:32 -04005556 gl::Context *context = gl::getNonLostContext();
5557 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005558 {
Geoff Langbfdea662014-07-23 14:16:32 -04005559 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005560 {
Geoff Langb1196682014-07-23 13:47:29 -04005561 context->recordError(gl::Error(GL_INVALID_OPERATION));
5562 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005563 }
Geoff Langbfdea662014-07-23 14:16:32 -04005564
5565 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5566 dstX0, dstY0, dstX1, dstY1, mask, filter,
5567 false))
5568 {
5569 return;
5570 }
5571
5572 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5573 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005574 }
5575}
5576
5577void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5578{
5579 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5580 target, samples, internalformat, width, height);
5581
Geoff Langbfdea662014-07-23 14:16:32 -04005582 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005583 if (context)
5584 {
5585 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005586 {
Geoff Langb1196682014-07-23 13:47:29 -04005587 context->recordError(gl::Error(GL_INVALID_OPERATION));
5588 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005589 }
Geoff Langbfdea662014-07-23 14:16:32 -04005590
5591 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5592 width, height, false))
5593 {
5594 return;
5595 }
5596
5597 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005598 }
5599}
5600
5601void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5602{
5603 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5604 target, attachment, texture, level, layer);
5605
Geoff Langbfdea662014-07-23 14:16:32 -04005606 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005607 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005608 {
Geoff Langbfdea662014-07-23 14:16:32 -04005609 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5610 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005611 {
Geoff Langbfdea662014-07-23 14:16:32 -04005612 return;
5613 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005614
Geoff Langbfdea662014-07-23 14:16:32 -04005615 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5616 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005617
Geoff Langbfdea662014-07-23 14:16:32 -04005618 gl::Texture *textureObject = context->getTexture(texture);
5619 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005620
Geoff Langbfdea662014-07-23 14:16:32 -04005621 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5622 {
5623 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5624 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5625 }
5626 else
5627 {
5628 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005629 {
Geoff Langbfdea662014-07-23 14:16:32 -04005630 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5631 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5632 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005633 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005634 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005635 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005636}
5637
5638GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5639{
5640 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5641 target, offset, length, access);
5642
Geoff Langbfdea662014-07-23 14:16:32 -04005643 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005644 if (context)
5645 {
5646 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005647 {
Geoff Langb1196682014-07-23 13:47:29 -04005648 context->recordError(gl::Error(GL_INVALID_OPERATION));
5649 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005650 }
Geoff Langbfdea662014-07-23 14:16:32 -04005651
5652 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005653 }
5654
5655 return NULL;
5656}
5657
5658void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5659{
5660 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5661
Geoff Langbfdea662014-07-23 14:16:32 -04005662 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005663 if (context)
5664 {
5665 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005666 {
Geoff Langb1196682014-07-23 13:47:29 -04005667 context->recordError(gl::Error(GL_INVALID_OPERATION));
5668 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005669 }
Geoff Langbfdea662014-07-23 14:16:32 -04005670
5671 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005672 }
5673}
5674
5675void __stdcall glBindVertexArray(GLuint array)
5676{
5677 EVENT("(GLuint array = %u)", array);
5678
Geoff Langbfdea662014-07-23 14:16:32 -04005679 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005680 if (context)
5681 {
5682 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005683 {
Geoff Langb1196682014-07-23 13:47:29 -04005684 context->recordError(gl::Error(GL_INVALID_OPERATION));
5685 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005686 }
Geoff Langbfdea662014-07-23 14:16:32 -04005687
5688 gl::VertexArray *vao = context->getVertexArray(array);
5689
5690 if (!vao)
5691 {
5692 // The default VAO should always exist
5693 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005694 context->recordError(gl::Error(GL_INVALID_OPERATION));
5695 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005696 }
5697
5698 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005699 }
5700}
5701
5702void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5703{
5704 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5705
Geoff Langbfdea662014-07-23 14:16:32 -04005706 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005707 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005708 {
Geoff Langbfdea662014-07-23 14:16:32 -04005709 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005710 {
Geoff Langb1196682014-07-23 13:47:29 -04005711 context->recordError(gl::Error(GL_INVALID_OPERATION));
5712 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005713 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005714
Geoff Langbfdea662014-07-23 14:16:32 -04005715 if (n < 0)
5716 {
Geoff Langb1196682014-07-23 13:47:29 -04005717 context->recordError(gl::Error(GL_INVALID_VALUE));
5718 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005719 }
Jamie Madilld1028542013-07-02 11:57:04 -04005720
Geoff Langbfdea662014-07-23 14:16:32 -04005721 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5722 {
5723 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005724 {
Geoff Langbfdea662014-07-23 14:16:32 -04005725 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005726 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005727 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005728 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005729}
5730
5731void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5732{
5733 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5734
Geoff Langbfdea662014-07-23 14:16:32 -04005735 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005736 if (context)
5737 {
5738 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005739 {
Geoff Langb1196682014-07-23 13:47:29 -04005740 context->recordError(gl::Error(GL_INVALID_OPERATION));
5741 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005742 }
Geoff Langbfdea662014-07-23 14:16:32 -04005743
5744 if (n < 0)
5745 {
Geoff Langb1196682014-07-23 13:47:29 -04005746 context->recordError(gl::Error(GL_INVALID_VALUE));
5747 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005748 }
5749
5750 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5751 {
5752 arrays[arrayIndex] = context->createVertexArray();
5753 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005754 }
5755}
5756
5757GLboolean __stdcall glIsVertexArray(GLuint array)
5758{
5759 EVENT("(GLuint array = %u)", array);
5760
Geoff Langbfdea662014-07-23 14:16:32 -04005761 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005762 if (context)
5763 {
5764 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005765 {
Geoff Langb1196682014-07-23 13:47:29 -04005766 context->recordError(gl::Error(GL_INVALID_OPERATION));
5767 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005768 }
Geoff Langbfdea662014-07-23 14:16:32 -04005769
5770 if (array == 0)
5771 {
5772 return GL_FALSE;
5773 }
5774
5775 gl::VertexArray *vao = context->getVertexArray(array);
5776
5777 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005778 }
5779
5780 return GL_FALSE;
5781}
5782
5783void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5784{
5785 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5786 target, index, data);
5787
Geoff Langbfdea662014-07-23 14:16:32 -04005788 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005789 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005790 {
Geoff Langbfdea662014-07-23 14:16:32 -04005791 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005792 {
Geoff Langb1196682014-07-23 13:47:29 -04005793 context->recordError(gl::Error(GL_INVALID_OPERATION));
5794 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005795 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005796
Geoff Lang3a61c322014-07-10 13:01:54 -04005797 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005798 switch (target)
5799 {
5800 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5801 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5802 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005803 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5804 {
Geoff Langb1196682014-07-23 13:47:29 -04005805 context->recordError(gl::Error(GL_INVALID_VALUE));
5806 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005807 }
Geoff Langbfdea662014-07-23 14:16:32 -04005808 break;
Geoff Langb1196682014-07-23 13:47:29 -04005809
Geoff Langbfdea662014-07-23 14:16:32 -04005810 case GL_UNIFORM_BUFFER_START:
5811 case GL_UNIFORM_BUFFER_SIZE:
5812 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005813 if (index >= caps.maxCombinedUniformBlocks)
5814 {
Geoff Langb1196682014-07-23 13:47:29 -04005815 context->recordError(gl::Error(GL_INVALID_VALUE));
5816 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005817 }
Geoff Langbfdea662014-07-23 14:16:32 -04005818 break;
Geoff Langb1196682014-07-23 13:47:29 -04005819
Geoff Langbfdea662014-07-23 14:16:32 -04005820 default:
Geoff Langb1196682014-07-23 13:47:29 -04005821 context->recordError(gl::Error(GL_INVALID_ENUM));
5822 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005823 }
5824
5825 if (!(context->getIndexedIntegerv(target, index, data)))
5826 {
5827 GLenum nativeType;
5828 unsigned int numParams = 0;
5829 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005830 {
5831 context->recordError(gl::Error(GL_INVALID_ENUM));
5832 return;
5833 }
Shannon Woods15934d52013-08-19 14:28:49 -04005834
Geoff Langbfdea662014-07-23 14:16:32 -04005835 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005836 {
Geoff Langbfdea662014-07-23 14:16:32 -04005837 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005838 }
Geoff Langbfdea662014-07-23 14:16:32 -04005839
5840 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005841 {
Geoff Langbfdea662014-07-23 14:16:32 -04005842 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5843 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5844 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005845
Geoff Langbfdea662014-07-23 14:16:32 -04005846 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005847
Geoff Langbfdea662014-07-23 14:16:32 -04005848 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005849 {
Geoff Langbfdea662014-07-23 14:16:32 -04005850 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5851 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005852 }
Geoff Langbfdea662014-07-23 14:16:32 -04005853
5854 delete [] int64Params;
5855 }
5856 else
5857 {
5858 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005859 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005860 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005861 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005862}
5863
5864void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5865{
5866 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5867
Geoff Langbfdea662014-07-23 14:16:32 -04005868 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005869 if (context)
5870 {
5871 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005872 {
Geoff Langb1196682014-07-23 13:47:29 -04005873 context->recordError(gl::Error(GL_INVALID_OPERATION));
5874 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005875 }
Geoff Langbfdea662014-07-23 14:16:32 -04005876
5877 switch (primitiveMode)
5878 {
5879 case GL_TRIANGLES:
5880 case GL_LINES:
5881 case GL_POINTS:
5882 break;
Geoff Langb1196682014-07-23 13:47:29 -04005883
Geoff Langbfdea662014-07-23 14:16:32 -04005884 default:
Geoff Langb1196682014-07-23 13:47:29 -04005885 context->recordError(gl::Error(GL_INVALID_ENUM));
5886 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005887 }
5888
5889 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5890 ASSERT(transformFeedback != NULL);
5891
5892 if (transformFeedback->isStarted())
5893 {
Geoff Langb1196682014-07-23 13:47:29 -04005894 context->recordError(gl::Error(GL_INVALID_OPERATION));
5895 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005896 }
5897
5898 if (transformFeedback->isPaused())
5899 {
5900 transformFeedback->resume();
5901 }
5902 else
5903 {
5904 transformFeedback->start(primitiveMode);
5905 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005906 }
5907}
5908
5909void __stdcall glEndTransformFeedback(void)
5910{
5911 EVENT("(void)");
5912
Geoff Langbfdea662014-07-23 14:16:32 -04005913 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005914 if (context)
5915 {
5916 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005917 {
Geoff Langb1196682014-07-23 13:47:29 -04005918 context->recordError(gl::Error(GL_INVALID_OPERATION));
5919 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005920 }
Geoff Langbfdea662014-07-23 14:16:32 -04005921
5922 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5923 ASSERT(transformFeedback != NULL);
5924
5925 if (!transformFeedback->isStarted())
5926 {
Geoff Langb1196682014-07-23 13:47:29 -04005927 context->recordError(gl::Error(GL_INVALID_OPERATION));
5928 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005929 }
5930
5931 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005932 }
5933}
5934
5935void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5936{
5937 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5938 target, index, buffer, offset, size);
5939
Geoff Langbfdea662014-07-23 14:16:32 -04005940 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005941 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005942 {
Geoff Langbfdea662014-07-23 14:16:32 -04005943 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005944 {
Geoff Langb1196682014-07-23 13:47:29 -04005945 context->recordError(gl::Error(GL_INVALID_OPERATION));
5946 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005947 }
5948
Geoff Lang3a61c322014-07-10 13:01:54 -04005949 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005950 switch (target)
5951 {
5952 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04005953 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005954 {
Geoff Langb1196682014-07-23 13:47:29 -04005955 context->recordError(gl::Error(GL_INVALID_VALUE));
5956 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005957 }
Geoff Langbfdea662014-07-23 14:16:32 -04005958 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005959
Geoff Langbfdea662014-07-23 14:16:32 -04005960 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04005961 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005962 {
Geoff Langb1196682014-07-23 13:47:29 -04005963 context->recordError(gl::Error(GL_INVALID_VALUE));
5964 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005965 }
Geoff Langbfdea662014-07-23 14:16:32 -04005966 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005967
Geoff Langbfdea662014-07-23 14:16:32 -04005968 default:
Geoff Langb1196682014-07-23 13:47:29 -04005969 context->recordError(gl::Error(GL_INVALID_ENUM));
5970 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005971 }
5972
5973 if (buffer != 0 && size <= 0)
5974 {
Geoff Langb1196682014-07-23 13:47:29 -04005975 context->recordError(gl::Error(GL_INVALID_VALUE));
5976 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005977 }
5978
5979 switch (target)
5980 {
5981 case GL_TRANSFORM_FEEDBACK_BUFFER:
5982
5983 // size and offset must be a multiple of 4
5984 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005985 {
Geoff Langb1196682014-07-23 13:47:29 -04005986 context->recordError(gl::Error(GL_INVALID_VALUE));
5987 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005988 }
5989
Geoff Langbfdea662014-07-23 14:16:32 -04005990 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5991 context->bindGenericTransformFeedbackBuffer(buffer);
5992 break;
5993
5994 case GL_UNIFORM_BUFFER:
5995
5996 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04005997 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005998 {
Geoff Langb1196682014-07-23 13:47:29 -04005999 context->recordError(gl::Error(GL_INVALID_VALUE));
6000 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006001 }
Geoff Langbfdea662014-07-23 14:16:32 -04006002
6003 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6004 context->bindGenericUniformBuffer(buffer);
6005 break;
6006
6007 default:
6008 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006009 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006010 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006011}
6012
6013void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
6014{
6015 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6016 target, index, buffer);
6017
Geoff Langbfdea662014-07-23 14:16:32 -04006018 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006019 if (context)
6020 {
6021 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006022 {
Geoff Langb1196682014-07-23 13:47:29 -04006023 context->recordError(gl::Error(GL_INVALID_OPERATION));
6024 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006025 }
Geoff Langbfdea662014-07-23 14:16:32 -04006026
Geoff Lang3a61c322014-07-10 13:01:54 -04006027 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006028 switch (target)
6029 {
6030 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006031 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006032 {
Geoff Langb1196682014-07-23 13:47:29 -04006033 context->recordError(gl::Error(GL_INVALID_VALUE));
6034 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006035 }
6036 break;
6037
6038 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006039 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006040 {
Geoff Langb1196682014-07-23 13:47:29 -04006041 context->recordError(gl::Error(GL_INVALID_VALUE));
6042 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006043 }
6044 break;
6045
6046 default:
Geoff Langb1196682014-07-23 13:47:29 -04006047 context->recordError(gl::Error(GL_INVALID_ENUM));
6048 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006049 }
6050
6051 switch (target)
6052 {
6053 case GL_TRANSFORM_FEEDBACK_BUFFER:
6054 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6055 context->bindGenericTransformFeedbackBuffer(buffer);
6056 break;
6057
6058 case GL_UNIFORM_BUFFER:
6059 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6060 context->bindGenericUniformBuffer(buffer);
6061 break;
6062
6063 default:
6064 UNREACHABLE();
6065 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006066 }
6067}
6068
6069void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6070{
6071 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6072 program, count, varyings, bufferMode);
6073
Geoff Langbfdea662014-07-23 14:16:32 -04006074 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006075 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006076 {
Geoff Langbfdea662014-07-23 14:16:32 -04006077 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006078 {
Geoff Langb1196682014-07-23 13:47:29 -04006079 context->recordError(gl::Error(GL_INVALID_OPERATION));
6080 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006081 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006082
Geoff Langbfdea662014-07-23 14:16:32 -04006083 if (count < 0)
6084 {
Geoff Langb1196682014-07-23 13:47:29 -04006085 context->recordError(gl::Error(GL_INVALID_VALUE));
6086 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006087 }
6088
Geoff Lang05881a02014-07-10 14:05:30 -04006089 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006090 switch (bufferMode)
6091 {
6092 case GL_INTERLEAVED_ATTRIBS:
6093 break;
6094 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006095 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006096 {
Geoff Langb1196682014-07-23 13:47:29 -04006097 context->recordError(gl::Error(GL_INVALID_VALUE));
6098 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006099 }
Geoff Langbfdea662014-07-23 14:16:32 -04006100 break;
6101 default:
Geoff Langb1196682014-07-23 13:47:29 -04006102 context->recordError(gl::Error(GL_INVALID_ENUM));
6103 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006104 }
Geoff Langbfdea662014-07-23 14:16:32 -04006105
6106 if (!gl::ValidProgram(context, program))
6107 {
6108 return;
6109 }
6110
6111 gl::Program *programObject = context->getProgram(program);
6112 ASSERT(programObject);
6113
6114 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006115 }
6116}
6117
6118void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6119{
6120 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6121 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6122 program, index, bufSize, length, size, type, name);
6123
Geoff Langbfdea662014-07-23 14:16:32 -04006124 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006125 if (context)
6126 {
6127 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006128 {
Geoff Langb1196682014-07-23 13:47:29 -04006129 context->recordError(gl::Error(GL_INVALID_OPERATION));
6130 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006131 }
Geoff Langbfdea662014-07-23 14:16:32 -04006132
6133 if (bufSize < 0)
6134 {
Geoff Langb1196682014-07-23 13:47:29 -04006135 context->recordError(gl::Error(GL_INVALID_VALUE));
6136 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006137 }
6138
6139 if (!gl::ValidProgram(context, program))
6140 {
6141 return;
6142 }
6143
6144 gl::Program *programObject = context->getProgram(program);
6145 ASSERT(programObject);
6146
6147 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6148 {
Geoff Langb1196682014-07-23 13:47:29 -04006149 context->recordError(gl::Error(GL_INVALID_VALUE));
6150 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006151 }
6152
6153 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006154 }
6155}
6156
6157void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6158{
6159 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6160 index, size, type, stride, pointer);
6161
Geoff Langbfdea662014-07-23 14:16:32 -04006162 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006163 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006164 {
Geoff Langbfdea662014-07-23 14:16:32 -04006165 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006166 {
Geoff Langb1196682014-07-23 13:47:29 -04006167 context->recordError(gl::Error(GL_INVALID_OPERATION));
6168 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006169 }
6170
Geoff Langb1196682014-07-23 13:47:29 -04006171 if (index >= gl::MAX_VERTEX_ATTRIBS)
6172 {
6173 context->recordError(gl::Error(GL_INVALID_VALUE));
6174 return;
6175 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006176
Geoff Langb1196682014-07-23 13:47:29 -04006177 if (size < 1 || size > 4)
6178 {
6179 context->recordError(gl::Error(GL_INVALID_VALUE));
6180 return;
6181 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006182
Geoff Langb1196682014-07-23 13:47:29 -04006183 switch (type)
6184 {
6185 case GL_BYTE:
6186 case GL_UNSIGNED_BYTE:
6187 case GL_SHORT:
6188 case GL_UNSIGNED_SHORT:
6189 case GL_INT:
6190 case GL_UNSIGNED_INT:
6191 case GL_INT_2_10_10_10_REV:
6192 case GL_UNSIGNED_INT_2_10_10_10_REV:
6193 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006194
Geoff Langb1196682014-07-23 13:47:29 -04006195 default:
6196 context->recordError(gl::Error(GL_INVALID_ENUM));
6197 return;
6198 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006199
Geoff Langb1196682014-07-23 13:47:29 -04006200 if (stride < 0)
6201 {
6202 context->recordError(gl::Error(GL_INVALID_VALUE));
6203 return;
6204 }
Geoff Langbfdea662014-07-23 14:16:32 -04006205
Geoff Langb1196682014-07-23 13:47:29 -04006206 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6207 {
6208 context->recordError(gl::Error(GL_INVALID_OPERATION));
6209 return;
6210 }
6211
Geoff Langbfdea662014-07-23 14:16:32 -04006212 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6213 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6214 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6215 // and the pointer argument is not NULL.
6216 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006217 {
Geoff Langb1196682014-07-23 13:47:29 -04006218 context->recordError(gl::Error(GL_INVALID_OPERATION));
6219 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006220 }
6221
Geoff Langbfdea662014-07-23 14:16:32 -04006222 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6223 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006224 }
6225}
6226
6227void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6228{
6229 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6230 index, pname, params);
6231
Geoff Langbfdea662014-07-23 14:16:32 -04006232 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006233 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006234 {
Geoff Langbfdea662014-07-23 14:16:32 -04006235 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006236 {
Geoff Langb1196682014-07-23 13:47:29 -04006237 context->recordError(gl::Error(GL_INVALID_OPERATION));
6238 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006239 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006240
Geoff Langbfdea662014-07-23 14:16:32 -04006241 if (index >= gl::MAX_VERTEX_ATTRIBS)
6242 {
Geoff Langb1196682014-07-23 13:47:29 -04006243 context->recordError(gl::Error(GL_INVALID_VALUE));
6244 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006245 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006246
Geoff Langbfdea662014-07-23 14:16:32 -04006247 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006248
Geoff Langb1196682014-07-23 13:47:29 -04006249 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006250 {
6251 return;
6252 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006253
Geoff Langbfdea662014-07-23 14:16:32 -04006254 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6255 {
6256 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6257 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006258 {
Geoff Langbfdea662014-07-23 14:16:32 -04006259 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006260 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006261 }
Geoff Langbfdea662014-07-23 14:16:32 -04006262 else
6263 {
6264 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6265 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006266 }
6267}
6268
6269void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6270{
6271 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6272 index, pname, params);
6273
Geoff Langbfdea662014-07-23 14:16:32 -04006274 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006275 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006276 {
Geoff Langbfdea662014-07-23 14:16:32 -04006277 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006278 {
Geoff Langb1196682014-07-23 13:47:29 -04006279 context->recordError(gl::Error(GL_INVALID_OPERATION));
6280 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006281 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006282
Geoff Langbfdea662014-07-23 14:16:32 -04006283 if (index >= gl::MAX_VERTEX_ATTRIBS)
6284 {
Geoff Langb1196682014-07-23 13:47:29 -04006285 context->recordError(gl::Error(GL_INVALID_VALUE));
6286 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006287 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006288
Geoff Langbfdea662014-07-23 14:16:32 -04006289 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006290
Geoff Langb1196682014-07-23 13:47:29 -04006291 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006292 {
6293 return;
6294 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006295
Geoff Langbfdea662014-07-23 14:16:32 -04006296 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6297 {
6298 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6299 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006300 {
Geoff Langbfdea662014-07-23 14:16:32 -04006301 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006302 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006303 }
Geoff Langbfdea662014-07-23 14:16:32 -04006304 else
6305 {
6306 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6307 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006308 }
6309}
6310
6311void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6312{
6313 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6314 index, x, y, z, w);
6315
Geoff Langbfdea662014-07-23 14:16:32 -04006316 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006317 if (context)
6318 {
6319 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006320 {
Geoff Langb1196682014-07-23 13:47:29 -04006321 context->recordError(gl::Error(GL_INVALID_OPERATION));
6322 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006323 }
Geoff Langbfdea662014-07-23 14:16:32 -04006324
6325 if (index >= gl::MAX_VERTEX_ATTRIBS)
6326 {
Geoff Langb1196682014-07-23 13:47:29 -04006327 context->recordError(gl::Error(GL_INVALID_VALUE));
6328 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006329 }
6330
6331 GLint vals[4] = { x, y, z, w };
6332 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006333 }
6334}
6335
6336void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6337{
6338 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6339 index, x, y, z, w);
6340
Geoff Langbfdea662014-07-23 14:16:32 -04006341 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006342 if (context)
6343 {
6344 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006345 {
Geoff Langb1196682014-07-23 13:47:29 -04006346 context->recordError(gl::Error(GL_INVALID_OPERATION));
6347 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006348 }
Geoff Langbfdea662014-07-23 14:16:32 -04006349
6350 if (index >= gl::MAX_VERTEX_ATTRIBS)
6351 {
Geoff Langb1196682014-07-23 13:47:29 -04006352 context->recordError(gl::Error(GL_INVALID_VALUE));
6353 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006354 }
6355
6356 GLuint vals[4] = { x, y, z, w };
6357 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006358 }
6359}
6360
6361void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6362{
6363 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6364
Geoff Langbfdea662014-07-23 14:16:32 -04006365 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006366 if (context)
6367 {
6368 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006369 {
Geoff Langb1196682014-07-23 13:47:29 -04006370 context->recordError(gl::Error(GL_INVALID_OPERATION));
6371 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006372 }
Geoff Langbfdea662014-07-23 14:16:32 -04006373
6374 if (index >= gl::MAX_VERTEX_ATTRIBS)
6375 {
Geoff Langb1196682014-07-23 13:47:29 -04006376 context->recordError(gl::Error(GL_INVALID_VALUE));
6377 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006378 }
6379
6380 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006381 }
6382}
6383
6384void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6385{
6386 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6387
Geoff Langbfdea662014-07-23 14:16:32 -04006388 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006389 if (context)
6390 {
6391 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006392 {
Geoff Langb1196682014-07-23 13:47:29 -04006393 context->recordError(gl::Error(GL_INVALID_OPERATION));
6394 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006395 }
Geoff Langbfdea662014-07-23 14:16:32 -04006396
6397 if (index >= gl::MAX_VERTEX_ATTRIBS)
6398 {
Geoff Langb1196682014-07-23 13:47:29 -04006399 context->recordError(gl::Error(GL_INVALID_VALUE));
6400 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006401 }
6402
6403 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006404 }
6405}
6406
6407void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6408{
6409 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6410 program, location, params);
6411
Geoff Langbfdea662014-07-23 14:16:32 -04006412 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006413 if (context)
6414 {
Jamie Madill0063c512014-08-25 15:47:53 -04006415 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006416 {
Jamie Madill0063c512014-08-25 15:47:53 -04006417 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006418 }
Geoff Langbfdea662014-07-23 14:16:32 -04006419
Jamie Madilla502c742014-08-28 17:19:13 -04006420 gl::Program *programObject = context->getProgram(program);
6421 ASSERT(programObject);
6422 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006423 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006424
Jamie Madill99a1e982014-08-25 15:47:54 -04006425 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006426 }
6427}
6428
6429GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6430{
6431 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6432 program, name);
6433
Geoff Langbfdea662014-07-23 14:16:32 -04006434 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006435 if (context)
6436 {
6437 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006438 {
Geoff Langb1196682014-07-23 13:47:29 -04006439 context->recordError(gl::Error(GL_INVALID_OPERATION));
6440 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006441 }
Geoff Langbfdea662014-07-23 14:16:32 -04006442
6443 if (program == 0)
6444 {
Geoff Langb1196682014-07-23 13:47:29 -04006445 context->recordError(gl::Error(GL_INVALID_VALUE));
6446 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006447 }
6448
6449 gl::Program *programObject = context->getProgram(program);
6450
6451 if (!programObject || !programObject->isLinked())
6452 {
Geoff Langb1196682014-07-23 13:47:29 -04006453 context->recordError(gl::Error(GL_INVALID_OPERATION));
6454 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006455 }
6456
6457 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6458 if (!programBinary)
6459 {
Geoff Langb1196682014-07-23 13:47:29 -04006460 context->recordError(gl::Error(GL_INVALID_OPERATION));
6461 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006462 }
6463
6464 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006465 }
6466
6467 return 0;
6468}
6469
6470void __stdcall glUniform1ui(GLint location, GLuint v0)
6471{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006472 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006473}
6474
6475void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6476{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006477 const GLuint xy[] = { v0, v1 };
6478 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006479}
6480
6481void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6482{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006483 const GLuint xyz[] = { v0, v1, v2 };
6484 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006485}
6486
6487void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6488{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006489 const GLuint xyzw[] = { v0, v1, v2, v3 };
6490 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006491}
6492
6493void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6494{
6495 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6496 location, count, value);
6497
Geoff Langbfdea662014-07-23 14:16:32 -04006498 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006499 if (context)
6500 {
6501 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006502 {
Geoff Langbfdea662014-07-23 14:16:32 -04006503 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006504 }
Geoff Langbfdea662014-07-23 14:16:32 -04006505
6506 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6507 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006508 }
6509}
6510
6511void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6512{
6513 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6514 location, count, value);
6515
Geoff Langbfdea662014-07-23 14:16:32 -04006516 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006517 if (context)
6518 {
6519 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006520 {
Geoff Langbfdea662014-07-23 14:16:32 -04006521 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006522 }
Geoff Langbfdea662014-07-23 14:16:32 -04006523
6524 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6525 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006526 }
6527}
6528
6529void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6530{
6531 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6532 location, count, value);
6533
Geoff Langbfdea662014-07-23 14:16:32 -04006534 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006535 if (context)
6536 {
6537 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006538 {
Geoff Langbfdea662014-07-23 14:16:32 -04006539 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006540 }
Geoff Langbfdea662014-07-23 14:16:32 -04006541
6542 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6543 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006544 }
6545}
6546
6547void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6548{
6549 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6550 location, count, value);
6551
Geoff Langbfdea662014-07-23 14:16:32 -04006552 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006553 if (context)
6554 {
6555 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006556 {
Geoff Langbfdea662014-07-23 14:16:32 -04006557 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006558 }
Geoff Langbfdea662014-07-23 14:16:32 -04006559
6560 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6561 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006562 }
6563}
6564
6565void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6566{
6567 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6568 buffer, drawbuffer, value);
6569
Geoff Langbfdea662014-07-23 14:16:32 -04006570 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006571 if (context)
6572 {
6573 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006574 {
Geoff Langbfdea662014-07-23 14:16:32 -04006575 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006576 }
Geoff Langbfdea662014-07-23 14:16:32 -04006577
6578 switch (buffer)
6579 {
6580 case GL_COLOR:
6581 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6582 {
Geoff Langb1196682014-07-23 13:47:29 -04006583 context->recordError(gl::Error(GL_INVALID_VALUE));
6584 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006585 }
6586 break;
Geoff Langb1196682014-07-23 13:47:29 -04006587
Geoff Langbfdea662014-07-23 14:16:32 -04006588 case GL_STENCIL:
6589 if (drawbuffer != 0)
6590 {
Geoff Langb1196682014-07-23 13:47:29 -04006591 context->recordError(gl::Error(GL_INVALID_VALUE));
6592 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006593 }
6594 break;
Geoff Langb1196682014-07-23 13:47:29 -04006595
Geoff Langbfdea662014-07-23 14:16:32 -04006596 default:
Geoff Langb1196682014-07-23 13:47:29 -04006597 context->recordError(gl::Error(GL_INVALID_ENUM));
6598 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006599 }
6600
6601 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006602 }
6603}
6604
6605void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6606{
6607 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6608 buffer, drawbuffer, value);
6609
Geoff Langbfdea662014-07-23 14:16:32 -04006610 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006611 if (context)
6612 {
6613 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006614 {
Geoff Langbfdea662014-07-23 14:16:32 -04006615 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006616 }
Geoff Langbfdea662014-07-23 14:16:32 -04006617
6618 switch (buffer)
6619 {
6620 case GL_COLOR:
6621 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6622 {
Geoff Langb1196682014-07-23 13:47:29 -04006623 context->recordError(gl::Error(GL_INVALID_VALUE));
6624 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006625 }
6626 break;
Geoff Langb1196682014-07-23 13:47:29 -04006627
Geoff Langbfdea662014-07-23 14:16:32 -04006628 default:
Geoff Langb1196682014-07-23 13:47:29 -04006629 context->recordError(gl::Error(GL_INVALID_ENUM));
6630 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006631 }
6632
6633 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006634 }
6635}
6636
6637void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6638{
6639 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6640 buffer, drawbuffer, value);
6641
Geoff Langbfdea662014-07-23 14:16:32 -04006642 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006643 if (context)
6644 {
6645 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006646 {
Geoff Langbfdea662014-07-23 14:16:32 -04006647 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006648 }
Geoff Langbfdea662014-07-23 14:16:32 -04006649
6650 switch (buffer)
6651 {
6652 case GL_COLOR:
6653 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6654 {
Geoff Langb1196682014-07-23 13:47:29 -04006655 context->recordError(gl::Error(GL_INVALID_VALUE));
6656 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006657 }
6658 break;
Geoff Langb1196682014-07-23 13:47:29 -04006659
Geoff Langbfdea662014-07-23 14:16:32 -04006660 case GL_DEPTH:
6661 if (drawbuffer != 0)
6662 {
Geoff Langb1196682014-07-23 13:47:29 -04006663 context->recordError(gl::Error(GL_INVALID_VALUE));
6664 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006665 }
6666 break;
Geoff Langb1196682014-07-23 13:47:29 -04006667
Geoff Langbfdea662014-07-23 14:16:32 -04006668 default:
Geoff Langb1196682014-07-23 13:47:29 -04006669 context->recordError(gl::Error(GL_INVALID_ENUM));
6670 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006671 }
6672
6673 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006674 }
6675}
6676
6677void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6678{
6679 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6680 buffer, drawbuffer, depth, stencil);
6681
Geoff Langbfdea662014-07-23 14:16:32 -04006682 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006683 if (context)
6684 {
6685 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006686 {
Geoff Langbfdea662014-07-23 14:16:32 -04006687 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006688 }
Geoff Langbfdea662014-07-23 14:16:32 -04006689
6690 switch (buffer)
6691 {
6692 case GL_DEPTH_STENCIL:
6693 if (drawbuffer != 0)
6694 {
Geoff Langb1196682014-07-23 13:47:29 -04006695 context->recordError(gl::Error(GL_INVALID_VALUE));
6696 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006697 }
6698 break;
Geoff Langb1196682014-07-23 13:47:29 -04006699
Geoff Langbfdea662014-07-23 14:16:32 -04006700 default:
Geoff Langb1196682014-07-23 13:47:29 -04006701 context->recordError(gl::Error(GL_INVALID_ENUM));
6702 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006703 }
6704
6705 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006706 }
6707}
6708
6709const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6710{
6711 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6712
Geoff Langbfdea662014-07-23 14:16:32 -04006713 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006714 if (context)
6715 {
6716 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006717 {
Geoff Langb1196682014-07-23 13:47:29 -04006718 context->recordError(gl::Error(GL_INVALID_OPERATION));
6719 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006720 }
Geoff Langbfdea662014-07-23 14:16:32 -04006721
6722 if (name != GL_EXTENSIONS)
6723 {
Geoff Langb1196682014-07-23 13:47:29 -04006724 context->recordError(gl::Error(GL_INVALID_ENUM));
6725 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006726 }
6727
6728 if (index >= context->getExtensionStringCount())
6729 {
Geoff Langb1196682014-07-23 13:47:29 -04006730 context->recordError(gl::Error(GL_INVALID_VALUE));
6731 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006732 }
6733
6734 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006735 }
6736
6737 return NULL;
6738}
6739
6740void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6741{
6742 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6743 readTarget, writeTarget, readOffset, writeOffset, size);
6744
Geoff Langbfdea662014-07-23 14:16:32 -04006745 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006746 if (context)
6747 {
6748 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006749 {
Geoff Langb1196682014-07-23 13:47:29 -04006750 context->recordError(gl::Error(GL_INVALID_OPERATION));
6751 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006752 }
Geoff Langbfdea662014-07-23 14:16:32 -04006753
6754 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6755 {
Geoff Langb1196682014-07-23 13:47:29 -04006756 context->recordError(gl::Error(GL_INVALID_ENUM));
6757 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006758 }
6759
6760 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6761 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6762
6763 if (!readBuffer || !writeBuffer)
6764 {
Geoff Langb1196682014-07-23 13:47:29 -04006765 context->recordError(gl::Error(GL_INVALID_OPERATION));
6766 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006767 }
6768
Jamie Madillcfaaf722014-07-31 10:47:54 -04006769 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006770 if (readBuffer->isMapped() || writeBuffer->isMapped())
6771 {
Geoff Langb1196682014-07-23 13:47:29 -04006772 context->recordError(gl::Error(GL_INVALID_OPERATION));
6773 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006774 }
6775
6776 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6777 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6778 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6779 {
Geoff Langb1196682014-07-23 13:47:29 -04006780 context->recordError(gl::Error(GL_INVALID_VALUE));
6781 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006782 }
6783
6784 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6785 {
Geoff Langb1196682014-07-23 13:47:29 -04006786 context->recordError(gl::Error(GL_INVALID_VALUE));
6787 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006788 }
6789
Geoff Langbfdea662014-07-23 14:16:32 -04006790 // if size is zero, the copy is a successful no-op
6791 if (size > 0)
6792 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006793 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6794 if (error.isError())
6795 {
6796 context->recordError(error);
6797 return;
6798 }
Geoff Langbfdea662014-07-23 14:16:32 -04006799 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006800 }
6801}
6802
6803void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6804{
6805 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6806 program, uniformCount, uniformNames, uniformIndices);
6807
Geoff Langbfdea662014-07-23 14:16:32 -04006808 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006809 if (context)
6810 {
6811 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006812 {
Geoff Langb1196682014-07-23 13:47:29 -04006813 context->recordError(gl::Error(GL_INVALID_OPERATION));
6814 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006815 }
6816
6817 if (uniformCount < 0)
6818 {
Geoff Langb1196682014-07-23 13:47:29 -04006819 context->recordError(gl::Error(GL_INVALID_VALUE));
6820 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006821 }
6822
6823 gl::Program *programObject = context->getProgram(program);
6824
6825 if (!programObject)
6826 {
6827 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006828 {
Geoff Langb1196682014-07-23 13:47:29 -04006829 context->recordError(gl::Error(GL_INVALID_OPERATION));
6830 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006831 }
Geoff Langbfdea662014-07-23 14:16:32 -04006832 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006833 {
Geoff Langb1196682014-07-23 13:47:29 -04006834 context->recordError(gl::Error(GL_INVALID_VALUE));
6835 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006836 }
Geoff Langbfdea662014-07-23 14:16:32 -04006837 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006838
Geoff Langbfdea662014-07-23 14:16:32 -04006839 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6840 if (!programObject->isLinked() || !programBinary)
6841 {
6842 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006843 {
Geoff Langbfdea662014-07-23 14:16:32 -04006844 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006845 }
6846 }
Geoff Langbfdea662014-07-23 14:16:32 -04006847 else
6848 {
6849 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6850 {
6851 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6852 }
6853 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006854 }
6855}
6856
6857void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6858{
6859 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6860 program, uniformCount, uniformIndices, pname, params);
6861
Geoff Langbfdea662014-07-23 14:16:32 -04006862 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006863 if (context)
6864 {
6865 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006866 {
Geoff Langb1196682014-07-23 13:47:29 -04006867 context->recordError(gl::Error(GL_INVALID_OPERATION));
6868 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006869 }
6870
6871 if (uniformCount < 0)
6872 {
Geoff Langb1196682014-07-23 13:47:29 -04006873 context->recordError(gl::Error(GL_INVALID_VALUE));
6874 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006875 }
6876
6877 gl::Program *programObject = context->getProgram(program);
6878
6879 if (!programObject)
6880 {
6881 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006882 {
Geoff Langb1196682014-07-23 13:47:29 -04006883 context->recordError(gl::Error(GL_INVALID_OPERATION));
6884 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006885 }
Geoff Langbfdea662014-07-23 14:16:32 -04006886 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006887 {
Geoff Langb1196682014-07-23 13:47:29 -04006888 context->recordError(gl::Error(GL_INVALID_VALUE));
6889 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006890 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006891 }
Geoff Langbfdea662014-07-23 14:16:32 -04006892
6893 switch (pname)
6894 {
6895 case GL_UNIFORM_TYPE:
6896 case GL_UNIFORM_SIZE:
6897 case GL_UNIFORM_NAME_LENGTH:
6898 case GL_UNIFORM_BLOCK_INDEX:
6899 case GL_UNIFORM_OFFSET:
6900 case GL_UNIFORM_ARRAY_STRIDE:
6901 case GL_UNIFORM_MATRIX_STRIDE:
6902 case GL_UNIFORM_IS_ROW_MAJOR:
6903 break;
Geoff Langb1196682014-07-23 13:47:29 -04006904
Geoff Langbfdea662014-07-23 14:16:32 -04006905 default:
Geoff Langb1196682014-07-23 13:47:29 -04006906 context->recordError(gl::Error(GL_INVALID_ENUM));
6907 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006908 }
6909
6910 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6911
6912 if (!programBinary && uniformCount > 0)
6913 {
Geoff Langb1196682014-07-23 13:47:29 -04006914 context->recordError(gl::Error(GL_INVALID_VALUE));
6915 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006916 }
6917
6918 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6919 {
6920 const GLuint index = uniformIndices[uniformId];
6921
6922 if (index >= (GLuint)programBinary->getActiveUniformCount())
6923 {
Geoff Langb1196682014-07-23 13:47:29 -04006924 context->recordError(gl::Error(GL_INVALID_VALUE));
6925 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006926 }
6927 }
6928
6929 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6930 {
6931 const GLuint index = uniformIndices[uniformId];
6932 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6933 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006934 }
6935}
6936
6937GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6938{
6939 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6940
Geoff Langbfdea662014-07-23 14:16:32 -04006941 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006942 if (context)
6943 {
6944 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006945 {
Geoff Langb1196682014-07-23 13:47:29 -04006946 context->recordError(gl::Error(GL_INVALID_OPERATION));
6947 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04006948 }
6949
6950 gl::Program *programObject = context->getProgram(program);
6951
6952 if (!programObject)
6953 {
6954 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006955 {
Geoff Langb1196682014-07-23 13:47:29 -04006956 context->recordError(gl::Error(GL_INVALID_OPERATION));
6957 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006958 }
Geoff Langbfdea662014-07-23 14:16:32 -04006959 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006960 {
Geoff Langb1196682014-07-23 13:47:29 -04006961 context->recordError(gl::Error(GL_INVALID_VALUE));
6962 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006963 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006964 }
Geoff Langbfdea662014-07-23 14:16:32 -04006965
6966 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6967 if (!programBinary)
6968 {
6969 return GL_INVALID_INDEX;
6970 }
6971
6972 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006973 }
6974
6975 return 0;
6976}
6977
6978void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6979{
6980 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6981 program, uniformBlockIndex, pname, params);
6982
Geoff Langbfdea662014-07-23 14:16:32 -04006983 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006984 if (context)
6985 {
6986 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006987 {
Geoff Langb1196682014-07-23 13:47:29 -04006988 context->recordError(gl::Error(GL_INVALID_OPERATION));
6989 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006990 }
6991 gl::Program *programObject = context->getProgram(program);
6992
6993 if (!programObject)
6994 {
6995 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006996 {
Geoff Langb1196682014-07-23 13:47:29 -04006997 context->recordError(gl::Error(GL_INVALID_OPERATION));
6998 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006999 }
Geoff Langbfdea662014-07-23 14:16:32 -04007000 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007001 {
Geoff Langb1196682014-07-23 13:47:29 -04007002 context->recordError(gl::Error(GL_INVALID_VALUE));
7003 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007004 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007005 }
Geoff Langbfdea662014-07-23 14:16:32 -04007006
7007 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7008
7009 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7010 {
Geoff Langb1196682014-07-23 13:47:29 -04007011 context->recordError(gl::Error(GL_INVALID_VALUE));
7012 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007013 }
7014
7015 switch (pname)
7016 {
7017 case GL_UNIFORM_BLOCK_BINDING:
7018 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7019 break;
7020
7021 case GL_UNIFORM_BLOCK_DATA_SIZE:
7022 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7023 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7024 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7025 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7026 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7027 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7028 break;
7029
7030 default:
Geoff Langb1196682014-07-23 13:47:29 -04007031 context->recordError(gl::Error(GL_INVALID_ENUM));
7032 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007033 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007034 }
7035}
7036
7037void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7038{
7039 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7040 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7041
Geoff Langbfdea662014-07-23 14:16:32 -04007042 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007043 if (context)
7044 {
7045 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007046 {
Geoff Langb1196682014-07-23 13:47:29 -04007047 context->recordError(gl::Error(GL_INVALID_OPERATION));
7048 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007049 }
7050
7051 gl::Program *programObject = context->getProgram(program);
7052
7053 if (!programObject)
7054 {
7055 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007056 {
Geoff Langb1196682014-07-23 13:47:29 -04007057 context->recordError(gl::Error(GL_INVALID_OPERATION));
7058 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007059 }
Geoff Langbfdea662014-07-23 14:16:32 -04007060 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007061 {
Geoff Langb1196682014-07-23 13:47:29 -04007062 context->recordError(gl::Error(GL_INVALID_VALUE));
7063 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007064 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007065 }
Geoff Langbfdea662014-07-23 14:16:32 -04007066
7067 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7068
7069 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7070 {
Geoff Langb1196682014-07-23 13:47:29 -04007071 context->recordError(gl::Error(GL_INVALID_VALUE));
7072 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007073 }
7074
7075 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007076 }
7077}
7078
7079void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7080{
7081 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7082 program, uniformBlockIndex, uniformBlockBinding);
7083
Geoff Langbfdea662014-07-23 14:16:32 -04007084 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007085 if (context)
7086 {
7087 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007088 {
Geoff Langb1196682014-07-23 13:47:29 -04007089 context->recordError(gl::Error(GL_INVALID_OPERATION));
7090 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007091 }
7092
Geoff Lang3a61c322014-07-10 13:01:54 -04007093 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007094 {
Geoff Langb1196682014-07-23 13:47:29 -04007095 context->recordError(gl::Error(GL_INVALID_VALUE));
7096 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007097 }
7098
7099 gl::Program *programObject = context->getProgram(program);
7100
7101 if (!programObject)
7102 {
7103 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007104 {
Geoff Langb1196682014-07-23 13:47:29 -04007105 context->recordError(gl::Error(GL_INVALID_OPERATION));
7106 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007107 }
Geoff Langbfdea662014-07-23 14:16:32 -04007108 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007109 {
Geoff Langb1196682014-07-23 13:47:29 -04007110 context->recordError(gl::Error(GL_INVALID_VALUE));
7111 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007112 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007113 }
Geoff Langbfdea662014-07-23 14:16:32 -04007114
7115 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7116
7117 // if never linked, there won't be any uniform blocks
7118 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7119 {
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 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007125 }
7126}
7127
7128void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7129{
7130 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7131 mode, first, count, instanceCount);
7132
Geoff Langbfdea662014-07-23 14:16:32 -04007133 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007134 if (context)
7135 {
7136 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007137 {
Geoff Langb1196682014-07-23 13:47:29 -04007138 context->recordError(gl::Error(GL_INVALID_OPERATION));
7139 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007140 }
Geoff Langbfdea662014-07-23 14:16:32 -04007141
7142 // glDrawArraysInstanced
7143 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007144 }
7145}
7146
7147void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7148{
7149 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7150 mode, count, type, indices, instanceCount);
7151
Geoff Langbfdea662014-07-23 14:16:32 -04007152 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007153 if (context)
7154 {
7155 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007156 {
Geoff Langb1196682014-07-23 13:47:29 -04007157 context->recordError(gl::Error(GL_INVALID_OPERATION));
7158 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007159 }
Geoff Langbfdea662014-07-23 14:16:32 -04007160
7161 // glDrawElementsInstanced
7162 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007163 }
7164}
7165
7166GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7167{
7168 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7169
Geoff Langbfdea662014-07-23 14:16:32 -04007170 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007171 if (context)
7172 {
7173 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007174 {
Geoff Langb1196682014-07-23 13:47:29 -04007175 context->recordError(gl::Error(GL_INVALID_OPERATION));
7176 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007177 }
Geoff Langbfdea662014-07-23 14:16:32 -04007178
7179 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7180 {
Geoff Langb1196682014-07-23 13:47:29 -04007181 context->recordError(gl::Error(GL_INVALID_ENUM));
7182 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007183 }
7184
7185 if (flags != 0)
7186 {
Geoff Langb1196682014-07-23 13:47:29 -04007187 context->recordError(gl::Error(GL_INVALID_VALUE));
7188 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007189 }
7190
7191 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007192 }
7193
7194 return NULL;
7195}
7196
7197GLboolean __stdcall glIsSync(GLsync sync)
7198{
7199 EVENT("(GLsync sync = 0x%0.8p)", sync);
7200
Geoff Langbfdea662014-07-23 14:16:32 -04007201 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007202 if (context)
7203 {
7204 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007205 {
Geoff Langb1196682014-07-23 13:47:29 -04007206 context->recordError(gl::Error(GL_INVALID_OPERATION));
7207 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007208 }
Geoff Langbfdea662014-07-23 14:16:32 -04007209
7210 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007211 }
7212
7213 return GL_FALSE;
7214}
7215
7216void __stdcall glDeleteSync(GLsync sync)
7217{
7218 EVENT("(GLsync sync = 0x%0.8p)", sync);
7219
Geoff Langbfdea662014-07-23 14:16:32 -04007220 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007221 if (context)
7222 {
7223 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007224 {
Geoff Langb1196682014-07-23 13:47:29 -04007225 context->recordError(gl::Error(GL_INVALID_OPERATION));
7226 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007227 }
Geoff Langbfdea662014-07-23 14:16:32 -04007228
7229 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7230 {
Geoff Langb1196682014-07-23 13:47:29 -04007231 context->recordError(gl::Error(GL_INVALID_VALUE));
7232 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007233 }
7234
7235 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007236 }
7237}
7238
7239GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7240{
7241 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7242 sync, flags, timeout);
7243
Geoff Langbfdea662014-07-23 14:16:32 -04007244 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007245 if (context)
7246 {
7247 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007248 {
Geoff Langb1196682014-07-23 13:47:29 -04007249 context->recordError(gl::Error(GL_INVALID_OPERATION));
7250 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007251 }
Geoff Langbfdea662014-07-23 14:16:32 -04007252
7253 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7254 {
Geoff Langb1196682014-07-23 13:47:29 -04007255 context->recordError(gl::Error(GL_INVALID_VALUE));
7256 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007257 }
7258
7259 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7260
7261 if (!fenceSync)
7262 {
Geoff Langb1196682014-07-23 13:47:29 -04007263 context->recordError(gl::Error(GL_INVALID_VALUE));
7264 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007265 }
7266
7267 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007268 }
7269
7270 return GL_FALSE;
7271}
7272
7273void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7274{
7275 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7276 sync, flags, timeout);
7277
Geoff Langbfdea662014-07-23 14:16:32 -04007278 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007279 if (context)
7280 {
7281 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007282 {
Geoff Langb1196682014-07-23 13:47:29 -04007283 context->recordError(gl::Error(GL_INVALID_OPERATION));
7284 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007285 }
Geoff Langbfdea662014-07-23 14:16:32 -04007286
7287 if (flags != 0)
7288 {
Geoff Langb1196682014-07-23 13:47:29 -04007289 context->recordError(gl::Error(GL_INVALID_VALUE));
7290 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007291 }
7292
7293 if (timeout != GL_TIMEOUT_IGNORED)
7294 {
Geoff Langb1196682014-07-23 13:47:29 -04007295 context->recordError(gl::Error(GL_INVALID_VALUE));
7296 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007297 }
7298
7299 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7300
7301 if (!fenceSync)
7302 {
Geoff Langb1196682014-07-23 13:47:29 -04007303 context->recordError(gl::Error(GL_INVALID_VALUE));
7304 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007305 }
7306
7307 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007308 }
7309}
7310
7311void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7312{
7313 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7314 pname, params);
7315
Geoff Langbfdea662014-07-23 14:16:32 -04007316 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007317 if (context)
7318 {
7319 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007320 {
Geoff Langb1196682014-07-23 13:47:29 -04007321 context->recordError(gl::Error(GL_INVALID_OPERATION));
7322 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007323 }
Geoff Langbfdea662014-07-23 14:16:32 -04007324
7325 GLenum nativeType;
7326 unsigned int numParams = 0;
7327 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7328 {
7329 return;
7330 }
7331
7332 if (nativeType == GL_INT_64_ANGLEX)
7333 {
7334 context->getInteger64v(pname, params);
7335 }
7336 else
7337 {
7338 CastStateValues(context, nativeType, pname, numParams, params);
7339 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007340 }
7341}
7342
7343void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7344{
7345 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7346 sync, pname, bufSize, length, values);
7347
Geoff Langbfdea662014-07-23 14:16:32 -04007348 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007349 if (context)
7350 {
7351 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007352 {
Geoff Langb1196682014-07-23 13:47:29 -04007353 context->recordError(gl::Error(GL_INVALID_OPERATION));
7354 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007355 }
Geoff Langbfdea662014-07-23 14:16:32 -04007356
7357 if (bufSize < 0)
7358 {
Geoff Langb1196682014-07-23 13:47:29 -04007359 context->recordError(gl::Error(GL_INVALID_VALUE));
7360 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007361 }
7362
7363 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7364
7365 if (!fenceSync)
7366 {
Geoff Langb1196682014-07-23 13:47:29 -04007367 context->recordError(gl::Error(GL_INVALID_VALUE));
7368 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007369 }
7370
7371 switch (pname)
7372 {
7373 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7374 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7375 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7376 case GL_SYNC_FLAGS: values[0] = 0; break;
7377
7378 default:
Geoff Langb1196682014-07-23 13:47:29 -04007379 context->recordError(gl::Error(GL_INVALID_ENUM));
7380 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007381 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007382 }
7383}
7384
7385void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7386{
7387 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7388 target, index, data);
7389
Geoff Langbfdea662014-07-23 14:16:32 -04007390 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007391 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007392 {
Geoff Langbfdea662014-07-23 14:16:32 -04007393 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007394 {
Geoff Langb1196682014-07-23 13:47:29 -04007395 context->recordError(gl::Error(GL_INVALID_OPERATION));
7396 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007397 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007398
Geoff Lang3a61c322014-07-10 13:01:54 -04007399 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007400 switch (target)
7401 {
7402 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7403 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7404 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007405 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7406 {
Geoff Langb1196682014-07-23 13:47:29 -04007407 context->recordError(gl::Error(GL_INVALID_VALUE));
7408 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007409 }
Geoff Langbfdea662014-07-23 14:16:32 -04007410 break;
Geoff Langb1196682014-07-23 13:47:29 -04007411
Geoff Langbfdea662014-07-23 14:16:32 -04007412 case GL_UNIFORM_BUFFER_START:
7413 case GL_UNIFORM_BUFFER_SIZE:
7414 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007415 if (index >= caps.maxUniformBufferBindings)
7416 {
Geoff Langb1196682014-07-23 13:47:29 -04007417 context->recordError(gl::Error(GL_INVALID_VALUE));
7418 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007419 }
Geoff Langbfdea662014-07-23 14:16:32 -04007420 break;
Geoff Langb1196682014-07-23 13:47:29 -04007421
Geoff Langbfdea662014-07-23 14:16:32 -04007422 default:
Geoff Langb1196682014-07-23 13:47:29 -04007423 context->recordError(gl::Error(GL_INVALID_ENUM));
7424 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007425 }
7426
7427 if (!(context->getIndexedInteger64v(target, index, data)))
7428 {
7429 GLenum nativeType;
7430 unsigned int numParams = 0;
7431 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007432 {
7433 context->recordError(gl::Error(GL_INVALID_ENUM));
7434 return;
7435 }
Shannon Woods15934d52013-08-19 14:28:49 -04007436
Geoff Langbfdea662014-07-23 14:16:32 -04007437 if (numParams == 0)
7438 return; // it is known that pname is valid, but there are no parameters to return
7439
7440 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007441 {
Geoff Langbfdea662014-07-23 14:16:32 -04007442 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007443
Geoff Langbfdea662014-07-23 14:16:32 -04007444 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007445
Geoff Langbfdea662014-07-23 14:16:32 -04007446 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007447 {
Geoff Langbfdea662014-07-23 14:16:32 -04007448 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007449 }
Geoff Langbfdea662014-07-23 14:16:32 -04007450
7451 delete [] intParams;
7452 }
7453 else
7454 {
7455 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007456 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007457 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007458 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007459}
7460
7461void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7462{
7463 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7464 target, pname, params);
7465
Geoff Langbfdea662014-07-23 14:16:32 -04007466 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007467 if (context)
7468 {
7469 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007470 {
Geoff Langb1196682014-07-23 13:47:29 -04007471 context->recordError(gl::Error(GL_INVALID_OPERATION));
7472 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007473 }
Geoff Langbfdea662014-07-23 14:16:32 -04007474
7475 if (!gl::ValidBufferTarget(context, target))
7476 {
Geoff Langb1196682014-07-23 13:47:29 -04007477 context->recordError(gl::Error(GL_INVALID_ENUM));
7478 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007479 }
7480
7481 if (!gl::ValidBufferParameter(context, pname))
7482 {
Geoff Langb1196682014-07-23 13:47:29 -04007483 context->recordError(gl::Error(GL_INVALID_ENUM));
7484 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007485 }
7486
7487 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7488
7489 if (!buffer)
7490 {
7491 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007492 context->recordError(gl::Error(GL_INVALID_OPERATION));
7493 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007494 }
7495
7496 switch (pname)
7497 {
7498 case GL_BUFFER_USAGE:
7499 *params = static_cast<GLint64>(buffer->getUsage());
7500 break;
7501 case GL_BUFFER_SIZE:
7502 *params = buffer->getSize();
7503 break;
7504 case GL_BUFFER_ACCESS_FLAGS:
7505 *params = static_cast<GLint64>(buffer->getAccessFlags());
7506 break;
7507 case GL_BUFFER_MAPPED:
7508 *params = static_cast<GLint64>(buffer->isMapped());
7509 break;
7510 case GL_BUFFER_MAP_OFFSET:
7511 *params = buffer->getMapOffset();
7512 break;
7513 case GL_BUFFER_MAP_LENGTH:
7514 *params = buffer->getMapLength();
7515 break;
7516 default: UNREACHABLE(); break;
7517 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007518 }
7519}
7520
7521void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7522{
7523 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7524
Geoff Langbfdea662014-07-23 14:16:32 -04007525 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007526 if (context)
7527 {
7528 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007529 {
Geoff Langb1196682014-07-23 13:47:29 -04007530 context->recordError(gl::Error(GL_INVALID_OPERATION));
7531 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007532 }
Geoff Langbfdea662014-07-23 14:16:32 -04007533
7534 if (count < 0)
7535 {
Geoff Langb1196682014-07-23 13:47:29 -04007536 context->recordError(gl::Error(GL_INVALID_VALUE));
7537 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007538 }
7539
7540 for (int i = 0; i < count; i++)
7541 {
7542 samplers[i] = context->createSampler();
7543 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007544 }
7545}
7546
7547void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7548{
7549 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7550
Geoff Langbfdea662014-07-23 14:16:32 -04007551 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007552 if (context)
7553 {
7554 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007555 {
Geoff Langb1196682014-07-23 13:47:29 -04007556 context->recordError(gl::Error(GL_INVALID_OPERATION));
7557 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007558 }
Geoff Langbfdea662014-07-23 14:16:32 -04007559
7560 if (count < 0)
7561 {
Geoff Langb1196682014-07-23 13:47:29 -04007562 context->recordError(gl::Error(GL_INVALID_VALUE));
7563 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007564 }
7565
7566 for (int i = 0; i < count; i++)
7567 {
7568 context->deleteSampler(samplers[i]);
7569 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007570 }
7571}
7572
7573GLboolean __stdcall glIsSampler(GLuint sampler)
7574{
7575 EVENT("(GLuint sampler = %u)", sampler);
7576
Geoff Langbfdea662014-07-23 14:16:32 -04007577 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007578 if (context)
7579 {
7580 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007581 {
Geoff Langb1196682014-07-23 13:47:29 -04007582 context->recordError(gl::Error(GL_INVALID_OPERATION));
7583 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007584 }
Geoff Langbfdea662014-07-23 14:16:32 -04007585
7586 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007587 }
7588
7589 return GL_FALSE;
7590}
7591
7592void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7593{
7594 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7595
Geoff Langbfdea662014-07-23 14:16:32 -04007596 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007597 if (context)
7598 {
7599 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007600 {
Geoff Langb1196682014-07-23 13:47:29 -04007601 context->recordError(gl::Error(GL_INVALID_OPERATION));
7602 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007603 }
Geoff Langbfdea662014-07-23 14:16:32 -04007604
7605 if (sampler != 0 && !context->isSampler(sampler))
7606 {
Geoff Langb1196682014-07-23 13:47:29 -04007607 context->recordError(gl::Error(GL_INVALID_OPERATION));
7608 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007609 }
7610
Geoff Lang3a61c322014-07-10 13:01:54 -04007611 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007612 {
Geoff Langb1196682014-07-23 13:47:29 -04007613 context->recordError(gl::Error(GL_INVALID_VALUE));
7614 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007615 }
7616
7617 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007618 }
7619}
7620
7621void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7622{
7623 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7624
Geoff Langbfdea662014-07-23 14:16:32 -04007625 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007626 if (context)
7627 {
7628 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007629 {
Geoff Langb1196682014-07-23 13:47:29 -04007630 context->recordError(gl::Error(GL_INVALID_OPERATION));
7631 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007632 }
Geoff Langbfdea662014-07-23 14:16:32 -04007633
Geoff Langb1196682014-07-23 13:47:29 -04007634 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007635 {
7636 return;
7637 }
7638
7639 if (!gl::ValidateTexParamParameters(context, pname, param))
7640 {
7641 return;
7642 }
7643
7644 if (!context->isSampler(sampler))
7645 {
Geoff Langb1196682014-07-23 13:47:29 -04007646 context->recordError(gl::Error(GL_INVALID_OPERATION));
7647 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007648 }
7649
7650 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007651 }
7652}
7653
7654void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7655{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007656 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007657}
7658
7659void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7660{
7661 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7662
Geoff Langbfdea662014-07-23 14:16:32 -04007663 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007664 if (context)
7665 {
7666 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007667 {
Geoff Langb1196682014-07-23 13:47:29 -04007668 context->recordError(gl::Error(GL_INVALID_OPERATION));
7669 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007670 }
Geoff Langbfdea662014-07-23 14:16:32 -04007671
Geoff Langb1196682014-07-23 13:47:29 -04007672 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007673 {
7674 return;
7675 }
7676
7677 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7678 {
7679 return;
7680 }
7681
7682 if (!context->isSampler(sampler))
7683 {
Geoff Langb1196682014-07-23 13:47:29 -04007684 context->recordError(gl::Error(GL_INVALID_OPERATION));
7685 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007686 }
7687
7688 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007689 }
7690}
7691
7692void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7693{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007694 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007695}
7696
7697void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7698{
7699 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7700
Geoff Langbfdea662014-07-23 14:16:32 -04007701 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007702 if (context)
7703 {
7704 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007705 {
Geoff Langb1196682014-07-23 13:47:29 -04007706 context->recordError(gl::Error(GL_INVALID_OPERATION));
7707 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007708 }
Geoff Langbfdea662014-07-23 14:16:32 -04007709
Geoff Langb1196682014-07-23 13:47:29 -04007710 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007711 {
7712 return;
7713 }
7714
7715 if (!context->isSampler(sampler))
7716 {
Geoff Langb1196682014-07-23 13:47:29 -04007717 context->recordError(gl::Error(GL_INVALID_OPERATION));
7718 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007719 }
7720
7721 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007722 }
7723}
7724
7725void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7726{
7727 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7728
Geoff Langbfdea662014-07-23 14:16:32 -04007729 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007730 if (context)
7731 {
7732 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007733 {
Geoff Langb1196682014-07-23 13:47:29 -04007734 context->recordError(gl::Error(GL_INVALID_OPERATION));
7735 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007736 }
Geoff Langbfdea662014-07-23 14:16:32 -04007737
Geoff Langb1196682014-07-23 13:47:29 -04007738 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007739 {
7740 return;
7741 }
7742
7743 if (!context->isSampler(sampler))
7744 {
Geoff Langb1196682014-07-23 13:47:29 -04007745 context->recordError(gl::Error(GL_INVALID_OPERATION));
7746 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007747 }
7748
7749 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007750 }
7751}
7752
7753void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7754{
7755 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7756
Geoff Langbfdea662014-07-23 14:16:32 -04007757 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007758 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007759 {
Geoff Langbfdea662014-07-23 14:16:32 -04007760 if (context->getClientVersion() < 3)
7761 {
Geoff Langb1196682014-07-23 13:47:29 -04007762 context->recordError(gl::Error(GL_INVALID_OPERATION));
7763 return;
7764 }
7765
7766 if (index >= gl::MAX_VERTEX_ATTRIBS)
7767 {
7768 context->recordError(gl::Error(GL_INVALID_VALUE));
7769 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007770 }
7771
7772 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007773 }
7774}
7775
7776void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7777{
7778 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7779
Geoff Langbfdea662014-07-23 14:16:32 -04007780 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007781 if (context)
7782 {
7783 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007784 {
Geoff Langb1196682014-07-23 13:47:29 -04007785 context->recordError(gl::Error(GL_INVALID_OPERATION));
7786 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007787 }
Geoff Langbfdea662014-07-23 14:16:32 -04007788
7789 switch (target)
7790 {
7791 case GL_TRANSFORM_FEEDBACK:
7792 {
7793 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7794 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7795 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7796 {
Geoff Langb1196682014-07-23 13:47:29 -04007797 context->recordError(gl::Error(GL_INVALID_OPERATION));
7798 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007799 }
7800
7801 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7802 if (context->getTransformFeedback(id) == NULL)
7803 {
Geoff Langb1196682014-07-23 13:47:29 -04007804 context->recordError(gl::Error(GL_INVALID_OPERATION));
7805 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007806 }
7807
7808 context->bindTransformFeedback(id);
7809 }
7810 break;
7811
7812 default:
Geoff Langb1196682014-07-23 13:47:29 -04007813 context->recordError(gl::Error(GL_INVALID_ENUM));
7814 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007815 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007816 }
7817}
7818
7819void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7820{
7821 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7822
Geoff Langbfdea662014-07-23 14:16:32 -04007823 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007824 if (context)
7825 {
7826 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007827 {
Geoff Langb1196682014-07-23 13:47:29 -04007828 context->recordError(gl::Error(GL_INVALID_OPERATION));
7829 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007830 }
Geoff Langbfdea662014-07-23 14:16:32 -04007831
7832 for (int i = 0; i < n; i++)
7833 {
7834 context->deleteTransformFeedback(ids[i]);
7835 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007836 }
7837}
7838
7839void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7840{
7841 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7842
Geoff Langbfdea662014-07-23 14:16:32 -04007843 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007844 if (context)
7845 {
7846 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007847 {
Geoff Langb1196682014-07-23 13:47:29 -04007848 context->recordError(gl::Error(GL_INVALID_OPERATION));
7849 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007850 }
Geoff Langbfdea662014-07-23 14:16:32 -04007851
7852 for (int i = 0; i < n; i++)
7853 {
7854 ids[i] = context->createTransformFeedback();
7855 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007856 }
7857}
7858
7859GLboolean __stdcall glIsTransformFeedback(GLuint id)
7860{
7861 EVENT("(GLuint id = %u)", id);
7862
Geoff Langbfdea662014-07-23 14:16:32 -04007863 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007864 if (context)
7865 {
7866 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007867 {
Geoff Langb1196682014-07-23 13:47:29 -04007868 context->recordError(gl::Error(GL_INVALID_OPERATION));
7869 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007870 }
Geoff Langbfdea662014-07-23 14:16:32 -04007871
7872 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007873 }
7874
7875 return GL_FALSE;
7876}
7877
7878void __stdcall glPauseTransformFeedback(void)
7879{
7880 EVENT("(void)");
7881
Geoff Langbfdea662014-07-23 14:16:32 -04007882 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007883 if (context)
7884 {
7885 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007886 {
Geoff Langb1196682014-07-23 13:47:29 -04007887 context->recordError(gl::Error(GL_INVALID_OPERATION));
7888 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007889 }
Geoff Langbfdea662014-07-23 14:16:32 -04007890
7891 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7892 ASSERT(transformFeedback != NULL);
7893
7894 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7895 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7896 {
Geoff Langb1196682014-07-23 13:47:29 -04007897 context->recordError(gl::Error(GL_INVALID_OPERATION));
7898 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007899 }
7900
7901 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007902 }
7903}
7904
7905void __stdcall glResumeTransformFeedback(void)
7906{
7907 EVENT("(void)");
7908
Geoff Langbfdea662014-07-23 14:16:32 -04007909 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007910 if (context)
7911 {
7912 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007913 {
Geoff Langb1196682014-07-23 13:47:29 -04007914 context->recordError(gl::Error(GL_INVALID_OPERATION));
7915 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007916 }
Geoff Langbfdea662014-07-23 14:16:32 -04007917
7918 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7919 ASSERT(transformFeedback != NULL);
7920
7921 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7922 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7923 {
Geoff Langb1196682014-07-23 13:47:29 -04007924 context->recordError(gl::Error(GL_INVALID_OPERATION));
7925 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007926 }
7927
7928 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007929 }
7930}
7931
7932void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7933{
7934 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7935 program, bufSize, length, binaryFormat, binary);
7936
Geoff Langbfdea662014-07-23 14:16:32 -04007937 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007938 if (context)
7939 {
7940 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007941 {
Geoff Langb1196682014-07-23 13:47:29 -04007942 context->recordError(gl::Error(GL_INVALID_OPERATION));
7943 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007944 }
Geoff Langbfdea662014-07-23 14:16:32 -04007945
7946 // glGetProgramBinary
7947 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007948 }
7949}
7950
7951void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7952{
7953 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7954 program, binaryFormat, binary, length);
7955
Geoff Langbfdea662014-07-23 14:16:32 -04007956 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007957 if (context)
7958 {
7959 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007960 {
Geoff Langb1196682014-07-23 13:47:29 -04007961 context->recordError(gl::Error(GL_INVALID_OPERATION));
7962 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007963 }
Geoff Langbfdea662014-07-23 14:16:32 -04007964
7965 // glProgramBinary
7966 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007967 }
7968}
7969
7970void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7971{
7972 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7973 program, pname, value);
7974
Geoff Langbfdea662014-07-23 14:16:32 -04007975 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007976 if (context)
7977 {
7978 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007979 {
Geoff Langb1196682014-07-23 13:47:29 -04007980 context->recordError(gl::Error(GL_INVALID_OPERATION));
7981 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007982 }
Geoff Langbfdea662014-07-23 14:16:32 -04007983
7984 // glProgramParameteri
7985 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007986 }
7987}
7988
7989void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7990{
7991 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7992 target, numAttachments, attachments);
7993
Geoff Langbfdea662014-07-23 14:16:32 -04007994 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007995 if (context)
7996 {
7997 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007998 {
Geoff Langb1196682014-07-23 13:47:29 -04007999 context->recordError(gl::Error(GL_INVALID_OPERATION));
8000 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008001 }
Geoff Langbfdea662014-07-23 14:16:32 -04008002
8003 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8004 {
8005 return;
8006 }
8007
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008008 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8009 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8010 {
8011 framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8012 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008013 }
8014}
8015
8016void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
8017{
8018 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8019 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8020 target, numAttachments, attachments, x, y, width, height);
8021
Geoff Langbfdea662014-07-23 14:16:32 -04008022 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008023 if (context)
8024 {
8025 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008026 {
Geoff Langb1196682014-07-23 13:47:29 -04008027 context->recordError(gl::Error(GL_INVALID_OPERATION));
8028 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008029 }
Geoff Langbfdea662014-07-23 14:16:32 -04008030
8031 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8032 {
8033 return;
8034 }
8035
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008036 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
8037 if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
8038 {
8039 framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height);
8040 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008041 }
8042}
8043
8044void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8045{
8046 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8047 target, levels, internalformat, width, height);
8048
Geoff Langbfdea662014-07-23 14:16:32 -04008049 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008050 if (context)
8051 {
8052 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008053 {
Geoff Langb1196682014-07-23 13:47:29 -04008054 context->recordError(gl::Error(GL_INVALID_OPERATION));
8055 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008056 }
Geoff Langbfdea662014-07-23 14:16:32 -04008057
8058 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8059 {
8060 return;
8061 }
8062
8063 switch (target)
8064 {
8065 case GL_TEXTURE_2D:
8066 {
8067 gl::Texture2D *texture2d = context->getTexture2D();
8068 texture2d->storage(levels, internalformat, width, height);
8069 }
8070 break;
8071
8072 case GL_TEXTURE_CUBE_MAP:
8073 {
8074 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8075 textureCube->storage(levels, internalformat, width);
8076 }
8077 break;
8078
8079 default:
Geoff Langb1196682014-07-23 13:47:29 -04008080 context->recordError(gl::Error(GL_INVALID_ENUM));
8081 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008082 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008083 }
8084}
8085
8086void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8087{
8088 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8089 "GLsizei height = %d, GLsizei depth = %d)",
8090 target, levels, internalformat, width, height, depth);
8091
Geoff Langbfdea662014-07-23 14:16:32 -04008092 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008093 if (context)
8094 {
8095 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008096 {
Geoff Langb1196682014-07-23 13:47:29 -04008097 context->recordError(gl::Error(GL_INVALID_OPERATION));
8098 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008099 }
Geoff Langbfdea662014-07-23 14:16:32 -04008100
8101 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8102 {
8103 return;
8104 }
8105
8106 switch (target)
8107 {
8108 case GL_TEXTURE_3D:
8109 {
8110 gl::Texture3D *texture3d = context->getTexture3D();
8111 texture3d->storage(levels, internalformat, width, height, depth);
8112 }
8113 break;
8114
8115 case GL_TEXTURE_2D_ARRAY:
8116 {
8117 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8118 texture2darray->storage(levels, internalformat, width, height, depth);
8119 }
8120 break;
8121
8122 default:
8123 UNREACHABLE();
8124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008125 }
8126}
8127
8128void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8129{
8130 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8131 "GLint* params = 0x%0.8p)",
8132 target, internalformat, pname, bufSize, params);
8133
Geoff Langbfdea662014-07-23 14:16:32 -04008134 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008135 if (context)
8136 {
8137 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008138 {
Geoff Langb1196682014-07-23 13:47:29 -04008139 context->recordError(gl::Error(GL_INVALID_OPERATION));
8140 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008141 }
Geoff Langbfdea662014-07-23 14:16:32 -04008142
8143 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8144 if (!formatCaps.renderable)
8145 {
Geoff Langb1196682014-07-23 13:47:29 -04008146 context->recordError(gl::Error(GL_INVALID_ENUM));
8147 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008148 }
8149
8150 if (target != GL_RENDERBUFFER)
8151 {
Geoff Langb1196682014-07-23 13:47:29 -04008152 context->recordError(gl::Error(GL_INVALID_ENUM));
8153 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008154 }
8155
8156 if (bufSize < 0)
8157 {
Geoff Langb1196682014-07-23 13:47:29 -04008158 context->recordError(gl::Error(GL_INVALID_VALUE));
8159 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008160 }
8161
8162 switch (pname)
8163 {
8164 case GL_NUM_SAMPLE_COUNTS:
8165 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008166 {
8167 *params = formatCaps.sampleCounts.size();
8168 }
Geoff Langbfdea662014-07-23 14:16:32 -04008169 break;
Geoff Langb1196682014-07-23 13:47:29 -04008170
Geoff Langbfdea662014-07-23 14:16:32 -04008171 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008172 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008173 break;
Geoff Langb1196682014-07-23 13:47:29 -04008174
Geoff Langbfdea662014-07-23 14:16:32 -04008175 default:
Geoff Langb1196682014-07-23 13:47:29 -04008176 context->recordError(gl::Error(GL_INVALID_ENUM));
8177 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008178 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008179 }
8180}
8181
8182// Extension functions
8183
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008184void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8185 GLbitfield mask, GLenum filter)
8186{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008187 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008188 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8189 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8190 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8191
Geoff Langbfdea662014-07-23 14:16:32 -04008192 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008193 if (context)
8194 {
8195 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8196 dstX0, dstY0, dstX1, dstY1, mask, filter,
8197 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008198 {
Geoff Langbfdea662014-07-23 14:16:32 -04008199 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008200 }
Geoff Langbfdea662014-07-23 14:16:32 -04008201
8202 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8203 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008204 }
8205}
8206
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008207void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8208 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008210 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008211 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008212 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008213 target, level, internalformat, width, height, depth, border, format, type, pixels);
8214
Geoff Langbfdea662014-07-23 14:16:32 -04008215 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008216}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008217
Geoff Langbfdea662014-07-23 14:16:32 -04008218void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008219 GLenum *binaryFormat, void *binary)
8220{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008221 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 +00008222 program, bufSize, length, binaryFormat, binary);
8223
Geoff Langbfdea662014-07-23 14:16:32 -04008224 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008225 if (context)
8226 {
8227 gl::Program *programObject = context->getProgram(program);
8228
8229 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008230 {
Geoff Langb1196682014-07-23 13:47:29 -04008231 context->recordError(gl::Error(GL_INVALID_OPERATION));
8232 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008233 }
Geoff Langbfdea662014-07-23 14:16:32 -04008234
8235 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8236
8237 if (!programBinary)
8238 {
Geoff Langb1196682014-07-23 13:47:29 -04008239 context->recordError(gl::Error(GL_INVALID_OPERATION));
8240 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008241 }
8242
Geoff Lang900013c2014-07-07 11:32:19 -04008243 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04008244 {
Geoff Langb1196682014-07-23 13:47:29 -04008245 context->recordError(gl::Error(GL_INVALID_OPERATION));
8246 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008247 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008248 }
8249}
8250
8251void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8252 const void *binary, GLint length)
8253{
8254 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8255 program, binaryFormat, binary, length);
8256
Geoff Langbfdea662014-07-23 14:16:32 -04008257 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008258 if (context)
8259 {
Geoff Lang900013c2014-07-07 11:32:19 -04008260 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8261 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008262 {
Geoff Langb1196682014-07-23 13:47:29 -04008263 context->recordError(gl::Error(GL_INVALID_ENUM));
8264 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008265 }
Geoff Langbfdea662014-07-23 14:16:32 -04008266
8267 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008268 if (!programObject)
8269 {
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 }
8273
Geoff Lang900013c2014-07-07 11:32:19 -04008274 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008275 }
8276}
8277
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008278void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8279{
8280 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8281
Geoff Langbfdea662014-07-23 14:16:32 -04008282 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008283 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008284 {
Geoff Langbfdea662014-07-23 14:16:32 -04008285 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008286 {
Geoff Langb1196682014-07-23 13:47:29 -04008287 context->recordError(gl::Error(GL_INVALID_VALUE));
8288 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008289 }
8290
8291 if (context->getState().getDrawFramebuffer()->id() == 0)
8292 {
8293 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008294 {
Geoff Langb1196682014-07-23 13:47:29 -04008295 context->recordError(gl::Error(GL_INVALID_OPERATION));
8296 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008297 }
8298
Geoff Langbfdea662014-07-23 14:16:32 -04008299 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008300 {
Geoff Langb1196682014-07-23 13:47:29 -04008301 context->recordError(gl::Error(GL_INVALID_OPERATION));
8302 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008303 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008304 }
Geoff Langbfdea662014-07-23 14:16:32 -04008305 else
8306 {
8307 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8308 {
8309 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8310 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8311 {
Geoff Langb1196682014-07-23 13:47:29 -04008312 context->recordError(gl::Error(GL_INVALID_OPERATION));
8313 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008314 }
8315 }
8316 }
8317
8318 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8319
8320 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8321 {
8322 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8323 }
8324
8325 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8326 {
8327 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8328 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008329 }
8330}
8331
Shannon Woodsb3801742014-03-27 14:59:19 -04008332void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8333{
8334 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8335
Geoff Langbfdea662014-07-23 14:16:32 -04008336 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008337 if (context)
8338 {
8339 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008340 {
Geoff Langb1196682014-07-23 13:47:29 -04008341 context->recordError(gl::Error(GL_INVALID_ENUM));
8342 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008343 }
Geoff Langbfdea662014-07-23 14:16:32 -04008344
8345 if (pname != GL_BUFFER_MAP_POINTER)
8346 {
Geoff Langb1196682014-07-23 13:47:29 -04008347 context->recordError(gl::Error(GL_INVALID_ENUM));
8348 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008349 }
8350
8351 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8352
8353 if (!buffer || !buffer->isMapped())
8354 {
8355 *params = NULL;
8356 }
8357 else
8358 {
8359 *params = buffer->getMapPointer();
8360 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008361 }
8362}
8363
8364void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8365{
8366 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8367
Geoff Langbfdea662014-07-23 14:16:32 -04008368 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008369 if (context)
8370 {
8371 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008372 {
Geoff Langb1196682014-07-23 13:47:29 -04008373 context->recordError(gl::Error(GL_INVALID_ENUM));
8374 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008375 }
Geoff Langbfdea662014-07-23 14:16:32 -04008376
8377 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8378
8379 if (buffer == NULL)
8380 {
Geoff Langb1196682014-07-23 13:47:29 -04008381 context->recordError(gl::Error(GL_INVALID_OPERATION));
8382 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008383 }
8384
8385 if (access != GL_WRITE_ONLY_OES)
8386 {
Geoff Langb1196682014-07-23 13:47:29 -04008387 context->recordError(gl::Error(GL_INVALID_ENUM));
8388 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008389 }
8390
8391 if (buffer->isMapped())
8392 {
Geoff Langb1196682014-07-23 13:47:29 -04008393 context->recordError(gl::Error(GL_INVALID_OPERATION));
8394 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008395 }
8396
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008397 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8398 if (error.isError())
8399 {
8400 context->recordError(error);
8401 return NULL;
8402 }
8403
8404 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008405 }
8406
8407 return NULL;
8408}
8409
8410GLboolean __stdcall glUnmapBufferOES(GLenum target)
8411{
8412 EVENT("(GLenum target = 0x%X)", target);
8413
Geoff Langbfdea662014-07-23 14:16:32 -04008414 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008415 if (context)
8416 {
8417 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008418 {
Geoff Langb1196682014-07-23 13:47:29 -04008419 context->recordError(gl::Error(GL_INVALID_ENUM));
8420 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008421 }
Geoff Langbfdea662014-07-23 14:16:32 -04008422
8423 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8424
8425 if (buffer == NULL || !buffer->isMapped())
8426 {
Geoff Langb1196682014-07-23 13:47:29 -04008427 context->recordError(gl::Error(GL_INVALID_OPERATION));
8428 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008429 }
8430
8431 // TODO: detect if we had corruption. if so, throw an error and return false.
8432
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008433 gl::Error error = buffer->unmap();
8434 if (error.isError())
8435 {
8436 context->recordError(error);
8437 return GL_FALSE;
8438 }
Geoff Langbfdea662014-07-23 14:16:32 -04008439
8440 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008441 }
8442
8443 return GL_FALSE;
8444}
8445
Shannon Woods916e7692014-03-27 16:58:22 -04008446void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8447{
8448 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8449 target, offset, length, access);
8450
Geoff Langbfdea662014-07-23 14:16:32 -04008451 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008452 if (context)
8453 {
8454 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008455 {
Geoff Langb1196682014-07-23 13:47:29 -04008456 context->recordError(gl::Error(GL_INVALID_ENUM));
8457 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008458 }
Geoff Langbfdea662014-07-23 14:16:32 -04008459
8460 if (offset < 0 || length < 0)
8461 {
Geoff Langb1196682014-07-23 13:47:29 -04008462 context->recordError(gl::Error(GL_INVALID_VALUE));
8463 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008464 }
8465
8466 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8467
8468 if (buffer == NULL)
8469 {
Geoff Langb1196682014-07-23 13:47:29 -04008470 context->recordError(gl::Error(GL_INVALID_OPERATION));
8471 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008472 }
8473
8474 // Check for buffer overflow
8475 size_t offsetSize = static_cast<size_t>(offset);
8476 size_t lengthSize = static_cast<size_t>(length);
8477
8478 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8479 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8480 {
Geoff Langb1196682014-07-23 13:47:29 -04008481 context->recordError(gl::Error(GL_INVALID_VALUE));
8482 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008483 }
8484
8485 // Check for invalid bits in the mask
8486 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8487 GL_MAP_WRITE_BIT |
8488 GL_MAP_INVALIDATE_RANGE_BIT |
8489 GL_MAP_INVALIDATE_BUFFER_BIT |
8490 GL_MAP_FLUSH_EXPLICIT_BIT |
8491 GL_MAP_UNSYNCHRONIZED_BIT;
8492
8493 if (access & ~(allAccessBits))
8494 {
Geoff Langb1196682014-07-23 13:47:29 -04008495 context->recordError(gl::Error(GL_INVALID_VALUE));
8496 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008497 }
8498
8499 if (length == 0 || buffer->isMapped())
8500 {
Geoff Langb1196682014-07-23 13:47:29 -04008501 context->recordError(gl::Error(GL_INVALID_OPERATION));
8502 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008503 }
8504
8505 // Check for invalid bit combinations
8506 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8507 {
Geoff Langb1196682014-07-23 13:47:29 -04008508 context->recordError(gl::Error(GL_INVALID_OPERATION));
8509 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008510 }
8511
8512 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8513 GL_MAP_INVALIDATE_BUFFER_BIT |
8514 GL_MAP_UNSYNCHRONIZED_BIT;
8515
8516 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8517 {
Geoff Langb1196682014-07-23 13:47:29 -04008518 context->recordError(gl::Error(GL_INVALID_OPERATION));
8519 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008520 }
8521
8522 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8523 {
Geoff Langb1196682014-07-23 13:47:29 -04008524 context->recordError(gl::Error(GL_INVALID_OPERATION));
8525 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008526 }
8527
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008528 gl::Error error = buffer->mapRange(offset, length, access);
8529 if (error.isError())
8530 {
8531 context->recordError(error);
8532 return NULL;
8533 }
8534
8535 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008536 }
8537
8538 return NULL;
8539}
8540
8541void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8542{
8543 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8544
Geoff Langbfdea662014-07-23 14:16:32 -04008545 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008546 if (context)
8547 {
8548 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008549 {
Geoff Langb1196682014-07-23 13:47:29 -04008550 context->recordError(gl::Error(GL_INVALID_VALUE));
8551 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008552 }
Geoff Langbfdea662014-07-23 14:16:32 -04008553
8554 if (!gl::ValidBufferTarget(context, target))
8555 {
Geoff Langb1196682014-07-23 13:47:29 -04008556 context->recordError(gl::Error(GL_INVALID_ENUM));
8557 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008558 }
8559
8560 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8561
8562 if (buffer == NULL)
8563 {
Geoff Langb1196682014-07-23 13:47:29 -04008564 context->recordError(gl::Error(GL_INVALID_OPERATION));
8565 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008566 }
8567
8568 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8569 {
Geoff Langb1196682014-07-23 13:47:29 -04008570 context->recordError(gl::Error(GL_INVALID_OPERATION));
8571 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008572 }
8573
8574 // Check for buffer overflow
8575 size_t offsetSize = static_cast<size_t>(offset);
8576 size_t lengthSize = static_cast<size_t>(length);
8577
8578 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8579 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8580 {
Geoff Langb1196682014-07-23 13:47:29 -04008581 context->recordError(gl::Error(GL_INVALID_VALUE));
8582 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008583 }
8584
8585 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008586 }
8587}
8588
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008589__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8590{
8591 struct Extension
8592 {
8593 const char *name;
8594 __eglMustCastToProperFunctionPointerType address;
8595 };
8596
8597 static const Extension glExtensions[] =
8598 {
8599 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008600 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008601 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008602 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8603 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8604 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8605 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8606 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8607 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8608 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008609 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008610 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008611 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8612 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8613 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8614 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008615 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8616 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8617 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8618 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8619 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8620 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8621 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008622 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008623 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8624 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8625 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008626 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008627 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8628 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8629 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008630 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8631 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8632 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008633
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008634 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008635 {
8636 if (strcmp(procname, glExtensions[ext].name) == 0)
8637 {
8638 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8639 }
8640 }
8641
8642 return NULL;
8643}
8644
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008645// Non-public functions used by EGL
8646
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008647bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008648{
8649 EVENT("(egl::Surface* surface = 0x%0.8p)",
8650 surface);
8651
Geoff Langbfdea662014-07-23 14:16:32 -04008652 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008653 if (context)
8654 {
8655 gl::Texture2D *textureObject = context->getTexture2D();
8656 ASSERT(textureObject != NULL);
8657
8658 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008659 {
Geoff Langbfdea662014-07-23 14:16:32 -04008660 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008661 }
Geoff Langbfdea662014-07-23 14:16:32 -04008662
8663 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008664 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008665
8666 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008667}
8668
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008669}