blob: 6c1bc5b828d4225b13bdc66a43b42b5c95aaf9df [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
545 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000546 }
547}
548
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000549void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000550{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000551 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 +0000552 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000553
Geoff Langbfdea662014-07-23 14:16:32 -0400554 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400555 if (context)
556 {
Geoff Langb1196682014-07-23 13:47:29 -0400557 if (size < 0 || offset < 0)
558 {
559 context->recordError(gl::Error(GL_INVALID_VALUE));
560 return;
561 }
562
563 if (data == NULL)
564 {
565 return;
566 }
567
Geoff Langbfdea662014-07-23 14:16:32 -0400568 if (!gl::ValidBufferTarget(context, target))
569 {
Geoff Langb1196682014-07-23 13:47:29 -0400570 context->recordError(gl::Error(GL_INVALID_ENUM));
571 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400572 }
573
574 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
575
576 if (!buffer)
577 {
Geoff Langb1196682014-07-23 13:47:29 -0400578 context->recordError(gl::Error(GL_INVALID_OPERATION));
579 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400580 }
581
582 if (buffer->isMapped())
583 {
Geoff Langb1196682014-07-23 13:47:29 -0400584 context->recordError(gl::Error(GL_INVALID_OPERATION));
585 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400586 }
587
588 // Check for possible overflow of size + offset
589 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
590 {
Geoff Langb1196682014-07-23 13:47:29 -0400591 context->recordError(gl::Error(GL_OUT_OF_MEMORY));
592 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400593 }
594
595 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000596 {
Geoff Langb1196682014-07-23 13:47:29 -0400597 context->recordError(gl::Error(GL_INVALID_VALUE));
598 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000599 }
600
Geoff Langbfdea662014-07-23 14:16:32 -0400601 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000602 }
603}
604
605GLenum __stdcall glCheckFramebufferStatus(GLenum target)
606{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000607 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000608
Geoff Langbfdea662014-07-23 14:16:32 -0400609 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400610 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000611 {
Geoff Langb1196682014-07-23 13:47:29 -0400612 if (!gl::ValidFramebufferTarget(target))
613 {
614 context->recordError(gl::Error(GL_INVALID_ENUM));
615 return 0;
616 }
617
Geoff Langbfdea662014-07-23 14:16:32 -0400618 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
619 ASSERT(framebuffer);
620 return framebuffer->completeness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000621 }
622
623 return 0;
624}
625
626void __stdcall glClear(GLbitfield mask)
627{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000628 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000629
Geoff Langbfdea662014-07-23 14:16:32 -0400630 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400631 if (context)
632 {
633 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
634
635 if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000636 {
Geoff Langb1196682014-07-23 13:47:29 -0400637 context->recordError(gl::Error(GL_INVALID_FRAMEBUFFER_OPERATION));
638 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000639 }
Geoff Langbfdea662014-07-23 14:16:32 -0400640
641 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
642 {
Geoff Langb1196682014-07-23 13:47:29 -0400643 context->recordError(gl::Error(GL_INVALID_VALUE));
644 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400645 }
646
647 context->clear(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000648 }
649}
650
651void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
652{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000653 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000654 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000655
Geoff Langbfdea662014-07-23 14:16:32 -0400656 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400657 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000658 {
Geoff Langbfdea662014-07-23 14:16:32 -0400659 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000660 }
661}
662
663void __stdcall glClearDepthf(GLclampf depth)
664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000665 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000666
Geoff Langbfdea662014-07-23 14:16:32 -0400667 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400668 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000669 {
Geoff Langbfdea662014-07-23 14:16:32 -0400670 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000671 }
672}
673
674void __stdcall glClearStencil(GLint s)
675{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000676 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000677
Geoff Langbfdea662014-07-23 14:16:32 -0400678 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400679 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000680 {
Geoff Langbfdea662014-07-23 14:16:32 -0400681 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000682 }
683}
684
685void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
686{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000687 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000688 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000689
Geoff Langbfdea662014-07-23 14:16:32 -0400690 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400691 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000692 {
Geoff Langbfdea662014-07-23 14:16:32 -0400693 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000694 }
695}
696
697void __stdcall glCompileShader(GLuint shader)
698{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000699 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000700
Geoff Langbfdea662014-07-23 14:16:32 -0400701 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400702 if (context)
703 {
704 gl::Shader *shaderObject = context->getShader(shader);
705
706 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000707 {
Geoff Langbfdea662014-07-23 14:16:32 -0400708 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000709 {
Geoff Langb1196682014-07-23 13:47:29 -0400710 context->recordError(gl::Error(GL_INVALID_OPERATION));
711 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000712 }
Geoff Langbfdea662014-07-23 14:16:32 -0400713 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000714 {
Geoff Langb1196682014-07-23 13:47:29 -0400715 context->recordError(gl::Error(GL_INVALID_VALUE));
716 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000717 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000718 }
Geoff Langbfdea662014-07-23 14:16:32 -0400719
720 shaderObject->compile();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000721 }
Geoff Langbfdea662014-07-23 14:16:32 -0400722}
723
724void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
725 GLint border, GLsizei imageSize, const GLvoid* data)
726{
727 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
728 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
729 target, level, internalformat, width, height, border, imageSize, data);
730
731 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400732 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000733 {
Geoff Langbfdea662014-07-23 14:16:32 -0400734 if (context->getClientVersion() < 3 &&
735 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
736 0, 0, width, height, border, GL_NONE, GL_NONE, data))
737 {
738 return;
739 }
740
741 if (context->getClientVersion() >= 3 &&
742 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
743 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
744 {
745 return;
746 }
747
Geoff Lang5d601382014-07-22 15:14:06 -0400748 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
749 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400750 {
Geoff Langb1196682014-07-23 13:47:29 -0400751 context->recordError(gl::Error(GL_INVALID_VALUE));
752 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400753 }
754
755 switch (target)
756 {
757 case GL_TEXTURE_2D:
758 {
759 gl::Texture2D *texture = context->getTexture2D();
760 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
761 }
762 break;
763
764 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
765 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
766 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
767 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
768 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
769 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
770 {
771 gl::TextureCubeMap *texture = context->getTextureCubeMap();
772 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
773 }
774 break;
775
776 default:
Geoff Langb1196682014-07-23 13:47:29 -0400777 context->recordError(gl::Error(GL_INVALID_ENUM));
778 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400779 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000780 }
781}
782
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000783void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
784 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000785{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000786 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000787 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000788 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000789 target, level, xoffset, yoffset, width, height, format, imageSize, data);
790
Geoff Langbfdea662014-07-23 14:16:32 -0400791 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400792 if (context)
793 {
794 if (context->getClientVersion() < 3 &&
795 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
796 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000797 {
Geoff Langbfdea662014-07-23 14:16:32 -0400798 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000799 }
Geoff Langbfdea662014-07-23 14:16:32 -0400800
801 if (context->getClientVersion() >= 3 &&
802 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
803 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
804 {
805 return;
806 }
807
Geoff Lang5d601382014-07-22 15:14:06 -0400808 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
809 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400810 {
Geoff Langb1196682014-07-23 13:47:29 -0400811 context->recordError(gl::Error(GL_INVALID_VALUE));
812 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400813 }
814
815 switch (target)
816 {
817 case GL_TEXTURE_2D:
818 {
819 gl::Texture2D *texture = context->getTexture2D();
820 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
821 }
822 break;
823
824 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
825 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
826 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
827 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
828 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
829 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
830 {
831 gl::TextureCubeMap *texture = context->getTextureCubeMap();
832 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
833 }
834 break;
835
836 default:
Geoff Langb1196682014-07-23 13:47:29 -0400837 context->recordError(gl::Error(GL_INVALID_ENUM));
838 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400839 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000840 }
841}
842
843void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000845 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000846 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000847 target, level, internalformat, x, y, width, height, border);
848
Geoff Langbfdea662014-07-23 14:16:32 -0400849 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400850 if (context)
851 {
852 if (context->getClientVersion() < 3 &&
853 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
854 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000855 {
Geoff Langbfdea662014-07-23 14:16:32 -0400856 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000857 }
Geoff Langbfdea662014-07-23 14:16:32 -0400858
859 if (context->getClientVersion() >= 3 &&
860 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
861 0, 0, 0, x, y, width, height, border))
862 {
863 return;
864 }
865
866 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
867
868 switch (target)
869 {
870 case GL_TEXTURE_2D:
871 {
872 gl::Texture2D *texture = context->getTexture2D();
873 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
874 }
875 break;
876
877 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
878 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
879 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
880 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
881 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
882 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
883 {
884 gl::TextureCubeMap *texture = context->getTextureCubeMap();
885 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
886 }
887 break;
888
Geoff Langb1196682014-07-23 13:47:29 -0400889 default:
890 context->recordError(gl::Error(GL_INVALID_ENUM));
891 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400892 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000893 }
894}
895
896void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
897{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000898 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000899 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000900 target, level, xoffset, yoffset, x, y, width, height);
901
Geoff Langbfdea662014-07-23 14:16:32 -0400902 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400903 if (context)
904 {
905 if (context->getClientVersion() < 3 &&
906 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
907 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000908 {
Geoff Langbfdea662014-07-23 14:16:32 -0400909 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000910 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000911
Geoff Langbfdea662014-07-23 14:16:32 -0400912 if (context->getClientVersion() >= 3 &&
913 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
914 xoffset, yoffset, 0, x, y, width, height, 0))
915 {
916 return;
917 }
918
919 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
920
921 switch (target)
922 {
923 case GL_TEXTURE_2D:
924 {
925 gl::Texture2D *texture = context->getTexture2D();
926 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
927 }
928 break;
929
930 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
931 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
932 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
933 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
934 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
935 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
936 {
937 gl::TextureCubeMap *texture = context->getTextureCubeMap();
938 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
939 }
940 break;
941
942 default:
Geoff Langb1196682014-07-23 13:47:29 -0400943 context->recordError(gl::Error(GL_INVALID_ENUM));
944 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400945 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000946 }
947}
948
949GLuint __stdcall glCreateProgram(void)
950{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000951 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000952
Geoff Langbfdea662014-07-23 14:16:32 -0400953 gl::Context *context = gl::getNonLostContext();
954 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000955 {
Geoff Langbfdea662014-07-23 14:16:32 -0400956 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000957 }
958
959 return 0;
960}
961
962GLuint __stdcall glCreateShader(GLenum type)
963{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000964 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000965
Geoff Langbfdea662014-07-23 14:16:32 -0400966 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400967 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000968 {
Geoff Langbfdea662014-07-23 14:16:32 -0400969 switch (type)
970 {
971 case GL_FRAGMENT_SHADER:
972 case GL_VERTEX_SHADER:
973 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -0400974
Geoff Langbfdea662014-07-23 14:16:32 -0400975 default:
Geoff Langb1196682014-07-23 13:47:29 -0400976 context->recordError(gl::Error(GL_INVALID_ENUM));
977 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -0400978 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000979 }
980
981 return 0;
982}
983
984void __stdcall glCullFace(GLenum mode)
985{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000986 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000987
Geoff Langb1196682014-07-23 13:47:29 -0400988 gl::Context *context = gl::getNonLostContext();
989 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000990 {
Geoff Langb1196682014-07-23 13:47:29 -0400991 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000992 {
Geoff Langb1196682014-07-23 13:47:29 -0400993 case GL_FRONT:
994 case GL_BACK:
995 case GL_FRONT_AND_BACK:
996 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000997
Geoff Langb1196682014-07-23 13:47:29 -0400998 default:
999 context->recordError(gl::Error(GL_INVALID_ENUM));
1000 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001001 }
Geoff Langb1196682014-07-23 13:47:29 -04001002
1003 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001004 }
1005}
1006
1007void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
1008{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001009 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001010
Geoff Langbfdea662014-07-23 14:16:32 -04001011 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001012 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001013 {
Geoff Langb1196682014-07-23 13:47:29 -04001014 if (n < 0)
1015 {
1016 context->recordError(gl::Error(GL_INVALID_VALUE));
1017 return;
1018 }
1019
Geoff Langbfdea662014-07-23 14:16:32 -04001020 for (int i = 0; i < n; i++)
1021 {
1022 context->deleteBuffer(buffers[i]);
1023 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001024 }
1025}
1026
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001027void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
1028{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001029 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001030
Geoff Langbfdea662014-07-23 14:16:32 -04001031 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001032 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001033 {
Geoff Langb1196682014-07-23 13:47:29 -04001034 if (n < 0)
1035 {
1036 context->recordError(gl::Error(GL_INVALID_VALUE));
1037 return;
1038 }
1039
Geoff Langbfdea662014-07-23 14:16:32 -04001040 for (int i = 0; i < n; i++)
1041 {
1042 context->deleteFenceNV(fences[i]);
1043 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001044 }
1045}
1046
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001047void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
1048{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001049 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001050
Geoff Langbfdea662014-07-23 14:16:32 -04001051 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001052 if (context)
1053 {
Geoff Langb1196682014-07-23 13:47:29 -04001054 if (n < 0)
1055 {
1056 context->recordError(gl::Error(GL_INVALID_VALUE));
1057 return;
1058 }
1059
Geoff Langbfdea662014-07-23 14:16:32 -04001060 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001061 {
Geoff Langbfdea662014-07-23 14:16:32 -04001062 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001063 {
Geoff Langbfdea662014-07-23 14:16:32 -04001064 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001065 }
1066 }
1067 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001068}
1069
1070void __stdcall glDeleteProgram(GLuint program)
1071{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001072 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001073
Geoff Langbfdea662014-07-23 14:16:32 -04001074 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001075 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001076 {
Geoff Langb1196682014-07-23 13:47:29 -04001077 if (program == 0)
1078 {
1079 return;
1080 }
1081
Geoff Langbfdea662014-07-23 14:16:32 -04001082 if (!context->getProgram(program))
1083 {
1084 if(context->getShader(program))
1085 {
Geoff Langb1196682014-07-23 13:47:29 -04001086 context->recordError(gl::Error(GL_INVALID_OPERATION));
1087 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001088 }
1089 else
1090 {
Geoff Langb1196682014-07-23 13:47:29 -04001091 context->recordError(gl::Error(GL_INVALID_VALUE));
1092 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001093 }
1094 }
1095
1096 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001097 }
1098}
1099
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001100void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
1101{
1102 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1103
Geoff Langbfdea662014-07-23 14:16:32 -04001104 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001105 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001106 {
Geoff Langb1196682014-07-23 13:47:29 -04001107 if (n < 0)
1108 {
1109 context->recordError(gl::Error(GL_INVALID_VALUE));
1110 return;
1111 }
1112
Geoff Langbfdea662014-07-23 14:16:32 -04001113 for (int i = 0; i < n; i++)
1114 {
1115 context->deleteQuery(ids[i]);
1116 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001117 }
1118}
1119
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001120void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
1121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001122 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001123
Geoff Langbfdea662014-07-23 14:16:32 -04001124 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001125 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001126 {
Geoff Langb1196682014-07-23 13:47:29 -04001127 if (n < 0)
1128 {
1129 context->recordError(gl::Error(GL_INVALID_VALUE));
1130 return;
1131 }
1132
Geoff Langbfdea662014-07-23 14:16:32 -04001133 for (int i = 0; i < n; i++)
1134 {
1135 context->deleteRenderbuffer(renderbuffers[i]);
1136 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001137 }
1138}
1139
1140void __stdcall glDeleteShader(GLuint shader)
1141{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001142 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001143
Geoff Langbfdea662014-07-23 14:16:32 -04001144 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001145 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001146 {
Geoff Langb1196682014-07-23 13:47:29 -04001147 if (shader == 0)
1148 {
1149 return;
1150 }
1151
Geoff Langbfdea662014-07-23 14:16:32 -04001152 if (!context->getShader(shader))
1153 {
1154 if(context->getProgram(shader))
1155 {
Geoff Langb1196682014-07-23 13:47:29 -04001156 context->recordError(gl::Error(GL_INVALID_OPERATION));
1157 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001158 }
1159 else
1160 {
Geoff Langb1196682014-07-23 13:47:29 -04001161 context->recordError(gl::Error(GL_INVALID_VALUE));
1162 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001163 }
1164 }
1165
1166 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001167 }
1168}
1169
1170void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
1171{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001172 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001173
Geoff Langbfdea662014-07-23 14:16:32 -04001174 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001175 if (context)
1176 {
Geoff Langb1196682014-07-23 13:47:29 -04001177 if (n < 0)
1178 {
1179 context->recordError(gl::Error(GL_INVALID_VALUE));
1180 return;
1181 }
1182
Geoff Langbfdea662014-07-23 14:16:32 -04001183 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001184 {
Geoff Langbfdea662014-07-23 14:16:32 -04001185 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001186 {
Geoff Langbfdea662014-07-23 14:16:32 -04001187 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001188 }
1189 }
1190 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001191}
1192
1193void __stdcall glDepthFunc(GLenum func)
1194{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001195 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001196
Geoff Langbfdea662014-07-23 14:16:32 -04001197 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001198 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001199 {
Geoff Langb1196682014-07-23 13:47:29 -04001200 switch (func)
1201 {
1202 case GL_NEVER:
1203 case GL_ALWAYS:
1204 case GL_LESS:
1205 case GL_LEQUAL:
1206 case GL_EQUAL:
1207 case GL_GREATER:
1208 case GL_GEQUAL:
1209 case GL_NOTEQUAL:
1210 context->getState().setDepthFunc(func);
1211 break;
1212
1213 default:
1214 context->recordError(gl::Error(GL_INVALID_ENUM));
1215 return;
1216 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001217 }
1218}
1219
1220void __stdcall glDepthMask(GLboolean flag)
1221{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001222 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001223
Geoff Langbfdea662014-07-23 14:16:32 -04001224 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001225 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001226 {
Geoff Langbfdea662014-07-23 14:16:32 -04001227 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001228 }
1229}
1230
1231void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
1232{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001233 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001234
Geoff Langbfdea662014-07-23 14:16:32 -04001235 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001236 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001237 {
Geoff Langbfdea662014-07-23 14:16:32 -04001238 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001239 }
1240}
1241
1242void __stdcall glDetachShader(GLuint program, GLuint shader)
1243{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001244 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001245
Geoff Langbfdea662014-07-23 14:16:32 -04001246 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001247 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001248 {
Geoff Langbfdea662014-07-23 14:16:32 -04001249 gl::Program *programObject = context->getProgram(program);
1250 gl::Shader *shaderObject = context->getShader(shader);
1251
1252 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001253 {
Geoff Langbfdea662014-07-23 14:16:32 -04001254 gl::Shader *shaderByProgramHandle;
1255 shaderByProgramHandle = context->getShader(program);
1256 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001257 {
Geoff Langb1196682014-07-23 13:47:29 -04001258 context->recordError(gl::Error(GL_INVALID_VALUE));
1259 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001260 }
Geoff Langbfdea662014-07-23 14:16:32 -04001261 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001262 {
Geoff Langb1196682014-07-23 13:47:29 -04001263 context->recordError(gl::Error(GL_INVALID_OPERATION));
1264 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001265 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266 }
Geoff Langbfdea662014-07-23 14:16:32 -04001267
1268 if (!shaderObject)
1269 {
1270 gl::Program *programByShaderHandle = context->getProgram(shader);
1271 if (!programByShaderHandle)
1272 {
Geoff Langb1196682014-07-23 13:47:29 -04001273 context->recordError(gl::Error(GL_INVALID_VALUE));
1274 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001275 }
1276 else
1277 {
Geoff Langb1196682014-07-23 13:47:29 -04001278 context->recordError(gl::Error(GL_INVALID_OPERATION));
1279 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001280 }
1281 }
1282
1283 if (!programObject->detachShader(shaderObject))
1284 {
Geoff Langb1196682014-07-23 13:47:29 -04001285 context->recordError(gl::Error(GL_INVALID_OPERATION));
1286 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001287 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001288 }
1289}
1290
1291void __stdcall glDisable(GLenum cap)
1292{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001293 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001294
Geoff Langbfdea662014-07-23 14:16:32 -04001295 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001296 if (context)
1297 {
1298 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001299 {
Geoff Langb1196682014-07-23 13:47:29 -04001300 context->recordError(gl::Error(GL_INVALID_ENUM));
1301 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001302 }
Geoff Langbfdea662014-07-23 14:16:32 -04001303
1304 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001305 }
1306}
1307
1308void __stdcall glDisableVertexAttribArray(GLuint index)
1309{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001310 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001311
Geoff Langbfdea662014-07-23 14:16:32 -04001312 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001313 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001314 {
Geoff Langb1196682014-07-23 13:47:29 -04001315 if (index >= gl::MAX_VERTEX_ATTRIBS)
1316 {
1317 context->recordError(gl::Error(GL_INVALID_VALUE));
1318 return;
1319 }
1320
Geoff Langbfdea662014-07-23 14:16:32 -04001321 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001322 }
1323}
1324
1325void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
1326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001327 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001328
Geoff Langbfdea662014-07-23 14:16:32 -04001329 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001330 if (context)
1331 {
Jamie Madill2b976812014-08-25 15:47:49 -04001332 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001333 {
Geoff Langbfdea662014-07-23 14:16:32 -04001334 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001335 }
Geoff Langbfdea662014-07-23 14:16:32 -04001336
1337 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001338 }
1339}
1340
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001341void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1342{
1343 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1344
Geoff Langbfdea662014-07-23 14:16:32 -04001345 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001346 if (context)
1347 {
1348 if (!ValidateDrawArraysInstanced(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001349 {
Geoff Langbfdea662014-07-23 14:16:32 -04001350 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001351 }
Geoff Langbfdea662014-07-23 14:16:32 -04001352
1353 context->drawArrays(mode, first, count, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001354 }
1355}
1356
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001357void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001358{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001359 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 +00001360 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001361
Geoff Langbfdea662014-07-23 14:16:32 -04001362 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001363 if (context)
1364 {
Jamie Madill2b976812014-08-25 15:47:49 -04001365 rx::RangeUI indexRange;
1366 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001367 {
Geoff Langbfdea662014-07-23 14:16:32 -04001368 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001369 }
Geoff Langbfdea662014-07-23 14:16:32 -04001370
Jamie Madill2b976812014-08-25 15:47:49 -04001371 context->drawElements(mode, count, type, indices, 0, indexRange);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001372 }
1373}
1374
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001375void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
1376{
1377 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1378 mode, count, type, indices, primcount);
1379
Geoff Langbfdea662014-07-23 14:16:32 -04001380 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001381 if (context)
1382 {
Jamie Madill2b976812014-08-25 15:47:49 -04001383 rx::RangeUI indexRange;
1384 if (!ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001385 {
Geoff Langbfdea662014-07-23 14:16:32 -04001386 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001387 }
Geoff Langbfdea662014-07-23 14:16:32 -04001388
Jamie Madill2b976812014-08-25 15:47:49 -04001389 context->drawElements(mode, count, type, indices, primcount, indexRange);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001390 }
1391}
1392
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001393void __stdcall glEnable(GLenum cap)
1394{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001395 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001396
Geoff Langbfdea662014-07-23 14:16:32 -04001397 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001398 if (context)
1399 {
1400 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001401 {
Geoff Langb1196682014-07-23 13:47:29 -04001402 context->recordError(gl::Error(GL_INVALID_ENUM));
1403 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001404 }
Geoff Langbfdea662014-07-23 14:16:32 -04001405
1406 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001407 }
1408}
1409
1410void __stdcall glEnableVertexAttribArray(GLuint index)
1411{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001412 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001413
Geoff Langbfdea662014-07-23 14:16:32 -04001414 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001415 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001416 {
Geoff Langb1196682014-07-23 13:47:29 -04001417 if (index >= gl::MAX_VERTEX_ATTRIBS)
1418 {
1419 context->recordError(gl::Error(GL_INVALID_VALUE));
1420 return;
1421 }
1422
Geoff Langbfdea662014-07-23 14:16:32 -04001423 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001424 }
1425}
1426
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001427void __stdcall glEndQueryEXT(GLenum target)
1428{
1429 EVENT("GLenum target = 0x%X)", target);
1430
Geoff Langbfdea662014-07-23 14:16:32 -04001431 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001432 if (context)
1433 {
1434 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001435 {
Geoff Langbfdea662014-07-23 14:16:32 -04001436 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001437 }
Geoff Langbfdea662014-07-23 14:16:32 -04001438
1439 context->endQuery(target);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001440 }
1441}
1442
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001443void __stdcall glFinishFenceNV(GLuint fence)
1444{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001445 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001446
Geoff Langbfdea662014-07-23 14:16:32 -04001447 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001448 if (context)
1449 {
1450 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1451
1452 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001453 {
Geoff Langb1196682014-07-23 13:47:29 -04001454 context->recordError(gl::Error(GL_INVALID_OPERATION));
1455 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001456 }
Geoff Langbfdea662014-07-23 14:16:32 -04001457
1458 if (fenceObject->isFence() != GL_TRUE)
1459 {
Geoff Langb1196682014-07-23 13:47:29 -04001460 context->recordError(gl::Error(GL_INVALID_OPERATION));
1461 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001462 }
1463
1464 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001465 }
1466}
1467
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001468void __stdcall glFinish(void)
1469{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001470 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001471
Geoff Langbfdea662014-07-23 14:16:32 -04001472 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001473 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001474 {
Geoff Langbfdea662014-07-23 14:16:32 -04001475 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001476 }
1477}
1478
1479void __stdcall glFlush(void)
1480{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001481 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001482
Geoff Langbfdea662014-07-23 14:16:32 -04001483 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001484 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001485 {
Geoff Langbfdea662014-07-23 14:16:32 -04001486 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001487 }
1488}
1489
1490void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001492 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001493 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001494
Geoff Langbfdea662014-07-23 14:16:32 -04001495 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001496 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001497 {
Geoff Langb1196682014-07-23 13:47:29 -04001498 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1499 {
1500 context->recordError(gl::Error(GL_INVALID_ENUM));
1501 return;
1502 }
1503
Geoff Langbfdea662014-07-23 14:16:32 -04001504 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1505 {
1506 return;
1507 }
1508
1509 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1510 ASSERT(framebuffer);
1511
1512 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1513 {
1514 unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1515 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
1516 }
1517 else
1518 {
1519 switch (attachment)
1520 {
1521 case GL_DEPTH_ATTACHMENT:
1522 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1523 break;
1524 case GL_STENCIL_ATTACHMENT:
1525 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1526 break;
1527 case GL_DEPTH_STENCIL_ATTACHMENT:
1528 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
1529 break;
1530 default:
1531 UNREACHABLE();
1532 break;
1533 }
1534 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001535 }
1536}
1537
1538void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1539{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001540 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001541 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001542
Geoff Langbfdea662014-07-23 14:16:32 -04001543 gl::Context *context = gl::getNonLostContext();
1544 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001545 {
Geoff Langbfdea662014-07-23 14:16:32 -04001546 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001547 {
Geoff Langbfdea662014-07-23 14:16:32 -04001548 return;
1549 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001550
Geoff Langbfdea662014-07-23 14:16:32 -04001551 if (texture == 0)
1552 {
1553 textarget = GL_NONE;
1554 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001555
Geoff Langbfdea662014-07-23 14:16:32 -04001556 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001557
Geoff Langbfdea662014-07-23 14:16:32 -04001558 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
1559 {
1560 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
1561 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
1562 }
1563 else
1564 {
1565 switch (attachment)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001566 {
Geoff Langbfdea662014-07-23 14:16:32 -04001567 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
1568 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
1569 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00001570 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001571 }
1572 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001573}
1574
1575void __stdcall glFrontFace(GLenum mode)
1576{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001577 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001578
Geoff Langb1196682014-07-23 13:47:29 -04001579 gl::Context *context = gl::getNonLostContext();
1580 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001581 {
Geoff Langb1196682014-07-23 13:47:29 -04001582 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001583 {
Geoff Langb1196682014-07-23 13:47:29 -04001584 case GL_CW:
1585 case GL_CCW:
1586 context->getState().setFrontFace(mode);
1587 break;
1588 default:
1589 context->recordError(gl::Error(GL_INVALID_ENUM));
1590 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001591 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001592 }
1593}
1594
1595void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
1596{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001597 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001598
Geoff Langbfdea662014-07-23 14:16:32 -04001599 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001600 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001601 {
Geoff Langb1196682014-07-23 13:47:29 -04001602 if (n < 0)
1603 {
1604 context->recordError(gl::Error(GL_INVALID_VALUE));
1605 return;
1606 }
1607
Geoff Langbfdea662014-07-23 14:16:32 -04001608 for (int i = 0; i < n; i++)
1609 {
1610 buffers[i] = context->createBuffer();
1611 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001612 }
1613}
1614
1615void __stdcall glGenerateMipmap(GLenum target)
1616{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001617 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001618
Geoff Langbfdea662014-07-23 14:16:32 -04001619 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001620 if (context)
1621 {
1622 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001623 {
Geoff Langb1196682014-07-23 13:47:29 -04001624 context->recordError(gl::Error(GL_INVALID_ENUM));
1625 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001626 }
Geoff Langbfdea662014-07-23 14:16:32 -04001627
1628 gl::Texture *texture = context->getTargetTexture(target);
1629
1630 if (texture == NULL)
1631 {
Geoff Langb1196682014-07-23 13:47:29 -04001632 context->recordError(gl::Error(GL_INVALID_OPERATION));
1633 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001634 }
1635
1636 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1637 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001638 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001639
1640 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1641 // unsized formats or that are color renderable and filterable. Since we do not track if
1642 // the texture was created with sized or unsized format (only sized formats are stored),
1643 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1644 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1645 // textures since they're the only texture format that can be created with unsized formats
1646 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1647 // was the last version to use add them.
1648 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1649 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1650 internalFormat == GL_ALPHA8_EXT;
1651
Geoff Lang5d601382014-07-22 15:14:06 -04001652 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1653 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001654 {
Geoff Langb1196682014-07-23 13:47:29 -04001655 context->recordError(gl::Error(GL_INVALID_OPERATION));
1656 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001657 }
1658
1659 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001660 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001661 {
Geoff Langb1196682014-07-23 13:47:29 -04001662 context->recordError(gl::Error(GL_INVALID_OPERATION));
1663 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001664 }
1665
1666 // Non-power of 2 ES2 check
1667 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1668 {
1669 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001670 context->recordError(gl::Error(GL_INVALID_OPERATION));
1671 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001672 }
1673
1674 // Cube completeness check
1675 if (target == GL_TEXTURE_CUBE_MAP)
1676 {
1677 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1678 if (!textureCube->isCubeComplete())
1679 {
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
1685 texture->generateMipmaps();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001686 }
1687}
1688
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001689void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
1690{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001691 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001692
Geoff Langbfdea662014-07-23 14:16:32 -04001693 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001694 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001695 {
Geoff Langb1196682014-07-23 13:47:29 -04001696 if (n < 0)
1697 {
1698 context->recordError(gl::Error(GL_INVALID_VALUE));
1699 return;
1700 }
1701
Geoff Langbfdea662014-07-23 14:16:32 -04001702 for (int i = 0; i < n; i++)
1703 {
1704 fences[i] = context->createFenceNV();
1705 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001706 }
1707}
1708
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001709void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
1710{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001711 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001712
Geoff Langbfdea662014-07-23 14:16:32 -04001713 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001714 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001715 {
Geoff Langb1196682014-07-23 13:47:29 -04001716 if (n < 0)
1717 {
1718 context->recordError(gl::Error(GL_INVALID_VALUE));
1719 return;
1720 }
1721
Geoff Langbfdea662014-07-23 14:16:32 -04001722 for (int i = 0; i < n; i++)
1723 {
1724 framebuffers[i] = context->createFramebuffer();
1725 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001726 }
1727}
1728
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001729void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
1730{
1731 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1732
Geoff Langbfdea662014-07-23 14:16:32 -04001733 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001734 if (context)
1735 {
1736 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001737 {
Geoff Langb1196682014-07-23 13:47:29 -04001738 context->recordError(gl::Error(GL_INVALID_VALUE));
1739 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001740 }
Geoff Langbfdea662014-07-23 14:16:32 -04001741
1742 for (GLsizei i = 0; i < n; i++)
1743 {
1744 ids[i] = context->createQuery();
1745 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001746 }
1747}
1748
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001749void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1750{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001751 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001752
Geoff Langbfdea662014-07-23 14:16:32 -04001753 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001754 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001755 {
Geoff Langb1196682014-07-23 13:47:29 -04001756 if (n < 0)
1757 {
1758 context->recordError(gl::Error(GL_INVALID_VALUE));
1759 return;
1760 }
1761
Geoff Langbfdea662014-07-23 14:16:32 -04001762 for (int i = 0; i < n; i++)
1763 {
1764 renderbuffers[i] = context->createRenderbuffer();
1765 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001766 }
1767}
1768
1769void __stdcall glGenTextures(GLsizei n, GLuint* textures)
1770{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001771 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001772
Geoff Langbfdea662014-07-23 14:16:32 -04001773 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001774 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001775 {
Geoff Langb1196682014-07-23 13:47:29 -04001776 if (n < 0)
1777 {
1778 context->recordError(gl::Error(GL_INVALID_VALUE));
1779 return;
1780 }
1781
Geoff Langbfdea662014-07-23 14:16:32 -04001782 for (int i = 0; i < n; i++)
1783 {
1784 textures[i] = context->createTexture();
1785 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001786 }
1787}
1788
daniel@transgaming.com85423182010-04-22 13:35:27 +00001789void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001790{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001791 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001792 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001793 program, index, bufsize, length, size, type, name);
1794
Geoff Langbfdea662014-07-23 14:16:32 -04001795 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001796 if (context)
1797 {
Geoff Langb1196682014-07-23 13:47:29 -04001798 if (bufsize < 0)
1799 {
1800 context->recordError(gl::Error(GL_INVALID_VALUE));
1801 return;
1802 }
1803
Geoff Langbfdea662014-07-23 14:16:32 -04001804 gl::Program *programObject = context->getProgram(program);
1805
1806 if (!programObject)
1807 {
1808 if (context->getShader(program))
1809 {
Geoff Langb1196682014-07-23 13:47:29 -04001810 context->recordError(gl::Error(GL_INVALID_OPERATION));
1811 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001812 }
1813 else
1814 {
Geoff Langb1196682014-07-23 13:47:29 -04001815 context->recordError(gl::Error(GL_INVALID_VALUE));
1816 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001817 }
1818 }
1819
1820 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001821 {
Geoff Langb1196682014-07-23 13:47:29 -04001822 context->recordError(gl::Error(GL_INVALID_VALUE));
1823 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001824 }
1825
Geoff Langbfdea662014-07-23 14:16:32 -04001826 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001827 }
1828}
1829
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001830void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001831{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001832 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001833 "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 +00001834 program, index, bufsize, length, size, type, name);
1835
Geoff Langbfdea662014-07-23 14:16:32 -04001836
1837 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001838 if (context)
1839 {
Geoff Langb1196682014-07-23 13:47:29 -04001840 if (bufsize < 0)
1841 {
1842 context->recordError(gl::Error(GL_INVALID_VALUE));
1843 return;
1844 }
1845
Geoff Langbfdea662014-07-23 14:16:32 -04001846 gl::Program *programObject = context->getProgram(program);
1847
1848 if (!programObject)
1849 {
1850 if (context->getShader(program))
1851 {
Geoff Langb1196682014-07-23 13:47:29 -04001852 context->recordError(gl::Error(GL_INVALID_OPERATION));
1853 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001854 }
1855 else
1856 {
Geoff Langb1196682014-07-23 13:47:29 -04001857 context->recordError(gl::Error(GL_INVALID_VALUE));
1858 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001859 }
1860 }
1861
1862 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001863 {
Geoff Langb1196682014-07-23 13:47:29 -04001864 context->recordError(gl::Error(GL_INVALID_VALUE));
1865 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001866 }
1867
Geoff Langbfdea662014-07-23 14:16:32 -04001868 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001869 }
1870}
1871
1872void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1873{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001874 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 +00001875 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001876
Geoff Langbfdea662014-07-23 14:16:32 -04001877 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001878 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001879 {
Geoff Langb1196682014-07-23 13:47:29 -04001880 if (maxcount < 0)
1881 {
1882 context->recordError(gl::Error(GL_INVALID_VALUE));
1883 return;
1884 }
1885
Geoff Langbfdea662014-07-23 14:16:32 -04001886 gl::Program *programObject = context->getProgram(program);
1887
1888 if (!programObject)
1889 {
1890 if (context->getShader(program))
1891 {
Geoff Langb1196682014-07-23 13:47:29 -04001892 context->recordError(gl::Error(GL_INVALID_OPERATION));
1893 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001894 }
1895 else
1896 {
Geoff Langb1196682014-07-23 13:47:29 -04001897 context->recordError(gl::Error(GL_INVALID_VALUE));
1898 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001899 }
1900 }
1901
1902 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001903 }
1904}
1905
Geoff Langb1196682014-07-23 13:47:29 -04001906GLint __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001907{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001908 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001909
Geoff Langbfdea662014-07-23 14:16:32 -04001910 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001911 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001912 {
Geoff Langbfdea662014-07-23 14:16:32 -04001913 gl::Program *programObject = context->getProgram(program);
1914
1915 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001916 {
Geoff Langbfdea662014-07-23 14:16:32 -04001917 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001918 {
Geoff Langb1196682014-07-23 13:47:29 -04001919 context->recordError(gl::Error(GL_INVALID_OPERATION));
1920 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001921 }
Geoff Langbfdea662014-07-23 14:16:32 -04001922 else
1923 {
Geoff Langb1196682014-07-23 13:47:29 -04001924 context->recordError(gl::Error(GL_INVALID_VALUE));
1925 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001926 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001927 }
Geoff Langbfdea662014-07-23 14:16:32 -04001928
1929 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1930 if (!programObject->isLinked() || !programBinary)
1931 {
Geoff Langb1196682014-07-23 13:47:29 -04001932 context->recordError(gl::Error(GL_INVALID_OPERATION));
1933 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001934 }
1935
1936 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001937 }
1938
1939 return -1;
1940}
1941
1942void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
1943{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001944 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001945
Geoff Langbfdea662014-07-23 14:16:32 -04001946 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001947 if (context)
1948 {
1949 GLenum nativeType;
1950 unsigned int numParams = 0;
1951 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001952 {
Geoff Langbfdea662014-07-23 14:16:32 -04001953 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001954 }
Geoff Langbfdea662014-07-23 14:16:32 -04001955
1956 if (nativeType == GL_BOOL)
1957 {
1958 context->getBooleanv(pname, params);
1959 }
1960 else
1961 {
1962 CastStateValues(context, nativeType, pname, numParams, params);
1963 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001964 }
1965}
1966
1967void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1968{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001969 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 +00001970
Geoff Langbfdea662014-07-23 14:16:32 -04001971 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001972 if (context)
1973 {
1974 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001975 {
Geoff Langb1196682014-07-23 13:47:29 -04001976 context->recordError(gl::Error(GL_INVALID_ENUM));
1977 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00001978 }
Geoff Langbfdea662014-07-23 14:16:32 -04001979
1980 if (!gl::ValidBufferParameter(context, pname))
1981 {
Geoff Langb1196682014-07-23 13:47:29 -04001982 context->recordError(gl::Error(GL_INVALID_ENUM));
1983 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001984 }
1985
1986 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
1987
1988 if (!buffer)
1989 {
1990 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04001991 context->recordError(gl::Error(GL_INVALID_OPERATION));
1992 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001993 }
1994
1995 switch (pname)
1996 {
1997 case GL_BUFFER_USAGE:
1998 *params = static_cast<GLint>(buffer->getUsage());
1999 break;
2000 case GL_BUFFER_SIZE:
2001 *params = gl::clampCast<GLint>(buffer->getSize());
2002 break;
2003 case GL_BUFFER_ACCESS_FLAGS:
2004 *params = buffer->getAccessFlags();
2005 break;
2006 case GL_BUFFER_MAPPED:
2007 *params = static_cast<GLint>(buffer->isMapped());
2008 break;
2009 case GL_BUFFER_MAP_OFFSET:
2010 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2011 break;
2012 case GL_BUFFER_MAP_LENGTH:
2013 *params = gl::clampCast<GLint>(buffer->getMapLength());
2014 break;
2015 default: UNREACHABLE(); break;
2016 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002017 }
2018}
2019
2020GLenum __stdcall glGetError(void)
2021{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002022 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002023
2024 gl::Context *context = gl::getContext();
2025
2026 if (context)
2027 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002028 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002029 }
2030
2031 return GL_NO_ERROR;
2032}
2033
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002034void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
2035{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002036 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002037
Geoff Langbfdea662014-07-23 14:16:32 -04002038 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002039 if (context)
2040 {
2041 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2042
2043 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002044 {
Geoff Langb1196682014-07-23 13:47:29 -04002045 context->recordError(gl::Error(GL_INVALID_OPERATION));
2046 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002047 }
Geoff Langbfdea662014-07-23 14:16:32 -04002048
2049 if (fenceObject->isFence() != GL_TRUE)
2050 {
Geoff Langb1196682014-07-23 13:47:29 -04002051 context->recordError(gl::Error(GL_INVALID_OPERATION));
2052 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002053 }
2054
2055 switch (pname)
2056 {
2057 case GL_FENCE_STATUS_NV:
2058 case GL_FENCE_CONDITION_NV:
2059 break;
2060
Geoff Langb1196682014-07-23 13:47:29 -04002061 default:
2062 context->recordError(gl::Error(GL_INVALID_ENUM));
2063 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002064 }
2065
2066 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002067 }
2068}
2069
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002070void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
2071{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002072 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002073
Geoff Langbfdea662014-07-23 14:16:32 -04002074 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002075 if (context)
2076 {
2077 GLenum nativeType;
2078 unsigned int numParams = 0;
2079 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002080 {
Geoff Langbfdea662014-07-23 14:16:32 -04002081 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002082 }
Geoff Langbfdea662014-07-23 14:16:32 -04002083
2084 if (nativeType == GL_FLOAT)
2085 {
2086 context->getFloatv(pname, params);
2087 }
2088 else
2089 {
2090 CastStateValues(context, nativeType, pname, numParams, params);
2091 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002092 }
2093}
2094
2095void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2096{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002097 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 +00002098 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002099
Geoff Langbfdea662014-07-23 14:16:32 -04002100 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002101 if (context)
2102 {
2103 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002104 {
Geoff Langb1196682014-07-23 13:47:29 -04002105 context->recordError(gl::Error(GL_INVALID_ENUM));
2106 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002107 }
2108
2109 int clientVersion = context->getClientVersion();
2110
2111 switch (pname)
2112 {
2113 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2114 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2115 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2116 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2117 break;
Geoff Langb1196682014-07-23 13:47:29 -04002118
Geoff Langbfdea662014-07-23 14:16:32 -04002119 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2120 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002121 {
Geoff Langb1196682014-07-23 13:47:29 -04002122 context->recordError(gl::Error(GL_INVALID_ENUM));
2123 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002124 }
Geoff Langbfdea662014-07-23 14:16:32 -04002125 break;
Geoff Langb1196682014-07-23 13:47:29 -04002126
Geoff Langbfdea662014-07-23 14:16:32 -04002127 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2128 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2129 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2130 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2131 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2132 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2133 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2134 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2135 if (clientVersion < 3)
2136 {
Geoff Langb1196682014-07-23 13:47:29 -04002137 context->recordError(gl::Error(GL_INVALID_ENUM));
2138 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002139 }
2140 break;
Geoff Langb1196682014-07-23 13:47:29 -04002141
Geoff Langbfdea662014-07-23 14:16:32 -04002142 default:
Geoff Langb1196682014-07-23 13:47:29 -04002143 context->recordError(gl::Error(GL_INVALID_ENUM));
2144 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002145 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002146
Geoff Langbfdea662014-07-23 14:16:32 -04002147 // Determine if the attachment is a valid enum
2148 switch (attachment)
2149 {
2150 case GL_BACK:
2151 case GL_FRONT:
2152 case GL_DEPTH:
2153 case GL_STENCIL:
2154 case GL_DEPTH_STENCIL_ATTACHMENT:
2155 if (clientVersion < 3)
2156 {
Geoff Langb1196682014-07-23 13:47:29 -04002157 context->recordError(gl::Error(GL_INVALID_ENUM));
2158 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002159 }
2160 break;
2161
2162 case GL_DEPTH_ATTACHMENT:
2163 case GL_STENCIL_ATTACHMENT:
2164 break;
2165
2166 default:
2167 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2168 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2169 {
Geoff Langb1196682014-07-23 13:47:29 -04002170 context->recordError(gl::Error(GL_INVALID_ENUM));
2171 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002172 }
2173 break;
2174 }
2175
2176 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
2177 gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
2178
2179 if (framebufferHandle == 0)
2180 {
2181 if (clientVersion < 3)
2182 {
Geoff Langb1196682014-07-23 13:47:29 -04002183 context->recordError(gl::Error(GL_INVALID_OPERATION));
2184 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002185 }
2186
2187 switch (attachment)
2188 {
2189 case GL_BACK:
2190 case GL_DEPTH:
2191 case GL_STENCIL:
2192 break;
Geoff Langb1196682014-07-23 13:47:29 -04002193
Geoff Langbfdea662014-07-23 14:16:32 -04002194 default:
Geoff Langb1196682014-07-23 13:47:29 -04002195 context->recordError(gl::Error(GL_INVALID_OPERATION));
2196 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002197 }
2198 }
2199 else
2200 {
2201 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2202 {
2203 // Valid attachment query
2204 }
2205 else
2206 {
2207 switch (attachment)
2208 {
2209 case GL_DEPTH_ATTACHMENT:
2210 case GL_STENCIL_ATTACHMENT:
2211 break;
Geoff Langb1196682014-07-23 13:47:29 -04002212
Geoff Langbfdea662014-07-23 14:16:32 -04002213 case GL_DEPTH_STENCIL_ATTACHMENT:
2214 if (framebuffer->hasValidDepthStencil())
2215 {
Geoff Langb1196682014-07-23 13:47:29 -04002216 context->recordError(gl::Error(GL_INVALID_OPERATION));
2217 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002218 }
2219 break;
Geoff Langb1196682014-07-23 13:47:29 -04002220
Geoff Langbfdea662014-07-23 14:16:32 -04002221 default:
Geoff Langb1196682014-07-23 13:47:29 -04002222 context->recordError(gl::Error(GL_INVALID_OPERATION));
2223 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002224 }
2225 }
2226 }
2227
2228 GLenum attachmentType = GL_NONE;
2229 GLuint attachmentHandle = 0;
2230 GLuint attachmentLevel = 0;
2231 GLuint attachmentLayer = 0;
2232
2233 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
2234
2235 if (attachmentObject)
2236 {
2237 attachmentType = attachmentObject->type();
2238 attachmentHandle = attachmentObject->id();
2239 attachmentLevel = attachmentObject->mipLevel();
2240 attachmentLayer = attachmentObject->layer();
2241 }
2242
2243 GLenum attachmentObjectType; // Type category
2244 if (framebufferHandle == 0)
2245 {
2246 attachmentObjectType = GL_FRAMEBUFFER_DEFAULT;
2247 }
2248 else if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
2249 {
2250 attachmentObjectType = attachmentType;
2251 }
2252 else if (gl::ValidTexture2DDestinationTarget(context, attachmentType))
2253 {
2254 attachmentObjectType = GL_TEXTURE;
2255 }
2256 else
2257 {
2258 UNREACHABLE();
2259 return;
2260 }
2261
2262 if (attachmentObjectType == GL_NONE)
2263 {
2264 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2265 // is NONE, then querying any other pname will generate INVALID_ENUM.
2266
2267 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2268 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2269 // INVALID_OPERATION for all other pnames
Jamie Madill1e3fa742014-06-16 10:34:00 -04002270
Geoff Lang646559f2013-08-15 11:08:15 -04002271 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002272 {
Geoff Lang646559f2013-08-15 11:08:15 -04002273 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Langbfdea662014-07-23 14:16:32 -04002274 *params = attachmentObjectType;
2275 break;
2276
Geoff Lang646559f2013-08-15 11:08:15 -04002277 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang05b05022014-06-11 15:31:45 -04002278 if (clientVersion < 3)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002279 {
Geoff Langb1196682014-07-23 13:47:29 -04002280 context->recordError(gl::Error(GL_INVALID_ENUM));
2281 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002282 }
Geoff Langbfdea662014-07-23 14:16:32 -04002283 *params = 0;
Geoff Lang646559f2013-08-15 11:08:15 -04002284 break;
2285
2286 default:
Jamie Madill1e3fa742014-06-16 10:34:00 -04002287 if (clientVersion < 3)
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002288 {
Geoff Langb1196682014-07-23 13:47:29 -04002289 context->recordError(gl::Error(GL_INVALID_ENUM));
2290 return;
Geoff Lang646559f2013-08-15 11:08:15 -04002291 }
2292 else
2293 {
Geoff Langb1196682014-07-23 13:47:29 -04002294 context->recordError(gl::Error(GL_INVALID_OPERATION));
2295 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002296 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002297 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002298 }
Geoff Langbfdea662014-07-23 14:16:32 -04002299 else
2300 {
2301 ASSERT(attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE ||
2302 attachmentObjectType == GL_FRAMEBUFFER_DEFAULT);
2303 ASSERT(attachmentObject != NULL);
2304
2305 switch (pname)
2306 {
2307 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2308 *params = attachmentObjectType;
2309 break;
2310
2311 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2312 if (attachmentObjectType != GL_RENDERBUFFER && attachmentObjectType != GL_TEXTURE)
2313 {
Geoff Langb1196682014-07-23 13:47:29 -04002314 context->recordError(gl::Error(GL_INVALID_ENUM));
2315 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002316 }
2317 *params = attachmentHandle;
2318 break;
2319
2320 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2321 if (attachmentObjectType != GL_TEXTURE)
2322 {
Geoff Langb1196682014-07-23 13:47:29 -04002323 context->recordError(gl::Error(GL_INVALID_ENUM));
2324 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002325 }
2326 *params = attachmentLevel;
2327 break;
2328
2329 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2330 if (attachmentObjectType != GL_TEXTURE)
2331 {
Geoff Langb1196682014-07-23 13:47:29 -04002332 context->recordError(gl::Error(GL_INVALID_ENUM));
2333 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002334 }
2335 *params = gl::IsCubemapTextureTarget(attachmentType) ? attachmentType : 0;
2336 break;
2337
2338 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2339 *params = attachmentObject->getRedSize();
2340 break;
2341
2342 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2343 *params = attachmentObject->getGreenSize();
2344 break;
2345
2346 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2347 *params = attachmentObject->getBlueSize();
2348 break;
2349
2350 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2351 *params = attachmentObject->getAlphaSize();
2352 break;
2353
2354 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2355 *params = attachmentObject->getDepthSize();
2356 break;
2357
2358 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2359 *params = attachmentObject->getStencilSize();
2360 break;
2361
2362 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2363 if (attachment == GL_DEPTH_STENCIL)
2364 {
Geoff Langb1196682014-07-23 13:47:29 -04002365 context->recordError(gl::Error(GL_INVALID_OPERATION));
2366 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002367 }
2368 *params = attachmentObject->getComponentType();
2369 break;
2370
2371 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2372 *params = attachmentObject->getColorEncoding();
2373 break;
2374
2375 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2376 if (attachmentObjectType != GL_TEXTURE)
2377 {
Geoff Langb1196682014-07-23 13:47:29 -04002378 context->recordError(gl::Error(GL_INVALID_ENUM));
2379 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002380 }
2381 *params = attachmentLayer;
2382 break;
2383
2384 default:
2385 UNREACHABLE();
2386 break;
2387 }
2388 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002389 }
2390}
2391
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002392GLenum __stdcall glGetGraphicsResetStatusEXT(void)
2393{
2394 EVENT("()");
2395
Geoff Langbfdea662014-07-23 14:16:32 -04002396 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002397
Geoff Langbfdea662014-07-23 14:16:32 -04002398 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002399 {
Geoff Langbfdea662014-07-23 14:16:32 -04002400 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002401 }
Geoff Langbfdea662014-07-23 14:16:32 -04002402
2403 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002404}
2405
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002406void __stdcall glGetIntegerv(GLenum pname, GLint* params)
2407{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002408 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002409
Geoff Langbfdea662014-07-23 14:16:32 -04002410 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002411 if (context)
2412 {
2413 GLenum nativeType;
2414 unsigned int numParams = 0;
2415
2416 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002417 {
Geoff Langbfdea662014-07-23 14:16:32 -04002418 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002419 }
Geoff Langbfdea662014-07-23 14:16:32 -04002420
2421 if (nativeType == GL_INT)
2422 {
2423 context->getIntegerv(pname, params);
2424 }
2425 else
2426 {
2427 CastStateValues(context, nativeType, pname, numParams, params);
2428 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002429 }
2430}
2431
2432void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
2433{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002434 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002435
Geoff Langbfdea662014-07-23 14:16:32 -04002436 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002437 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002438 {
Geoff Langbfdea662014-07-23 14:16:32 -04002439 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002440
Geoff Langbfdea662014-07-23 14:16:32 -04002441 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442 {
Geoff Langb1196682014-07-23 13:47:29 -04002443 context->recordError(gl::Error(GL_INVALID_VALUE));
2444 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002445 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002446
Geoff Langbfdea662014-07-23 14:16:32 -04002447 if (context->getClientVersion() < 3)
2448 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449 switch (pname)
2450 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002451 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002452 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002453 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002454 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002455 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002456 context->recordError(gl::Error(GL_INVALID_ENUM));
2457 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002458 }
2459 }
Geoff Langbfdea662014-07-23 14:16:32 -04002460
2461 switch (pname)
2462 {
2463 case GL_DELETE_STATUS:
2464 *params = programObject->isFlaggedForDeletion();
2465 return;
2466 case GL_LINK_STATUS:
2467 *params = programObject->isLinked();
2468 return;
2469 case GL_VALIDATE_STATUS:
2470 *params = programObject->isValidated();
2471 return;
2472 case GL_INFO_LOG_LENGTH:
2473 *params = programObject->getInfoLogLength();
2474 return;
2475 case GL_ATTACHED_SHADERS:
2476 *params = programObject->getAttachedShadersCount();
2477 return;
2478 case GL_ACTIVE_ATTRIBUTES:
2479 *params = programObject->getActiveAttributeCount();
2480 return;
2481 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2482 *params = programObject->getActiveAttributeMaxLength();
2483 return;
2484 case GL_ACTIVE_UNIFORMS:
2485 *params = programObject->getActiveUniformCount();
2486 return;
2487 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2488 *params = programObject->getActiveUniformMaxLength();
2489 return;
2490 case GL_PROGRAM_BINARY_LENGTH_OES:
2491 *params = programObject->getProgramBinaryLength();
2492 return;
2493 case GL_ACTIVE_UNIFORM_BLOCKS:
2494 *params = programObject->getActiveUniformBlockCount();
2495 return;
2496 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2497 *params = programObject->getActiveUniformBlockMaxLength();
2498 break;
2499 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2500 *params = programObject->getTransformFeedbackBufferMode();
2501 break;
2502 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2503 *params = programObject->getTransformFeedbackVaryingCount();
2504 break;
2505 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2506 *params = programObject->getTransformFeedbackVaryingMaxLength();
2507 break;
Geoff Langb1196682014-07-23 13:47:29 -04002508
Geoff Langbfdea662014-07-23 14:16:32 -04002509 default:
Geoff Langb1196682014-07-23 13:47:29 -04002510 context->recordError(gl::Error(GL_INVALID_ENUM));
2511 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002512 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002513 }
2514}
2515
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002516void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002517{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002518 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 +00002519 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002520
Geoff Langbfdea662014-07-23 14:16:32 -04002521 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002522 if (context)
2523 {
Geoff Langb1196682014-07-23 13:47:29 -04002524 if (bufsize < 0)
2525 {
2526 context->recordError(gl::Error(GL_INVALID_VALUE));
2527 return;
2528 }
2529
Geoff Langbfdea662014-07-23 14:16:32 -04002530 gl::Program *programObject = context->getProgram(program);
2531
2532 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002533 {
Geoff Langb1196682014-07-23 13:47:29 -04002534 context->recordError(gl::Error(GL_INVALID_VALUE));
2535 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002536 }
2537
Geoff Langbfdea662014-07-23 14:16:32 -04002538 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002539 }
2540}
2541
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002542void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
2543{
2544 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2545
Geoff Langbfdea662014-07-23 14:16:32 -04002546 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002547 if (context)
2548 {
2549 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002550 {
Geoff Langb1196682014-07-23 13:47:29 -04002551 context->recordError(gl::Error(GL_INVALID_ENUM));
2552 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002553 }
Geoff Langbfdea662014-07-23 14:16:32 -04002554
2555 switch (pname)
2556 {
2557 case GL_CURRENT_QUERY_EXT:
2558 params[0] = context->getState().getActiveQueryId(target);
2559 break;
2560
2561 default:
Geoff Langb1196682014-07-23 13:47:29 -04002562 context->recordError(gl::Error(GL_INVALID_ENUM));
2563 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002564 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002565 }
2566}
2567
2568void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
2569{
2570 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2571
Geoff Langbfdea662014-07-23 14:16:32 -04002572 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002573 if (context)
2574 {
2575 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2576
2577 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002578 {
Geoff Langb1196682014-07-23 13:47:29 -04002579 context->recordError(gl::Error(GL_INVALID_OPERATION));
2580 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002581 }
Geoff Langbfdea662014-07-23 14:16:32 -04002582
2583 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2584 {
Geoff Langb1196682014-07-23 13:47:29 -04002585 context->recordError(gl::Error(GL_INVALID_OPERATION));
2586 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002587 }
2588
2589 switch(pname)
2590 {
2591 case GL_QUERY_RESULT_EXT:
2592 params[0] = queryObject->getResult();
2593 break;
2594 case GL_QUERY_RESULT_AVAILABLE_EXT:
2595 params[0] = queryObject->isResultAvailable();
2596 break;
2597 default:
Geoff Langb1196682014-07-23 13:47:29 -04002598 context->recordError(gl::Error(GL_INVALID_ENUM));
2599 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002600 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002601 }
2602}
2603
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002604void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
2605{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002606 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 +00002607
Geoff Langbfdea662014-07-23 14:16:32 -04002608 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002609 if (context)
2610 {
2611 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002612 {
Geoff Langb1196682014-07-23 13:47:29 -04002613 context->recordError(gl::Error(GL_INVALID_ENUM));
2614 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002615 }
Geoff Langbfdea662014-07-23 14:16:32 -04002616
2617 if (context->getState().getRenderbufferId() == 0)
2618 {
Geoff Langb1196682014-07-23 13:47:29 -04002619 context->recordError(gl::Error(GL_INVALID_OPERATION));
2620 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002621 }
2622
2623 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2624
2625 switch (pname)
2626 {
2627 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2628 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2629 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2630 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2631 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2632 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2633 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2634 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2635 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002636
Geoff Langbfdea662014-07-23 14:16:32 -04002637 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2638 if (!context->getExtensions().framebufferMultisample)
2639 {
Geoff Langb1196682014-07-23 13:47:29 -04002640 context->recordError(gl::Error(GL_INVALID_ENUM));
2641 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002642 }
2643 *params = renderbuffer->getSamples();
2644 break;
Geoff Langb1196682014-07-23 13:47:29 -04002645
Geoff Langbfdea662014-07-23 14:16:32 -04002646 default:
Geoff Langb1196682014-07-23 13:47:29 -04002647 context->recordError(gl::Error(GL_INVALID_ENUM));
2648 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002649 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002650 }
2651}
2652
2653void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
2654{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002655 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002656
Geoff Langbfdea662014-07-23 14:16:32 -04002657 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002658 if (context)
2659 {
2660 gl::Shader *shaderObject = context->getShader(shader);
2661
2662 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002663 {
Geoff Langb1196682014-07-23 13:47:29 -04002664 context->recordError(gl::Error(GL_INVALID_VALUE));
2665 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002666 }
Geoff Langbfdea662014-07-23 14:16:32 -04002667
2668 switch (pname)
2669 {
2670 case GL_SHADER_TYPE:
2671 *params = shaderObject->getType();
2672 return;
2673 case GL_DELETE_STATUS:
2674 *params = shaderObject->isFlaggedForDeletion();
2675 return;
2676 case GL_COMPILE_STATUS:
2677 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2678 return;
2679 case GL_INFO_LOG_LENGTH:
2680 *params = shaderObject->getInfoLogLength();
2681 return;
2682 case GL_SHADER_SOURCE_LENGTH:
2683 *params = shaderObject->getSourceLength();
2684 return;
2685 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2686 *params = shaderObject->getTranslatedSourceLength();
2687 return;
Geoff Langb1196682014-07-23 13:47:29 -04002688
Geoff Langbfdea662014-07-23 14:16:32 -04002689 default:
Geoff Langb1196682014-07-23 13:47:29 -04002690 context->recordError(gl::Error(GL_INVALID_ENUM));
2691 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002692 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002693 }
2694}
2695
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002696void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002697{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002698 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 +00002699 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002700
Geoff Langbfdea662014-07-23 14:16:32 -04002701 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002702 if (context)
2703 {
Geoff Langb1196682014-07-23 13:47:29 -04002704 if (bufsize < 0)
2705 {
2706 context->recordError(gl::Error(GL_INVALID_VALUE));
2707 return;
2708 }
2709
Geoff Langbfdea662014-07-23 14:16:32 -04002710 gl::Shader *shaderObject = context->getShader(shader);
2711
2712 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002713 {
Geoff Langb1196682014-07-23 13:47:29 -04002714 context->recordError(gl::Error(GL_INVALID_VALUE));
2715 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002716 }
2717
Geoff Langbfdea662014-07-23 14:16:32 -04002718 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002719 }
2720}
2721
2722void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2723{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002724 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 +00002725 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726
Geoff Langb1196682014-07-23 13:47:29 -04002727 gl::Context *context = gl::getNonLostContext();
2728 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002729 {
Geoff Langb1196682014-07-23 13:47:29 -04002730 switch (shadertype)
2731 {
2732 case GL_VERTEX_SHADER:
2733 case GL_FRAGMENT_SHADER:
2734 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002735
Geoff Langb1196682014-07-23 13:47:29 -04002736 default:
2737 context->recordError(gl::Error(GL_INVALID_ENUM));
2738 return;
2739 }
2740
2741 switch (precisiontype)
2742 {
2743 case GL_LOW_FLOAT:
2744 case GL_MEDIUM_FLOAT:
2745 case GL_HIGH_FLOAT:
2746 // Assume IEEE 754 precision
2747 range[0] = 127;
2748 range[1] = 127;
2749 *precision = 23;
2750 break;
2751
2752 case GL_LOW_INT:
2753 case GL_MEDIUM_INT:
2754 case GL_HIGH_INT:
2755 // Some (most) hardware only supports single-precision floating-point numbers,
2756 // which can accurately represent integers up to +/-16777216
2757 range[0] = 24;
2758 range[1] = 24;
2759 *precision = 0;
2760 break;
2761
2762 default:
2763 context->recordError(gl::Error(GL_INVALID_ENUM));
2764 return;
2765 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002766 }
2767}
2768
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002769void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002770{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002771 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 +00002772 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002773
Geoff Langbfdea662014-07-23 14:16:32 -04002774 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002775 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002776 {
Geoff Langb1196682014-07-23 13:47:29 -04002777 if (bufsize < 0)
2778 {
2779 context->recordError(gl::Error(GL_INVALID_VALUE));
2780 return;
2781 }
2782
Geoff Langbfdea662014-07-23 14:16:32 -04002783 gl::Shader *shaderObject = context->getShader(shader);
2784
2785 if (!shaderObject)
2786 {
Geoff Langb1196682014-07-23 13:47:29 -04002787 context->recordError(gl::Error(GL_INVALID_OPERATION));
2788 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002789 }
2790
2791 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002792 }
2793}
2794
zmo@google.coma574f782011-10-03 21:45:23 +00002795void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
2796{
2797 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2798 shader, bufsize, length, source);
2799
Geoff Langbfdea662014-07-23 14:16:32 -04002800 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002801 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002802 {
Geoff Langb1196682014-07-23 13:47:29 -04002803 if (bufsize < 0)
2804 {
2805 context->recordError(gl::Error(GL_INVALID_VALUE));
2806 return;
2807 }
2808
Geoff Langbfdea662014-07-23 14:16:32 -04002809 gl::Shader *shaderObject = context->getShader(shader);
2810
2811 if (!shaderObject)
2812 {
Geoff Langb1196682014-07-23 13:47:29 -04002813 context->recordError(gl::Error(GL_INVALID_OPERATION));
2814 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002815 }
2816
2817 shaderObject->getTranslatedSource(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002818 }
2819}
2820
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002821const GLubyte* __stdcall glGetString(GLenum name)
2822{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002823 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002824
Geoff Langbfdea662014-07-23 14:16:32 -04002825 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002826
Geoff Langbfdea662014-07-23 14:16:32 -04002827 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002828 {
Geoff Langbfdea662014-07-23 14:16:32 -04002829 case GL_VENDOR:
2830 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002831
Geoff Langbfdea662014-07-23 14:16:32 -04002832 case GL_RENDERER:
2833 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002834
Geoff Langbfdea662014-07-23 14:16:32 -04002835 case GL_VERSION:
2836 if (context->getClientVersion() == 2)
2837 {
2838 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2839 }
2840 else
2841 {
2842 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2843 }
Geoff Langb1196682014-07-23 13:47:29 -04002844
Geoff Langbfdea662014-07-23 14:16:32 -04002845 case GL_SHADING_LANGUAGE_VERSION:
2846 if (context->getClientVersion() == 2)
2847 {
2848 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2849 }
2850 else
2851 {
2852 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2853 }
Geoff Langb1196682014-07-23 13:47:29 -04002854
Geoff Langbfdea662014-07-23 14:16:32 -04002855 case GL_EXTENSIONS:
2856 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002857
Geoff Langbfdea662014-07-23 14:16:32 -04002858 default:
Geoff Langb1196682014-07-23 13:47:29 -04002859 if (context)
2860 {
2861 context->recordError(gl::Error(GL_INVALID_ENUM));
2862 }
2863 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002864 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002865}
2866
2867void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2868{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002869 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 +00002870
Geoff Langbfdea662014-07-23 14:16:32 -04002871 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002872 if (context)
2873 {
2874 gl::Texture *texture = context->getTargetTexture(target);
2875
2876 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002877 {
Geoff Langb1196682014-07-23 13:47:29 -04002878 context->recordError(gl::Error(GL_INVALID_ENUM));
2879 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002880 }
Geoff Langbfdea662014-07-23 14:16:32 -04002881
2882 switch (pname)
2883 {
2884 case GL_TEXTURE_MAG_FILTER:
2885 *params = (GLfloat)texture->getSamplerState().magFilter;
2886 break;
2887 case GL_TEXTURE_MIN_FILTER:
2888 *params = (GLfloat)texture->getSamplerState().minFilter;
2889 break;
2890 case GL_TEXTURE_WRAP_S:
2891 *params = (GLfloat)texture->getSamplerState().wrapS;
2892 break;
2893 case GL_TEXTURE_WRAP_T:
2894 *params = (GLfloat)texture->getSamplerState().wrapT;
2895 break;
2896 case GL_TEXTURE_WRAP_R:
2897 if (context->getClientVersion() < 3)
2898 {
Geoff Langb1196682014-07-23 13:47:29 -04002899 context->recordError(gl::Error(GL_INVALID_ENUM));
2900 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002901 }
2902 *params = (GLfloat)texture->getSamplerState().wrapR;
2903 break;
2904 case GL_TEXTURE_IMMUTABLE_FORMAT:
2905 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2906 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2907 break;
2908 case GL_TEXTURE_IMMUTABLE_LEVELS:
2909 if (context->getClientVersion() < 3)
2910 {
Geoff Langb1196682014-07-23 13:47:29 -04002911 context->recordError(gl::Error(GL_INVALID_ENUM));
2912 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002913 }
2914 *params = (GLfloat)texture->immutableLevelCount();
2915 break;
2916 case GL_TEXTURE_USAGE_ANGLE:
2917 *params = (GLfloat)texture->getUsage();
2918 break;
2919 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2920 if (!context->getExtensions().textureFilterAnisotropic)
2921 {
Geoff Langb1196682014-07-23 13:47:29 -04002922 context->recordError(gl::Error(GL_INVALID_ENUM));
2923 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002924 }
2925 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
2926 break;
2927 case GL_TEXTURE_SWIZZLE_R:
2928 if (context->getClientVersion() < 3)
2929 {
Geoff Langb1196682014-07-23 13:47:29 -04002930 context->recordError(gl::Error(GL_INVALID_ENUM));
2931 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002932 }
2933 *params = (GLfloat)texture->getSamplerState().swizzleRed;
2934 break;
2935 case GL_TEXTURE_SWIZZLE_G:
2936 if (context->getClientVersion() < 3)
2937 {
Geoff Langb1196682014-07-23 13:47:29 -04002938 context->recordError(gl::Error(GL_INVALID_ENUM));
2939 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002940 }
2941 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
2942 break;
2943 case GL_TEXTURE_SWIZZLE_B:
2944 if (context->getClientVersion() < 3)
2945 {
Geoff Langb1196682014-07-23 13:47:29 -04002946 context->recordError(gl::Error(GL_INVALID_ENUM));
2947 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002948 }
2949 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
2950 break;
2951 case GL_TEXTURE_SWIZZLE_A:
2952 if (context->getClientVersion() < 3)
2953 {
Geoff Langb1196682014-07-23 13:47:29 -04002954 context->recordError(gl::Error(GL_INVALID_ENUM));
2955 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002956 }
2957 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
2958 break;
2959 case GL_TEXTURE_BASE_LEVEL:
2960 if (context->getClientVersion() < 3)
2961 {
Geoff Langb1196682014-07-23 13:47:29 -04002962 context->recordError(gl::Error(GL_INVALID_ENUM));
2963 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002964 }
2965 *params = (GLfloat)texture->getSamplerState().baseLevel;
2966 break;
2967 case GL_TEXTURE_MAX_LEVEL:
2968 if (context->getClientVersion() < 3)
2969 {
Geoff Langb1196682014-07-23 13:47:29 -04002970 context->recordError(gl::Error(GL_INVALID_ENUM));
2971 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002972 }
2973 *params = (GLfloat)texture->getSamplerState().maxLevel;
2974 break;
2975 case GL_TEXTURE_MIN_LOD:
2976 if (context->getClientVersion() < 3)
2977 {
Geoff Langb1196682014-07-23 13:47:29 -04002978 context->recordError(gl::Error(GL_INVALID_ENUM));
2979 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002980 }
2981 *params = texture->getSamplerState().minLod;
2982 break;
2983 case GL_TEXTURE_MAX_LOD:
2984 if (context->getClientVersion() < 3)
2985 {
Geoff Langb1196682014-07-23 13:47:29 -04002986 context->recordError(gl::Error(GL_INVALID_ENUM));
2987 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002988 }
2989 *params = texture->getSamplerState().maxLod;
2990 break;
Geoff Langb1196682014-07-23 13:47:29 -04002991
Geoff Langbfdea662014-07-23 14:16:32 -04002992 default:
Geoff Langb1196682014-07-23 13:47:29 -04002993 context->recordError(gl::Error(GL_INVALID_ENUM));
2994 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002995 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002996 }
2997}
2998
2999void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
3000{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003001 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 +00003002
Geoff Langbfdea662014-07-23 14:16:32 -04003003 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003004 if (context)
3005 {
3006 gl::Texture *texture = context->getTargetTexture(target);
3007
3008 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003009 {
Geoff Langb1196682014-07-23 13:47:29 -04003010 context->recordError(gl::Error(GL_INVALID_ENUM));
3011 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003012 }
Geoff Langbfdea662014-07-23 14:16:32 -04003013
3014 switch (pname)
3015 {
3016 case GL_TEXTURE_MAG_FILTER:
3017 *params = texture->getSamplerState().magFilter;
3018 break;
3019 case GL_TEXTURE_MIN_FILTER:
3020 *params = texture->getSamplerState().minFilter;
3021 break;
3022 case GL_TEXTURE_WRAP_S:
3023 *params = texture->getSamplerState().wrapS;
3024 break;
3025 case GL_TEXTURE_WRAP_T:
3026 *params = texture->getSamplerState().wrapT;
3027 break;
3028 case GL_TEXTURE_WRAP_R:
3029 if (context->getClientVersion() < 3)
3030 {
Geoff Langb1196682014-07-23 13:47:29 -04003031 context->recordError(gl::Error(GL_INVALID_ENUM));
3032 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003033 }
3034 *params = texture->getSamplerState().wrapR;
3035 break;
3036 case GL_TEXTURE_IMMUTABLE_FORMAT:
3037 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3038 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3039 break;
3040 case GL_TEXTURE_IMMUTABLE_LEVELS:
3041 if (context->getClientVersion() < 3)
3042 {
Geoff Langb1196682014-07-23 13:47:29 -04003043 context->recordError(gl::Error(GL_INVALID_ENUM));
3044 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003045 }
3046 *params = texture->immutableLevelCount();
3047 break;
3048 case GL_TEXTURE_USAGE_ANGLE:
3049 *params = texture->getUsage();
3050 break;
3051 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3052 if (!context->getExtensions().textureFilterAnisotropic)
3053 {
Geoff Langb1196682014-07-23 13:47:29 -04003054 context->recordError(gl::Error(GL_INVALID_ENUM));
3055 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003056 }
3057 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3058 break;
3059 case GL_TEXTURE_SWIZZLE_R:
3060 if (context->getClientVersion() < 3)
3061 {
Geoff Langb1196682014-07-23 13:47:29 -04003062 context->recordError(gl::Error(GL_INVALID_ENUM));
3063 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003064 }
3065 *params = texture->getSamplerState().swizzleRed;
3066 break;
3067 case GL_TEXTURE_SWIZZLE_G:
3068 if (context->getClientVersion() < 3)
3069 {
Geoff Langb1196682014-07-23 13:47:29 -04003070 context->recordError(gl::Error(GL_INVALID_ENUM));
3071 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003072 }
3073 *params = texture->getSamplerState().swizzleGreen;
3074 break;
3075 case GL_TEXTURE_SWIZZLE_B:
3076 if (context->getClientVersion() < 3)
3077 {
Geoff Langb1196682014-07-23 13:47:29 -04003078 context->recordError(gl::Error(GL_INVALID_ENUM));
3079 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003080 }
3081 *params = texture->getSamplerState().swizzleBlue;
3082 break;
3083 case GL_TEXTURE_SWIZZLE_A:
3084 if (context->getClientVersion() < 3)
3085 {
Geoff Langb1196682014-07-23 13:47:29 -04003086 context->recordError(gl::Error(GL_INVALID_ENUM));
3087 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003088 }
3089 *params = texture->getSamplerState().swizzleAlpha;
3090 break;
3091 case GL_TEXTURE_BASE_LEVEL:
3092 if (context->getClientVersion() < 3)
3093 {
Geoff Langb1196682014-07-23 13:47:29 -04003094 context->recordError(gl::Error(GL_INVALID_ENUM));
3095 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003096 }
3097 *params = texture->getSamplerState().baseLevel;
3098 break;
3099 case GL_TEXTURE_MAX_LEVEL:
3100 if (context->getClientVersion() < 3)
3101 {
Geoff Langb1196682014-07-23 13:47:29 -04003102 context->recordError(gl::Error(GL_INVALID_ENUM));
3103 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003104 }
3105 *params = texture->getSamplerState().maxLevel;
3106 break;
3107 case GL_TEXTURE_MIN_LOD:
3108 if (context->getClientVersion() < 3)
3109 {
Geoff Langb1196682014-07-23 13:47:29 -04003110 context->recordError(gl::Error(GL_INVALID_ENUM));
3111 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003112 }
3113 *params = (GLint)texture->getSamplerState().minLod;
3114 break;
3115 case GL_TEXTURE_MAX_LOD:
3116 if (context->getClientVersion() < 3)
3117 {
Geoff Langb1196682014-07-23 13:47:29 -04003118 context->recordError(gl::Error(GL_INVALID_ENUM));
3119 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003120 }
3121 *params = (GLint)texture->getSamplerState().maxLod;
3122 break;
Geoff Langb1196682014-07-23 13:47:29 -04003123
Geoff Langbfdea662014-07-23 14:16:32 -04003124 default:
Geoff Langb1196682014-07-23 13:47:29 -04003125 context->recordError(gl::Error(GL_INVALID_ENUM));
3126 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003127 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003128 }
3129}
3130
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003131void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
3132{
3133 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3134 program, location, bufSize, params);
3135
Geoff Langbfdea662014-07-23 14:16:32 -04003136 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003137 if (context)
3138 {
Jamie Madill0063c512014-08-25 15:47:53 -04003139 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003140 {
Jamie Madill0063c512014-08-25 15:47:53 -04003141 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003142 }
3143
Jamie Madill0063c512014-08-25 15:47:53 -04003144 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3145 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003146
Jamie Madill99a1e982014-08-25 15:47:54 -04003147 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003148 }
3149}
3150
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003151void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
3152{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003153 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003154
Geoff Langbfdea662014-07-23 14:16:32 -04003155 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003156 if (context)
3157 {
Jamie Madill0063c512014-08-25 15:47:53 -04003158 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003159 {
Jamie Madill0063c512014-08-25 15:47:53 -04003160 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003161 }
Geoff Langbfdea662014-07-23 14:16:32 -04003162
Jamie Madill0063c512014-08-25 15:47:53 -04003163 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3164 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003165
Jamie Madill99a1e982014-08-25 15:47:54 -04003166 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003167 }
3168}
3169
3170void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
3171{
Geoff Langbfdea662014-07-23 14:16:32 -04003172 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003173 program, location, bufSize, params);
3174
Geoff Langbfdea662014-07-23 14:16:32 -04003175 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003176 if (context)
3177 {
Jamie Madill0063c512014-08-25 15:47:53 -04003178 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003179 {
Jamie Madill0063c512014-08-25 15:47:53 -04003180 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003181 }
3182
Jamie Madill0063c512014-08-25 15:47:53 -04003183 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3184 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003185
Jamie Madill99a1e982014-08-25 15:47:54 -04003186 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187 }
3188}
3189
3190void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
3191{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003192 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003193
Geoff Langbfdea662014-07-23 14:16:32 -04003194 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003195 if (context)
3196 {
Jamie Madill0063c512014-08-25 15:47:53 -04003197 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003198 {
Jamie Madill0063c512014-08-25 15:47:53 -04003199 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003200 }
Geoff Langbfdea662014-07-23 14:16:32 -04003201
Jamie Madill0063c512014-08-25 15:47:53 -04003202 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
3203 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003204
Jamie Madill99a1e982014-08-25 15:47:54 -04003205 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003206 }
3207}
3208
Geoff Langb1196682014-07-23 13:47:29 -04003209GLint __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003210{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003211 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003212
Geoff Langbfdea662014-07-23 14:16:32 -04003213 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003214 if (context)
3215 {
Geoff Langb1196682014-07-23 13:47:29 -04003216 if (strstr(name, "gl_") == name)
3217 {
3218 return -1;
3219 }
3220
Geoff Langbfdea662014-07-23 14:16:32 -04003221 gl::Program *programObject = context->getProgram(program);
3222
3223 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003224 {
Geoff Langbfdea662014-07-23 14:16:32 -04003225 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003226 {
Geoff Langb1196682014-07-23 13:47:29 -04003227 context->recordError(gl::Error(GL_INVALID_OPERATION));
3228 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229 }
Geoff Langbfdea662014-07-23 14:16:32 -04003230 else
3231 {
Geoff Langb1196682014-07-23 13:47:29 -04003232 context->recordError(gl::Error(GL_INVALID_VALUE));
3233 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003234 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003235 }
Geoff Langbfdea662014-07-23 14:16:32 -04003236
3237 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3238 if (!programObject->isLinked() || !programBinary)
3239 {
Geoff Langb1196682014-07-23 13:47:29 -04003240 context->recordError(gl::Error(GL_INVALID_OPERATION));
3241 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003242 }
3243
3244 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003245 }
3246
3247 return -1;
3248}
3249
3250void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
3251{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003252 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003253
Geoff Langbfdea662014-07-23 14:16:32 -04003254 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003255 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003256 {
Geoff Langbfdea662014-07-23 14:16:32 -04003257 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003258 {
Geoff Langb1196682014-07-23 13:47:29 -04003259 context->recordError(gl::Error(GL_INVALID_VALUE));
3260 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003261 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003262
Geoff Langbfdea662014-07-23 14:16:32 -04003263 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003264 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003265 {
3266 return;
3267 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003268
Geoff Langbfdea662014-07-23 14:16:32 -04003269 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3270 {
3271 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3272 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003273 {
Geoff Langbfdea662014-07-23 14:16:32 -04003274 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003275 }
3276 }
Geoff Langbfdea662014-07-23 14:16:32 -04003277 else
3278 {
3279 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3280 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003281 }
3282}
3283
3284void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
3285{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003286 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003287
Geoff Langbfdea662014-07-23 14:16:32 -04003288 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003289 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003290 {
Geoff Langbfdea662014-07-23 14:16:32 -04003291 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003292 {
Geoff Langb1196682014-07-23 13:47:29 -04003293 context->recordError(gl::Error(GL_INVALID_VALUE));
3294 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003295 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003296
Geoff Langbfdea662014-07-23 14:16:32 -04003297 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003298
Geoff Langb1196682014-07-23 13:47:29 -04003299 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003300 {
3301 return;
3302 }
Jamie Madillaff71502013-07-02 11:57:05 -04003303
Geoff Langbfdea662014-07-23 14:16:32 -04003304 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3305 {
3306 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3307 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003308 {
Geoff Langbfdea662014-07-23 14:16:32 -04003309 float currentValue = currentValueData.FloatValues[i];
3310 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003311 }
3312 }
Geoff Langbfdea662014-07-23 14:16:32 -04003313 else
3314 {
3315 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003317 }
3318}
3319
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003320void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003321{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003322 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003323
Geoff Langbfdea662014-07-23 14:16:32 -04003324 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003325 if (context)
3326 {
3327 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003328 {
Geoff Langb1196682014-07-23 13:47:29 -04003329 context->recordError(gl::Error(GL_INVALID_VALUE));
3330 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003331 }
Geoff Langbfdea662014-07-23 14:16:32 -04003332
3333 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3334 {
Geoff Langb1196682014-07-23 13:47:29 -04003335 context->recordError(gl::Error(GL_INVALID_ENUM));
3336 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003337 }
3338
3339 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003340 }
3341}
3342
3343void __stdcall glHint(GLenum target, GLenum mode)
3344{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003345 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003346
Geoff Langbfdea662014-07-23 14:16:32 -04003347 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003348 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003349 {
Geoff Langb1196682014-07-23 13:47:29 -04003350 switch (mode)
3351 {
3352 case GL_FASTEST:
3353 case GL_NICEST:
3354 case GL_DONT_CARE:
3355 break;
3356
3357 default:
3358 context->recordError(gl::Error(GL_INVALID_ENUM));
3359 return;
3360 }
3361
3362 switch (target)
3363 {
3364 case GL_GENERATE_MIPMAP_HINT:
3365 context->getState().setGenerateMipmapHint(mode);
3366 break;
3367
3368 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3369 context->getState().setFragmentShaderDerivativeHint(mode);
3370 break;
3371
3372 default:
3373 context->recordError(gl::Error(GL_INVALID_ENUM));
3374 return;
3375 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003376 }
3377}
3378
3379GLboolean __stdcall glIsBuffer(GLuint buffer)
3380{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003381 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003382
Geoff Langbfdea662014-07-23 14:16:32 -04003383 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003384 if (context && buffer)
3385 {
3386 gl::Buffer *bufferObject = context->getBuffer(buffer);
3387
3388 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003389 {
Geoff Langbfdea662014-07-23 14:16:32 -04003390 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003391 }
3392 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003393
3394 return GL_FALSE;
3395}
3396
3397GLboolean __stdcall glIsEnabled(GLenum cap)
3398{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003399 EVENT("(GLenum cap = 0x%X)", cap);
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)
3403 {
3404 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003405 {
Geoff Langb1196682014-07-23 13:47:29 -04003406 context->recordError(gl::Error(GL_INVALID_ENUM));
3407 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003408 }
Geoff Langbfdea662014-07-23 14:16:32 -04003409
3410 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003411 }
3412
3413 return false;
3414}
3415
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003416GLboolean __stdcall glIsFenceNV(GLuint fence)
3417{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003418 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003419
Geoff Langbfdea662014-07-23 14:16:32 -04003420 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003421 if (context)
3422 {
3423 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3424
3425 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003426 {
Geoff Langbfdea662014-07-23 14:16:32 -04003427 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003428 }
Geoff Langbfdea662014-07-23 14:16:32 -04003429
3430 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003431 }
3432
3433 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003434}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003435
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003436GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
3437{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003438 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003439
Geoff Langbfdea662014-07-23 14:16:32 -04003440 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003441 if (context && framebuffer)
3442 {
3443 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3444
3445 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003446 {
Geoff Langbfdea662014-07-23 14:16:32 -04003447 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003448 }
3449 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003450
3451 return GL_FALSE;
3452}
3453
3454GLboolean __stdcall glIsProgram(GLuint program)
3455{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003456 EVENT("(GLuint program = %d)", program);
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 && program)
3460 {
3461 gl::Program *programObject = context->getProgram(program);
3462
3463 if (programObject)
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
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003472GLboolean __stdcall glIsQueryEXT(GLuint id)
3473{
3474 EVENT("(GLuint id = %d)", id);
3475
Geoff Langbfdea662014-07-23 14:16:32 -04003476 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003477 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003478 {
Geoff Langbfdea662014-07-23 14:16:32 -04003479 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003480 }
3481
3482 return GL_FALSE;
3483}
3484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003485GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
3486{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003487 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003488
Geoff Langbfdea662014-07-23 14:16:32 -04003489 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003490 if (context && renderbuffer)
3491 {
3492 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3493
3494 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003495 {
Geoff Langbfdea662014-07-23 14:16:32 -04003496 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003497 }
3498 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003499
3500 return GL_FALSE;
3501}
3502
3503GLboolean __stdcall glIsShader(GLuint shader)
3504{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003505 EVENT("(GLuint shader = %d)", shader);
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 && shader)
3509 {
3510 gl::Shader *shaderObject = context->getShader(shader);
3511
3512 if (shaderObject)
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 glIsTexture(GLuint texture)
3522{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003523 EVENT("(GLuint texture = %d)", texture);
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 && texture)
3527 {
3528 gl::Texture *textureObject = context->getTexture(texture);
3529
3530 if (textureObject)
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
3539void __stdcall glLineWidth(GLfloat width)
3540{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003541 EVENT("(GLfloat width = %f)", width);
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)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003545 {
Geoff Langb1196682014-07-23 13:47:29 -04003546 if (width <= 0.0f)
3547 {
3548 context->recordError(gl::Error(GL_INVALID_VALUE));
3549 return;
3550 }
3551
Geoff Langbfdea662014-07-23 14:16:32 -04003552 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003553 }
3554}
3555
3556void __stdcall glLinkProgram(GLuint program)
3557{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003558 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003559
Geoff Langbfdea662014-07-23 14:16:32 -04003560 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003561 if (context)
3562 {
3563 gl::Program *programObject = context->getProgram(program);
3564
3565 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003566 {
Geoff Langbfdea662014-07-23 14:16:32 -04003567 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568 {
Geoff Langb1196682014-07-23 13:47:29 -04003569 context->recordError(gl::Error(GL_INVALID_OPERATION));
3570 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571 }
Geoff Langbfdea662014-07-23 14:16:32 -04003572 else
3573 {
Geoff Langb1196682014-07-23 13:47:29 -04003574 context->recordError(gl::Error(GL_INVALID_VALUE));
3575 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003576 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003577 }
Geoff Langbfdea662014-07-23 14:16:32 -04003578
3579 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003580 }
3581}
3582
3583void __stdcall glPixelStorei(GLenum pname, GLint param)
3584{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003585 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003586
Geoff Langbfdea662014-07-23 14:16:32 -04003587 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003588 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003589 {
Geoff Langbfdea662014-07-23 14:16:32 -04003590 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003591 {
Geoff Langbfdea662014-07-23 14:16:32 -04003592 case GL_UNPACK_ALIGNMENT:
3593 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003594 {
Geoff Langb1196682014-07-23 13:47:29 -04003595 context->recordError(gl::Error(GL_INVALID_VALUE));
3596 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003597 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003598
Geoff Langbfdea662014-07-23 14:16:32 -04003599 context->getState().setUnpackAlignment(param);
3600 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003601
Geoff Langbfdea662014-07-23 14:16:32 -04003602 case GL_PACK_ALIGNMENT:
3603 if (param != 1 && param != 2 && param != 4 && param != 8)
3604 {
Geoff Langb1196682014-07-23 13:47:29 -04003605 context->recordError(gl::Error(GL_INVALID_VALUE));
3606 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003607 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003608
Geoff Langbfdea662014-07-23 14:16:32 -04003609 context->getState().setPackAlignment(param);
3610 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003611
Geoff Langbfdea662014-07-23 14:16:32 -04003612 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3613 context->getState().setPackReverseRowOrder(param != 0);
3614 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003615
Geoff Langbfdea662014-07-23 14:16:32 -04003616 case GL_UNPACK_IMAGE_HEIGHT:
3617 case GL_UNPACK_SKIP_IMAGES:
3618 case GL_UNPACK_ROW_LENGTH:
3619 case GL_UNPACK_SKIP_ROWS:
3620 case GL_UNPACK_SKIP_PIXELS:
3621 case GL_PACK_ROW_LENGTH:
3622 case GL_PACK_SKIP_ROWS:
3623 case GL_PACK_SKIP_PIXELS:
3624 if (context->getClientVersion() < 3)
3625 {
Geoff Langb1196682014-07-23 13:47:29 -04003626 context->recordError(gl::Error(GL_INVALID_ENUM));
3627 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003628 }
Geoff Langbfdea662014-07-23 14:16:32 -04003629 UNIMPLEMENTED();
3630 break;
3631
3632 default:
Geoff Langb1196682014-07-23 13:47:29 -04003633 context->recordError(gl::Error(GL_INVALID_ENUM));
3634 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003635 }
3636 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003637}
3638
3639void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
3640{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003641 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003642
Geoff Langbfdea662014-07-23 14:16:32 -04003643 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003644 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003645 {
Geoff Langbfdea662014-07-23 14:16:32 -04003646 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003647 }
3648}
3649
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003650void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
3651 GLenum format, GLenum type, GLsizei bufSize,
3652 GLvoid *data)
3653{
3654 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3655 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3656 x, y, width, height, format, type, bufSize, data);
3657
Geoff Langbfdea662014-07-23 14:16:32 -04003658 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003659 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003660 {
Geoff Langb1196682014-07-23 13:47:29 -04003661 if (width < 0 || height < 0 || bufSize < 0)
3662 {
3663 context->recordError(gl::Error(GL_INVALID_VALUE));
3664 return;
3665 }
3666
Geoff Langbfdea662014-07-23 14:16:32 -04003667 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3668 format, type, &bufSize, data))
3669 {
3670 return;
3671 }
3672
3673 context->readPixels(x, y, width, height, format, type, &bufSize, data);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003674 }
3675}
3676
3677void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
3678 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003680 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003681 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003682 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003683
Geoff Langbfdea662014-07-23 14:16:32 -04003684 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003685 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003686 {
Geoff Langb1196682014-07-23 13:47:29 -04003687 if (width < 0 || height < 0)
3688 {
3689 context->recordError(gl::Error(GL_INVALID_VALUE));
3690 return;
3691 }
3692
Geoff Langbfdea662014-07-23 14:16:32 -04003693 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3694 format, type, NULL, pixels))
3695 {
3696 return;
3697 }
3698
3699 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003700 }
3701}
3702
3703void __stdcall glReleaseShaderCompiler(void)
3704{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003705 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003706
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003707 gl::Context *context = gl::getNonLostContext();
3708
3709 if (context)
3710 {
3711 context->releaseShaderCompiler();
3712 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003713}
3714
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003715void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003716{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003717 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 +00003718 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003719
Geoff Langbfdea662014-07-23 14:16:32 -04003720 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003721 if (context)
3722 {
3723 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
3724 width, height, true))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003725 {
Geoff Langbfdea662014-07-23 14:16:32 -04003726 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003727 }
Geoff Langbfdea662014-07-23 14:16:32 -04003728
3729 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003730 }
3731}
3732
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003733void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3734{
3735 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3736}
3737
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003738void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
3739{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003740 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003741
Geoff Langbfdea662014-07-23 14:16:32 -04003742 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003743
Geoff Langbfdea662014-07-23 14:16:32 -04003744 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003745 {
Geoff Langbfdea662014-07-23 14:16:32 -04003746 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003747 }
3748}
3749
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003750void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
3751{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003752 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003753
Geoff Langbfdea662014-07-23 14:16:32 -04003754 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003755 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003756 {
Geoff Langb1196682014-07-23 13:47:29 -04003757 if (condition != GL_ALL_COMPLETED_NV)
3758 {
3759 context->recordError(gl::Error(GL_INVALID_ENUM));
3760 return;
3761 }
3762
Geoff Langbfdea662014-07-23 14:16:32 -04003763 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3764
3765 if (fenceObject == NULL)
3766 {
Geoff Langb1196682014-07-23 13:47:29 -04003767 context->recordError(gl::Error(GL_INVALID_OPERATION));
3768 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003769 }
3770
3771 fenceObject->setFence(condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003772 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003773}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003774
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003775void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
3776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003777 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 +00003778
Geoff Langbfdea662014-07-23 14:16:32 -04003779 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003780 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003781 {
Geoff Langb1196682014-07-23 13:47:29 -04003782 if (width < 0 || height < 0)
3783 {
3784 context->recordError(gl::Error(GL_INVALID_VALUE));
3785 return;
3786 }
3787
Geoff Langbfdea662014-07-23 14:16:32 -04003788 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789 }
3790}
3791
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003792void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003793{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003794 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003795 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003796 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003797
Geoff Lang900013c2014-07-07 11:32:19 -04003798 gl::Context* context = gl::getNonLostContext();
3799 if (context)
3800 {
3801 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3802 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3803 {
Geoff Langb1196682014-07-23 13:47:29 -04003804 context->recordError(gl::Error(GL_INVALID_ENUM));
3805 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003806 }
3807
3808 // No binary shader formats are supported.
3809 UNIMPLEMENTED();
3810 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003811}
3812
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00003813void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003814{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003815 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 +00003816 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003817
Geoff Langbfdea662014-07-23 14:16:32 -04003818 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003819 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003820 {
Geoff Langb1196682014-07-23 13:47:29 -04003821 if (count < 0)
3822 {
3823 context->recordError(gl::Error(GL_INVALID_VALUE));
3824 return;
3825 }
3826
Geoff Langbfdea662014-07-23 14:16:32 -04003827 gl::Shader *shaderObject = context->getShader(shader);
3828
3829 if (!shaderObject)
3830 {
3831 if (context->getProgram(shader))
3832 {
Geoff Langb1196682014-07-23 13:47:29 -04003833 context->recordError(gl::Error(GL_INVALID_OPERATION));
3834 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003835 }
3836 else
3837 {
Geoff Langb1196682014-07-23 13:47:29 -04003838 context->recordError(gl::Error(GL_INVALID_VALUE));
3839 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003840 }
3841 }
3842
3843 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003844 }
3845}
3846
3847void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
3848{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003849 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003850}
3851
3852void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3853{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003854 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 +00003855
Geoff Langbfdea662014-07-23 14:16:32 -04003856 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003857 if (context)
3858 {
Geoff Langb1196682014-07-23 13:47:29 -04003859 switch (face)
3860 {
3861 case GL_FRONT:
3862 case GL_BACK:
3863 case GL_FRONT_AND_BACK:
3864 break;
3865
3866 default:
3867 context->recordError(gl::Error(GL_INVALID_ENUM));
3868 return;
3869 }
3870
3871 switch (func)
3872 {
3873 case GL_NEVER:
3874 case GL_ALWAYS:
3875 case GL_LESS:
3876 case GL_LEQUAL:
3877 case GL_EQUAL:
3878 case GL_GEQUAL:
3879 case GL_GREATER:
3880 case GL_NOTEQUAL:
3881 break;
3882
3883 default:
3884 context->recordError(gl::Error(GL_INVALID_ENUM));
3885 return;
3886 }
3887
Geoff Langbfdea662014-07-23 14:16:32 -04003888 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3889 {
3890 context->getState().setStencilParams(func, ref, mask);
3891 }
3892
3893 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3894 {
3895 context->getState().setStencilBackParams(func, ref, mask);
3896 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003897 }
3898}
3899
3900void __stdcall glStencilMask(GLuint mask)
3901{
3902 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3903}
3904
3905void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
3906{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003907 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003908
Geoff Langbfdea662014-07-23 14:16:32 -04003909 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003910 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003911 {
Geoff Langb1196682014-07-23 13:47:29 -04003912 switch (face)
3913 {
3914 case GL_FRONT:
3915 case GL_BACK:
3916 case GL_FRONT_AND_BACK:
3917 break;
3918
3919 default:
3920 context->recordError(gl::Error(GL_INVALID_ENUM));
3921 return;
3922 }
3923
Geoff Langbfdea662014-07-23 14:16:32 -04003924 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3925 {
3926 context->getState().setStencilWritemask(mask);
3927 }
3928
3929 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3930 {
3931 context->getState().setStencilBackWritemask(mask);
3932 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003933 }
3934}
3935
3936void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3937{
3938 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
3939}
3940
3941void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3942{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003943 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 +00003944 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003945
Geoff Langbfdea662014-07-23 14:16:32 -04003946 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003947 if (context)
3948 {
Geoff Langb1196682014-07-23 13:47:29 -04003949 switch (face)
3950 {
3951 case GL_FRONT:
3952 case GL_BACK:
3953 case GL_FRONT_AND_BACK:
3954 break;
3955
3956 default:
3957 context->recordError(gl::Error(GL_INVALID_ENUM));
3958 return;
3959 }
3960
3961 switch (fail)
3962 {
3963 case GL_ZERO:
3964 case GL_KEEP:
3965 case GL_REPLACE:
3966 case GL_INCR:
3967 case GL_DECR:
3968 case GL_INVERT:
3969 case GL_INCR_WRAP:
3970 case GL_DECR_WRAP:
3971 break;
3972
3973 default:
3974 context->recordError(gl::Error(GL_INVALID_ENUM));
3975 return;
3976 }
3977
3978 switch (zfail)
3979 {
3980 case GL_ZERO:
3981 case GL_KEEP:
3982 case GL_REPLACE:
3983 case GL_INCR:
3984 case GL_DECR:
3985 case GL_INVERT:
3986 case GL_INCR_WRAP:
3987 case GL_DECR_WRAP:
3988 break;
3989
3990 default:
3991 context->recordError(gl::Error(GL_INVALID_ENUM));
3992 return;
3993 }
3994
3995 switch (zpass)
3996 {
3997 case GL_ZERO:
3998 case GL_KEEP:
3999 case GL_REPLACE:
4000 case GL_INCR:
4001 case GL_DECR:
4002 case GL_INVERT:
4003 case GL_INCR_WRAP:
4004 case GL_DECR_WRAP:
4005 break;
4006
4007 default:
4008 context->recordError(gl::Error(GL_INVALID_ENUM));
4009 return;
4010 }
4011
Geoff Langbfdea662014-07-23 14:16:32 -04004012 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4013 {
4014 context->getState().setStencilOperations(fail, zfail, zpass);
4015 }
4016
4017 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4018 {
4019 context->getState().setStencilBackOperations(fail, zfail, zpass);
4020 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004021 }
4022}
4023
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004024GLboolean __stdcall glTestFenceNV(GLuint fence)
4025{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004026 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004027
Geoff Langbfdea662014-07-23 14:16:32 -04004028 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004029 if (context)
4030 {
4031 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4032
4033 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004034 {
Geoff Langb1196682014-07-23 13:47:29 -04004035 context->recordError(gl::Error(GL_INVALID_OPERATION));
4036 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004037 }
Geoff Langbfdea662014-07-23 14:16:32 -04004038
4039 if (fenceObject->isFence() != GL_TRUE)
4040 {
Geoff Langb1196682014-07-23 13:47:29 -04004041 context->recordError(gl::Error(GL_INVALID_OPERATION));
4042 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004043 }
4044
4045 return fenceObject->testFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004046 }
Geoff Langbfdea662014-07-23 14:16:32 -04004047
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004048 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004049}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004050
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004051void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4052 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004053{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004054 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004055 "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 +00004056 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004057
Geoff Langbfdea662014-07-23 14:16:32 -04004058 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004059 if (context)
4060 {
4061 if (context->getClientVersion() < 3 &&
4062 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4063 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004064 {
Geoff Langbfdea662014-07-23 14:16:32 -04004065 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004066 }
Geoff Langbfdea662014-07-23 14:16:32 -04004067
4068 if (context->getClientVersion() >= 3 &&
4069 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4070 0, 0, 0, width, height, 1, border, format, type, pixels))
4071 {
4072 return;
4073 }
4074
4075 switch (target)
4076 {
4077 case GL_TEXTURE_2D:
4078 {
4079 gl::Texture2D *texture = context->getTexture2D();
4080 texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4081 }
4082 break;
4083 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4084 {
4085 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4086 texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4087 }
4088 break;
4089 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4090 {
4091 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4092 texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4093 }
4094 break;
4095 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4096 {
4097 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4098 texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4099 }
4100 break;
4101 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4102 {
4103 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4104 texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4105 }
4106 break;
4107 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4108 {
4109 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4110 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4111 }
4112 break;
4113 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4114 {
4115 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4116 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4117 }
4118 break;
4119 default: UNREACHABLE();
4120 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004121 }
4122}
4123
4124void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
4125{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004126 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4127
Geoff Langbfdea662014-07-23 14:16:32 -04004128 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004129 if (context)
4130 {
4131 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004132 {
Geoff Langbfdea662014-07-23 14:16:32 -04004133 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004134 }
Geoff Langbfdea662014-07-23 14:16:32 -04004135
4136 gl::Texture *texture = context->getTargetTexture(target);
4137
4138 if (!texture)
4139 {
Geoff Langb1196682014-07-23 13:47:29 -04004140 context->recordError(gl::Error(GL_INVALID_ENUM));
4141 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004142 }
4143
4144 switch (pname)
4145 {
4146 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4147 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4148 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4149 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4150 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4151 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4152 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4153 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4154 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4155 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4156 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4157 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4158 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4159 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4160 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4161 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4162 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4163 default: UNREACHABLE(); break;
4164 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004165 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004166}
4167
4168void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4169{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004170 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004171}
4172
4173void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
4174{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004175 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004176
Geoff Langbfdea662014-07-23 14:16:32 -04004177 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004178 if (context)
4179 {
4180 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004181 {
Geoff Langbfdea662014-07-23 14:16:32 -04004182 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004183 }
Geoff Langbfdea662014-07-23 14:16:32 -04004184
4185 gl::Texture *texture = context->getTargetTexture(target);
4186
4187 if (!texture)
4188 {
Geoff Langb1196682014-07-23 13:47:29 -04004189 context->recordError(gl::Error(GL_INVALID_ENUM));
4190 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004191 }
4192
4193 switch (pname)
4194 {
4195 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4196 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4197 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4198 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4199 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4200 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4201 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4202 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4203 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4204 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4205 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4206 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4207 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4208 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4209 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4210 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4211 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4212 default: UNREACHABLE(); break;
4213 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004214 }
4215}
4216
4217void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
4218{
4219 glTexParameteri(target, pname, *params);
4220}
4221
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004222void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
4223{
4224 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4225 target, levels, internalformat, width, height);
4226
Geoff Langbfdea662014-07-23 14:16:32 -04004227 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004228 if (context)
4229 {
4230 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004231 {
Geoff Langb1196682014-07-23 13:47:29 -04004232 context->recordError(gl::Error(GL_INVALID_OPERATION));
4233 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004234 }
Geoff Langbfdea662014-07-23 14:16:32 -04004235
4236 if (context->getClientVersion() < 3 &&
4237 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4238 {
4239 return;
4240 }
4241
4242 if (context->getClientVersion() >= 3 &&
4243 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4244 {
4245 return;
4246 }
4247
4248 switch (target)
4249 {
4250 case GL_TEXTURE_2D:
4251 {
4252 gl::Texture2D *texture2d = context->getTexture2D();
4253 texture2d->storage(levels, internalformat, width, height);
4254 }
4255 break;
4256
4257 case GL_TEXTURE_CUBE_MAP:
4258 {
4259 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
4260 textureCube->storage(levels, internalformat, width);
4261 }
4262 break;
4263
4264 default:
Geoff Langb1196682014-07-23 13:47:29 -04004265 context->recordError(gl::Error(GL_INVALID_ENUM));
4266 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004267 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004268 }
4269}
4270
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004271void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4272 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004274 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004275 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004276 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004277 target, level, xoffset, yoffset, width, height, format, type, pixels);
4278
Geoff Langbfdea662014-07-23 14:16:32 -04004279 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004280 if (context)
4281 {
4282 if (context->getClientVersion() < 3 &&
4283 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4284 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004285 {
Geoff Langbfdea662014-07-23 14:16:32 -04004286 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004287 }
Geoff Langbfdea662014-07-23 14:16:32 -04004288
4289 if (context->getClientVersion() >= 3 &&
4290 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4291 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4292 {
4293 return;
4294 }
4295
4296 // Zero sized uploads are valid but no-ops
4297 if (width == 0 || height == 0)
4298 {
4299 return;
4300 }
4301
4302 switch (target)
4303 {
4304 case GL_TEXTURE_2D:
4305 {
4306 gl::Texture2D *texture = context->getTexture2D();
4307 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4308 }
4309 break;
4310
4311 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4312 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4313 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4314 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4315 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4316 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4317 {
4318 gl::TextureCubeMap *texture = context->getTextureCubeMap();
4319 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4320 }
4321 break;
4322
4323 default:
4324 UNREACHABLE();
4325 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004326 }
4327}
4328
4329void __stdcall glUniform1f(GLint location, GLfloat x)
4330{
4331 glUniform1fv(location, 1, &x);
4332}
4333
4334void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
4335{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004336 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004337
Geoff Langbfdea662014-07-23 14:16:32 -04004338 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004339 if (context)
4340 {
4341 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004342 {
Geoff Langbfdea662014-07-23 14:16:32 -04004343 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004344 }
Geoff Langbfdea662014-07-23 14:16:32 -04004345
4346 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4347 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004348 }
4349}
4350
4351void __stdcall glUniform1i(GLint location, GLint x)
4352{
4353 glUniform1iv(location, 1, &x);
4354}
4355
4356void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
4357{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004358 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004359
Geoff Langbfdea662014-07-23 14:16:32 -04004360 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004361 if (context)
4362 {
4363 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004364 {
Geoff Langbfdea662014-07-23 14:16:32 -04004365 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004366 }
Geoff Langbfdea662014-07-23 14:16:32 -04004367
4368 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4369 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004370 }
4371}
4372
4373void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
4374{
4375 GLfloat xy[2] = {x, y};
4376
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004377 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004378}
4379
4380void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
4381{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004382 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004383
Geoff Langbfdea662014-07-23 14:16:32 -04004384 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004385 if (context)
4386 {
4387 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004388 {
Geoff Langbfdea662014-07-23 14:16:32 -04004389 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004390 }
Geoff Langbfdea662014-07-23 14:16:32 -04004391
4392 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4393 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004394 }
4395}
4396
4397void __stdcall glUniform2i(GLint location, GLint x, GLint y)
4398{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004399 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004400
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004401 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004402}
4403
4404void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
4405{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004406 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004407
Geoff Langbfdea662014-07-23 14:16:32 -04004408 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004409 if (context)
4410 {
4411 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004412 {
Geoff Langbfdea662014-07-23 14:16:32 -04004413 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004414 }
Geoff Langbfdea662014-07-23 14:16:32 -04004415
4416 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4417 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004418 }
4419}
4420
4421void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4422{
4423 GLfloat xyz[3] = {x, y, z};
4424
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004425 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004426}
4427
4428void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
4429{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004430 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004431
Geoff Langbfdea662014-07-23 14:16:32 -04004432 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004433 if (context)
4434 {
4435 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004436 {
Geoff Langbfdea662014-07-23 14:16:32 -04004437 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438 }
Geoff Langbfdea662014-07-23 14:16:32 -04004439
4440 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4441 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442 }
4443}
4444
4445void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
4446{
4447 GLint xyz[3] = {x, y, z};
4448
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004449 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450}
4451
4452void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
4453{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004454 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004455
Geoff Langbfdea662014-07-23 14:16:32 -04004456 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004457 if (context)
4458 {
4459 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004460 {
Geoff Langbfdea662014-07-23 14:16:32 -04004461 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004462 }
Geoff Langbfdea662014-07-23 14:16:32 -04004463
4464 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4465 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004466 }
4467}
4468
4469void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4470{
4471 GLfloat xyzw[4] = {x, y, z, w};
4472
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004473 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004474}
4475
4476void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
4477{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004478 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479
Geoff Langbfdea662014-07-23 14:16:32 -04004480 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004481 if (context)
4482 {
4483 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004484 {
Geoff Langbfdea662014-07-23 14:16:32 -04004485 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004486 }
Geoff Langbfdea662014-07-23 14:16:32 -04004487
4488 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4489 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490 }
4491}
4492
4493void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4494{
4495 GLint xyzw[4] = {x, y, z, w};
4496
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004497 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004498}
4499
4500void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
4501{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004502 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004503
Geoff Langbfdea662014-07-23 14:16:32 -04004504 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004505 if (context)
4506 {
4507 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004508 {
Geoff Langbfdea662014-07-23 14:16:32 -04004509 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004510 }
Geoff Langbfdea662014-07-23 14:16:32 -04004511
4512 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4513 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004514 }
4515}
4516
4517void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
4518{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004519 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004520 location, count, transpose, value);
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 (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004526 {
Geoff Langbfdea662014-07-23 14:16:32 -04004527 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004528 }
Geoff Langbfdea662014-07-23 14:16:32 -04004529
4530 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4531 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004532 }
4533}
4534
4535void __stdcall glUniformMatrix3fv(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_MAT3, 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->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004550 }
4551}
4552
4553void __stdcall glUniformMatrix4fv(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_MAT4, 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->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004568 }
4569}
4570
4571void __stdcall glUseProgram(GLuint program)
4572{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004573 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004574
Geoff Langbfdea662014-07-23 14:16:32 -04004575 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004576 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004577 {
Geoff Langbfdea662014-07-23 14:16:32 -04004578 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004579
Geoff Langbfdea662014-07-23 14:16:32 -04004580 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004581 {
Geoff Langbfdea662014-07-23 14:16:32 -04004582 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004583 {
Geoff Langb1196682014-07-23 13:47:29 -04004584 context->recordError(gl::Error(GL_INVALID_OPERATION));
4585 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004586 }
Geoff Langbfdea662014-07-23 14:16:32 -04004587 else
4588 {
Geoff Langb1196682014-07-23 13:47:29 -04004589 context->recordError(gl::Error(GL_INVALID_VALUE));
4590 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004591 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004592 }
Geoff Langbfdea662014-07-23 14:16:32 -04004593
4594 if (program != 0 && !programObject->isLinked())
4595 {
Geoff Langb1196682014-07-23 13:47:29 -04004596 context->recordError(gl::Error(GL_INVALID_OPERATION));
4597 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004598 }
4599
4600 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004601 }
4602}
4603
4604void __stdcall glValidateProgram(GLuint program)
4605{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004606 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004607
Geoff Langbfdea662014-07-23 14:16:32 -04004608 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004609 if (context)
4610 {
4611 gl::Program *programObject = context->getProgram(program);
4612
4613 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004614 {
Geoff Langbfdea662014-07-23 14:16:32 -04004615 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004616 {
Geoff Langb1196682014-07-23 13:47:29 -04004617 context->recordError(gl::Error(GL_INVALID_OPERATION));
4618 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004619 }
Geoff Langbfdea662014-07-23 14:16:32 -04004620 else
4621 {
Geoff Langb1196682014-07-23 13:47:29 -04004622 context->recordError(gl::Error(GL_INVALID_VALUE));
4623 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004624 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004625 }
Geoff Langbfdea662014-07-23 14:16:32 -04004626
4627 programObject->validate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004628 }
4629}
4630
4631void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
4632{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004633 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634
Geoff Langbfdea662014-07-23 14:16:32 -04004635 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004636 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004637 {
Geoff Langb1196682014-07-23 13:47:29 -04004638 if (index >= gl::MAX_VERTEX_ATTRIBS)
4639 {
4640 context->recordError(gl::Error(GL_INVALID_VALUE));
4641 return;
4642 }
4643
Geoff Langbfdea662014-07-23 14:16:32 -04004644 GLfloat vals[4] = { x, 0, 0, 1 };
4645 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004646 }
4647}
4648
4649void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
4650{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004651 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
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] = { values[0], 0, 0, 1 };
4663 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004664 }
4665}
4666
4667void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4668{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004669 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
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] = { x, y, 0, 1 };
4681 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004682 }
4683}
4684
4685void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
4686{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004687 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
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] = { values[0], values[1], 0, 1 };
4699 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004700 }
4701}
4702
4703void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4704{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004705 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 +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] = { x, y, z, 1 };
4717 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004718 }
4719}
4720
4721void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
4722{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004723 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
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] = { values[0], values[1], values[2], 1 };
4735 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004736 }
4737}
4738
4739void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4740{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004741 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 +00004742
Geoff Langbfdea662014-07-23 14:16:32 -04004743 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004744 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004745 {
Geoff Langb1196682014-07-23 13:47:29 -04004746 if (index >= gl::MAX_VERTEX_ATTRIBS)
4747 {
4748 context->recordError(gl::Error(GL_INVALID_VALUE));
4749 return;
4750 }
4751
Geoff Langbfdea662014-07-23 14:16:32 -04004752 GLfloat vals[4] = { x, y, z, w };
4753 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004754 }
4755}
4756
4757void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
4758{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004759 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004760
Geoff Langbfdea662014-07-23 14:16:32 -04004761 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004762 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004763 {
Geoff Langb1196682014-07-23 13:47:29 -04004764 if (index >= gl::MAX_VERTEX_ATTRIBS)
4765 {
4766 context->recordError(gl::Error(GL_INVALID_VALUE));
4767 return;
4768 }
4769
Geoff Langbfdea662014-07-23 14:16:32 -04004770 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004771 }
4772}
4773
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004774void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
4775{
4776 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4777
Geoff Langbfdea662014-07-23 14:16:32 -04004778 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004779 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004780 {
Geoff Langb1196682014-07-23 13:47:29 -04004781 if (index >= gl::MAX_VERTEX_ATTRIBS)
4782 {
4783 context->recordError(gl::Error(GL_INVALID_VALUE));
4784 return;
4785 }
4786
Geoff Langbfdea662014-07-23 14:16:32 -04004787 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004788 }
4789}
4790
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004791void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004792{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004793 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004794 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004795 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004796
Geoff Langbfdea662014-07-23 14:16:32 -04004797 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004798 if (context)
4799 {
Geoff Langb1196682014-07-23 13:47:29 -04004800 if (index >= gl::MAX_VERTEX_ATTRIBS)
4801 {
4802 context->recordError(gl::Error(GL_INVALID_VALUE));
4803 return;
4804 }
4805
4806 if (size < 1 || size > 4)
4807 {
4808 context->recordError(gl::Error(GL_INVALID_VALUE));
4809 return;
4810 }
4811
4812 switch (type)
4813 {
4814 case GL_BYTE:
4815 case GL_UNSIGNED_BYTE:
4816 case GL_SHORT:
4817 case GL_UNSIGNED_SHORT:
4818 case GL_FIXED:
4819 case GL_FLOAT:
4820 break;
4821
4822 case GL_HALF_FLOAT:
4823 case GL_INT:
4824 case GL_UNSIGNED_INT:
4825 case GL_INT_2_10_10_10_REV:
4826 case GL_UNSIGNED_INT_2_10_10_10_REV:
4827 if (context->getClientVersion() < 3)
4828 {
4829 context->recordError(gl::Error(GL_INVALID_ENUM));
4830 return;
4831 }
4832 break;
4833
4834 default:
4835 context->recordError(gl::Error(GL_INVALID_ENUM));
4836 return;
4837 }
4838
4839 if (stride < 0)
4840 {
4841 context->recordError(gl::Error(GL_INVALID_VALUE));
4842 return;
4843 }
4844
4845 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4846 {
4847 context->recordError(gl::Error(GL_INVALID_OPERATION));
4848 return;
4849 }
4850
Geoff Langbfdea662014-07-23 14:16:32 -04004851 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4852 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4853 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4854 // and the pointer argument is not NULL.
4855 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004856 {
Geoff Langb1196682014-07-23 13:47:29 -04004857 context->recordError(gl::Error(GL_INVALID_OPERATION));
4858 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004859 }
4860
Geoff Langbfdea662014-07-23 14:16:32 -04004861 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4862 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004863 }
4864}
4865
4866void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4867{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004868 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 +00004869
Geoff Langbfdea662014-07-23 14:16:32 -04004870 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004871 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004872 {
Geoff Langb1196682014-07-23 13:47:29 -04004873 if (width < 0 || height < 0)
4874 {
4875 context->recordError(gl::Error(GL_INVALID_VALUE));
4876 return;
4877 }
4878
Geoff Langbfdea662014-07-23 14:16:32 -04004879 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004880 }
4881}
4882
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004883// OpenGL ES 3.0 functions
4884
4885void __stdcall glReadBuffer(GLenum mode)
4886{
4887 EVENT("(GLenum mode = 0x%X)", mode);
4888
Geoff Langbfdea662014-07-23 14:16:32 -04004889 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004890 if (context)
4891 {
4892 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004893 {
Geoff Langb1196682014-07-23 13:47:29 -04004894 context->recordError(gl::Error(GL_INVALID_OPERATION));
4895 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004896 }
Geoff Langbfdea662014-07-23 14:16:32 -04004897
4898 // glReadBuffer
4899 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004900 }
4901}
4902
4903void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
4904{
4905 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
4906 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
4907
Geoff Langbfdea662014-07-23 14:16:32 -04004908 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004909 if (context)
4910 {
4911 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004912 {
Geoff Langb1196682014-07-23 13:47:29 -04004913 context->recordError(gl::Error(GL_INVALID_OPERATION));
4914 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00004915 }
Geoff Langbfdea662014-07-23 14:16:32 -04004916
4917 // glDrawRangeElements
4918 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004919 }
4920}
4921
4922void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4923{
4924 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
4925 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
4926 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4927 target, level, internalformat, width, height, depth, border, format, type, pixels);
4928
Geoff Langbfdea662014-07-23 14:16:32 -04004929 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004930 if (context)
4931 {
4932 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004933 {
Geoff Langb1196682014-07-23 13:47:29 -04004934 context->recordError(gl::Error(GL_INVALID_OPERATION));
4935 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004936 }
Geoff Langbfdea662014-07-23 14:16:32 -04004937
4938 // validateES3TexImageFormat sets the error code if there is an error
4939 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4940 0, 0, 0, width, height, depth, border, format, type, pixels))
4941 {
4942 return;
4943 }
4944
4945 switch(target)
4946 {
4947 case GL_TEXTURE_3D:
4948 {
4949 gl::Texture3D *texture = context->getTexture3D();
4950 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4951 }
4952 break;
4953
4954 case GL_TEXTURE_2D_ARRAY:
4955 {
4956 gl::Texture2DArray *texture = context->getTexture2DArray();
4957 texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
4958 }
4959 break;
4960
4961 default:
Geoff Langb1196682014-07-23 13:47:29 -04004962 context->recordError(gl::Error(GL_INVALID_ENUM));
4963 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004964 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004965 }
4966}
4967
4968void __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)
4969{
4970 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4971 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
4972 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
4973 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
4974
Geoff Langbfdea662014-07-23 14:16:32 -04004975 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004976 if (context)
4977 {
4978 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004979 {
Geoff Langb1196682014-07-23 13:47:29 -04004980 context->recordError(gl::Error(GL_INVALID_OPERATION));
4981 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00004982 }
Geoff Langbfdea662014-07-23 14:16:32 -04004983
4984 // validateES3TexImageFormat sets the error code if there is an error
4985 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4986 xoffset, yoffset, zoffset, width, height, depth, 0,
4987 format, type, pixels))
4988 {
4989 return;
4990 }
4991
4992 // Zero sized uploads are valid but no-ops
4993 if (width == 0 || height == 0 || depth == 0)
4994 {
4995 return;
4996 }
4997
4998 switch(target)
4999 {
5000 case GL_TEXTURE_3D:
5001 {
5002 gl::Texture3D *texture = context->getTexture3D();
5003 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5004 }
5005 break;
5006
5007 case GL_TEXTURE_2D_ARRAY:
5008 {
5009 gl::Texture2DArray *texture = context->getTexture2DArray();
5010 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5011 }
5012 break;
5013
5014 default:
Geoff Langb1196682014-07-23 13:47:29 -04005015 context->recordError(gl::Error(GL_INVALID_ENUM));
5016 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005017 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005018 }
5019}
5020
5021void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5022{
5023 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5024 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5025 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5026
Geoff Langbfdea662014-07-23 14:16:32 -04005027 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005028 if (context)
5029 {
5030 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005031 {
Geoff Langb1196682014-07-23 13:47:29 -04005032 context->recordError(gl::Error(GL_INVALID_OPERATION));
5033 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005034 }
Geoff Langbfdea662014-07-23 14:16:32 -04005035
5036 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5037 x, y, width, height, 0))
5038 {
5039 return;
5040 }
5041
5042 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5043 gl::Texture *texture = NULL;
5044 switch (target)
5045 {
5046 case GL_TEXTURE_3D:
5047 texture = context->getTexture3D();
5048 break;
5049
5050 case GL_TEXTURE_2D_ARRAY:
5051 texture = context->getTexture2DArray();
5052 break;
5053
5054 default:
Geoff Langb1196682014-07-23 13:47:29 -04005055 context->recordError(gl::Error(GL_INVALID_ENUM));
5056 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005057 }
5058
5059 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005060 }
5061}
5062
5063void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
5064{
Geoff Langeef52cc2013-10-16 15:07:39 -04005065 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 +00005066 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5067 "const GLvoid* data = 0x%0.8p)",
5068 target, level, internalformat, width, height, depth, border, imageSize, data);
5069
Geoff Langbfdea662014-07-23 14:16:32 -04005070 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005071 if (context)
5072 {
5073 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005074 {
Geoff Langb1196682014-07-23 13:47:29 -04005075 context->recordError(gl::Error(GL_INVALID_OPERATION));
5076 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005077 }
Geoff Langbfdea662014-07-23 14:16:32 -04005078
Geoff Lang5d601382014-07-22 15:14:06 -04005079 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5080 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005081 {
Geoff Langb1196682014-07-23 13:47:29 -04005082 context->recordError(gl::Error(GL_INVALID_VALUE));
5083 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005084 }
5085
5086 // validateES3TexImageFormat sets the error code if there is an error
5087 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5088 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5089 {
5090 return;
5091 }
5092
5093 switch(target)
5094 {
5095 case GL_TEXTURE_3D:
5096 {
5097 gl::Texture3D *texture = context->getTexture3D();
5098 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5099 }
5100 break;
5101
5102 case GL_TEXTURE_2D_ARRAY:
5103 {
5104 gl::Texture2DArray *texture = context->getTexture2DArray();
5105 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
5106 }
5107 break;
5108
5109 default:
Geoff Langb1196682014-07-23 13:47:29 -04005110 context->recordError(gl::Error(GL_INVALID_ENUM));
5111 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005112 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005113 }
5114}
5115
5116void __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)
5117{
5118 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5119 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5120 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5121 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5122
Geoff Langbfdea662014-07-23 14:16:32 -04005123 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005124 if (context)
5125 {
5126 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005127 {
Geoff Langb1196682014-07-23 13:47:29 -04005128 context->recordError(gl::Error(GL_INVALID_OPERATION));
5129 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005130 }
Geoff Langbfdea662014-07-23 14:16:32 -04005131
Geoff Lang5d601382014-07-22 15:14:06 -04005132 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5133 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005134 {
Geoff Langb1196682014-07-23 13:47:29 -04005135 context->recordError(gl::Error(GL_INVALID_VALUE));
5136 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005137 }
5138
5139 if (!data)
5140 {
Geoff Langb1196682014-07-23 13:47:29 -04005141 context->recordError(gl::Error(GL_INVALID_VALUE));
5142 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005143 }
5144
5145 // validateES3TexImageFormat sets the error code if there is an error
5146 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5147 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5148 {
5149 return;
5150 }
5151
5152 // Zero sized uploads are valid but no-ops
5153 if (width == 0 || height == 0)
5154 {
5155 return;
5156 }
5157
5158 switch(target)
5159 {
5160 case GL_TEXTURE_3D:
5161 {
5162 gl::Texture3D *texture = context->getTexture3D();
5163 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5164 format, imageSize, data);
5165 }
5166 break;
5167
5168 case GL_TEXTURE_2D_ARRAY:
5169 {
5170 gl::Texture2DArray *texture = context->getTexture2DArray();
5171 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
5172 format, imageSize, data);
5173 }
5174 break;
5175
Geoff Langb1196682014-07-23 13:47:29 -04005176 default:
5177 context->recordError(gl::Error(GL_INVALID_ENUM));
5178 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005179 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005180 }
5181}
5182
5183void __stdcall glGenQueries(GLsizei n, GLuint* ids)
5184{
5185 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5186
Geoff Langbfdea662014-07-23 14:16:32 -04005187 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005188 if (context)
5189 {
5190 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005191 {
Geoff Langb1196682014-07-23 13:47:29 -04005192 context->recordError(gl::Error(GL_INVALID_OPERATION));
5193 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005194 }
Geoff Langbfdea662014-07-23 14:16:32 -04005195
5196 if (n < 0)
5197 {
Geoff Langb1196682014-07-23 13:47:29 -04005198 context->recordError(gl::Error(GL_INVALID_VALUE));
5199 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005200 }
5201
5202 for (GLsizei i = 0; i < n; i++)
5203 {
5204 ids[i] = context->createQuery();
5205 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005206 }
5207}
5208
5209void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
5210{
5211 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5212
Geoff Langbfdea662014-07-23 14:16:32 -04005213 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005214 if (context)
5215 {
5216 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005217 {
Geoff Langb1196682014-07-23 13:47:29 -04005218 context->recordError(gl::Error(GL_INVALID_OPERATION));
5219 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005220 }
Geoff Langbfdea662014-07-23 14:16:32 -04005221
5222 if (n < 0)
5223 {
Geoff Langb1196682014-07-23 13:47:29 -04005224 context->recordError(gl::Error(GL_INVALID_VALUE));
5225 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005226 }
5227
5228 for (GLsizei i = 0; i < n; i++)
5229 {
5230 context->deleteQuery(ids[i]);
5231 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005232 }
5233}
5234
5235GLboolean __stdcall glIsQuery(GLuint id)
5236{
5237 EVENT("(GLuint id = %u)", id);
5238
Geoff Langbfdea662014-07-23 14:16:32 -04005239 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005240 if (context)
5241 {
5242 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005243 {
Geoff Langb1196682014-07-23 13:47:29 -04005244 context->recordError(gl::Error(GL_INVALID_OPERATION));
5245 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005246 }
Geoff Langbfdea662014-07-23 14:16:32 -04005247
5248 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005249 }
5250
5251 return GL_FALSE;
5252}
5253
5254void __stdcall glBeginQuery(GLenum target, GLuint id)
5255{
5256 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5257
Geoff Langbfdea662014-07-23 14:16:32 -04005258 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005259 if (context)
5260 {
5261 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005262 {
Geoff Langb1196682014-07-23 13:47:29 -04005263 context->recordError(gl::Error(GL_INVALID_OPERATION));
5264 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005265 }
Geoff Langbfdea662014-07-23 14:16:32 -04005266
5267 if (!ValidateBeginQuery(context, target, id))
5268 {
5269 return;
5270 }
5271 context->beginQuery(target, id);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005272 }
5273}
5274
5275void __stdcall glEndQuery(GLenum target)
5276{
5277 EVENT("(GLenum target = 0x%X)", target);
5278
Geoff Langbfdea662014-07-23 14:16:32 -04005279 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005280 if (context)
5281 {
5282 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005283 {
Geoff Langb1196682014-07-23 13:47:29 -04005284 context->recordError(gl::Error(GL_INVALID_OPERATION));
5285 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005286 }
Geoff Langbfdea662014-07-23 14:16:32 -04005287
5288 if (!ValidateEndQuery(context, target))
5289 {
5290 return;
5291 }
5292
5293 context->endQuery(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005294 }
5295}
5296
5297void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
5298{
5299 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5300
Geoff Langbfdea662014-07-23 14:16:32 -04005301 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005302 if (context)
5303 {
5304 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005305 {
Geoff Langb1196682014-07-23 13:47:29 -04005306 context->recordError(gl::Error(GL_INVALID_OPERATION));
5307 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005308 }
Geoff Langbfdea662014-07-23 14:16:32 -04005309
5310 if (!ValidQueryType(context, target))
5311 {
Geoff Langb1196682014-07-23 13:47:29 -04005312 context->recordError(gl::Error(GL_INVALID_ENUM));
5313 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005314 }
5315
5316 switch (pname)
5317 {
5318 case GL_CURRENT_QUERY:
5319 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5320 break;
5321
5322 default:
Geoff Langb1196682014-07-23 13:47:29 -04005323 context->recordError(gl::Error(GL_INVALID_ENUM));
5324 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005325 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005326 }
5327}
5328
5329void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
5330{
5331 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5332
Geoff Langbfdea662014-07-23 14:16:32 -04005333 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005334 if (context)
5335 {
5336 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005337 {
Geoff Langb1196682014-07-23 13:47:29 -04005338 context->recordError(gl::Error(GL_INVALID_OPERATION));
5339 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005340 }
Geoff Langbfdea662014-07-23 14:16:32 -04005341
5342 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5343
5344 if (!queryObject)
5345 {
Geoff Langb1196682014-07-23 13:47:29 -04005346 context->recordError(gl::Error(GL_INVALID_OPERATION));
5347 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005348 }
5349
5350 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5351 {
Geoff Langb1196682014-07-23 13:47:29 -04005352 context->recordError(gl::Error(GL_INVALID_OPERATION));
5353 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005354 }
5355
5356 switch(pname)
5357 {
5358 case GL_QUERY_RESULT:
5359 params[0] = queryObject->getResult();
5360 break;
Geoff Langb1196682014-07-23 13:47:29 -04005361
Geoff Langbfdea662014-07-23 14:16:32 -04005362 case GL_QUERY_RESULT_AVAILABLE:
5363 params[0] = queryObject->isResultAvailable();
5364 break;
Geoff Langb1196682014-07-23 13:47:29 -04005365
Geoff Langbfdea662014-07-23 14:16:32 -04005366 default:
Geoff Langb1196682014-07-23 13:47:29 -04005367 context->recordError(gl::Error(GL_INVALID_ENUM));
5368 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005369 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005370 }
5371}
5372
5373GLboolean __stdcall glUnmapBuffer(GLenum target)
5374{
5375 EVENT("(GLenum target = 0x%X)", target);
5376
Geoff Langbfdea662014-07-23 14:16:32 -04005377 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005378 if (context)
5379 {
5380 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005381 {
Geoff Langb1196682014-07-23 13:47:29 -04005382 context->recordError(gl::Error(GL_INVALID_OPERATION));
5383 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005384 }
Geoff Langbfdea662014-07-23 14:16:32 -04005385
5386 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005387 }
5388
5389 return GL_FALSE;
5390}
5391
5392void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
5393{
5394 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5395
Geoff Langbfdea662014-07-23 14:16:32 -04005396 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005397 if (context)
5398 {
5399 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005400 {
Geoff Langb1196682014-07-23 13:47:29 -04005401 context->recordError(gl::Error(GL_INVALID_OPERATION));
5402 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005403 }
Geoff Langbfdea662014-07-23 14:16:32 -04005404
5405 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005406 }
5407}
5408
5409void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
5410{
Geoff Langbfdea662014-07-23 14:16:32 -04005411 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005412 if (context)
5413 {
5414 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005415 {
Geoff Langb1196682014-07-23 13:47:29 -04005416 context->recordError(gl::Error(GL_INVALID_OPERATION));
5417 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005418 }
Geoff Langbfdea662014-07-23 14:16:32 -04005419
5420 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005421 }
5422}
5423
5424void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
5425{
5426 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5427 location, count, transpose, value);
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 (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005433 {
Geoff Langbfdea662014-07-23 14:16:32 -04005434 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005435 }
Geoff Langbfdea662014-07-23 14:16:32 -04005436
5437 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5438 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005439 }
5440}
5441
5442void __stdcall glUniformMatrix3x2fv(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_MAT3x2, 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->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005457 }
5458}
5459
5460void __stdcall glUniformMatrix2x4fv(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_MAT2x4, 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->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005475 }
5476}
5477
5478void __stdcall glUniformMatrix4x2fv(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_MAT4x2, 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->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005493 }
5494}
5495
5496void __stdcall glUniformMatrix3x4fv(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_MAT3x4, 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->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005511 }
5512}
5513
5514void __stdcall glUniformMatrix4x3fv(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_MAT4x3, 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->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005529 }
5530}
5531
5532void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
5533{
5534 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5535 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5536 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5537
Geoff Langbfdea662014-07-23 14:16:32 -04005538 gl::Context *context = gl::getNonLostContext();
5539 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005540 {
Geoff Langbfdea662014-07-23 14:16:32 -04005541 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005542 {
Geoff Langb1196682014-07-23 13:47:29 -04005543 context->recordError(gl::Error(GL_INVALID_OPERATION));
5544 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005545 }
Geoff Langbfdea662014-07-23 14:16:32 -04005546
5547 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5548 dstX0, dstY0, dstX1, dstY1, mask, filter,
5549 false))
5550 {
5551 return;
5552 }
5553
5554 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5555 mask, filter);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005556 }
5557}
5558
5559void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
5560{
5561 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5562 target, samples, internalformat, width, height);
5563
Geoff Langbfdea662014-07-23 14:16:32 -04005564 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005565 if (context)
5566 {
5567 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005568 {
Geoff Langb1196682014-07-23 13:47:29 -04005569 context->recordError(gl::Error(GL_INVALID_OPERATION));
5570 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005571 }
Geoff Langbfdea662014-07-23 14:16:32 -04005572
5573 if (!ValidateRenderbufferStorageParameters(context, target, samples, internalformat,
5574 width, height, false))
5575 {
5576 return;
5577 }
5578
5579 context->setRenderbufferStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005580 }
5581}
5582
5583void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
5584{
5585 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5586 target, attachment, texture, level, layer);
5587
Geoff Langbfdea662014-07-23 14:16:32 -04005588 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005589 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005590 {
Geoff Langbfdea662014-07-23 14:16:32 -04005591 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5592 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005593 {
Geoff Langbfdea662014-07-23 14:16:32 -04005594 return;
5595 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005596
Geoff Langbfdea662014-07-23 14:16:32 -04005597 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5598 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005599
Geoff Langbfdea662014-07-23 14:16:32 -04005600 gl::Texture *textureObject = context->getTexture(texture);
5601 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005602
Geoff Langbfdea662014-07-23 14:16:32 -04005603 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
5604 {
5605 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5606 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
5607 }
5608 else
5609 {
5610 switch (attachment)
Geoff Lang3ed0c482013-07-25 17:03:18 -04005611 {
Geoff Langbfdea662014-07-23 14:16:32 -04005612 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
5613 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
5614 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
Geoff Lang3ed0c482013-07-25 17:03:18 -04005615 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005616 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005617 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005618}
5619
5620GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
5621{
5622 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5623 target, offset, length, access);
5624
Geoff Langbfdea662014-07-23 14:16:32 -04005625 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005626 if (context)
5627 {
5628 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005629 {
Geoff Langb1196682014-07-23 13:47:29 -04005630 context->recordError(gl::Error(GL_INVALID_OPERATION));
5631 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005632 }
Geoff Langbfdea662014-07-23 14:16:32 -04005633
5634 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005635 }
5636
5637 return NULL;
5638}
5639
5640void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
5641{
5642 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5643
Geoff Langbfdea662014-07-23 14:16:32 -04005644 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005645 if (context)
5646 {
5647 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005648 {
Geoff Langb1196682014-07-23 13:47:29 -04005649 context->recordError(gl::Error(GL_INVALID_OPERATION));
5650 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005651 }
Geoff Langbfdea662014-07-23 14:16:32 -04005652
5653 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005654 }
5655}
5656
5657void __stdcall glBindVertexArray(GLuint array)
5658{
5659 EVENT("(GLuint array = %u)", array);
5660
Geoff Langbfdea662014-07-23 14:16:32 -04005661 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005662 if (context)
5663 {
5664 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005665 {
Geoff Langb1196682014-07-23 13:47:29 -04005666 context->recordError(gl::Error(GL_INVALID_OPERATION));
5667 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005668 }
Geoff Langbfdea662014-07-23 14:16:32 -04005669
5670 gl::VertexArray *vao = context->getVertexArray(array);
5671
5672 if (!vao)
5673 {
5674 // The default VAO should always exist
5675 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005676 context->recordError(gl::Error(GL_INVALID_OPERATION));
5677 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005678 }
5679
5680 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005681 }
5682}
5683
5684void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
5685{
5686 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5687
Geoff Langbfdea662014-07-23 14:16:32 -04005688 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005689 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005690 {
Geoff Langbfdea662014-07-23 14:16:32 -04005691 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005692 {
Geoff Langb1196682014-07-23 13:47:29 -04005693 context->recordError(gl::Error(GL_INVALID_OPERATION));
5694 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005695 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005696
Geoff Langbfdea662014-07-23 14:16:32 -04005697 if (n < 0)
5698 {
Geoff Langb1196682014-07-23 13:47:29 -04005699 context->recordError(gl::Error(GL_INVALID_VALUE));
5700 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005701 }
Jamie Madilld1028542013-07-02 11:57:04 -04005702
Geoff Langbfdea662014-07-23 14:16:32 -04005703 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5704 {
5705 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005706 {
Geoff Langbfdea662014-07-23 14:16:32 -04005707 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005708 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005709 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005710 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005711}
5712
5713void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
5714{
5715 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5716
Geoff Langbfdea662014-07-23 14:16:32 -04005717 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005718 if (context)
5719 {
5720 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005721 {
Geoff Langb1196682014-07-23 13:47:29 -04005722 context->recordError(gl::Error(GL_INVALID_OPERATION));
5723 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005724 }
Geoff Langbfdea662014-07-23 14:16:32 -04005725
5726 if (n < 0)
5727 {
Geoff Langb1196682014-07-23 13:47:29 -04005728 context->recordError(gl::Error(GL_INVALID_VALUE));
5729 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005730 }
5731
5732 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5733 {
5734 arrays[arrayIndex] = context->createVertexArray();
5735 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005736 }
5737}
5738
5739GLboolean __stdcall glIsVertexArray(GLuint array)
5740{
5741 EVENT("(GLuint array = %u)", array);
5742
Geoff Langbfdea662014-07-23 14:16:32 -04005743 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005744 if (context)
5745 {
5746 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005747 {
Geoff Langb1196682014-07-23 13:47:29 -04005748 context->recordError(gl::Error(GL_INVALID_OPERATION));
5749 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005750 }
Geoff Langbfdea662014-07-23 14:16:32 -04005751
5752 if (array == 0)
5753 {
5754 return GL_FALSE;
5755 }
5756
5757 gl::VertexArray *vao = context->getVertexArray(array);
5758
5759 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005760 }
5761
5762 return GL_FALSE;
5763}
5764
5765void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
5766{
5767 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5768 target, index, data);
5769
Geoff Langbfdea662014-07-23 14:16:32 -04005770 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005771 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005772 {
Geoff Langbfdea662014-07-23 14:16:32 -04005773 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005774 {
Geoff Langb1196682014-07-23 13:47:29 -04005775 context->recordError(gl::Error(GL_INVALID_OPERATION));
5776 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005777 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005778
Geoff Lang3a61c322014-07-10 13:01:54 -04005779 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005780 switch (target)
5781 {
5782 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5783 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5784 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005785 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5786 {
Geoff Langb1196682014-07-23 13:47:29 -04005787 context->recordError(gl::Error(GL_INVALID_VALUE));
5788 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005789 }
Geoff Langbfdea662014-07-23 14:16:32 -04005790 break;
Geoff Langb1196682014-07-23 13:47:29 -04005791
Geoff Langbfdea662014-07-23 14:16:32 -04005792 case GL_UNIFORM_BUFFER_START:
5793 case GL_UNIFORM_BUFFER_SIZE:
5794 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005795 if (index >= caps.maxCombinedUniformBlocks)
5796 {
Geoff Langb1196682014-07-23 13:47:29 -04005797 context->recordError(gl::Error(GL_INVALID_VALUE));
5798 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005799 }
Geoff Langbfdea662014-07-23 14:16:32 -04005800 break;
Geoff Langb1196682014-07-23 13:47:29 -04005801
Geoff Langbfdea662014-07-23 14:16:32 -04005802 default:
Geoff Langb1196682014-07-23 13:47:29 -04005803 context->recordError(gl::Error(GL_INVALID_ENUM));
5804 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005805 }
5806
5807 if (!(context->getIndexedIntegerv(target, index, data)))
5808 {
5809 GLenum nativeType;
5810 unsigned int numParams = 0;
5811 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04005812 {
5813 context->recordError(gl::Error(GL_INVALID_ENUM));
5814 return;
5815 }
Shannon Woods15934d52013-08-19 14:28:49 -04005816
Geoff Langbfdea662014-07-23 14:16:32 -04005817 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04005818 {
Geoff Langbfdea662014-07-23 14:16:32 -04005819 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04005820 }
Geoff Langbfdea662014-07-23 14:16:32 -04005821
5822 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04005823 {
Geoff Langbfdea662014-07-23 14:16:32 -04005824 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5825 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5826 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04005827
Geoff Langbfdea662014-07-23 14:16:32 -04005828 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04005829
Geoff Langbfdea662014-07-23 14:16:32 -04005830 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04005831 {
Geoff Langbfdea662014-07-23 14:16:32 -04005832 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5833 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04005834 }
Geoff Langbfdea662014-07-23 14:16:32 -04005835
5836 delete [] int64Params;
5837 }
5838 else
5839 {
5840 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04005841 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005842 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005843 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005844}
5845
5846void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
5847{
5848 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
5849
Geoff Langbfdea662014-07-23 14:16:32 -04005850 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005851 if (context)
5852 {
5853 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005854 {
Geoff Langb1196682014-07-23 13:47:29 -04005855 context->recordError(gl::Error(GL_INVALID_OPERATION));
5856 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005857 }
Geoff Langbfdea662014-07-23 14:16:32 -04005858
5859 switch (primitiveMode)
5860 {
5861 case GL_TRIANGLES:
5862 case GL_LINES:
5863 case GL_POINTS:
5864 break;
Geoff Langb1196682014-07-23 13:47:29 -04005865
Geoff Langbfdea662014-07-23 14:16:32 -04005866 default:
Geoff Langb1196682014-07-23 13:47:29 -04005867 context->recordError(gl::Error(GL_INVALID_ENUM));
5868 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005869 }
5870
5871 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5872 ASSERT(transformFeedback != NULL);
5873
5874 if (transformFeedback->isStarted())
5875 {
Geoff Langb1196682014-07-23 13:47:29 -04005876 context->recordError(gl::Error(GL_INVALID_OPERATION));
5877 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005878 }
5879
5880 if (transformFeedback->isPaused())
5881 {
5882 transformFeedback->resume();
5883 }
5884 else
5885 {
5886 transformFeedback->start(primitiveMode);
5887 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005888 }
5889}
5890
5891void __stdcall glEndTransformFeedback(void)
5892{
5893 EVENT("(void)");
5894
Geoff Langbfdea662014-07-23 14:16:32 -04005895 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005896 if (context)
5897 {
5898 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005899 {
Geoff Langb1196682014-07-23 13:47:29 -04005900 context->recordError(gl::Error(GL_INVALID_OPERATION));
5901 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005902 }
Geoff Langbfdea662014-07-23 14:16:32 -04005903
5904 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
5905 ASSERT(transformFeedback != NULL);
5906
5907 if (!transformFeedback->isStarted())
5908 {
Geoff Langb1196682014-07-23 13:47:29 -04005909 context->recordError(gl::Error(GL_INVALID_OPERATION));
5910 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005911 }
5912
5913 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005914 }
5915}
5916
5917void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
5918{
5919 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
5920 target, index, buffer, offset, size);
5921
Geoff Langbfdea662014-07-23 14:16:32 -04005922 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005923 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005924 {
Geoff Langbfdea662014-07-23 14:16:32 -04005925 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005926 {
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
Geoff Lang3a61c322014-07-10 13:01:54 -04005931 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005932 switch (target)
5933 {
5934 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04005935 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005936 {
Geoff Langb1196682014-07-23 13:47:29 -04005937 context->recordError(gl::Error(GL_INVALID_VALUE));
5938 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005939 }
Geoff Langbfdea662014-07-23 14:16:32 -04005940 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005941
Geoff Langbfdea662014-07-23 14:16:32 -04005942 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04005943 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005944 {
Geoff Langb1196682014-07-23 13:47:29 -04005945 context->recordError(gl::Error(GL_INVALID_VALUE));
5946 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005947 }
Geoff Langbfdea662014-07-23 14:16:32 -04005948 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005949
Geoff Langbfdea662014-07-23 14:16:32 -04005950 default:
Geoff Langb1196682014-07-23 13:47:29 -04005951 context->recordError(gl::Error(GL_INVALID_ENUM));
5952 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005953 }
5954
5955 if (buffer != 0 && size <= 0)
5956 {
Geoff Langb1196682014-07-23 13:47:29 -04005957 context->recordError(gl::Error(GL_INVALID_VALUE));
5958 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005959 }
5960
5961 switch (target)
5962 {
5963 case GL_TRANSFORM_FEEDBACK_BUFFER:
5964
5965 // size and offset must be a multiple of 4
5966 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005967 {
Geoff Langb1196682014-07-23 13:47:29 -04005968 context->recordError(gl::Error(GL_INVALID_VALUE));
5969 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005970 }
5971
Geoff Langbfdea662014-07-23 14:16:32 -04005972 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
5973 context->bindGenericTransformFeedbackBuffer(buffer);
5974 break;
5975
5976 case GL_UNIFORM_BUFFER:
5977
5978 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04005979 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005980 {
Geoff Langb1196682014-07-23 13:47:29 -04005981 context->recordError(gl::Error(GL_INVALID_VALUE));
5982 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005983 }
Geoff Langbfdea662014-07-23 14:16:32 -04005984
5985 context->bindIndexedUniformBuffer(buffer, index, offset, size);
5986 context->bindGenericUniformBuffer(buffer);
5987 break;
5988
5989 default:
5990 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00005991 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005992 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005993}
5994
5995void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
5996{
5997 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
5998 target, index, buffer);
5999
Geoff Langbfdea662014-07-23 14:16:32 -04006000 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006001 if (context)
6002 {
6003 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006004 {
Geoff Langb1196682014-07-23 13:47:29 -04006005 context->recordError(gl::Error(GL_INVALID_OPERATION));
6006 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006007 }
Geoff Langbfdea662014-07-23 14:16:32 -04006008
Geoff Lang3a61c322014-07-10 13:01:54 -04006009 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006010 switch (target)
6011 {
6012 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006013 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006014 {
Geoff Langb1196682014-07-23 13:47:29 -04006015 context->recordError(gl::Error(GL_INVALID_VALUE));
6016 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006017 }
6018 break;
6019
6020 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006021 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006022 {
Geoff Langb1196682014-07-23 13:47:29 -04006023 context->recordError(gl::Error(GL_INVALID_VALUE));
6024 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006025 }
6026 break;
6027
6028 default:
Geoff Langb1196682014-07-23 13:47:29 -04006029 context->recordError(gl::Error(GL_INVALID_ENUM));
6030 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006031 }
6032
6033 switch (target)
6034 {
6035 case GL_TRANSFORM_FEEDBACK_BUFFER:
6036 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6037 context->bindGenericTransformFeedbackBuffer(buffer);
6038 break;
6039
6040 case GL_UNIFORM_BUFFER:
6041 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6042 context->bindGenericUniformBuffer(buffer);
6043 break;
6044
6045 default:
6046 UNREACHABLE();
6047 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006048 }
6049}
6050
6051void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
6052{
6053 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6054 program, count, varyings, bufferMode);
6055
Geoff Langbfdea662014-07-23 14:16:32 -04006056 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006057 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006058 {
Geoff Langbfdea662014-07-23 14:16:32 -04006059 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006060 {
Geoff Langb1196682014-07-23 13:47:29 -04006061 context->recordError(gl::Error(GL_INVALID_OPERATION));
6062 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006063 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006064
Geoff Langbfdea662014-07-23 14:16:32 -04006065 if (count < 0)
6066 {
Geoff Langb1196682014-07-23 13:47:29 -04006067 context->recordError(gl::Error(GL_INVALID_VALUE));
6068 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006069 }
6070
Geoff Lang05881a02014-07-10 14:05:30 -04006071 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006072 switch (bufferMode)
6073 {
6074 case GL_INTERLEAVED_ATTRIBS:
6075 break;
6076 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006077 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006078 {
Geoff Langb1196682014-07-23 13:47:29 -04006079 context->recordError(gl::Error(GL_INVALID_VALUE));
6080 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006081 }
Geoff Langbfdea662014-07-23 14:16:32 -04006082 break;
6083 default:
Geoff Langb1196682014-07-23 13:47:29 -04006084 context->recordError(gl::Error(GL_INVALID_ENUM));
6085 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006086 }
Geoff Langbfdea662014-07-23 14:16:32 -04006087
6088 if (!gl::ValidProgram(context, program))
6089 {
6090 return;
6091 }
6092
6093 gl::Program *programObject = context->getProgram(program);
6094 ASSERT(programObject);
6095
6096 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006097 }
6098}
6099
6100void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
6101{
6102 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6103 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6104 program, index, bufSize, length, size, type, name);
6105
Geoff Langbfdea662014-07-23 14:16:32 -04006106 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006107 if (context)
6108 {
6109 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006110 {
Geoff Langb1196682014-07-23 13:47:29 -04006111 context->recordError(gl::Error(GL_INVALID_OPERATION));
6112 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006113 }
Geoff Langbfdea662014-07-23 14:16:32 -04006114
6115 if (bufSize < 0)
6116 {
Geoff Langb1196682014-07-23 13:47:29 -04006117 context->recordError(gl::Error(GL_INVALID_VALUE));
6118 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006119 }
6120
6121 if (!gl::ValidProgram(context, program))
6122 {
6123 return;
6124 }
6125
6126 gl::Program *programObject = context->getProgram(program);
6127 ASSERT(programObject);
6128
6129 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6130 {
Geoff Langb1196682014-07-23 13:47:29 -04006131 context->recordError(gl::Error(GL_INVALID_VALUE));
6132 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006133 }
6134
6135 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006136 }
6137}
6138
6139void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
6140{
6141 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6142 index, size, type, stride, pointer);
6143
Geoff Langbfdea662014-07-23 14:16:32 -04006144 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006145 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006146 {
Geoff Langbfdea662014-07-23 14:16:32 -04006147 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006148 {
Geoff Langb1196682014-07-23 13:47:29 -04006149 context->recordError(gl::Error(GL_INVALID_OPERATION));
6150 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006151 }
6152
Geoff Langb1196682014-07-23 13:47:29 -04006153 if (index >= gl::MAX_VERTEX_ATTRIBS)
6154 {
6155 context->recordError(gl::Error(GL_INVALID_VALUE));
6156 return;
6157 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006158
Geoff Langb1196682014-07-23 13:47:29 -04006159 if (size < 1 || size > 4)
6160 {
6161 context->recordError(gl::Error(GL_INVALID_VALUE));
6162 return;
6163 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006164
Geoff Langb1196682014-07-23 13:47:29 -04006165 switch (type)
6166 {
6167 case GL_BYTE:
6168 case GL_UNSIGNED_BYTE:
6169 case GL_SHORT:
6170 case GL_UNSIGNED_SHORT:
6171 case GL_INT:
6172 case GL_UNSIGNED_INT:
6173 case GL_INT_2_10_10_10_REV:
6174 case GL_UNSIGNED_INT_2_10_10_10_REV:
6175 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006176
Geoff Langb1196682014-07-23 13:47:29 -04006177 default:
6178 context->recordError(gl::Error(GL_INVALID_ENUM));
6179 return;
6180 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006181
Geoff Langb1196682014-07-23 13:47:29 -04006182 if (stride < 0)
6183 {
6184 context->recordError(gl::Error(GL_INVALID_VALUE));
6185 return;
6186 }
Geoff Langbfdea662014-07-23 14:16:32 -04006187
Geoff Langb1196682014-07-23 13:47:29 -04006188 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6189 {
6190 context->recordError(gl::Error(GL_INVALID_OPERATION));
6191 return;
6192 }
6193
Geoff Langbfdea662014-07-23 14:16:32 -04006194 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6195 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6196 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6197 // and the pointer argument is not NULL.
6198 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006199 {
Geoff Langb1196682014-07-23 13:47:29 -04006200 context->recordError(gl::Error(GL_INVALID_OPERATION));
6201 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006202 }
6203
Geoff Langbfdea662014-07-23 14:16:32 -04006204 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6205 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006206 }
6207}
6208
6209void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
6210{
6211 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6212 index, pname, params);
6213
Geoff Langbfdea662014-07-23 14:16:32 -04006214 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006215 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006216 {
Geoff Langbfdea662014-07-23 14:16:32 -04006217 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006218 {
Geoff Langb1196682014-07-23 13:47:29 -04006219 context->recordError(gl::Error(GL_INVALID_OPERATION));
6220 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006221 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006222
Geoff Langbfdea662014-07-23 14:16:32 -04006223 if (index >= gl::MAX_VERTEX_ATTRIBS)
6224 {
Geoff Langb1196682014-07-23 13:47:29 -04006225 context->recordError(gl::Error(GL_INVALID_VALUE));
6226 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006227 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006228
Geoff Langbfdea662014-07-23 14:16:32 -04006229 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006230
Geoff Langb1196682014-07-23 13:47:29 -04006231 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006232 {
6233 return;
6234 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006235
Geoff Langbfdea662014-07-23 14:16:32 -04006236 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6237 {
6238 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6239 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006240 {
Geoff Langbfdea662014-07-23 14:16:32 -04006241 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006242 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006243 }
Geoff Langbfdea662014-07-23 14:16:32 -04006244 else
6245 {
6246 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6247 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006248 }
6249}
6250
6251void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
6252{
6253 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6254 index, pname, params);
6255
Geoff Langbfdea662014-07-23 14:16:32 -04006256 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006257 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006258 {
Geoff Langbfdea662014-07-23 14:16:32 -04006259 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006260 {
Geoff Langb1196682014-07-23 13:47:29 -04006261 context->recordError(gl::Error(GL_INVALID_OPERATION));
6262 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006263 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006264
Geoff Langbfdea662014-07-23 14:16:32 -04006265 if (index >= gl::MAX_VERTEX_ATTRIBS)
6266 {
Geoff Langb1196682014-07-23 13:47:29 -04006267 context->recordError(gl::Error(GL_INVALID_VALUE));
6268 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006269 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006270
Geoff Langbfdea662014-07-23 14:16:32 -04006271 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006272
Geoff Langb1196682014-07-23 13:47:29 -04006273 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006274 {
6275 return;
6276 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006277
Geoff Langbfdea662014-07-23 14:16:32 -04006278 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6279 {
6280 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6281 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006282 {
Geoff Langbfdea662014-07-23 14:16:32 -04006283 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006284 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006285 }
Geoff Langbfdea662014-07-23 14:16:32 -04006286 else
6287 {
6288 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6289 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006290 }
6291}
6292
6293void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
6294{
6295 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6296 index, x, y, z, w);
6297
Geoff Langbfdea662014-07-23 14:16:32 -04006298 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006299 if (context)
6300 {
6301 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006302 {
Geoff Langb1196682014-07-23 13:47:29 -04006303 context->recordError(gl::Error(GL_INVALID_OPERATION));
6304 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006305 }
Geoff Langbfdea662014-07-23 14:16:32 -04006306
6307 if (index >= gl::MAX_VERTEX_ATTRIBS)
6308 {
Geoff Langb1196682014-07-23 13:47:29 -04006309 context->recordError(gl::Error(GL_INVALID_VALUE));
6310 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006311 }
6312
6313 GLint vals[4] = { x, y, z, w };
6314 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006315 }
6316}
6317
6318void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
6319{
6320 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6321 index, x, y, z, w);
6322
Geoff Langbfdea662014-07-23 14:16:32 -04006323 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006324 if (context)
6325 {
6326 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006327 {
Geoff Langb1196682014-07-23 13:47:29 -04006328 context->recordError(gl::Error(GL_INVALID_OPERATION));
6329 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006330 }
Geoff Langbfdea662014-07-23 14:16:32 -04006331
6332 if (index >= gl::MAX_VERTEX_ATTRIBS)
6333 {
Geoff Langb1196682014-07-23 13:47:29 -04006334 context->recordError(gl::Error(GL_INVALID_VALUE));
6335 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006336 }
6337
6338 GLuint vals[4] = { x, y, z, w };
6339 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006340 }
6341}
6342
6343void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
6344{
6345 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6346
Geoff Langbfdea662014-07-23 14:16:32 -04006347 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006348 if (context)
6349 {
6350 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006351 {
Geoff Langb1196682014-07-23 13:47:29 -04006352 context->recordError(gl::Error(GL_INVALID_OPERATION));
6353 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006354 }
Geoff Langbfdea662014-07-23 14:16:32 -04006355
6356 if (index >= gl::MAX_VERTEX_ATTRIBS)
6357 {
Geoff Langb1196682014-07-23 13:47:29 -04006358 context->recordError(gl::Error(GL_INVALID_VALUE));
6359 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006360 }
6361
6362 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006363 }
6364}
6365
6366void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
6367{
6368 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6369
Geoff Langbfdea662014-07-23 14:16:32 -04006370 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006371 if (context)
6372 {
6373 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006374 {
Geoff Langb1196682014-07-23 13:47:29 -04006375 context->recordError(gl::Error(GL_INVALID_OPERATION));
6376 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006377 }
Geoff Langbfdea662014-07-23 14:16:32 -04006378
6379 if (index >= gl::MAX_VERTEX_ATTRIBS)
6380 {
Geoff Langb1196682014-07-23 13:47:29 -04006381 context->recordError(gl::Error(GL_INVALID_VALUE));
6382 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006383 }
6384
6385 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006386 }
6387}
6388
6389void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
6390{
6391 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6392 program, location, params);
6393
Geoff Langbfdea662014-07-23 14:16:32 -04006394 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006395 if (context)
6396 {
Jamie Madill0063c512014-08-25 15:47:53 -04006397 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006398 {
Jamie Madill0063c512014-08-25 15:47:53 -04006399 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006400 }
Geoff Langbfdea662014-07-23 14:16:32 -04006401
Jamie Madill0063c512014-08-25 15:47:53 -04006402 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6403 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006404
Jamie Madill99a1e982014-08-25 15:47:54 -04006405 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006406 }
6407}
6408
6409GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
6410{
6411 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6412 program, name);
6413
Geoff Langbfdea662014-07-23 14:16:32 -04006414 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006415 if (context)
6416 {
6417 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006418 {
Geoff Langb1196682014-07-23 13:47:29 -04006419 context->recordError(gl::Error(GL_INVALID_OPERATION));
6420 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006421 }
Geoff Langbfdea662014-07-23 14:16:32 -04006422
6423 if (program == 0)
6424 {
Geoff Langb1196682014-07-23 13:47:29 -04006425 context->recordError(gl::Error(GL_INVALID_VALUE));
6426 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006427 }
6428
6429 gl::Program *programObject = context->getProgram(program);
6430
6431 if (!programObject || !programObject->isLinked())
6432 {
Geoff Langb1196682014-07-23 13:47:29 -04006433 context->recordError(gl::Error(GL_INVALID_OPERATION));
6434 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006435 }
6436
6437 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6438 if (!programBinary)
6439 {
Geoff Langb1196682014-07-23 13:47:29 -04006440 context->recordError(gl::Error(GL_INVALID_OPERATION));
6441 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006442 }
6443
6444 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006445 }
6446
6447 return 0;
6448}
6449
6450void __stdcall glUniform1ui(GLint location, GLuint v0)
6451{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006452 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006453}
6454
6455void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
6456{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006457 const GLuint xy[] = { v0, v1 };
6458 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006459}
6460
6461void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6462{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006463 const GLuint xyz[] = { v0, v1, v2 };
6464 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006465}
6466
6467void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6468{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006469 const GLuint xyzw[] = { v0, v1, v2, v3 };
6470 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006471}
6472
6473void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
6474{
6475 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6476 location, count, value);
6477
Geoff Langbfdea662014-07-23 14:16:32 -04006478 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006479 if (context)
6480 {
6481 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006482 {
Geoff Langbfdea662014-07-23 14:16:32 -04006483 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006484 }
Geoff Langbfdea662014-07-23 14:16:32 -04006485
6486 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6487 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006488 }
6489}
6490
6491void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
6492{
6493 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6494 location, count, value);
6495
Geoff Langbfdea662014-07-23 14:16:32 -04006496 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006497 if (context)
6498 {
6499 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006500 {
Geoff Langbfdea662014-07-23 14:16:32 -04006501 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006502 }
Geoff Langbfdea662014-07-23 14:16:32 -04006503
6504 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6505 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006506 }
6507}
6508
6509void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
6510{
6511 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6512 location, count, value);
6513
Geoff Langbfdea662014-07-23 14:16:32 -04006514 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006515 if (context)
6516 {
6517 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006518 {
Geoff Langbfdea662014-07-23 14:16:32 -04006519 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006520 }
Geoff Langbfdea662014-07-23 14:16:32 -04006521
6522 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6523 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006524 }
6525}
6526
6527void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
6528{
6529 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6530 location, count, value);
6531
Geoff Langbfdea662014-07-23 14:16:32 -04006532 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006533 if (context)
6534 {
6535 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006536 {
Geoff Langbfdea662014-07-23 14:16:32 -04006537 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006538 }
Geoff Langbfdea662014-07-23 14:16:32 -04006539
6540 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6541 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006542 }
6543}
6544
6545void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
6546{
6547 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6548 buffer, drawbuffer, value);
6549
Geoff Langbfdea662014-07-23 14:16:32 -04006550 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006551 if (context)
6552 {
6553 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006554 {
Geoff Langbfdea662014-07-23 14:16:32 -04006555 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006556 }
Geoff Langbfdea662014-07-23 14:16:32 -04006557
6558 switch (buffer)
6559 {
6560 case GL_COLOR:
6561 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6562 {
Geoff Langb1196682014-07-23 13:47:29 -04006563 context->recordError(gl::Error(GL_INVALID_VALUE));
6564 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006565 }
6566 break;
Geoff Langb1196682014-07-23 13:47:29 -04006567
Geoff Langbfdea662014-07-23 14:16:32 -04006568 case GL_STENCIL:
6569 if (drawbuffer != 0)
6570 {
Geoff Langb1196682014-07-23 13:47:29 -04006571 context->recordError(gl::Error(GL_INVALID_VALUE));
6572 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006573 }
6574 break;
Geoff Langb1196682014-07-23 13:47:29 -04006575
Geoff Langbfdea662014-07-23 14:16:32 -04006576 default:
Geoff Langb1196682014-07-23 13:47:29 -04006577 context->recordError(gl::Error(GL_INVALID_ENUM));
6578 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006579 }
6580
6581 context->clearBufferiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006582 }
6583}
6584
6585void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
6586{
6587 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6588 buffer, drawbuffer, value);
6589
Geoff Langbfdea662014-07-23 14:16:32 -04006590 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006591 if (context)
6592 {
6593 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006594 {
Geoff Langbfdea662014-07-23 14:16:32 -04006595 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006596 }
Geoff Langbfdea662014-07-23 14:16:32 -04006597
6598 switch (buffer)
6599 {
6600 case GL_COLOR:
6601 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6602 {
Geoff Langb1196682014-07-23 13:47:29 -04006603 context->recordError(gl::Error(GL_INVALID_VALUE));
6604 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006605 }
6606 break;
Geoff Langb1196682014-07-23 13:47:29 -04006607
Geoff Langbfdea662014-07-23 14:16:32 -04006608 default:
Geoff Langb1196682014-07-23 13:47:29 -04006609 context->recordError(gl::Error(GL_INVALID_ENUM));
6610 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006611 }
6612
6613 context->clearBufferuiv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006614 }
6615}
6616
6617void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
6618{
6619 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6620 buffer, drawbuffer, value);
6621
Geoff Langbfdea662014-07-23 14:16:32 -04006622 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006623 if (context)
6624 {
6625 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006626 {
Geoff Langbfdea662014-07-23 14:16:32 -04006627 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006628 }
Geoff Langbfdea662014-07-23 14:16:32 -04006629
6630 switch (buffer)
6631 {
6632 case GL_COLOR:
6633 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6634 {
Geoff Langb1196682014-07-23 13:47:29 -04006635 context->recordError(gl::Error(GL_INVALID_VALUE));
6636 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006637 }
6638 break;
Geoff Langb1196682014-07-23 13:47:29 -04006639
Geoff Langbfdea662014-07-23 14:16:32 -04006640 case GL_DEPTH:
6641 if (drawbuffer != 0)
6642 {
Geoff Langb1196682014-07-23 13:47:29 -04006643 context->recordError(gl::Error(GL_INVALID_VALUE));
6644 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006645 }
6646 break;
Geoff Langb1196682014-07-23 13:47:29 -04006647
Geoff Langbfdea662014-07-23 14:16:32 -04006648 default:
Geoff Langb1196682014-07-23 13:47:29 -04006649 context->recordError(gl::Error(GL_INVALID_ENUM));
6650 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006651 }
6652
6653 context->clearBufferfv(buffer, drawbuffer, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006654 }
6655}
6656
6657void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
6658{
6659 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6660 buffer, drawbuffer, depth, stencil);
6661
Geoff Langbfdea662014-07-23 14:16:32 -04006662 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006663 if (context)
6664 {
6665 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006666 {
Geoff Langbfdea662014-07-23 14:16:32 -04006667 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006668 }
Geoff Langbfdea662014-07-23 14:16:32 -04006669
6670 switch (buffer)
6671 {
6672 case GL_DEPTH_STENCIL:
6673 if (drawbuffer != 0)
6674 {
Geoff Langb1196682014-07-23 13:47:29 -04006675 context->recordError(gl::Error(GL_INVALID_VALUE));
6676 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006677 }
6678 break;
Geoff Langb1196682014-07-23 13:47:29 -04006679
Geoff Langbfdea662014-07-23 14:16:32 -04006680 default:
Geoff Langb1196682014-07-23 13:47:29 -04006681 context->recordError(gl::Error(GL_INVALID_ENUM));
6682 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006683 }
6684
6685 context->clearBufferfi(buffer, drawbuffer, depth, stencil);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006686 }
6687}
6688
6689const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
6690{
6691 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6692
Geoff Langbfdea662014-07-23 14:16:32 -04006693 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006694 if (context)
6695 {
6696 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006697 {
Geoff Langb1196682014-07-23 13:47:29 -04006698 context->recordError(gl::Error(GL_INVALID_OPERATION));
6699 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006700 }
Geoff Langbfdea662014-07-23 14:16:32 -04006701
6702 if (name != GL_EXTENSIONS)
6703 {
Geoff Langb1196682014-07-23 13:47:29 -04006704 context->recordError(gl::Error(GL_INVALID_ENUM));
6705 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006706 }
6707
6708 if (index >= context->getExtensionStringCount())
6709 {
Geoff Langb1196682014-07-23 13:47:29 -04006710 context->recordError(gl::Error(GL_INVALID_VALUE));
6711 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006712 }
6713
6714 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006715 }
6716
6717 return NULL;
6718}
6719
6720void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
6721{
6722 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6723 readTarget, writeTarget, readOffset, writeOffset, size);
6724
Geoff Langbfdea662014-07-23 14:16:32 -04006725 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006726 if (context)
6727 {
6728 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006729 {
Geoff Langb1196682014-07-23 13:47:29 -04006730 context->recordError(gl::Error(GL_INVALID_OPERATION));
6731 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006732 }
Geoff Langbfdea662014-07-23 14:16:32 -04006733
6734 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, readTarget))
6735 {
Geoff Langb1196682014-07-23 13:47:29 -04006736 context->recordError(gl::Error(GL_INVALID_ENUM));
6737 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006738 }
6739
6740 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6741 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6742
6743 if (!readBuffer || !writeBuffer)
6744 {
Geoff Langb1196682014-07-23 13:47:29 -04006745 context->recordError(gl::Error(GL_INVALID_OPERATION));
6746 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006747 }
6748
Jamie Madillcfaaf722014-07-31 10:47:54 -04006749 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006750 if (readBuffer->isMapped() || writeBuffer->isMapped())
6751 {
Geoff Langb1196682014-07-23 13:47:29 -04006752 context->recordError(gl::Error(GL_INVALID_OPERATION));
6753 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006754 }
6755
6756 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6757 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6758 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6759 {
Geoff Langb1196682014-07-23 13:47:29 -04006760 context->recordError(gl::Error(GL_INVALID_VALUE));
6761 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006762 }
6763
6764 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
6765 {
Geoff Langb1196682014-07-23 13:47:29 -04006766 context->recordError(gl::Error(GL_INVALID_VALUE));
6767 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006768 }
6769
Geoff Langbfdea662014-07-23 14:16:32 -04006770 // if size is zero, the copy is a successful no-op
6771 if (size > 0)
6772 {
6773 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6774 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006775 }
6776}
6777
6778void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
6779{
6780 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
6781 program, uniformCount, uniformNames, uniformIndices);
6782
Geoff Langbfdea662014-07-23 14:16:32 -04006783 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006784 if (context)
6785 {
6786 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006787 {
Geoff Langb1196682014-07-23 13:47:29 -04006788 context->recordError(gl::Error(GL_INVALID_OPERATION));
6789 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006790 }
6791
6792 if (uniformCount < 0)
6793 {
Geoff Langb1196682014-07-23 13:47:29 -04006794 context->recordError(gl::Error(GL_INVALID_VALUE));
6795 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006796 }
6797
6798 gl::Program *programObject = context->getProgram(program);
6799
6800 if (!programObject)
6801 {
6802 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006803 {
Geoff Langb1196682014-07-23 13:47:29 -04006804 context->recordError(gl::Error(GL_INVALID_OPERATION));
6805 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006806 }
Geoff Langbfdea662014-07-23 14:16:32 -04006807 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006808 {
Geoff Langb1196682014-07-23 13:47:29 -04006809 context->recordError(gl::Error(GL_INVALID_VALUE));
6810 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006811 }
Geoff Langbfdea662014-07-23 14:16:32 -04006812 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006813
Geoff Langbfdea662014-07-23 14:16:32 -04006814 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6815 if (!programObject->isLinked() || !programBinary)
6816 {
6817 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006818 {
Geoff Langbfdea662014-07-23 14:16:32 -04006819 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00006820 }
6821 }
Geoff Langbfdea662014-07-23 14:16:32 -04006822 else
6823 {
6824 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6825 {
6826 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
6827 }
6828 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006829 }
6830}
6831
6832void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
6833{
6834 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6835 program, uniformCount, uniformIndices, pname, params);
6836
Geoff Langbfdea662014-07-23 14:16:32 -04006837 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006838 if (context)
6839 {
6840 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006841 {
Geoff Langb1196682014-07-23 13:47:29 -04006842 context->recordError(gl::Error(GL_INVALID_OPERATION));
6843 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006844 }
6845
6846 if (uniformCount < 0)
6847 {
Geoff Langb1196682014-07-23 13:47:29 -04006848 context->recordError(gl::Error(GL_INVALID_VALUE));
6849 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006850 }
6851
6852 gl::Program *programObject = context->getProgram(program);
6853
6854 if (!programObject)
6855 {
6856 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006857 {
Geoff Langb1196682014-07-23 13:47:29 -04006858 context->recordError(gl::Error(GL_INVALID_OPERATION));
6859 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006860 }
Geoff Langbfdea662014-07-23 14:16:32 -04006861 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006862 {
Geoff Langb1196682014-07-23 13:47:29 -04006863 context->recordError(gl::Error(GL_INVALID_VALUE));
6864 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006865 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00006866 }
Geoff Langbfdea662014-07-23 14:16:32 -04006867
6868 switch (pname)
6869 {
6870 case GL_UNIFORM_TYPE:
6871 case GL_UNIFORM_SIZE:
6872 case GL_UNIFORM_NAME_LENGTH:
6873 case GL_UNIFORM_BLOCK_INDEX:
6874 case GL_UNIFORM_OFFSET:
6875 case GL_UNIFORM_ARRAY_STRIDE:
6876 case GL_UNIFORM_MATRIX_STRIDE:
6877 case GL_UNIFORM_IS_ROW_MAJOR:
6878 break;
Geoff Langb1196682014-07-23 13:47:29 -04006879
Geoff Langbfdea662014-07-23 14:16:32 -04006880 default:
Geoff Langb1196682014-07-23 13:47:29 -04006881 context->recordError(gl::Error(GL_INVALID_ENUM));
6882 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006883 }
6884
6885 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6886
6887 if (!programBinary && uniformCount > 0)
6888 {
Geoff Langb1196682014-07-23 13:47:29 -04006889 context->recordError(gl::Error(GL_INVALID_VALUE));
6890 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006891 }
6892
6893 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6894 {
6895 const GLuint index = uniformIndices[uniformId];
6896
6897 if (index >= (GLuint)programBinary->getActiveUniformCount())
6898 {
Geoff Langb1196682014-07-23 13:47:29 -04006899 context->recordError(gl::Error(GL_INVALID_VALUE));
6900 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006901 }
6902 }
6903
6904 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6905 {
6906 const GLuint index = uniformIndices[uniformId];
6907 params[uniformId] = programBinary->getActiveUniformi(index, pname);
6908 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006909 }
6910}
6911
6912GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
6913{
6914 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
6915
Geoff Langbfdea662014-07-23 14:16:32 -04006916 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006917 if (context)
6918 {
6919 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006920 {
Geoff Langb1196682014-07-23 13:47:29 -04006921 context->recordError(gl::Error(GL_INVALID_OPERATION));
6922 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04006923 }
6924
6925 gl::Program *programObject = context->getProgram(program);
6926
6927 if (!programObject)
6928 {
6929 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006930 {
Geoff Langb1196682014-07-23 13:47:29 -04006931 context->recordError(gl::Error(GL_INVALID_OPERATION));
6932 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006933 }
Geoff Langbfdea662014-07-23 14:16:32 -04006934 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006935 {
Geoff Langb1196682014-07-23 13:47:29 -04006936 context->recordError(gl::Error(GL_INVALID_VALUE));
6937 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006938 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00006939 }
Geoff Langbfdea662014-07-23 14:16:32 -04006940
6941 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6942 if (!programBinary)
6943 {
6944 return GL_INVALID_INDEX;
6945 }
6946
6947 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006948 }
6949
6950 return 0;
6951}
6952
6953void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
6954{
6955 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6956 program, uniformBlockIndex, pname, params);
6957
Geoff Langbfdea662014-07-23 14:16:32 -04006958 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006959 if (context)
6960 {
6961 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006962 {
Geoff Langb1196682014-07-23 13:47:29 -04006963 context->recordError(gl::Error(GL_INVALID_OPERATION));
6964 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006965 }
6966 gl::Program *programObject = context->getProgram(program);
6967
6968 if (!programObject)
6969 {
6970 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006971 {
Geoff Langb1196682014-07-23 13:47:29 -04006972 context->recordError(gl::Error(GL_INVALID_OPERATION));
6973 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006974 }
Geoff Langbfdea662014-07-23 14:16:32 -04006975 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006976 {
Geoff Langb1196682014-07-23 13:47:29 -04006977 context->recordError(gl::Error(GL_INVALID_VALUE));
6978 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006979 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00006980 }
Geoff Langbfdea662014-07-23 14:16:32 -04006981
6982 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6983
6984 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
6985 {
Geoff Langb1196682014-07-23 13:47:29 -04006986 context->recordError(gl::Error(GL_INVALID_VALUE));
6987 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006988 }
6989
6990 switch (pname)
6991 {
6992 case GL_UNIFORM_BLOCK_BINDING:
6993 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
6994 break;
6995
6996 case GL_UNIFORM_BLOCK_DATA_SIZE:
6997 case GL_UNIFORM_BLOCK_NAME_LENGTH:
6998 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
6999 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7000 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7001 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7002 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7003 break;
7004
7005 default:
Geoff Langb1196682014-07-23 13:47:29 -04007006 context->recordError(gl::Error(GL_INVALID_ENUM));
7007 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007008 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007009 }
7010}
7011
7012void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
7013{
7014 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7015 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7016
Geoff Langbfdea662014-07-23 14:16:32 -04007017 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007018 if (context)
7019 {
7020 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007021 {
Geoff Langb1196682014-07-23 13:47:29 -04007022 context->recordError(gl::Error(GL_INVALID_OPERATION));
7023 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007024 }
7025
7026 gl::Program *programObject = context->getProgram(program);
7027
7028 if (!programObject)
7029 {
7030 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007031 {
Geoff Langb1196682014-07-23 13:47:29 -04007032 context->recordError(gl::Error(GL_INVALID_OPERATION));
7033 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007034 }
Geoff Langbfdea662014-07-23 14:16:32 -04007035 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007036 {
Geoff Langb1196682014-07-23 13:47:29 -04007037 context->recordError(gl::Error(GL_INVALID_VALUE));
7038 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007039 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007040 }
Geoff Langbfdea662014-07-23 14:16:32 -04007041
7042 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7043
7044 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7045 {
Geoff Langb1196682014-07-23 13:47:29 -04007046 context->recordError(gl::Error(GL_INVALID_VALUE));
7047 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007048 }
7049
7050 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007051 }
7052}
7053
7054void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
7055{
7056 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7057 program, uniformBlockIndex, uniformBlockBinding);
7058
Geoff Langbfdea662014-07-23 14:16:32 -04007059 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007060 if (context)
7061 {
7062 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007063 {
Geoff Langb1196682014-07-23 13:47:29 -04007064 context->recordError(gl::Error(GL_INVALID_OPERATION));
7065 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007066 }
7067
Geoff Lang3a61c322014-07-10 13:01:54 -04007068 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007069 {
Geoff Langb1196682014-07-23 13:47:29 -04007070 context->recordError(gl::Error(GL_INVALID_VALUE));
7071 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007072 }
7073
7074 gl::Program *programObject = context->getProgram(program);
7075
7076 if (!programObject)
7077 {
7078 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007079 {
Geoff Langb1196682014-07-23 13:47:29 -04007080 context->recordError(gl::Error(GL_INVALID_OPERATION));
7081 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007082 }
Geoff Langbfdea662014-07-23 14:16:32 -04007083 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007084 {
Geoff Langb1196682014-07-23 13:47:29 -04007085 context->recordError(gl::Error(GL_INVALID_VALUE));
7086 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007087 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007088 }
Geoff Langbfdea662014-07-23 14:16:32 -04007089
7090 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7091
7092 // if never linked, there won't be any uniform blocks
7093 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7094 {
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 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007100 }
7101}
7102
7103void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
7104{
7105 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7106 mode, first, count, instanceCount);
7107
Geoff Langbfdea662014-07-23 14:16:32 -04007108 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007109 if (context)
7110 {
7111 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007112 {
Geoff Langb1196682014-07-23 13:47:29 -04007113 context->recordError(gl::Error(GL_INVALID_OPERATION));
7114 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007115 }
Geoff Langbfdea662014-07-23 14:16:32 -04007116
7117 // glDrawArraysInstanced
7118 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007119 }
7120}
7121
7122void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
7123{
7124 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7125 mode, count, type, indices, instanceCount);
7126
Geoff Langbfdea662014-07-23 14:16:32 -04007127 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007128 if (context)
7129 {
7130 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007131 {
Geoff Langb1196682014-07-23 13:47:29 -04007132 context->recordError(gl::Error(GL_INVALID_OPERATION));
7133 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007134 }
Geoff Langbfdea662014-07-23 14:16:32 -04007135
7136 // glDrawElementsInstanced
7137 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007138 }
7139}
7140
7141GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
7142{
7143 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7144
Geoff Langbfdea662014-07-23 14:16:32 -04007145 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007146 if (context)
7147 {
7148 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007149 {
Geoff Langb1196682014-07-23 13:47:29 -04007150 context->recordError(gl::Error(GL_INVALID_OPERATION));
7151 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007152 }
Geoff Langbfdea662014-07-23 14:16:32 -04007153
7154 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7155 {
Geoff Langb1196682014-07-23 13:47:29 -04007156 context->recordError(gl::Error(GL_INVALID_ENUM));
7157 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007158 }
7159
7160 if (flags != 0)
7161 {
Geoff Langb1196682014-07-23 13:47:29 -04007162 context->recordError(gl::Error(GL_INVALID_VALUE));
7163 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007164 }
7165
7166 return context->createFenceSync(condition);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007167 }
7168
7169 return NULL;
7170}
7171
7172GLboolean __stdcall glIsSync(GLsync sync)
7173{
7174 EVENT("(GLsync sync = 0x%0.8p)", sync);
7175
Geoff Langbfdea662014-07-23 14:16:32 -04007176 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007177 if (context)
7178 {
7179 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007180 {
Geoff Langb1196682014-07-23 13:47:29 -04007181 context->recordError(gl::Error(GL_INVALID_OPERATION));
7182 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007183 }
Geoff Langbfdea662014-07-23 14:16:32 -04007184
7185 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007186 }
7187
7188 return GL_FALSE;
7189}
7190
7191void __stdcall glDeleteSync(GLsync sync)
7192{
7193 EVENT("(GLsync sync = 0x%0.8p)", sync);
7194
Geoff Langbfdea662014-07-23 14:16:32 -04007195 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007196 if (context)
7197 {
7198 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007199 {
Geoff Langb1196682014-07-23 13:47:29 -04007200 context->recordError(gl::Error(GL_INVALID_OPERATION));
7201 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007202 }
Geoff Langbfdea662014-07-23 14:16:32 -04007203
7204 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7205 {
Geoff Langb1196682014-07-23 13:47:29 -04007206 context->recordError(gl::Error(GL_INVALID_VALUE));
7207 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007208 }
7209
7210 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007211 }
7212}
7213
7214GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7215{
7216 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7217 sync, flags, timeout);
7218
Geoff Langbfdea662014-07-23 14:16:32 -04007219 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007220 if (context)
7221 {
7222 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007223 {
Geoff Langb1196682014-07-23 13:47:29 -04007224 context->recordError(gl::Error(GL_INVALID_OPERATION));
7225 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007226 }
Geoff Langbfdea662014-07-23 14:16:32 -04007227
7228 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7229 {
Geoff Langb1196682014-07-23 13:47:29 -04007230 context->recordError(gl::Error(GL_INVALID_VALUE));
7231 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007232 }
7233
7234 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7235
7236 if (!fenceSync)
7237 {
Geoff Langb1196682014-07-23 13:47:29 -04007238 context->recordError(gl::Error(GL_INVALID_VALUE));
7239 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007240 }
7241
7242 return fenceSync->clientWait(flags, timeout);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007243 }
7244
7245 return GL_FALSE;
7246}
7247
7248void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7249{
7250 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7251 sync, flags, timeout);
7252
Geoff Langbfdea662014-07-23 14:16:32 -04007253 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007254 if (context)
7255 {
7256 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007257 {
Geoff Langb1196682014-07-23 13:47:29 -04007258 context->recordError(gl::Error(GL_INVALID_OPERATION));
7259 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007260 }
Geoff Langbfdea662014-07-23 14:16:32 -04007261
7262 if (flags != 0)
7263 {
Geoff Langb1196682014-07-23 13:47:29 -04007264 context->recordError(gl::Error(GL_INVALID_VALUE));
7265 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007266 }
7267
7268 if (timeout != GL_TIMEOUT_IGNORED)
7269 {
Geoff Langb1196682014-07-23 13:47:29 -04007270 context->recordError(gl::Error(GL_INVALID_VALUE));
7271 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007272 }
7273
7274 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7275
7276 if (!fenceSync)
7277 {
Geoff Langb1196682014-07-23 13:47:29 -04007278 context->recordError(gl::Error(GL_INVALID_VALUE));
7279 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007280 }
7281
7282 fenceSync->serverWait();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007283 }
7284}
7285
7286void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
7287{
7288 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7289 pname, params);
7290
Geoff Langbfdea662014-07-23 14:16:32 -04007291 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007292 if (context)
7293 {
7294 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007295 {
Geoff Langb1196682014-07-23 13:47:29 -04007296 context->recordError(gl::Error(GL_INVALID_OPERATION));
7297 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007298 }
Geoff Langbfdea662014-07-23 14:16:32 -04007299
7300 GLenum nativeType;
7301 unsigned int numParams = 0;
7302 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7303 {
7304 return;
7305 }
7306
7307 if (nativeType == GL_INT_64_ANGLEX)
7308 {
7309 context->getInteger64v(pname, params);
7310 }
7311 else
7312 {
7313 CastStateValues(context, nativeType, pname, numParams, params);
7314 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007315 }
7316}
7317
7318void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
7319{
7320 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7321 sync, pname, bufSize, length, values);
7322
Geoff Langbfdea662014-07-23 14:16:32 -04007323 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007324 if (context)
7325 {
7326 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007327 {
Geoff Langb1196682014-07-23 13:47:29 -04007328 context->recordError(gl::Error(GL_INVALID_OPERATION));
7329 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007330 }
Geoff Langbfdea662014-07-23 14:16:32 -04007331
7332 if (bufSize < 0)
7333 {
Geoff Langb1196682014-07-23 13:47:29 -04007334 context->recordError(gl::Error(GL_INVALID_VALUE));
7335 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007336 }
7337
7338 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7339
7340 if (!fenceSync)
7341 {
Geoff Langb1196682014-07-23 13:47:29 -04007342 context->recordError(gl::Error(GL_INVALID_VALUE));
7343 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007344 }
7345
7346 switch (pname)
7347 {
7348 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
7349 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
7350 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7351 case GL_SYNC_FLAGS: values[0] = 0; break;
7352
7353 default:
Geoff Langb1196682014-07-23 13:47:29 -04007354 context->recordError(gl::Error(GL_INVALID_ENUM));
7355 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007356 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007357 }
7358}
7359
7360void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
7361{
7362 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7363 target, index, data);
7364
Geoff Langbfdea662014-07-23 14:16:32 -04007365 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007366 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007367 {
Geoff Langbfdea662014-07-23 14:16:32 -04007368 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007369 {
Geoff Langb1196682014-07-23 13:47:29 -04007370 context->recordError(gl::Error(GL_INVALID_OPERATION));
7371 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007372 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007373
Geoff Lang3a61c322014-07-10 13:01:54 -04007374 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007375 switch (target)
7376 {
7377 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7378 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7379 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007380 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7381 {
Geoff Langb1196682014-07-23 13:47:29 -04007382 context->recordError(gl::Error(GL_INVALID_VALUE));
7383 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007384 }
Geoff Langbfdea662014-07-23 14:16:32 -04007385 break;
Geoff Langb1196682014-07-23 13:47:29 -04007386
Geoff Langbfdea662014-07-23 14:16:32 -04007387 case GL_UNIFORM_BUFFER_START:
7388 case GL_UNIFORM_BUFFER_SIZE:
7389 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007390 if (index >= caps.maxUniformBufferBindings)
7391 {
Geoff Langb1196682014-07-23 13:47:29 -04007392 context->recordError(gl::Error(GL_INVALID_VALUE));
7393 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007394 }
Geoff Langbfdea662014-07-23 14:16:32 -04007395 break;
Geoff Langb1196682014-07-23 13:47:29 -04007396
Geoff Langbfdea662014-07-23 14:16:32 -04007397 default:
Geoff Langb1196682014-07-23 13:47:29 -04007398 context->recordError(gl::Error(GL_INVALID_ENUM));
7399 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007400 }
7401
7402 if (!(context->getIndexedInteger64v(target, index, data)))
7403 {
7404 GLenum nativeType;
7405 unsigned int numParams = 0;
7406 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007407 {
7408 context->recordError(gl::Error(GL_INVALID_ENUM));
7409 return;
7410 }
Shannon Woods15934d52013-08-19 14:28:49 -04007411
Geoff Langbfdea662014-07-23 14:16:32 -04007412 if (numParams == 0)
7413 return; // it is known that pname is valid, but there are no parameters to return
7414
7415 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007416 {
Geoff Langbfdea662014-07-23 14:16:32 -04007417 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007418
Geoff Langbfdea662014-07-23 14:16:32 -04007419 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007420
Geoff Langbfdea662014-07-23 14:16:32 -04007421 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007422 {
Geoff Langbfdea662014-07-23 14:16:32 -04007423 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007424 }
Geoff Langbfdea662014-07-23 14:16:32 -04007425
7426 delete [] intParams;
7427 }
7428 else
7429 {
7430 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007431 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007432 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007433 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007434}
7435
7436void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
7437{
7438 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7439 target, pname, params);
7440
Geoff Langbfdea662014-07-23 14:16:32 -04007441 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007442 if (context)
7443 {
7444 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007445 {
Geoff Langb1196682014-07-23 13:47:29 -04007446 context->recordError(gl::Error(GL_INVALID_OPERATION));
7447 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007448 }
Geoff Langbfdea662014-07-23 14:16:32 -04007449
7450 if (!gl::ValidBufferTarget(context, target))
7451 {
Geoff Langb1196682014-07-23 13:47:29 -04007452 context->recordError(gl::Error(GL_INVALID_ENUM));
7453 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007454 }
7455
7456 if (!gl::ValidBufferParameter(context, pname))
7457 {
Geoff Langb1196682014-07-23 13:47:29 -04007458 context->recordError(gl::Error(GL_INVALID_ENUM));
7459 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007460 }
7461
7462 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7463
7464 if (!buffer)
7465 {
7466 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007467 context->recordError(gl::Error(GL_INVALID_OPERATION));
7468 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007469 }
7470
7471 switch (pname)
7472 {
7473 case GL_BUFFER_USAGE:
7474 *params = static_cast<GLint64>(buffer->getUsage());
7475 break;
7476 case GL_BUFFER_SIZE:
7477 *params = buffer->getSize();
7478 break;
7479 case GL_BUFFER_ACCESS_FLAGS:
7480 *params = static_cast<GLint64>(buffer->getAccessFlags());
7481 break;
7482 case GL_BUFFER_MAPPED:
7483 *params = static_cast<GLint64>(buffer->isMapped());
7484 break;
7485 case GL_BUFFER_MAP_OFFSET:
7486 *params = buffer->getMapOffset();
7487 break;
7488 case GL_BUFFER_MAP_LENGTH:
7489 *params = buffer->getMapLength();
7490 break;
7491 default: UNREACHABLE(); break;
7492 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007493 }
7494}
7495
7496void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
7497{
7498 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7499
Geoff Langbfdea662014-07-23 14:16:32 -04007500 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007501 if (context)
7502 {
7503 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007504 {
Geoff Langb1196682014-07-23 13:47:29 -04007505 context->recordError(gl::Error(GL_INVALID_OPERATION));
7506 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007507 }
Geoff Langbfdea662014-07-23 14:16:32 -04007508
7509 if (count < 0)
7510 {
Geoff Langb1196682014-07-23 13:47:29 -04007511 context->recordError(gl::Error(GL_INVALID_VALUE));
7512 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007513 }
7514
7515 for (int i = 0; i < count; i++)
7516 {
7517 samplers[i] = context->createSampler();
7518 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007519 }
7520}
7521
7522void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
7523{
7524 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7525
Geoff Langbfdea662014-07-23 14:16:32 -04007526 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007527 if (context)
7528 {
7529 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007530 {
Geoff Langb1196682014-07-23 13:47:29 -04007531 context->recordError(gl::Error(GL_INVALID_OPERATION));
7532 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007533 }
Geoff Langbfdea662014-07-23 14:16:32 -04007534
7535 if (count < 0)
7536 {
Geoff Langb1196682014-07-23 13:47:29 -04007537 context->recordError(gl::Error(GL_INVALID_VALUE));
7538 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007539 }
7540
7541 for (int i = 0; i < count; i++)
7542 {
7543 context->deleteSampler(samplers[i]);
7544 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007545 }
7546}
7547
7548GLboolean __stdcall glIsSampler(GLuint sampler)
7549{
7550 EVENT("(GLuint sampler = %u)", sampler);
7551
Geoff Langbfdea662014-07-23 14:16:32 -04007552 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007553 if (context)
7554 {
7555 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007556 {
Geoff Langb1196682014-07-23 13:47:29 -04007557 context->recordError(gl::Error(GL_INVALID_OPERATION));
7558 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007559 }
Geoff Langbfdea662014-07-23 14:16:32 -04007560
7561 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007562 }
7563
7564 return GL_FALSE;
7565}
7566
7567void __stdcall glBindSampler(GLuint unit, GLuint sampler)
7568{
7569 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7570
Geoff Langbfdea662014-07-23 14:16:32 -04007571 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007572 if (context)
7573 {
7574 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007575 {
Geoff Langb1196682014-07-23 13:47:29 -04007576 context->recordError(gl::Error(GL_INVALID_OPERATION));
7577 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007578 }
Geoff Langbfdea662014-07-23 14:16:32 -04007579
7580 if (sampler != 0 && !context->isSampler(sampler))
7581 {
Geoff Langb1196682014-07-23 13:47:29 -04007582 context->recordError(gl::Error(GL_INVALID_OPERATION));
7583 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007584 }
7585
Geoff Lang3a61c322014-07-10 13:01:54 -04007586 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007587 {
Geoff Langb1196682014-07-23 13:47:29 -04007588 context->recordError(gl::Error(GL_INVALID_VALUE));
7589 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007590 }
7591
7592 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007593 }
7594}
7595
7596void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7597{
7598 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7599
Geoff Langbfdea662014-07-23 14:16:32 -04007600 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007601 if (context)
7602 {
7603 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007604 {
Geoff Langb1196682014-07-23 13:47:29 -04007605 context->recordError(gl::Error(GL_INVALID_OPERATION));
7606 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007607 }
Geoff Langbfdea662014-07-23 14:16:32 -04007608
Geoff Langb1196682014-07-23 13:47:29 -04007609 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007610 {
7611 return;
7612 }
7613
7614 if (!gl::ValidateTexParamParameters(context, pname, param))
7615 {
7616 return;
7617 }
7618
7619 if (!context->isSampler(sampler))
7620 {
Geoff Langb1196682014-07-23 13:47:29 -04007621 context->recordError(gl::Error(GL_INVALID_OPERATION));
7622 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007623 }
7624
7625 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007626 }
7627}
7628
7629void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
7630{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007631 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007632}
7633
7634void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7635{
7636 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7637
Geoff Langbfdea662014-07-23 14:16:32 -04007638 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007639 if (context)
7640 {
7641 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007642 {
Geoff Langb1196682014-07-23 13:47:29 -04007643 context->recordError(gl::Error(GL_INVALID_OPERATION));
7644 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007645 }
Geoff Langbfdea662014-07-23 14:16:32 -04007646
Geoff Langb1196682014-07-23 13:47:29 -04007647 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007648 {
7649 return;
7650 }
7651
7652 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7653 {
7654 return;
7655 }
7656
7657 if (!context->isSampler(sampler))
7658 {
Geoff Langb1196682014-07-23 13:47:29 -04007659 context->recordError(gl::Error(GL_INVALID_OPERATION));
7660 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007661 }
7662
7663 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007664 }
7665}
7666
7667void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
7668{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007669 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007670}
7671
7672void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
7673{
7674 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7675
Geoff Langbfdea662014-07-23 14:16:32 -04007676 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007677 if (context)
7678 {
7679 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007680 {
Geoff Langb1196682014-07-23 13:47:29 -04007681 context->recordError(gl::Error(GL_INVALID_OPERATION));
7682 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007683 }
Geoff Langbfdea662014-07-23 14:16:32 -04007684
Geoff Langb1196682014-07-23 13:47:29 -04007685 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007686 {
7687 return;
7688 }
7689
7690 if (!context->isSampler(sampler))
7691 {
Geoff Langb1196682014-07-23 13:47:29 -04007692 context->recordError(gl::Error(GL_INVALID_OPERATION));
7693 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007694 }
7695
7696 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007697 }
7698}
7699
7700void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
7701{
7702 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7703
Geoff Langbfdea662014-07-23 14:16:32 -04007704 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007705 if (context)
7706 {
7707 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007708 {
Geoff Langb1196682014-07-23 13:47:29 -04007709 context->recordError(gl::Error(GL_INVALID_OPERATION));
7710 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007711 }
Geoff Langbfdea662014-07-23 14:16:32 -04007712
Geoff Langb1196682014-07-23 13:47:29 -04007713 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007714 {
7715 return;
7716 }
7717
7718 if (!context->isSampler(sampler))
7719 {
Geoff Langb1196682014-07-23 13:47:29 -04007720 context->recordError(gl::Error(GL_INVALID_OPERATION));
7721 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007722 }
7723
7724 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007725 }
7726}
7727
7728void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
7729{
7730 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7731
Geoff Langbfdea662014-07-23 14:16:32 -04007732 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007733 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007734 {
Geoff Langbfdea662014-07-23 14:16:32 -04007735 if (context->getClientVersion() < 3)
7736 {
Geoff Langb1196682014-07-23 13:47:29 -04007737 context->recordError(gl::Error(GL_INVALID_OPERATION));
7738 return;
7739 }
7740
7741 if (index >= gl::MAX_VERTEX_ATTRIBS)
7742 {
7743 context->recordError(gl::Error(GL_INVALID_VALUE));
7744 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007745 }
7746
7747 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007748 }
7749}
7750
7751void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
7752{
7753 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7754
Geoff Langbfdea662014-07-23 14:16:32 -04007755 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007756 if (context)
7757 {
7758 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007759 {
Geoff Langb1196682014-07-23 13:47:29 -04007760 context->recordError(gl::Error(GL_INVALID_OPERATION));
7761 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007762 }
Geoff Langbfdea662014-07-23 14:16:32 -04007763
7764 switch (target)
7765 {
7766 case GL_TRANSFORM_FEEDBACK:
7767 {
7768 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
7769 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
7770 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
7771 {
Geoff Langb1196682014-07-23 13:47:29 -04007772 context->recordError(gl::Error(GL_INVALID_OPERATION));
7773 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007774 }
7775
7776 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
7777 if (context->getTransformFeedback(id) == NULL)
7778 {
Geoff Langb1196682014-07-23 13:47:29 -04007779 context->recordError(gl::Error(GL_INVALID_OPERATION));
7780 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007781 }
7782
7783 context->bindTransformFeedback(id);
7784 }
7785 break;
7786
7787 default:
Geoff Langb1196682014-07-23 13:47:29 -04007788 context->recordError(gl::Error(GL_INVALID_ENUM));
7789 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007790 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007791 }
7792}
7793
7794void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
7795{
7796 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
7797
Geoff Langbfdea662014-07-23 14:16:32 -04007798 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007799 if (context)
7800 {
7801 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007802 {
Geoff Langb1196682014-07-23 13:47:29 -04007803 context->recordError(gl::Error(GL_INVALID_OPERATION));
7804 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007805 }
Geoff Langbfdea662014-07-23 14:16:32 -04007806
7807 for (int i = 0; i < n; i++)
7808 {
7809 context->deleteTransformFeedback(ids[i]);
7810 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007811 }
7812}
7813
7814void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
7815{
7816 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7817
Geoff Langbfdea662014-07-23 14:16:32 -04007818 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007819 if (context)
7820 {
7821 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007822 {
Geoff Langb1196682014-07-23 13:47:29 -04007823 context->recordError(gl::Error(GL_INVALID_OPERATION));
7824 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007825 }
Geoff Langbfdea662014-07-23 14:16:32 -04007826
7827 for (int i = 0; i < n; i++)
7828 {
7829 ids[i] = context->createTransformFeedback();
7830 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007831 }
7832}
7833
7834GLboolean __stdcall glIsTransformFeedback(GLuint id)
7835{
7836 EVENT("(GLuint id = %u)", id);
7837
Geoff Langbfdea662014-07-23 14:16:32 -04007838 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007839 if (context)
7840 {
7841 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007842 {
Geoff Langb1196682014-07-23 13:47:29 -04007843 context->recordError(gl::Error(GL_INVALID_OPERATION));
7844 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007845 }
Geoff Langbfdea662014-07-23 14:16:32 -04007846
7847 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007848 }
7849
7850 return GL_FALSE;
7851}
7852
7853void __stdcall glPauseTransformFeedback(void)
7854{
7855 EVENT("(void)");
7856
Geoff Langbfdea662014-07-23 14:16:32 -04007857 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007858 if (context)
7859 {
7860 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007861 {
Geoff Langb1196682014-07-23 13:47:29 -04007862 context->recordError(gl::Error(GL_INVALID_OPERATION));
7863 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007864 }
Geoff Langbfdea662014-07-23 14:16:32 -04007865
7866 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7867 ASSERT(transformFeedback != NULL);
7868
7869 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
7870 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
7871 {
Geoff Langb1196682014-07-23 13:47:29 -04007872 context->recordError(gl::Error(GL_INVALID_OPERATION));
7873 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007874 }
7875
7876 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007877 }
7878}
7879
7880void __stdcall glResumeTransformFeedback(void)
7881{
7882 EVENT("(void)");
7883
Geoff Langbfdea662014-07-23 14:16:32 -04007884 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007885 if (context)
7886 {
7887 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007888 {
Geoff Langb1196682014-07-23 13:47:29 -04007889 context->recordError(gl::Error(GL_INVALID_OPERATION));
7890 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007891 }
Geoff Langbfdea662014-07-23 14:16:32 -04007892
7893 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
7894 ASSERT(transformFeedback != NULL);
7895
7896 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
7897 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
7898 {
Geoff Langb1196682014-07-23 13:47:29 -04007899 context->recordError(gl::Error(GL_INVALID_OPERATION));
7900 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007901 }
7902
7903 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007904 }
7905}
7906
7907void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
7908{
7909 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
7910 program, bufSize, length, binaryFormat, binary);
7911
Geoff Langbfdea662014-07-23 14:16:32 -04007912 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007913 if (context)
7914 {
7915 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007916 {
Geoff Langb1196682014-07-23 13:47:29 -04007917 context->recordError(gl::Error(GL_INVALID_OPERATION));
7918 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007919 }
Geoff Langbfdea662014-07-23 14:16:32 -04007920
7921 // glGetProgramBinary
7922 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007923 }
7924}
7925
7926void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
7927{
7928 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
7929 program, binaryFormat, binary, length);
7930
Geoff Langbfdea662014-07-23 14:16:32 -04007931 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007932 if (context)
7933 {
7934 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007935 {
Geoff Langb1196682014-07-23 13:47:29 -04007936 context->recordError(gl::Error(GL_INVALID_OPERATION));
7937 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007938 }
Geoff Langbfdea662014-07-23 14:16:32 -04007939
7940 // glProgramBinary
7941 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007942 }
7943}
7944
7945void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
7946{
7947 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
7948 program, pname, value);
7949
Geoff Langbfdea662014-07-23 14:16:32 -04007950 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007951 if (context)
7952 {
7953 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007954 {
Geoff Langb1196682014-07-23 13:47:29 -04007955 context->recordError(gl::Error(GL_INVALID_OPERATION));
7956 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007957 }
Geoff Langbfdea662014-07-23 14:16:32 -04007958
7959 // glProgramParameteri
7960 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007961 }
7962}
7963
7964void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
7965{
7966 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
7967 target, numAttachments, attachments);
7968
Geoff Langbfdea662014-07-23 14:16:32 -04007969 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007970 if (context)
7971 {
7972 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007973 {
Geoff Langb1196682014-07-23 13:47:29 -04007974 context->recordError(gl::Error(GL_INVALID_OPERATION));
7975 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00007976 }
Geoff Langbfdea662014-07-23 14:16:32 -04007977
7978 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
7979 {
7980 return;
7981 }
7982
7983 GLuint maxDimension = context->getCaps().maxRenderbufferSize;
7984 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007985 }
7986}
7987
7988void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
7989{
7990 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
7991 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7992 target, numAttachments, attachments, x, y, width, height);
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
8008 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008009 }
8010}
8011
8012void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
8013{
8014 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8015 target, levels, internalformat, width, height);
8016
Geoff Langbfdea662014-07-23 14:16:32 -04008017 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008018 if (context)
8019 {
8020 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008021 {
Geoff Langb1196682014-07-23 13:47:29 -04008022 context->recordError(gl::Error(GL_INVALID_OPERATION));
8023 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008024 }
Geoff Langbfdea662014-07-23 14:16:32 -04008025
8026 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8027 {
8028 return;
8029 }
8030
8031 switch (target)
8032 {
8033 case GL_TEXTURE_2D:
8034 {
8035 gl::Texture2D *texture2d = context->getTexture2D();
8036 texture2d->storage(levels, internalformat, width, height);
8037 }
8038 break;
8039
8040 case GL_TEXTURE_CUBE_MAP:
8041 {
8042 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
8043 textureCube->storage(levels, internalformat, width);
8044 }
8045 break;
8046
8047 default:
Geoff Langb1196682014-07-23 13:47:29 -04008048 context->recordError(gl::Error(GL_INVALID_ENUM));
8049 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008050 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008051 }
8052}
8053
8054void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
8055{
8056 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8057 "GLsizei height = %d, GLsizei depth = %d)",
8058 target, levels, internalformat, width, height, depth);
8059
Geoff Langbfdea662014-07-23 14:16:32 -04008060 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008061 if (context)
8062 {
8063 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008064 {
Geoff Langb1196682014-07-23 13:47:29 -04008065 context->recordError(gl::Error(GL_INVALID_OPERATION));
8066 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008067 }
Geoff Langbfdea662014-07-23 14:16:32 -04008068
8069 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8070 {
8071 return;
8072 }
8073
8074 switch (target)
8075 {
8076 case GL_TEXTURE_3D:
8077 {
8078 gl::Texture3D *texture3d = context->getTexture3D();
8079 texture3d->storage(levels, internalformat, width, height, depth);
8080 }
8081 break;
8082
8083 case GL_TEXTURE_2D_ARRAY:
8084 {
8085 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
8086 texture2darray->storage(levels, internalformat, width, height, depth);
8087 }
8088 break;
8089
8090 default:
8091 UNREACHABLE();
8092 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008093 }
8094}
8095
8096void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
8097{
8098 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8099 "GLint* params = 0x%0.8p)",
8100 target, internalformat, pname, bufSize, params);
8101
Geoff Langbfdea662014-07-23 14:16:32 -04008102 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008103 if (context)
8104 {
8105 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008106 {
Geoff Langb1196682014-07-23 13:47:29 -04008107 context->recordError(gl::Error(GL_INVALID_OPERATION));
8108 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008109 }
Geoff Langbfdea662014-07-23 14:16:32 -04008110
8111 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8112 if (!formatCaps.renderable)
8113 {
Geoff Langb1196682014-07-23 13:47:29 -04008114 context->recordError(gl::Error(GL_INVALID_ENUM));
8115 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008116 }
8117
8118 if (target != GL_RENDERBUFFER)
8119 {
Geoff Langb1196682014-07-23 13:47:29 -04008120 context->recordError(gl::Error(GL_INVALID_ENUM));
8121 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008122 }
8123
8124 if (bufSize < 0)
8125 {
Geoff Langb1196682014-07-23 13:47:29 -04008126 context->recordError(gl::Error(GL_INVALID_VALUE));
8127 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008128 }
8129
8130 switch (pname)
8131 {
8132 case GL_NUM_SAMPLE_COUNTS:
8133 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008134 {
8135 *params = formatCaps.sampleCounts.size();
8136 }
Geoff Langbfdea662014-07-23 14:16:32 -04008137 break;
Geoff Langb1196682014-07-23 13:47:29 -04008138
Geoff Langbfdea662014-07-23 14:16:32 -04008139 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008140 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008141 break;
Geoff Langb1196682014-07-23 13:47:29 -04008142
Geoff Langbfdea662014-07-23 14:16:32 -04008143 default:
Geoff Langb1196682014-07-23 13:47:29 -04008144 context->recordError(gl::Error(GL_INVALID_ENUM));
8145 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008146 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008147 }
8148}
8149
8150// Extension functions
8151
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008152void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
8153 GLbitfield mask, GLenum filter)
8154{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008155 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008156 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8157 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8158 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8159
Geoff Langbfdea662014-07-23 14:16:32 -04008160 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008161 if (context)
8162 {
8163 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8164 dstX0, dstY0, dstX1, dstY1, mask, filter,
8165 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008166 {
Geoff Langbfdea662014-07-23 14:16:32 -04008167 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008168 }
Geoff Langbfdea662014-07-23 14:16:32 -04008169
8170 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8171 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008172 }
8173}
8174
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008175void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
8176 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008177{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008178 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008179 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008180 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008181 target, level, internalformat, width, height, depth, border, format, type, pixels);
8182
Geoff Langbfdea662014-07-23 14:16:32 -04008183 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008184}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008185
Geoff Langbfdea662014-07-23 14:16:32 -04008186void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008187 GLenum *binaryFormat, void *binary)
8188{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008189 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 +00008190 program, bufSize, length, binaryFormat, binary);
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 gl::Program *programObject = context->getProgram(program);
8196
8197 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008198 {
Geoff Langb1196682014-07-23 13:47:29 -04008199 context->recordError(gl::Error(GL_INVALID_OPERATION));
8200 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008201 }
Geoff Langbfdea662014-07-23 14:16:32 -04008202
8203 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8204
8205 if (!programBinary)
8206 {
Geoff Langb1196682014-07-23 13:47:29 -04008207 context->recordError(gl::Error(GL_INVALID_OPERATION));
8208 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008209 }
8210
Geoff Lang900013c2014-07-07 11:32:19 -04008211 if (!programBinary->save(binaryFormat, binary, bufSize, length))
Geoff Langbfdea662014-07-23 14:16:32 -04008212 {
Geoff Langb1196682014-07-23 13:47:29 -04008213 context->recordError(gl::Error(GL_INVALID_OPERATION));
8214 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008215 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008216 }
8217}
8218
8219void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
8220 const void *binary, GLint length)
8221{
8222 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8223 program, binaryFormat, binary, length);
8224
Geoff Langbfdea662014-07-23 14:16:32 -04008225 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008226 if (context)
8227 {
Geoff Lang900013c2014-07-07 11:32:19 -04008228 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8229 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008230 {
Geoff Langb1196682014-07-23 13:47:29 -04008231 context->recordError(gl::Error(GL_INVALID_ENUM));
8232 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008233 }
Geoff Langbfdea662014-07-23 14:16:32 -04008234
8235 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008236 if (!programObject)
8237 {
Geoff Langb1196682014-07-23 13:47:29 -04008238 context->recordError(gl::Error(GL_INVALID_OPERATION));
8239 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008240 }
8241
Geoff Lang900013c2014-07-07 11:32:19 -04008242 context->setProgramBinary(program, binaryFormat, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008243 }
8244}
8245
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008246void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
8247{
8248 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8249
Geoff Langbfdea662014-07-23 14:16:32 -04008250 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008251 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008252 {
Geoff Langbfdea662014-07-23 14:16:32 -04008253 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008254 {
Geoff Langb1196682014-07-23 13:47:29 -04008255 context->recordError(gl::Error(GL_INVALID_VALUE));
8256 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008257 }
8258
8259 if (context->getState().getDrawFramebuffer()->id() == 0)
8260 {
8261 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008262 {
Geoff Langb1196682014-07-23 13:47:29 -04008263 context->recordError(gl::Error(GL_INVALID_OPERATION));
8264 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008265 }
8266
Geoff Langbfdea662014-07-23 14:16:32 -04008267 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008268 {
Geoff Langb1196682014-07-23 13:47:29 -04008269 context->recordError(gl::Error(GL_INVALID_OPERATION));
8270 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008271 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008272 }
Geoff Langbfdea662014-07-23 14:16:32 -04008273 else
8274 {
8275 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8276 {
8277 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8278 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8279 {
Geoff Langb1196682014-07-23 13:47:29 -04008280 context->recordError(gl::Error(GL_INVALID_OPERATION));
8281 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008282 }
8283 }
8284 }
8285
8286 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
8287
8288 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8289 {
8290 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8291 }
8292
8293 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8294 {
8295 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8296 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008297 }
8298}
8299
Shannon Woodsb3801742014-03-27 14:59:19 -04008300void __stdcall glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
8301{
8302 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8303
Geoff Langbfdea662014-07-23 14:16:32 -04008304 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008305 if (context)
8306 {
8307 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008308 {
Geoff Langb1196682014-07-23 13:47:29 -04008309 context->recordError(gl::Error(GL_INVALID_ENUM));
8310 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008311 }
Geoff Langbfdea662014-07-23 14:16:32 -04008312
8313 if (pname != GL_BUFFER_MAP_POINTER)
8314 {
Geoff Langb1196682014-07-23 13:47:29 -04008315 context->recordError(gl::Error(GL_INVALID_ENUM));
8316 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008317 }
8318
8319 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8320
8321 if (!buffer || !buffer->isMapped())
8322 {
8323 *params = NULL;
8324 }
8325 else
8326 {
8327 *params = buffer->getMapPointer();
8328 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008329 }
8330}
8331
8332void * __stdcall glMapBufferOES(GLenum target, GLenum access)
8333{
8334 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
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 NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008343 }
Geoff Langbfdea662014-07-23 14:16:32 -04008344
8345 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8346
8347 if (buffer == NULL)
8348 {
Geoff Langb1196682014-07-23 13:47:29 -04008349 context->recordError(gl::Error(GL_INVALID_OPERATION));
8350 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008351 }
8352
8353 if (access != GL_WRITE_ONLY_OES)
8354 {
Geoff Langb1196682014-07-23 13:47:29 -04008355 context->recordError(gl::Error(GL_INVALID_ENUM));
8356 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008357 }
8358
8359 if (buffer->isMapped())
8360 {
Geoff Langb1196682014-07-23 13:47:29 -04008361 context->recordError(gl::Error(GL_INVALID_OPERATION));
8362 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008363 }
8364
8365 return buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
Shannon Woodsb3801742014-03-27 14:59:19 -04008366 }
8367
8368 return NULL;
8369}
8370
8371GLboolean __stdcall glUnmapBufferOES(GLenum target)
8372{
8373 EVENT("(GLenum target = 0x%X)", target);
8374
Geoff Langbfdea662014-07-23 14:16:32 -04008375 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008376 if (context)
8377 {
8378 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008379 {
Geoff Langb1196682014-07-23 13:47:29 -04008380 context->recordError(gl::Error(GL_INVALID_ENUM));
8381 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008382 }
Geoff Langbfdea662014-07-23 14:16:32 -04008383
8384 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8385
8386 if (buffer == NULL || !buffer->isMapped())
8387 {
Geoff Langb1196682014-07-23 13:47:29 -04008388 context->recordError(gl::Error(GL_INVALID_OPERATION));
8389 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008390 }
8391
8392 // TODO: detect if we had corruption. if so, throw an error and return false.
8393
8394 buffer->unmap();
8395
8396 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008397 }
8398
8399 return GL_FALSE;
8400}
8401
Shannon Woods916e7692014-03-27 16:58:22 -04008402void* __stdcall glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8403{
8404 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8405 target, offset, length, access);
8406
Geoff Langbfdea662014-07-23 14:16:32 -04008407 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008408 if (context)
8409 {
8410 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008411 {
Geoff Langb1196682014-07-23 13:47:29 -04008412 context->recordError(gl::Error(GL_INVALID_ENUM));
8413 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008414 }
Geoff Langbfdea662014-07-23 14:16:32 -04008415
8416 if (offset < 0 || length < 0)
8417 {
Geoff Langb1196682014-07-23 13:47:29 -04008418 context->recordError(gl::Error(GL_INVALID_VALUE));
8419 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008420 }
8421
8422 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8423
8424 if (buffer == NULL)
8425 {
Geoff Langb1196682014-07-23 13:47:29 -04008426 context->recordError(gl::Error(GL_INVALID_OPERATION));
8427 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008428 }
8429
8430 // Check for buffer overflow
8431 size_t offsetSize = static_cast<size_t>(offset);
8432 size_t lengthSize = static_cast<size_t>(length);
8433
8434 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8435 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8436 {
Geoff Langb1196682014-07-23 13:47:29 -04008437 context->recordError(gl::Error(GL_INVALID_VALUE));
8438 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008439 }
8440
8441 // Check for invalid bits in the mask
8442 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8443 GL_MAP_WRITE_BIT |
8444 GL_MAP_INVALIDATE_RANGE_BIT |
8445 GL_MAP_INVALIDATE_BUFFER_BIT |
8446 GL_MAP_FLUSH_EXPLICIT_BIT |
8447 GL_MAP_UNSYNCHRONIZED_BIT;
8448
8449 if (access & ~(allAccessBits))
8450 {
Geoff Langb1196682014-07-23 13:47:29 -04008451 context->recordError(gl::Error(GL_INVALID_VALUE));
8452 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008453 }
8454
8455 if (length == 0 || buffer->isMapped())
8456 {
Geoff Langb1196682014-07-23 13:47:29 -04008457 context->recordError(gl::Error(GL_INVALID_OPERATION));
8458 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008459 }
8460
8461 // Check for invalid bit combinations
8462 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8463 {
Geoff Langb1196682014-07-23 13:47:29 -04008464 context->recordError(gl::Error(GL_INVALID_OPERATION));
8465 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008466 }
8467
8468 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8469 GL_MAP_INVALIDATE_BUFFER_BIT |
8470 GL_MAP_UNSYNCHRONIZED_BIT;
8471
8472 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8473 {
Geoff Langb1196682014-07-23 13:47:29 -04008474 context->recordError(gl::Error(GL_INVALID_OPERATION));
8475 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008476 }
8477
8478 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8479 {
Geoff Langb1196682014-07-23 13:47:29 -04008480 context->recordError(gl::Error(GL_INVALID_OPERATION));
8481 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008482 }
8483
8484 return buffer->mapRange(offset, length, access);
Shannon Woods916e7692014-03-27 16:58:22 -04008485 }
8486
8487 return NULL;
8488}
8489
8490void __stdcall glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
8491{
8492 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8493
Geoff Langbfdea662014-07-23 14:16:32 -04008494 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008495 if (context)
8496 {
8497 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008498 {
Geoff Langb1196682014-07-23 13:47:29 -04008499 context->recordError(gl::Error(GL_INVALID_VALUE));
8500 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008501 }
Geoff Langbfdea662014-07-23 14:16:32 -04008502
8503 if (!gl::ValidBufferTarget(context, target))
8504 {
Geoff Langb1196682014-07-23 13:47:29 -04008505 context->recordError(gl::Error(GL_INVALID_ENUM));
8506 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008507 }
8508
8509 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8510
8511 if (buffer == NULL)
8512 {
Geoff Langb1196682014-07-23 13:47:29 -04008513 context->recordError(gl::Error(GL_INVALID_OPERATION));
8514 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008515 }
8516
8517 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8518 {
Geoff Langb1196682014-07-23 13:47:29 -04008519 context->recordError(gl::Error(GL_INVALID_OPERATION));
8520 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008521 }
8522
8523 // Check for buffer overflow
8524 size_t offsetSize = static_cast<size_t>(offset);
8525 size_t lengthSize = static_cast<size_t>(length);
8526
8527 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8528 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8529 {
Geoff Langb1196682014-07-23 13:47:29 -04008530 context->recordError(gl::Error(GL_INVALID_VALUE));
8531 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008532 }
8533
8534 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008535 }
8536}
8537
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008538__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
8539{
8540 struct Extension
8541 {
8542 const char *name;
8543 __eglMustCastToProperFunctionPointerType address;
8544 };
8545
8546 static const Extension glExtensions[] =
8547 {
8548 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +00008549 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +00008550 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00008551 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
8552 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
8553 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
8554 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
8555 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
8556 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
8557 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +00008558 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +00008559 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +00008560 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
8561 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
8562 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
8563 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00008564 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
8565 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
8566 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
8567 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
8568 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
8569 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
8570 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +00008571 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +00008572 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
8573 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
8574 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008575 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
Shannon Woodsb3801742014-03-27 14:59:19 -04008576 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES},
8577 {"glGetBufferPointervOES", (__eglMustCastToProperFunctionPointerType)glGetBufferPointervOES},
8578 {"glMapBufferOES", (__eglMustCastToProperFunctionPointerType)glMapBufferOES},
Shannon Woods916e7692014-03-27 16:58:22 -04008579 {"glUnmapBufferOES", (__eglMustCastToProperFunctionPointerType)glUnmapBufferOES},
8580 {"glMapBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glMapBufferRangeEXT},
8581 {"glFlushMappedBufferRangeEXT", (__eglMustCastToProperFunctionPointerType)glFlushMappedBufferRangeEXT}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008582
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +00008583 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008584 {
8585 if (strcmp(procname, glExtensions[ext].name) == 0)
8586 {
8587 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
8588 }
8589 }
8590
8591 return NULL;
8592}
8593
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00008594// Non-public functions used by EGL
8595
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008596bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008597{
8598 EVENT("(egl::Surface* surface = 0x%0.8p)",
8599 surface);
8600
Geoff Langbfdea662014-07-23 14:16:32 -04008601 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008602 if (context)
8603 {
8604 gl::Texture2D *textureObject = context->getTexture2D();
8605 ASSERT(textureObject != NULL);
8606
8607 if (textureObject->isImmutable())
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008608 {
Geoff Langbfdea662014-07-23 14:16:32 -04008609 return false;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008610 }
Geoff Langbfdea662014-07-23 14:16:32 -04008611
8612 textureObject->bindTexImage(surface);
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008613 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00008614
8615 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +00008616}
8617
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008618}