1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // libGLES_CM.cpp: Implements the exported OpenGL ES 1.1 functions.
19 #include "utilities.h"
22 #include "Framebuffer.h"
23 #include "Renderbuffer.h"
25 #include "common/debug.h"
26 #include "Common/SharedLibrary.hpp"
27 #include "Common/Version.h"
30 #include <EGL/eglext.h>
33 #include <GLES/glext.h>
40 static bool validImageSize(GLint level, GLsizei width, GLsizei height)
42 if(level < 0 || level >= es1::IMPLEMENTATION_MAX_TEXTURE_LEVELS || width < 0 || height < 0)
50 static bool validateSubImageParams(bool compressed, GLsizei width, GLsizei height, GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, es1::Texture *texture)
54 return error(GL_INVALID_OPERATION, false);
57 if(compressed != texture->isCompressed(target, level))
59 return error(GL_INVALID_OPERATION, false);
62 if(format != GL_NONE_OES && format != texture->getFormat(target, level))
64 return error(GL_INVALID_OPERATION, false);
69 if((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
70 (height % 4 != 0 && height != texture->getHeight(target, 0)))
72 return error(GL_INVALID_OPERATION, false);
76 if(xoffset + width > texture->getWidth(target, level) ||
77 yoffset + height > texture->getHeight(target, level))
79 return error(GL_INVALID_VALUE, false);
85 void ActiveTexture(GLenum texture)
87 TRACE("(GLenum texture = 0x%X)", texture);
89 es1::Context *context = es1::getContext();
93 if(texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + es1::MAX_TEXTURE_UNITS - 1)
95 return error(GL_INVALID_ENUM);
98 context->setActiveSampler(texture - GL_TEXTURE0);
102 void AlphaFunc(GLenum func, GLclampf ref)
104 TRACE("(GLenum func = 0x%X, GLclampf ref = %f)", func, ref);
118 return error(GL_INVALID_ENUM);
121 es1::Context *context = es1::getContext();
125 context->setAlphaFunc(func, clamp01(ref));
129 void AlphaFuncx(GLenum func, GLclampx ref)
131 AlphaFunc(func, (float)ref / 0x10000);
134 void BindBuffer(GLenum target, GLuint buffer)
136 TRACE("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
138 es1::Context *context = es1::getContext();
144 case GL_ARRAY_BUFFER:
145 context->bindArrayBuffer(buffer);
147 case GL_ELEMENT_ARRAY_BUFFER:
148 context->bindElementArrayBuffer(buffer);
151 return error(GL_INVALID_ENUM);
156 void BindFramebuffer(GLenum target, GLuint framebuffer)
158 TRACE("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
160 if(target != GL_FRAMEBUFFER_OES)
162 return error(GL_INVALID_ENUM);
165 es1::Context *context = es1::getContext();
169 context->bindFramebuffer(framebuffer);
173 void BindFramebufferOES(GLenum target, GLuint framebuffer)
175 TRACE("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
177 if(target != GL_FRAMEBUFFER_OES)
179 return error(GL_INVALID_ENUM);
182 es1::Context *context = es1::getContext();
186 context->bindFramebuffer(framebuffer);
190 void BindRenderbufferOES(GLenum target, GLuint renderbuffer)
192 TRACE("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
194 if(target != GL_RENDERBUFFER_OES)
196 return error(GL_INVALID_ENUM);
199 es1::Context *context = es1::getContext();
203 if(renderbuffer != 0 && !context->getRenderbuffer(renderbuffer))
205 // [OpenGL ES 2.0.25] Section 4.4.3 page 112
206 // [OpenGL ES 3.0.2] Section 4.4.2 page 201
207 // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of
208 // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated.
209 return error(GL_INVALID_OPERATION);
212 context->bindRenderbuffer(renderbuffer);
216 void BindTexture(GLenum target, GLuint texture)
218 TRACE("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
220 es1::Context *context = es1::getContext();
224 es1::Texture *textureObject = context->getTexture(texture);
226 if(textureObject && textureObject->getTarget() != target && texture != 0)
228 return error(GL_INVALID_OPERATION);
234 context->bindTexture2D(texture);
236 case GL_TEXTURE_EXTERNAL_OES:
237 context->bindTextureExternal(texture);
240 return error(GL_INVALID_ENUM);
245 void BlendEquationSeparateOES(GLenum modeRGB, GLenum modeAlpha);
247 void BlendEquationOES(GLenum mode)
249 BlendEquationSeparateOES(mode, mode);
252 void BlendEquationSeparateOES(GLenum modeRGB, GLenum modeAlpha)
254 TRACE("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
258 case GL_FUNC_ADD_OES:
259 case GL_FUNC_SUBTRACT_OES:
260 case GL_FUNC_REVERSE_SUBTRACT_OES:
265 return error(GL_INVALID_ENUM);
270 case GL_FUNC_ADD_OES:
271 case GL_FUNC_SUBTRACT_OES:
272 case GL_FUNC_REVERSE_SUBTRACT_OES:
277 return error(GL_INVALID_ENUM);
280 es1::Context *context = es1::getContext();
284 context->setBlendEquation(modeRGB, modeAlpha);
288 void BlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
290 void BlendFunc(GLenum sfactor, GLenum dfactor)
292 BlendFuncSeparateOES(sfactor, dfactor, sfactor, dfactor);
295 void BlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
297 TRACE("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
298 srcRGB, dstRGB, srcAlpha, dstAlpha);
305 case GL_ONE_MINUS_SRC_COLOR:
307 case GL_ONE_MINUS_DST_COLOR:
309 case GL_ONE_MINUS_SRC_ALPHA:
311 case GL_ONE_MINUS_DST_ALPHA:
312 case GL_SRC_ALPHA_SATURATE:
315 return error(GL_INVALID_ENUM);
323 case GL_ONE_MINUS_SRC_COLOR:
325 case GL_ONE_MINUS_DST_COLOR:
327 case GL_ONE_MINUS_SRC_ALPHA:
329 case GL_ONE_MINUS_DST_ALPHA:
332 return error(GL_INVALID_ENUM);
340 case GL_ONE_MINUS_SRC_COLOR:
342 case GL_ONE_MINUS_DST_COLOR:
344 case GL_ONE_MINUS_SRC_ALPHA:
346 case GL_ONE_MINUS_DST_ALPHA:
347 case GL_SRC_ALPHA_SATURATE:
350 return error(GL_INVALID_ENUM);
358 case GL_ONE_MINUS_SRC_COLOR:
360 case GL_ONE_MINUS_DST_COLOR:
362 case GL_ONE_MINUS_SRC_ALPHA:
364 case GL_ONE_MINUS_DST_ALPHA:
367 return error(GL_INVALID_ENUM);
370 es1::Context *context = es1::getContext();
374 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
378 void BufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
380 size = static_cast<GLint>(size); // Work around issues with some 64-bit applications
382 TRACE("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = %p, GLenum usage = %d)",
383 target, size, data, usage);
387 return error(GL_INVALID_VALUE);
393 case GL_DYNAMIC_DRAW:
396 return error(GL_INVALID_ENUM);
399 es1::Context *context = es1::getContext();
407 case GL_ARRAY_BUFFER:
408 buffer = context->getArrayBuffer();
410 case GL_ELEMENT_ARRAY_BUFFER:
411 buffer = context->getElementArrayBuffer();
414 return error(GL_INVALID_ENUM);
419 return error(GL_INVALID_OPERATION);
422 buffer->bufferData(data, size, usage);
426 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
428 size = static_cast<GLint>(size); // Work around issues with some 64-bit applications
429 offset = static_cast<GLint>(offset);
431 TRACE("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = %p)",
432 target, offset, size, data);
434 if(size < 0 || offset < 0)
436 return error(GL_INVALID_VALUE);
444 es1::Context *context = es1::getContext();
452 case GL_ARRAY_BUFFER:
453 buffer = context->getArrayBuffer();
455 case GL_ELEMENT_ARRAY_BUFFER:
456 buffer = context->getElementArrayBuffer();
459 return error(GL_INVALID_ENUM);
464 return error(GL_INVALID_OPERATION);
467 if((size_t)size + offset > buffer->size())
469 return error(GL_INVALID_VALUE);
472 buffer->bufferSubData(data, size, offset);
476 GLenum CheckFramebufferStatusOES(GLenum target)
478 TRACE("(GLenum target = 0x%X)", target);
480 if(target != GL_FRAMEBUFFER_OES)
482 return error(GL_INVALID_ENUM, 0);
485 es1::Context *context = es1::getContext();
489 es1::Framebuffer *framebuffer = context->getFramebuffer();
491 return framebuffer->completeness();
497 void Clear(GLbitfield mask)
499 TRACE("(GLbitfield mask = %X)", mask);
501 if((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
503 return error(GL_INVALID_VALUE);
506 es1::Context *context = es1::getContext();
510 context->clear(mask);
514 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
516 TRACE("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
517 red, green, blue, alpha);
519 es1::Context *context = es1::getContext();
523 context->setClearColor(red, green, blue, alpha);
527 void ClearColorx(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha)
529 ClearColor((float)red / 0x10000, (float)green / 0x10000, (float)blue / 0x10000, (float)alpha / 0x10000);
532 void ClearDepthf(GLclampf depth)
534 TRACE("(GLclampf depth = %f)", depth);
536 es1::Context *context = es1::getContext();
540 context->setClearDepth(depth);
544 void ClearDepthx(GLclampx depth)
546 ClearDepthf((float)depth / 0x10000);
549 void ClearStencil(GLint s)
551 TRACE("(GLint s = %d)", s);
553 es1::Context *context = es1::getContext();
557 context->setClearStencil(s);
561 void ClientActiveTexture(GLenum texture)
563 TRACE("(GLenum texture = 0x%X)", texture);
571 return error(GL_INVALID_ENUM);
574 es1::Context *context = es1::getContext();
578 context->clientActiveTexture(texture);
582 void ClipPlanef(GLenum plane, const GLfloat *equation)
584 TRACE("(GLenum plane = 0x%X, const GLfloat *equation)", plane);
586 int index = plane - GL_CLIP_PLANE0;
588 if(index < 0 || index >= MAX_CLIP_PLANES)
590 return error(GL_INVALID_ENUM);
593 es1::Context *context = es1::getContext();
597 context->setClipPlane(index, equation);
601 void ClipPlanex(GLenum plane, const GLfixed *equation)
603 GLfloat equationf[4] =
605 (float)equation[0] / 0x10000,
606 (float)equation[1] / 0x10000,
607 (float)equation[2] / 0x10000,
608 (float)equation[3] / 0x10000,
611 ClipPlanef(plane, equationf);
614 void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
616 TRACE("(GLfloat red = %f, GLfloat green = %f, GLfloat blue = %f, GLfloat alpha = %f)", red, green, blue, alpha);
618 es1::Context *context = es1::getContext();
622 context->setVertexAttrib(sw::Color0, red, green, blue, alpha);
626 void Color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
628 Color4f((float)red / 0xFF, (float)green / 0xFF, (float)blue / 0xFF, (float)alpha / 0xFF);
631 void Color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
633 Color4f((float)red / 0x10000, (float)green / 0x10000, (float)blue / 0x10000, (float)alpha / 0x10000);
636 void ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
638 TRACE("(GLboolean red = %d, GLboolean green = %d, GLboolean blue = %d, GLboolean alpha = %d)",
639 red, green, blue, alpha);
641 es1::Context *context = es1::getContext();
645 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
649 void VertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
651 TRACE("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
652 "GLboolean normalized = %d, GLsizei stride = %d, const GLvoid* ptr = %p)",
653 index, size, type, normalized, stride, ptr);
655 if(index >= es1::MAX_VERTEX_ATTRIBS)
657 return error(GL_INVALID_VALUE);
660 if(size < 1 || size > 4)
662 return error(GL_INVALID_VALUE);
668 case GL_UNSIGNED_BYTE:
670 case GL_UNSIGNED_SHORT:
675 return error(GL_INVALID_ENUM);
680 return error(GL_INVALID_VALUE);
683 es1::Context *context = es1::getContext();
687 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, (normalized == GL_TRUE), stride, ptr);
691 void ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
693 TRACE("(GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid *pointer = %p)", size, type, stride, pointer);
697 return error(GL_INVALID_VALUE);
700 VertexAttribPointer(sw::Color0, size, type, true, stride, pointer);
703 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
704 GLint border, GLsizei imageSize, const GLvoid* data)
706 TRACE("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
707 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = %p)",
708 target, level, internalformat, width, height, border, imageSize, data);
710 if(level < 0 || level >= es1::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
712 return error(GL_INVALID_VALUE);
715 if(!validImageSize(level, width, height) || imageSize < 0)
717 return error(GL_INVALID_VALUE);
720 switch(internalformat)
722 case GL_ETC1_RGB8_OES:
724 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
725 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
728 return error(GL_INVALID_ENUM);
731 case GL_DEPTH_COMPONENT16_OES:
732 case GL_DEPTH_COMPONENT32_OES:
733 case GL_DEPTH_STENCIL_OES:
734 case GL_DEPTH24_STENCIL8_OES:
735 return error(GL_INVALID_OPERATION);
737 return error(GL_INVALID_ENUM);
742 return error(GL_INVALID_VALUE);
745 es1::Context *context = es1::getContext();
752 if(width > (es1::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level) ||
753 height > (es1::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level))
755 return error(GL_INVALID_VALUE);
759 return error(GL_INVALID_ENUM);
762 if(imageSize != egl::ComputeCompressedSize(width, height, internalformat))
764 return error(GL_INVALID_VALUE);
767 if(target == GL_TEXTURE_2D)
769 es1::Texture2D *texture = context->getTexture2D();
773 return error(GL_INVALID_OPERATION);
776 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
778 else UNREACHABLE(target);
782 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
783 GLenum format, GLsizei imageSize, const GLvoid* data)
785 TRACE("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
786 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
787 "GLsizei imageSize = %d, const GLvoid* data = %p)",
788 target, level, xoffset, yoffset, width, height, format, imageSize, data);
790 if(!es1::IsTextureTarget(target))
792 return error(GL_INVALID_ENUM);
795 if(level < 0 || level >= es1::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
797 return error(GL_INVALID_VALUE);
800 if(xoffset < 0 || yoffset < 0 || !validImageSize(level, width, height) || imageSize < 0)
802 return error(GL_INVALID_VALUE);
807 case GL_ETC1_RGB8_OES:
809 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
810 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
813 return error(GL_INVALID_ENUM);
817 return error(GL_INVALID_ENUM);
820 if(width == 0 || height == 0 || !data)
825 es1::Context *context = es1::getContext();
829 if(imageSize != egl::ComputeCompressedSize(width, height, format))
831 return error(GL_INVALID_VALUE);
834 if(xoffset % 4 != 0 || yoffset % 4 != 0)
836 // We wait to check the offsets until this point, because the multiple-of-four restriction does not exist unless DXT1 textures are supported
837 return error(GL_INVALID_OPERATION);
840 if(target == GL_TEXTURE_2D)
842 es1::Texture2D *texture = context->getTexture2D();
844 if(validateSubImageParams(true, width, height, xoffset, yoffset, target, level, format, texture))
846 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
849 else UNREACHABLE(target);
853 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
855 TRACE("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
856 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
857 target, level, internalformat, x, y, width, height, border);
859 if(!validImageSize(level, width, height))
861 return error(GL_INVALID_VALUE);
866 return error(GL_INVALID_VALUE);
869 es1::Context *context = es1::getContext();
876 if(width > (es1::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level) ||
877 height > (es1::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level))
879 return error(GL_INVALID_VALUE);
883 return error(GL_INVALID_ENUM);
886 es1::Framebuffer *framebuffer = context->getFramebuffer();
888 if(framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE_OES)
890 return error(GL_INVALID_FRAMEBUFFER_OPERATION_OES);
893 if(context->getFramebufferName() != 0 && framebuffer->getColorbuffer()->getSamples() > 1)
895 return error(GL_INVALID_OPERATION);
898 es1::Renderbuffer *source = framebuffer->getColorbuffer();
899 GLenum colorbufferFormat = source->getFormat();
901 // [OpenGL ES 2.0.24] table 3.9
902 switch(internalformat)
905 if(colorbufferFormat != GL_ALPHA &&
906 colorbufferFormat != GL_RGBA &&
907 colorbufferFormat != GL_RGBA4_OES &&
908 colorbufferFormat != GL_RGB5_A1_OES &&
909 colorbufferFormat != GL_RGBA8_OES)
911 return error(GL_INVALID_OPERATION);
916 if(colorbufferFormat != GL_RGB &&
917 colorbufferFormat != GL_RGB565_OES &&
918 colorbufferFormat != GL_RGB8_OES &&
919 colorbufferFormat != GL_RGBA &&
920 colorbufferFormat != GL_RGBA4_OES &&
921 colorbufferFormat != GL_RGB5_A1_OES &&
922 colorbufferFormat != GL_RGBA8_OES)
924 return error(GL_INVALID_OPERATION);
927 case GL_LUMINANCE_ALPHA:
929 if(colorbufferFormat != GL_RGBA &&
930 colorbufferFormat != GL_RGBA4_OES &&
931 colorbufferFormat != GL_RGB5_A1_OES &&
932 colorbufferFormat != GL_RGBA8_OES)
934 return error(GL_INVALID_OPERATION);
937 case GL_ETC1_RGB8_OES:
938 return error(GL_INVALID_OPERATION);
939 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
940 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
943 return error(GL_INVALID_OPERATION);
947 return error(GL_INVALID_ENUM);
950 return error(GL_INVALID_ENUM);
953 if(target == GL_TEXTURE_2D)
955 es1::Texture2D *texture = context->getTexture2D();
959 return error(GL_INVALID_OPERATION);
962 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
964 else UNREACHABLE(target);
968 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
970 TRACE("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
971 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
972 target, level, xoffset, yoffset, x, y, width, height);
974 if(!es1::IsTextureTarget(target))
976 return error(GL_INVALID_ENUM);
979 if(level < 0 || level >= es1::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
981 return error(GL_INVALID_VALUE);
984 if(xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
986 return error(GL_INVALID_VALUE);
989 if(std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
991 return error(GL_INVALID_VALUE);
994 if(width == 0 || height == 0)
999 es1::Context *context = es1::getContext();
1004 es1::Framebuffer *framebuffer = context->getFramebuffer();
1006 if(framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE_OES)
1008 return error(GL_INVALID_FRAMEBUFFER_OPERATION_OES);
1011 es1::Renderbuffer *source = framebuffer->getColorbuffer();
1013 if(context->getFramebufferName() != 0 && (!source || source->getSamples() > 1))
1015 return error(GL_INVALID_OPERATION);
1018 es1::Texture *texture = nullptr;
1020 if(target == GL_TEXTURE_2D)
1022 texture = context->getTexture2D();
1024 else UNREACHABLE(target);
1026 if(!validateSubImageParams(false, width, height, xoffset, yoffset, target, level, GL_NONE_OES, texture))
1031 texture->copySubImage(target, level, xoffset, yoffset, x, y, width, height, framebuffer);
1035 void CullFace(GLenum mode)
1037 TRACE("(GLenum mode = 0x%X)", mode);
1043 case GL_FRONT_AND_BACK:
1045 es1::Context *context = es1::getContext();
1049 context->setCullMode(mode);
1054 return error(GL_INVALID_ENUM);
1058 void DeleteBuffers(GLsizei n, const GLuint* buffers)
1060 TRACE("(GLsizei n = %d, const GLuint* buffers = %p)", n, buffers);
1064 return error(GL_INVALID_VALUE);
1067 es1::Context *context = es1::getContext();
1071 for(int i = 0; i < n; i++)
1073 context->deleteBuffer(buffers[i]);
1078 void DeleteFramebuffersOES(GLsizei n, const GLuint* framebuffers)
1080 TRACE("(GLsizei n = %d, const GLuint* framebuffers = %p)", n, framebuffers);
1084 return error(GL_INVALID_VALUE);
1087 es1::Context *context = es1::getContext();
1091 for(int i = 0; i < n; i++)
1093 if(framebuffers[i] != 0)
1095 context->deleteFramebuffer(framebuffers[i]);
1101 void DeleteRenderbuffersOES(GLsizei n, const GLuint* renderbuffers)
1103 TRACE("(GLsizei n = %d, const GLuint* renderbuffers = %p)", n, renderbuffers);
1107 return error(GL_INVALID_VALUE);
1110 es1::Context *context = es1::getContext();
1114 for(int i = 0; i < n; i++)
1116 context->deleteRenderbuffer(renderbuffers[i]);
1121 void DeleteTextures(GLsizei n, const GLuint* textures)
1123 TRACE("(GLsizei n = %d, const GLuint* textures = %p)", n, textures);
1127 return error(GL_INVALID_VALUE);
1130 es1::Context *context = es1::getContext();
1134 for(int i = 0; i < n; i++)
1136 if(textures[i] != 0)
1138 context->deleteTexture(textures[i]);
1144 void DepthFunc(GLenum func)
1146 TRACE("(GLenum func = 0x%X)", func);
1160 return error(GL_INVALID_ENUM);
1163 es1::Context *context = es1::getContext();
1167 context->setDepthFunc(func);
1171 void DepthMask(GLboolean flag)
1173 TRACE("(GLboolean flag = %d)", flag);
1175 es1::Context *context = es1::getContext();
1179 context->setDepthMask(flag != GL_FALSE);
1183 void DepthRangef(GLclampf zNear, GLclampf zFar)
1185 TRACE("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
1187 es1::Context *context = es1::getContext();
1191 context->setDepthRange(zNear, zFar);
1195 void DepthRangex(GLclampx zNear, GLclampx zFar)
1197 DepthRangef((float)zNear / 0x10000, (float)zFar / 0x10000);
1200 void Disable(GLenum cap)
1202 TRACE("(GLenum cap = 0x%X)", cap);
1204 es1::Context *context = es1::getContext();
1210 case GL_CULL_FACE: context->setCullFaceEnabled(false); break;
1211 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFillEnabled(false); break;
1212 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverageEnabled(false); break;
1213 case GL_SAMPLE_COVERAGE: context->setSampleCoverageEnabled(false); break;
1214 case GL_SCISSOR_TEST: context->setScissorTestEnabled(false); break;
1215 case GL_STENCIL_TEST: context->setStencilTestEnabled(false); break;
1216 case GL_DEPTH_TEST: context->setDepthTestEnabled(false); break;
1217 case GL_BLEND: context->setBlendEnabled(false); break;
1218 case GL_DITHER: context->setDitherEnabled(false); break;
1219 case GL_LIGHTING: context->setLightingEnabled(false); break;
1220 case GL_LIGHT0: context->setLightEnabled(0, false); break;
1221 case GL_LIGHT1: context->setLightEnabled(1, false); break;
1222 case GL_LIGHT2: context->setLightEnabled(2, false); break;
1223 case GL_LIGHT3: context->setLightEnabled(3, false); break;
1224 case GL_LIGHT4: context->setLightEnabled(4, false); break;
1225 case GL_LIGHT5: context->setLightEnabled(5, false); break;
1226 case GL_LIGHT6: context->setLightEnabled(6, false); break;
1227 case GL_LIGHT7: context->setLightEnabled(7, false); break;
1228 case GL_FOG: context->setFogEnabled(false); break;
1229 case GL_TEXTURE_2D: context->setTexture2Denabled(false); break;
1230 case GL_TEXTURE_EXTERNAL_OES: context->setTextureExternalEnabled(false); break;
1231 case GL_ALPHA_TEST: context->setAlphaTestEnabled(false); break;
1232 case GL_COLOR_LOGIC_OP: context->setColorLogicOpEnabled(false); break;
1233 case GL_POINT_SMOOTH: context->setPointSmoothEnabled(false); break;
1234 case GL_LINE_SMOOTH: context->setLineSmoothEnabled(false); break;
1235 case GL_COLOR_MATERIAL: context->setColorMaterialEnabled(false); break;
1236 case GL_NORMALIZE: context->setNormalizeEnabled(false); break;
1237 case GL_RESCALE_NORMAL: context->setRescaleNormalEnabled(false); break;
1238 case GL_VERTEX_ARRAY: context->setVertexArrayEnabled(false); break;
1239 case GL_NORMAL_ARRAY: context->setNormalArrayEnabled(false); break;
1240 case GL_COLOR_ARRAY: context->setColorArrayEnabled(false); break;
1241 case GL_POINT_SIZE_ARRAY_OES: context->setPointSizeArrayEnabled(false); break;
1242 case GL_TEXTURE_COORD_ARRAY: context->setTextureCoordArrayEnabled(false); break;
1243 case GL_MULTISAMPLE: context->setMultisampleEnabled(false); break;
1244 case GL_SAMPLE_ALPHA_TO_ONE: context->setSampleAlphaToOneEnabled(false); break;
1245 case GL_CLIP_PLANE0: context->setClipPlaneEnabled(0, false); break;
1246 case GL_CLIP_PLANE1: context->setClipPlaneEnabled(1, false); break;
1247 case GL_CLIP_PLANE2: context->setClipPlaneEnabled(2, false); break;
1248 case GL_CLIP_PLANE3: context->setClipPlaneEnabled(3, false); break;
1249 case GL_CLIP_PLANE4: context->setClipPlaneEnabled(4, false); break;
1250 case GL_CLIP_PLANE5: context->setClipPlaneEnabled(5, false); break;
1251 case GL_POINT_SPRITE_OES: context->setPointSpriteEnabled(false); break;
1253 return error(GL_INVALID_ENUM);
1258 void DisableClientState(GLenum array)
1260 TRACE("(GLenum array = 0x%X)", array);
1264 case GL_VERTEX_ARRAY:
1265 case GL_NORMAL_ARRAY:
1266 case GL_COLOR_ARRAY:
1267 case GL_POINT_SIZE_ARRAY_OES:
1268 case GL_TEXTURE_COORD_ARRAY:
1271 return error(GL_INVALID_ENUM);
1274 es1::Context *context = es1::getContext();
1278 GLenum texture = context->getClientActiveTexture();
1282 case GL_VERTEX_ARRAY: context->setVertexAttribArrayEnabled(sw::Position, false); break;
1283 case GL_NORMAL_ARRAY: context->setVertexAttribArrayEnabled(sw::Normal, false); break;
1284 case GL_COLOR_ARRAY: context->setVertexAttribArrayEnabled(sw::Color0, false); break;
1285 case GL_POINT_SIZE_ARRAY_OES: context->setVertexAttribArrayEnabled(sw::PointSize, false); break;
1286 case GL_TEXTURE_COORD_ARRAY: context->setVertexAttribArrayEnabled(sw::TexCoord0 + (texture - GL_TEXTURE0), false); break;
1287 default: UNREACHABLE(array);
1292 void DrawArrays(GLenum mode, GLint first, GLsizei count)
1294 TRACE("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
1296 if(count < 0 || first < 0)
1298 return error(GL_INVALID_VALUE);
1301 es1::Context *context = es1::getContext();
1305 context->drawArrays(mode, first, count);
1309 void DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
1311 TRACE("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = %p)",
1312 mode, count, type, indices);
1316 return error(GL_INVALID_VALUE);
1319 es1::Context *context = es1::getContext();
1325 case GL_UNSIGNED_BYTE:
1326 case GL_UNSIGNED_SHORT:
1327 case GL_UNSIGNED_INT:
1330 return error(GL_INVALID_ENUM);
1333 context->drawElements(mode, count, type, indices);
1337 void Enable(GLenum cap)
1339 TRACE("(GLenum cap = 0x%X)", cap);
1341 es1::Context *context = es1::getContext();
1347 case GL_CULL_FACE: context->setCullFaceEnabled(true); break;
1348 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFillEnabled(true); break;
1349 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverageEnabled(true); break;
1350 case GL_SAMPLE_COVERAGE: context->setSampleCoverageEnabled(true); break;
1351 case GL_SCISSOR_TEST: context->setScissorTestEnabled(true); break;
1352 case GL_STENCIL_TEST: context->setStencilTestEnabled(true); break;
1353 case GL_DEPTH_TEST: context->setDepthTestEnabled(true); break;
1354 case GL_BLEND: context->setBlendEnabled(true); break;
1355 case GL_DITHER: context->setDitherEnabled(true); break;
1356 case GL_LIGHTING: context->setLightingEnabled(true); break;
1357 case GL_LIGHT0: context->setLightEnabled(0, true); break;
1358 case GL_LIGHT1: context->setLightEnabled(1, true); break;
1359 case GL_LIGHT2: context->setLightEnabled(2, true); break;
1360 case GL_LIGHT3: context->setLightEnabled(3, true); break;
1361 case GL_LIGHT4: context->setLightEnabled(4, true); break;
1362 case GL_LIGHT5: context->setLightEnabled(5, true); break;
1363 case GL_LIGHT6: context->setLightEnabled(6, true); break;
1364 case GL_LIGHT7: context->setLightEnabled(7, true); break;
1365 case GL_FOG: context->setFogEnabled(true); break;
1366 case GL_TEXTURE_2D: context->setTexture2Denabled(true); break;
1367 case GL_TEXTURE_EXTERNAL_OES: context->setTextureExternalEnabled(true); break;
1368 case GL_ALPHA_TEST: context->setAlphaTestEnabled(true); break;
1369 case GL_COLOR_LOGIC_OP: context->setColorLogicOpEnabled(true); break;
1370 case GL_POINT_SMOOTH: context->setPointSmoothEnabled(true); break;
1371 case GL_LINE_SMOOTH: context->setLineSmoothEnabled(true); break;
1372 case GL_COLOR_MATERIAL: context->setColorMaterialEnabled(true); break;
1373 case GL_NORMALIZE: context->setNormalizeEnabled(true); break;
1374 case GL_RESCALE_NORMAL: context->setRescaleNormalEnabled(true); break;
1375 case GL_VERTEX_ARRAY: context->setVertexArrayEnabled(true); break;
1376 case GL_NORMAL_ARRAY: context->setNormalArrayEnabled(true); break;
1377 case GL_COLOR_ARRAY: context->setColorArrayEnabled(true); break;
1378 case GL_POINT_SIZE_ARRAY_OES: context->setPointSizeArrayEnabled(true); break;
1379 case GL_TEXTURE_COORD_ARRAY: context->setTextureCoordArrayEnabled(true); break;
1380 case GL_MULTISAMPLE: context->setMultisampleEnabled(true); break;
1381 case GL_SAMPLE_ALPHA_TO_ONE: context->setSampleAlphaToOneEnabled(true); break;
1382 case GL_CLIP_PLANE0: context->setClipPlaneEnabled(0, true); break;
1383 case GL_CLIP_PLANE1: context->setClipPlaneEnabled(1, true); break;
1384 case GL_CLIP_PLANE2: context->setClipPlaneEnabled(2, true); break;
1385 case GL_CLIP_PLANE3: context->setClipPlaneEnabled(3, true); break;
1386 case GL_CLIP_PLANE4: context->setClipPlaneEnabled(4, true); break;
1387 case GL_CLIP_PLANE5: context->setClipPlaneEnabled(5, true); break;
1388 case GL_POINT_SPRITE_OES: context->setPointSpriteEnabled(true); break;
1390 return error(GL_INVALID_ENUM);
1395 void EnableClientState(GLenum array)
1397 TRACE("(GLenum array = 0x%X)", array);
1401 case GL_VERTEX_ARRAY:
1402 case GL_NORMAL_ARRAY:
1403 case GL_COLOR_ARRAY:
1404 case GL_POINT_SIZE_ARRAY_OES:
1405 case GL_TEXTURE_COORD_ARRAY:
1408 return error(GL_INVALID_ENUM);
1411 es1::Context *context = es1::getContext();
1415 GLenum texture = context->getClientActiveTexture();
1419 case GL_VERTEX_ARRAY: context->setVertexAttribArrayEnabled(sw::Position, true); break;
1420 case GL_NORMAL_ARRAY: context->setVertexAttribArrayEnabled(sw::Normal, true); break;
1421 case GL_COLOR_ARRAY: context->setVertexAttribArrayEnabled(sw::Color0, true); break;
1422 case GL_POINT_SIZE_ARRAY_OES: context->setVertexAttribArrayEnabled(sw::PointSize, true); break;
1423 case GL_TEXTURE_COORD_ARRAY: context->setVertexAttribArrayEnabled(sw::TexCoord0 + (texture - GL_TEXTURE0), true); break;
1424 default: UNREACHABLE(array);
1433 es1::Context *context = es1::getContext();
1445 es1::Context *context = es1::getContext();
1453 void FramebufferRenderbufferOES(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1455 TRACE("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
1456 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
1458 if(target != GL_FRAMEBUFFER_OES || (renderbuffertarget != GL_RENDERBUFFER_OES && renderbuffer != 0))
1460 return error(GL_INVALID_ENUM);
1463 es1::Context *context = es1::getContext();
1467 es1::Framebuffer *framebuffer = context->getFramebuffer();
1468 GLuint framebufferName = context->getFramebufferName();
1470 if(!framebuffer || (framebufferName == 0 && renderbuffer != 0))
1472 return error(GL_INVALID_OPERATION);
1477 case GL_COLOR_ATTACHMENT0_OES:
1478 framebuffer->setColorbuffer(GL_RENDERBUFFER_OES, renderbuffer);
1480 case GL_DEPTH_ATTACHMENT_OES:
1481 framebuffer->setDepthbuffer(GL_RENDERBUFFER_OES, renderbuffer);
1483 case GL_STENCIL_ATTACHMENT_OES:
1484 framebuffer->setStencilbuffer(GL_RENDERBUFFER_OES, renderbuffer);
1487 return error(GL_INVALID_ENUM);
1492 void FramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1494 TRACE("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
1495 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
1497 if(target != GL_FRAMEBUFFER_OES)
1499 return error(GL_INVALID_ENUM);
1504 case GL_COLOR_ATTACHMENT0_OES:
1505 case GL_DEPTH_ATTACHMENT_OES:
1506 case GL_STENCIL_ATTACHMENT_OES:
1509 return error(GL_INVALID_ENUM);
1512 es1::Context *context = es1::getContext();
1518 textarget = GL_NONE_OES;
1522 es1::Texture *tex = context->getTexture(texture);
1526 return error(GL_INVALID_OPERATION);
1532 if(tex->getTarget() != GL_TEXTURE_2D)
1534 return error(GL_INVALID_OPERATION);
1538 return error(GL_INVALID_ENUM);
1543 return error(GL_INVALID_VALUE);
1546 if(tex->isCompressed(textarget, level))
1548 return error(GL_INVALID_OPERATION);
1552 es1::Framebuffer *framebuffer = context->getFramebuffer();
1553 GLuint framebufferName = context->getFramebufferName();
1555 if(framebufferName == 0 || !framebuffer)
1557 return error(GL_INVALID_OPERATION);
1562 case GL_COLOR_ATTACHMENT0_OES: framebuffer->setColorbuffer(textarget, texture); break;
1563 case GL_DEPTH_ATTACHMENT_OES: framebuffer->setDepthbuffer(textarget, texture); break;
1564 case GL_STENCIL_ATTACHMENT_OES: framebuffer->setStencilbuffer(textarget, texture); break;
1569 void Fogf(GLenum pname, GLfloat param)
1571 TRACE("(GLenum pname = 0x%X, GLfloat param = %f)", pname, param);
1573 es1::Context *context = es1::getContext();
1580 switch((GLenum)param)
1585 context->setFogMode((GLenum)param);
1588 return error(GL_INVALID_ENUM);
1591 case GL_FOG_DENSITY:
1594 return error(GL_INVALID_VALUE);
1596 context->setFogDensity(param);
1599 context->setFogStart(param);
1602 context->setFogEnd(param);
1605 return error(GL_INVALID_ENUM); // Need four values, should call glFogfv() instead
1607 return error(GL_INVALID_ENUM);
1612 void Fogfv(GLenum pname, const GLfloat *params)
1614 TRACE("(GLenum pname = 0x%X, const GLfloat *params)", pname);
1616 es1::Context *context = es1::getContext();
1623 switch((GLenum)params[0])
1628 context->setFogMode((GLenum)params[0]);
1631 return error(GL_INVALID_ENUM);
1634 case GL_FOG_DENSITY:
1637 return error(GL_INVALID_VALUE);
1639 context->setFogDensity(params[0]);
1642 context->setFogStart(params[0]);
1645 context->setFogEnd(params[0]);
1648 context->setFogColor(params[0], params[1], params[2], params[3]);
1651 return error(GL_INVALID_ENUM);
1656 void Fogx(GLenum pname, GLfixed param)
1658 TRACE("(GLenum pname = 0x%X, GLfixed param = %d)", pname, param);
1660 es1::Context *context = es1::getContext();
1667 switch((GLenum)param)
1672 context->setFogMode((GLenum)param);
1675 return error(GL_INVALID_ENUM);
1678 case GL_FOG_DENSITY:
1681 return error(GL_INVALID_VALUE);
1683 context->setFogDensity((float)param / 0x10000);
1686 context->setFogStart((float)param / 0x10000);
1689 context->setFogEnd((float)param / 0x10000);
1692 return error(GL_INVALID_ENUM); // Need four values, should call glFogxv() instead
1694 return error(GL_INVALID_ENUM);
1699 void Fogxv(GLenum pname, const GLfixed *params)
1704 void FrontFace(GLenum mode)
1706 TRACE("(GLenum mode = 0x%X)", mode);
1713 es1::Context *context = es1::getContext();
1717 context->setFrontFace(mode);
1722 return error(GL_INVALID_ENUM);
1726 void Frustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
1728 TRACE("(GLfloat left = %f, GLfloat right = %f, GLfloat bottom = %f, GLfloat top = %f, GLfloat zNear = %f, GLfloat zFar = %f)", left, right, bottom, top, zNear, zFar);
1730 if(zNear <= 0.0f || zFar <= 0.0f || left == right || bottom == top || zNear == zFar)
1732 return error(GL_INVALID_VALUE);
1735 es1::Context *context = es1::getContext();
1739 context->frustum(left, right, bottom, top, zNear, zFar);
1743 void Frustumx(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)
1745 Frustumf((float)left / 0x10000, (float)right / 0x10000, (float)bottom / 0x10000, (float)top / 0x10000, (float)zNear / 0x10000, (float)zFar / 0x10000);
1748 void GenerateMipmapOES(GLenum target)
1750 TRACE("(GLenum target = 0x%X)", target);
1752 es1::Context *context = es1::getContext();
1756 es1::Texture *texture;
1761 texture = context->getTexture2D();
1764 return error(GL_INVALID_ENUM);
1767 if(texture->isCompressed(target, 0) || texture->isDepth(target, 0))
1769 return error(GL_INVALID_OPERATION);
1772 texture->generateMipmaps();
1776 void GenBuffers(GLsizei n, GLuint* buffers)
1778 TRACE("(GLsizei n = %d, GLuint* buffers = %p)", n, buffers);
1782 return error(GL_INVALID_VALUE);
1785 es1::Context *context = es1::getContext();
1789 for(int i = 0; i < n; i++)
1791 buffers[i] = context->createBuffer();
1796 void GenFramebuffersOES(GLsizei n, GLuint* framebuffers)
1798 TRACE("(GLsizei n = %d, GLuint* framebuffers = %p)", n, framebuffers);
1802 return error(GL_INVALID_VALUE);
1805 es1::Context *context = es1::getContext();
1809 for(int i = 0; i < n; i++)
1811 framebuffers[i] = context->createFramebuffer();
1816 void GenRenderbuffersOES(GLsizei n, GLuint* renderbuffers)
1818 TRACE("(GLsizei n = %d, GLuint* renderbuffers = %p)", n, renderbuffers);
1822 return error(GL_INVALID_VALUE);
1825 es1::Context *context = es1::getContext();
1829 for(int i = 0; i < n; i++)
1831 renderbuffers[i] = context->createRenderbuffer();
1836 void GenTextures(GLsizei n, GLuint* textures)
1838 TRACE("(GLsizei n = %d, GLuint* textures = %p)", n, textures);
1842 return error(GL_INVALID_VALUE);
1845 es1::Context *context = es1::getContext();
1849 for(int i = 0; i < n; i++)
1851 textures[i] = context->createTexture();
1856 void GetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint* params)
1858 TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = %p)", target, pname, params);
1860 es1::Context *context = es1::getContext();
1864 if(target != GL_RENDERBUFFER_OES)
1866 return error(GL_INVALID_ENUM);
1869 if(context->getRenderbufferName() == 0)
1871 return error(GL_INVALID_OPERATION);
1874 es1::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferName());
1878 case GL_RENDERBUFFER_WIDTH_OES: *params = renderbuffer->getWidth(); break;
1879 case GL_RENDERBUFFER_HEIGHT_OES: *params = renderbuffer->getHeight(); break;
1880 case GL_RENDERBUFFER_INTERNAL_FORMAT_OES: *params = renderbuffer->getFormat(); break;
1881 case GL_RENDERBUFFER_RED_SIZE_OES: *params = renderbuffer->getRedSize(); break;
1882 case GL_RENDERBUFFER_GREEN_SIZE_OES: *params = renderbuffer->getGreenSize(); break;
1883 case GL_RENDERBUFFER_BLUE_SIZE_OES: *params = renderbuffer->getBlueSize(); break;
1884 case GL_RENDERBUFFER_ALPHA_SIZE_OES: *params = renderbuffer->getAlphaSize(); break;
1885 case GL_RENDERBUFFER_DEPTH_SIZE_OES: *params = renderbuffer->getDepthSize(); break;
1886 case GL_RENDERBUFFER_STENCIL_SIZE_OES: *params = renderbuffer->getStencilSize(); break;
1888 return error(GL_INVALID_ENUM);
1893 void GetBooleanv(GLenum pname, GLboolean* params)
1895 TRACE("(GLenum pname = 0x%X, GLboolean* params = %p)", pname, params);
1897 es1::Context *context = es1::getContext();
1901 if(!(context->getBooleanv(pname, params)))
1903 int numParams = context->getQueryParameterNum(pname);
1907 return error(GL_INVALID_ENUM);
1915 if(context->isQueryParameterFloat(pname))
1917 GLfloat *floatParams = nullptr;
1918 floatParams = new GLfloat[numParams];
1920 context->getFloatv(pname, floatParams);
1922 for(int i = 0; i < numParams; ++i)
1924 if(floatParams[i] == 0.0f)
1925 params[i] = GL_FALSE;
1927 params[i] = GL_TRUE;
1930 delete [] floatParams;
1932 else if(context->isQueryParameterInt(pname))
1934 GLint *intParams = nullptr;
1935 intParams = new GLint[numParams];
1937 context->getIntegerv(pname, intParams);
1939 for(int i = 0; i < numParams; ++i)
1941 if(intParams[i] == 0)
1942 params[i] = GL_FALSE;
1944 params[i] = GL_TRUE;
1947 delete [] intParams;
1949 else UNREACHABLE(pname);
1954 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1956 TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = %p)", target, pname, params);
1958 es1::Context *context = es1::getContext();
1962 es1::Buffer *buffer;
1966 case GL_ARRAY_BUFFER:
1967 buffer = context->getArrayBuffer();
1969 case GL_ELEMENT_ARRAY_BUFFER:
1970 buffer = context->getElementArrayBuffer();
1973 return error(GL_INVALID_ENUM);
1978 // A null buffer means that "0" is bound to the requested buffer target
1979 return error(GL_INVALID_OPERATION);
1984 case GL_BUFFER_USAGE:
1985 *params = buffer->usage();
1987 case GL_BUFFER_SIZE:
1988 *params = (GLint)buffer->size();
1991 return error(GL_INVALID_ENUM);
1996 void GetClipPlanef(GLenum pname, GLfloat eqn[4])
2001 void GetClipPlanex(GLenum pname, GLfixed eqn[4])
2006 GLenum GetError(void)
2010 es1::Context *context = es1::getContext();
2014 return context->getError();
2020 void GetFixedv(GLenum pname, GLfixed *params)
2025 void GetFloatv(GLenum pname, GLfloat* params)
2027 TRACE("(GLenum pname = 0x%X, GLfloat* params = %p)", pname, params);
2029 es1::Context *context = es1::getContext();
2033 if(!(context->getFloatv(pname, params)))
2035 int numParams = context->getQueryParameterNum(pname);
2039 return error(GL_INVALID_ENUM);
2047 if(context->isQueryParameterBool(pname))
2049 GLboolean *boolParams = nullptr;
2050 boolParams = new GLboolean[numParams];
2052 context->getBooleanv(pname, boolParams);
2054 for(int i = 0; i < numParams; ++i)
2056 if(boolParams[i] == GL_FALSE)
2062 delete [] boolParams;
2064 else if(context->isQueryParameterInt(pname))
2066 GLint *intParams = nullptr;
2067 intParams = new GLint[numParams];
2069 context->getIntegerv(pname, intParams);
2071 for(int i = 0; i < numParams; ++i)
2073 params[i] = (GLfloat)intParams[i];
2076 delete [] intParams;
2078 else UNREACHABLE(pname);
2083 void GetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint* params)
2085 TRACE("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum pname = 0x%X, GLint* params = %p)",
2086 target, attachment, pname, params);
2088 es1::Context *context = es1::getContext();
2092 if(target != GL_FRAMEBUFFER_OES)
2094 return error(GL_INVALID_ENUM);
2097 if(context->getFramebufferName() == 0)
2099 return error(GL_INVALID_OPERATION);
2102 es1::Framebuffer *framebuffer = context->getFramebuffer();
2104 GLenum attachmentType;
2105 GLuint attachmentHandle;
2108 case GL_COLOR_ATTACHMENT0_OES:
2109 attachmentType = framebuffer->getColorbufferType();
2110 attachmentHandle = framebuffer->getColorbufferName();
2112 case GL_DEPTH_ATTACHMENT_OES:
2113 attachmentType = framebuffer->getDepthbufferType();
2114 attachmentHandle = framebuffer->getDepthbufferName();
2116 case GL_STENCIL_ATTACHMENT_OES:
2117 attachmentType = framebuffer->getStencilbufferType();
2118 attachmentHandle = framebuffer->getStencilbufferName();
2121 return error(GL_INVALID_ENUM);
2124 GLenum attachmentObjectType; // Type category
2125 if(attachmentType == GL_NONE_OES || attachmentType == GL_RENDERBUFFER_OES)
2127 attachmentObjectType = attachmentType;
2129 else if(es1::IsTextureTarget(attachmentType))
2131 attachmentObjectType = GL_TEXTURE;
2133 else UNREACHABLE(attachmentType);
2137 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES:
2138 *params = attachmentObjectType;
2140 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES:
2141 if(attachmentObjectType == GL_RENDERBUFFER_OES || attachmentObjectType == GL_TEXTURE)
2143 *params = attachmentHandle;
2147 return error(GL_INVALID_ENUM);
2150 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES:
2151 if(attachmentObjectType == GL_TEXTURE)
2153 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
2157 return error(GL_INVALID_ENUM);
2161 return error(GL_INVALID_ENUM);
2166 void GetIntegerv(GLenum pname, GLint* params)
2168 TRACE("(GLenum pname = 0x%X, GLint* params = %p)", pname, params);
2170 es1::Context *context = es1::getContext();
2174 if(!(context->getIntegerv(pname, params)))
2176 int numParams = context->getQueryParameterNum(pname);
2180 return error(GL_INVALID_ENUM);
2188 if(context->isQueryParameterBool(pname))
2190 GLboolean *boolParams = nullptr;
2191 boolParams = new GLboolean[numParams];
2193 context->getBooleanv(pname, boolParams);
2195 for(int i = 0; i < numParams; ++i)
2197 if(boolParams[i] == GL_FALSE)
2203 delete [] boolParams;
2205 else if(context->isQueryParameterFloat(pname))
2207 GLfloat *floatParams = nullptr;
2208 floatParams = new GLfloat[numParams];
2210 context->getFloatv(pname, floatParams);
2212 for(int i = 0; i < numParams; ++i)
2214 if(pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE)
2216 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
2220 params[i] = (GLint)(floatParams[i] > 0.0f ? floor(floatParams[i] + 0.5) : ceil(floatParams[i] - 0.5));
2224 delete [] floatParams;
2226 else UNREACHABLE(pname);
2231 void GetLightfv(GLenum light, GLenum pname, GLfloat *params)
2236 void GetLightxv(GLenum light, GLenum pname, GLfixed *params)
2241 void GetMaterialfv(GLenum face, GLenum pname, GLfloat *params)
2246 void GetMaterialxv(GLenum face, GLenum pname, GLfixed *params)
2251 void GetPointerv(GLenum pname, GLvoid **params)
2253 TRACE("(GLenum pname = 0x%X, GLvoid **params = %p)", pname, params);
2255 es1::Context *context = es1::getContext();
2259 if(!(context->getPointerv(pname, const_cast<const GLvoid**>(params))))
2261 return error(GL_INVALID_ENUM);
2266 const GLubyte* GetString(GLenum name)
2268 TRACE("(GLenum name = 0x%X)", name);
2273 return (GLubyte*)"Google Inc.";
2275 return (GLubyte*)"Google SwiftShader " VERSION_STRING;
2277 return (GLubyte*)"OpenGL ES-CM 1.1";
2279 // Keep list sorted in following order:
2282 // Vendor extensions
2284 "GL_OES_blend_equation_separate "
2285 "GL_OES_blend_func_separate "
2286 "GL_OES_blend_subtract "
2287 "GL_OES_compressed_ETC1_RGB8_texture "
2288 "GL_OES_depth_texture "
2290 "GL_OES_EGL_image_external "
2292 "GL_OES_element_index_uint "
2293 "GL_OES_framebuffer_object "
2294 "GL_OES_packed_depth_stencil "
2295 "GL_OES_read_format "
2296 "GL_OES_rgb8_rgba8 "
2298 "GL_OES_stencil_wrap "
2299 "GL_OES_texture_mirrored_repeat "
2300 "GL_OES_texture_npot "
2301 "GL_EXT_blend_minmax "
2302 "GL_EXT_read_format_bgra "
2304 "GL_EXT_texture_compression_dxt1 "
2305 "GL_ANGLE_texture_compression_dxt3 "
2306 "GL_ANGLE_texture_compression_dxt5 "
2308 "GL_EXT_texture_filter_anisotropic "
2309 "GL_EXT_texture_format_BGRA8888";
2311 return error(GL_INVALID_ENUM, (GLubyte*)nullptr);
2315 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
2317 TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat* params = %p)", target, pname, params);
2319 es1::Context *context = es1::getContext();
2323 es1::Texture *texture;
2328 texture = context->getTexture2D();
2330 case GL_TEXTURE_EXTERNAL_OES:
2331 texture = context->getTextureExternal();
2334 return error(GL_INVALID_ENUM);
2339 case GL_TEXTURE_MAG_FILTER:
2340 *params = (GLfloat)texture->getMagFilter();
2342 case GL_TEXTURE_MIN_FILTER:
2343 *params = (GLfloat)texture->getMinFilter();
2345 case GL_TEXTURE_WRAP_S:
2346 *params = (GLfloat)texture->getWrapS();
2348 case GL_TEXTURE_WRAP_T:
2349 *params = (GLfloat)texture->getWrapT();
2351 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2352 *params = texture->getMaxAnisotropy();
2354 case GL_GENERATE_MIPMAP:
2355 *params = (GLfloat)texture->getGenerateMipmap();
2357 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2358 *params = (GLfloat)1;
2361 return error(GL_INVALID_ENUM);
2366 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
2368 TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = %p)", target, pname, params);
2370 es1::Context *context = es1::getContext();
2374 es1::Texture *texture;
2379 texture = context->getTexture2D();
2381 case GL_TEXTURE_EXTERNAL_OES:
2382 texture = context->getTextureExternal();
2385 return error(GL_INVALID_ENUM);
2390 case GL_TEXTURE_MAG_FILTER:
2391 *params = texture->getMagFilter();
2393 case GL_TEXTURE_MIN_FILTER:
2394 *params = texture->getMinFilter();
2396 case GL_TEXTURE_WRAP_S:
2397 *params = texture->getWrapS();
2399 case GL_TEXTURE_WRAP_T:
2400 *params = texture->getWrapT();
2402 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2403 *params = (GLint)texture->getMaxAnisotropy();
2405 case GL_GENERATE_MIPMAP:
2406 *params = (GLint)texture->getGenerateMipmap();
2408 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2412 return error(GL_INVALID_ENUM);
2417 void GetTexEnvfv(GLenum env, GLenum pname, GLfloat *params)
2422 void GetTexEnviv(GLenum env, GLenum pname, GLint *params)
2427 void GetTexEnvxv(GLenum env, GLenum pname, GLfixed *params)
2432 void GetTexParameterxv(GLenum target, GLenum pname, GLfixed *params)
2437 void Hint(GLenum target, GLenum mode)
2439 TRACE("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
2448 return error(GL_INVALID_ENUM);
2451 es1::Context *context = es1::getContext();
2457 case GL_GENERATE_MIPMAP_HINT:
2458 context->setGenerateMipmapHint(mode);
2460 case GL_PERSPECTIVE_CORRECTION_HINT:
2461 context->setPerspectiveCorrectionHint(mode);
2464 context->setFogHint(mode);
2467 return error(GL_INVALID_ENUM);
2472 GLboolean IsBuffer(GLuint buffer)
2474 TRACE("(GLuint buffer = %d)", buffer);
2476 es1::Context *context = es1::getContext();
2478 if(context && buffer)
2480 es1::Buffer *bufferObject = context->getBuffer(buffer);
2491 GLboolean IsEnabled(GLenum cap)
2493 TRACE("(GLenum cap = 0x%X)", cap);
2495 es1::Context *context = es1::getContext();
2501 case GL_CULL_FACE: return context->isCullFaceEnabled(); break;
2502 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled(); break;
2503 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled(); break;
2504 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled(); break;
2505 case GL_SCISSOR_TEST: return context->isScissorTestEnabled(); break;
2506 case GL_STENCIL_TEST: return context->isStencilTestEnabled(); break;
2507 case GL_DEPTH_TEST: return context->isDepthTestEnabled(); break;
2508 case GL_BLEND: return context->isBlendEnabled(); break;
2509 case GL_DITHER: return context->isDitherEnabled(); break;
2510 case GL_LIGHTING: return context->isLightingEnabled(); break;
2511 case GL_LIGHT0: return context->isLightEnabled(0); break;
2512 case GL_LIGHT1: return context->isLightEnabled(1); break;
2513 case GL_LIGHT2: return context->isLightEnabled(2); break;
2514 case GL_LIGHT3: return context->isLightEnabled(3); break;
2515 case GL_LIGHT4: return context->isLightEnabled(4); break;
2516 case GL_LIGHT5: return context->isLightEnabled(5); break;
2517 case GL_LIGHT6: return context->isLightEnabled(6); break;
2518 case GL_LIGHT7: return context->isLightEnabled(7); break;
2519 case GL_FOG: return context->isFogEnabled(); break;
2520 case GL_TEXTURE_2D: return context->isTexture2Denabled(); break;
2521 case GL_TEXTURE_EXTERNAL_OES: return context->isTextureExternalEnabled(); break;
2522 case GL_ALPHA_TEST: return context->isAlphaTestEnabled(); break;
2523 case GL_COLOR_LOGIC_OP: return context->isColorLogicOpEnabled(); break;
2524 case GL_POINT_SMOOTH: return context->isPointSmoothEnabled(); break;
2525 case GL_LINE_SMOOTH: return context->isLineSmoothEnabled(); break;
2526 case GL_COLOR_MATERIAL: return context->isColorMaterialEnabled(); break;
2527 case GL_NORMALIZE: return context->isNormalizeEnabled(); break;
2528 case GL_RESCALE_NORMAL: return context->isRescaleNormalEnabled(); break;
2529 case GL_VERTEX_ARRAY: return context->isVertexArrayEnabled(); break;
2530 case GL_NORMAL_ARRAY: return context->isNormalArrayEnabled(); break;
2531 case GL_COLOR_ARRAY: return context->isColorArrayEnabled(); break;
2532 case GL_POINT_SIZE_ARRAY_OES: return context->isPointSizeArrayEnabled(); break;
2533 case GL_TEXTURE_COORD_ARRAY: return context->isTextureCoordArrayEnabled(); break;
2534 case GL_MULTISAMPLE: return context->isMultisampleEnabled(); break;
2535 case GL_SAMPLE_ALPHA_TO_ONE: return context->isSampleAlphaToOneEnabled(); break;
2536 case GL_CLIP_PLANE0: return context->isClipPlaneEnabled(0); break;
2537 case GL_CLIP_PLANE1: return context->isClipPlaneEnabled(1); break;
2538 case GL_CLIP_PLANE2: return context->isClipPlaneEnabled(2); break;
2539 case GL_CLIP_PLANE3: return context->isClipPlaneEnabled(3); break;
2540 case GL_CLIP_PLANE4: return context->isClipPlaneEnabled(4); break;
2541 case GL_CLIP_PLANE5: return context->isClipPlaneEnabled(5); break;
2542 case GL_POINT_SPRITE_OES: return context->isPointSpriteEnabled(); break;
2544 return error(GL_INVALID_ENUM, GL_FALSE);
2551 GLboolean IsFramebufferOES(GLuint framebuffer)
2553 TRACE("(GLuint framebuffer = %d)", framebuffer);
2555 es1::Context *context = es1::getContext();
2557 if(context && framebuffer)
2559 es1::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
2561 if(framebufferObject)
2570 GLboolean IsTexture(GLuint texture)
2572 TRACE("(GLuint texture = %d)", texture);
2574 es1::Context *context = es1::getContext();
2576 if(context && texture)
2578 es1::Texture *textureObject = context->getTexture(texture);
2589 GLboolean IsRenderbufferOES(GLuint renderbuffer)
2591 TRACE("(GLuint renderbuffer = %d)", renderbuffer);
2593 es1::Context *context = es1::getContext();
2595 if(context && renderbuffer)
2597 es1::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
2599 if(renderbufferObject)
2608 void LightModelf(GLenum pname, GLfloat param)
2610 TRACE("(GLenum pname = 0x%X, GLfloat param = %f)", pname, param);
2612 es1::Context *context = es1::getContext();
2618 case GL_LIGHT_MODEL_TWO_SIDE:
2619 context->setLightModelTwoSide(param != 0.0f);
2621 case GL_LIGHT_MODEL_AMBIENT:
2622 return error(GL_INVALID_ENUM); // Need four values, should call glLightModelfv() instead
2624 return error(GL_INVALID_ENUM);
2629 void LightModelfv(GLenum pname, const GLfloat *params)
2631 TRACE("(GLenum pname = 0x%X, const GLfloat *params)", pname);
2633 es1::Context *context = es1::getContext();
2639 case GL_LIGHT_MODEL_AMBIENT:
2640 context->setGlobalAmbient(params[0], params[1], params[2], params[3]);
2642 case GL_LIGHT_MODEL_TWO_SIDE:
2643 context->setLightModelTwoSide(params[0] != 0.0f);
2646 return error(GL_INVALID_ENUM);
2651 void LightModelx(GLenum pname, GLfixed param)
2653 TRACE("(GLenum pname = 0x%X, GLfixed param = %d)", pname, param);
2655 es1::Context *context = es1::getContext();
2661 case GL_LIGHT_MODEL_TWO_SIDE:
2662 context->setLightModelTwoSide(param != 0);
2664 case GL_LIGHT_MODEL_AMBIENT:
2665 return error(GL_INVALID_ENUM); // Need four values, should call glLightModelxv() instead
2667 return error(GL_INVALID_ENUM);
2672 void LightModelxv(GLenum pname, const GLfixed *params)
2674 TRACE("(GLenum pname = 0x%X, const GLfixed *params)", pname);
2676 es1::Context *context = es1::getContext();
2682 case GL_LIGHT_MODEL_AMBIENT:
2683 context->setGlobalAmbient((float)params[0] / 0x10000, (float)params[1] / 0x10000, (float)params[2] / 0x10000, (float)params[3] / 0x10000);
2685 case GL_LIGHT_MODEL_TWO_SIDE:
2686 context->setLightModelTwoSide(params[0] != 0);
2689 return error(GL_INVALID_ENUM);
2694 void Lightf(GLenum light, GLenum pname, GLfloat param)
2696 TRACE("(GLenum light = 0x%X, GLenum pname = 0x%X, GLfloat param = %f)", light, pname, param);
2698 int index = light - GL_LIGHT0;
2700 if(index < 0 || index >= es1::MAX_LIGHTS)
2702 return error(GL_INVALID_ENUM);
2705 es1::Context *context = es1::getContext();
2711 case GL_SPOT_EXPONENT:
2712 if(param < 0.0f || param > 128.0f)
2714 return error(GL_INVALID_VALUE);
2716 context->setSpotLightExponent(index, param);
2718 case GL_SPOT_CUTOFF:
2719 if((param < 0.0f || param > 90.0f) && param != 180.0f)
2721 return error(GL_INVALID_VALUE);
2723 context->setSpotLightCutoff(index, param);
2725 case GL_CONSTANT_ATTENUATION:
2728 return error(GL_INVALID_VALUE);
2730 context->setLightAttenuationConstant(index, param);
2732 case GL_LINEAR_ATTENUATION:
2735 return error(GL_INVALID_VALUE);
2737 context->setLightAttenuationLinear(index, param);
2739 case GL_QUADRATIC_ATTENUATION:
2742 return error(GL_INVALID_VALUE);
2744 context->setLightAttenuationQuadratic(index, param);
2750 case GL_SPOT_DIRECTION:
2751 return error(GL_INVALID_ENUM); // Need four values, should call glLightfv() instead
2753 return error(GL_INVALID_ENUM);
2758 void Lightfv(GLenum light, GLenum pname, const GLfloat *params)
2760 TRACE("(GLenum light = 0x%X, GLenum pname = 0x%X, const GLint *params)", light, pname);
2762 es1::Context *context = es1::getContext();
2766 int index = light - GL_LIGHT0;
2768 if(index < 0 || index > es1::MAX_LIGHTS)
2770 return error(GL_INVALID_ENUM);
2775 case GL_AMBIENT: context->setLightAmbient(index, params[0], params[1], params[2], params[3]); break;
2776 case GL_DIFFUSE: context->setLightDiffuse(index, params[0], params[1], params[2], params[3]); break;
2777 case GL_SPECULAR: context->setLightSpecular(index, params[0], params[1], params[2], params[3]); break;
2778 case GL_POSITION: context->setLightPosition(index, params[0], params[1], params[2], params[3]); break;
2779 case GL_SPOT_DIRECTION: context->setLightDirection(index, params[0], params[1], params[2]); break;
2780 case GL_SPOT_EXPONENT:
2781 if(params[0] < 0.0f || params[0] > 128.0f)
2783 return error(GL_INVALID_VALUE);
2785 context->setSpotLightExponent(index, params[0]);
2787 case GL_SPOT_CUTOFF:
2788 if((params[0] < 0.0f || params[0] > 90.0f) && params[0] != 180.0f)
2790 return error(GL_INVALID_VALUE);
2792 context->setSpotLightCutoff(index, params[0]);
2794 case GL_CONSTANT_ATTENUATION:
2795 if(params[0] < 0.0f)
2797 return error(GL_INVALID_VALUE);
2799 context->setLightAttenuationConstant(index, params[0]);
2801 case GL_LINEAR_ATTENUATION:
2802 if(params[0] < 0.0f)
2804 return error(GL_INVALID_VALUE);
2806 context->setLightAttenuationLinear(index, params[0]);
2808 case GL_QUADRATIC_ATTENUATION:
2809 if(params[0] < 0.0f)
2811 return error(GL_INVALID_VALUE);
2813 context->setLightAttenuationQuadratic(index, params[0]);
2816 return error(GL_INVALID_ENUM);
2821 void Lightx(GLenum light, GLenum pname, GLfixed param)
2826 void Lightxv(GLenum light, GLenum pname, const GLfixed *params)
2831 void LineWidth(GLfloat width)
2833 TRACE("(GLfloat width = %f)", width);
2837 return error(GL_INVALID_VALUE);
2840 es1::Context *context = es1::getContext();
2844 context->setLineWidth(width);
2848 void LineWidthx(GLfixed width)
2850 LineWidth((float)width / 0x10000);
2853 void LoadIdentity(void)
2857 es1::Context *context = es1::getContext();
2861 context->loadIdentity();
2865 void LoadMatrixf(const GLfloat *m)
2867 TRACE("(const GLfloat *m)");
2869 es1::Context *context = es1::getContext();
2877 void LoadMatrixx(const GLfixed *m)
2879 GLfloat matrix[16] =
2881 (float)m[0] / 0x10000, (float)m[1] / 0x10000, (float)m[2] / 0x10000, (float)m[3] / 0x10000,
2882 (float)m[4] / 0x10000, (float)m[5] / 0x10000, (float)m[6] / 0x10000, (float)m[7] / 0x10000,
2883 (float)m[8] / 0x10000, (float)m[9] / 0x10000, (float)m[10] / 0x10000, (float)m[11] / 0x10000,
2884 (float)m[12] / 0x10000, (float)m[13] / 0x10000, (float)m[14] / 0x10000, (float)m[15] / 0x10000
2887 LoadMatrixf(matrix);
2890 void LogicOp(GLenum opcode)
2892 TRACE("(GLenum opcode = 0x%X)", opcode);
2899 case GL_COPY_INVERTED:
2908 case GL_AND_REVERSE:
2909 case GL_AND_INVERTED:
2911 case GL_OR_INVERTED:
2914 return error(GL_INVALID_ENUM);
2917 es1::Context *context = es1::getContext();
2921 context->setLogicalOperation(opcode);
2925 void Materialf(GLenum face, GLenum pname, GLfloat param)
2927 TRACE("(GLenum face = 0x%X, GLenum pname = 0x%X, GLfloat param = %f)", face, pname, param);
2929 if(face != GL_FRONT_AND_BACK)
2931 return error(GL_INVALID_ENUM);
2934 es1::Context *context = es1::getContext();
2941 if(param < 0.0f || param > 128.0f)
2943 return error(GL_INVALID_VALUE);
2945 context->setMaterialShininess(param);
2949 case GL_AMBIENT_AND_DIFFUSE:
2952 return error(GL_INVALID_ENUM); // Need four values, should call glMaterialfv() instead
2954 return error(GL_INVALID_ENUM);
2959 void Materialfv(GLenum face, GLenum pname, const GLfloat *params)
2961 TRACE("(GLenum face = 0x%X, GLenum pname = 0x%X, GLfloat params)", face, pname);
2963 if(face != GL_FRONT_AND_BACK)
2965 return error(GL_INVALID_ENUM);
2968 es1::Context *context = es1::getContext();
2975 context->setMaterialAmbient(params[0], params[1], params[2], params[3]);
2978 context->setMaterialDiffuse(params[0], params[1], params[2], params[3]);
2980 case GL_AMBIENT_AND_DIFFUSE:
2981 context->setMaterialAmbient(params[0], params[1], params[2], params[3]);
2982 context->setMaterialDiffuse(params[0], params[1], params[2], params[3]);
2985 context->setMaterialSpecular(params[0], params[1], params[2], params[3]);
2988 context->setMaterialEmission(params[0], params[1], params[2], params[3]);
2991 context->setMaterialShininess(params[0]);
2994 return error(GL_INVALID_ENUM);
2999 void Materialx(GLenum face, GLenum pname, GLfixed param)
3004 void Materialxv(GLenum face, GLenum pname, const GLfixed *params)
3009 void MatrixMode(GLenum mode)
3011 TRACE("(GLenum mode = 0x%X)", mode);
3013 es1::Context *context = es1::getContext();
3017 context->setMatrixMode(mode);
3021 void MultMatrixf(const GLfloat *m)
3023 TRACE("(const GLfloat *m)");
3025 es1::Context *context = es1::getContext();
3029 context->multiply(m);
3033 void MultMatrixx(const GLfixed *m)
3035 GLfloat matrix[16] =
3037 (float)m[0] / 0x10000, (float)m[1] / 0x10000, (float)m[2] / 0x10000, (float)m[3] / 0x10000,
3038 (float)m[4] / 0x10000, (float)m[5] / 0x10000, (float)m[6] / 0x10000, (float)m[7] / 0x10000,
3039 (float)m[8] / 0x10000, (float)m[9] / 0x10000, (float)m[10] / 0x10000, (float)m[11] / 0x10000,
3040 (float)m[12] / 0x10000, (float)m[13] / 0x10000, (float)m[14] / 0x10000, (float)m[15] / 0x10000
3043 MultMatrixf(matrix);
3046 void MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
3048 TRACE("(GLenum target = 0x%X, GLfloat s = %f, GLfloat t = %f, GLfloat r = %f, GLfloat q = %f)", target, s, t, r, q);
3056 return error(GL_INVALID_ENUM);
3059 es1::Context *context = es1::getContext();
3063 context->setVertexAttrib(sw::TexCoord0 + (target - GL_TEXTURE0), s, t, r, q);
3067 void MultiTexCoord4x(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
3072 void Normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
3074 TRACE("(GLfloat nx, GLfloat ny, GLfloat nz)", nx, ny, nz);
3076 es1::Context *context = es1::getContext();
3080 context->setVertexAttrib(sw::Normal, nx, ny, nz, 0);
3084 void Normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
3089 void NormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer)
3091 TRACE("(GLenum type = 0x%X, GLsizei stride = %d, const GLvoid *pointer = %p)", type, stride, pointer);
3093 VertexAttribPointer(sw::Normal, 3, type, true, stride, pointer);
3096 void Orthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
3098 TRACE("(GLfloat left = %f, GLfloat right = %f, GLfloat bottom = %f, GLfloat top = %f, GLfloat zNear = %f, GLfloat zFar = %f)", left, right, bottom, top, zNear, zFar);
3100 if(left == right || bottom == top || zNear == zFar)
3102 return error(GL_INVALID_VALUE);
3105 es1::Context *context = es1::getContext();
3109 context->ortho(left, right, bottom, top, zNear, zFar);
3113 void Orthox(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)
3115 Orthof((float)left / 0x10000, (float)right / 0x10000, (float)bottom / 0x10000, (float)top / 0x10000, (float)zNear / 0x10000, (float)zFar / 0x10000);
3118 void PixelStorei(GLenum pname, GLint param)
3120 TRACE("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
3122 es1::Context *context = es1::getContext();
3128 case GL_UNPACK_ALIGNMENT:
3129 if(param != 1 && param != 2 && param != 4 && param != 8)
3131 return error(GL_INVALID_VALUE);
3134 context->setUnpackAlignment(param);
3136 case GL_PACK_ALIGNMENT:
3137 if(param != 1 && param != 2 && param != 4 && param != 8)
3139 return error(GL_INVALID_VALUE);
3142 context->setPackAlignment(param);
3145 return error(GL_INVALID_ENUM);
3150 void PointParameterf(GLenum pname, GLfloat param)
3152 TRACE("(GLenum pname = 0x%X, GLfloat param = %f)", pname, param);
3154 es1::Context *context = es1::getContext();
3160 case GL_POINT_SIZE_MIN:
3163 return error(GL_INVALID_VALUE);
3165 context->setPointSizeMin(param);
3167 case GL_POINT_SIZE_MAX:
3170 return error(GL_INVALID_VALUE);
3172 context->setPointSizeMax(param);
3174 case GL_POINT_FADE_THRESHOLD_SIZE:
3177 return error(GL_INVALID_VALUE);
3179 context->setPointFadeThresholdSize(param);
3181 case GL_POINT_DISTANCE_ATTENUATION:
3182 return error(GL_INVALID_ENUM); // Needs three values, should call glPointParameterfv() instead
3184 return error(GL_INVALID_ENUM);
3189 void PointParameterfv(GLenum pname, const GLfloat *params)
3191 TRACE("(GLenum pname = 0x%X, const GLfloat *params)", pname);
3193 es1::Context *context = es1::getContext();
3199 case GL_POINT_SIZE_MIN:
3200 if(params[0] < 0.0f)
3202 return error(GL_INVALID_VALUE);
3204 context->setPointSizeMin(params[0]);
3206 case GL_POINT_SIZE_MAX:
3207 if(params[0] < 0.0f)
3209 return error(GL_INVALID_VALUE);
3211 context->setPointSizeMax(params[0]);
3213 case GL_POINT_DISTANCE_ATTENUATION:
3214 context->setPointDistanceAttenuation(params[0], params[1], params[2]);
3216 case GL_POINT_FADE_THRESHOLD_SIZE:
3217 if(params[0] < 0.0f)
3219 return error(GL_INVALID_VALUE);
3221 context->setPointFadeThresholdSize(params[0]);
3224 return error(GL_INVALID_ENUM);
3229 void PointParameterx(GLenum pname, GLfixed param)
3231 TRACE("(GLenum pname = 0x%X, GLfixed param = %d)", pname, param);
3233 es1::Context *context = es1::getContext();
3239 case GL_POINT_SIZE_MIN:
3242 return error(GL_INVALID_VALUE);
3244 context->setPointSizeMin((float)param / 0x10000);
3246 case GL_POINT_SIZE_MAX:
3249 return error(GL_INVALID_VALUE);
3251 context->setPointSizeMax((float)param / 0x10000);
3253 case GL_POINT_FADE_THRESHOLD_SIZE:
3256 return error(GL_INVALID_VALUE);
3258 context->setPointFadeThresholdSize((float)param / 0x10000);
3260 case GL_POINT_DISTANCE_ATTENUATION:
3261 return error(GL_INVALID_ENUM); // Needs three parameters, should call glPointParameterxv() instead
3263 return error(GL_INVALID_ENUM);
3268 void PointParameterxv(GLenum pname, const GLfixed *params)
3270 TRACE("(GLenum pname = 0x%X, const GLfixed *params)", pname);
3272 es1::Context *context = es1::getContext();
3278 case GL_POINT_SIZE_MIN:
3281 return error(GL_INVALID_VALUE);
3283 context->setPointSizeMin((float)params[0] / 0x10000);
3285 case GL_POINT_SIZE_MAX:
3288 return error(GL_INVALID_VALUE);
3290 context->setPointSizeMax((float)params[0] / 0x10000);
3292 case GL_POINT_DISTANCE_ATTENUATION:
3293 context->setPointDistanceAttenuation((float)params[0] / 0x10000, (float)params[1] / 0x10000, (float)params[2] / 0x10000);
3295 case GL_POINT_FADE_THRESHOLD_SIZE:
3298 return error(GL_INVALID_VALUE);
3300 context->setPointFadeThresholdSize((float)params[0] / 0x10000);
3303 return error(GL_INVALID_ENUM);
3308 void PointSize(GLfloat size)
3310 TRACE("(GLfloat size = %f)", size);
3314 return error(GL_INVALID_VALUE);
3317 es1::Context *context = es1::getContext();
3321 context->setVertexAttrib(sw::PointSize, size, size, size, size);
3325 void PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *pointer)
3327 TRACE("(GLenum type = 0x%X, GLsizei stride = %d, const GLvoid *pointer = %p)", type, stride, pointer);
3335 return error(GL_INVALID_ENUM);
3338 VertexAttribPointer(sw::PointSize, 1, type, true, stride, pointer);
3341 void PointSizex(GLfixed size)
3343 PointSize((float)size / 0x10000);
3346 void PolygonOffset(GLfloat factor, GLfloat units)
3348 TRACE("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
3350 es1::Context *context = es1::getContext();
3354 context->setPolygonOffsetParams(factor, units);
3358 void PolygonOffsetx(GLfixed factor, GLfixed units)
3360 PolygonOffset((float)factor / 0x10000, (float)units / 0x10000);
3363 void PopMatrix(void)
3367 es1::Context *context = es1::getContext();
3371 context->popMatrix();
3375 void PushMatrix(void)
3379 es1::Context *context = es1::getContext();
3383 context->pushMatrix();
3387 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels)
3389 TRACE("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3390 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = %p)",
3391 x, y, width, height, format, type, pixels);
3393 if(width < 0 || height < 0)
3395 return error(GL_INVALID_VALUE);
3398 es1::Context *context = es1::getContext();
3402 context->readPixels(x, y, width, height, format, type, nullptr, pixels);
3406 void RenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
3408 TRACE("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
3409 target, internalformat, width, height);
3413 case GL_RENDERBUFFER_OES:
3416 return error(GL_INVALID_ENUM);
3419 if(!es1::IsColorRenderable(internalformat) && !es1::IsDepthRenderable(internalformat) && !es1::IsStencilRenderable(internalformat))
3421 return error(GL_INVALID_ENUM);
3424 if(width < 0 || height < 0)
3426 return error(GL_INVALID_VALUE);
3429 es1::Context *context = es1::getContext();
3433 if(width > es1::IMPLEMENTATION_MAX_RENDERBUFFER_SIZE ||
3434 height > es1::IMPLEMENTATION_MAX_RENDERBUFFER_SIZE)
3436 return error(GL_INVALID_VALUE);
3439 GLuint handle = context->getRenderbufferName();
3442 return error(GL_INVALID_OPERATION);
3445 switch(internalformat)
3447 case GL_DEPTH_COMPONENT16_OES:
3448 context->setRenderbufferStorage(new es1::Depthbuffer(width, height, 0));
3451 case GL_RGB5_A1_OES:
3455 context->setRenderbufferStorage(new es1::Colorbuffer(width, height, internalformat, 0));
3457 case GL_STENCIL_INDEX8_OES:
3458 context->setRenderbufferStorage(new es1::Stencilbuffer(width, height, 0));
3460 case GL_DEPTH24_STENCIL8_OES:
3461 context->setRenderbufferStorage(new es1::DepthStencilbuffer(width, height, 0));
3464 return error(GL_INVALID_ENUM);
3469 void Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
3471 TRACE("(GLfloat angle = %f, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f)", angle, x, y, z);
3473 es1::Context *context = es1::getContext();
3477 context->rotate(angle, x, y, z);
3481 void Rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
3483 Rotatef((float)angle / 0x10000, (float)x / 0x10000, (float)y / 0x10000, (float)z / 0x10000);
3486 void SampleCoverage(GLclampf value, GLboolean invert)
3488 TRACE("(GLclampf value = %f, GLboolean invert = %d)", value, invert);
3490 es1::Context* context = es1::getContext();
3494 context->setSampleCoverageParams(es1::clamp01(value), invert == GL_TRUE);
3498 void SampleCoveragex(GLclampx value, GLboolean invert)
3500 SampleCoverage((float)value / 0x10000, invert);
3503 void Scalef(GLfloat x, GLfloat y, GLfloat z)
3505 TRACE("(GLfloat x = %f, GLfloat y = %f, GLfloat z = %f)", x, y, z);
3507 es1::Context *context = es1::getContext();
3511 context->scale(x, y, z);
3515 void Scalex(GLfixed x, GLfixed y, GLfixed z)
3517 Scalef((float)x / 0x10000, (float)y / 0x10000, (float)z / 0x10000);
3520 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3522 TRACE("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height);
3524 if(width < 0 || height < 0)
3526 return error(GL_INVALID_VALUE);
3529 es1::Context* context = es1::getContext();
3533 context->setScissorParams(x, y, width, height);
3537 void ShadeModel(GLenum mode)
3545 return error(GL_INVALID_ENUM);
3548 es1::Context *context = es1::getContext();
3552 context->setShadeModel(mode);
3556 void StencilFunc(GLenum func, GLint ref, GLuint mask)
3558 TRACE("(GLenum func = 0x%X, GLint ref = %d, GLuint mask = %d)", func, ref, mask);
3572 return error(GL_INVALID_ENUM);
3575 es1::Context *context = es1::getContext();
3579 context->setStencilParams(func, ref, mask);
3583 void StencilMask(GLuint mask)
3585 TRACE("(GLuint mask = %d)", mask);
3587 es1::Context *context = es1::getContext();
3591 context->setStencilWritemask(mask);
3595 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3597 TRACE("(GLenum fail = 0x%X, GLenum zfail = 0x%X, GLenum zpas = 0x%Xs)", fail, zfail, zpass);
3607 case GL_INCR_WRAP_OES:
3608 case GL_DECR_WRAP_OES:
3611 return error(GL_INVALID_ENUM);
3622 case GL_INCR_WRAP_OES:
3623 case GL_DECR_WRAP_OES:
3626 return error(GL_INVALID_ENUM);
3637 case GL_INCR_WRAP_OES:
3638 case GL_DECR_WRAP_OES:
3641 return error(GL_INVALID_ENUM);
3644 es1::Context *context = es1::getContext();
3648 context->setStencilOperations(fail, zfail, zpass);
3652 void TexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
3654 TRACE("(GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid *pointer = %p)", size, type, stride, pointer);
3656 if(size < 2 || size > 4)
3658 return error(GL_INVALID_VALUE);
3661 es1::Context *context = es1::getContext();
3665 GLenum texture = context->getClientActiveTexture();
3666 VertexAttribPointer(sw::TexCoord0 + (texture - GL_TEXTURE0), size, type, false, stride, pointer);
3670 void TexEnvi(GLenum target, GLenum pname, GLint param);
3672 void TexEnvf(GLenum target, GLenum pname, GLfloat param)
3674 TexEnvi(target, pname, (GLint)param);
3677 void TexEnvfv(GLenum target, GLenum pname, const GLfloat *params)
3679 TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, const GLfloat *params)", target, pname);
3681 es1::Context *context = es1::getContext();
3685 GLint iParam = (GLint)roundf(params[0]);
3689 case GL_POINT_SPRITE_OES:
3692 case GL_TEXTURE_ENV:
3695 case GL_TEXTURE_ENV_MODE:
3706 error(GL_INVALID_ENUM);
3709 context->setTextureEnvMode(iParam);
3711 case GL_TEXTURE_ENV_COLOR:
3712 context->setTextureEnvColor(clamp01(params[0]), clamp01(params[1]), clamp01(params[2]), clamp01(params[3]));
3714 case GL_COMBINE_RGB:
3721 case GL_INTERPOLATE:
3727 error(GL_INVALID_ENUM);
3730 context->setCombineRGB(iParam);
3732 case GL_COMBINE_ALPHA:
3739 case GL_INTERPOLATE:
3743 error(GL_INVALID_ENUM);
3746 context->setCombineAlpha(iParam);
3749 if(iParam != 1 && iParam != 2 && iParam != 4)
3751 return error(GL_INVALID_VALUE);
3753 if(iParam != 1) UNIMPLEMENTED();
3755 case GL_ALPHA_SCALE:
3756 if(iParam != 1 && iParam != 2 && iParam != 4)
3758 return error(GL_INVALID_VALUE);
3760 if(iParam != 1) UNIMPLEMENTED();
3762 case GL_OPERAND0_RGB:
3766 case GL_ONE_MINUS_SRC_COLOR:
3768 case GL_ONE_MINUS_SRC_ALPHA:
3771 error(GL_INVALID_ENUM);
3774 context->setOperand0RGB(iParam);
3776 case GL_OPERAND1_RGB:
3780 case GL_ONE_MINUS_SRC_COLOR:
3782 case GL_ONE_MINUS_SRC_ALPHA:
3785 error(GL_INVALID_ENUM);
3788 context->setOperand1RGB(iParam);
3790 case GL_OPERAND2_RGB:
3794 case GL_ONE_MINUS_SRC_COLOR:
3796 case GL_ONE_MINUS_SRC_ALPHA:
3799 error(GL_INVALID_ENUM);
3802 context->setOperand2RGB(iParam);
3804 case GL_OPERAND0_ALPHA:
3808 case GL_ONE_MINUS_SRC_ALPHA:
3811 error(GL_INVALID_ENUM);
3814 context->setOperand0Alpha(iParam);
3816 case GL_OPERAND1_ALPHA:
3820 case GL_ONE_MINUS_SRC_ALPHA:
3823 error(GL_INVALID_ENUM);
3826 context->setOperand1Alpha(iParam);
3828 case GL_OPERAND2_ALPHA:
3832 case GL_ONE_MINUS_SRC_ALPHA:
3835 error(GL_INVALID_ENUM);
3838 context->setOperand2Alpha(iParam);
3845 case GL_PRIMARY_COLOR:
3849 error(GL_INVALID_ENUM);
3852 context->setSrc0RGB(iParam);
3859 case GL_PRIMARY_COLOR:
3863 error(GL_INVALID_ENUM);
3866 context->setSrc1RGB(iParam);
3873 case GL_PRIMARY_COLOR:
3877 error(GL_INVALID_ENUM);
3880 context->setSrc2RGB(iParam);
3887 case GL_PRIMARY_COLOR:
3891 error(GL_INVALID_ENUM);
3894 context->setSrc0Alpha(iParam);
3901 case GL_PRIMARY_COLOR:
3905 error(GL_INVALID_ENUM);
3908 context->setSrc1Alpha(iParam);
3915 case GL_PRIMARY_COLOR:
3919 error(GL_INVALID_ENUM);
3922 context->setSrc2Alpha(iParam);
3925 return error(GL_INVALID_ENUM);
3929 return error(GL_INVALID_ENUM);
3934 void TexEnvi(GLenum target, GLenum pname, GLint param)
3936 TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
3938 es1::Context *context = es1::getContext();
3944 case GL_POINT_SPRITE_OES:
3947 case GL_TEXTURE_ENV:
3950 case GL_TEXTURE_ENV_MODE:
3951 switch((GLenum)param)
3961 error(GL_INVALID_ENUM);
3964 context->setTextureEnvMode((GLenum)param);
3966 case GL_TEXTURE_ENV_COLOR:
3967 return error(GL_INVALID_ENUM); // Needs four values, should call glTexEnviv() instead
3969 case GL_COMBINE_RGB:
3970 switch((GLenum)param)
3976 case GL_INTERPOLATE:
3982 error(GL_INVALID_ENUM);
3985 context->setCombineRGB((GLenum)param);
3987 case GL_COMBINE_ALPHA:
3988 switch((GLenum)param)
3994 case GL_INTERPOLATE:
3998 error(GL_INVALID_ENUM);
4001 context->setCombineAlpha((GLenum)param);
4004 if(param != 1 && param != 2 && param != 4)
4006 return error(GL_INVALID_VALUE);
4008 if(param != 1) UNIMPLEMENTED();
4010 case GL_ALPHA_SCALE:
4011 if(param != 1 && param != 2 && param != 4)
4013 return error(GL_INVALID_VALUE);
4015 if(param != 1) UNIMPLEMENTED();
4017 case GL_OPERAND0_RGB:
4018 switch((GLenum)param)
4021 case GL_ONE_MINUS_SRC_COLOR:
4023 case GL_ONE_MINUS_SRC_ALPHA:
4026 error(GL_INVALID_ENUM);
4029 context->setOperand0RGB((GLenum)param);
4031 case GL_OPERAND1_RGB:
4032 switch((GLenum)param)
4035 case GL_ONE_MINUS_SRC_COLOR:
4037 case GL_ONE_MINUS_SRC_ALPHA:
4040 error(GL_INVALID_ENUM);
4043 context->setOperand1RGB((GLenum)param);
4045 case GL_OPERAND2_RGB:
4046 switch((GLenum)param)
4049 case GL_ONE_MINUS_SRC_COLOR:
4051 case GL_ONE_MINUS_SRC_ALPHA:
4054 error(GL_INVALID_ENUM);
4057 context->setOperand2RGB((GLenum)param);
4059 case GL_OPERAND0_ALPHA:
4060 switch((GLenum)param)
4063 case GL_ONE_MINUS_SRC_ALPHA:
4066 error(GL_INVALID_ENUM);
4069 context->setOperand0Alpha((GLenum)param);
4071 case GL_OPERAND1_ALPHA:
4072 switch((GLenum)param)
4075 case GL_ONE_MINUS_SRC_ALPHA:
4078 error(GL_INVALID_ENUM);
4081 context->setOperand1Alpha((GLenum)param);
4083 case GL_OPERAND2_ALPHA:
4084 switch((GLenum)param)
4087 case GL_ONE_MINUS_SRC_ALPHA:
4090 error(GL_INVALID_ENUM);
4093 context->setOperand2Alpha((GLenum)param);
4096 switch((GLenum)param)
4100 case GL_PRIMARY_COLOR:
4104 error(GL_INVALID_ENUM);
4107 context->setSrc0RGB((GLenum)param);
4110 switch((GLenum)param)
4114 case GL_PRIMARY_COLOR:
4118 error(GL_INVALID_ENUM);
4121 context->setSrc1RGB((GLenum)param);
4124 switch((GLenum)param)
4128 case GL_PRIMARY_COLOR:
4132 error(GL_INVALID_ENUM);
4135 context->setSrc2RGB((GLenum)param);
4138 switch((GLenum)param)
4142 case GL_PRIMARY_COLOR:
4146 error(GL_INVALID_ENUM);
4149 context->setSrc0Alpha((GLenum)param);
4152 switch((GLenum)param)
4156 case GL_PRIMARY_COLOR:
4160 error(GL_INVALID_ENUM);
4163 context->setSrc1Alpha((GLenum)param);
4166 switch((GLenum)param)
4170 case GL_PRIMARY_COLOR:
4174 error(GL_INVALID_ENUM);
4177 context->setSrc2Alpha((GLenum)param);
4180 return error(GL_INVALID_ENUM);
4184 return error(GL_INVALID_ENUM);
4189 void TexEnvx(GLenum target, GLenum pname, GLfixed param)
4191 TexEnvi(target, pname, (GLint)param);
4194 void TexEnviv(GLenum target, GLenum pname, const GLint *params)
4199 void TexEnvxv(GLenum target, GLenum pname, const GLfixed *params)
4204 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
4205 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
4207 TRACE("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
4208 "GLint border = %d, GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = %p)",
4209 target, level, internalformat, width, height, border, format, type, pixels);
4211 if(!validImageSize(level, width, height))
4213 return error(GL_INVALID_VALUE);
4216 if(internalformat != (GLint)format)
4218 return error(GL_INVALID_OPERATION);
4225 case GL_LUMINANCE_ALPHA:
4228 case GL_UNSIGNED_BYTE:
4232 return error(GL_INVALID_ENUM);
4238 case GL_UNSIGNED_BYTE:
4239 case GL_UNSIGNED_SHORT_5_6_5:
4243 return error(GL_INVALID_ENUM);
4249 case GL_UNSIGNED_BYTE:
4250 case GL_UNSIGNED_SHORT_4_4_4_4:
4251 case GL_UNSIGNED_SHORT_5_5_5_1:
4255 return error(GL_INVALID_ENUM);
4261 case GL_UNSIGNED_BYTE:
4264 return error(GL_INVALID_ENUM);
4267 case GL_ETC1_RGB8_OES:
4268 return error(GL_INVALID_OPERATION);
4269 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
4270 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
4273 return error(GL_INVALID_OPERATION);
4277 return error(GL_INVALID_ENUM);
4279 case GL_DEPTH_STENCIL_OES:
4282 case GL_UNSIGNED_INT_24_8_OES:
4285 return error(GL_INVALID_ENUM);
4289 return error(GL_INVALID_VALUE);
4294 return error(GL_INVALID_VALUE);
4297 es1::Context *context = es1::getContext();
4304 if(width > (es1::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level) ||
4305 height > (es1::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level))
4307 return error(GL_INVALID_VALUE);
4311 return error(GL_INVALID_ENUM);
4314 if(target == GL_TEXTURE_2D)
4316 es1::Texture2D *texture = context->getTexture2D();
4320 return error(GL_INVALID_OPERATION);
4323 texture->setImage(context, level, width, height, format, type, context->getUnpackAlignment(), pixels);
4325 else UNREACHABLE(target);
4329 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
4331 TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat param = %f)", target, pname, param);
4333 es1::Context *context = es1::getContext();
4337 es1::Texture *texture;
4342 texture = context->getTexture2D();
4344 case GL_TEXTURE_EXTERNAL_OES:
4345 texture = context->getTextureExternal();
4348 return error(GL_INVALID_ENUM);
4353 case GL_TEXTURE_WRAP_S:
4354 if(!texture->setWrapS((GLenum)param))
4356 return error(GL_INVALID_ENUM);
4359 case GL_TEXTURE_WRAP_T:
4360 if(!texture->setWrapT((GLenum)param))
4362 return error(GL_INVALID_ENUM);
4365 case GL_TEXTURE_MIN_FILTER:
4366 if(!texture->setMinFilter((GLenum)param))
4368 return error(GL_INVALID_ENUM);
4371 case GL_TEXTURE_MAG_FILTER:
4372 if(!texture->setMagFilter((GLenum)param))
4374 return error(GL_INVALID_ENUM);
4377 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
4378 if(!texture->setMaxAnisotropy(param))
4380 return error(GL_INVALID_VALUE);
4383 case GL_GENERATE_MIPMAP:
4384 texture->setGenerateMipmap((GLboolean)param);
4386 case GL_TEXTURE_CROP_RECT_OES:
4387 return error(GL_INVALID_ENUM); // Needs four values, should call glTexParameterfv() instead
4389 return error(GL_INVALID_ENUM);
4394 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
4396 TexParameterf(target, pname, *params);
4399 void TexParameteri(GLenum target, GLenum pname, GLint param)
4401 TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
4403 es1::Context *context = es1::getContext();
4407 es1::Texture *texture;
4412 texture = context->getTexture2D();
4414 case GL_TEXTURE_EXTERNAL_OES:
4415 texture = context->getTextureExternal();
4418 return error(GL_INVALID_ENUM);
4423 case GL_TEXTURE_WRAP_S:
4424 if(!texture->setWrapS((GLenum)param))
4426 return error(GL_INVALID_ENUM);
4429 case GL_TEXTURE_WRAP_T:
4430 if(!texture->setWrapT((GLenum)param))
4432 return error(GL_INVALID_ENUM);
4435 case GL_TEXTURE_MIN_FILTER:
4436 if(!texture->setMinFilter((GLenum)param))
4438 return error(GL_INVALID_ENUM);
4441 case GL_TEXTURE_MAG_FILTER:
4442 if(!texture->setMagFilter((GLenum)param))
4444 return error(GL_INVALID_ENUM);
4447 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
4448 if(!texture->setMaxAnisotropy((GLfloat)param))
4450 return error(GL_INVALID_VALUE);
4453 case GL_GENERATE_MIPMAP:
4454 texture->setGenerateMipmap((GLboolean)param);
4456 case GL_TEXTURE_CROP_RECT_OES:
4457 return error(GL_INVALID_ENUM); // Needs four values, should call glTexParameteriv() instead
4459 return error(GL_INVALID_ENUM);
4464 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
4466 TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %p)", target, pname, params);
4470 case GL_TEXTURE_CROP_RECT_OES:
4473 return TexParameteri(target, pname, params[0]);
4476 es1::Context *context = es1::getContext();
4480 es1::Texture *texture;
4485 texture = context->getTexture2D();
4488 return error(GL_INVALID_ENUM);
4493 case GL_TEXTURE_CROP_RECT_OES:
4494 texture->setCropRect(params[0], params[1], params[2], params[3]);
4497 return error(GL_INVALID_ENUM);
4502 void TexParameterx(GLenum target, GLenum pname, GLfixed param)
4504 TexParameteri(target, pname, (GLint)param);
4507 void TexParameterxv(GLenum target, GLenum pname, const GLfixed *params)
4512 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
4513 GLenum format, GLenum type, const GLvoid* pixels)
4515 TRACE("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
4516 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
4517 "const GLvoid* pixels = %p)",
4518 target, level, xoffset, yoffset, width, height, format, type, pixels);
4520 if(!es1::IsTextureTarget(target))
4522 return error(GL_INVALID_ENUM);
4525 if(level < 0 || level >= es1::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
4527 return error(GL_INVALID_VALUE);
4530 if(xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
4532 return error(GL_INVALID_VALUE);
4535 if(std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
4537 return error(GL_INVALID_VALUE);
4540 if(!es1::CheckTextureFormatType(format, type))
4542 return error(GL_INVALID_ENUM);
4545 if(width == 0 || height == 0 || !pixels)
4550 es1::Context *context = es1::getContext();
4554 if(target == GL_TEXTURE_2D)
4556 es1::Texture2D *texture = context->getTexture2D();
4558 if(validateSubImageParams(false, width, height, xoffset, yoffset, target, level, format, texture))
4560 texture->subImage(context, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
4563 else UNREACHABLE(target);
4567 void Translatef(GLfloat x, GLfloat y, GLfloat z)
4569 TRACE("(GLfloat x = %f, GLfloat y = %f, GLfloat z = %f)", x, y, z);
4571 es1::Context *context = es1::getContext();
4575 context->translate(x, y, z);
4579 void Translatex(GLfixed x, GLfixed y, GLfixed z)
4581 Translatef((float)x / 0x10000, (float)y / 0x10000, (float)z / 0x10000);
4584 void VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
4586 TRACE("(GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid *pointer = %p)", size, type, stride, pointer);
4588 if(size < 2 || size > 4)
4590 return error(GL_INVALID_VALUE);
4593 VertexAttribPointer(sw::Position, size, type, false, stride, pointer);
4596 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4598 TRACE("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height);
4600 if(width < 0 || height < 0)
4602 return error(GL_INVALID_VALUE);
4605 es1::Context *context = es1::getContext();
4609 context->setViewportParams(x, y, width, height);
4613 void EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
4615 TRACE("(GLenum target = 0x%X, GLeglImageOES image = %p)", target, image);
4620 case GL_TEXTURE_EXTERNAL_OES:
4623 return error(GL_INVALID_ENUM);
4626 es1::Context *context = es1::getContext();
4630 es1::Texture2D *texture = nullptr;
4634 case GL_TEXTURE_2D: texture = context->getTexture2D(); break;
4635 case GL_TEXTURE_EXTERNAL_OES: texture = context->getTextureExternal(); break;
4636 default: UNREACHABLE(target);
4641 return error(GL_INVALID_OPERATION);
4644 egl::Image *eglImage = context->getSharedImage(image);
4648 return error(GL_INVALID_OPERATION);
4651 texture->setSharedImage(eglImage);
4655 void EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
4657 TRACE("(GLenum target = 0x%X, GLeglImageOES image = %p)", target, image);
4662 void DrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
4667 void DrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
4669 TRACE("(GLint x = %d, GLint y = %d, GLint z = %d, GLint width = %d, GLint height = %d)", x, y, z, width, height);
4671 if(width <= 0 || height <= 0)
4673 return error(GL_INVALID_VALUE);
4676 es1::Context *context = es1::getContext();
4680 context->drawTexture((GLfloat)x, (GLfloat)y, (GLfloat)z, (GLfloat)width, (GLfloat)height);
4684 void DrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
4689 void DrawTexsvOES(const GLshort *coords)
4694 void DrawTexivOES(const GLint *coords)
4699 void DrawTexxvOES(const GLfixed *coords)
4704 void DrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
4706 TRACE("(GLfloat x = %f, GLfloat y = %f, GLfloat z = %f, GLfloat width = %f, GLfloat height = %f)", x, y, z, width, height);
4708 if(width <= 0 || height <= 0)
4710 return error(GL_INVALID_VALUE);
4713 es1::Context *context = es1::getContext();
4717 context->drawTexture(x, y, z, width, height);
4721 void DrawTexfvOES(const GLfloat *coords)
4728 extern "C" __eglMustCastToProperFunctionPointerType es1GetProcAddress(const char *procname)
4733 __eglMustCastToProperFunctionPointerType address;
4736 static const Extension glExtensions[] =
4738 #define EXTENSION(name) {#name, (__eglMustCastToProperFunctionPointerType)name}
4740 EXTENSION(glEGLImageTargetTexture2DOES),
4741 EXTENSION(glEGLImageTargetRenderbufferStorageOES),
4742 EXTENSION(glIsRenderbufferOES),
4743 EXTENSION(glBindRenderbufferOES),
4744 EXTENSION(glDeleteRenderbuffersOES),
4745 EXTENSION(glGenRenderbuffersOES),
4746 EXTENSION(glRenderbufferStorageOES),
4747 EXTENSION(glGetRenderbufferParameterivOES),
4748 EXTENSION(glIsFramebufferOES),
4749 EXTENSION(glBindFramebufferOES),
4750 EXTENSION(glDeleteFramebuffersOES),
4751 EXTENSION(glGenFramebuffersOES),
4752 EXTENSION(glCheckFramebufferStatusOES),
4753 EXTENSION(glFramebufferRenderbufferOES),
4754 EXTENSION(glFramebufferTexture2DOES),
4755 EXTENSION(glGetFramebufferAttachmentParameterivOES),
4756 EXTENSION(glGenerateMipmapOES),
4757 EXTENSION(glBlendEquationOES),
4758 EXTENSION(glBlendEquationSeparateOES),
4759 EXTENSION(glBlendFuncSeparateOES),
4760 EXTENSION(glPointSizePointerOES),
4765 for(unsigned int ext = 0; ext < sizeof(glExtensions) / sizeof(Extension); ext++)
4767 if(strcmp(procname, glExtensions[ext].name) == 0)
4769 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;