4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
7 * Stanislav Vorobiov <s.vorobiov@samsung.com>
8 * Jinhyung Jo <jinhyung.jo@samsung.com>
9 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
36 #include "yagl_gles_calls.h"
37 #include "yagl_host_gles_calls.h"
38 #include "yagl_impl.h"
39 #include "yagl_malloc.h"
40 #include "yagl_render.h"
41 #include "yagl_utils.h"
42 #include "yagl_sharegroup.h"
43 #include "yagl_state.h"
44 #include "yagl_pixel_format.h"
45 #include "yagl_gles_context.h"
46 #include "yagl_gles_vertex_array.h"
47 #include "yagl_gles_buffer.h"
48 #include "yagl_gles_texture.h"
49 #include "yagl_gles_texture_unit.h"
50 #include "yagl_gles_framebuffer.h"
51 #include "yagl_gles_renderbuffer.h"
52 #include "yagl_gles_image.h"
53 #include "yagl_gles_array.h"
54 #include "yagl_gles_validate.h"
55 #include "yagl_gles_utils.h"
62 #define YAGL_SET_ERR(err) \
63 yagl_gles_context_set_error(ctx, err); \
64 YAGL_LOG_ERROR("error = 0x%X", err)
66 #define YAGL_GET_CTX_IMPL(ret_expr) \
67 struct yagl_gles_context *ctx = \
68 (struct yagl_gles_context*)yagl_get_client_context(); \
70 YAGL_LOG_WARN("no current context"); \
71 YAGL_LOG_FUNC_EXIT(NULL); \
75 #define YAGL_GET_CTX_RET(ret) YAGL_GET_CTX_IMPL(return ret)
77 #define YAGL_GET_CTX() YAGL_GET_CTX_IMPL(return)
79 YAGL_API void glClearStencil(GLint s)
81 YAGL_LOG_FUNC_ENTER_SPLIT1(glClearStencil, GLint, s);
85 ctx->clear_stencil = s;
87 yagl_host_glClearStencil(s);
89 YAGL_LOG_FUNC_EXIT(NULL);
92 YAGL_API void glHint(GLenum target, GLenum mode)
94 YAGL_LOG_FUNC_ENTER_SPLIT2(glHint, GLenum, GLenum, target, mode);
98 if (yagl_gles_is_hint_mode_valid(mode)) {
99 yagl_gles_context_hint(ctx, target, mode);
101 YAGL_SET_ERR(GL_INVALID_ENUM);
104 YAGL_LOG_FUNC_EXIT(NULL);
107 YAGL_API void glLineWidth(GLfloat width)
109 YAGL_LOG_FUNC_ENTER_SPLIT1(glLineWidth, GLfloat, width);
113 yagl_gles_context_line_width(ctx, width);
115 YAGL_LOG_FUNC_EXIT(NULL);
118 YAGL_API void glPolygonOffset(GLfloat factor, GLfloat units)
120 YAGL_LOG_FUNC_ENTER_SPLIT2(glPolygonOffset, GLfloat, GLfloat, factor, units);
124 yagl_gles_context_polygon_offset(ctx, factor, units);
126 YAGL_LOG_FUNC_EXIT(NULL);
129 void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
131 GLenum actual_internalformat = internalformat;
132 struct yagl_gles_renderbuffer *renderbuffer_obj = NULL;
134 YAGL_LOG_FUNC_ENTER_SPLIT4(glRenderbufferStorage, GLenum, GLenum, GLsizei, GLsizei, target, internalformat, width, height);
138 if (!yagl_gles_context_validate_renderbuffer_format(ctx, &actual_internalformat)) {
139 YAGL_SET_ERR(GL_INVALID_ENUM);
143 if (!yagl_gles_context_acquire_binded_renderbuffer(ctx, target, &renderbuffer_obj)) {
144 YAGL_SET_ERR(GL_INVALID_ENUM);
148 if (!renderbuffer_obj) {
152 yagl_gles_renderbuffer_set_internalformat(renderbuffer_obj, internalformat);
154 yagl_host_glRenderbufferStorage(target, actual_internalformat, width, height);
157 yagl_gles_renderbuffer_release(renderbuffer_obj);
159 YAGL_LOG_FUNC_EXIT(NULL);
162 YAGL_API void glSampleCoverage(GLclampf value, GLboolean invert)
164 YAGL_LOG_FUNC_ENTER_SPLIT2(glSampleCoverage, GLclampf, GLboolean, value, invert);
168 yagl_gles_context_sample_coverage(ctx, value, invert);
170 YAGL_LOG_FUNC_EXIT(NULL);
173 YAGL_API void glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
175 YAGL_LOG_FUNC_ENTER_SPLIT4(glScissor, GLint, GLint, GLsizei, GLsizei, x, y, width, height);
179 if ((width < 0) || (height < 0)) {
180 YAGL_SET_ERR(GL_INVALID_VALUE);
184 yagl_render_invalidate(0);
186 ctx->have_scissor_box = 1;
187 ctx->scissor_box[0] = x;
188 ctx->scissor_box[1] = y;
189 ctx->scissor_box[2] = width;
190 ctx->scissor_box[3] = height;
192 yagl_host_glScissor(x, y, width, height);
195 YAGL_LOG_FUNC_EXIT(NULL);
198 YAGL_API void glStencilFunc(GLenum func, GLint ref, GLuint mask)
200 YAGL_LOG_FUNC_ENTER_SPLIT3(glStencilFunc, GLenum, GLint, GLuint, func, ref, mask);
204 if (yagl_gles_is_stencil_func_valid(func)) {
205 ctx->stencil_front.func = func;
206 ctx->stencil_front.ref = ref;
207 ctx->stencil_front.mask = mask;
209 ctx->stencil_back.func = func;
210 ctx->stencil_back.ref = ref;
211 ctx->stencil_back.mask = mask;
213 yagl_host_glStencilFunc(func, ref, mask);
215 YAGL_SET_ERR(GL_INVALID_ENUM);
218 YAGL_LOG_FUNC_EXIT(NULL);
221 YAGL_API void glStencilMask(GLuint mask)
223 YAGL_LOG_FUNC_ENTER_SPLIT1(glStencilMask, GLuint, mask);
227 ctx->stencil_front.writemask = mask;
228 ctx->stencil_back.writemask = mask;
230 yagl_host_glStencilMask(mask);
232 YAGL_LOG_FUNC_EXIT(NULL);
235 YAGL_API void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
237 YAGL_LOG_FUNC_ENTER_SPLIT3(glStencilOp, GLenum, GLenum, GLenum, fail, zfail, zpass);
241 if (yagl_gles_is_stencil_op_valid(fail) &&
242 yagl_gles_is_stencil_op_valid(zfail) &&
243 yagl_gles_is_stencil_op_valid(zpass)) {
244 ctx->stencil_front.fail = fail;
245 ctx->stencil_front.zfail = zfail;
246 ctx->stencil_front.zpass = zpass;
248 ctx->stencil_back.fail = fail;
249 ctx->stencil_back.zfail = zfail;
250 ctx->stencil_back.zpass = zpass;
252 yagl_host_glStencilOp(fail, zfail, zpass);
254 YAGL_SET_ERR(GL_INVALID_ENUM);
257 YAGL_LOG_FUNC_EXIT(NULL);
260 YAGL_API void glTexParameterf(GLenum target, GLenum pname, GLfloat param)
262 YAGL_LOG_FUNC_ENTER_SPLIT3(glTexParameterf, GLenum, GLenum, GLfloat, target, pname, param);
266 yagl_gles_context_tex_parameterf(ctx, target, pname, param);
268 YAGL_LOG_FUNC_EXIT(NULL);
271 YAGL_API void glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
273 YAGL_LOG_FUNC_ENTER_SPLIT3(glTexParameterfv, GLenum, GLenum, const GLfloat*, target, pname, params);
277 yagl_gles_context_tex_parameterfv(ctx, target, pname, params);
279 YAGL_LOG_FUNC_EXIT(NULL);
282 YAGL_API void glTexParameteri(GLenum target, GLenum pname, GLint param)
284 yagl_gles_texture_target texture_target;
285 struct yagl_gles_texture_target_state *tex_target_state;
287 YAGL_LOG_FUNC_ENTER_SPLIT3(glTexParameteri, GLenum, GLenum, GLint, target, pname, param);
291 if (!yagl_gles_context_validate_texture_target(ctx,
294 YAGL_SET_ERR(GL_INVALID_ENUM);
299 yagl_gles_context_get_active_texture_target_state(ctx, texture_target);
301 if (pname == GL_TEXTURE_MIN_FILTER) {
302 tex_target_state->texture->min_filter = param;
303 } else if (pname == GL_TEXTURE_MAG_FILTER) {
304 tex_target_state->texture->mag_filter = param;
307 yagl_host_glTexParameteri(target, pname, param);
310 YAGL_LOG_FUNC_EXIT(NULL);
313 YAGL_API void glTexParameteriv(GLenum target, GLenum pname, const GLint *params)
315 yagl_gles_texture_target texture_target;
316 struct yagl_gles_texture_target_state *tex_target_state;
318 YAGL_LOG_FUNC_ENTER_SPLIT3(glTexParameteriv, GLenum, GLenum, const GLint*, target, pname, params);
322 if (!yagl_gles_context_validate_texture_target(ctx,
325 YAGL_SET_ERR(GL_INVALID_ENUM);
330 yagl_gles_context_get_active_texture_target_state(ctx, texture_target);
332 if (pname == GL_TEXTURE_MIN_FILTER) {
333 tex_target_state->texture->min_filter = params[0];
334 } else if (pname == GL_TEXTURE_MAG_FILTER) {
335 tex_target_state->texture->mag_filter = params[0];
338 yagl_host_glTexParameteriv(target, pname, params, 1);
341 YAGL_LOG_FUNC_EXIT(NULL);
344 YAGL_API void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
346 YAGL_LOG_FUNC_ENTER_SPLIT4(glViewport, GLint, GLint, GLsizei, GLsizei, x, y, width, height);
350 if ((width < 0) || (height < 0)) {
351 YAGL_SET_ERR(GL_INVALID_VALUE);
355 yagl_render_invalidate(0);
357 ctx->have_viewport = 1;
358 ctx->viewport[0] = x;
359 ctx->viewport[1] = y;
360 ctx->viewport[2] = width;
361 ctx->viewport[3] = height;
363 yagl_host_glViewport(x, y, width, height);
366 YAGL_LOG_FUNC_EXIT(NULL);
369 YAGL_API const GLubyte *glGetString(GLenum name)
371 struct yagl_gles_context *ctx;
372 const char *str = NULL;
374 YAGL_LOG_FUNC_ENTER(glGetString, "name = 0x%X", name);
376 ctx = (struct yagl_gles_context*)yagl_get_client_context();
384 str = ctx->extension_string;
391 str = ctx->get_string(ctx, name);
397 YAGL_LOG_FUNC_EXIT("%s", str);
399 return (const GLubyte*)str;
402 YAGL_API void glActiveTexture(GLenum texture)
404 YAGL_LOG_FUNC_ENTER_SPLIT1(glActiveTexture, GLenum, texture);
408 yagl_gles_context_set_active_texture(ctx, texture);
410 YAGL_LOG_FUNC_EXIT(NULL);
413 YAGL_API void glBindBuffer(GLenum target, GLuint buffer)
415 struct yagl_gles_buffer *buffer_obj = NULL;
417 YAGL_LOG_FUNC_ENTER_SPLIT2(glBindBuffer, GLenum, GLuint, target, buffer);
422 buffer_obj = (struct yagl_gles_buffer*)yagl_sharegroup_acquire_object(ctx->base.sg,
423 YAGL_NS_BUFFER, buffer);
426 buffer_obj = yagl_gles_buffer_create();
432 buffer_obj = (struct yagl_gles_buffer*)yagl_sharegroup_add_named(ctx->base.sg,
433 YAGL_NS_BUFFER, buffer, &buffer_obj->base);
437 yagl_gles_context_bind_buffer(ctx, target, buffer_obj);
440 yagl_gles_buffer_release(buffer_obj);
442 YAGL_LOG_FUNC_EXIT(NULL);
445 void glBindFramebuffer(GLenum target, GLuint framebuffer)
447 struct yagl_gles_framebuffer *framebuffer_obj = NULL;
449 YAGL_LOG_FUNC_ENTER_SPLIT2(glBindFramebuffer, GLenum, GLuint, target, framebuffer);
453 if (framebuffer != 0) {
454 framebuffer_obj = (struct yagl_gles_framebuffer*)yagl_namespace_acquire(&ctx->framebuffers,
457 if (!framebuffer_obj) {
458 framebuffer_obj = yagl_gles_framebuffer_create();
460 if (!framebuffer_obj) {
464 framebuffer_obj = (struct yagl_gles_framebuffer*)yagl_namespace_add_named(&ctx->framebuffers,
465 framebuffer, &framebuffer_obj->base);
469 yagl_gles_context_bind_framebuffer(ctx, target, framebuffer_obj);
472 yagl_gles_framebuffer_release(framebuffer_obj);
474 YAGL_LOG_FUNC_EXIT(NULL);
477 void glBindRenderbuffer(GLenum target, GLuint renderbuffer)
479 struct yagl_gles_renderbuffer *renderbuffer_obj = NULL;
481 YAGL_LOG_FUNC_ENTER_SPLIT2(glBindRenderbuffer, GLenum, GLuint, target, renderbuffer);
485 if (renderbuffer != 0) {
486 renderbuffer_obj = (struct yagl_gles_renderbuffer*)yagl_sharegroup_acquire_object(ctx->base.sg,
487 YAGL_NS_RENDERBUFFER, renderbuffer);
489 if (!renderbuffer_obj) {
490 renderbuffer_obj = yagl_gles_renderbuffer_create();
492 if (!renderbuffer_obj) {
496 renderbuffer_obj = (struct yagl_gles_renderbuffer*)yagl_sharegroup_add_named(ctx->base.sg,
497 YAGL_NS_RENDERBUFFER, renderbuffer, &renderbuffer_obj->base);
501 yagl_gles_context_bind_renderbuffer(ctx, target, renderbuffer_obj);
504 yagl_gles_renderbuffer_release(renderbuffer_obj);
506 YAGL_LOG_FUNC_EXIT(NULL);
509 YAGL_API void glBindTexture(GLenum target, GLuint texture)
511 struct yagl_gles_texture *texture_obj = NULL;
512 yagl_gles_texture_target texture_target;
514 YAGL_LOG_FUNC_ENTER_SPLIT2(glBindTexture, GLenum, GLuint, target, texture);
518 if (!yagl_gles_context_validate_texture_target(ctx, target, &texture_target)) {
519 YAGL_SET_ERR(GL_INVALID_ENUM);
524 texture_obj = (struct yagl_gles_texture*)yagl_sharegroup_acquire_object(ctx->base.sg,
525 YAGL_NS_TEXTURE, texture);
528 texture_obj = yagl_gles_texture_create();
534 texture_obj = (struct yagl_gles_texture*)yagl_sharegroup_add_named(ctx->base.sg,
535 YAGL_NS_TEXTURE, texture, &texture_obj->base);
539 yagl_gles_context_bind_texture(ctx, target, texture_obj);
542 yagl_gles_texture_release(texture_obj);
544 YAGL_LOG_FUNC_EXIT(NULL);
547 void glBlendEquation(GLenum mode)
549 YAGL_LOG_FUNC_ENTER_SPLIT1(glBlendEquation, GLenum, mode);
553 if (yagl_gles_is_blend_equation_valid(mode)) {
554 ctx->blend_equation_rgb = mode;
555 ctx->blend_equation_alpha = mode;
557 yagl_host_glBlendEquation(mode);
559 YAGL_SET_ERR(GL_INVALID_ENUM);
562 YAGL_LOG_FUNC_EXIT(NULL);
565 void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
567 YAGL_LOG_FUNC_ENTER_SPLIT2(glBlendEquationSeparate, GLenum, GLenum, modeRGB, modeAlpha);
571 if (yagl_gles_is_blend_equation_valid(modeRGB) &&
572 yagl_gles_is_blend_equation_valid(modeAlpha)) {
573 ctx->blend_equation_rgb = modeRGB;
574 ctx->blend_equation_alpha = modeAlpha;
576 yagl_host_glBlendEquationSeparate(modeRGB, modeAlpha);
578 YAGL_SET_ERR(GL_INVALID_ENUM);
581 YAGL_LOG_FUNC_EXIT(NULL);
584 YAGL_API void glBlendFunc(GLenum sfactor, GLenum dfactor)
586 YAGL_LOG_FUNC_ENTER_SPLIT2(glBlendFunc, GLenum, GLenum, sfactor, dfactor);
590 if (yagl_gles_is_blend_func_valid(sfactor) &&
591 yagl_gles_is_blend_func_valid(dfactor)) {
592 ctx->blend_src_rgb = sfactor;
593 ctx->blend_src_alpha = sfactor;
595 ctx->blend_dst_rgb = dfactor;
596 ctx->blend_dst_alpha = dfactor;
598 yagl_host_glBlendFunc(sfactor, dfactor);
600 YAGL_SET_ERR(GL_INVALID_ENUM);
603 YAGL_LOG_FUNC_EXIT(NULL);
606 void glBlendFuncSeparate(GLenum srcRGB,
611 YAGL_LOG_FUNC_ENTER_SPLIT4(glBlendFuncSeparate, GLenum, GLenum, GLenum, GLenum, srcRGB, dstRGB, srcAlpha, dstAlpha);
615 if (yagl_gles_is_blend_func_valid(srcRGB) &&
616 yagl_gles_is_blend_func_valid(dstRGB) &&
617 yagl_gles_is_blend_func_valid(srcAlpha) &&
618 yagl_gles_is_blend_func_valid(dstAlpha)) {
619 ctx->blend_src_rgb = srcRGB;
620 ctx->blend_src_alpha = srcAlpha;
622 ctx->blend_dst_rgb = dstRGB;
623 ctx->blend_dst_alpha = dstAlpha;
625 yagl_host_glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
627 YAGL_SET_ERR(GL_INVALID_ENUM);
630 YAGL_LOG_FUNC_EXIT(NULL);
633 YAGL_API void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)
635 struct yagl_gles_buffer *buffer_obj = NULL;
637 YAGL_LOG_FUNC_ENTER_SPLIT4(glBufferData, GLenum, GLsizeiptr, const GLvoid*, GLenum, target, size, data, usage);
642 YAGL_SET_ERR(GL_INVALID_VALUE);
646 if (!yagl_gles_is_buffer_usage_valid(usage)) {
647 YAGL_SET_ERR(GL_INVALID_ENUM);
651 if (!yagl_gles_context_acquire_binded_buffer(ctx, target, &buffer_obj)) {
652 YAGL_SET_ERR(GL_INVALID_ENUM);
657 YAGL_SET_ERR(GL_INVALID_OPERATION);
661 yagl_gles_buffer_set_data(buffer_obj, size, data, usage);
664 yagl_gles_buffer_release(buffer_obj);
666 YAGL_LOG_FUNC_EXIT(NULL);
669 YAGL_API void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data)
671 struct yagl_gles_buffer *buffer_obj = NULL;
673 YAGL_LOG_FUNC_ENTER_SPLIT4(glBufferSubData, GLenum, GLintptr, GLsizeiptr, const GLvoid*, target, offset, size, data);
677 if ((offset < 0) || (size < 0)) {
678 YAGL_SET_ERR(GL_INVALID_VALUE);
682 if (!yagl_gles_context_acquire_binded_buffer(ctx, target, &buffer_obj)) {
683 YAGL_SET_ERR(GL_INVALID_ENUM);
688 YAGL_SET_ERR(GL_INVALID_OPERATION);
696 if (!yagl_gles_buffer_update_data(buffer_obj, offset, size, data)) {
697 YAGL_SET_ERR(GL_INVALID_VALUE);
702 yagl_gles_buffer_release(buffer_obj);
704 YAGL_LOG_FUNC_EXIT(NULL);
707 GLenum glCheckFramebufferStatus(GLenum target)
710 struct yagl_gles_framebuffer *framebuffer_obj = NULL;
712 YAGL_LOG_FUNC_ENTER_SPLIT1(glCheckFramebufferStatus, GLenum, target);
716 if (!yagl_gles_context_acquire_binded_framebuffer(ctx, target, &framebuffer_obj)) {
717 YAGL_SET_ERR(GL_INVALID_ENUM);
721 res = yagl_gles_context_check_framebuffer_status(ctx, framebuffer_obj);
724 yagl_gles_framebuffer_release(framebuffer_obj);
726 YAGL_LOG_FUNC_EXIT_SPLIT(GLenum, res);
731 YAGL_API void glClear(GLbitfield mask)
733 YAGL_LOG_FUNC_ENTER_SPLIT1(glClear, GLbitfield, mask);
737 yagl_render_invalidate((mask & GL_COLOR_BUFFER_BIT));
739 yagl_host_glClear(mask);
741 YAGL_LOG_FUNC_EXIT(NULL);
744 YAGL_API void glClearColor(GLclampf red,
749 YAGL_LOG_FUNC_ENTER_SPLIT4(glClearColor, GLclampf, GLclampf, GLclampf, GLclampf, red, green, blue, alpha);
753 yagl_gles_context_clear_color(ctx,
759 YAGL_LOG_FUNC_EXIT(NULL);
762 YAGL_API void glClearDepthf(GLclampf depth)
764 YAGL_LOG_FUNC_ENTER_SPLIT1(glClearDepthf, GLclampf, depth);
768 yagl_gles_context_clear_depthf(ctx, depth);
770 YAGL_LOG_FUNC_EXIT(NULL);
773 YAGL_API void glColorMask(GLboolean red,
778 YAGL_LOG_FUNC_ENTER_SPLIT4(glColorMask, GLboolean, GLboolean, GLboolean, GLboolean, red, green, blue, alpha);
782 ctx->color_writemask[0] = red;
783 ctx->color_writemask[1] = green;
784 ctx->color_writemask[2] = blue;
785 ctx->color_writemask[3] = alpha;
787 yagl_host_glColorMask(red, green, blue, alpha);
789 YAGL_LOG_FUNC_EXIT(NULL);
792 YAGL_API void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data)
794 GLenum squashed_target;
795 yagl_gles_texture_target texture_target;
796 struct yagl_gles_texture_target_state *tex_target_state;
799 YAGL_LOG_FUNC_ENTER_SPLIT8(glCompressedTexImage2D, GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*, target, level, internalformat, width, height, border, imageSize, data);
803 if ((width < 0) || (height < 0)) {
804 YAGL_SET_ERR(GL_INVALID_VALUE);
808 if (!yagl_gles_validate_texture_target_squash(target, &squashed_target)) {
809 YAGL_SET_ERR(GL_INVALID_ENUM);
813 if (!yagl_gles_context_validate_texture_target(ctx,
816 YAGL_SET_ERR(GL_INVALID_ENUM);
821 yagl_gles_context_get_active_texture_target_state(ctx, texture_target);
823 if ((width == 0) || (height == 0)) {
827 if ((width != 0) && !yagl_gles_context_pre_unpack(ctx, &data, 1, &using_pbo)) {
828 YAGL_SET_ERR(GL_INVALID_OPERATION);
834 if (target == GL_TEXTURE_2D) {
835 if (tex_target_state->texture != tex_target_state->texture_zero) {
837 * This operation should orphan EGLImage according
838 * to OES_EGL_image specs.
840 * This operation should release TexImage according
841 * to eglBindTexImage spec.
843 yagl_gles_texture_unset_image(tex_target_state->texture);
847 ctx->compressed_tex_image_2d(ctx,
849 tex_target_state->texture,
859 yagl_gles_context_post_unpack(ctx, 1);
863 YAGL_LOG_FUNC_EXIT(NULL);
866 YAGL_API void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data)
870 YAGL_LOG_FUNC_ENTER_SPLIT9(glCompressedTexSubImage2D, GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid*, target, level, xoffset, yoffset, width, height, format, imageSize, data);
874 if ((width < 0) || (height < 0)) {
875 YAGL_SET_ERR(GL_INVALID_VALUE);
879 if ((width == 0) || (height == 0)) {
883 if ((width != 0) && !yagl_gles_context_pre_unpack(ctx, &data, 1, &using_pbo)) {
884 YAGL_SET_ERR(GL_INVALID_OPERATION);
890 ctx->compressed_tex_sub_image_2d(ctx,
902 yagl_gles_context_post_unpack(ctx, 1);
906 YAGL_LOG_FUNC_EXIT(NULL);
909 YAGL_API void glCopyTexImage2D(GLenum target,
911 GLenum internalformat,
918 GLenum actual_internalformat = internalformat;
919 GLenum squashed_target;
920 yagl_gles_texture_target texture_target;
921 struct yagl_gles_texture_target_state *tex_target_state;
924 YAGL_LOG_FUNC_ENTER_SPLIT8(glCopyTexImage2D, GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint, target, level, internalformat, x, y, width, height, border);
929 YAGL_SET_ERR(GL_INVALID_VALUE);
933 if (!yagl_gles_validate_texture_target_squash(target, &squashed_target)) {
934 YAGL_SET_ERR(GL_INVALID_ENUM);
938 if (!yagl_gles_context_validate_texture_target(ctx,
941 YAGL_SET_ERR(GL_INVALID_ENUM);
946 yagl_gles_context_get_active_texture_target_state(ctx, texture_target);
948 if (!yagl_gles_context_validate_copyteximage_format(ctx,
949 &actual_internalformat,
951 YAGL_SET_ERR(GL_INVALID_OPERATION);
955 yagl_host_glCopyTexImage2D(target,
957 actual_internalformat,
964 yagl_gles_texture_set_internalformat(tex_target_state->texture,
966 (is_float ? GL_FLOAT : 0),
967 yagl_gles_context_convert_textures(ctx));
970 YAGL_LOG_FUNC_EXIT(NULL);
973 YAGL_API void glCopyTexSubImage2D(GLenum target,
982 YAGL_LOG_FUNC_ENTER_SPLIT8(glCopyTexSubImage2D, GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei, target, level, xoffset, yoffset, x, y, width, height);
986 if ((ctx->base.client_api == yagl_client_api_gles1) &&
987 (target != GL_TEXTURE_2D)) {
988 YAGL_SET_ERR(GL_INVALID_ENUM);
992 yagl_host_glCopyTexSubImage2D(target,
1002 YAGL_LOG_FUNC_EXIT(NULL);
1005 YAGL_API void glCullFace(GLenum mode)
1007 YAGL_LOG_FUNC_ENTER_SPLIT1(glCullFace, GLenum, mode);
1011 if (yagl_gles_is_cull_face_mode_valid(mode)) {
1012 ctx->cull_face_mode = mode;
1014 yagl_host_glCullFace(mode);
1016 YAGL_SET_ERR(GL_INVALID_ENUM);
1019 YAGL_LOG_FUNC_EXIT(NULL);
1022 YAGL_API void glDeleteBuffers(GLsizei n, const GLuint *buffers)
1026 YAGL_LOG_FUNC_ENTER_SPLIT2(glDeleteBuffers, GLsizei, const GLuint*, n, buffers);
1031 YAGL_SET_ERR(GL_INVALID_VALUE);
1036 for (i = 0; i < n; ++i) {
1037 yagl_gles_context_unbind_buffer(ctx, buffers[i]);
1039 yagl_sharegroup_remove(ctx->base.sg,
1046 YAGL_LOG_FUNC_EXIT(NULL);
1049 void glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
1053 YAGL_LOG_FUNC_ENTER_SPLIT2(glDeleteFramebuffers, GLsizei, const GLuint*, n, framebuffers);
1058 YAGL_SET_ERR(GL_INVALID_VALUE);
1063 for (i = 0; i < n; ++i) {
1064 yagl_gles_context_unbind_framebuffer(ctx, framebuffers[i]);
1066 yagl_namespace_remove(&ctx->framebuffers,
1072 YAGL_LOG_FUNC_EXIT(NULL);
1075 void glDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
1079 YAGL_LOG_FUNC_ENTER_SPLIT2(glDeleteRenderbuffers, GLsizei, const GLuint*, n, renderbuffers);
1084 YAGL_SET_ERR(GL_INVALID_VALUE);
1088 if (renderbuffers) {
1089 for (i = 0; i < n; ++i) {
1090 yagl_gles_context_unbind_renderbuffer(ctx, renderbuffers[i]);
1092 yagl_sharegroup_remove(ctx->base.sg,
1093 YAGL_NS_RENDERBUFFER,
1099 YAGL_LOG_FUNC_EXIT(NULL);
1102 YAGL_API void glDeleteTextures(GLsizei n, const GLuint *textures)
1106 YAGL_LOG_FUNC_ENTER_SPLIT2(glDeleteTextures, GLsizei, const GLuint*, n, textures);
1111 YAGL_SET_ERR(GL_INVALID_VALUE);
1116 for (i = 0; i < n; ++i) {
1117 yagl_gles_context_unbind_texture(ctx, textures[i]);
1119 yagl_sharegroup_remove(ctx->base.sg,
1127 YAGL_LOG_FUNC_EXIT(NULL);
1130 YAGL_API void glDepthFunc(GLenum func)
1132 YAGL_LOG_FUNC_ENTER_SPLIT1(glDepthFunc, GLenum, func);
1136 if (yagl_gles_is_depth_func_valid(func)) {
1137 ctx->depth_func = func;
1139 yagl_host_glDepthFunc(func);
1141 YAGL_SET_ERR(GL_INVALID_ENUM);
1144 YAGL_LOG_FUNC_EXIT(NULL);
1147 YAGL_API void glDepthMask(GLboolean flag)
1149 YAGL_LOG_FUNC_ENTER_SPLIT1(glDepthMask, GLboolean, flag);
1153 ctx->depth_writemask = flag;
1155 yagl_host_glDepthMask(flag);
1157 YAGL_LOG_FUNC_EXIT(NULL);
1160 YAGL_API void glDepthRangef(GLclampf zNear, GLclampf zFar)
1162 YAGL_LOG_FUNC_ENTER_SPLIT2(glDepthRangef, GLclampf, GLclampf, zNear, zFar);
1166 yagl_gles_context_depth_rangef(ctx, zNear, zFar);
1168 YAGL_LOG_FUNC_EXIT(NULL);
1171 YAGL_API void glDisable(GLenum cap)
1173 YAGL_LOG_FUNC_ENTER_SPLIT1(glDisable, GLenum, cap);
1177 yagl_gles_context_enable(ctx, cap, GL_FALSE);
1179 YAGL_LOG_FUNC_EXIT(NULL);
1182 YAGL_API void glDrawArrays(GLenum mode, GLint first, GLsizei count)
1184 YAGL_LOG_FUNC_ENTER_SPLIT3(glDrawArrays, GLenum, GLint, GLsizei, mode, first, count);
1188 yagl_gles_context_draw_arrays(ctx, mode, first, count, -1);
1190 YAGL_LOG_FUNC_EXIT(NULL);
1193 YAGL_API void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
1195 YAGL_LOG_FUNC_ENTER_SPLIT4(glDrawElements, GLenum, GLsizei, GLenum, const GLvoid*, mode, count, type, indices);
1199 yagl_gles_context_draw_elements(ctx, mode, count, type, indices, -1);
1201 YAGL_LOG_FUNC_EXIT(NULL);
1204 YAGL_API void glEnable(GLenum cap)
1206 YAGL_LOG_FUNC_ENTER_SPLIT1(glEnable, GLenum, cap);
1210 yagl_gles_context_enable(ctx, cap, GL_TRUE);
1212 YAGL_LOG_FUNC_EXIT(NULL);
1215 YAGL_API void glFinish()
1217 YAGL_LOG_FUNC_ENTER_SPLIT0(glFinish);
1219 yagl_render_finish();
1221 YAGL_LOG_FUNC_EXIT(NULL);
1224 YAGL_IMPLEMENT_API_NORET0(glFlush)
1226 void glFramebufferRenderbuffer(GLenum target,
1228 GLenum renderbuffertarget,
1229 GLuint renderbuffer)
1231 struct yagl_gles_framebuffer *framebuffer_obj = NULL;
1232 struct yagl_gles_renderbuffer *renderbuffer_obj = NULL;
1233 yagl_gles_framebuffer_attachment framebuffer_attachment;
1235 YAGL_LOG_FUNC_ENTER_SPLIT4(glFramebufferRenderbuffer, GLenum, GLenum, GLenum, GLuint, target, attachment, renderbuffertarget, renderbuffer);
1239 if (!yagl_gles_context_acquire_binded_framebuffer(ctx, target, &framebuffer_obj)) {
1240 YAGL_SET_ERR(GL_INVALID_ENUM);
1244 if (!framebuffer_obj) {
1245 YAGL_SET_ERR(GL_INVALID_OPERATION);
1250 renderbuffer_obj = (struct yagl_gles_renderbuffer*)yagl_sharegroup_acquire_object(ctx->base.sg,
1251 YAGL_NS_RENDERBUFFER, renderbuffer);
1253 if (!renderbuffer_obj) {
1254 YAGL_SET_ERR(GL_INVALID_OPERATION);
1259 if (renderbuffer_obj && (renderbuffertarget != GL_RENDERBUFFER)) {
1260 YAGL_SET_ERR(GL_INVALID_ENUM);
1264 if ((ctx->base.client_api == yagl_client_api_gles3) &&
1265 (attachment == GL_DEPTH_STENCIL_ATTACHMENT)) {
1266 yagl_gles_framebuffer_renderbuffer(framebuffer_obj,
1267 target, GL_DEPTH_ATTACHMENT,
1268 yagl_gles_framebuffer_attachment_depth,
1271 yagl_gles_framebuffer_renderbuffer(framebuffer_obj,
1272 target, GL_STENCIL_ATTACHMENT,
1273 yagl_gles_framebuffer_attachment_stencil,
1277 if (!yagl_gles_validate_framebuffer_attachment(attachment,
1278 ctx->max_color_attachments,
1279 &framebuffer_attachment)) {
1280 YAGL_SET_ERR(GL_INVALID_ENUM);
1284 yagl_gles_framebuffer_renderbuffer(framebuffer_obj,
1286 framebuffer_attachment,
1292 yagl_gles_renderbuffer_release(renderbuffer_obj);
1293 yagl_gles_framebuffer_release(framebuffer_obj);
1295 YAGL_LOG_FUNC_EXIT(NULL);
1298 void glFramebufferTexture2D(GLenum target,
1304 struct yagl_gles_framebuffer *framebuffer_obj = NULL;
1305 struct yagl_gles_texture *texture_obj = NULL;
1306 yagl_gles_framebuffer_attachment framebuffer_attachment;
1307 GLenum squashed_textarget;
1309 YAGL_LOG_FUNC_ENTER_SPLIT5(glFramebufferTexture2D, GLenum, GLenum, GLenum, GLuint, GLint, target, attachment, textarget, texture, level);
1313 if (!yagl_gles_context_acquire_binded_framebuffer(ctx, target, &framebuffer_obj)) {
1314 YAGL_SET_ERR(GL_INVALID_ENUM);
1318 if (!framebuffer_obj) {
1319 YAGL_SET_ERR(GL_INVALID_OPERATION);
1324 texture_obj = (struct yagl_gles_texture*)yagl_sharegroup_acquire_object(ctx->base.sg,
1325 YAGL_NS_TEXTURE, texture);
1328 YAGL_SET_ERR(GL_INVALID_OPERATION);
1333 if (texture_obj && (level != 0)) {
1334 YAGL_SET_ERR(GL_INVALID_ENUM);
1338 if (!yagl_gles_validate_texture_target_squash(textarget,
1339 &squashed_textarget)) {
1340 YAGL_SET_ERR(GL_INVALID_ENUM);
1344 if (texture_obj && (texture_obj->target != squashed_textarget)) {
1345 YAGL_SET_ERR(GL_INVALID_ENUM);
1349 if ((ctx->base.client_api == yagl_client_api_gles3) &&
1350 (attachment == GL_DEPTH_STENCIL_ATTACHMENT)) {
1351 yagl_gles_framebuffer_texture2d(framebuffer_obj,
1352 target, GL_DEPTH_ATTACHMENT,
1353 yagl_gles_framebuffer_attachment_depth,
1357 yagl_gles_framebuffer_texture2d(framebuffer_obj,
1358 target, GL_STENCIL_ATTACHMENT,
1359 yagl_gles_framebuffer_attachment_stencil,
1364 if (!yagl_gles_validate_framebuffer_attachment(attachment,
1365 ctx->max_color_attachments,
1366 &framebuffer_attachment)) {
1367 YAGL_SET_ERR(GL_INVALID_ENUM);
1371 yagl_gles_framebuffer_texture2d(framebuffer_obj,
1373 framebuffer_attachment,
1380 yagl_gles_texture_release(texture_obj);
1381 yagl_gles_framebuffer_release(framebuffer_obj);
1383 YAGL_LOG_FUNC_EXIT(NULL);
1386 YAGL_API void glFrontFace(GLenum mode)
1388 YAGL_LOG_FUNC_ENTER_SPLIT1(glFrontFace, GLenum, mode);
1392 if (yagl_gles_is_front_face_mode_valid(mode)) {
1393 ctx->front_face_mode = mode;
1395 yagl_host_glFrontFace(mode);
1397 YAGL_SET_ERR(GL_INVALID_ENUM);
1400 YAGL_LOG_FUNC_EXIT(NULL);
1403 YAGL_API void glGenBuffers(GLsizei n, GLuint *buffer_names)
1405 struct yagl_gles_buffer **buffers = NULL;
1408 YAGL_LOG_FUNC_ENTER_SPLIT2(glGenBuffers, GLsizei, GLuint*, n, buffer_names);
1413 YAGL_SET_ERR(GL_INVALID_VALUE);
1417 buffers = yagl_malloc0(n * sizeof(*buffers));
1419 for (i = 0; i < n; ++i) {
1420 buffers[i] = yagl_gles_buffer_create();
1427 for (i = 0; i < n; ++i) {
1428 yagl_sharegroup_add(ctx->base.sg,
1433 buffer_names[i] = buffers[i]->base.local_name;
1438 for (i = 0; i < n; ++i) {
1439 yagl_gles_buffer_release(buffers[i]);
1443 YAGL_LOG_FUNC_EXIT(NULL);
1446 void glGenerateMipmap(GLenum target)
1448 YAGL_LOG_FUNC_ENTER_SPLIT1(glGenerateMipmap, GLenum, target);
1452 yagl_host_glGenerateMipmap(target);
1454 YAGL_LOG_FUNC_EXIT(NULL);
1457 void glGenFramebuffers(GLsizei n, GLuint *framebuffer_names)
1459 struct yagl_gles_framebuffer **framebuffers = NULL;
1462 YAGL_LOG_FUNC_ENTER_SPLIT2(glGenFramebuffers, GLsizei, GLuint*, n, framebuffer_names);
1467 YAGL_SET_ERR(GL_INVALID_VALUE);
1471 framebuffers = yagl_malloc0(n * sizeof(*framebuffers));
1473 for (i = 0; i < n; ++i) {
1474 framebuffers[i] = yagl_gles_framebuffer_create();
1476 if (!framebuffers[i]) {
1481 for (i = 0; i < n; ++i) {
1482 yagl_namespace_add(&ctx->framebuffers,
1483 &framebuffers[i]->base);
1485 if (framebuffer_names) {
1486 framebuffer_names[i] = framebuffers[i]->base.local_name;
1491 for (i = 0; i < n; ++i) {
1492 yagl_gles_framebuffer_release(framebuffers[i]);
1494 yagl_free(framebuffers);
1496 YAGL_LOG_FUNC_EXIT(NULL);
1499 void glGenRenderbuffers(GLsizei n, GLuint *renderbuffer_names)
1501 struct yagl_gles_renderbuffer **renderbuffers = NULL;
1504 YAGL_LOG_FUNC_ENTER_SPLIT2(glGenRenderbuffers, GLsizei, GLuint*, n, renderbuffer_names);
1509 YAGL_SET_ERR(GL_INVALID_VALUE);
1513 renderbuffers = yagl_malloc0(n * sizeof(*renderbuffers));
1515 for (i = 0; i < n; ++i) {
1516 renderbuffers[i] = yagl_gles_renderbuffer_create();
1518 if (!renderbuffers[i]) {
1523 for (i = 0; i < n; ++i) {
1524 yagl_sharegroup_add(ctx->base.sg,
1525 YAGL_NS_RENDERBUFFER,
1526 &renderbuffers[i]->base);
1528 if (renderbuffer_names) {
1529 renderbuffer_names[i] = renderbuffers[i]->base.local_name;
1534 for (i = 0; i < n; ++i) {
1535 yagl_gles_renderbuffer_release(renderbuffers[i]);
1537 yagl_free(renderbuffers);
1539 YAGL_LOG_FUNC_EXIT(NULL);
1542 YAGL_API void glGenTextures(GLsizei n, GLuint *texture_names)
1544 struct yagl_gles_texture **textures = NULL;
1547 YAGL_LOG_FUNC_ENTER_SPLIT2(glGenTextures, GLsizei, GLuint*, n, texture_names);
1552 YAGL_SET_ERR(GL_INVALID_VALUE);
1556 textures = yagl_malloc0(n * sizeof(*textures));
1558 for (i = 0; i < n; ++i) {
1559 textures[i] = yagl_gles_texture_create();
1566 for (i = 0; i < n; ++i) {
1567 yagl_sharegroup_add(ctx->base.sg,
1569 &textures[i]->base);
1571 if (texture_names) {
1572 texture_names[i] = textures[i]->base.local_name;
1577 for (i = 0; i < n; ++i) {
1578 yagl_gles_texture_release(textures[i]);
1580 yagl_free(textures);
1582 YAGL_LOG_FUNC_EXIT(NULL);
1585 YAGL_API void glGetBooleanv(GLenum pname, GLboolean *params)
1587 GLint ints[100]; // This fits all cases.
1588 uint32_t i, num = 0;
1591 YAGL_LOG_FUNC_ENTER_SPLIT2(glGetBooleanv, GLenum, GLboolean*, pname, params);
1595 if (yagl_gles_context_get_integerv(ctx, pname, ints, &num)) {
1596 for (i = 0; i < num; ++i) {
1597 params[i] = ints[i] ? GL_TRUE : GL_FALSE;
1600 GLfloat floats[100]; // This fits all cases.
1601 if (yagl_gles_context_get_floatv(ctx, pname, floats, &num, &needs_map)) {
1602 for (i = 0; i < num; ++i) {
1603 params[i] = (floats[i] == 0.0f) ? GL_FALSE : GL_TRUE;
1606 YAGL_SET_ERR(GL_INVALID_ENUM);
1610 YAGL_LOG_FUNC_EXIT(NULL);
1613 YAGL_API void glGetBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1615 struct yagl_gles_buffer *buffer_obj = NULL;
1617 YAGL_LOG_FUNC_ENTER_SPLIT3(glGetBufferParameteriv, GLenum, GLenum, GLint*, target, pname, params);
1621 if (!yagl_gles_context_acquire_binded_buffer(ctx, target, &buffer_obj)) {
1622 YAGL_SET_ERR(GL_INVALID_ENUM);
1627 YAGL_SET_ERR(GL_INVALID_OPERATION);
1631 if (!yagl_gles_buffer_get_parameter(buffer_obj,
1634 YAGL_SET_ERR(GL_INVALID_ENUM);
1639 yagl_gles_buffer_release(buffer_obj);
1641 YAGL_LOG_FUNC_EXIT(NULL);
1644 YAGL_API GLenum glGetError(void)
1648 YAGL_LOG_FUNC_ENTER_SPLIT0(glGetError);
1650 YAGL_GET_CTX_RET(GL_NO_ERROR);
1652 ret = yagl_gles_context_get_error(ctx);
1654 YAGL_LOG_FUNC_EXIT_SPLIT(GLenum, ret);
1659 YAGL_API void glGetFloatv(GLenum pname, GLfloat *params)
1661 uint32_t i, num = 0;
1664 YAGL_LOG_FUNC_ENTER_SPLIT2(glGetFloatv, GLenum, GLfloat*, pname, params);
1668 if (!yagl_gles_context_get_floatv(ctx, pname, params, &num, &needs_map)) {
1669 GLint ints[100]; // This fits all cases.
1670 if (yagl_gles_context_get_integerv(ctx, pname, ints, &num)) {
1671 for (i = 0; i < num; ++i) {
1672 params[i] = ints[i];
1675 YAGL_SET_ERR(GL_INVALID_ENUM);
1679 YAGL_LOG_FUNC_EXIT(NULL);
1682 void glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint *params)
1684 struct yagl_gles_framebuffer *framebuffer_obj = NULL;
1685 yagl_gles_framebuffer_attachment framebuffer_attachment;
1687 YAGL_LOG_FUNC_ENTER_SPLIT4(glGetFramebufferAttachmentParameteriv, GLenum, GLenum, GLenum, GLint*, target, attachment, pname, params);
1691 if (!yagl_gles_context_acquire_binded_framebuffer(ctx, target, &framebuffer_obj)) {
1692 YAGL_SET_ERR(GL_INVALID_ENUM);
1696 if (!framebuffer_obj) {
1698 * Default framebuffer, special handling.
1701 switch (attachment) {
1707 YAGL_SET_ERR(GL_INVALID_OPERATION);
1712 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
1713 *params = GL_FRAMEBUFFER_DEFAULT;
1715 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
1718 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1719 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1720 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1721 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1722 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1723 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1724 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
1730 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
1731 *params = GL_LINEAR;
1734 YAGL_SET_ERR(GL_INVALID_ENUM);
1741 if ((ctx->base.client_api == yagl_client_api_gles3) &&
1742 (attachment == GL_DEPTH_STENCIL_ATTACHMENT)) {
1743 if (memcmp(&framebuffer_obj->attachment_states[yagl_gles_framebuffer_attachment_depth],
1744 &framebuffer_obj->attachment_states[yagl_gles_framebuffer_attachment_stencil],
1745 sizeof(struct yagl_gles_framebuffer_attachment_state)) != 0) {
1746 YAGL_SET_ERR(GL_INVALID_OPERATION);
1749 framebuffer_attachment = yagl_gles_framebuffer_attachment_depth;
1750 } else if (!yagl_gles_validate_framebuffer_attachment(attachment,
1751 ctx->max_color_attachments,
1752 &framebuffer_attachment)) {
1753 YAGL_SET_ERR(GL_INVALID_ENUM);
1758 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
1759 *params = framebuffer_obj->attachment_states[framebuffer_attachment].type;
1761 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
1762 *params = framebuffer_obj->attachment_states[framebuffer_attachment].local_name;
1764 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
1765 if (framebuffer_obj->attachment_states[framebuffer_attachment].type == GL_TEXTURE) {
1768 YAGL_SET_ERR(GL_INVALID_ENUM);
1771 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
1772 if (framebuffer_obj->attachment_states[framebuffer_attachment].type == GL_TEXTURE) {
1774 (framebuffer_obj->attachment_states[framebuffer_attachment].textarget == GL_TEXTURE_2D)
1775 ? 0 : framebuffer_obj->attachment_states[framebuffer_attachment].textarget;
1777 YAGL_SET_ERR(GL_INVALID_ENUM);
1780 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
1781 if (framebuffer_obj->attachment_states[framebuffer_attachment].type == GL_TEXTURE) {
1782 *params = framebuffer_obj->attachment_states[framebuffer_attachment].layer;
1784 YAGL_SET_ERR(GL_INVALID_ENUM);
1788 if (framebuffer_obj->attachment_states[framebuffer_attachment].type != GL_NONE) {
1789 GLenum internalformat = 0;
1790 const struct yagl_gles_format_info *format_info;
1792 yagl_gles_framebuffer_attachment_internalformat(
1793 &framebuffer_obj->attachment_states[framebuffer_attachment],
1796 format_info = yagl_gles_internalformat_info(internalformat);
1799 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1800 *params = format_info->red_size;
1802 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1803 *params = format_info->green_size;
1805 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1806 *params = format_info->blue_size;
1808 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1809 *params = format_info->alpha_size;
1811 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1812 *params = format_info->depth_size;
1814 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1815 *params = format_info->stencil_size;
1817 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
1818 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
1819 YAGL_SET_ERR(GL_INVALID_OPERATION);
1827 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
1828 *params = ((format_info->flags & yagl_gles_format_srgb) != 0) ?
1829 GL_SRGB : GL_LINEAR;
1832 YAGL_SET_ERR(GL_INVALID_ENUM);
1836 YAGL_SET_ERR(GL_INVALID_ENUM);
1842 yagl_gles_framebuffer_release(framebuffer_obj);
1844 YAGL_LOG_FUNC_EXIT(NULL);
1847 YAGL_API void glGetIntegerv(GLenum pname, GLint *params)
1849 uint32_t i, num = 0;
1852 YAGL_LOG_FUNC_ENTER_SPLIT2(glGetIntegerv, GLenum, GLint*, pname, params);
1856 if (!yagl_gles_context_get_integerv(ctx, pname, params, &num)) {
1857 GLfloat floats[100]; // This fits all cases.
1858 if (yagl_gles_context_get_floatv(ctx, pname, floats, &num, &needs_map)) {
1859 for (i = 0; i < num; ++i) {
1861 params[i] = 2147483647.0 * floats[i];
1863 params[i] = floats[i];
1867 YAGL_SET_ERR(GL_INVALID_ENUM);
1871 YAGL_LOG_FUNC_EXIT(NULL);
1874 void glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1876 YAGL_LOG_FUNC_ENTER_SPLIT3(glGetRenderbufferParameteriv, GLenum, GLenum, GLint*, target, pname, params);
1881 * TODO: Passthrough for now.
1884 yagl_host_glGetRenderbufferParameteriv(target, pname, params);
1886 YAGL_LOG_FUNC_EXIT(NULL);
1889 YAGL_API void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1891 YAGL_LOG_FUNC_ENTER_SPLIT3(glGetTexParameterfv, GLenum, GLenum, GLfloat*, target, pname, params);
1895 if (!yagl_gles_context_get_tex_parameterfv(ctx, target, pname, params)) {
1896 YAGL_SET_ERR(GL_INVALID_ENUM);
1899 YAGL_LOG_FUNC_EXIT(NULL);
1902 YAGL_API void glGetTexParameteriv(GLenum target, GLenum pname, GLint *params)
1904 YAGL_LOG_FUNC_ENTER_SPLIT3(glGetTexParameteriv, GLenum, GLenum, GLint*, target, pname, params);
1908 if (!yagl_gles_context_get_tex_parameteriv(ctx, target, pname, params)) {
1909 YAGL_SET_ERR(GL_INVALID_ENUM);
1912 YAGL_LOG_FUNC_EXIT(NULL);
1915 YAGL_API GLboolean glIsBuffer(GLuint buffer)
1917 GLboolean res = GL_FALSE;
1918 struct yagl_gles_buffer *buffer_obj = NULL;
1920 YAGL_LOG_FUNC_ENTER_SPLIT1(glIsBuffer, GLuint, buffer);
1922 YAGL_GET_CTX_RET(GL_FALSE);
1924 buffer_obj = (struct yagl_gles_buffer*)yagl_sharegroup_acquire_object(ctx->base.sg,
1925 YAGL_NS_BUFFER, buffer);
1927 if (buffer_obj && yagl_gles_buffer_was_bound(buffer_obj)) {
1931 yagl_gles_buffer_release(buffer_obj);
1933 YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, res);
1938 YAGL_API GLboolean glIsEnabled(GLenum cap)
1942 YAGL_LOG_FUNC_ENTER_SPLIT1(glIsEnabled, GLenum, cap);
1944 YAGL_GET_CTX_RET(GL_FALSE);
1946 res = yagl_gles_context_is_enabled(ctx, cap);
1948 YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, res);
1953 GLboolean glIsFramebuffer(GLuint framebuffer)
1955 GLboolean res = GL_FALSE;
1956 struct yagl_gles_framebuffer *framebuffer_obj = NULL;
1958 YAGL_LOG_FUNC_ENTER_SPLIT1(glIsFramebuffer, GLuint, framebuffer);
1960 YAGL_GET_CTX_RET(GL_FALSE);
1962 framebuffer_obj = (struct yagl_gles_framebuffer*)yagl_namespace_acquire(&ctx->framebuffers,
1965 if (framebuffer_obj && yagl_gles_framebuffer_was_bound(framebuffer_obj)) {
1969 yagl_gles_framebuffer_release(framebuffer_obj);
1971 YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, res);
1976 GLboolean glIsRenderbuffer(GLuint renderbuffer)
1978 GLboolean res = GL_FALSE;
1979 struct yagl_gles_renderbuffer *renderbuffer_obj = NULL;
1981 YAGL_LOG_FUNC_ENTER_SPLIT1(glIsRenderbuffer, GLuint, renderbuffer);
1983 YAGL_GET_CTX_RET(GL_FALSE);
1985 renderbuffer_obj = (struct yagl_gles_renderbuffer*)yagl_sharegroup_acquire_object(ctx->base.sg,
1986 YAGL_NS_RENDERBUFFER, renderbuffer);
1988 if (renderbuffer_obj && yagl_gles_renderbuffer_was_bound(renderbuffer_obj)) {
1992 yagl_gles_renderbuffer_release(renderbuffer_obj);
1994 YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, res);
1999 YAGL_API GLboolean glIsTexture(GLuint texture)
2001 GLboolean res = GL_FALSE;
2002 struct yagl_gles_texture *texture_obj = NULL;
2004 YAGL_LOG_FUNC_ENTER_SPLIT1(glIsTexture, GLuint, texture);
2006 YAGL_GET_CTX_RET(GL_FALSE);
2008 texture_obj = (struct yagl_gles_texture*)yagl_sharegroup_acquire_object(ctx->base.sg,
2009 YAGL_NS_TEXTURE, texture);
2011 if (texture_obj && (texture_obj->target != 0)) {
2015 yagl_gles_texture_release(texture_obj);
2017 YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, res);
2022 YAGL_API void glPixelStorei(GLenum pname, GLint param)
2024 YAGL_LOG_FUNC_ENTER_SPLIT2(glPixelStorei, GLenum, GLint, pname, param);
2029 * We don't pass GL_XXX_SKIP_YYY to host, this
2030 * is intentionally so that we can pass less data later in glTexImage*
2031 * and glReadPixels, i.e. we process skips ourselves and feed biased
2036 case GL_PACK_ALIGNMENT:
2037 if (yagl_gles_is_alignment_valid(param)) {
2038 ctx->pack.alignment = param;
2040 YAGL_SET_ERR(GL_INVALID_VALUE);
2044 case GL_PACK_ROW_LENGTH:
2046 ctx->pack.row_length = param;
2048 YAGL_SET_ERR(GL_INVALID_VALUE);
2052 case GL_PACK_IMAGE_HEIGHT:
2054 ctx->pack.image_height = param;
2056 YAGL_SET_ERR(GL_INVALID_VALUE);
2060 case GL_PACK_SKIP_PIXELS:
2062 ctx->pack.skip_pixels = param;
2064 YAGL_SET_ERR(GL_INVALID_VALUE);
2068 case GL_PACK_SKIP_ROWS:
2070 ctx->pack.skip_rows = param;
2072 YAGL_SET_ERR(GL_INVALID_VALUE);
2076 case GL_PACK_SKIP_IMAGES:
2078 ctx->pack.skip_images = param;
2080 YAGL_SET_ERR(GL_INVALID_VALUE);
2084 case GL_UNPACK_ALIGNMENT:
2085 if (yagl_gles_is_alignment_valid(param)) {
2086 ctx->unpack.alignment = param;
2088 YAGL_SET_ERR(GL_INVALID_VALUE);
2092 case GL_UNPACK_ROW_LENGTH:
2094 ctx->unpack.row_length = param;
2096 YAGL_SET_ERR(GL_INVALID_VALUE);
2100 case GL_UNPACK_IMAGE_HEIGHT:
2102 ctx->unpack.image_height = param;
2104 YAGL_SET_ERR(GL_INVALID_VALUE);
2108 case GL_UNPACK_SKIP_PIXELS:
2110 ctx->unpack.skip_pixels = param;
2112 YAGL_SET_ERR(GL_INVALID_VALUE);
2116 case GL_UNPACK_SKIP_ROWS:
2118 ctx->unpack.skip_rows = param;
2120 YAGL_SET_ERR(GL_INVALID_VALUE);
2124 case GL_UNPACK_SKIP_IMAGES:
2126 ctx->unpack.skip_images = param;
2128 YAGL_SET_ERR(GL_INVALID_VALUE);
2133 YAGL_SET_ERR(GL_INVALID_ENUM);
2137 yagl_host_glPixelStorei(pname, param);
2140 YAGL_LOG_FUNC_EXIT(NULL);
2143 YAGL_API void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)
2145 struct yagl_pixel_format *pf;
2149 YAGL_LOG_FUNC_ENTER_SPLIT7(glReadPixels, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*, x, y, width, height, format, type, pixels);
2153 if ((width < 0) || (height < 0)) {
2154 YAGL_SET_ERR(GL_INVALID_VALUE);
2158 if ((width == 0) || (height == 0)) {
2162 pf = yagl_gles_context_validate_getteximage_format(ctx, format, type);
2165 YAGL_SET_ERR(GL_INVALID_OPERATION);
2169 yagl_render_invalidate(0);
2171 if ((width != 0) && !yagl_gles_context_pre_pack(ctx, &pixels, pf->need_convert, &using_pbo)) {
2172 YAGL_SET_ERR(GL_INVALID_OPERATION);
2176 pixels += yagl_pixel_format_get_info(pf, &ctx->pack,
2177 width, height, 1, &size);
2180 yagl_host_glReadPixelsOffset(x, y,
2186 GLvoid *pixels_from;
2188 pixels_from = yagl_pixel_format_pack_alloc(pf, &ctx->pack,
2193 yagl_host_glReadPixelsData(x, y,
2201 yagl_pixel_format_pack(pf, &ctx->pack,
2209 yagl_gles_context_post_pack(ctx, pixels, size, pf->need_convert);
2213 YAGL_LOG_FUNC_EXIT(NULL);
2216 YAGL_API void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
2218 GLenum squashed_target;
2219 yagl_gles_texture_target texture_target;
2220 struct yagl_gles_texture_target_state *tex_target_state;
2221 struct yagl_pixel_format *pf;
2225 YAGL_LOG_FUNC_ENTER_SPLIT9(glTexImage2D, GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid*, target, level, internalformat, width, height, border, format, type, pixels);
2229 if ((width < 0) || (height < 0)) {
2230 YAGL_SET_ERR(GL_INVALID_VALUE);
2234 if (!yagl_gles_validate_texture_target_squash(target, &squashed_target)) {
2235 YAGL_SET_ERR(GL_INVALID_ENUM);
2239 if (!yagl_gles_context_validate_texture_target(ctx,
2242 YAGL_SET_ERR(GL_INVALID_ENUM);
2246 if (squashed_target == GL_TEXTURE_CUBE_MAP && width != height) {
2247 YAGL_SET_ERR(GL_INVALID_VALUE);
2252 yagl_gles_context_get_active_texture_target_state(ctx, texture_target);
2254 if ((width == 0) || (height == 0)) {
2258 pf = yagl_gles_context_validate_teximage_format(ctx, internalformat, format, type);
2261 YAGL_SET_ERR(GL_INVALID_OPERATION);
2265 if ((width != 0) && !yagl_gles_context_pre_unpack(ctx, &pixels, pf->need_convert, &using_pbo)) {
2266 YAGL_SET_ERR(GL_INVALID_OPERATION);
2270 if (target == GL_TEXTURE_2D) {
2271 if (tex_target_state->texture != tex_target_state->texture_zero) {
2273 * This operation should orphan EGLImage according
2274 * to OES_EGL_image specs.
2276 * This operation should release TexImage according
2277 * to eglBindTexImage spec.
2279 yagl_gles_texture_unset_image(tex_target_state->texture);
2283 if (pixels || using_pbo) {
2284 pixels += yagl_pixel_format_get_info(pf, &ctx->unpack,
2285 width, height, 1, &size);
2287 yagl_pixel_format_get_info(pf, &ctx->unpack,
2288 width, height, 1, &size);
2292 yagl_host_glTexImage2DOffset(target,
2294 pf->dst_internalformat,
2302 yagl_host_glTexImage2DData(target,
2304 pf->dst_internalformat,
2310 yagl_pixel_format_unpack(pf, &ctx->unpack,
2319 yagl_gles_context_post_unpack(ctx, pf->need_convert);
2322 yagl_gles_texture_set_internalformat(tex_target_state->texture,
2325 yagl_gles_context_convert_textures(ctx));
2328 YAGL_LOG_FUNC_EXIT(NULL);
2331 YAGL_API void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
2333 GLenum squashed_target;
2334 yagl_gles_texture_target texture_target;
2335 struct yagl_gles_texture_target_state *tex_target_state;
2336 struct yagl_pixel_format *pf;
2340 YAGL_LOG_FUNC_ENTER_SPLIT9(glTexSubImage2D, GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid*, target, level, xoffset, yoffset, width, height, format, type, pixels);
2344 if ((width < 0) || (height < 0)) {
2345 YAGL_SET_ERR(GL_INVALID_VALUE);
2349 if (!yagl_gles_validate_texture_target_squash(target, &squashed_target)) {
2350 YAGL_SET_ERR(GL_INVALID_ENUM);
2354 if (!yagl_gles_context_validate_texture_target(ctx,
2357 YAGL_SET_ERR(GL_INVALID_ENUM);
2362 yagl_gles_context_get_active_texture_target_state(ctx, texture_target);
2364 if ((width == 0) || (height == 0)) {
2368 pf = yagl_gles_context_validate_teximage_format(ctx,
2369 tex_target_state->texture->internalformat, format, type);
2372 YAGL_SET_ERR(GL_INVALID_OPERATION);
2376 if ((width != 0) && !yagl_gles_context_pre_unpack(ctx, &pixels, pf->need_convert, &using_pbo)) {
2377 YAGL_SET_ERR(GL_INVALID_OPERATION);
2381 pixels += yagl_pixel_format_get_info(pf, &ctx->unpack,
2382 width, height, 1, &size);
2385 yagl_host_glTexSubImage2DOffset(target,
2395 yagl_host_glTexSubImage2DData(target,
2403 yagl_pixel_format_unpack(pf, &ctx->unpack,
2412 yagl_gles_context_post_unpack(ctx, pf->need_convert);
2416 YAGL_LOG_FUNC_EXIT(NULL);
2419 YAGL_API void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
2421 struct yagl_gles_image *image_obj = NULL;
2422 struct yagl_gles_texture_target_state *tex_target_state;
2424 YAGL_LOG_FUNC_ENTER_SPLIT2(glEGLImageTargetTexture2DOES, GLenum, GLeglImageOES, target, image);
2428 if (target != GL_TEXTURE_2D) {
2429 YAGL_SET_ERR(GL_INVALID_ENUM);
2433 image_obj = (struct yagl_gles_image*)yagl_acquire_client_image((yagl_host_handle)image);
2436 YAGL_SET_ERR(GL_INVALID_OPERATION);
2441 yagl_gles_context_get_active_texture_target_state(ctx,
2442 yagl_gles_texture_target_2d);
2444 if (tex_target_state->texture == tex_target_state->texture_zero) {
2445 YAGL_SET_ERR(GL_INVALID_OPERATION);
2449 yagl_gles_texture_set_image(tex_target_state->texture, image_obj);
2452 yagl_gles_image_release(image_obj);
2454 YAGL_LOG_FUNC_EXIT(NULL);
2457 YAGL_API void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
2459 fprintf(stderr, "glEGLImageTargetRenderbufferStorageOES not supported in YaGL\n");
2463 * GL_ANGLE_framebuffer_blit.
2467 YAGL_API void glBlitFramebuffer(GLint srcX0, GLint srcY0,
2468 GLint srcX1, GLint srcY1,
2469 GLint dstX0, GLint dstY0,
2470 GLint dstX1, GLint dstY1,
2471 GLbitfield mask, GLenum filter)
2473 GLenum read_status, draw_status;
2475 YAGL_LOG_FUNC_ENTER_SPLIT10(glBlitFramebuffer, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
2479 if (mask & ~(GL_COLOR_BUFFER_BIT |
2480 GL_DEPTH_BUFFER_BIT |
2481 GL_STENCIL_BUFFER_BIT)) {
2482 YAGL_SET_ERR(GL_INVALID_VALUE);
2491 YAGL_SET_ERR(GL_INVALID_VALUE);
2495 if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) &&
2496 (filter != GL_NEAREST)) {
2497 YAGL_SET_ERR(GL_INVALID_OPERATION);
2501 read_status = yagl_gles_context_check_framebuffer_status(ctx,
2504 if (read_status != GL_FRAMEBUFFER_COMPLETE) {
2505 YAGL_SET_ERR(GL_INVALID_FRAMEBUFFER_OPERATION);
2509 draw_status = yagl_gles_context_check_framebuffer_status(ctx,
2512 if (draw_status != GL_FRAMEBUFFER_COMPLETE) {
2513 YAGL_SET_ERR(GL_INVALID_FRAMEBUFFER_OPERATION);
2517 if (!ctx->min_mag_blits &&
2518 ((abs(dstX0 - dstX1) != abs(srcX0 - srcX1)) ||
2519 (abs(dstY0 - dstY1) != abs(srcY0 - srcY1)))) {
2521 * Minifying/magnifying blits cause crashes with some host OpenGL
2522 * drivers, so disable them for now.
2524 YAGL_SET_ERR(GL_INVALID_OPERATION);
2528 yagl_render_invalidate(0);
2530 yagl_host_glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
2533 YAGL_LOG_FUNC_EXIT(NULL);
2535 YAGL_API YAGL_ALIAS(glBlitFramebuffer, glBlitFramebufferANGLE);
2542 * GL_OES_vertex_array_object.
2546 YAGL_API void glBindVertexArray(GLuint array)
2548 struct yagl_gles_vertex_array *va_obj = NULL;
2550 YAGL_LOG_FUNC_ENTER_SPLIT1(glBindVertexArray, GLuint, array);
2554 if (!ctx->vertex_arrays_supported) {
2555 YAGL_SET_ERR(GL_INVALID_OPERATION);
2560 va_obj = (struct yagl_gles_vertex_array*)yagl_namespace_acquire(&ctx->vertex_arrays,
2564 YAGL_SET_ERR(GL_INVALID_OPERATION);
2569 yagl_gles_context_bind_vertex_array(ctx, va_obj);
2572 yagl_gles_vertex_array_release(va_obj);
2574 YAGL_LOG_FUNC_EXIT(NULL);
2576 YAGL_API YAGL_ALIAS(glBindVertexArray, glBindVertexArrayOES);
2578 YAGL_API void glDeleteVertexArrays(GLsizei n, const GLuint *arrays)
2582 YAGL_LOG_FUNC_ENTER_SPLIT2(glDeleteVertexArrays, GLsizei, const GLuint*, n, arrays);
2586 if (!ctx->vertex_arrays_supported) {
2587 YAGL_SET_ERR(GL_INVALID_OPERATION);
2592 YAGL_SET_ERR(GL_INVALID_VALUE);
2597 for (i = 0; i < n; ++i) {
2598 yagl_gles_context_unbind_vertex_array(ctx, arrays[i]);
2599 yagl_namespace_remove(&ctx->vertex_arrays, arrays[i]);
2604 YAGL_LOG_FUNC_EXIT(NULL);
2606 YAGL_API YAGL_ALIAS(glDeleteVertexArrays, glDeleteVertexArraysOES);
2608 YAGL_API void glGenVertexArrays(GLsizei n, GLuint *array_names)
2610 struct yagl_gles_vertex_array **arrays = NULL;
2613 YAGL_LOG_FUNC_ENTER_SPLIT2(glGenVertexArrays, GLsizei, GLuint*, n, array_names);
2617 if (!ctx->vertex_arrays_supported) {
2618 YAGL_SET_ERR(GL_INVALID_OPERATION);
2623 YAGL_SET_ERR(GL_INVALID_VALUE);
2627 arrays = yagl_malloc0(n * sizeof(*arrays));
2629 for (i = 0; i < n; ++i) {
2630 arrays[i] = yagl_gles_vertex_array_create(0,
2631 ctx->create_arrays(ctx),
2639 for (i = 0; i < n; ++i) {
2640 yagl_namespace_add(&ctx->vertex_arrays,
2644 array_names[i] = arrays[i]->base.local_name;
2649 for (i = 0; i < n; ++i) {
2650 yagl_gles_vertex_array_release(arrays[i]);
2654 YAGL_LOG_FUNC_EXIT(NULL);
2656 YAGL_API YAGL_ALIAS(glGenVertexArrays, glGenVertexArraysOES);
2658 YAGL_API GLboolean glIsVertexArray(GLuint array)
2660 GLboolean res = GL_FALSE;
2661 struct yagl_gles_vertex_array *va_obj = NULL;
2663 YAGL_LOG_FUNC_ENTER_SPLIT1(glIsVertexArray, GLuint, array);
2665 YAGL_GET_CTX_RET(GL_FALSE);
2667 if (!ctx->vertex_arrays_supported) {
2668 YAGL_SET_ERR(GL_INVALID_OPERATION);
2672 va_obj = (struct yagl_gles_vertex_array*)yagl_namespace_acquire(&ctx->vertex_arrays,
2675 if (va_obj && yagl_gles_vertex_array_was_bound(va_obj)) {
2679 yagl_gles_vertex_array_release(va_obj);
2682 YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, res);
2686 YAGL_API YAGL_ALIAS(glIsVertexArray, glIsVertexArrayOES);
2693 * GL_EXT_draw_buffers.
2697 YAGL_API void glDrawBuffers(GLsizei n, const GLenum *bufs)
2701 YAGL_LOG_FUNC_ENTER_SPLIT2(glDrawBuffers, GLsizei, const GLenum*, n, bufs);
2705 if ((n < 0) || (n > ctx->max_draw_buffers)) {
2706 YAGL_SET_ERR(GL_INVALID_VALUE);
2710 if (ctx->fbo_draw) {
2711 for (i = 0; i < n; ++i) {
2712 if (bufs[i] == GL_NONE) {
2716 if ((bufs[i] == GL_BACK) ||
2717 (bufs[i] >= (GL_COLOR_ATTACHMENT0 + ctx->max_color_attachments))) {
2718 YAGL_SET_ERR(GL_INVALID_OPERATION);
2722 if (bufs[i] < GL_COLOR_ATTACHMENT0) {
2723 YAGL_SET_ERR(GL_INVALID_ENUM);
2727 if ((bufs[i] - GL_COLOR_ATTACHMENT0) != i) {
2728 YAGL_SET_ERR(GL_INVALID_OPERATION);
2733 memcpy(&ctx->fbo_draw->draw_buffers[0], bufs, n * sizeof(bufs[0]));
2735 for (i = n; i < ctx->max_draw_buffers; ++i) {
2736 ctx->fbo_draw->draw_buffers[i] = GL_NONE;
2739 if ((n != 1) || ((bufs[0] != GL_NONE) && (bufs[0] != GL_BACK))) {
2740 YAGL_SET_ERR(GL_INVALID_OPERATION);
2744 ctx->fb0_draw_buffer = bufs[0];
2747 yagl_host_glDrawBuffers(bufs, n);
2750 YAGL_LOG_FUNC_EXIT(NULL);
2752 YAGL_API YAGL_ALIAS(glDrawBuffers, glDrawBuffersEXT);
2759 * GL_NV_read_buffer.
2763 YAGL_API void glReadBuffer(GLenum mode)
2765 YAGL_LOG_FUNC_ENTER_SPLIT1(glReadBuffer, GLenum, mode);
2769 if (ctx->fbo_read) {
2770 if (mode != GL_NONE) {
2771 if ((mode < GL_COLOR_ATTACHMENT0) ||
2772 (mode >= (GL_COLOR_ATTACHMENT0 + ctx->max_color_attachments))) {
2773 YAGL_SET_ERR(GL_INVALID_OPERATION);
2778 ctx->fbo_read->read_buffer = mode;
2780 if ((mode != GL_NONE) && (mode != GL_BACK)) {
2781 YAGL_SET_ERR(GL_INVALID_OPERATION);
2785 ctx->fb0_read_buffer = mode;
2788 yagl_host_glReadBuffer(mode);
2791 YAGL_LOG_FUNC_EXIT(NULL);
2793 YAGL_API YAGL_ALIAS(glReadBuffer, glReadBufferNV);
2804 YAGL_API void *glMapBuffer(GLenum target, GLenum access)
2807 struct yagl_gles_buffer *buffer_obj = NULL;
2809 YAGL_LOG_FUNC_ENTER_SPLIT2(glMapBuffer, GLenum, GLenum, target, access);
2811 YAGL_GET_CTX_RET(NULL);
2813 if (access != GL_WRITE_ONLY) {
2814 YAGL_SET_ERR(GL_INVALID_ENUM);
2818 if (!yagl_gles_context_acquire_binded_buffer(ctx, target, &buffer_obj)) {
2819 YAGL_SET_ERR(GL_INVALID_ENUM);
2824 YAGL_SET_ERR(GL_INVALID_OPERATION);
2828 if (yagl_gles_buffer_mapped(buffer_obj)) {
2829 YAGL_SET_ERR(GL_INVALID_OPERATION);
2833 if (!yagl_gles_buffer_map(buffer_obj, 0, buffer_obj->size, GL_MAP_WRITE_BIT)) {
2834 YAGL_SET_ERR(GL_OUT_OF_MEMORY);
2838 ptr = buffer_obj->map_pointer;
2841 yagl_gles_buffer_release(buffer_obj);
2843 YAGL_LOG_FUNC_EXIT("%p", ptr);
2847 YAGL_API YAGL_ALIAS(glMapBuffer, glMapBufferOES);
2849 YAGL_API GLboolean glUnmapBuffer(GLenum target)
2851 GLboolean ret = GL_FALSE;
2852 struct yagl_gles_buffer *buffer_obj = NULL;
2854 YAGL_LOG_FUNC_ENTER_SPLIT1(glUnmapBuffer, GLenum, target);
2856 YAGL_GET_CTX_RET(GL_FALSE);
2858 if (!yagl_gles_context_acquire_binded_buffer(ctx, target, &buffer_obj)) {
2859 YAGL_SET_ERR(GL_INVALID_ENUM);
2864 YAGL_SET_ERR(GL_INVALID_OPERATION);
2868 if (!yagl_gles_buffer_mapped(buffer_obj)) {
2869 YAGL_SET_ERR(GL_INVALID_OPERATION);
2873 yagl_gles_buffer_unmap(buffer_obj);
2878 yagl_gles_buffer_release(buffer_obj);
2880 YAGL_LOG_FUNC_EXIT("%u", ret);
2884 YAGL_API YAGL_ALIAS(glUnmapBuffer, glUnmapBufferOES);
2886 YAGL_API void glGetBufferPointerv(GLenum target,
2890 struct yagl_gles_buffer *buffer_obj = NULL;
2892 YAGL_LOG_FUNC_ENTER_SPLIT3(glGetBufferPointerv, GLenum, GLenum, GLvoid**, target, pname, params);
2896 if (pname != GL_BUFFER_MAP_POINTER) {
2897 YAGL_SET_ERR(GL_INVALID_ENUM);
2901 if (!yagl_gles_context_acquire_binded_buffer(ctx, target, &buffer_obj)) {
2902 YAGL_SET_ERR(GL_INVALID_ENUM);
2907 YAGL_SET_ERR(GL_INVALID_OPERATION);
2911 *params = buffer_obj->map_pointer;
2914 yagl_gles_buffer_release(buffer_obj);
2916 YAGL_LOG_FUNC_EXIT(NULL);
2918 YAGL_API YAGL_ALIAS(glGetBufferPointerv, glGetBufferPointervOES);
2925 * GL_EXT_map_buffer_range.
2929 YAGL_API void *glMapBufferRange(GLenum target, GLintptr offset,
2930 GLsizeiptr length, GLbitfield access)
2933 struct yagl_gles_buffer *buffer_obj = NULL;
2935 YAGL_LOG_FUNC_ENTER_SPLIT4(glMapBufferRange, GLenum, GLintptr, GLsizeiptr, GLbitfield, target, offset, length, access);
2937 YAGL_GET_CTX_RET(NULL);
2939 if ((offset < 0) || (length < 0)) {
2940 YAGL_SET_ERR(GL_INVALID_VALUE);
2945 YAGL_SET_ERR(GL_INVALID_OPERATION);
2949 if (access & ~(GL_MAP_READ_BIT |
2951 GL_MAP_INVALIDATE_RANGE_BIT |
2952 GL_MAP_INVALIDATE_BUFFER_BIT |
2953 GL_MAP_FLUSH_EXPLICIT_BIT |
2954 GL_MAP_UNSYNCHRONIZED_BIT)) {
2955 YAGL_SET_ERR(GL_INVALID_VALUE);
2959 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) {
2960 YAGL_SET_ERR(GL_INVALID_OPERATION);
2964 if ((access & GL_MAP_READ_BIT) &&
2965 (access & (GL_MAP_INVALIDATE_RANGE_BIT |
2966 GL_MAP_INVALIDATE_BUFFER_BIT |
2967 GL_MAP_UNSYNCHRONIZED_BIT))) {
2968 YAGL_SET_ERR(GL_INVALID_OPERATION);
2972 if ((access & GL_MAP_FLUSH_EXPLICIT_BIT) &&
2973 ((access & GL_MAP_WRITE_BIT) == 0)) {
2974 YAGL_SET_ERR(GL_INVALID_OPERATION);
2978 if (!yagl_gles_context_acquire_binded_buffer(ctx, target, &buffer_obj)) {
2979 YAGL_SET_ERR(GL_INVALID_ENUM);
2984 YAGL_SET_ERR(GL_INVALID_OPERATION);
2988 if (yagl_gles_buffer_mapped(buffer_obj)) {
2989 YAGL_SET_ERR(GL_INVALID_OPERATION);
2993 if (!yagl_gles_buffer_map(buffer_obj, offset, length, access)) {
2994 YAGL_SET_ERR(GL_INVALID_VALUE);
2998 ptr = buffer_obj->map_pointer;
3001 yagl_gles_buffer_release(buffer_obj);
3003 YAGL_LOG_FUNC_EXIT("%p", ptr);
3007 YAGL_API YAGL_ALIAS(glMapBufferRange, glMapBufferRangeEXT);
3009 YAGL_API void glFlushMappedBufferRange(GLenum target, GLintptr offset,
3012 struct yagl_gles_buffer *buffer_obj = NULL;
3014 YAGL_LOG_FUNC_ENTER_SPLIT3(glFlushMappedBufferRange, GLenum, GLintptr, GLsizeiptr, target, offset, length);
3018 if ((offset < 0) || (length < 0)) {
3019 YAGL_SET_ERR(GL_INVALID_VALUE);
3023 if (!yagl_gles_context_acquire_binded_buffer(ctx, target, &buffer_obj)) {
3024 YAGL_SET_ERR(GL_INVALID_ENUM);
3029 YAGL_SET_ERR(GL_INVALID_OPERATION);
3033 if (!yagl_gles_buffer_mapped(buffer_obj)) {
3034 YAGL_SET_ERR(GL_INVALID_OPERATION);
3038 if ((buffer_obj->map_access & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) {
3039 YAGL_SET_ERR(GL_INVALID_OPERATION);
3043 if (!yagl_gles_buffer_flush_mapped_range(buffer_obj, offset, length)) {
3044 YAGL_SET_ERR(GL_INVALID_VALUE);
3049 yagl_gles_buffer_release(buffer_obj);
3051 YAGL_LOG_FUNC_EXIT(NULL);
3053 YAGL_API YAGL_ALIAS(glFlushMappedBufferRange, glFlushMappedBufferRangeEXT);
3060 * GL_EXT_texture_storage.
3064 YAGL_API void glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
3066 yagl_gles_texture_target texture_target;
3067 struct yagl_gles_texture_target_state *tex_target_state;
3068 GLenum base_internalformat, format, type;
3070 GLenum cubemap_targets[] =
3072 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
3073 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
3074 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
3075 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
3076 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
3077 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
3080 YAGL_LOG_FUNC_ENTER_SPLIT5(glTexStorage2D, GLenum, GLsizei, GLenum, GLsizei, GLsizei, target, levels, internalformat, width, height);
3084 if ((levels <= 0) || (width <= 0) || (height <= 0)) {
3085 YAGL_SET_ERR(GL_INVALID_VALUE);
3089 if (!yagl_gles_context_validate_texstorage_format(ctx,
3091 &base_internalformat,
3094 YAGL_SET_ERR(GL_INVALID_ENUM);
3098 if (!yagl_gles_context_validate_texture_target(ctx, target, &texture_target)) {
3099 YAGL_SET_ERR(GL_INVALID_ENUM);
3103 tex_target_state = yagl_gles_context_get_active_texture_target_state(ctx,
3106 if ((tex_target_state->texture == tex_target_state->texture_zero) ||
3107 tex_target_state->texture->immutable) {
3108 YAGL_SET_ERR(GL_INVALID_OPERATION);
3112 switch (texture_target) {
3113 case yagl_gles_texture_target_2d:
3114 for (i = 0; i < levels; ++i) {
3115 yagl_host_glTexImage2DData(target, i, internalformat,
3116 width, height, 0, format, type,
3130 case yagl_gles_texture_target_cubemap:
3131 for (i = 0; i < levels; ++i) {
3133 j < sizeof(cubemap_targets)/sizeof(cubemap_targets[0]);
3135 yagl_host_glTexImage2DData(cubemap_targets[j], i, internalformat,
3136 width, height, 0, format, type,
3152 YAGL_SET_ERR(GL_INVALID_ENUM);
3156 yagl_gles_texture_set_immutable(tex_target_state->texture,
3157 base_internalformat,
3159 yagl_gles_context_convert_textures(ctx));
3162 YAGL_LOG_FUNC_EXIT(NULL);
3164 YAGL_API YAGL_ALIAS(glTexStorage2D, glTexStorage2DEXT);