1 #include "coregl_fastpath.h"
10 #define _COREGL_SYMBOL(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;
29 static int api_gl_version=COREGL_GLAPI_2;
32 _state_get_texture_states(GLenum pname, GLint *params)
34 GLuint cur_active_tex = 0;
36 AST(initial_ctx != NULL);
38 _orig_fastpath_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
40 for (i = 0; i < initial_ctx->gl_num_tex_units[0]; i++)
42 _orig_fastpath_glActiveTexture(GL_TEXTURE0 + i);
43 _orig_fastpath_glGetIntegerv(pname, (GLint *)¶ms[i]);
45 _orig_fastpath_glActiveTexture(cur_active_tex);
49 _state_get_draw_buffers(GLenum *params)
51 AST(initial_ctx != NULL);
54 for (i = 0; i < initial_ctx->gl_num_draw_buffers[0]; i++)
56 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER0 + i, (GLint *)¶ms[i]);
61 _state_get_transform_feedback_buffer_bindings(GLuint *params)
63 AST(initial_ctx != NULL);
66 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0]; i++)
68 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, i, (GLint *)¶ms[i]);
73 _state_get_transform_feedback_buffer_bindings_offset(GLintptr *params)
75 AST(initial_ctx != NULL);
78 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0]; i++)
80 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_START, i, (GLint *)¶ms[i]);
85 _state_get_transform_feedback_buffer_bindings_size(GLsizeiptr *params)
87 AST(initial_ctx != NULL);
90 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0]; i++)
92 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE, i, (GLint *)¶ms[i]);
97 _state_get_uniform_buffer_bindings(GLuint *params)
99 AST(initial_ctx != NULL);
102 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++)
104 /////////////////////////////////////////////////////////////////////////////////
105 // XXXX : AVOID SEGFAULT in ADRENO
106 ((GLint *)params)[i] = 0;
107 // _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, i, (GLint *)¶ms[i]);
108 /////////////////////////////////////////////////////////////////////////////////
113 _state_get_uniform_buffer_bindings_offset(GLintptr *params)
115 AST(initial_ctx != NULL);
118 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++)
120 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_START, i, (GLint *)¶ms[i]);
125 _state_get_uniform_buffer_bindings_size(GLsizeiptr *params)
127 AST(initial_ctx != NULL);
130 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++)
132 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, i, (GLint *)¶ms[i]);
137 fastpath_state_get_draw_buffers(GLenum *params)
139 _state_get_draw_buffers(params);
143 init_modules_fastpath()
145 int fastpath_opt = 0;
146 int fastpath_force_off_opt = 0;
148 COREGL_LOG("[CoreGL] <Fastpath> : ");
150 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
151 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
153 if (fastpath_force_off_opt == 1)
155 COREGL_LOG("\E[40;31;1m(DISABLED by force option)\E[0m ");
159 switch (fastpath_opt)
162 COREGL_LOG("(%d) Fastpath enabled...\n", fastpath_opt);
163 fp_opt = FP_FAST_PATH;
166 COREGL_LOG("(%d) Default API path enabled...\n", fastpath_opt);
167 fp_opt = FP_NORMAL_PATH;
171 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
176 deinit_modules_fastpath()
178 GLContext_List *current = NULL;
180 AST(mutex_lock(&ctx_list_access_mutex) == 1);
182 // Destroy remained context & Detect leaks
183 int retry_destroy = 0;
188 current = glctx_list;
191 if (current->cstate != NULL)
193 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);
195 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
196 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
198 fastpath_remove_context_states_from_list(current->cstate, NULL);
203 glctx_list = current->next;
205 current = glctx_list;
207 if (retry_destroy == 0) break;
212 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
216 init_modules_tstate_fastpath(GLThreadState *tstate)
218 MY_MODULE_TSTATE *tstate_mt = NULL;
220 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
222 /* Prevent CID : 403055 */
223 if (tstate_mt != NULL)
225 tstate_mt->binded_api = EGL_OPENGL_ES_API;
227 tstate->module_data[MY_MODULE_ID] = tstate_mt;
232 deinit_modules_tstate_fastpath(GLThreadState *tstate)
234 if (tstate->module_data[MY_MODULE_ID] != NULL)
236 free(tstate->module_data[MY_MODULE_ID]);
237 tstate->module_data[MY_MODULE_ID] = NULL;
242 fastpath_apply_overrides()
247 fastpath_apply_overrides_egl(1);
248 fastpath_apply_overrides_gl(1);
253 COREGL_ERR("Invalide GL Override Option!!!\n");
260 fastpath_apply_overrides_egl(int enable)
262 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
263 # include "../../headers/sym_egl.h"
264 #undef _COREGL_SYMBOL
266 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
268 COREGL_OVERRIDE(fastpath_, eglBindAPI);
269 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
271 COREGL_OVERRIDE(fastpath_, eglCreateContext);
272 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
273 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
274 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
275 COREGL_OVERRIDE(fastpath_, eglQueryContext);
276 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
277 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
278 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
279 COREGL_OVERRIDE(fastpath_, eglTerminate);
280 COREGL_OVERRIDE(fastpath_, eglGetCurrentDisplay);
285 fastpath_apply_overrides_gl(int enable)
287 #define _COREGL_START_API(version) api_gl_version = version;
288 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
289 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
290 if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
292 # include "../../headers/sym_gl.h"
293 #undef _COREGL_SYMBOL
294 #undef _COREGL_START_API
295 #undef _COREGL_END_API
299 COREGL_OVERRIDE(fastpath_, glGetError);
300 COREGL_OVERRIDE(fastpath_, glGetString);
302 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
303 COREGL_OVERRIDE(fastpath_, glGetFloatv);
304 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
306 COREGL_OVERRIDE(fastpath_, glActiveTexture);
307 COREGL_OVERRIDE(fastpath_, glGenTextures);
308 COREGL_OVERRIDE(fastpath_, glBindTexture);
309 COREGL_OVERRIDE(fastpath_, glIsTexture);
310 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
311 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
313 COREGL_OVERRIDE(fastpath_, glGenBuffers);
314 COREGL_OVERRIDE(fastpath_, glBindBuffer);
315 COREGL_OVERRIDE(fastpath_, glIsBuffer);
316 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
318 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
319 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
320 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
321 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
322 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
324 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
325 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
326 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
327 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
328 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
330 COREGL_OVERRIDE(fastpath_, glCreateShader);
331 COREGL_OVERRIDE(fastpath_, glCreateProgram);
332 COREGL_OVERRIDE(fastpath_, glAttachShader);
333 COREGL_OVERRIDE(fastpath_, glCompileShader);
334 COREGL_OVERRIDE(fastpath_, glShaderBinary);
335 COREGL_OVERRIDE(fastpath_, glDeleteShader);
336 COREGL_OVERRIDE(fastpath_, glDetachShader);
337 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
338 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
339 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
340 COREGL_OVERRIDE(fastpath_, glIsShader);
341 COREGL_OVERRIDE(fastpath_, glShaderSource);
342 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
343 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
344 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
345 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
346 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
347 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
348 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
349 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
350 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
351 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
352 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
353 COREGL_OVERRIDE(fastpath_, glIsProgram);
354 COREGL_OVERRIDE(fastpath_, glLinkProgram);
355 COREGL_OVERRIDE(fastpath_, glUseProgram);
356 COREGL_OVERRIDE(fastpath_, glValidateProgram);
358 COREGL_OVERRIDE(fastpath_, glBlendColor);
359 COREGL_OVERRIDE(fastpath_, glBlendEquation);
360 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
361 COREGL_OVERRIDE(fastpath_, glBlendFunc);
362 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
363 COREGL_OVERRIDE(fastpath_, glClearColor);
364 COREGL_OVERRIDE(fastpath_, glClearDepthf);
365 COREGL_OVERRIDE(fastpath_, glClearStencil);
366 COREGL_OVERRIDE(fastpath_, glColorMask);
367 COREGL_OVERRIDE(fastpath_, glCullFace);
368 COREGL_OVERRIDE(fastpath_, glDepthFunc);
369 COREGL_OVERRIDE(fastpath_, glDepthMask);
370 COREGL_OVERRIDE(fastpath_, glDepthRangef);
371 COREGL_OVERRIDE(fastpath_, glDisable);
372 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
373 COREGL_OVERRIDE(fastpath_, glEnable);
374 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
375 COREGL_OVERRIDE(fastpath_, glFrontFace);
376 COREGL_OVERRIDE(fastpath_, glHint);
377 COREGL_OVERRIDE(fastpath_, glLineWidth);
378 COREGL_OVERRIDE(fastpath_, glPixelStorei);
379 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
380 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
381 COREGL_OVERRIDE(fastpath_, glScissor);
382 COREGL_OVERRIDE(fastpath_, glStencilFunc);
383 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
384 COREGL_OVERRIDE(fastpath_, glStencilMask);
385 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
386 COREGL_OVERRIDE(fastpath_, glStencilOp);
387 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
388 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
389 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
390 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
391 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
392 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
393 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
394 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
395 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
396 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
397 COREGL_OVERRIDE(fastpath_, glViewport);
399 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
400 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
402 COREGL_OVERRIDE(fastpath_, glUseProgramStagesEXT);
403 COREGL_OVERRIDE(fastpath_, glActiveShaderProgramEXT);
404 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
405 COREGL_OVERRIDE(fastpath_, glProgramUniform1iEXT);
406 COREGL_OVERRIDE(fastpath_, glProgramUniform2iEXT);
407 COREGL_OVERRIDE(fastpath_, glProgramUniform3iEXT);
408 COREGL_OVERRIDE(fastpath_, glProgramUniform4iEXT);
409 COREGL_OVERRIDE(fastpath_, glProgramUniform1fEXT);
410 COREGL_OVERRIDE(fastpath_, glProgramUniform2fEXT);
411 COREGL_OVERRIDE(fastpath_, glProgramUniform3fEXT);
412 COREGL_OVERRIDE(fastpath_, glProgramUniform4fEXT);
413 COREGL_OVERRIDE(fastpath_, glProgramUniform1ivEXT);
414 COREGL_OVERRIDE(fastpath_, glProgramUniform2ivEXT);
415 COREGL_OVERRIDE(fastpath_, glProgramUniform3ivEXT);
416 COREGL_OVERRIDE(fastpath_, glProgramUniform4ivEXT);
417 COREGL_OVERRIDE(fastpath_, glProgramUniform1fvEXT);
418 COREGL_OVERRIDE(fastpath_, glProgramUniform2fvEXT);
419 COREGL_OVERRIDE(fastpath_, glProgramUniform3fvEXT);
420 COREGL_OVERRIDE(fastpath_, glProgramUniform4fvEXT);
421 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fvEXT);
422 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fvEXT);
423 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fvEXT);
424 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
425 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
426 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
427 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
428 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
430 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
431 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
433 /* Start overriding GLES 3.0 */
434 if(driver_gl_version >= COREGL_GLAPI_3) {
435 COREGL_OVERRIDE(fastpath_, glReadBuffer);
437 COREGL_OVERRIDE(fastpath_, glGenQueries);
438 COREGL_OVERRIDE(fastpath_, glDeleteQueries);
439 COREGL_OVERRIDE(fastpath_, glIsQuery);
440 COREGL_OVERRIDE(fastpath_, glBeginQuery);
441 COREGL_OVERRIDE(fastpath_, glGetQueryiv);
442 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
443 COREGL_OVERRIDE(fastpath_, glDrawBuffers);
444 COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
446 COREGL_OVERRIDE(fastpath_, glBindVertexArray);
447 COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
448 COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
449 COREGL_OVERRIDE(fastpath_, glIsVertexArray);
451 COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
453 COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
454 COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
455 COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
456 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
458 COREGL_OVERRIDE(fastpath_, glBindBufferRange);
459 COREGL_OVERRIDE(fastpath_, glBindBufferBase);
460 COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
461 COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
462 COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
463 COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
464 COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
465 COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
466 COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
467 COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
468 COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
469 COREGL_OVERRIDE(fastpath_, glGetStringi);
470 COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
471 COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
472 COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
473 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
474 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
475 COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
476 COREGL_OVERRIDE(fastpath_, glGetInteger64v);
477 COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
478 COREGL_OVERRIDE(fastpath_, glGenSamplers);
479 COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
480 COREGL_OVERRIDE(fastpath_, glIsSampler);
481 COREGL_OVERRIDE(fastpath_, glBindSampler);
482 COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
483 COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
484 COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
485 COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
486 COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
487 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
488 COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
489 COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
490 COREGL_OVERRIDE(fastpath_, glProgramBinary);
491 COREGL_OVERRIDE(fastpath_, glProgramParameteri);
497 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
503 static inline GL_Object_Hash_Base *
504 _lock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
508 case GL_OBJECT_TYPE_QUERY:
509 return &ostate->query;
510 case GL_OBJECT_TYPE_TEXTURE:
511 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
512 return &ostate->shared->texture;
513 case GL_OBJECT_TYPE_BUFFER:
514 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
515 return &ostate->shared->buffer;
516 case GL_OBJECT_TYPE_FRAMEBUFFER:
517 return &ostate->framebuffer;
518 case GL_OBJECT_TYPE_RENDERBUFFER:
519 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
520 return &ostate->shared->renderbuffer;
521 case GL_OBJECT_TYPE_PROGRAM:
522 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
523 return &ostate->shared->program;
524 case GL_OBJECT_TYPE_VERTEXARRAY:
525 return &ostate->vertexarray;
526 case GL_OBJECT_TYPE_SAMPLER:
527 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
528 return &ostate->shared->sampler;
529 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
530 return &ostate->transformfeedback;
537 _unlock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
541 case GL_OBJECT_TYPE_TEXTURE:
542 case GL_OBJECT_TYPE_BUFFER:
543 case GL_OBJECT_TYPE_RENDERBUFFER:
544 case GL_OBJECT_TYPE_PROGRAM:
545 case GL_OBJECT_TYPE_SAMPLER:
546 AST(mutex_unlock(&ostate->shared->access_mutex) == 1);
552 static inline GL_Object_Hash_Base *
553 _lock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
557 case GL_OBJECT_TYPE_QUERY:
558 return &ostate->query_real;
559 case GL_OBJECT_TYPE_TEXTURE:
560 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
561 return &ostate->shared->texture_real;
562 case GL_OBJECT_TYPE_BUFFER:
563 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
564 return &ostate->shared->buffer_real;
565 case GL_OBJECT_TYPE_FRAMEBUFFER:
566 return &ostate->framebuffer_real;
567 case GL_OBJECT_TYPE_RENDERBUFFER:
568 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
569 return &ostate->shared->renderbuffer_real;
570 case GL_OBJECT_TYPE_PROGRAM:
571 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
572 return &ostate->shared->program_real;
573 case GL_OBJECT_TYPE_VERTEXARRAY:
574 return &ostate->vertexarray_real;
575 case GL_OBJECT_TYPE_SAMPLER:
576 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
577 return &ostate->shared->sampler_real;
578 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
579 return &ostate->transformfeedback_real;
586 _unlock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
590 case GL_OBJECT_TYPE_TEXTURE:
591 case GL_OBJECT_TYPE_BUFFER:
592 case GL_OBJECT_TYPE_RENDERBUFFER:
593 case GL_OBJECT_TYPE_PROGRAM:
594 case GL_OBJECT_TYPE_SAMPLER:
595 AST(mutex_unlock(&ostate->shared->real_access_mutex) == 1);
603 fastpath_add_context_state_to_list(const void *option, const int option_len, GLContextState *cstate, Mutex *mtx)
607 GLContext_List *current = NULL;
608 GLContext_List *newitm = NULL;
610 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
614 tid = get_current_thread();
616 current = glctx_list;
617 while (current != NULL)
619 if (current->option_len == option_len &&
620 memcmp(current->option, option, option_len) == 0 &&
621 current->thread_id == tid)
623 AST(current->cstate == cstate);
626 current = current->next;
629 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
632 COREGL_ERR("Failed to create context list.\n");
636 newitm->cstate = cstate;
637 newitm->thread_id = tid;
638 newitm->option_len = option_len;
639 newitm->option = (void *)malloc(option_len);
640 memcpy(newitm->option, option, option_len);
642 if (glctx_list != NULL)
643 newitm->next = glctx_list;
653 /* Prevent CID : 394333 - delete dead code */
660 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
666 fastpath_get_context_state_from_list(const void *option, const int option_len, Mutex *mtx)
668 GLContextState *ret = NULL;
669 GLContext_List *current = NULL;
672 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
674 tid = get_current_thread();
676 current = glctx_list;
677 while (current != NULL)
679 if (current->option_len == option_len &&
680 memcmp(current->option, option, option_len) == 0 &&
681 current->thread_id == tid)
683 ret = current->cstate;
686 current = current->next;
691 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
696 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
699 GLContext_List *olditm = NULL;
700 GLContext_List *current = NULL;
702 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
706 current = glctx_list;
708 while (current != NULL)
710 if (current->cstate == cstate)
712 GLContext_List *nextitm = NULL;
715 olditm->next = current->next;
716 nextitm = olditm->next;
720 glctx_list = current->next;
721 nextitm = glctx_list;
723 if (current->option != NULL)
725 AST(current->option_len > 0);
726 free(current->option);
727 current->option = NULL;
728 current->option_len = 0;
736 current = current->next;
741 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
747 #define HASH_INIT(hash_base) \
748 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
749 hash_base.hash_size = GL_OBJECT_HASH_BASE;
752 fastpath_ostate_init(GL_Object_State *ostate)
754 HASH_INIT(ostate->query);
755 HASH_INIT(ostate->framebuffer);
756 HASH_INIT(ostate->vertexarray);
757 HASH_INIT(ostate->transformfeedback);
759 HASH_INIT(ostate->query_real);
760 HASH_INIT(ostate->framebuffer_real);
761 HASH_INIT(ostate->vertexarray_real);
762 HASH_INIT(ostate->transformfeedback_real);
766 fastpath_sostate_init(GL_Shared_Object_State *sostate)
768 mutex_init(&sostate->access_mutex);
770 HASH_INIT(sostate->texture);
771 HASH_INIT(sostate->buffer);
772 HASH_INIT(sostate->renderbuffer);
773 HASH_INIT(sostate->program);
774 HASH_INIT(sostate->sampler);
776 HASH_INIT(sostate->texture_real);
777 HASH_INIT(sostate->buffer_real);
778 HASH_INIT(sostate->renderbuffer_real);
779 HASH_INIT(sostate->program_real);
780 HASH_INIT(sostate->sampler_real);
787 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
789 int array_idx = data->hash_key & (hash_base->hash_size - 1);
790 if (hash_base->hash_field[array_idx] == NULL)
792 hash_base->hash_field[array_idx] = data;
796 GL_Object_Hash *current = hash_base->hash_field[array_idx];
799 AST(current->hash_key != data->hash_key);
800 current = current->next;
802 current->next = data;
805 hash_base->item_size++;
809 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
812 int array_idx = hash & (hash_base->hash_size - 1);
814 GL_Object_Hash *current = hash_base->hash_field[array_idx];
815 GL_Object_Hash *prev = NULL;
819 if (current->hash_key == hash)
822 prev->next = current->next;
824 hash_base->hash_field[array_idx] = current->next;
825 hash_base->item_size--;
830 current = current->next;
837 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
839 if (hash_base->item_size == 0) return;
841 for (int i = 0; i < hash_base->hash_size; i++)
843 if (hash_base->hash_field[i] != NULL)
845 GL_Object_Hash *current = hash_base->hash_field[i];
847 while (current != NULL)
849 GL_Object_Hash *current_next = current->next;
851 if (free_data == 1 && current->item != NULL)
857 hash_base->item_size--;
858 current = current_next;
866 #define HASH_DEINIT(hash_base, free_data) \
867 _free_hash_list(&hash_base, free_data); \
868 free(hash_base.hash_field); \
869 hash_base.hash_size = 0;
872 fastpath_ostate_deinit(GL_Object_State *ostate)
874 HASH_DEINIT(ostate->query, 1);
875 HASH_DEINIT(ostate->framebuffer, 1);
876 HASH_DEINIT(ostate->vertexarray, 1);
877 HASH_DEINIT(ostate->transformfeedback, 1);
879 HASH_DEINIT(ostate->query_real, 0);
880 HASH_DEINIT(ostate->framebuffer_real, 0);
881 HASH_DEINIT(ostate->vertexarray_real, 0);
882 HASH_DEINIT(ostate->transformfeedback_real, 0);
886 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
888 HASH_DEINIT(sostate->texture, 1);
889 HASH_DEINIT(sostate->buffer, 1);
890 HASH_DEINIT(sostate->renderbuffer, 1);
891 HASH_DEINIT(sostate->program, 1);
892 HASH_DEINIT(sostate->sampler, 1);
894 HASH_DEINIT(sostate->texture_real, 0);
895 HASH_DEINIT(sostate->buffer_real, 0);
896 HASH_DEINIT(sostate->renderbuffer_real, 0);
897 HASH_DEINIT(sostate->program_real, 0);
898 HASH_DEINIT(sostate->sampler_real, 0);
905 #define FIND_HASH(hash_base, key, ret) \
907 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
910 if (fh_current->hash_key == (key)) \
915 fh_current = fh_current->next; \
920 _ostate_hash_check(GL_Object_Hash_Base *hash_base)
922 if (hash_base->item_size + 1 < hash_base->hash_size)
925 int oldsize = hash_base->hash_size;
926 GL_Object_Hash **oldfield = hash_base->hash_field;
928 hash_base->hash_size = oldsize << 1;
929 hash_base->hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * hash_base->hash_size);
930 AST(hash_base->hash_field != NULL);
932 for (int i = 0; i < oldsize; i++)
934 if (oldfield[i] != NULL)
936 GL_Object_Hash *current = oldfield[i];
938 while (current != NULL)
940 GL_Object_Hash *current_next = current->next;
941 _add_hash(hash_base, current);
942 hash_base->item_size--;
943 current = current_next;
952 fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name)
954 GLuint ret = _COREGL_INT_INIT_VALUE;
956 GL_Object_Hash_Base *hash_base = NULL;
957 GL_Object_Hash_Base *hash_base_real = NULL;
958 int newid = _COREGL_INT_INIT_VALUE;
960 hash_base = _lock_gl_object_hash(ostate, type);
961 hash_base_real = _lock_gl_object_hash_real(ostate, type);
963 /* Prevent CID : 393638 */
964 /* Prevent CID : 393538 */
965 if (hash_base == NULL || hash_base_real == NULL)
968 newid = hash_base->last_id + 1;
969 if (newid >= hash_base->hash_size)
971 hash_base->is_looped = 1;
973 hash_base->last_id = 1;
976 if (hash_base->is_looped != 0)
979 int findingid = newid;
981 for (i = 0; i < hash_base->hash_size; i++)
983 GL_Object_Hash *exist_hash = NULL;
984 FIND_HASH(hash_base, findingid, exist_hash);
985 if (exist_hash == NULL)
991 if (findingid >= hash_base->hash_size) findingid = 1;
995 hash_base->last_id = newid;
998 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
1000 newobj->id = (int)type + newid;
1001 newobj->real_id = real_name;
1002 newobj->ref_count = 1;
1005 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
1006 AST(newobj_hash != NULL);
1007 newobj_hash->item = newobj;
1008 newobj_hash->hash_key = newid;
1009 _add_hash(hash_base, newobj_hash);
1011 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
1012 AST(newobj_hash_real != NULL);
1013 newobj_hash_real->item = newobj;
1014 newobj_hash_real->hash_key = real_name;
1015 _add_hash(hash_base_real, newobj_hash_real);
1018 _ostate_hash_check(hash_base);
1019 _ostate_hash_check(hash_base_real);
1024 _unlock_gl_object_hash(ostate, type);
1025 _unlock_gl_object_hash_real(ostate, type);
1029 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
1030 if (((int)(hash)) < 0) { ret = 0; goto finish; } \
1032 GL_Object_Hash *object_hash = NULL; \
1033 FIND_HASH((hash_base), (int)(hash), object_hash); \
1034 if (object_hash == NULL) { ret = 0; goto finish; } \
1035 (object) = object_hash->item; \
1036 if ((object) == NULL) { ret = 0; goto finish; } \
1040 fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1042 GLuint ret = _COREGL_INT_INIT_VALUE;
1044 GL_Object_Hash_Base *hash_base = NULL;
1045 GL_Object_Hash_Base *hash_base_real = NULL;
1046 GL_Object *object = NULL;
1048 hash_base = _lock_gl_object_hash(ostate, type);
1049 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1051 /* Prevent CID : 400742 */
1052 if (hash_base == NULL || hash_base_real == NULL)
1055 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1057 object->ref_count--;
1059 if (object->ref_count <= 0)
1061 GL_Object_Hash *object_hash = NULL;
1063 FIND_HASH(hash_base, object->id - (int)type, object_hash);
1064 AST(object_hash != NULL);
1065 _remove_hash(hash_base, object->id - (int)type);
1069 FIND_HASH(hash_base_real, object->real_id, object_hash);
1070 AST(object_hash != NULL);
1071 _remove_hash(hash_base_real, object->real_id);
1083 _unlock_gl_object_hash(ostate, type);
1084 _unlock_gl_object_hash_real(ostate, type);
1089 fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1091 GLuint ret = _COREGL_INT_INIT_VALUE;
1093 GL_Object_Hash_Base *hash_base = NULL;
1094 GL_Object *object = NULL;
1096 hash_base = _lock_gl_object_hash(ostate, type);
1098 /* Prvent CID : 387143 */
1099 if (hash_base == NULL) goto finish;
1101 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1103 ret = object->real_id;
1107 _unlock_gl_object_hash(ostate, type);
1112 /* Check if the context's state contains object of a given type */
1114 fastpath_ostate_has_object_type(GL_Object_State *ostate, GL_Object_Type type)
1116 GLuint ret = _COREGL_INT_INIT_VALUE;
1118 GL_Object_Hash_Base *hash_base = NULL;
1119 GL_Object *object = NULL;
1120 hash_base = _lock_gl_object_hash(ostate, type);
1121 /* Prevent CID : 398319 */
1122 if(hash_base == NULL || hash_base->hash_field == 0)
1128 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, 1, object);
1130 ret = object->real_id;
1134 _unlock_gl_object_hash(ostate, type);
1140 fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag)
1142 GLint ret = _COREGL_INT_INIT_VALUE;
1144 GL_Object_Hash_Base *hash_base = NULL;
1145 GL_Object *object = NULL;
1146 int hash = _COREGL_INT_INIT_VALUE;
1148 hash_base = _lock_gl_object_hash(ostate, type);
1149 /* Prevent CID : 392281 */
1150 if (hash_base == NULL) goto finish;
1152 hash = glue_name - (int)type;
1154 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
1156 AST(object->tag == NULL);
1162 _unlock_gl_object_hash(ostate, type);
1167 fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1171 GL_Object_Hash_Base *hash_base = NULL;
1172 GL_Object *object = NULL;
1174 hash_base = _lock_gl_object_hash(ostate, type);
1176 /* Prevent CID : 389752 */
1177 if (hash_base == NULL) goto finish;
1179 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1185 _unlock_gl_object_hash(ostate, type);
1190 fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name)
1192 GLuint ret = _COREGL_INT_INIT_VALUE;
1194 GL_Object_Hash_Base *hash_base_real = NULL;
1195 GL_Object *object = NULL;
1197 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1198 /* Prevent CID : 398100 */
1199 if (hash_base_real == NULL) goto finish;
1201 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
1207 _unlock_gl_object_hash_real(ostate, type);
1212 fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1214 GLint ret = _COREGL_INT_INIT_VALUE;
1216 GL_Object_Hash_Base *hash_base = NULL;
1217 GL_Object *object = NULL;
1219 hash_base = _lock_gl_object_hash(ostate, type);
1221 /* Prevent CID : 390897 */
1222 if (hash_base == NULL) goto finish;
1224 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1226 object->ref_count++;
1231 _unlock_gl_object_hash(ostate, type);
1236 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
1238 static struct timeval tv_last = { 0, 0 };
1240 if (unlikely(trace_state_flag != 1)) return;
1244 struct timeval tv_now = { 0, 0 };
1245 AST(gettimeofday(&tv_now, NULL) == 0);
1246 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC)
1254 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1255 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n", getpid(), ctx);
1256 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1258 #define PRINTF_CHAR_GLenum "0x%8X"
1259 #define PRINTF_CHAR_GLboolean "%10d"
1260 #define PRINTF_CHAR_GLint "%10d"
1261 #define PRINTF_CHAR_GLsizei "%10u"
1262 #define PRINTF_CHAR_GLuint "%10u"
1263 #define PRINTF_CHAR_GLuintmask "0x%8X"
1264 #define PRINTF_CHAR_GLintptr "%10ld"
1265 #define PRINTF_CHAR_GLsizeiptr "%10ld"
1267 #define PRINTF_CHAR_GLclampf "%10.6f"
1268 #define PRINTF_CHAR_GLfloat "%10.6f"
1270 #define PRINTF_CHAR_GLvoidptr "%10p"
1272 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1274 #define _COREGL_START_API(version) api_gl_version = version;
1275 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1276 #define INITIAL_CTX initial_ctx
1277 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1279 TYPE valuedata[SIZE]; \
1280 TYPE *value = NULL; \
1281 if(api_gl_version <= driver_gl_version) { \
1282 value = valuedata; GET_STMT; value = valuedata; \
1283 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1284 for (int i = 0; i < SIZE; i++) \
1288 TRACE("\n %-30.30s ", "");\
1292 if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
1293 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1294 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1295 if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
1297 TRACE(" \E[40;37;1m)\E[0m\n"); \
1300 # include "coregl_fastpath_state.h"
1303 #undef _COREGL_START_API
1304 #undef _COREGL_END_API
1306 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1316 fastpath_init_context_states(GLGlueContext *ctx)
1320 AST(mutex_lock(&init_context_mutex) == 1);
1324 COREGL_ERR("Context NULL\n");
1329 AST(ctx->initialized == 0);
1330 AST(ctx->ostate.shared != NULL);
1332 if (initial_ctx == NULL)
1334 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1335 AST(initial_ctx != NULL);
1337 //#define FORCE_DEFAULT_VALUE
1338 #define _COREGL_START_API(version) api_gl_version = version;
1339 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1340 #ifdef FORCE_DEFAULT_VALUE
1341 # define INITIAL_CTX initial_ctx
1342 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1345 TYPE valuedata[SIZE]; \
1346 TYPE *value = NULL; \
1347 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1348 if(api_gl_version <= driver_gl_version) { \
1349 value = valuedata; DEFAULT_STMT; value = valuedata; \
1350 for (i = 0; i < SIZE; i++) \
1352 if (*((char *)(&value[i])) == 0xcc) \
1354 memset(&value[i], 0xaa, sizeof(TYPE)); \
1355 value = valuedata; DEFAULT_STMT; value = valuedata; \
1356 if (*((char *)(&value[i])) == 0xaa) \
1358 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1362 initial_ctx->NAME[i] = value[i]; \
1366 # include "coregl_fastpath_state.h"
1370 # define INITIAL_CTX initial_ctx
1371 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1372 if (try_step == 1) \
1374 value = valuedata; DEFAULT_STMT; value = valuedata; \
1378 value = valuedata; FALLBACK_STMT; value = valuedata; \
1381 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1385 TYPE valuedata[SIZE]; \
1386 TYPE *value = NULL; \
1387 _sym_glGetError(); \
1388 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1389 if(api_gl_version <= driver_gl_version) { \
1392 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1393 if (_sym_glGetError() == GL_INVALID_ENUM) \
1395 initial_ctx->NAME##_used = 0; \
1396 value = valuedata; DEFAULT_STMT; value = valuedata; \
1399 initial_ctx->NAME##_used = 1; \
1400 for (i = 0; i < SIZE; i++) \
1402 if (*((char *)(&value[i])) == 0xcc) \
1404 memset(&value[i], 0xaa, sizeof(TYPE)); \
1405 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1406 if (*((char *)(&value[i])) == 0xaa) \
1409 if (try_step == 2) \
1411 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1416 initial_ctx->NAME[i] = value[i]; \
1418 if (try_step != 2) \
1420 value = valuedata; DEFAULT_STMT; value = valuedata; \
1421 for (i = 0; i < SIZE; i++) \
1423 if (initial_ctx->NAME[i] != value[i]) \
1425 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]); \
1430 while (try_step == 2); \
1433 # include "coregl_fastpath_state.h"
1434 # undef SET_GLUE_VALUE
1438 # undef _COREGL_END_API
1439 # undef _COREGL_START_API
1441 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS)
1443 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]);
1445 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS)
1447 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]);
1449 if (initial_ctx->gl_num_transform_feedback_separate_attribs[0] > MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS)
1451 COREGL_WRN("\E[40;31;1mNumber of transform feedback separate attrib is too big! (%d-%d)\E[0m\n", MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, initial_ctx->gl_num_transform_feedback_separate_attribs[0]);
1453 if (initial_ctx->gl_num_uniform_buffer_bindings[0] > MAX_UNIFORM_BUFFER_BINDINGS)
1455 COREGL_WRN("\E[40;31;1mNumber of uniform buffer binding is too big! (%d-%d)\E[0m\n", MAX_UNIFORM_BUFFER_BINDINGS, initial_ctx->gl_num_uniform_buffer_bindings[0]);
1461 #define _COREGL_START_API(version) api_gl_version = version;
1462 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1463 #define INITIAL_CTX initial_ctx
1464 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1465 if(api_gl_version <= driver_gl_version) { \
1466 for (i = 0; i < SIZE; i++) \
1468 ctx->NAME[i] = initial_ctx->NAME[i]; \
1469 ctx->NAME##_used = initial_ctx->NAME##_used; \
1472 # include "coregl_fastpath_state.h"
1475 #undef _COREGL_START_API
1476 #undef _COREGL_END_API
1479 ctx->initialized = 1;
1484 AST(mutex_unlock(&init_context_mutex) == 1);
1489 #ifdef COREGL_USE_MODULE_TRACEPATH
1490 extern void *tracepath_api_trace_begin(const char *name, void *hint, int trace_total_time);
1491 extern void *tracepath_api_trace_end(const char *name, void *hint, int trace_total_time);
1494 #define CHECK_GL_ERROR(func) \
1497 int err = _orig_fastpath_glGetError(); \
1498 if (err != GL_NO_ERROR) \
1500 COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1506 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1509 unsigned char flag = 0;
1512 if (debug_nofp == 1)
1518 // Return if they're the same
1519 if (oldctx == newctx)
1525 #define STATE_COMPARE(state) \
1526 if ((oldctx->state) != (newctx->state))
1528 #define STATES_COMPARE(state_ptr, bytes) \
1529 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1532 #ifdef COREGL_USE_MODULE_TRACEPATH
1533 static void *trace_hint_glfinish = NULL;
1534 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1535 #endif // COREGL_USE_MODULE_TRACEPATH
1538 int err = _orig_fastpath_glGetError();
1539 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1540 oldctx->gl_error = err;
1543 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1545 #ifdef COREGL_USE_MODULE_TRACEPATH
1546 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1547 #endif // COREGL_USE_MODULE_TRACEPATH
1550 #ifdef COREGL_USE_MODULE_TRACEPATH
1551 static void *trace_hint_vertex_attrib = NULL;
1552 trace_hint_vertex_attrib = tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1553 #endif // COREGL_USE_MODULE_TRACEPATH
1555 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1558 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++)
1560 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i])
1562 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_vertex_array_buf_id[i]))
1566 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1569 STATE_COMPARE(gl_vertex_array_divisor[i])
1571 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribDivisor(i, newctx->gl_vertex_array_divisor[i]))
1574 if (newctx->gl_vertex_array_size[i] != 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]))
1585 if (newctx->gl_vertex_array_integer[0] == GL_TRUE)
1587 if (newctx->gl_vertex_array_type[0] == GL_UNSIGNED_INT)
1589 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4uiv(i, &newctx->gl_vertex_attrib_value_unsigned_integer[4 * i]))
1593 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4iv(i, &newctx->gl_vertex_attrib_value_integer[4 * i]))
1598 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i, &newctx->gl_vertex_attrib_value[4 * i]))
1602 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE)
1604 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1608 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1614 #ifdef COREGL_USE_MODULE_TRACEPATH
1615 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1616 #endif // COREGL_USE_MODULE_TRACEPATH
1619 #ifdef COREGL_USE_MODULE_TRACEPATH
1620 static void *trace_hint_bindbuffers = NULL;
1621 trace_hint_bindbuffers = tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1622 #endif // COREGL_USE_MODULE_TRACEPATH
1624 //------------------//
1626 flag = oldctx->_bind_flag1 | newctx->_bind_flag1;
1629 STATE_COMPARE(gl_array_buffer_binding[0])
1631 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1633 STATE_COMPARE(gl_element_array_buffer_binding[0])
1635 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1638 if (newctx->gl_framebuffer_binding_read_used == 1)
1640 STATE_COMPARE(gl_framebuffer_binding_read[0])
1642 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER, newctx->gl_framebuffer_binding_read[0]))
1644 STATE_COMPARE(gl_framebuffer_binding_draw[0])
1646 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, newctx->gl_framebuffer_binding_draw[0]))
1651 STATE_COMPARE(gl_framebuffer_binding[0])
1653 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER, newctx->gl_framebuffer_binding[0]))
1656 STATE_COMPARE(gl_renderbuffer_binding[0])
1658 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER, newctx->gl_renderbuffer_binding[0]))
1662 //------------------//
1664 flag = oldctx->_bind_flag2 | newctx->_bind_flag2;
1667 STATE_COMPARE(gl_copy_read_buffer_binding[0])
1669 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_READ_BUFFER, newctx->gl_copy_read_buffer_binding[0]))
1671 STATE_COMPARE(gl_copy_write_buffer_binding[0])
1673 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_WRITE_BUFFER, newctx->gl_copy_write_buffer_binding[0]))
1675 STATE_COMPARE(gl_pixel_pack_buffer_binding[0])
1677 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_PACK_BUFFER, newctx->gl_pixel_pack_buffer_binding[0]))
1679 STATE_COMPARE(gl_pixel_unpack_buffer_binding[0])
1681 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, newctx->gl_pixel_unpack_buffer_binding[0]))
1683 STATE_COMPARE(gl_transform_feedback_buffer_binding[0])
1685 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, newctx->gl_transform_feedback_buffer_binding[0]))
1687 STATE_COMPARE(gl_uniform_buffer_binding[0])
1689 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_UNIFORM_BUFFER, newctx->gl_uniform_buffer_binding[0]))
1692 #ifdef COREGL_USE_MODULE_TRACEPATH
1693 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1694 #endif // COREGL_USE_MODULE_TRACEPATH
1697 //------------------//
1700 #ifdef COREGL_USE_MODULE_TRACEPATH
1701 static void *trace_hint_enable_states = NULL;
1702 trace_hint_enable_states = tracepath_api_trace_begin("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1703 #endif // COREGL_USE_MODULE_TRACEPATH
1705 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1708 STATE_COMPARE(gl_blend[0])
1710 if (newctx->gl_blend[0])
1712 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1715 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1717 STATE_COMPARE(gl_cull_face[0])
1719 if (newctx->gl_cull_face[0])
1721 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1724 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1726 STATE_COMPARE(gl_depth_test[0])
1728 if (newctx->gl_depth_test[0])
1730 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1733 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1735 STATE_COMPARE(gl_dither[0])
1737 if (newctx->gl_dither[0])
1739 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1742 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1747 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1750 STATE_COMPARE(gl_polygon_offset_fill[0])
1752 if (newctx->gl_polygon_offset_fill[0])
1754 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1757 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1759 STATE_COMPARE(gl_sample_alpha_to_coverage[0])
1761 if (newctx->gl_sample_alpha_to_coverage[0])
1763 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1766 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1768 STATE_COMPARE(gl_sample_coverage[0])
1770 if (newctx->gl_sample_coverage[0])
1772 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1775 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1777 STATE_COMPARE(gl_scissor_test[0])
1779 if (newctx->gl_scissor_test[0])
1781 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1784 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1786 STATE_COMPARE(gl_stencil_test[0])
1788 if (newctx->gl_stencil_test[0])
1790 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1793 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1798 flag = oldctx->_enable_flag3 | newctx->_enable_flag3;
1801 STATE_COMPARE(gl_primitive_restart_fixed_index[0])
1803 if (newctx->gl_primitive_restart_fixed_index[0])
1805 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1808 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1810 STATE_COMPARE(gl_rasterizer_discard[0])
1812 if (newctx->gl_rasterizer_discard[0])
1814 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_RASTERIZER_DISCARD))
1817 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_RASTERIZER_DISCARD))
1821 #ifdef COREGL_USE_MODULE_TRACEPATH
1822 tracepath_api_trace_end("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1823 #endif // COREGL_USE_MODULE_TRACEPATH
1825 //------------------//
1827 #ifdef COREGL_USE_MODULE_TRACEPATH
1828 static void *trace_hint_clear_viewport = NULL;
1829 trace_hint_clear_viewport = tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1830 #endif // COREGL_USE_MODULE_TRACEPATH
1832 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1836 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint))
1838 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1839 newctx->gl_viewport[1],
1840 newctx->gl_viewport[2],
1841 newctx->gl_viewport[3]))
1844 STATE_COMPARE(gl_current_program[0])
1846 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1848 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf))
1850 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1851 newctx->gl_color_clear_value[1],
1852 newctx->gl_color_clear_value[2],
1853 newctx->gl_color_clear_value[3]))
1859 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1862 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean))
1864 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1865 newctx->gl_color_writemask[1],
1866 newctx->gl_color_writemask[2],
1867 newctx->gl_color_writemask[3]))
1869 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf))
1871 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1872 newctx->gl_depth_range[1]))
1874 STATE_COMPARE(gl_depth_clear_value[0])
1876 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1878 STATE_COMPARE(gl_depth_func[0])
1880 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1882 STATE_COMPARE(gl_depth_writemask[0])
1884 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1886 STATE_COMPARE(gl_cull_face_mode[0])
1888 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1893 #ifdef COREGL_USE_MODULE_TRACEPATH
1894 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1895 #endif // COREGL_USE_MODULE_TRACEPATH
1897 //------------------//
1899 #ifdef COREGL_USE_MODULE_TRACEPATH
1900 static void *trace_hint_bind_textures = NULL;
1901 trace_hint_bind_textures = tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1902 #endif // COREGL_USE_MODULE_TRACEPATH
1904 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1908 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++)
1910 STATE_COMPARE(gl_tex_2d_state[i])
1912 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1913 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D, newctx->gl_tex_2d_state[i]))
1915 STATE_COMPARE(gl_tex_3d_state[i])
1917 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1918 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_3D, newctx->gl_tex_3d_state[i]))
1920 STATE_COMPARE(gl_tex_2d_array_state[i])
1922 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1923 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_ARRAY, newctx->gl_tex_2d_array_state[i]))
1925 STATE_COMPARE(gl_tex_cube_state[i])
1927 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1928 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP, newctx->gl_tex_cube_state[i]))
1930 STATE_COMPARE(gl_tex_external_oes_state[i])
1932 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1933 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_EXTERNAL_OES, newctx->gl_tex_external_oes_state[i]))
1937 // Restore active texture
1938 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1940 STATE_COMPARE(gl_generate_mipmap_hint[0])
1942 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT, newctx->gl_generate_mipmap_hint[0]))
1945 #ifdef COREGL_USE_MODULE_TRACEPATH
1946 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1947 #endif // COREGL_USE_MODULE_TRACEPATH
1949 //------------------//
1950 #ifdef COREGL_USE_MODULE_TRACEPATH
1951 static void *trace_hint_etc = NULL;
1952 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1953 #endif // COREGL_USE_MODULE_TRACEPATH
1955 flag = oldctx->_blend_flag | newctx->_blend_flag;
1958 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf))
1960 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
1961 newctx->gl_blend_color[1],
1962 newctx->gl_blend_color[2],
1963 newctx->gl_blend_color[3]))
1965 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
1966 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
1967 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
1968 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0]))
1970 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
1971 newctx->gl_blend_dst_rgb[0],
1972 newctx->gl_blend_src_alpha[0],
1973 newctx->gl_blend_dst_alpha[0]))
1975 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
1976 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0]))
1978 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
1983 //------------------//
1985 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
1988 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
1989 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
1990 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0]))
1992 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
1993 newctx->gl_stencil_func[0],
1994 newctx->gl_stencil_ref[0],
1995 newctx->gl_stencil_value_mask[0]))
1997 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
1998 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0]) ||
1999 (oldctx->gl_stencil_pass_depth_pass[0] != newctx->gl_stencil_pass_depth_pass[0]))
2001 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
2002 newctx->gl_stencil_fail[0],
2003 newctx->gl_stencil_pass_depth_fail[0],
2004 newctx->gl_stencil_pass_depth_pass[0]))
2007 STATE_COMPARE(gl_stencil_writemask[0])
2009 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT, newctx->gl_stencil_writemask[0]))
2015 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
2018 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
2019 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
2020 (oldctx->gl_stencil_back_value_mask[0] != newctx->gl_stencil_back_value_mask[0]))
2022 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
2023 newctx->gl_stencil_back_func[0],
2024 newctx->gl_stencil_back_ref[0],
2025 newctx->gl_stencil_back_value_mask[0]))
2027 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
2028 (oldctx->gl_stencil_back_pass_depth_fail[0] != newctx->gl_stencil_back_pass_depth_fail[0]) ||
2029 (oldctx->gl_stencil_back_pass_depth_pass[0] != newctx->gl_stencil_back_pass_depth_pass[0]))
2031 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
2032 newctx->gl_stencil_back_fail[0],
2033 newctx->gl_stencil_back_pass_depth_fail[0],
2034 newctx->gl_stencil_back_pass_depth_pass[0]))
2037 STATE_COMPARE(gl_stencil_back_writemask[0])
2039 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK, newctx->gl_stencil_back_writemask[0]))
2041 STATE_COMPARE(gl_stencil_clear_value[0])
2043 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
2047 //------------------//
2049 flag = oldctx->_pixel_flag1 | newctx->_pixel_flag1;
2052 STATE_COMPARE(gl_pack_row_length[0])
2054 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ROW_LENGTH, newctx->gl_pack_row_length[0]))
2056 STATE_COMPARE(gl_pack_skip_rows[0])
2058 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_ROWS, newctx->gl_pack_skip_rows[0]))
2060 STATE_COMPARE(gl_pack_skip_pixels[0])
2062 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_PIXELS, newctx->gl_pack_skip_pixels[0]))
2064 STATE_COMPARE(gl_pack_alignment[0])
2066 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT, newctx->gl_pack_alignment[0]))
2071 flag = oldctx->_pixel_flag2 | newctx->_pixel_flag2;
2074 STATE_COMPARE(gl_unpack_row_length[0])
2076 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ROW_LENGTH, newctx->gl_unpack_row_length[0]))
2078 STATE_COMPARE(gl_unpack_skip_rows[0])
2080 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_ROWS, newctx->gl_unpack_skip_rows[0]))
2082 STATE_COMPARE(gl_unpack_skip_pixels[0])
2084 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_PIXELS, newctx->gl_unpack_skip_pixels[0]))
2086 STATE_COMPARE(gl_unpack_alignment[0])
2088 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT, newctx->gl_unpack_alignment[0]))
2090 STATE_COMPARE(gl_unpack_image_height[0])
2092 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, newctx->gl_unpack_image_height[0]))
2094 STATE_COMPARE(gl_unpack_skip_images[0])
2096 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_IMAGES, newctx->gl_unpack_skip_images[0]))
2100 //------------------//
2102 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
2105 STATE_COMPARE(gl_front_face[0])
2107 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
2109 STATE_COMPARE(gl_line_width[0])
2111 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
2113 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0]) ||
2114 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0]))
2116 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(newctx->gl_polygon_offset_factor[0],
2117 newctx->gl_polygon_offset_units[0]))
2119 if ((oldctx->gl_sample_coverage_value[0] != newctx->gl_sample_coverage_value[0]) ||
2120 (oldctx->gl_sample_coverage_invert[0] != newctx->gl_sample_coverage_invert[0]))
2122 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(newctx->gl_sample_coverage_value[0],
2123 newctx->gl_sample_coverage_invert[0]))
2125 STATE_COMPARE(gl_fragment_shader_derivative_hint[0])
2127 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, newctx->gl_fragment_shader_derivative_hint[0]))
2132 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
2135 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint))
2137 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
2138 newctx->gl_scissor_box[1],
2139 newctx->gl_scissor_box[2],
2140 newctx->gl_scissor_box[3]))
2145 flag = oldctx->_misc_flag3 | newctx->_misc_flag3;
2148 STATE_COMPARE(gl_read_buffer[0])
2150 CHECK_GL_ERROR(_orig_fastpath_glReadBuffer(newctx->gl_read_buffer[0]))
2152 STATES_COMPARE(gl_draw_buffers, 16 * sizeof(GLenum))
2154 int drawBuffSize = 16;
2155 /* If the context has only default framebuffer, then size of glDrawBuffers can only be 1 */
2156 if(fastpath_ostate_has_object_type(&newctx->ostate, GL_OBJECT_TYPE_FRAMEBUFFER) == 0) {
2160 CHECK_GL_ERROR(_orig_fastpath_glDrawBuffers(drawBuffSize, newctx->gl_draw_buffers))
2162 STATE_COMPARE(gl_vertex_array_binding[0])
2164 CHECK_GL_ERROR(_orig_fastpath_glBindVertexArray(newctx->gl_vertex_array_binding[0]))
2167 if (oldctx->gl_transform_feedback_active[0] == GL_TRUE && oldctx->gl_transform_feedback_paused[0] == GL_FALSE)
2169 CHECK_GL_ERROR(_orig_fastpath_glPauseTransformFeedback())
2171 STATE_COMPARE(gl_transform_feedback_binding[0])
2173 CHECK_GL_ERROR(_orig_fastpath_glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, newctx->gl_transform_feedback_binding[0]))
2175 if (newctx->gl_transform_feedback_active[0] == GL_TRUE && newctx->gl_transform_feedback_paused[0] == GL_FALSE)
2177 CHECK_GL_ERROR(_orig_fastpath_glResumeTransformFeedback())
2181 #ifdef COREGL_USE_MODULE_TRACEPATH
2182 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
2183 #endif // COREGL_USE_MODULE_TRACEPATH
2190 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
2191 if (unlikely(trace_state_flag == 1))
2192 fastpath_dump_context_states(newctx, 0);
2193 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
2195 #undef STATE_COMPARE
2196 #undef STATES_COMPARE