1 #include "coregl_fastpath.h"
11 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST = NULL;
12 # include "../../headers/sym_gl1.h"
13 # include "../../headers/sym_gl2.h"
14 # include "../../headers/sym_gl_common.h"
15 # include "../../headers/sym_egl.h"
18 Fastpath_Opt_Flag fp_opt = FP_UNKNOWN_PATH;
21 FILE *trace_fp = NULL;
23 GLenum FPGL_Error = GL_NO_ERROR;
25 GLGlueContext_List *gctx_list = NULL;
27 Mutex init_context_mutex = MUTEX_INITIALIZER;
28 GLGlueContext *initial_ctx = NULL;
30 Mutex ctx_list_access_mutex = MUTEX_INITIALIZER;
32 GLContext_List *glctx_list = NULL;
33 static int api_gl_version = COREGL_GLAPI_2;
36 _state_get_texture_states(GLenum pname, GLint *params)
38 GLuint cur_active_tex = 0;
40 AST(initial_ctx != NULL);
42 _orig_fastpath_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
44 for (i = 0; i < initial_ctx->gl_tex_units_num[0]; i++) {
45 _orig_fastpath_glActiveTexture(GL_TEXTURE0 + i);
46 _orig_fastpath_glGetIntegerv(pname, (GLint *)¶ms[i]);
48 _orig_fastpath_glActiveTexture(cur_active_tex);
52 _state_get_draw_buffers(GLenum *params)
54 AST(initial_ctx != NULL);
57 for (i = 0; i < initial_ctx->gl_draw_buffers_num[0]; i++) {
58 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER0 + i, (GLint *)¶ms[i]);
63 _state_get_transform_feedback_buffer_bindings(GLuint *params)
65 AST(initial_ctx != NULL);
68 for (i = 0; i < initial_ctx->gl_transform_feedback_buffer_binding_num[0];
70 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, i,
76 _state_get_transform_feedback_buffer_bindings_offset(GLintptr *params)
78 AST(initial_ctx != NULL);
81 for (i = 0; i < initial_ctx->gl_transform_feedback_buffer_binding_num[0];
83 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_START, i,
89 _state_get_transform_feedback_buffer_bindings_size(GLsizeiptr *params)
91 AST(initial_ctx != NULL);
94 for (i = 0; i < initial_ctx->gl_transform_feedback_buffer_binding_num[0];
96 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE, i,
102 _state_get_uniform_buffer_bindings(GLuint *params)
104 AST(initial_ctx != NULL);
107 for (i = 0; i < initial_ctx->gl_uniform_buffer_binding_num[0]; i++) {
108 /////////////////////////////////////////////////////////////////////////////////
109 // XXXX : AVOID SEGFAULT in ADRENO
110 ((GLint *)params)[i] = 0;
111 // _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, i, (GLint *)¶ms[i]);
112 /////////////////////////////////////////////////////////////////////////////////
117 _state_get_uniform_buffer_bindings_offset(GLintptr *params)
119 AST(initial_ctx != NULL);
122 for (i = 0; i < initial_ctx->gl_uniform_buffer_binding_num[0]; i++) {
123 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_START, i, (GLint *)¶ms[i]);
128 _state_get_uniform_buffer_bindings_size(GLsizeiptr *params)
130 AST(initial_ctx != NULL);
133 for (i = 0; i < initial_ctx->gl_uniform_buffer_binding_num[0]; i++) {
134 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, i, (GLint *)¶ms[i]);
138 /* shader storage buffer */
140 _state_get_shader_storage_buffer_bindings(GLuint *params)
142 AST(initial_ctx != NULL);
145 for (i = 0; i < initial_ctx->gl_shader_storage_buffer_binding_num[0]; i++) {
146 _orig_fastpath_glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_BINDING, i, (GLint *)¶ms[i]);
151 _state_get_shader_storage_buffer_bindings_offset(GLintptr *params)
153 AST(initial_ctx != NULL);
156 for (i = 0; i < initial_ctx->gl_shader_storage_buffer_binding_num[0]; i++) {
157 _orig_fastpath_glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_START, i, (GLint *)¶ms[i]);
162 _state_get_shader_storage_buffer_bindings_size(GLsizeiptr *params)
164 AST(initial_ctx != NULL);
167 for (i = 0; i < initial_ctx->gl_shader_storage_buffer_binding_num[0]; i++) {
168 _orig_fastpath_glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_SIZE, i, (GLint *)¶ms[i]);
172 /* atomic counter buffer */
174 _state_get_atomic_counter_buffer_bindings(GLuint *params)
176 AST(initial_ctx != NULL);
179 for (i = 0; i < initial_ctx->gl_atomic_counter_buffer_binding_num[0]; i++) {
180 _orig_fastpath_glGetIntegeri_v(GL_ATOMIC_COUNTER_BUFFER_BINDING, i, (GLint *)¶ms[i]);
185 _state_get_atomic_counter_buffer_bindings_offset(GLintptr *params)
187 AST(initial_ctx != NULL);
190 for (i = 0; i < initial_ctx->gl_atomic_counter_buffer_binding_num[0]; i++) {
191 _orig_fastpath_glGetIntegeri_v(GL_ATOMIC_COUNTER_BUFFER_START, i, (GLint *)¶ms[i]);
196 _state_get_atomic_counter_buffer_bindings_size(GLsizeiptr *params)
198 AST(initial_ctx != NULL);
201 for (i = 0; i < initial_ctx->gl_atomic_counter_buffer_binding_num[0]; i++) {
202 _orig_fastpath_glGetIntegeri_v(GL_ATOMIC_COUNTER_BUFFER_SIZE, i, (GLint *)¶ms[i]);
207 fastpath_state_get_draw_buffers(GLenum *params)
209 _state_get_draw_buffers(params);
213 init_modules_fastpath()
215 int fastpath_opt = 0;
216 int fastpath_force_off_opt = 0;
218 COREGL_LOG("[CoreGL] <Fastpath> : ");
220 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
221 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
223 if (fastpath_force_off_opt == 1) {
224 COREGL_LOG("\E[40;31;1m(DISABLED by force option)\E[0m ");
228 switch (fastpath_opt) {
230 COREGL_LOG("(%d) Fastpath enabled...\n", fastpath_opt);
231 fp_opt = FP_FAST_PATH;
234 COREGL_LOG("(%d) Default API path enabled...\n", fastpath_opt);
235 fp_opt = FP_NORMAL_PATH;
239 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
244 deinit_modules_fastpath()
246 GLContext_List *current = NULL;
248 AST(mutex_lock(&ctx_list_access_mutex) == 1);
250 // Destroy remained context & Detect leaks
251 int retry_destroy = 0;
255 current = glctx_list;
257 if (current->cstate != NULL) {
258 COREGL_WRN("\E[40;31;1mContext attached to [dpy=%p|rctx=%p] has not been completely destroyed.(leak)\E[0m\n",
259 current->cstate->rdpy, current->cstate->rctx);
261 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE,
262 EGL_NO_SURFACE, EGL_NO_CONTEXT);
263 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
265 fastpath_remove_context_states_from_list(current->cstate, NULL);
270 glctx_list = current->next;
272 current = glctx_list;
274 if (retry_destroy == 0) break;
279 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
283 init_modules_tstate_fastpath(GLThreadState *tstate)
285 MY_MODULE_TSTATE *tstate_mt = NULL;
287 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
289 tstate_mt->binded_api = EGL_OPENGL_ES_API;
291 tstate->module_data[MY_MODULE_ID] = tstate_mt;
295 deinit_modules_tstate_fastpath(GLThreadState *tstate)
297 if (tstate->module_data[MY_MODULE_ID] != NULL) {
298 free(tstate->module_data[MY_MODULE_ID]);
299 tstate->module_data[MY_MODULE_ID] = NULL;
304 fastpath_apply_overrides()
308 fastpath_apply_overrides_egl(1);
309 fastpath_apply_overrides_gl(1);
314 COREGL_ERR("Invalide GL Override Option!!!\n");
321 fastpath_apply_overrides_egl(int enable)
323 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
324 # include "../../headers/sym_egl.h"
325 #undef _COREGL_SYMBOL
327 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
329 COREGL_OVERRIDE(fastpath_, eglBindAPI);
330 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
332 COREGL_OVERRIDE(fastpath_, eglCreateContext);
333 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
334 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
335 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
336 COREGL_OVERRIDE(fastpath_, eglQueryContext);
337 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
338 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
339 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
340 COREGL_OVERRIDE(fastpath_, eglTerminate);
341 COREGL_OVERRIDE(fastpath_, eglGetCurrentDisplay);
346 fastpath_apply_overrides_gl(int enable)
348 #define _COREGL_START_API(version) api_gl_version = version;
349 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
350 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
351 if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
353 # include "../../headers/sym_gl1.h"
354 # include "../../headers/sym_gl2.h"
355 # include "../../headers/sym_gl_common.h"
356 #undef _COREGL_SYMBOL
357 #undef _COREGL_START_API
358 #undef _COREGL_END_API
360 if (debug_nofp != 1) {
361 if (driver_gl_version >= COREGL_GLAPI_1) {
362 COREGL_OVERRIDE(fastpath_, glClientActiveTexture);
363 COREGL_OVERRIDE(fastpath_, glSampleCoveragex);
364 COREGL_OVERRIDE(fastpath_, glVertexPointer);
367 COREGL_OVERRIDE(fastpath_, glGetError);
368 COREGL_OVERRIDE(fastpath_, glGetString);
370 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
371 COREGL_OVERRIDE(fastpath_, glGetFloatv);
372 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
374 COREGL_OVERRIDE(fastpath_, glActiveTexture);
375 COREGL_OVERRIDE(fastpath_, glGenTextures);
376 COREGL_OVERRIDE(fastpath_, glBindTexture);
377 COREGL_OVERRIDE(fastpath_, glIsTexture);
378 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
379 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
381 COREGL_OVERRIDE(fastpath_, glGenBuffers);
382 COREGL_OVERRIDE(fastpath_, glBindBuffer);
383 COREGL_OVERRIDE(fastpath_, glIsBuffer);
384 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
386 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
387 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
388 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
389 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
390 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
392 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
393 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
394 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
395 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
396 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
398 COREGL_OVERRIDE(fastpath_, glCreateShader);
399 COREGL_OVERRIDE(fastpath_, glCreateProgram);
400 COREGL_OVERRIDE(fastpath_, glAttachShader);
401 COREGL_OVERRIDE(fastpath_, glCompileShader);
402 COREGL_OVERRIDE(fastpath_, glShaderBinary);
403 COREGL_OVERRIDE(fastpath_, glDeleteShader);
404 COREGL_OVERRIDE(fastpath_, glDetachShader);
405 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
406 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
407 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
408 COREGL_OVERRIDE(fastpath_, glIsShader);
409 COREGL_OVERRIDE(fastpath_, glShaderSource);
410 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
411 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
412 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
413 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
414 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
415 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
416 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
417 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
418 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
419 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
420 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
421 COREGL_OVERRIDE(fastpath_, glIsProgram);
422 COREGL_OVERRIDE(fastpath_, glLinkProgram);
423 COREGL_OVERRIDE(fastpath_, glUseProgram);
424 COREGL_OVERRIDE(fastpath_, glValidateProgram);
426 COREGL_OVERRIDE(fastpath_, glBlendColor);
427 COREGL_OVERRIDE(fastpath_, glBlendEquation);
428 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
429 COREGL_OVERRIDE(fastpath_, glBlendFunc);
430 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
431 COREGL_OVERRIDE(fastpath_, glClearColor);
432 COREGL_OVERRIDE(fastpath_, glClearDepthf);
433 COREGL_OVERRIDE(fastpath_, glClearStencil);
434 COREGL_OVERRIDE(fastpath_, glColorMask);
435 COREGL_OVERRIDE(fastpath_, glCullFace);
436 COREGL_OVERRIDE(fastpath_, glDepthFunc);
437 COREGL_OVERRIDE(fastpath_, glDepthMask);
438 COREGL_OVERRIDE(fastpath_, glDepthRangef);
439 COREGL_OVERRIDE(fastpath_, glDisable);
440 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
441 COREGL_OVERRIDE(fastpath_, glEnable);
442 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
443 COREGL_OVERRIDE(fastpath_, glFrontFace);
444 COREGL_OVERRIDE(fastpath_, glHint);
445 COREGL_OVERRIDE(fastpath_, glLineWidth);
446 COREGL_OVERRIDE(fastpath_, glPixelStorei);
447 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
448 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
449 COREGL_OVERRIDE(fastpath_, glScissor);
450 COREGL_OVERRIDE(fastpath_, glStencilFunc);
451 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
452 COREGL_OVERRIDE(fastpath_, glStencilMask);
453 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
454 COREGL_OVERRIDE(fastpath_, glStencilOp);
455 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
456 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
457 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
458 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
459 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
460 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
461 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
462 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
463 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
464 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
465 COREGL_OVERRIDE(fastpath_, glViewport);
467 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
468 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
470 COREGL_OVERRIDE(fastpath_, glUseProgramStagesEXT);
471 COREGL_OVERRIDE(fastpath_, glActiveShaderProgramEXT);
472 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
473 COREGL_OVERRIDE(fastpath_, glProgramUniform1iEXT);
474 COREGL_OVERRIDE(fastpath_, glProgramUniform2iEXT);
475 COREGL_OVERRIDE(fastpath_, glProgramUniform3iEXT);
476 COREGL_OVERRIDE(fastpath_, glProgramUniform4iEXT);
477 COREGL_OVERRIDE(fastpath_, glProgramUniform1fEXT);
478 COREGL_OVERRIDE(fastpath_, glProgramUniform2fEXT);
479 COREGL_OVERRIDE(fastpath_, glProgramUniform3fEXT);
480 COREGL_OVERRIDE(fastpath_, glProgramUniform4fEXT);
481 COREGL_OVERRIDE(fastpath_, glProgramUniform1ivEXT);
482 COREGL_OVERRIDE(fastpath_, glProgramUniform2ivEXT);
483 COREGL_OVERRIDE(fastpath_, glProgramUniform3ivEXT);
484 COREGL_OVERRIDE(fastpath_, glProgramUniform4ivEXT);
485 COREGL_OVERRIDE(fastpath_, glProgramUniform1fvEXT);
486 COREGL_OVERRIDE(fastpath_, glProgramUniform2fvEXT);
487 COREGL_OVERRIDE(fastpath_, glProgramUniform3fvEXT);
488 COREGL_OVERRIDE(fastpath_, glProgramUniform4fvEXT);
489 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fvEXT);
490 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fvEXT);
491 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fvEXT);
493 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
494 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
496 COREGL_OVERRIDE(fastpath_, glBindFramebufferOES);
497 COREGL_OVERRIDE(fastpath_, glBindRenderbufferOES);
498 COREGL_OVERRIDE(fastpath_, glClearBufferfi);
499 COREGL_OVERRIDE(fastpath_, glClearBufferfv);
500 COREGL_OVERRIDE(fastpath_, glClearBufferiv);
501 COREGL_OVERRIDE(fastpath_, glClearBufferuiv);
502 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffersOES);
503 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffersOES);
504 COREGL_OVERRIDE(fastpath_, glDepthRangefOES);
505 COREGL_OVERRIDE(fastpath_, glDepthRangexOES);
506 COREGL_OVERRIDE(fastpath_, glFramebufferParameteri);
507 COREGL_OVERRIDE(fastpath_, glGetFramebufferParameteriv);
508 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbufferOES);
509 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DOES);
510 COREGL_OVERRIDE(fastpath_, glGenFramebuffersOES);
511 COREGL_OVERRIDE(fastpath_, glGenRenderbuffersOES);
512 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameterivOES);
513 COREGL_OVERRIDE(fastpath_, glGetQueryObjecti64vEXT);
514 COREGL_OVERRIDE(fastpath_, glGetQueryObjectivEXT);
515 COREGL_OVERRIDE(fastpath_, glGetQueryObjectui64vEXT);
516 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuivEXT);
517 COREGL_OVERRIDE(fastpath_, glGetQueryivEXT);
518 COREGL_OVERRIDE(fastpath_, glBeginQueryEXT);
519 COREGL_OVERRIDE(fastpath_, glDeleteQueriesEXT);
520 COREGL_OVERRIDE(fastpath_, glGenQueriesEXT);
521 COREGL_OVERRIDE(fastpath_, glIsFramebufferOES);
522 COREGL_OVERRIDE(fastpath_, glIsQueryEXT);
523 COREGL_OVERRIDE(fastpath_, glIsRenderbufferOES);
524 COREGL_OVERRIDE(fastpath_, glBlendEquationOES);
525 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparateOES);
526 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparateOES);
527 COREGL_OVERRIDE(fastpath_, glPolygonOffsetxOES);
528 COREGL_OVERRIDE(fastpath_, glLineWidthxOES);
529 COREGL_OVERRIDE(fastpath_, glSampleCoveragexOES);
530 COREGL_OVERRIDE(fastpath_, glQueryCounterEXT);
531 COREGL_OVERRIDE(fastpath_, glBindVertexArrayOES);
532 COREGL_OVERRIDE(fastpath_, glDeleteVertexArraysOES);
533 COREGL_OVERRIDE(fastpath_, glGenVertexArraysOES);
534 COREGL_OVERRIDE(fastpath_, glIsVertexArrayOES);
535 COREGL_OVERRIDE(fastpath_, glClearDepthfOES );
536 COREGL_OVERRIDE(fastpath_, glClearDepthxOES );
537 /* Start overriding GLES 3.0 */
538 if (driver_gl_version >= COREGL_GLAPI_3) {
539 COREGL_OVERRIDE(fastpath_, glReadBuffer);
541 COREGL_OVERRIDE(fastpath_, glGenQueries);
542 COREGL_OVERRIDE(fastpath_, glDeleteQueries);
543 COREGL_OVERRIDE(fastpath_, glIsQuery);
544 COREGL_OVERRIDE(fastpath_, glBeginQuery);
545 COREGL_OVERRIDE(fastpath_, glGetQueryiv);
546 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
547 COREGL_OVERRIDE(fastpath_, glDrawBuffers);
548 COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
550 COREGL_OVERRIDE(fastpath_, glBindVertexArray);
551 COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
552 COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
553 COREGL_OVERRIDE(fastpath_, glIsVertexArray);
555 COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
557 COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
558 COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
559 COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
560 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
562 COREGL_OVERRIDE(fastpath_, glBindBufferRange);
563 COREGL_OVERRIDE(fastpath_, glBindBufferBase);
564 COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
565 COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
566 COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
567 COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
568 COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
569 COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
570 COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
571 COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
572 COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
573 COREGL_OVERRIDE(fastpath_, glGetStringi);
574 COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
575 COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
576 COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
577 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
578 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
579 COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
580 COREGL_OVERRIDE(fastpath_, glGetInteger64v);
581 COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
582 COREGL_OVERRIDE(fastpath_, glGenSamplers);
583 COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
584 COREGL_OVERRIDE(fastpath_, glIsSampler);
585 COREGL_OVERRIDE(fastpath_, glBindSampler);
586 COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
587 COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
588 COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
589 COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
590 COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
591 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
592 COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
593 COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
594 COREGL_OVERRIDE(fastpath_, glProgramBinary);
595 COREGL_OVERRIDE(fastpath_, glProgramParameteri);
598 if (driver_gl_version >= COREGL_GLAPI_31) {
599 COREGL_OVERRIDE(fastpath_, glCreateShaderProgramv);
600 COREGL_OVERRIDE(fastpath_, glGenProgramPipelines);
601 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineiv);
602 COREGL_OVERRIDE(fastpath_, glBindProgramPipeline);
603 COREGL_OVERRIDE(fastpath_, glDeleteProgramPipelines);
604 COREGL_OVERRIDE(fastpath_, glIsProgramPipeline);
605 COREGL_OVERRIDE(fastpath_, glValidateProgramPipeline);
606 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineInfoLog);
607 COREGL_OVERRIDE(fastpath_, glDispatchCompute);
608 COREGL_OVERRIDE(fastpath_, glDispatchComputeIndirect);
609 COREGL_OVERRIDE(fastpath_, glGetProgramInterfaceiv);
610 COREGL_OVERRIDE(fastpath_, glGetProgramResourceIndex);
611 COREGL_OVERRIDE(fastpath_, glGetProgramResourceName);
612 COREGL_OVERRIDE(fastpath_, glGetProgramResourceiv);
613 COREGL_OVERRIDE(fastpath_, glGetProgramResourceLocation);
614 COREGL_OVERRIDE(fastpath_, glUseProgramStages);
615 COREGL_OVERRIDE(fastpath_, glActiveShaderProgram);
616 COREGL_OVERRIDE(fastpath_, glProgramUniform1iv);
617 COREGL_OVERRIDE(fastpath_, glProgramUniform2iv);
618 COREGL_OVERRIDE(fastpath_, glProgramUniform3iv);
619 COREGL_OVERRIDE(fastpath_, glProgramUniform4iv);
620 COREGL_OVERRIDE(fastpath_, glProgramUniform1fv);
621 COREGL_OVERRIDE(fastpath_, glProgramUniform2fv);
622 COREGL_OVERRIDE(fastpath_, glProgramUniform3fv);
623 COREGL_OVERRIDE(fastpath_, glProgramUniform4fv);
624 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fv);
625 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fv);
626 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fv);
627 COREGL_OVERRIDE(fastpath_, glProgramUniform1i);
628 COREGL_OVERRIDE(fastpath_, glProgramUniform2i);
629 COREGL_OVERRIDE(fastpath_, glProgramUniform3i);
630 COREGL_OVERRIDE(fastpath_, glProgramUniform4i);
631 COREGL_OVERRIDE(fastpath_, glProgramUniform1f);
632 COREGL_OVERRIDE(fastpath_, glProgramUniform2f);
633 COREGL_OVERRIDE(fastpath_, glProgramUniform3f);
634 COREGL_OVERRIDE(fastpath_, glProgramUniform4f);
635 COREGL_OVERRIDE(fastpath_, glProgramUniform1uiv);
636 COREGL_OVERRIDE(fastpath_, glProgramUniform2uiv);
637 COREGL_OVERRIDE(fastpath_, glProgramUniform3uiv);
638 COREGL_OVERRIDE(fastpath_, glProgramUniform4uiv);
639 COREGL_OVERRIDE(fastpath_, glProgramUniform1ui);
640 COREGL_OVERRIDE(fastpath_, glProgramUniform2ui);
641 COREGL_OVERRIDE(fastpath_, glProgramUniform3ui);
642 COREGL_OVERRIDE(fastpath_, glProgramUniform4ui);
643 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x3fv);
644 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x2fv);
645 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x2fv);
646 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x4fv);
647 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x4fv);
648 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x3fv);
649 COREGL_OVERRIDE(fastpath_, glBindImageTexture);
650 COREGL_OVERRIDE(fastpath_, glGetBooleani_v);
651 COREGL_OVERRIDE(fastpath_, glMemoryBarrier);
652 COREGL_OVERRIDE(fastpath_, glMemoryBarrierByRegion);
653 COREGL_OVERRIDE(fastpath_, glTexStorage2DMultisample);
654 COREGL_OVERRIDE(fastpath_, glGetMultisamplefv);
655 COREGL_OVERRIDE(fastpath_, glSampleMaski);
656 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameteriv);
657 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameterfv);
658 COREGL_OVERRIDE(fastpath_, glBindVertexBuffer);
659 COREGL_OVERRIDE(fastpath_, glVertexAttribFormat);
660 COREGL_OVERRIDE(fastpath_, glVertexAttribIFormat);
661 COREGL_OVERRIDE(fastpath_, glVertexAttribBinding);
662 COREGL_OVERRIDE(fastpath_, glVertexBindingDivisor);
665 if(driver_gl_version >= COREGL_GLAPI_32) {
666 COREGL_OVERRIDE(fastpath_, glBlendEquationi);
667 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparatei);
668 COREGL_OVERRIDE(fastpath_, glTexBuffer);
669 COREGL_OVERRIDE(fastpath_, glTexBufferRange);
670 COREGL_OVERRIDE(fastpath_, glFramebufferTexture);
671 COREGL_OVERRIDE(fastpath_, glGetnUniformfv);
672 COREGL_OVERRIDE(fastpath_, glGetnUniformiv);
673 COREGL_OVERRIDE(fastpath_, glGetnUniformuiv);
674 COREGL_OVERRIDE(fastpath_, glSamplerParameterIiv);
675 COREGL_OVERRIDE(fastpath_, glSamplerParameterIuiv);
676 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterIiv);
677 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterIuiv);
680 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
686 static inline GL_Object_Hash_Base *
687 _lock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
690 case GL_OBJECT_TYPE_QUERY:
691 return &ostate->query;
692 case GL_OBJECT_TYPE_TEXTURE:
693 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
694 return &ostate->shared->texture;
695 case GL_OBJECT_TYPE_BUFFER:
696 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
697 return &ostate->shared->buffer;
698 case GL_OBJECT_TYPE_FRAMEBUFFER:
699 return &ostate->framebuffer;
700 case GL_OBJECT_TYPE_RENDERBUFFER:
701 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
702 return &ostate->shared->renderbuffer;
703 case GL_OBJECT_TYPE_PROGRAM:
704 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
705 return &ostate->shared->program;
706 case GL_OBJECT_TYPE_VERTEXARRAY:
707 return &ostate->vertexarray;
708 case GL_OBJECT_TYPE_SAMPLER:
709 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
710 return &ostate->shared->sampler;
711 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
712 return &ostate->transformfeedback;
713 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
714 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
715 return &ostate->shared->programpipeline;
722 _unlock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
725 case GL_OBJECT_TYPE_TEXTURE:
726 case GL_OBJECT_TYPE_BUFFER:
727 case GL_OBJECT_TYPE_RENDERBUFFER:
728 case GL_OBJECT_TYPE_PROGRAM:
729 case GL_OBJECT_TYPE_SAMPLER:
730 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
731 AST(mutex_unlock(&ostate->shared->access_mutex) == 1);
737 static inline GL_Object_Hash_Base *
738 _lock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
741 case GL_OBJECT_TYPE_QUERY:
742 return &ostate->query_real;
743 case GL_OBJECT_TYPE_TEXTURE:
744 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
745 return &ostate->shared->texture_real;
746 case GL_OBJECT_TYPE_BUFFER:
747 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
748 return &ostate->shared->buffer_real;
749 case GL_OBJECT_TYPE_FRAMEBUFFER:
750 return &ostate->framebuffer_real;
751 case GL_OBJECT_TYPE_RENDERBUFFER:
752 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
753 return &ostate->shared->renderbuffer_real;
754 case GL_OBJECT_TYPE_PROGRAM:
755 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
756 return &ostate->shared->program_real;
757 case GL_OBJECT_TYPE_VERTEXARRAY:
758 return &ostate->vertexarray_real;
759 case GL_OBJECT_TYPE_SAMPLER:
760 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
761 return &ostate->shared->sampler_real;
762 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
763 return &ostate->transformfeedback_real;
764 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
765 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
766 return &ostate->shared->programpipeline_real;
773 _unlock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
776 case GL_OBJECT_TYPE_TEXTURE:
777 case GL_OBJECT_TYPE_BUFFER:
778 case GL_OBJECT_TYPE_RENDERBUFFER:
779 case GL_OBJECT_TYPE_PROGRAM:
780 case GL_OBJECT_TYPE_SAMPLER:
781 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
782 AST(mutex_unlock(&ostate->shared->real_access_mutex) == 1);
790 fastpath_add_context_state_to_list(const void *option, const int option_len,
791 GLContextState *cstate, Mutex *mtx)
795 GLContext_List *current = NULL;
796 GLContext_List *newitm = NULL;
798 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
802 tid = get_current_thread();
804 current = glctx_list;
805 while (current != NULL) {
806 if (current->option_len == option_len &&
807 memcmp(current->option, option, option_len) == 0 &&
808 current->thread_id == tid) {
809 AST(current->cstate == cstate);
812 current = current->next;
815 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
816 if (newitm == NULL) {
817 COREGL_ERR("Failed to create context list.\n");
821 newitm->cstate = cstate;
822 newitm->thread_id = tid;
823 newitm->option_len = option_len;
824 newitm->option = (void *)malloc(option_len);
825 memcpy(newitm->option, option, option_len);
827 if (glctx_list != NULL)
828 newitm->next = glctx_list;
837 if (newitm != NULL) {
841 if (cstate != NULL) {
846 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
852 fastpath_get_context_state_from_list(const void *option, const int option_len,
855 GLContextState *ret = NULL;
856 GLContext_List *current = NULL;
859 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
861 tid = get_current_thread();
863 current = glctx_list;
864 while (current != NULL) {
865 if (current->option_len == option_len &&
866 memcmp(current->option, option, option_len) == 0 &&
867 current->thread_id == tid) {
868 ret = current->cstate;
871 current = current->next;
876 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
881 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
884 GLContext_List *olditm = NULL;
885 GLContext_List *current = NULL;
887 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
891 current = glctx_list;
893 while (current != NULL) {
894 if (current->cstate == cstate) {
895 GLContext_List *nextitm = NULL;
896 if (olditm != NULL) {
897 olditm->next = current->next;
898 nextitm = olditm->next;
900 glctx_list = current->next;
901 nextitm = glctx_list;
903 if (current->option != NULL) {
904 AST(current->option_len > 0);
905 free(current->option);
906 current->option = NULL;
907 current->option_len = 0;
915 current = current->next;
920 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
926 #define HASH_INIT(hash_base) \
927 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
928 hash_base.hash_size = GL_OBJECT_HASH_BASE;
931 fastpath_ostate_init(GL_Object_State *ostate)
933 HASH_INIT(ostate->query);
934 HASH_INIT(ostate->framebuffer);
935 HASH_INIT(ostate->vertexarray);
936 HASH_INIT(ostate->transformfeedback);
938 HASH_INIT(ostate->query_real);
939 HASH_INIT(ostate->framebuffer_real);
940 HASH_INIT(ostate->vertexarray_real);
941 HASH_INIT(ostate->transformfeedback_real);
945 fastpath_sostate_init(GL_Shared_Object_State *sostate)
947 mutex_init(&sostate->access_mutex);
949 HASH_INIT(sostate->texture);
950 HASH_INIT(sostate->buffer);
951 HASH_INIT(sostate->renderbuffer);
952 HASH_INIT(sostate->program);
953 HASH_INIT(sostate->sampler);
954 HASH_INIT(sostate->programpipeline);
956 HASH_INIT(sostate->texture_real);
957 HASH_INIT(sostate->buffer_real);
958 HASH_INIT(sostate->renderbuffer_real);
959 HASH_INIT(sostate->program_real);
960 HASH_INIT(sostate->sampler_real);
961 HASH_INIT(sostate->programpipeline_real);
968 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
970 int array_idx = data->hash_key & (hash_base->hash_size - 1);
971 if (hash_base->hash_field[array_idx] == NULL) {
972 hash_base->hash_field[array_idx] = data;
974 GL_Object_Hash *current = hash_base->hash_field[array_idx];
975 while (current->next) {
976 AST(current->hash_key != data->hash_key);
977 current = current->next;
979 current->next = data;
982 hash_base->item_size++;
986 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
989 int array_idx = hash & (hash_base->hash_size - 1);
991 GL_Object_Hash *current = hash_base->hash_field[array_idx];
992 GL_Object_Hash *prev = NULL;
995 if (current->hash_key == hash) {
997 prev->next = current->next;
999 hash_base->hash_field[array_idx] = current->next;
1000 hash_base->item_size--;
1005 current = current->next;
1012 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
1014 if (hash_base->item_size == 0) return;
1016 for (int i = 0; i < hash_base->hash_size; i++) {
1017 if (hash_base->hash_field[i] != NULL) {
1018 GL_Object_Hash *current = hash_base->hash_field[i];
1020 while (current != NULL) {
1021 GL_Object_Hash *current_next = current->next;
1023 if (free_data == 1 && current->item != NULL) {
1024 free(current->item);
1028 hash_base->item_size--;
1029 current = current_next;
1037 #define HASH_DEINIT(hash_base, free_data) \
1038 _free_hash_list(&hash_base, free_data); \
1039 free(hash_base.hash_field); \
1040 hash_base.hash_size = 0;
1043 fastpath_ostate_deinit(GL_Object_State *ostate)
1045 HASH_DEINIT(ostate->query, 1);
1046 HASH_DEINIT(ostate->framebuffer, 1);
1047 HASH_DEINIT(ostate->vertexarray, 1);
1048 HASH_DEINIT(ostate->transformfeedback, 1);
1050 HASH_DEINIT(ostate->query_real, 0);
1051 HASH_DEINIT(ostate->framebuffer_real, 0);
1052 HASH_DEINIT(ostate->vertexarray_real, 0);
1053 HASH_DEINIT(ostate->transformfeedback_real, 0);
1057 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
1059 HASH_DEINIT(sostate->texture, 1);
1060 HASH_DEINIT(sostate->buffer, 1);
1061 HASH_DEINIT(sostate->renderbuffer, 1);
1062 HASH_DEINIT(sostate->program, 1);
1063 HASH_DEINIT(sostate->sampler, 1);
1064 HASH_DEINIT(sostate->programpipeline, 1);
1066 HASH_DEINIT(sostate->texture_real, 0);
1067 HASH_DEINIT(sostate->buffer_real, 0);
1068 HASH_DEINIT(sostate->renderbuffer_real, 0);
1069 HASH_DEINIT(sostate->program_real, 0);
1070 HASH_DEINIT(sostate->sampler_real, 0);
1072 HASH_DEINIT(sostate->programpipeline_real, 0);
1079 #define FIND_HASH(hash_base, key, ret) \
1081 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
1084 if (fh_current->hash_key == (key)) \
1089 fh_current = fh_current->next; \
1094 _ostate_hash_check(GL_Object_Hash_Base *hash_base)
1096 if (hash_base->item_size + 1 < hash_base->hash_size)
1099 int oldsize = hash_base->hash_size;
1100 GL_Object_Hash **oldfield = hash_base->hash_field;
1102 hash_base->hash_size = oldsize << 1;
1103 hash_base->hash_field = (GL_Object_Hash **)calloc(1,
1104 sizeof(GL_Object_Hash *) * hash_base->hash_size);
1105 AST(hash_base->hash_field != NULL);
1107 for (int i = 0; i < oldsize; i++) {
1108 if (oldfield[i] != NULL) {
1109 GL_Object_Hash *current = oldfield[i];
1111 while (current != NULL) {
1112 GL_Object_Hash *current_next = current->next;
1113 _add_hash(hash_base, current);
1114 hash_base->item_size--;
1115 current = current_next;
1124 fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type,
1127 GLuint ret = _COREGL_INT_INIT_VALUE;
1129 GL_Object_Hash_Base *hash_base = NULL;
1130 GL_Object_Hash_Base *hash_base_real = NULL;
1131 int newid = _COREGL_INT_INIT_VALUE;
1133 hash_base = _lock_gl_object_hash(ostate, type);
1134 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1136 newid = hash_base->last_id + 1;
1137 if (newid >= hash_base->hash_size) {
1138 hash_base->is_looped = 1;
1140 hash_base->last_id = 1;
1143 if (hash_base->is_looped != 0) {
1145 int findingid = newid;
1147 for (i = 0; i < hash_base->hash_size; i++) {
1148 GL_Object_Hash *exist_hash = NULL;
1149 FIND_HASH(hash_base, findingid, exist_hash);
1150 if (exist_hash == NULL) {
1155 if (findingid >= hash_base->hash_size) findingid = 1;
1159 hash_base->last_id = newid;
1162 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
1165 newobj->id = (int)type + newid;
1166 newobj->real_id = real_name;
1167 newobj->ref_count = 1;
1170 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1,
1171 sizeof(GL_Object_Hash));
1172 if (newobj_hash == NULL) {
1176 newobj_hash->item = newobj;
1177 newobj_hash->hash_key = newid;
1178 _add_hash(hash_base, newobj_hash);
1180 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1,
1181 sizeof(GL_Object_Hash));
1182 if (newobj_hash_real == NULL) {
1187 newobj_hash_real->item = newobj;
1188 newobj_hash_real->hash_key = real_name;
1189 _add_hash(hash_base_real, newobj_hash_real);
1194 _ostate_hash_check(hash_base);
1195 _ostate_hash_check(hash_base_real);
1200 _unlock_gl_object_hash(ostate, type);
1201 _unlock_gl_object_hash_real(ostate, type);
1205 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
1206 if (((int)(hash)) < 0) { ret = 0; goto finish; } \
1208 GL_Object_Hash *object_hash = NULL; \
1209 FIND_HASH((hash_base), (int)(hash), object_hash); \
1210 if (object_hash == NULL) { ret = 0; goto finish; } \
1211 (object) = object_hash->item; \
1212 if ((object) == NULL) { ret = 0; goto finish; } \
1216 fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type,
1219 GLuint ret = _COREGL_INT_INIT_VALUE;
1221 GL_Object_Hash_Base *hash_base = NULL;
1222 GL_Object_Hash_Base *hash_base_real = NULL;
1223 GL_Object *object = NULL;
1225 hash_base = _lock_gl_object_hash(ostate, type);
1226 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1228 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1230 object->ref_count--;
1232 if (object->ref_count <= 0) {
1233 GL_Object_Hash *object_hash = NULL;
1235 FIND_HASH(hash_base, object->id - (int)type, object_hash);
1236 AST(object_hash != NULL);
1237 _remove_hash(hash_base, object->id - (int)type);
1241 FIND_HASH(hash_base_real, object->real_id, object_hash);
1242 AST(object_hash != NULL);
1243 _remove_hash(hash_base_real, object->real_id);
1255 _unlock_gl_object_hash(ostate, type);
1256 _unlock_gl_object_hash_real(ostate, type);
1261 fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type,
1264 GLuint ret = _COREGL_INT_INIT_VALUE;
1266 GL_Object_Hash_Base *hash_base = NULL;
1267 GL_Object *object = NULL;
1269 hash_base = _lock_gl_object_hash(ostate, type);
1271 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1273 ret = object->real_id;
1277 _unlock_gl_object_hash(ostate, type);
1281 /* Check if the context's state contains object of a given type */
1283 fastpath_ostate_has_object_type(GL_Object_State *ostate, GL_Object_Type type)
1285 GLuint ret = _COREGL_INT_INIT_VALUE;
1287 GL_Object_Hash_Base *hash_base = NULL;
1288 GL_Object *object = NULL;
1289 hash_base = _lock_gl_object_hash(ostate, type);
1291 if (hash_base->hash_field == 0) {
1296 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, 1, object);
1298 ret = object->real_id;
1302 _unlock_gl_object_hash(ostate, type);
1308 fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1309 GLuint glue_name, GLvoid *tag)
1311 GLint ret = _COREGL_INT_INIT_VALUE;
1313 GL_Object_Hash_Base *hash_base = NULL;
1314 GL_Object *object = NULL;
1315 int hash = _COREGL_INT_INIT_VALUE;
1317 hash_base = _lock_gl_object_hash(ostate, type);
1319 hash = glue_name - (int)type;
1321 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
1323 AST(object->tag == NULL);
1329 _unlock_gl_object_hash(ostate, type);
1334 fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1339 GL_Object_Hash_Base *hash_base = NULL;
1340 GL_Object *object = NULL;
1342 hash_base = _lock_gl_object_hash(ostate, type);
1344 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1350 _unlock_gl_object_hash(ostate, type);
1355 fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type,
1358 GLuint ret = _COREGL_INT_INIT_VALUE;
1360 GL_Object_Hash_Base *hash_base_real = NULL;
1361 GL_Object *object = NULL;
1363 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1365 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
1371 _unlock_gl_object_hash_real(ostate, type);
1376 fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type,
1379 GLint ret = _COREGL_INT_INIT_VALUE;
1381 GL_Object_Hash_Base *hash_base = NULL;
1382 GL_Object *object = NULL;
1384 hash_base = _lock_gl_object_hash(ostate, type);
1386 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1388 object->ref_count++;
1393 _unlock_gl_object_hash(ostate, type);
1398 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
1400 static struct timeval tv_last = { 0, 0 };
1402 if (unlikely(trace_state_flag != 1)) return;
1404 if (!force_output) {
1405 struct timeval tv_now = { 0, 0 };
1406 AST(gettimeofday(&tv_now, NULL) == 0);
1407 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC) {
1414 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1415 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n",
1417 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1419 #define PRINTF_CHAR_GLenum "0x%8X"
1420 #define PRINTF_CHAR_GLboolean "%10d"
1421 #define PRINTF_CHAR_GLint "%10d"
1422 #define PRINTF_CHAR_GLsizei "%10u"
1423 #define PRINTF_CHAR_GLuint "%10u"
1424 #define PRINTF_CHAR_GLuintmask "0x%8X"
1425 #define PRINTF_CHAR_GLintptr "%10ld"
1426 #define PRINTF_CHAR_GLsizeiptr "%10ld"
1428 #define PRINTF_CHAR_GLclampf "%10.6f"
1429 #define PRINTF_CHAR_GLfloat "%10.6f"
1431 #define PRINTF_CHAR_GLvoidptr "%10p"
1433 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1435 #define _COREGL_START_API(version) api_gl_version = version;
1436 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1437 #define INITIAL_CTX initial_ctx
1438 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1440 TYPE valuedata[SIZE]; \
1441 TYPE *value = NULL; \
1442 if(api_gl_version <= driver_gl_version) { \
1443 value = valuedata; GET_STMT; value = valuedata; \
1444 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1445 for (int i = 0; i < SIZE; i++) \
1449 TRACE("\n %-30.30s ", "");\
1453 if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
1454 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1455 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1456 if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
1458 TRACE(" \E[40;37;1m)\E[0m\n"); \
1461 # include "coregl_fastpath_state.h"
1464 #undef _COREGL_START_API
1465 #undef _COREGL_END_API
1467 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1477 fastpath_init_context_states(GLGlueContext *ctx)
1481 AST(mutex_lock(&init_context_mutex) == 1);
1484 COREGL_ERR("Context NULL\n");
1489 AST(ctx->initialized == 0);
1490 AST(ctx->ostate.shared != NULL);
1492 if (initial_ctx == NULL) {
1493 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1494 AST(initial_ctx != NULL);
1496 //#define FORCE_DEFAULT_VALUE
1497 #define _COREGL_START_API(version) api_gl_version = version;
1498 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1499 #ifdef FORCE_DEFAULT_VALUE
1500 # define INITIAL_CTX initial_ctx
1501 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1505 TYPE valuedata[SIZE]; \
1506 TYPE *value = NULL; \
1507 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1508 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1509 initial_ctx->NAME##_updated = (GLboolean *)calloc(SIZE, sizeof(GLboolean)); \
1510 if(api_gl_version <= driver_gl_version) { \
1511 value = valuedata; DEFAULT_STMT; value = valuedata; \
1512 for (i = 0; i < SIZE; i++) \
1514 if (*((char *)(&value[i])) == 0xcc) \
1516 memset(&value[i], 0xaa, sizeof(TYPE)); \
1517 value = valuedata; DEFAULT_STMT; value = valuedata; \
1518 if (*((char *)(&value[i])) == 0xaa) \
1520 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1524 initial_ctx->NAME[i] = value[i]; \
1525 initial_ctx->NAME##_updated[i] = GL_FALSE; \
1530 # include "coregl_fastpath_state.h"
1534 # define INITIAL_CTX initial_ctx
1535 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1536 if (try_step == 1) \
1538 value = valuedata; DEFAULT_STMT; value = valuedata; \
1542 value = valuedata; FALLBACK_STMT; value = valuedata; \
1545 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1550 TYPE valuedata[SIZE]; \
1551 TYPE *value = NULL; \
1552 _sym_glGetError(); \
1553 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1554 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1555 initial_ctx->NAME##_updated = (GLboolean *)calloc(SIZE, sizeof(GLboolean)); \
1556 if(api_gl_version <= driver_gl_version) { \
1559 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1560 if (_sym_glGetError() == GL_INVALID_ENUM) \
1562 initial_ctx->NAME##_used = 0; \
1563 value = valuedata; DEFAULT_STMT; value = valuedata; \
1566 initial_ctx->NAME##_used = 1; \
1567 for (i = 0; i < SIZE; i++) \
1569 if (*((char *)(&value[i])) == 0xcc) \
1571 memset(&value[i], 0xaa, sizeof(TYPE)); \
1572 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1573 if (*((char *)(&value[i])) == 0xaa) \
1576 if (try_step == 2) \
1578 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1583 initial_ctx->NAME[i] = value[i]; \
1584 initial_ctx->NAME##_updated[i] = GL_FALSE; \
1586 if (try_step != 2) \
1588 value = valuedata; DEFAULT_STMT; value = valuedata; \
1589 for (i = 0; i < SIZE; i++) \
1591 if (initial_ctx->NAME[i] != value[i]) \
1593 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]); \
1598 while (try_step == 2); \
1602 # include "coregl_fastpath_state.h"
1603 # undef SET_GLUE_VALUE
1607 # undef _COREGL_END_API
1608 # undef _COREGL_START_API
1610 if (initial_ctx->gl_vertex_attribs_num[0] > MAX_VERTEX_ATTRIBS) {
1611 COREGL_WRN("\E[40;31;1mNumber of vertex attrib is too big! (%d-%d)\E[0m\n",
1612 MAX_VERTEX_ATTRIBS, initial_ctx->gl_vertex_attribs_num[0]);
1614 if (initial_ctx->gl_tex_units_num[0] > MAX_TEXTURE_UNITS) {
1615 COREGL_WRN("\E[40;31;1mNumber of texture unit is too big! (%d-%d)\E[0m\n",
1616 MAX_TEXTURE_UNITS, initial_ctx->gl_tex_units_num[0]);
1618 if (initial_ctx->gl_transform_feedback_buffer_binding_num[0] >
1619 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS) {
1620 COREGL_WRN("\E[40;31;1mNumber of transform feedback separate attrib is too big! (%d-%d)\E[0m\n",
1621 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
1622 initial_ctx->gl_transform_feedback_buffer_binding_num[0]);
1624 if (initial_ctx->gl_uniform_buffer_binding_num[0] >
1625 MAX_UNIFORM_BUFFER_BINDINGS) {
1626 COREGL_WRN("\E[40;31;1mNumber of uniform buffer binding is too big! (%d-%d)\E[0m\n",
1627 MAX_UNIFORM_BUFFER_BINDINGS, initial_ctx->gl_uniform_buffer_binding_num[0]);
1629 if (initial_ctx->gl_shader_storage_buffer_binding_num[0] >
1630 MAX_SHADER_STORAGE_BUFFER_BINDINGS) {
1631 COREGL_WRN("\E[40;31;1mNumber of shader storage buffer binding is too big! (%d-%d)\E[0m\n",
1632 MAX_SHADER_STORAGE_BUFFER_BINDINGS, initial_ctx->gl_shader_storage_buffer_binding_num[0]);
1634 if (initial_ctx->gl_atomic_counter_buffer_binding_num[0] >
1635 MAX_ATOMIC_COUNTER_BUFFER_BINDING) {
1636 COREGL_WRN("\E[40;31;1mNumber of uniform buffer binding is too big! (%d-%d)\E[0m\n",
1637 MAX_ATOMIC_COUNTER_BUFFER_BINDING, initial_ctx->gl_atomic_counter_buffer_binding_num[0]);
1643 #define _COREGL_START_API(version) api_gl_version = version;
1644 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1645 #define INITIAL_CTX initial_ctx
1646 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1649 ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE)); \
1650 ctx->NAME##_updated = (GLboolean *)calloc(SIZE, sizeof(GLboolean)); \
1651 if(api_gl_version <= driver_gl_version) { \
1652 for (i = 0; i < SIZE; i++) \
1654 ctx->NAME[i] = initial_ctx->NAME[i]; \
1655 ctx->NAME##_used = initial_ctx->NAME##_used; \
1656 ctx->NAME##_updated[i] = initial_ctx->NAME##_updated[i]; \
1661 # include "coregl_fastpath_state.h"
1664 #undef _COREGL_START_API
1665 #undef _COREGL_END_API
1668 ctx->initialized = 1;
1673 AST(mutex_unlock(&init_context_mutex) == 1);
1678 #ifdef COREGL_USE_MODULE_TRACEPATH
1679 extern void *tracepath_api_trace_begin(const char *name, void *hint,
1680 int trace_total_time);
1681 extern void *tracepath_api_trace_end(const char *name, void *hint,
1682 int trace_total_time);
1685 #define CHECK_GL_ERROR(func) \
1688 int err = _orig_fastpath_glGetError(); \
1689 if (err != GL_NO_ERROR) \
1691 COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1697 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1700 unsigned char flag = 0;
1703 if (debug_nofp == 1) {
1708 // Return if they're the same
1709 if (oldctx == newctx) {
1714 #define STATE_COMPARE(state) \
1715 if ((oldctx->state) != (newctx->state))
1717 #define STATES_COMPARE(state_ptr, bytes) \
1718 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1721 #ifdef COREGL_USE_MODULE_TRACEPATH
1722 static void *trace_hint_glfinish = NULL;
1723 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)",
1724 trace_hint_glfinish, 0);
1725 #endif // COREGL_USE_MODULE_TRACEPATH
1728 int err = _orig_fastpath_glGetError();
1729 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1730 oldctx->gl_error = err;
1733 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1735 #ifdef COREGL_USE_MODULE_TRACEPATH
1736 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1737 #endif // COREGL_USE_MODULE_TRACEPATH
1740 #ifdef COREGL_USE_MODULE_TRACEPATH
1741 static void *trace_hint_vertex_attrib = NULL;
1742 trace_hint_vertex_attrib =
1743 tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)",
1744 trace_hint_vertex_attrib, 0);
1745 #endif // COREGL_USE_MODULE_TRACEPATH
1747 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1749 for (i = 0; i < oldctx->gl_vertex_attribs_num[0]; i++) {
1750 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i]) {
1751 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1752 newctx->gl_vertex_array_buf_id[i]))
1754 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1757 STATE_COMPARE(gl_vertex_array_divisor[i]) {
1758 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribDivisor(i,
1759 newctx->gl_vertex_array_divisor[i]))
1762 if (newctx->gl_vertex_array_size[i] != 0) {
1763 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1764 newctx->gl_vertex_array_size[i],
1765 newctx->gl_vertex_array_type[i],
1766 newctx->gl_vertex_array_normalized[i],
1767 newctx->gl_vertex_array_stride[i],
1768 newctx->gl_vertex_array_pointer[i]))
1770 if (newctx->gl_vertex_array_integer[0] == GL_TRUE) {
1771 if (newctx->gl_vertex_array_type[0] == GL_UNSIGNED_INT) {
1772 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4uiv(i,
1773 &newctx->gl_vertex_attrib_value_unsigned_integer[4 * i]))
1775 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4iv(i,
1776 &newctx->gl_vertex_attrib_value_integer[4 * i]))
1779 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i,
1780 &newctx->gl_vertex_attrib_value[4 * i]))
1784 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE) {
1785 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1787 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1793 #ifdef COREGL_USE_MODULE_TRACEPATH
1794 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)",
1795 trace_hint_vertex_attrib, 0);
1796 #endif // COREGL_USE_MODULE_TRACEPATH
1799 #ifdef COREGL_USE_MODULE_TRACEPATH
1800 static void *trace_hint_bindbuffers = NULL;
1801 trace_hint_bindbuffers =
1802 tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)",
1803 trace_hint_bindbuffers, 0);
1804 #endif // COREGL_USE_MODULE_TRACEPATH
1806 //------------------//
1808 flag = oldctx->_bind_flag1 | newctx->_bind_flag1;
1810 STATE_COMPARE(gl_array_buffer_binding[0]) {
1811 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1812 newctx->gl_array_buffer_binding[0]))
1814 STATE_COMPARE(gl_element_array_buffer_binding[0]) {
1815 STATE_COMPARE(gl_vertex_array_binding[0]) {
1816 CHECK_GL_ERROR(_orig_fastpath_glBindVertexArray(
1817 newctx->gl_vertex_array_binding[0]))
1819 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1820 newctx->gl_element_array_buffer_binding[0]))
1823 if (newctx->gl_framebuffer_binding_read_used == 1) {
1824 STATE_COMPARE(gl_framebuffer_binding_read[0]) {
1825 if (driver_gl_version >= 2)
1826 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER,
1827 newctx->gl_framebuffer_binding_read[0]))
1829 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_READ_FRAMEBUFFER,
1830 newctx->gl_framebuffer_binding_read[0]))
1832 STATE_COMPARE(gl_framebuffer_binding_draw[0]) {
1833 if (driver_gl_version >= 2)
1834 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1835 newctx->gl_framebuffer_binding_draw[0]))
1837 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_DRAW_FRAMEBUFFER,
1838 newctx->gl_framebuffer_binding_draw[0]))
1841 STATE_COMPARE(gl_framebuffer_binding[0]) {
1842 if (driver_gl_version >= 2)
1843 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER,
1844 newctx->gl_framebuffer_binding[0]))
1846 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_FRAMEBUFFER,
1847 newctx->gl_framebuffer_binding[0]))
1850 STATE_COMPARE(gl_renderbuffer_binding[0]) {
1851 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER,
1852 newctx->gl_renderbuffer_binding[0]))
1856 //------------------//
1858 flag = oldctx->_bind_flag2 | newctx->_bind_flag2;
1860 STATE_COMPARE(gl_copy_read_buffer_binding[0]) {
1861 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_READ_BUFFER,
1862 newctx->gl_copy_read_buffer_binding[0]))
1864 STATE_COMPARE(gl_copy_write_buffer_binding[0]) {
1865 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_WRITE_BUFFER,
1866 newctx->gl_copy_write_buffer_binding[0]))
1868 STATE_COMPARE(gl_pixel_pack_buffer_binding[0]) {
1869 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_PACK_BUFFER,
1870 newctx->gl_pixel_pack_buffer_binding[0]))
1872 STATE_COMPARE(gl_pixel_unpack_buffer_binding[0]) {
1873 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
1874 newctx->gl_pixel_unpack_buffer_binding[0]))
1876 STATE_COMPARE(gl_transform_feedback_buffer_binding[0]) {
1877 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER,
1878 newctx->gl_transform_feedback_buffer_binding[0]))
1880 STATE_COMPARE(gl_uniform_buffer_binding[0]) {
1881 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_UNIFORM_BUFFER,
1882 newctx->gl_uniform_buffer_binding[0]))
1886 flag = oldctx->_bind_flag3 | newctx->_bind_flag3;
1888 STATE_COMPARE(gl_shader_storage_buffer_binding[0]) {
1889 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_SHADER_STORAGE_BUFFER,
1890 newctx->gl_shader_storage_buffer_binding[0]))
1892 STATE_COMPARE(gl_atomic_counter_buffer_binding[0]) {
1893 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ATOMIC_COUNTER_BUFFER,
1894 newctx->gl_atomic_counter_buffer_binding[0]))
1896 STATE_COMPARE(gl_draw_indirect_buffer_binding[0]) {
1897 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_DRAW_INDIRECT_BUFFER,
1898 newctx->gl_draw_indirect_buffer_binding[0]))
1900 STATE_COMPARE(gl_dispatch_indirect_buffer_binding[0]) {
1901 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER,
1902 newctx->gl_dispatch_indirect_buffer_binding[0]))
1904 STATE_COMPARE(gl_texture_buffer_binding[0]) {
1905 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TEXTURE_BUFFER,
1906 newctx->gl_texture_buffer_binding[0]))
1909 #ifdef COREGL_USE_MODULE_TRACEPATH
1910 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)",
1911 trace_hint_bindbuffers, 0);
1912 #endif // COREGL_USE_MODULE_TRACEPATH
1915 //------------------//
1918 #ifdef COREGL_USE_MODULE_TRACEPATH
1919 static void *trace_hint_enable_states = NULL;
1920 trace_hint_enable_states =
1921 tracepath_api_trace_begin("eglMakeCurrent(FP enable states)",
1922 trace_hint_enable_states, 0);
1923 #endif // COREGL_USE_MODULE_TRACEPATH
1925 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1927 STATE_COMPARE(gl_blend[0]) {
1928 if (newctx->gl_blend[0]) {
1929 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1931 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1933 STATE_COMPARE(gl_cull_face[0]) {
1934 if (newctx->gl_cull_face[0]) {
1935 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1937 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1939 STATE_COMPARE(gl_depth_test[0]) {
1940 if (newctx->gl_depth_test[0]) {
1941 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1943 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1945 STATE_COMPARE(gl_dither[0]) {
1946 if (newctx->gl_dither[0]) {
1947 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1949 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1954 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1956 STATE_COMPARE(gl_polygon_offset_fill[0]) {
1957 if (newctx->gl_polygon_offset_fill[0]) {
1958 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1960 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1962 STATE_COMPARE(gl_sample_alpha_to_coverage[0]) {
1963 if (newctx->gl_sample_alpha_to_coverage[0]) {
1964 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1966 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1968 STATE_COMPARE(gl_sample_coverage[0]) {
1969 if (newctx->gl_sample_coverage[0]) {
1970 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1972 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1974 STATE_COMPARE(gl_scissor_test[0]) {
1975 if (newctx->gl_scissor_test[0]) {
1976 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1978 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1980 STATE_COMPARE(gl_stencil_test[0]) {
1981 if (newctx->gl_stencil_test[0]) {
1982 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1984 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1986 STATE_COMPARE(gl_sample_shading_oes[0]) {
1987 if (newctx->gl_sample_shading_oes[0]) {
1988 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_SHADING_OES))
1990 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_SHADING_OES))
1992 STATE_COMPARE(gl_sample_mask[0]) {
1993 if (newctx->gl_sample_mask[0]) {
1994 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_MASK))
1996 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_MASK))
2001 flag = oldctx->_enable_flag3 | newctx->_enable_flag3;
2003 STATE_COMPARE(gl_primitive_restart_fixed_index[0]) {
2004 if (newctx->gl_primitive_restart_fixed_index[0]) {
2005 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
2007 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
2009 STATE_COMPARE(gl_rasterizer_discard[0]) {
2010 if (newctx->gl_rasterizer_discard[0]) {
2011 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_RASTERIZER_DISCARD))
2013 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_RASTERIZER_DISCARD))
2015 STATE_COMPARE(gl_blend_advanced_coherent_khr[0]) {
2016 if (newctx->gl_blend_advanced_coherent_khr[0]) {
2017 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND_ADVANCED_COHERENT_KHR))
2019 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND_ADVANCED_COHERENT_KHR))
2023 #ifdef COREGL_USE_MODULE_TRACEPATH
2024 tracepath_api_trace_end("eglMakeCurrent(FP enable states)",
2025 trace_hint_enable_states, 0);
2026 #endif // COREGL_USE_MODULE_TRACEPATH
2028 //------------------//
2030 #ifdef COREGL_USE_MODULE_TRACEPATH
2031 static void *trace_hint_clear_viewport = NULL;
2032 trace_hint_clear_viewport =
2033 tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)",
2034 trace_hint_clear_viewport, 0);
2035 #endif // COREGL_USE_MODULE_TRACEPATH
2037 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
2040 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint)) {
2041 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
2042 newctx->gl_viewport[1],
2043 newctx->gl_viewport[2],
2044 newctx->gl_viewport[3]))
2047 STATE_COMPARE(gl_current_program[0]) {
2048 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
2050 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf)) {
2051 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
2052 newctx->gl_color_clear_value[1],
2053 newctx->gl_color_clear_value[2],
2054 newctx->gl_color_clear_value[3]))
2060 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
2062 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean)) {
2063 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
2064 newctx->gl_color_writemask[1],
2065 newctx->gl_color_writemask[2],
2066 newctx->gl_color_writemask[3]))
2068 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf)) {
2069 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
2070 newctx->gl_depth_range[1]))
2072 STATE_COMPARE(gl_depth_clear_value[0]) {
2073 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
2075 STATE_COMPARE(gl_depth_func[0]) {
2076 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
2078 STATE_COMPARE(gl_depth_writemask[0]) {
2079 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
2081 STATE_COMPARE(gl_cull_face_mode[0]) {
2082 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
2087 #ifdef COREGL_USE_MODULE_TRACEPATH
2088 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)",
2089 trace_hint_clear_viewport, 0);
2090 #endif // COREGL_USE_MODULE_TRACEPATH
2092 //------------------//
2094 #ifdef COREGL_USE_MODULE_TRACEPATH
2095 static void *trace_hint_bind_textures = NULL;
2096 trace_hint_bind_textures =
2097 tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)",
2098 trace_hint_bind_textures, 0);
2099 #endif // COREGL_USE_MODULE_TRACEPATH
2101 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
2104 for (i = 0; i < oldctx->gl_tex_units_num[0]; i++) {
2105 STATE_COMPARE(gl_tex_2d_state[i]) {
2106 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2107 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D,
2108 newctx->gl_tex_2d_state[i]))
2110 STATE_COMPARE(gl_tex_3d_state[i]) {
2111 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2112 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_3D,
2113 newctx->gl_tex_3d_state[i]))
2115 STATE_COMPARE(gl_tex_2d_array_state[i]) {
2116 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2117 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_ARRAY,
2118 newctx->gl_tex_2d_array_state[i]))
2120 STATE_COMPARE(gl_tex_cube_state[i]) {
2121 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2122 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP,
2123 newctx->gl_tex_cube_state[i]))
2125 STATE_COMPARE(gl_tex_external_oes_state[i]) {
2126 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2127 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_EXTERNAL_OES,
2128 newctx->gl_tex_external_oes_state[i]))
2132 // Restore active texture
2133 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
2135 STATE_COMPARE(gl_generate_mipmap_hint[0]) {
2136 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT,
2137 newctx->gl_generate_mipmap_hint[0]))
2141 flag = oldctx->_tex_flag2 | newctx->_tex_flag2;
2143 for (i = 0; i < oldctx->gl_tex_units_num[0]; i++) {
2144 STATE_COMPARE(gl_tex_buffer_ext_state[i]) {
2145 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2146 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_BUFFER_EXT,
2147 newctx->gl_tex_buffer_ext_state[i]))
2149 STATE_COMPARE(gl_tex_2d_multisample_state[i]) {
2150 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2151 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE,
2152 newctx->gl_tex_2d_multisample_state[i]))
2154 STATE_COMPARE(gl_tex_2d_multisample_array_oes_state[i]) {
2155 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2156 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES,
2157 newctx->gl_tex_2d_multisample_array_oes_state[i]))
2161 #ifdef COREGL_USE_MODULE_TRACEPATH
2162 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)",
2163 trace_hint_bind_textures, 0);
2164 #endif // COREGL_USE_MODULE_TRACEPATH
2166 //------------------//
2167 #ifdef COREGL_USE_MODULE_TRACEPATH
2168 static void *trace_hint_etc = NULL;
2169 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)",
2171 #endif // COREGL_USE_MODULE_TRACEPATH
2173 flag = oldctx->_blend_flag | newctx->_blend_flag;
2175 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf)) {
2176 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
2177 newctx->gl_blend_color[1],
2178 newctx->gl_blend_color[2],
2179 newctx->gl_blend_color[3]))
2181 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
2182 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
2183 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
2184 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0])) {
2185 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
2186 newctx->gl_blend_dst_rgb[0],
2187 newctx->gl_blend_src_alpha[0],
2188 newctx->gl_blend_dst_alpha[0]))
2190 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
2191 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0])) {
2192 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(
2193 newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
2198 //------------------//
2200 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
2202 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
2203 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
2204 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0])) {
2205 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
2206 newctx->gl_stencil_func[0],
2207 newctx->gl_stencil_ref[0],
2208 newctx->gl_stencil_value_mask[0]))
2210 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
2211 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0])
2213 (oldctx->gl_stencil_pass_depth_pass[0] !=
2214 newctx->gl_stencil_pass_depth_pass[0])) {
2215 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
2216 newctx->gl_stencil_fail[0],
2217 newctx->gl_stencil_pass_depth_fail[0],
2218 newctx->gl_stencil_pass_depth_pass[0]))
2221 STATE_COMPARE(gl_stencil_writemask[0]) {
2222 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT,
2223 newctx->gl_stencil_writemask[0]))
2229 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
2231 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
2232 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
2233 (oldctx->gl_stencil_back_value_mask[0] !=
2234 newctx->gl_stencil_back_value_mask[0])) {
2235 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
2236 newctx->gl_stencil_back_func[0],
2237 newctx->gl_stencil_back_ref[0],
2238 newctx->gl_stencil_back_value_mask[0]))
2240 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
2241 (oldctx->gl_stencil_back_pass_depth_fail[0] !=
2242 newctx->gl_stencil_back_pass_depth_fail[0]) ||
2243 (oldctx->gl_stencil_back_pass_depth_pass[0] !=
2244 newctx->gl_stencil_back_pass_depth_pass[0])) {
2245 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
2246 newctx->gl_stencil_back_fail[0],
2247 newctx->gl_stencil_back_pass_depth_fail[0],
2248 newctx->gl_stencil_back_pass_depth_pass[0]))
2251 STATE_COMPARE(gl_stencil_back_writemask[0]) {
2252 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK,
2253 newctx->gl_stencil_back_writemask[0]))
2255 STATE_COMPARE(gl_stencil_clear_value[0]) {
2256 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
2260 //------------------//
2262 flag = oldctx->_pixel_flag1 | newctx->_pixel_flag1;
2264 STATE_COMPARE(gl_pack_row_length[0]) {
2265 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ROW_LENGTH,
2266 newctx->gl_pack_row_length[0]))
2268 STATE_COMPARE(gl_pack_skip_rows[0]) {
2269 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_ROWS,
2270 newctx->gl_pack_skip_rows[0]))
2272 STATE_COMPARE(gl_pack_skip_pixels[0]) {
2273 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_PIXELS,
2274 newctx->gl_pack_skip_pixels[0]))
2276 STATE_COMPARE(gl_pack_alignment[0]) {
2277 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT,
2278 newctx->gl_pack_alignment[0]))
2283 flag = oldctx->_pixel_flag2 | newctx->_pixel_flag2;
2285 STATE_COMPARE(gl_unpack_row_length[0]) {
2286 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ROW_LENGTH,
2287 newctx->gl_unpack_row_length[0]))
2289 STATE_COMPARE(gl_unpack_skip_rows[0]) {
2290 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_ROWS,
2291 newctx->gl_unpack_skip_rows[0]))
2293 STATE_COMPARE(gl_unpack_skip_pixels[0]) {
2294 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_PIXELS,
2295 newctx->gl_unpack_skip_pixels[0]))
2297 STATE_COMPARE(gl_unpack_alignment[0]) {
2298 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT,
2299 newctx->gl_unpack_alignment[0]))
2301 STATE_COMPARE(gl_unpack_image_height[0]) {
2302 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,
2303 newctx->gl_unpack_image_height[0]))
2305 STATE_COMPARE(gl_unpack_skip_images[0]) {
2306 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_IMAGES,
2307 newctx->gl_unpack_skip_images[0]))
2311 //------------------//
2313 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
2315 STATE_COMPARE(gl_front_face[0]) {
2316 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
2318 STATE_COMPARE(gl_line_width[0]) {
2319 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
2321 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0])
2323 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0])) {
2324 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(
2325 newctx->gl_polygon_offset_factor[0],
2326 newctx->gl_polygon_offset_units[0]))
2328 if ((oldctx->gl_sample_coverage_value[0] !=
2329 newctx->gl_sample_coverage_value[0]) ||
2330 (oldctx->gl_sample_coverage_invert[0] !=
2331 newctx->gl_sample_coverage_invert[0])) {
2332 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(
2333 newctx->gl_sample_coverage_value[0],
2334 newctx->gl_sample_coverage_invert[0]))
2336 STATE_COMPARE(gl_fragment_shader_derivative_hint[0]) {
2337 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES,
2338 newctx->gl_fragment_shader_derivative_hint[0]))
2343 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
2345 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint)) {
2346 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
2347 newctx->gl_scissor_box[1],
2348 newctx->gl_scissor_box[2],
2349 newctx->gl_scissor_box[3]))
2354 flag = oldctx->_misc_flag3 | newctx->_misc_flag3;
2356 STATE_COMPARE(gl_read_buffer[0]) {
2357 CHECK_GL_ERROR(_orig_fastpath_glReadBuffer(newctx->gl_read_buffer[0]))
2359 STATES_COMPARE(gl_draw_buffers, 16 * sizeof(GLenum)) {
2360 int drawBuffSize = 16;
2361 /* If the context has only default framebuffer, then size of glDrawBuffers can only be 1 */
2362 if (fastpath_ostate_has_object_type(&newctx->ostate,
2363 GL_OBJECT_TYPE_FRAMEBUFFER) == 0) {
2367 CHECK_GL_ERROR(_orig_fastpath_glDrawBuffers(drawBuffSize,
2368 newctx->gl_draw_buffers))
2371 if (oldctx->gl_transform_feedback_active[0] == GL_TRUE &&
2372 oldctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2373 CHECK_GL_ERROR(_orig_fastpath_glPauseTransformFeedback())
2375 STATE_COMPARE(gl_transform_feedback_binding[0]) {
2376 CHECK_GL_ERROR(_orig_fastpath_glBindTransformFeedback(GL_TRANSFORM_FEEDBACK,
2377 newctx->gl_transform_feedback_binding[0]))
2379 if (newctx->gl_transform_feedback_active[0] == GL_TRUE &&
2380 newctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2381 CHECK_GL_ERROR(_orig_fastpath_glResumeTransformFeedback())
2385 #ifdef COREGL_USE_MODULE_TRACEPATH
2386 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
2387 #endif // COREGL_USE_MODULE_TRACEPATH
2394 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
2395 if (unlikely(trace_state_flag == 1))
2396 fastpath_dump_context_states(newctx, 0);
2397 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
2399 #undef STATE_COMPARE
2400 #undef STATES_COMPARE