1 #include "coregl_fastpath.h"
10 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST = NULL;
11 #include "../../headers/sym.h"
14 Fastpath_Opt_Flag fp_opt = FP_UNKNOWN_PATH;
17 FILE *trace_fp = NULL;
19 GLenum FPGL_Error = GL_NO_ERROR;
21 GLGlueContext_List *gctx_list = NULL;
23 Mutex init_context_mutex = MUTEX_INITIALIZER;
24 GLGlueContext *initial_ctx = NULL;
26 Mutex ctx_list_access_mutex = MUTEX_INITIALIZER;
28 GLContext_List *glctx_list = NULL;
31 _get_texture_states(GLenum pname, GLint *params)
33 GLuint cur_active_tex = 0;
35 AST(initial_ctx != NULL);
37 _orig_fastpath_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
39 for (i = 0; i < initial_ctx->gl_num_tex_units[0]; i++)
41 _orig_fastpath_glActiveTexture(GL_TEXTURE0 + i);
42 _orig_fastpath_glGetIntegerv(pname, &(((GLint *)params)[i]));
44 _orig_fastpath_glActiveTexture(cur_active_tex);
48 init_modules_fastpath()
51 int fastpath_force_off_opt = 0;
53 COREGL_LOG("[CoreGL] <Fastpath> : ");
55 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
56 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
58 if (fastpath_force_off_opt == 1)
60 COREGL_LOG("\E[40;31;1m(DISABLED by force option)\E[0m ");
67 COREGL_LOG("(%d) Fastpath enabled...\n", fastpath_opt);
68 fp_opt = FP_FAST_PATH;
71 COREGL_LOG("(%d) Default API path enabled...\n", fastpath_opt);
72 fp_opt = FP_NORMAL_PATH;
76 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
81 deinit_modules_fastpath()
83 GLContext_List *current = NULL;
85 AST(mutex_lock(&ctx_list_access_mutex) == 1);
87 // Destroy remained context & Detect leaks
88 int retry_destroy = 0;
96 if (current->cstate != NULL)
98 COREGL_WRN("\E[40;31;1mContext attached to [dpy=%p|rctx=%p] has not been completely destroyed.(leak)\E[0m\n", current->cstate->rdpy, current->cstate->rctx);
100 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
101 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
103 fastpath_remove_context_states_from_list(current->cstate, NULL);
108 glctx_list = current->next;
110 current = glctx_list;
112 if (retry_destroy == 0) break;
117 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
121 init_modules_tstate_fastpath(GLThreadState *tstate)
123 MY_MODULE_TSTATE *tstate_mt = NULL;
125 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
127 tstate_mt->binded_api = EGL_OPENGL_ES_API;
129 tstate->module_data[MY_MODULE_ID] = tstate_mt;
133 deinit_modules_tstate_fastpath(GLThreadState *tstate)
135 if (tstate->module_data[MY_MODULE_ID] != NULL)
137 free(tstate->module_data[MY_MODULE_ID]);
138 tstate->module_data[MY_MODULE_ID] = NULL;
143 fastpath_apply_overrides()
148 fastpath_apply_overrides_egl(1);
149 fastpath_apply_overrides_gl(1);
154 COREGL_ERR("Invalide GL Override Option!!!\n");
161 fastpath_apply_overrides_egl(int enable)
163 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
164 # include "../../headers/sym_egl.h"
165 #undef _COREGL_SYMBOL
167 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
169 COREGL_OVERRIDE(fastpath_, eglBindAPI);
170 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
172 COREGL_OVERRIDE(fastpath_, eglCreateContext);
173 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
174 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
175 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
176 COREGL_OVERRIDE(fastpath_, eglQueryContext);
177 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
178 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
179 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
180 COREGL_OVERRIDE(fastpath_, eglTerminate);
185 fastpath_apply_overrides_gl(int enable)
187 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
188 # include "../../headers/sym_gl.h"
189 #undef _COREGL_SYMBOL
193 COREGL_OVERRIDE(fastpath_, glGetError);
195 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
196 COREGL_OVERRIDE(fastpath_, glGetFloatv);
197 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
199 COREGL_OVERRIDE(fastpath_, glActiveTexture);
200 COREGL_OVERRIDE(fastpath_, glGenTextures);
201 COREGL_OVERRIDE(fastpath_, glBindTexture);
202 COREGL_OVERRIDE(fastpath_, glIsTexture);
203 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
204 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
206 COREGL_OVERRIDE(fastpath_, glGenBuffers);
207 COREGL_OVERRIDE(fastpath_, glBindBuffer);
208 COREGL_OVERRIDE(fastpath_, glIsBuffer);
209 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
211 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
212 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
213 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
214 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
216 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
217 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
218 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
219 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
220 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
222 COREGL_OVERRIDE(fastpath_, glCreateShader);
223 COREGL_OVERRIDE(fastpath_, glCreateProgram);
224 COREGL_OVERRIDE(fastpath_, glAttachShader);
225 COREGL_OVERRIDE(fastpath_, glCompileShader);
226 COREGL_OVERRIDE(fastpath_, glShaderBinary);
227 COREGL_OVERRIDE(fastpath_, glDeleteShader);
228 COREGL_OVERRIDE(fastpath_, glDetachShader);
229 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
230 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
231 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
232 COREGL_OVERRIDE(fastpath_, glIsShader);
233 COREGL_OVERRIDE(fastpath_, glShaderSource);
234 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
235 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
236 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
237 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
238 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
239 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
240 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
241 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
242 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
243 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
244 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
245 COREGL_OVERRIDE(fastpath_, glIsProgram);
246 COREGL_OVERRIDE(fastpath_, glLinkProgram);
247 COREGL_OVERRIDE(fastpath_, glUseProgram);
248 COREGL_OVERRIDE(fastpath_, glValidateProgram);
250 COREGL_OVERRIDE(fastpath_, glBlendColor);
251 COREGL_OVERRIDE(fastpath_, glBlendEquation);
252 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
253 COREGL_OVERRIDE(fastpath_, glBlendFunc);
254 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
255 COREGL_OVERRIDE(fastpath_, glClearColor);
256 COREGL_OVERRIDE(fastpath_, glClearDepthf);
257 COREGL_OVERRIDE(fastpath_, glClearStencil);
258 COREGL_OVERRIDE(fastpath_, glColorMask);
259 COREGL_OVERRIDE(fastpath_, glCullFace);
260 COREGL_OVERRIDE(fastpath_, glDepthFunc);
261 COREGL_OVERRIDE(fastpath_, glDepthMask);
262 COREGL_OVERRIDE(fastpath_, glDepthRangef);
263 COREGL_OVERRIDE(fastpath_, glDisable);
264 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
265 COREGL_OVERRIDE(fastpath_, glEnable);
266 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
267 COREGL_OVERRIDE(fastpath_, glFrontFace);
268 COREGL_OVERRIDE(fastpath_, glHint);
269 COREGL_OVERRIDE(fastpath_, glLineWidth);
270 COREGL_OVERRIDE(fastpath_, glPixelStorei);
271 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
272 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
273 COREGL_OVERRIDE(fastpath_, glScissor);
274 COREGL_OVERRIDE(fastpath_, glStencilFunc);
275 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
276 COREGL_OVERRIDE(fastpath_, glStencilMask);
277 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
278 COREGL_OVERRIDE(fastpath_, glStencilOp);
279 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
280 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
281 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
282 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
283 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
284 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
285 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
286 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
287 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
288 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
289 COREGL_OVERRIDE(fastpath_, glViewport);
291 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
292 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
293 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
294 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
295 COREGL_OVERRIDE(fastpath_, glEGLImageTargetTexture2DOES);
296 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
301 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
307 static inline GL_Object_Hash_Base *
308 _get_shared_object_hash(GL_Shared_Object_State *sostate, GL_Object_Type type)
312 case GL_OBJECT_TYPE_TEXTURE:
313 return &sostate->texture;
314 case GL_OBJECT_TYPE_BUFFER:
315 return &sostate->buffer;
316 case GL_OBJECT_TYPE_FRAMEBUFFER:
317 return &sostate->framebuffer;
318 case GL_OBJECT_TYPE_RENDERBUFFER:
319 return &sostate->renderbuffer;
320 case GL_OBJECT_TYPE_PROGRAM:
321 return &sostate->program;
327 static inline GL_Object_Hash_Base *
328 _get_shared_object_hash_real(GL_Shared_Object_State *sostate, GL_Object_Type type)
332 case GL_OBJECT_TYPE_TEXTURE:
333 return &sostate->texture_real;
334 case GL_OBJECT_TYPE_BUFFER:
335 return &sostate->buffer_real;
336 case GL_OBJECT_TYPE_FRAMEBUFFER:
337 return &sostate->framebuffer_real;
338 case GL_OBJECT_TYPE_RENDERBUFFER:
339 return &sostate->renderbuffer_real;
340 case GL_OBJECT_TYPE_PROGRAM:
341 return &sostate->program_real;
348 fastpath_add_context_state_to_list(const void *option, const int option_len, GLContextState *cstate, Mutex *mtx)
352 GLContext_List *current = NULL;
353 GLContext_List *newitm = NULL;
355 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
359 tid = get_current_thread();
361 current = glctx_list;
362 while (current != NULL)
364 if (current->option_len == option_len &&
365 memcmp(current->option, option, option_len) == 0 &&
366 current->thread_id == tid)
368 AST(current->cstate == cstate);
371 current = current->next;
374 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
377 COREGL_ERR("Failed to create context list.\n");
381 newitm->cstate = cstate;
382 newitm->thread_id = tid;
383 newitm->option_len = option_len;
384 newitm->option = (void *)malloc(option_len);
385 memcpy(newitm->option, option, option_len);
387 if (glctx_list != NULL)
388 newitm->next = glctx_list;
409 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
415 fastpath_get_context_state_from_list(const void *option, const int option_len, Mutex *mtx)
417 GLContextState *ret = NULL;
418 GLContext_List *current = NULL;
421 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
423 tid = get_current_thread();
425 current = glctx_list;
426 while (current != NULL)
428 if (current->option_len == option_len &&
429 memcmp(current->option, option, option_len) == 0 &&
430 current->thread_id == tid)
432 ret = current->cstate;
435 current = current->next;
440 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
445 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
449 GLContext_List *olditm = NULL;
450 GLContext_List *current = NULL;
452 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
456 tid = get_current_thread();
457 current = glctx_list;
459 while (current != NULL)
461 if (current->cstate == cstate)
463 GLContext_List *nextitm = NULL;
466 olditm->next = current->next;
467 nextitm = olditm->next;
471 glctx_list = current->next;
472 nextitm = glctx_list;
480 current = current->next;
485 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
490 fastpath_sostate_init(GL_Shared_Object_State *sostate)
492 #define HASH_INIT(hash_base) \
493 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
494 hash_base.hash_size = GL_OBJECT_HASH_BASE;
496 HASH_INIT(sostate->texture);
497 HASH_INIT(sostate->buffer);
498 HASH_INIT(sostate->framebuffer);
499 HASH_INIT(sostate->renderbuffer);
500 HASH_INIT(sostate->program);
502 HASH_INIT(sostate->texture_real);
503 HASH_INIT(sostate->buffer_real);
504 HASH_INIT(sostate->framebuffer_real);
505 HASH_INIT(sostate->renderbuffer_real);
506 HASH_INIT(sostate->program_real);
512 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
514 int array_idx = data->hash_key & (hash_base->hash_size - 1);
515 if (hash_base->hash_field[array_idx] == NULL)
517 hash_base->hash_field[array_idx] = data;
521 GL_Object_Hash *current = hash_base->hash_field[array_idx];
524 AST(current->hash_key != data->hash_key);
525 current = current->next;
527 current->next = data;
530 hash_base->item_size++;
534 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
537 int array_idx = hash & (hash_base->hash_size - 1);
539 GL_Object_Hash *current = hash_base->hash_field[array_idx];
540 GL_Object_Hash *prev = NULL;
544 if (current->hash_key == hash)
547 prev->next = current->next;
549 hash_base->hash_field[array_idx] = current->next;
550 hash_base->item_size--;
555 current = current->next;
562 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
564 if (hash_base->item_size == 0) return;
566 for (int i = 0; i < hash_base->hash_size; i++)
568 if (hash_base->hash_field[i] != NULL)
570 GL_Object_Hash *current = hash_base->hash_field[i];
572 while (current != NULL)
574 GL_Object_Hash *current_next = current->next;
576 if (free_data == 1 && current->item != NULL)
582 hash_base->item_size--;
583 current = current_next;
590 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
592 #define HASH_DEINIT(hash_base, free_data) \
593 _free_hash_list(&hash_base, free_data); \
594 free(hash_base.hash_field); \
595 hash_base.hash_size = 0;
597 HASH_DEINIT(sostate->texture, 1);
598 HASH_DEINIT(sostate->buffer, 1);
599 HASH_DEINIT(sostate->framebuffer, 1);
600 HASH_DEINIT(sostate->renderbuffer, 1);
601 HASH_DEINIT(sostate->program, 1);
603 HASH_DEINIT(sostate->texture_real, 0);
604 HASH_DEINIT(sostate->buffer_real, 0);
605 HASH_DEINIT(sostate->framebuffer_real, 0);
606 HASH_DEINIT(sostate->renderbuffer_real, 0);
607 HASH_DEINIT(sostate->program_real, 0);
612 #define FIND_HASH(hash_base, key, ret) \
614 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
617 if (fh_current->hash_key == (key)) \
622 fh_current = fh_current->next; \
627 _sostate_hash_check(GL_Object_Hash_Base *hash_base)
629 if (hash_base->item_size + 1 < hash_base->hash_size)
632 int oldsize = hash_base->hash_size;
633 GL_Object_Hash **oldfield = hash_base->hash_field;
635 hash_base->hash_size = oldsize << 1;
636 hash_base->hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * hash_base->hash_size);
637 AST(hash_base->hash_field != NULL);
639 for (int i = 0; i < oldsize; i++)
641 if (oldfield[i] != NULL)
643 GL_Object_Hash *current = oldfield[i];
645 while (current != NULL)
647 GL_Object_Hash *current_next = current->next;
648 _add_hash(hash_base, current);
649 hash_base->item_size--;
650 current = current_next;
659 fastpath_sostate_create_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint real_name)
661 GLuint ret = _COREGL_INT_INIT_VALUE;
663 GL_Object_Hash_Base *hash_base = NULL;
664 GL_Object_Hash_Base *hash_base_real = NULL;
665 int newid = _COREGL_INT_INIT_VALUE;
667 hash_base = _get_shared_object_hash(sostate, type);
668 hash_base_real = _get_shared_object_hash_real(sostate, type);
670 newid = hash_base->last_id + 1;
671 if (newid >= hash_base->hash_size)
673 hash_base->is_looped = 1;
675 hash_base->last_id = 1;
678 if (hash_base->is_looped != 0)
681 int findingid = newid;
683 for (i = 0; i < hash_base->hash_size; i++)
685 GL_Object_Hash *exist_hash = NULL;
686 FIND_HASH(hash_base, findingid, exist_hash);
687 if (exist_hash == NULL)
693 if (findingid >= hash_base->hash_size) findingid = 1;
697 hash_base->last_id = newid;
700 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
702 newobj->id = (int)type + newid;
703 newobj->real_id = real_name;
704 newobj->ref_count = 1;
707 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
708 AST(newobj_hash != NULL);
709 newobj_hash->item = newobj;
710 newobj_hash->hash_key = newid;
711 _add_hash(hash_base, newobj_hash);
713 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
714 AST(newobj_hash_real != NULL);
715 newobj_hash_real->item = newobj;
716 newobj_hash_real->hash_key = real_name;
717 _add_hash(hash_base_real, newobj_hash_real);
720 _sostate_hash_check(hash_base);
721 _sostate_hash_check(hash_base_real);
729 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
730 if ((hash) < 0) { ret = 0; goto finish; } \
732 GL_Object_Hash *object_hash = NULL; \
733 FIND_HASH((hash_base), (hash), object_hash); \
734 if (object_hash == NULL) { ret = 0; goto finish; } \
735 (object) = object_hash->item; \
736 if ((object) == NULL) { ret = 0; goto finish; } \
740 fastpath_sostate_remove_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
742 GLuint ret = _COREGL_INT_INIT_VALUE;
744 GL_Object_Hash_Base *hash_base = NULL;
745 GL_Object_Hash_Base *hash_base_real = NULL;
746 GL_Object *object = NULL;
748 hash_base = _get_shared_object_hash(sostate, type);
749 hash_base_real = _get_shared_object_hash_real(sostate, type);
751 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
755 if (object->ref_count <= 0)
757 GL_Object_Hash *object_hash = NULL;
759 FIND_HASH(hash_base, object->id - (int)type, object_hash);
760 AST(object_hash != NULL);
761 _remove_hash(hash_base, object->id - (int)type);
765 FIND_HASH(hash_base_real, object->real_id, object_hash);
766 AST(object_hash != NULL);
767 _remove_hash(hash_base_real, object->real_id);
783 fastpath_sostate_get_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
785 GLuint ret = _COREGL_INT_INIT_VALUE;
787 GL_Object_Hash_Base *hash_base = NULL;
788 GL_Object *object = NULL;
790 hash_base = _get_shared_object_hash(sostate, type);
792 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
794 ret = object->real_id;
802 fastpath_sostate_set_object_tag(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag)
804 GLint ret = _COREGL_INT_INIT_VALUE;
806 GL_Object_Hash_Base *hash_base = NULL;
807 GL_Object *object = NULL;
808 int hash = _COREGL_INT_INIT_VALUE;
810 hash_base = _get_shared_object_hash(sostate, type);
812 hash = glue_name - (int)type;
814 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
825 fastpath_sostate_get_object_tag(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
829 GL_Object_Hash_Base *hash_base = NULL;
830 GL_Object *object = NULL;
832 hash_base = _get_shared_object_hash(sostate, type);
834 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
844 fastpath_sostate_find_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint real_name)
846 GLuint ret = _COREGL_INT_INIT_VALUE;
848 GL_Object_Hash_Base *hash_base_real = NULL;
849 GL_Object *object = NULL;
851 hash_base_real = _get_shared_object_hash_real(sostate, type);
853 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
863 fastpath_sostate_use_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
865 GLint ret = _COREGL_INT_INIT_VALUE;
867 GL_Object_Hash_Base *hash_base = NULL;
868 GL_Object *object = NULL;
870 hash_base = _get_shared_object_hash(sostate, type);
872 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
883 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
885 static struct timeval tv_last = { 0, 0 };
887 if (unlikely(trace_state_flag != 1)) return;
891 struct timeval tv_now = { 0, 0 };
892 AST(gettimeofday(&tv_now, NULL) == 0);
893 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC)
901 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
902 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n", getpid(), ctx);
903 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
905 #define PRINTF_CHAR_GLenum "%10d"
906 #define PRINTF_CHAR_GLboolean "%10d"
907 #define PRINTF_CHAR_GLint "%10d"
908 #define PRINTF_CHAR_GLsizei "%10u"
909 #define PRINTF_CHAR_GLuint "%10u"
910 #define PRINTF_CHAR_GLuintmask "0x%8X"
912 #define PRINTF_CHAR_GLclampf "%10.6f"
913 #define PRINTF_CHAR_GLfloat "%10.6f"
915 #define PRINTF_CHAR_GLvoidptr "%10p"
917 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
919 #define INITIAL_CTX initial_ctx
920 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
922 TYPE valuedata[SIZE]; \
923 TYPE *value = NULL; \
924 value = valuedata; GET_STMT; value = valuedata; \
925 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
926 for (int i = 0; i < SIZE; i++) \
930 TRACE("\n %-30.30s ", "");\
934 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
935 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
937 TRACE(" \E[40;37;1m)\E[0m\n"); \
939 # include "coregl_fastpath_state.h"
943 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
953 fastpath_init_context_states(GLGlueContext *ctx)
957 AST(mutex_lock(&init_context_mutex) == 1);
961 COREGL_ERR("Context NULL\n");
966 AST(ctx->initialized == 0);
967 AST(ctx->sostate != NULL);
969 if (initial_ctx == NULL)
971 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
972 AST(initial_ctx != NULL);
974 //#define FORCE_DEFAULT_VALUE
975 #ifdef FORCE_DEFAULT_VALUE
976 # define INITIAL_CTX initial_ctx
977 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
980 TYPE valuedata[SIZE]; \
981 TYPE *value = NULL; \
982 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
983 value = valuedata; DEFAULT_STMT; value = valuedata; \
984 for (i = 0; i < SIZE; i++) \
986 if (*((char *)(&value[i])) == 0xcc) \
988 memset(&value[i], 0xaa, sizeof(TYPE)); \
989 value = valuedata; DEFAULT_STMT; value = valuedata; \
990 if (*((char *)(&value[i])) == 0xaa) \
992 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
996 initial_ctx->NAME[i] = value[i]; \
999 # include "coregl_fastpath_state.h"
1003 # define INITIAL_CTX initial_ctx
1004 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1005 if (try_step == 1) \
1007 value = valuedata; DEFAULT_STMT; value = valuedata; \
1011 value = valuedata; FALLBACK_STMT; value = valuedata; \
1014 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1018 TYPE valuedata[SIZE]; \
1019 TYPE *value = NULL; \
1020 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1023 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1024 for (i = 0; i < SIZE; i++) \
1026 if (*((char *)(&value[i])) == 0xcc) \
1028 memset(&value[i], 0xaa, sizeof(TYPE)); \
1029 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1030 if (*((char *)(&value[i])) == 0xaa) \
1033 if (try_step == 2) \
1035 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1040 initial_ctx->NAME[i] = value[i]; \
1042 if (try_step != 2) \
1044 value = valuedata; DEFAULT_STMT; value = valuedata; \
1045 for (i = 0; i < SIZE; i++) \
1047 if (initial_ctx->NAME[i] != value[i]) \
1049 COREGL_WRN("GL-state '"#NAME"'[%d] value ["PRINTF_CHAR(TYPE)"] is different from SPEC-DEFAULT ["PRINTF_CHAR(TYPE)"]\n", i, initial_ctx->NAME[i], value[i]); \
1054 while (try_step == 2); \
1056 # include "coregl_fastpath_state.h"
1057 # undef SET_GLUE_VALUE
1062 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS)
1064 COREGL_WRN("\E[40;31;1mNumber of vertex attrib is too big! (%d-%d)\E[0m\n", MAX_VERTEX_ATTRIBS, initial_ctx->gl_num_vertex_attribs[0]);
1066 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS)
1068 COREGL_WRN("\E[40;31;1mNumber of texture unit is too big! (%d-%d)\E[0m\n", MAX_TEXTURE_UNITS, initial_ctx->gl_num_tex_units[0]);
1074 #define INITIAL_CTX initial_ctx
1075 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1076 for (i = 0; i < SIZE; i++) \
1078 ctx->NAME[i] = initial_ctx->NAME[i]; \
1080 # include "coregl_fastpath_state.h"
1085 ctx->initialized = 1;
1090 AST(mutex_unlock(&init_context_mutex) == 1);
1095 #ifdef COREGL_USE_MODULE_TRACEPATH
1096 extern void *tracepath_api_trace_begin(const char *name, void *hint, int trace_total_time);
1097 extern void *tracepath_api_trace_end(const char *name, void *hint, int trace_total_time);
1100 #define CHECK_GL_ERROR(func) \
1103 int err = _orig_fastpath_glGetError(); \
1104 if (err != GL_NO_ERROR) \
1106 COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1112 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1115 unsigned char flag = 0;
1118 if (debug_nofp == 1)
1124 // Return if they're the same
1125 if (oldctx == newctx)
1131 #define STATE_COMPARE(state) \
1132 if ((oldctx->state) != (newctx->state))
1134 #define STATES_COMPARE(state_ptr, bytes) \
1135 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1138 #ifdef COREGL_USE_MODULE_TRACEPATH
1139 static void *trace_hint_glfinish = NULL;
1140 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1141 #endif // COREGL_USE_MODULE_TRACEPATH
1144 int err = _orig_fastpath_glGetError();
1145 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1146 oldctx->gl_error = err;
1149 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1151 #ifdef COREGL_USE_MODULE_TRACEPATH
1152 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1153 #endif // COREGL_USE_MODULE_TRACEPATH
1155 #ifdef COREGL_USE_MODULE_TRACEPATH
1156 static void *trace_hint_bindbuffers = NULL;
1157 trace_hint_bindbuffers = tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1158 #endif // COREGL_USE_MODULE_TRACEPATH
1161 //------------------//
1163 flag = oldctx->_bind_flag | newctx->_bind_flag;
1166 STATE_COMPARE(gl_array_buffer_binding[0])
1168 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1170 STATE_COMPARE(gl_element_array_buffer_binding[0])
1172 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1174 STATE_COMPARE(gl_framebuffer_binding[0])
1176 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER, newctx->gl_framebuffer_binding[0]))
1178 STATE_COMPARE(gl_renderbuffer_binding[0])
1180 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER, newctx->gl_renderbuffer_binding[0]))
1184 #ifdef COREGL_USE_MODULE_TRACEPATH
1185 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1186 #endif // COREGL_USE_MODULE_TRACEPATH
1189 //------------------//
1192 #ifdef COREGL_USE_MODULE_TRACEPATH
1193 static void *trace_hint_enable_states = NULL;
1194 trace_hint_enable_states = tracepath_api_trace_begin("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1195 #endif // COREGL_USE_MODULE_TRACEPATH
1197 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1200 STATE_COMPARE(gl_blend[0])
1202 if (newctx->gl_blend[0])
1204 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1207 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1209 STATE_COMPARE(gl_cull_face[0])
1211 if (newctx->gl_cull_face[0])
1213 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1216 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1218 STATE_COMPARE(gl_depth_test[0])
1220 if (newctx->gl_depth_test[0])
1222 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1225 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1227 STATE_COMPARE(gl_dither[0])
1229 if (newctx->gl_dither[0])
1231 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1234 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1239 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1242 STATE_COMPARE(gl_polygon_offset_fill[0])
1244 if (newctx->gl_polygon_offset_fill[0])
1246 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1249 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1251 STATE_COMPARE(gl_sample_alpha_to_coverage[0])
1253 if (newctx->gl_sample_alpha_to_coverage[0])
1255 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1258 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1260 STATE_COMPARE(gl_sample_coverage[0])
1262 if (newctx->gl_sample_coverage[0])
1264 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1267 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1269 STATE_COMPARE(gl_scissor_test[0])
1271 if (newctx->gl_scissor_test[0])
1273 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1276 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1278 STATE_COMPARE(gl_stencil_test[0])
1280 if (newctx->gl_stencil_test[0])
1282 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1285 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1289 #ifdef COREGL_USE_MODULE_TRACEPATH
1290 tracepath_api_trace_end("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1291 #endif // COREGL_USE_MODULE_TRACEPATH
1293 //------------------//
1295 #ifdef COREGL_USE_MODULE_TRACEPATH
1296 static void *trace_hint_clear_viewport = NULL;
1297 trace_hint_clear_viewport = tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1298 #endif // COREGL_USE_MODULE_TRACEPATH
1300 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1304 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint))
1306 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1307 newctx->gl_viewport[1],
1308 newctx->gl_viewport[2],
1309 newctx->gl_viewport[3]))
1312 STATE_COMPARE(gl_current_program[0])
1314 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1316 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf))
1318 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1319 newctx->gl_color_clear_value[1],
1320 newctx->gl_color_clear_value[2],
1321 newctx->gl_color_clear_value[3]))
1327 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1330 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean))
1332 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1333 newctx->gl_color_writemask[1],
1334 newctx->gl_color_writemask[2],
1335 newctx->gl_color_writemask[3]))
1337 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf))
1339 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1340 newctx->gl_depth_range[1]))
1342 STATE_COMPARE(gl_depth_clear_value[0])
1344 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1346 STATE_COMPARE(gl_depth_func[0])
1348 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1350 STATE_COMPARE(gl_depth_writemask[0])
1352 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1354 STATE_COMPARE(gl_cull_face_mode[0])
1356 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1361 #ifdef COREGL_USE_MODULE_TRACEPATH
1362 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1363 #endif // COREGL_USE_MODULE_TRACEPATH
1365 //------------------//
1367 #ifdef COREGL_USE_MODULE_TRACEPATH
1368 static void *trace_hint_bind_textures = NULL;
1369 trace_hint_bind_textures = tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1370 #endif // COREGL_USE_MODULE_TRACEPATH
1372 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1376 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++)
1378 STATE_COMPARE(gl_tex_2d_state[i])
1380 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1381 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D, newctx->gl_tex_2d_state[i]))
1384 STATE_COMPARE(gl_tex_cube_state[i])
1386 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1387 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP, newctx->gl_tex_cube_state[i]))
1391 // Restore active texture
1392 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1394 STATE_COMPARE(gl_generate_mipmap_hint[0])
1396 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT, newctx->gl_generate_mipmap_hint[0]))
1399 #ifdef COREGL_USE_MODULE_TRACEPATH
1400 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1401 #endif // COREGL_USE_MODULE_TRACEPATH
1403 //------------------//
1404 #ifdef COREGL_USE_MODULE_TRACEPATH
1405 static void *trace_hint_etc = NULL;
1406 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1407 #endif // COREGL_USE_MODULE_TRACEPATH
1409 flag = oldctx->_blend_flag | newctx->_blend_flag;
1412 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf))
1414 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
1415 newctx->gl_blend_color[1],
1416 newctx->gl_blend_color[2],
1417 newctx->gl_blend_color[3]))
1419 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
1420 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
1421 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
1422 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0]))
1424 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
1425 newctx->gl_blend_dst_rgb[0],
1426 newctx->gl_blend_src_alpha[0],
1427 newctx->gl_blend_dst_alpha[0]))
1429 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
1430 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0]))
1432 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
1437 //------------------//
1439 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
1442 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
1443 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
1444 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0]))
1446 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
1447 newctx->gl_stencil_func[0],
1448 newctx->gl_stencil_ref[0],
1449 newctx->gl_stencil_value_mask[0]))
1451 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
1452 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0]) ||
1453 (oldctx->gl_stencil_pass_depth_pass[0] != newctx->gl_stencil_pass_depth_pass[0]))
1455 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
1456 newctx->gl_stencil_fail[0],
1457 newctx->gl_stencil_pass_depth_fail[0],
1458 newctx->gl_stencil_pass_depth_pass[0]))
1461 STATE_COMPARE(gl_stencil_writemask[0])
1463 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT, newctx->gl_stencil_writemask[0]))
1469 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
1472 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
1473 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
1474 (oldctx->gl_stencil_back_value_mask[0] != newctx->gl_stencil_back_value_mask[0]))
1476 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
1477 newctx->gl_stencil_back_func[0],
1478 newctx->gl_stencil_back_ref[0],
1479 newctx->gl_stencil_back_value_mask[0]))
1481 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
1482 (oldctx->gl_stencil_back_pass_depth_fail[0] != newctx->gl_stencil_back_pass_depth_fail[0]) ||
1483 (oldctx->gl_stencil_back_pass_depth_pass[0] != newctx->gl_stencil_back_pass_depth_pass[0]))
1485 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
1486 newctx->gl_stencil_back_fail[0],
1487 newctx->gl_stencil_back_pass_depth_fail[0],
1488 newctx->gl_stencil_back_pass_depth_pass[0]))
1491 STATE_COMPARE(gl_stencil_back_writemask[0])
1493 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK, newctx->gl_stencil_back_writemask[0]))
1495 STATE_COMPARE(gl_stencil_clear_value[0])
1497 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
1501 //------------------//
1503 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
1506 STATE_COMPARE(gl_front_face[0])
1508 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
1510 STATE_COMPARE(gl_line_width[0])
1512 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
1514 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0]) ||
1515 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0]))
1517 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(newctx->gl_polygon_offset_factor[0],
1518 newctx->gl_polygon_offset_units[0]))
1520 if ((oldctx->gl_sample_coverage_value[0] != newctx->gl_sample_coverage_value[0]) ||
1521 (oldctx->gl_sample_coverage_invert[0] != newctx->gl_sample_coverage_invert[0]))
1523 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(newctx->gl_sample_coverage_value[0],
1524 newctx->gl_sample_coverage_invert[0]))
1526 STATE_COMPARE(gl_fragment_shader_derivative_hint[0])
1528 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, newctx->gl_fragment_shader_derivative_hint[0]))
1533 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
1536 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint))
1538 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
1539 newctx->gl_scissor_box[1],
1540 newctx->gl_scissor_box[2],
1541 newctx->gl_scissor_box[3]))
1543 STATE_COMPARE(gl_pack_alignment[0])
1545 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT, newctx->gl_pack_alignment[0]))
1547 STATE_COMPARE(gl_unpack_alignment[0])
1549 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT, newctx->gl_unpack_alignment[0]))
1552 #ifdef COREGL_USE_MODULE_TRACEPATH
1553 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1554 #endif // COREGL_USE_MODULE_TRACEPATH
1557 #ifdef COREGL_USE_MODULE_TRACEPATH
1558 static void *trace_hint_vertex_attrib = NULL;
1559 trace_hint_vertex_attrib = tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1560 #endif // COREGL_USE_MODULE_TRACEPATH
1562 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1565 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++)
1567 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i])
1569 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_vertex_array_buf_id[i]))
1573 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1576 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1577 newctx->gl_vertex_array_size[i],
1578 newctx->gl_vertex_array_type[i],
1579 newctx->gl_vertex_array_normalized[i],
1580 newctx->gl_vertex_array_stride[i],
1581 newctx->gl_vertex_array_pointer[i]))
1583 STATES_COMPARE(gl_vertex_attrib_value + 4 * i, 4 * sizeof(GLfloat))
1585 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i, &newctx->gl_vertex_attrib_value[4 * i]))
1588 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE)
1590 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1594 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1598 STATE_COMPARE(gl_array_buffer_binding[0])
1600 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1602 STATE_COMPARE(gl_element_array_buffer_binding[0])
1604 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1609 #ifdef COREGL_USE_MODULE_TRACEPATH
1610 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1611 #endif // COREGL_USE_MODULE_TRACEPATH
1618 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
1619 if (unlikely(trace_state_flag == 1))
1620 fastpath_dump_context_states(newctx, 0);
1621 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
1623 #undef STATE_COMPARE
1624 #undef STATES_COMPARE