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 _get_stencil_max_mask()
50 GLuint stencil_bit = 0;
52 _orig_fastpath_glGetIntegerv(GL_STENCIL_BITS, (GLint *)&stencil_bit);
53 return (1 << stencil_bit) - 1;
57 init_modules_fastpath()
60 int fastpath_force_off_opt = 0;
62 LOG("[CoreGL] <Fastpath> : ");
64 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
65 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
67 if (fastpath_force_off_opt == 1)
69 LOG("\E[0;31;1m(DISABLED by force option)\E[0m ");
76 LOG("(%d) Fastpath enabled...\n", fastpath_opt);
77 fp_opt = FP_FAST_PATH;
80 LOG("(%d) Default API path enabled...\n", fastpath_opt);
81 fp_opt = FP_NORMAL_PATH;
85 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
90 deinit_modules_fastpath()
92 GLContext_List *current = NULL;
94 AST(mutex_lock(&ctx_list_access_mutex) == 1);
96 // Destroy remained context & Detect leaks
97 int retry_destroy = 0;
102 current = glctx_list;
105 if (current->cstate != NULL)
107 ERR("\E[0;31;1mWARNING : Context attached to [dpy=%p|rctx=%p] has not been completely destroyed.(leak)\E[0m\n", current->cstate->rdpy, current->cstate->rctx);
109 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
110 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
112 fastpath_remove_context_states_from_list(current->cstate, NULL);
117 glctx_list = current->next;
119 current = glctx_list;
121 if (retry_destroy == 0) break;
126 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
130 init_modules_tstate_fastpath(GLThreadState *tstate)
132 MY_MODULE_TSTATE *tstate_mt = NULL;
134 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
136 tstate_mt->binded_api = EGL_OPENGL_ES_API;
138 tstate->module_data[MY_MODULE_ID] = tstate_mt;
142 deinit_modules_tstate_fastpath(GLThreadState *tstate)
144 if (tstate->module_data[MY_MODULE_ID] != NULL)
146 free(tstate->module_data[MY_MODULE_ID]);
147 tstate->module_data[MY_MODULE_ID] = NULL;
152 fastpath_apply_overrides()
157 fastpath_apply_overrides_egl(1);
158 fastpath_apply_overrides_gl(1);
163 ERR("Invalide GL Override Option!!!\n");
170 fastpath_apply_overrides_egl(int enable)
172 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
173 # include "../../headers/sym_egl.h"
174 #undef _COREGL_SYMBOL
176 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
178 COREGL_OVERRIDE(fastpath_, eglBindAPI);
179 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
181 COREGL_OVERRIDE(fastpath_, eglCreateContext);
182 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
183 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
184 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
185 COREGL_OVERRIDE(fastpath_, eglQueryContext);
186 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
187 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
188 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
189 COREGL_OVERRIDE(fastpath_, eglTerminate);
194 fastpath_apply_overrides_gl(int enable)
196 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
197 # include "../../headers/sym_gl.h"
198 #undef _COREGL_SYMBOL
202 COREGL_OVERRIDE(fastpath_, glGetError);
204 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
205 COREGL_OVERRIDE(fastpath_, glGetFloatv);
206 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
208 COREGL_OVERRIDE(fastpath_, glActiveTexture);
209 COREGL_OVERRIDE(fastpath_, glGenTextures);
210 COREGL_OVERRIDE(fastpath_, glBindTexture);
211 COREGL_OVERRIDE(fastpath_, glIsTexture);
212 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
213 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
215 COREGL_OVERRIDE(fastpath_, glGenBuffers);
216 COREGL_OVERRIDE(fastpath_, glBindBuffer);
217 COREGL_OVERRIDE(fastpath_, glIsBuffer);
218 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
220 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
221 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
222 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
223 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
225 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
226 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
227 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
228 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
229 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
231 COREGL_OVERRIDE(fastpath_, glCreateShader);
232 COREGL_OVERRIDE(fastpath_, glCreateProgram);
233 COREGL_OVERRIDE(fastpath_, glAttachShader);
234 COREGL_OVERRIDE(fastpath_, glCompileShader);
235 COREGL_OVERRIDE(fastpath_, glShaderBinary);
236 COREGL_OVERRIDE(fastpath_, glDeleteShader);
237 COREGL_OVERRIDE(fastpath_, glDetachShader);
238 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
239 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
240 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
241 COREGL_OVERRIDE(fastpath_, glIsShader);
242 COREGL_OVERRIDE(fastpath_, glShaderSource);
243 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
244 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
245 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
246 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
247 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
248 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
249 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
250 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
251 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
252 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
253 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
254 COREGL_OVERRIDE(fastpath_, glIsProgram);
255 COREGL_OVERRIDE(fastpath_, glLinkProgram);
256 COREGL_OVERRIDE(fastpath_, glUseProgram);
257 COREGL_OVERRIDE(fastpath_, glValidateProgram);
259 COREGL_OVERRIDE(fastpath_, glBlendColor);
260 COREGL_OVERRIDE(fastpath_, glBlendEquation);
261 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
262 COREGL_OVERRIDE(fastpath_, glBlendFunc);
263 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
264 COREGL_OVERRIDE(fastpath_, glClearColor);
265 COREGL_OVERRIDE(fastpath_, glClearDepthf);
266 COREGL_OVERRIDE(fastpath_, glClearStencil);
267 COREGL_OVERRIDE(fastpath_, glColorMask);
268 COREGL_OVERRIDE(fastpath_, glCullFace);
269 COREGL_OVERRIDE(fastpath_, glDepthFunc);
270 COREGL_OVERRIDE(fastpath_, glDepthMask);
271 COREGL_OVERRIDE(fastpath_, glDepthRangef);
272 COREGL_OVERRIDE(fastpath_, glDisable);
273 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
274 COREGL_OVERRIDE(fastpath_, glEnable);
275 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
276 COREGL_OVERRIDE(fastpath_, glFrontFace);
277 COREGL_OVERRIDE(fastpath_, glHint);
278 COREGL_OVERRIDE(fastpath_, glLineWidth);
279 COREGL_OVERRIDE(fastpath_, glPixelStorei);
280 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
281 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
282 COREGL_OVERRIDE(fastpath_, glScissor);
283 COREGL_OVERRIDE(fastpath_, glStencilFunc);
284 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
285 COREGL_OVERRIDE(fastpath_, glStencilMask);
286 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
287 COREGL_OVERRIDE(fastpath_, glStencilOp);
288 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
289 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
290 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
291 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
292 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
293 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
294 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
295 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
296 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
297 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
298 COREGL_OVERRIDE(fastpath_, glViewport);
300 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
301 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
302 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
303 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
304 COREGL_OVERRIDE(fastpath_, glEGLImageTargetTexture2DOES);
309 LOG("\E[0;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
315 static inline GL_Object_Hash_Base *
316 _get_shared_object_hash(GL_Shared_Object_State *sostate, GL_Object_Type type)
320 case GL_OBJECT_TYPE_TEXTURE:
321 return &sostate->texture;
322 case GL_OBJECT_TYPE_BUFFER:
323 return &sostate->buffer;
324 case GL_OBJECT_TYPE_FRAMEBUFFER:
325 return &sostate->framebuffer;
326 case GL_OBJECT_TYPE_RENDERBUFFER:
327 return &sostate->renderbuffer;
328 case GL_OBJECT_TYPE_PROGRAM:
329 return &sostate->program;
335 static inline GL_Object_Hash_Base *
336 _get_shared_object_hash_real(GL_Shared_Object_State *sostate, GL_Object_Type type)
340 case GL_OBJECT_TYPE_TEXTURE:
341 return &sostate->texture_real;
342 case GL_OBJECT_TYPE_BUFFER:
343 return &sostate->buffer_real;
344 case GL_OBJECT_TYPE_FRAMEBUFFER:
345 return &sostate->framebuffer_real;
346 case GL_OBJECT_TYPE_RENDERBUFFER:
347 return &sostate->renderbuffer_real;
348 case GL_OBJECT_TYPE_PROGRAM:
349 return &sostate->program_real;
356 fastpath_add_context_state_to_list(const void *option, const int option_len, GLContextState *cstate, Mutex *mtx)
360 GLContext_List *current = NULL;
361 GLContext_List *newitm = NULL;
363 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
367 tid = get_current_thread();
369 current = glctx_list;
370 while (current != NULL)
372 if (current->option_len == option_len &&
373 memcmp(current->option, option, option_len) == 0 &&
374 current->thread_id == tid)
376 AST(current->cstate == cstate);
379 current = current->next;
382 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
385 ERR("Failed to create context list.\n");
389 newitm->cstate = cstate;
390 newitm->thread_id = tid;
391 newitm->option_len = option_len;
392 newitm->option = (void *)malloc(option_len);
393 memcpy(newitm->option, option, option_len);
395 if (glctx_list != NULL)
396 newitm->next = glctx_list;
417 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
423 fastpath_get_context_state_from_list(const void *option, const int option_len, Mutex *mtx)
425 GLContextState *ret = NULL;
426 GLContext_List *current = NULL;
429 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
431 tid = get_current_thread();
433 current = glctx_list;
434 while (current != NULL)
436 if (current->option_len == option_len &&
437 memcmp(current->option, option, option_len) == 0 &&
438 current->thread_id == tid)
440 ret = current->cstate;
443 current = current->next;
448 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
453 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
457 GLContext_List *olditm = NULL;
458 GLContext_List *current = NULL;
460 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
464 tid = get_current_thread();
465 current = glctx_list;
467 while (current != NULL)
469 if (current->cstate == cstate)
471 GLContext_List *nextitm = NULL;
474 olditm->next = current->next;
475 nextitm = olditm->next;
479 glctx_list = current->next;
480 nextitm = glctx_list;
488 current = current->next;
493 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
498 fastpath_sostate_init(GL_Shared_Object_State *sostate)
500 #define HASH_INIT(hash_base) \
501 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
502 hash_base.hash_size = GL_OBJECT_HASH_BASE;
504 HASH_INIT(sostate->texture);
505 HASH_INIT(sostate->buffer);
506 HASH_INIT(sostate->framebuffer);
507 HASH_INIT(sostate->renderbuffer);
508 HASH_INIT(sostate->program);
510 HASH_INIT(sostate->texture_real);
511 HASH_INIT(sostate->buffer_real);
512 HASH_INIT(sostate->framebuffer_real);
513 HASH_INIT(sostate->renderbuffer_real);
514 HASH_INIT(sostate->program_real);
520 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
522 int array_idx = data->hash_key & (hash_base->hash_size - 1);
523 if (hash_base->hash_field[array_idx] == NULL)
525 hash_base->hash_field[array_idx] = data;
529 GL_Object_Hash *current = hash_base->hash_field[array_idx];
532 AST(current->hash_key != data->hash_key);
533 current = current->next;
535 current->next = data;
538 hash_base->item_size++;
542 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
545 int array_idx = hash & (hash_base->hash_size - 1);
547 GL_Object_Hash *current = hash_base->hash_field[array_idx];
548 GL_Object_Hash *prev = NULL;
552 if (current->hash_key == hash)
555 prev->next = current->next;
557 hash_base->hash_field[array_idx] = current->next;
558 hash_base->item_size--;
562 current = current->next;
569 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
571 if (hash_base->item_size == 0) return;
573 for (int i = 0; i < hash_base->hash_size; i++)
575 if (hash_base->hash_field[i] != NULL)
577 GL_Object_Hash *current = hash_base->hash_field[i];
579 while (current != NULL)
581 GL_Object_Hash *current_next = current->next;
583 if (free_data == 1 && current->item != NULL)
589 hash_base->item_size--;
590 current = current_next;
597 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
599 #define HASH_DEINIT(hash_base, free_data) \
600 _free_hash_list(&hash_base, free_data); \
601 free(hash_base.hash_field); \
602 hash_base.hash_size = 0;
604 HASH_DEINIT(sostate->texture, 1);
605 HASH_DEINIT(sostate->buffer, 1);
606 HASH_DEINIT(sostate->framebuffer, 1);
607 HASH_DEINIT(sostate->renderbuffer, 1);
608 HASH_DEINIT(sostate->program, 1);
610 HASH_DEINIT(sostate->texture_real, 0);
611 HASH_DEINIT(sostate->buffer_real, 0);
612 HASH_DEINIT(sostate->framebuffer_real, 0);
613 HASH_DEINIT(sostate->renderbuffer_real, 0);
614 HASH_DEINIT(sostate->program_real, 0);
619 #define FIND_HASH(hash_base, key, ret) \
621 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
624 if (fh_current->hash_key == (key)) \
629 fh_current = fh_current->next; \
634 _sostate_hash_check(GL_Object_Hash_Base *hash_base)
636 if (hash_base->item_size < hash_base->hash_size)
639 int oldsize = hash_base->hash_size;
640 GL_Object_Hash **oldfield = hash_base->hash_field;
642 hash_base->hash_size = oldsize << 1;
643 hash_base->hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * hash_base->hash_size);
644 AST(hash_base->hash_field != NULL);
646 for (int i = 0; i < oldsize; i++)
648 if (oldfield[i] != NULL)
650 GL_Object_Hash *current = oldfield[i];
652 while (current != NULL)
654 GL_Object_Hash *current_next = current->next;
655 _add_hash(hash_base, current);
656 hash_base->item_size--;
657 current = current_next;
666 fastpath_sostate_create_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint real_name)
668 GLuint ret = _COREGL_INT_INIT_VALUE;
670 GL_Object_Hash_Base *hash_base = NULL;
671 GL_Object_Hash_Base *hash_base_real = NULL;
672 int newid = _COREGL_INT_INIT_VALUE;
674 hash_base = _get_shared_object_hash(sostate, type);
675 hash_base_real = _get_shared_object_hash_real(sostate, type);
677 newid = hash_base->last_id + 1;
678 if (newid >= GL_OBJECT_ID_LIMIT)
680 hash_base->is_looped = 1;
682 hash_base->last_id = 1;
685 if (hash_base->is_looped != 0)
688 int findingid = newid;
690 for (i = 0; i < GL_OBJECT_ID_LIMIT; i++)
692 GL_Object_Hash *exist_hash = NULL;
693 FIND_HASH(hash_base, findingid, exist_hash);
694 if (exist_hash == NULL)
700 if (findingid >= GL_OBJECT_ID_LIMIT) findingid = 1;
704 hash_base->last_id = newid;
707 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
709 newobj->id = (int)type + newid;
710 newobj->real_id = real_name;
711 newobj->ref_count = 1;
714 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
715 AST(newobj_hash != NULL);
716 newobj_hash->item = newobj;
717 newobj_hash->hash_key = newid;
718 _add_hash(hash_base, newobj_hash);
720 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
721 AST(newobj_hash_real != NULL);
722 newobj_hash_real->item = newobj;
723 newobj_hash_real->hash_key = real_name;
724 _add_hash(hash_base_real, newobj_hash_real);
727 _sostate_hash_check(hash_base);
728 _sostate_hash_check(hash_base_real);
736 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
737 if ((hash) < 0 || (hash) > GL_OBJECT_ID_LIMIT) { ret = 0; goto finish; } \
739 GL_Object_Hash *object_hash = NULL; \
740 FIND_HASH((hash_base), (hash), object_hash); \
741 if (object_hash == NULL) { ret = 0; goto finish; } \
742 (object) = object_hash->item; \
743 if ((object) == NULL) { ret = 0; goto finish; } \
747 fastpath_sostate_remove_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
749 GLuint ret = _COREGL_INT_INIT_VALUE;
751 GL_Object_Hash_Base *hash_base = NULL;
752 GL_Object_Hash_Base *hash_base_real = NULL;
753 GL_Object *object = NULL;
755 hash_base = _get_shared_object_hash(sostate, type);
756 hash_base_real = _get_shared_object_hash_real(sostate, type);
758 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
762 if (object->ref_count <= 0)
764 GL_Object_Hash *object_hash = NULL;
766 FIND_HASH(hash_base, object->id - (int)type, object_hash);
767 AST(object_hash != NULL);
768 _remove_hash(hash_base, object->id - (int)type);
772 FIND_HASH(hash_base_real, object->real_id, object_hash);
773 AST(object_hash != NULL);
774 _remove_hash(hash_base_real, object->real_id);
790 fastpath_sostate_get_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
792 GLuint ret = _COREGL_INT_INIT_VALUE;
794 GL_Object_Hash_Base *hash_base = NULL;
795 GL_Object *object = NULL;
797 hash_base = _get_shared_object_hash(sostate, type);
799 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
801 ret = object->real_id;
809 fastpath_sostate_set_object_tag(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag)
811 GLint ret = _COREGL_INT_INIT_VALUE;
813 GL_Object_Hash_Base *hash_base = NULL;
814 GL_Object *object = NULL;
815 int hash = _COREGL_INT_INIT_VALUE;
817 hash_base = _get_shared_object_hash(sostate, type);
819 hash = glue_name - (int)type;
821 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
832 fastpath_sostate_get_object_tag(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
836 GL_Object_Hash_Base *hash_base = NULL;
837 GL_Object *object = NULL;
839 hash_base = _get_shared_object_hash(sostate, type);
841 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
851 fastpath_sostate_find_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint real_name)
853 GLuint ret = _COREGL_INT_INIT_VALUE;
855 GL_Object_Hash_Base *hash_base_real = NULL;
856 GL_Object *object = NULL;
858 hash_base_real = _get_shared_object_hash_real(sostate, type);
860 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
870 fastpath_sostate_use_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
872 GLint ret = _COREGL_INT_INIT_VALUE;
874 GL_Object_Hash_Base *hash_base = NULL;
875 GL_Object *object = NULL;
877 hash_base = _get_shared_object_hash(sostate, type);
879 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
890 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
892 static struct timeval tv_last = { 0, 0 };
894 if (unlikely(trace_state_flag != 1)) return;
898 struct timeval tv_now = { 0, 0 };
899 AST(gettimeofday(&tv_now, NULL) == 0);
900 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC)
908 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
909 TRACE("\E[0;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n", getpid(), ctx);
910 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
912 #define PRINTF_CHAR_GLenum "%10d"
913 #define PRINTF_CHAR_GLboolean "%10d"
914 #define PRINTF_CHAR_GLint "%10d"
915 #define PRINTF_CHAR_GLsizei "%10u"
916 #define PRINTF_CHAR_GLuint "%10u"
917 #define PRINTF_CHAR_GLuintmask "0x%8X"
919 #define PRINTF_CHAR_GLclampf "%10.6f"
920 #define PRINTF_CHAR_GLfloat "%10.6f"
922 #define PRINTF_CHAR_GLvoidptr "%10p"
924 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
926 #define INITIAL_CTX initial_ctx
927 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
929 TYPE valuedata[SIZE]; \
930 TYPE *value = NULL; \
931 value = valuedata; GET_STMT; value = valuedata; \
932 TRACE("\E[0;37;1m %-30.30s : (\E[0m ", #NAME); \
933 for (int i = 0; i < SIZE; i++) \
937 TRACE("\n %-30.30s ", "");\
941 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
942 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
944 TRACE(" \E[0;37;1m)\E[0m\n"); \
946 # include "coregl_fastpath_state.h"
950 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
960 fastpath_init_context_states(GLGlueContext *ctx)
964 AST(mutex_lock(&init_context_mutex) == 1);
968 ERR("Context NULL\n");
973 AST(ctx->initialized == 0);
974 AST(ctx->sostate != NULL);
976 if (initial_ctx == NULL)
978 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
979 AST(initial_ctx != NULL);
981 //#define FORCE_DEFAULT_VALUE
982 #ifdef FORCE_DEFAULT_VALUE
983 # define INITIAL_CTX initial_ctx
984 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
987 TYPE valuedata[SIZE]; \
988 TYPE *value = NULL; \
989 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
990 value = valuedata; DEFAULT_STMT; value = valuedata; \
991 for (i = 0; i < SIZE; i++) \
993 if (*((char *)(&value[i])) == 0xcc) \
995 memset(&value[i], 0xaa, sizeof(TYPE)); \
996 value = valuedata; DEFAULT_STMT; value = valuedata; \
997 if (*((char *)(&value[i])) == 0xaa) \
999 ERR("\E[0;31;1mWARNING : GL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1003 initial_ctx->NAME[i] = value[i]; \
1006 # include "coregl_fastpath_state.h"
1010 # define INITIAL_CTX initial_ctx
1011 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1012 if (try_step == 1) \
1014 value = valuedata; DEFAULT_STMT; value = valuedata; \
1018 value = valuedata; FALLBACK_STMT; value = valuedata; \
1021 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1025 TYPE valuedata[SIZE]; \
1026 TYPE *value = NULL; \
1027 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1030 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1031 for (i = 0; i < SIZE; i++) \
1033 if (*((char *)(&value[i])) == 0xcc) \
1035 memset(&value[i], 0xaa, sizeof(TYPE)); \
1036 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1037 if (*((char *)(&value[i])) == 0xaa) \
1040 if (try_step == 2) \
1042 ERR("\E[0;31;1mWARNING : GL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1047 initial_ctx->NAME[i] = value[i]; \
1049 if (try_step != 2) \
1051 value = valuedata; DEFAULT_STMT; value = valuedata; \
1052 for (i = 0; i < SIZE; i++) \
1054 if (initial_ctx->NAME[i] != value[i]) \
1056 ERR("WARNING : GL-state '"#NAME"'[%d] value ["PRINTF_CHAR(TYPE)"] is different from SPEC-DEFAULT ["PRINTF_CHAR(TYPE)"]\n", i, ctx->NAME[i], value[i]); \
1061 while (try_step == 2); \
1063 # include "coregl_fastpath_state.h"
1064 # undef SET_GLUE_VALUE
1069 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS)
1071 ERR("\E[0;31;1mWARNING : Number of vertex attrib is too big! (%d-%d)\E[0m\n", MAX_VERTEX_ATTRIBS, initial_ctx->gl_num_vertex_attribs[0]);
1073 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS)
1075 ERR("\E[0;31;1mWARNING : Number of texture unit is too big! (%d-%d)\E[0m\n", MAX_TEXTURE_UNITS, initial_ctx->gl_num_tex_units[0]);
1081 #define INITIAL_CTX initial_ctx
1082 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1083 for (i = 0; i < SIZE; i++) \
1085 ctx->NAME[i] = initial_ctx->NAME[i]; \
1087 # include "coregl_fastpath_state.h"
1092 ctx->initialized = 1;
1097 AST(mutex_unlock(&init_context_mutex) == 1);
1102 #ifdef COREGL_USE_MODULE_TRACEPATH
1103 extern void *tracepath_api_trace_begin(const char *name, void *hint, int trace_total_time);
1104 extern void *tracepath_api_trace_end(const char *name, void *hint, int trace_total_time);
1107 #define CHECK_GL_ERROR(func) \
1110 int err = _orig_fastpath_glGetError(); \
1111 if (err != GL_NO_ERROR) \
1113 ERR("\E[0;31;1mERROR(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1119 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1122 unsigned char flag = 0;
1125 if (debug_nofp == 1)
1131 // Return if they're the same
1132 if (oldctx == newctx)
1138 #define STATE_COMPARE(state) \
1139 if ((oldctx->state) != (newctx->state))
1141 #define STATES_COMPARE(state_ptr, bytes) \
1142 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1145 #ifdef COREGL_USE_MODULE_TRACEPATH
1146 static void *trace_hint_glfinish = NULL;
1147 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1148 #endif // COREGL_USE_MODULE_TRACEPATH
1151 int err = _orig_fastpath_glGetError();
1152 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1153 oldctx->gl_error = err;
1156 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1158 #ifdef COREGL_USE_MODULE_TRACEPATH
1159 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1160 #endif // COREGL_USE_MODULE_TRACEPATH
1162 #ifdef COREGL_USE_MODULE_TRACEPATH
1163 static void *trace_hint_bindbuffers = NULL;
1164 trace_hint_bindbuffers = tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1165 #endif // COREGL_USE_MODULE_TRACEPATH
1168 //------------------//
1170 flag = oldctx->_bind_flag | newctx->_bind_flag;
1173 STATE_COMPARE(gl_array_buffer_binding[0])
1175 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1177 STATE_COMPARE(gl_element_array_buffer_binding[0])
1179 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1181 STATE_COMPARE(gl_framebuffer_binding[0])
1183 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER, newctx->gl_framebuffer_binding[0]))
1185 STATE_COMPARE(gl_renderbuffer_binding[0])
1187 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER, newctx->gl_renderbuffer_binding[0]))
1191 #ifdef COREGL_USE_MODULE_TRACEPATH
1192 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1193 #endif // COREGL_USE_MODULE_TRACEPATH
1196 //------------------//
1199 #ifdef COREGL_USE_MODULE_TRACEPATH
1200 static void *trace_hint_enable_states = NULL;
1201 trace_hint_enable_states = tracepath_api_trace_begin("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1202 #endif // COREGL_USE_MODULE_TRACEPATH
1204 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1207 STATE_COMPARE(gl_blend[0])
1209 if (newctx->gl_blend[0])
1211 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1214 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1216 STATE_COMPARE(gl_cull_face[0])
1218 if (newctx->gl_cull_face[0])
1220 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1223 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1225 STATE_COMPARE(gl_depth_test[0])
1227 if (newctx->gl_depth_test[0])
1229 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1232 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1234 STATE_COMPARE(gl_dither[0])
1236 if (newctx->gl_dither[0])
1238 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1241 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1246 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1249 STATE_COMPARE(gl_polygon_offset_fill[0])
1251 if (newctx->gl_polygon_offset_fill[0])
1253 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1256 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1258 STATE_COMPARE(gl_sample_alpha_to_coverage[0])
1260 if (newctx->gl_sample_alpha_to_coverage[0])
1262 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1265 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1267 STATE_COMPARE(gl_sample_coverage[0])
1269 if (newctx->gl_sample_coverage[0])
1271 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1274 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1276 STATE_COMPARE(gl_scissor_test[0])
1278 if (newctx->gl_scissor_test[0])
1280 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1283 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1285 STATE_COMPARE(gl_stencil_test[0])
1287 if (newctx->gl_stencil_test[0])
1289 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1292 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1296 #ifdef COREGL_USE_MODULE_TRACEPATH
1297 tracepath_api_trace_end("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1298 #endif // COREGL_USE_MODULE_TRACEPATH
1300 //------------------//
1302 #ifdef COREGL_USE_MODULE_TRACEPATH
1303 static void *trace_hint_clear_viewport = NULL;
1304 trace_hint_clear_viewport = tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1305 #endif // COREGL_USE_MODULE_TRACEPATH
1307 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1311 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint))
1313 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1314 newctx->gl_viewport[1],
1315 newctx->gl_viewport[2],
1316 newctx->gl_viewport[3]))
1319 STATE_COMPARE(gl_current_program[0])
1321 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1323 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf))
1325 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1326 newctx->gl_color_clear_value[1],
1327 newctx->gl_color_clear_value[2],
1328 newctx->gl_color_clear_value[3]))
1334 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1337 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean))
1339 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1340 newctx->gl_color_writemask[1],
1341 newctx->gl_color_writemask[2],
1342 newctx->gl_color_writemask[3]))
1344 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf))
1346 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1347 newctx->gl_depth_range[1]))
1349 STATE_COMPARE(gl_depth_clear_value[0])
1351 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1353 STATE_COMPARE(gl_depth_func[0])
1355 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1357 STATE_COMPARE(gl_depth_writemask[0])
1359 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1361 STATE_COMPARE(gl_cull_face_mode[0])
1363 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1368 #ifdef COREGL_USE_MODULE_TRACEPATH
1369 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1370 #endif // COREGL_USE_MODULE_TRACEPATH
1372 //------------------//
1374 #ifdef COREGL_USE_MODULE_TRACEPATH
1375 static void *trace_hint_bind_textures = NULL;
1376 trace_hint_bind_textures = tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1377 #endif // COREGL_USE_MODULE_TRACEPATH
1379 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1383 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++)
1385 STATE_COMPARE(gl_tex_2d_state[i])
1387 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1388 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D, newctx->gl_tex_2d_state[i]))
1391 STATE_COMPARE(gl_tex_cube_state[i])
1393 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1394 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP, newctx->gl_tex_cube_state[i]))
1398 // Restore active texture
1399 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1401 STATE_COMPARE(gl_generate_mipmap_hint[0])
1403 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT, newctx->gl_generate_mipmap_hint[0]))
1406 #ifdef COREGL_USE_MODULE_TRACEPATH
1407 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1408 #endif // COREGL_USE_MODULE_TRACEPATH
1410 //------------------//
1411 #ifdef COREGL_USE_MODULE_TRACEPATH
1412 static void *trace_hint_etc = NULL;
1413 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1414 #endif // COREGL_USE_MODULE_TRACEPATH
1416 flag = oldctx->_blend_flag | newctx->_blend_flag;
1419 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf))
1421 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
1422 newctx->gl_blend_color[1],
1423 newctx->gl_blend_color[2],
1424 newctx->gl_blend_color[3]))
1426 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
1427 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
1428 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
1429 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0]))
1431 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
1432 newctx->gl_blend_dst_rgb[0],
1433 newctx->gl_blend_src_alpha[0],
1434 newctx->gl_blend_dst_alpha[0]))
1436 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
1437 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0]))
1439 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
1444 //------------------//
1446 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
1449 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
1450 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
1451 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0]))
1453 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
1454 newctx->gl_stencil_func[0],
1455 newctx->gl_stencil_ref[0],
1456 newctx->gl_stencil_value_mask[0]))
1458 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
1459 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0]) ||
1460 (oldctx->gl_stencil_pass_depth_pass[0] != newctx->gl_stencil_pass_depth_pass[0]))
1462 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
1463 newctx->gl_stencil_fail[0],
1464 newctx->gl_stencil_pass_depth_fail[0],
1465 newctx->gl_stencil_pass_depth_pass[0]))
1468 STATE_COMPARE(gl_stencil_writemask[0])
1470 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT, newctx->gl_stencil_writemask[0]))
1476 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
1479 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
1480 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
1481 (oldctx->gl_stencil_back_value_mask[0] != newctx->gl_stencil_back_value_mask[0]))
1483 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
1484 newctx->gl_stencil_back_func[0],
1485 newctx->gl_stencil_back_ref[0],
1486 newctx->gl_stencil_back_value_mask[0]))
1488 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
1489 (oldctx->gl_stencil_back_pass_depth_fail[0] != newctx->gl_stencil_back_pass_depth_fail[0]) ||
1490 (oldctx->gl_stencil_back_pass_depth_pass[0] != newctx->gl_stencil_back_pass_depth_pass[0]))
1492 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
1493 newctx->gl_stencil_back_fail[0],
1494 newctx->gl_stencil_back_pass_depth_fail[0],
1495 newctx->gl_stencil_back_pass_depth_pass[0]))
1498 STATE_COMPARE(gl_stencil_back_writemask[0])
1500 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK, newctx->gl_stencil_back_writemask[0]))
1502 STATE_COMPARE(gl_stencil_clear_value[0])
1504 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
1508 //------------------//
1510 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
1513 STATE_COMPARE(gl_front_face[0])
1515 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
1517 STATE_COMPARE(gl_line_width[0])
1519 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
1521 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0]) ||
1522 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0]))
1524 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(newctx->gl_polygon_offset_factor[0],
1525 newctx->gl_polygon_offset_units[0]))
1527 if ((oldctx->gl_sample_coverage_value[0] != newctx->gl_sample_coverage_value[0]) ||
1528 (oldctx->gl_sample_coverage_invert[0] != newctx->gl_sample_coverage_invert[0]))
1530 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(newctx->gl_sample_coverage_value[0],
1531 newctx->gl_sample_coverage_invert[0]))
1536 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
1539 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint))
1541 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
1542 newctx->gl_scissor_box[1],
1543 newctx->gl_scissor_box[2],
1544 newctx->gl_scissor_box[3]))
1546 STATE_COMPARE(gl_pack_alignment[0])
1548 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT, newctx->gl_pack_alignment[0]))
1550 STATE_COMPARE(gl_unpack_alignment[0])
1552 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT, newctx->gl_unpack_alignment[0]))
1555 #ifdef COREGL_USE_MODULE_TRACEPATH
1556 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1557 #endif // COREGL_USE_MODULE_TRACEPATH
1560 #ifdef COREGL_USE_MODULE_TRACEPATH
1561 static void *trace_hint_vertex_attrib = NULL;
1562 trace_hint_vertex_attrib = tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1563 #endif // COREGL_USE_MODULE_TRACEPATH
1565 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1568 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++)
1570 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i])
1572 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_vertex_array_buf_id[i]))
1576 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1579 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1580 newctx->gl_vertex_array_size[i],
1581 newctx->gl_vertex_array_type[i],
1582 newctx->gl_vertex_array_normalized[i],
1583 newctx->gl_vertex_array_stride[i],
1584 newctx->gl_vertex_array_pointer[i]))
1586 STATES_COMPARE(gl_vertex_attrib_value + 4 * i, 4 * sizeof(GLfloat))
1588 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i, &newctx->gl_vertex_attrib_value[4 * i]))
1591 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE)
1593 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1597 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1601 STATE_COMPARE(gl_array_buffer_binding[0])
1603 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1605 STATE_COMPARE(gl_element_array_buffer_binding[0])
1607 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1612 #ifdef COREGL_USE_MODULE_TRACEPATH
1613 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1614 #endif // COREGL_USE_MODULE_TRACEPATH
1621 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
1622 if (unlikely(trace_state_flag == 1))
1623 fastpath_dump_context_states(newctx, 0);
1624 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
1626 #undef STATE_COMPARE
1627 #undef STATES_COMPARE