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 tstate_mt->binded_api = EGL_OPENGL_ES_API;
224 tstate->module_data[MY_MODULE_ID] = tstate_mt;
228 deinit_modules_tstate_fastpath(GLThreadState *tstate)
230 if (tstate->module_data[MY_MODULE_ID] != NULL)
232 free(tstate->module_data[MY_MODULE_ID]);
233 tstate->module_data[MY_MODULE_ID] = NULL;
238 fastpath_apply_overrides()
243 fastpath_apply_overrides_egl(1);
244 fastpath_apply_overrides_gl(1);
249 COREGL_ERR("Invalide GL Override Option!!!\n");
256 fastpath_apply_overrides_egl(int enable)
258 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
259 # include "../../headers/sym_egl.h"
260 #undef _COREGL_SYMBOL
262 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
264 COREGL_OVERRIDE(fastpath_, eglBindAPI);
265 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
267 COREGL_OVERRIDE(fastpath_, eglCreateContext);
268 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
269 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
270 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
271 COREGL_OVERRIDE(fastpath_, eglQueryContext);
272 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
273 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
274 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
275 COREGL_OVERRIDE(fastpath_, eglTerminate);
276 COREGL_OVERRIDE(fastpath_, eglGetCurrentDisplay);
281 fastpath_apply_overrides_gl(int enable)
283 #define _COREGL_START_API(version) api_gl_version = version;
284 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
285 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
286 if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
288 # include "../../headers/sym_gl.h"
289 #undef _COREGL_SYMBOL
290 #undef _COREGL_START_API
291 #undef _COREGL_END_API
295 COREGL_OVERRIDE(fastpath_, glGetError);
296 COREGL_OVERRIDE(fastpath_, glGetString);
298 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
299 COREGL_OVERRIDE(fastpath_, glGetFloatv);
300 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
302 COREGL_OVERRIDE(fastpath_, glActiveTexture);
303 COREGL_OVERRIDE(fastpath_, glGenTextures);
304 COREGL_OVERRIDE(fastpath_, glBindTexture);
305 COREGL_OVERRIDE(fastpath_, glIsTexture);
306 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
307 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
309 COREGL_OVERRIDE(fastpath_, glGenBuffers);
310 COREGL_OVERRIDE(fastpath_, glBindBuffer);
311 COREGL_OVERRIDE(fastpath_, glIsBuffer);
312 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
314 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
315 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
316 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
317 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
318 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
320 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
321 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
322 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
323 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
324 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
326 COREGL_OVERRIDE(fastpath_, glCreateShader);
327 COREGL_OVERRIDE(fastpath_, glCreateProgram);
328 COREGL_OVERRIDE(fastpath_, glAttachShader);
329 COREGL_OVERRIDE(fastpath_, glCompileShader);
330 COREGL_OVERRIDE(fastpath_, glShaderBinary);
331 COREGL_OVERRIDE(fastpath_, glDeleteShader);
332 COREGL_OVERRIDE(fastpath_, glDetachShader);
333 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
334 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
335 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
336 COREGL_OVERRIDE(fastpath_, glIsShader);
337 COREGL_OVERRIDE(fastpath_, glShaderSource);
338 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
339 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
340 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
341 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
342 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
343 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
344 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
345 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
346 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
347 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
348 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
349 COREGL_OVERRIDE(fastpath_, glIsProgram);
350 COREGL_OVERRIDE(fastpath_, glLinkProgram);
351 COREGL_OVERRIDE(fastpath_, glUseProgram);
352 COREGL_OVERRIDE(fastpath_, glValidateProgram);
354 COREGL_OVERRIDE(fastpath_, glBlendColor);
355 COREGL_OVERRIDE(fastpath_, glBlendEquation);
356 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
357 COREGL_OVERRIDE(fastpath_, glBlendFunc);
358 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
359 COREGL_OVERRIDE(fastpath_, glClearColor);
360 COREGL_OVERRIDE(fastpath_, glClearDepthf);
361 COREGL_OVERRIDE(fastpath_, glClearStencil);
362 COREGL_OVERRIDE(fastpath_, glColorMask);
363 COREGL_OVERRIDE(fastpath_, glCullFace);
364 COREGL_OVERRIDE(fastpath_, glDepthFunc);
365 COREGL_OVERRIDE(fastpath_, glDepthMask);
366 COREGL_OVERRIDE(fastpath_, glDepthRangef);
367 COREGL_OVERRIDE(fastpath_, glDisable);
368 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
369 COREGL_OVERRIDE(fastpath_, glEnable);
370 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
371 COREGL_OVERRIDE(fastpath_, glFrontFace);
372 COREGL_OVERRIDE(fastpath_, glHint);
373 COREGL_OVERRIDE(fastpath_, glLineWidth);
374 COREGL_OVERRIDE(fastpath_, glPixelStorei);
375 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
376 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
377 COREGL_OVERRIDE(fastpath_, glScissor);
378 COREGL_OVERRIDE(fastpath_, glStencilFunc);
379 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
380 COREGL_OVERRIDE(fastpath_, glStencilMask);
381 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
382 COREGL_OVERRIDE(fastpath_, glStencilOp);
383 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
384 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
385 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
386 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
387 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
388 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
389 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
390 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
391 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
392 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
393 COREGL_OVERRIDE(fastpath_, glViewport);
395 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
396 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
398 COREGL_OVERRIDE(fastpath_, glUseProgramStagesEXT);
399 COREGL_OVERRIDE(fastpath_, glActiveShaderProgramEXT);
400 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
401 COREGL_OVERRIDE(fastpath_, glProgramUniform1iEXT);
402 COREGL_OVERRIDE(fastpath_, glProgramUniform2iEXT);
403 COREGL_OVERRIDE(fastpath_, glProgramUniform3iEXT);
404 COREGL_OVERRIDE(fastpath_, glProgramUniform4iEXT);
405 COREGL_OVERRIDE(fastpath_, glProgramUniform1fEXT);
406 COREGL_OVERRIDE(fastpath_, glProgramUniform2fEXT);
407 COREGL_OVERRIDE(fastpath_, glProgramUniform3fEXT);
408 COREGL_OVERRIDE(fastpath_, glProgramUniform4fEXT);
409 COREGL_OVERRIDE(fastpath_, glProgramUniform1ivEXT);
410 COREGL_OVERRIDE(fastpath_, glProgramUniform2ivEXT);
411 COREGL_OVERRIDE(fastpath_, glProgramUniform3ivEXT);
412 COREGL_OVERRIDE(fastpath_, glProgramUniform4ivEXT);
413 COREGL_OVERRIDE(fastpath_, glProgramUniform1fvEXT);
414 COREGL_OVERRIDE(fastpath_, glProgramUniform2fvEXT);
415 COREGL_OVERRIDE(fastpath_, glProgramUniform3fvEXT);
416 COREGL_OVERRIDE(fastpath_, glProgramUniform4fvEXT);
417 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fvEXT);
418 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fvEXT);
419 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fvEXT);
420 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
421 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
422 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
423 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
424 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
426 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
427 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
429 /* Start overriding GLES 3.0 */
430 if(driver_gl_version >= COREGL_GLAPI_3) {
431 COREGL_OVERRIDE(fastpath_, glReadBuffer);
433 COREGL_OVERRIDE(fastpath_, glGenQueries);
434 COREGL_OVERRIDE(fastpath_, glDeleteQueries);
435 COREGL_OVERRIDE(fastpath_, glIsQuery);
436 COREGL_OVERRIDE(fastpath_, glBeginQuery);
437 COREGL_OVERRIDE(fastpath_, glGetQueryiv);
438 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
439 COREGL_OVERRIDE(fastpath_, glDrawBuffers);
440 COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
442 COREGL_OVERRIDE(fastpath_, glBindVertexArray);
443 COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
444 COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
445 COREGL_OVERRIDE(fastpath_, glIsVertexArray);
447 COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
449 COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
450 COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
451 COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
452 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
454 COREGL_OVERRIDE(fastpath_, glBindBufferRange);
455 COREGL_OVERRIDE(fastpath_, glBindBufferBase);
456 COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
457 COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
458 COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
459 COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
460 COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
461 COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
462 COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
463 COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
464 COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
465 COREGL_OVERRIDE(fastpath_, glGetStringi);
466 COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
467 COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
468 COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
469 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
470 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
471 COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
472 COREGL_OVERRIDE(fastpath_, glGetInteger64v);
473 COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
474 COREGL_OVERRIDE(fastpath_, glGenSamplers);
475 COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
476 COREGL_OVERRIDE(fastpath_, glIsSampler);
477 COREGL_OVERRIDE(fastpath_, glBindSampler);
478 COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
479 COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
480 COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
481 COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
482 COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
483 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
484 COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
485 COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
486 COREGL_OVERRIDE(fastpath_, glProgramBinary);
487 COREGL_OVERRIDE(fastpath_, glProgramParameteri);
493 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
499 static inline GL_Object_Hash_Base *
500 _lock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
504 case GL_OBJECT_TYPE_QUERY:
505 return &ostate->query;
506 case GL_OBJECT_TYPE_TEXTURE:
507 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
508 return &ostate->shared->texture;
509 case GL_OBJECT_TYPE_BUFFER:
510 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
511 return &ostate->shared->buffer;
512 case GL_OBJECT_TYPE_FRAMEBUFFER:
513 return &ostate->framebuffer;
514 case GL_OBJECT_TYPE_RENDERBUFFER:
515 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
516 return &ostate->shared->renderbuffer;
517 case GL_OBJECT_TYPE_PROGRAM:
518 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
519 return &ostate->shared->program;
520 case GL_OBJECT_TYPE_VERTEXARRAY:
521 return &ostate->vertexarray;
522 case GL_OBJECT_TYPE_SAMPLER:
523 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
524 return &ostate->shared->sampler;
525 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
526 return &ostate->transformfeedback;
533 _unlock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
537 case GL_OBJECT_TYPE_TEXTURE:
538 case GL_OBJECT_TYPE_BUFFER:
539 case GL_OBJECT_TYPE_RENDERBUFFER:
540 case GL_OBJECT_TYPE_PROGRAM:
541 case GL_OBJECT_TYPE_SAMPLER:
542 AST(mutex_unlock(&ostate->shared->access_mutex) == 1);
548 static inline GL_Object_Hash_Base *
549 _lock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
553 case GL_OBJECT_TYPE_QUERY:
554 return &ostate->query_real;
555 case GL_OBJECT_TYPE_TEXTURE:
556 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
557 return &ostate->shared->texture_real;
558 case GL_OBJECT_TYPE_BUFFER:
559 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
560 return &ostate->shared->buffer_real;
561 case GL_OBJECT_TYPE_FRAMEBUFFER:
562 return &ostate->framebuffer_real;
563 case GL_OBJECT_TYPE_RENDERBUFFER:
564 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
565 return &ostate->shared->renderbuffer_real;
566 case GL_OBJECT_TYPE_PROGRAM:
567 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
568 return &ostate->shared->program_real;
569 case GL_OBJECT_TYPE_VERTEXARRAY:
570 return &ostate->vertexarray_real;
571 case GL_OBJECT_TYPE_SAMPLER:
572 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
573 return &ostate->shared->sampler_real;
574 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
575 return &ostate->transformfeedback_real;
582 _unlock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
586 case GL_OBJECT_TYPE_TEXTURE:
587 case GL_OBJECT_TYPE_BUFFER:
588 case GL_OBJECT_TYPE_RENDERBUFFER:
589 case GL_OBJECT_TYPE_PROGRAM:
590 case GL_OBJECT_TYPE_SAMPLER:
591 AST(mutex_unlock(&ostate->shared->real_access_mutex) == 1);
599 fastpath_add_context_state_to_list(const void *option, const int option_len, GLContextState *cstate, Mutex *mtx)
603 GLContext_List *current = NULL;
604 GLContext_List *newitm = NULL;
606 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
610 tid = get_current_thread();
612 current = glctx_list;
613 while (current != NULL)
615 if (current->option_len == option_len &&
616 memcmp(current->option, option, option_len) == 0 &&
617 current->thread_id == tid)
619 AST(current->cstate == cstate);
622 current = current->next;
625 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
628 COREGL_ERR("Failed to create context list.\n");
632 newitm->cstate = cstate;
633 newitm->thread_id = tid;
634 newitm->option_len = option_len;
635 newitm->option = (void *)malloc(option_len);
636 memcpy(newitm->option, option, option_len);
638 if (glctx_list != NULL)
639 newitm->next = glctx_list;
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 newid = hash_base->last_id + 1;
964 if (newid >= hash_base->hash_size)
966 hash_base->is_looped = 1;
968 hash_base->last_id = 1;
971 if (hash_base->is_looped != 0)
974 int findingid = newid;
976 for (i = 0; i < hash_base->hash_size; i++)
978 GL_Object_Hash *exist_hash = NULL;
979 FIND_HASH(hash_base, findingid, exist_hash);
980 if (exist_hash == NULL)
986 if (findingid >= hash_base->hash_size) findingid = 1;
990 hash_base->last_id = newid;
993 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
995 newobj->id = (int)type + newid;
996 newobj->real_id = real_name;
997 newobj->ref_count = 1;
1000 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
1001 AST(newobj_hash != NULL);
1002 newobj_hash->item = newobj;
1003 newobj_hash->hash_key = newid;
1004 _add_hash(hash_base, newobj_hash);
1006 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
1007 AST(newobj_hash_real != NULL);
1008 newobj_hash_real->item = newobj;
1009 newobj_hash_real->hash_key = real_name;
1010 _add_hash(hash_base_real, newobj_hash_real);
1013 _ostate_hash_check(hash_base);
1014 _ostate_hash_check(hash_base_real);
1019 _unlock_gl_object_hash(ostate, type);
1020 _unlock_gl_object_hash_real(ostate, type);
1024 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
1025 if (((int)(hash)) < 0) { ret = 0; goto finish; } \
1027 GL_Object_Hash *object_hash = NULL; \
1028 FIND_HASH((hash_base), (int)(hash), object_hash); \
1029 if (object_hash == NULL) { ret = 0; goto finish; } \
1030 (object) = object_hash->item; \
1031 if ((object) == NULL) { ret = 0; goto finish; } \
1035 fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1037 GLuint ret = _COREGL_INT_INIT_VALUE;
1039 GL_Object_Hash_Base *hash_base = NULL;
1040 GL_Object_Hash_Base *hash_base_real = NULL;
1041 GL_Object *object = NULL;
1043 hash_base = _lock_gl_object_hash(ostate, type);
1044 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1046 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1048 object->ref_count--;
1050 if (object->ref_count <= 0)
1052 GL_Object_Hash *object_hash = NULL;
1054 FIND_HASH(hash_base, object->id - (int)type, object_hash);
1055 AST(object_hash != NULL);
1056 _remove_hash(hash_base, object->id - (int)type);
1060 FIND_HASH(hash_base_real, object->real_id, object_hash);
1061 AST(object_hash != NULL);
1062 _remove_hash(hash_base_real, object->real_id);
1074 _unlock_gl_object_hash(ostate, type);
1075 _unlock_gl_object_hash_real(ostate, type);
1080 fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1082 GLuint ret = _COREGL_INT_INIT_VALUE;
1084 GL_Object_Hash_Base *hash_base = NULL;
1085 GL_Object *object = NULL;
1087 hash_base = _lock_gl_object_hash(ostate, type);
1089 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1091 ret = object->real_id;
1095 _unlock_gl_object_hash(ostate, type);
1100 /* Check if the context's state contains object of a given type */
1102 fastpath_ostate_has_object_type(GL_Object_State *ostate, GL_Object_Type type)
1104 GLuint ret = _COREGL_INT_INIT_VALUE;
1106 GL_Object_Hash_Base *hash_base = NULL;
1107 GL_Object *object = NULL;
1108 hash_base = _lock_gl_object_hash(ostate, type);
1110 if(hash_base->hash_field == 0)
1116 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, 1, object);
1118 ret = object->real_id;
1122 _unlock_gl_object_hash(ostate, type);
1128 fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag)
1130 GLint ret = _COREGL_INT_INIT_VALUE;
1132 GL_Object_Hash_Base *hash_base = NULL;
1133 GL_Object *object = NULL;
1134 int hash = _COREGL_INT_INIT_VALUE;
1136 hash_base = _lock_gl_object_hash(ostate, type);
1138 hash = glue_name - (int)type;
1140 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
1142 AST(object->tag == NULL);
1148 _unlock_gl_object_hash(ostate, type);
1153 fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1157 GL_Object_Hash_Base *hash_base = NULL;
1158 GL_Object *object = NULL;
1160 hash_base = _lock_gl_object_hash(ostate, type);
1162 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1168 _unlock_gl_object_hash(ostate, type);
1173 fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name)
1175 GLuint ret = _COREGL_INT_INIT_VALUE;
1177 GL_Object_Hash_Base *hash_base_real = NULL;
1178 GL_Object *object = NULL;
1180 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1182 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
1188 _unlock_gl_object_hash_real(ostate, type);
1193 fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1195 GLint ret = _COREGL_INT_INIT_VALUE;
1197 GL_Object_Hash_Base *hash_base = NULL;
1198 GL_Object *object = NULL;
1200 hash_base = _lock_gl_object_hash(ostate, type);
1202 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1204 object->ref_count++;
1209 _unlock_gl_object_hash(ostate, type);
1214 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
1216 static struct timeval tv_last = { 0, 0 };
1218 if (unlikely(trace_state_flag != 1)) return;
1222 struct timeval tv_now = { 0, 0 };
1223 AST(gettimeofday(&tv_now, NULL) == 0);
1224 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC)
1232 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1233 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n", getpid(), ctx);
1234 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1236 #define PRINTF_CHAR_GLenum "0x%8X"
1237 #define PRINTF_CHAR_GLboolean "%10d"
1238 #define PRINTF_CHAR_GLint "%10d"
1239 #define PRINTF_CHAR_GLsizei "%10u"
1240 #define PRINTF_CHAR_GLuint "%10u"
1241 #define PRINTF_CHAR_GLuintmask "0x%8X"
1242 #define PRINTF_CHAR_GLintptr "%10ld"
1243 #define PRINTF_CHAR_GLsizeiptr "%10ld"
1245 #define PRINTF_CHAR_GLclampf "%10.6f"
1246 #define PRINTF_CHAR_GLfloat "%10.6f"
1248 #define PRINTF_CHAR_GLvoidptr "%10p"
1250 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1252 #define _COREGL_START_API(version) api_gl_version = version;
1253 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1254 #define INITIAL_CTX initial_ctx
1255 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1257 TYPE valuedata[SIZE]; \
1258 TYPE *value = NULL; \
1259 if(api_gl_version <= driver_gl_version) { \
1260 value = valuedata; GET_STMT; value = valuedata; \
1261 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1262 for (int i = 0; i < SIZE; i++) \
1266 TRACE("\n %-30.30s ", "");\
1270 if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
1271 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1272 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1273 if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
1275 TRACE(" \E[40;37;1m)\E[0m\n"); \
1278 # include "coregl_fastpath_state.h"
1281 #undef _COREGL_START_API
1282 #undef _COREGL_END_API
1284 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1294 fastpath_init_context_states(GLGlueContext *ctx)
1298 AST(mutex_lock(&init_context_mutex) == 1);
1302 COREGL_ERR("Context NULL\n");
1307 AST(ctx->initialized == 0);
1308 AST(ctx->ostate.shared != NULL);
1310 if (initial_ctx == NULL)
1312 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1313 AST(initial_ctx != NULL);
1315 //#define FORCE_DEFAULT_VALUE
1316 #define _COREGL_START_API(version) api_gl_version = version;
1317 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1318 #ifdef FORCE_DEFAULT_VALUE
1319 # define INITIAL_CTX initial_ctx
1320 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1323 TYPE valuedata[SIZE]; \
1324 TYPE *value = NULL; \
1325 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1326 if(api_gl_version <= driver_gl_version) { \
1327 value = valuedata; DEFAULT_STMT; value = valuedata; \
1328 for (i = 0; i < SIZE; i++) \
1330 if (*((char *)(&value[i])) == 0xcc) \
1332 memset(&value[i], 0xaa, sizeof(TYPE)); \
1333 value = valuedata; DEFAULT_STMT; value = valuedata; \
1334 if (*((char *)(&value[i])) == 0xaa) \
1336 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1340 initial_ctx->NAME[i] = value[i]; \
1344 # include "coregl_fastpath_state.h"
1348 # define INITIAL_CTX initial_ctx
1349 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1350 if (try_step == 1) \
1352 value = valuedata; DEFAULT_STMT; value = valuedata; \
1356 value = valuedata; FALLBACK_STMT; value = valuedata; \
1359 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1363 TYPE valuedata[SIZE]; \
1364 TYPE *value = NULL; \
1365 _sym_glGetError(); \
1366 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1367 if(api_gl_version <= driver_gl_version) { \
1370 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1371 if (_sym_glGetError() == GL_INVALID_ENUM) \
1373 initial_ctx->NAME##_used = 0; \
1374 value = valuedata; DEFAULT_STMT; value = valuedata; \
1377 initial_ctx->NAME##_used = 1; \
1378 for (i = 0; i < SIZE; i++) \
1380 if (*((char *)(&value[i])) == 0xcc) \
1382 memset(&value[i], 0xaa, sizeof(TYPE)); \
1383 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1384 if (*((char *)(&value[i])) == 0xaa) \
1387 if (try_step == 2) \
1389 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1394 initial_ctx->NAME[i] = value[i]; \
1396 if (try_step != 2) \
1398 value = valuedata; DEFAULT_STMT; value = valuedata; \
1399 for (i = 0; i < SIZE; i++) \
1401 if (initial_ctx->NAME[i] != value[i]) \
1403 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]); \
1408 while (try_step == 2); \
1411 # include "coregl_fastpath_state.h"
1412 # undef SET_GLUE_VALUE
1416 # undef _COREGL_END_API
1417 # undef _COREGL_START_API
1419 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS)
1421 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]);
1423 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS)
1425 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]);
1427 if (initial_ctx->gl_num_transform_feedback_separate_attribs[0] > MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS)
1429 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]);
1431 if (initial_ctx->gl_num_uniform_buffer_bindings[0] > MAX_UNIFORM_BUFFER_BINDINGS)
1433 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]);
1439 #define _COREGL_START_API(version) api_gl_version = version;
1440 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1441 #define INITIAL_CTX initial_ctx
1442 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1443 if(api_gl_version <= driver_gl_version) { \
1444 for (i = 0; i < SIZE; i++) \
1446 ctx->NAME[i] = initial_ctx->NAME[i]; \
1447 ctx->NAME##_used = initial_ctx->NAME##_used; \
1450 # include "coregl_fastpath_state.h"
1453 #undef _COREGL_START_API
1454 #undef _COREGL_END_API
1457 ctx->initialized = 1;
1462 AST(mutex_unlock(&init_context_mutex) == 1);
1467 #ifdef COREGL_USE_MODULE_TRACEPATH
1468 extern void *tracepath_api_trace_begin(const char *name, void *hint, int trace_total_time);
1469 extern void *tracepath_api_trace_end(const char *name, void *hint, int trace_total_time);
1472 #define CHECK_GL_ERROR(func) \
1475 int err = _orig_fastpath_glGetError(); \
1476 if (err != GL_NO_ERROR) \
1478 COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1484 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1487 unsigned char flag = 0;
1490 if (debug_nofp == 1)
1496 // Return if they're the same
1497 if (oldctx == newctx)
1503 #define STATE_COMPARE(state) \
1504 if ((oldctx->state) != (newctx->state))
1506 #define STATES_COMPARE(state_ptr, bytes) \
1507 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1510 #ifdef COREGL_USE_MODULE_TRACEPATH
1511 static void *trace_hint_glfinish = NULL;
1512 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1513 #endif // COREGL_USE_MODULE_TRACEPATH
1516 int err = _orig_fastpath_glGetError();
1517 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1518 oldctx->gl_error = err;
1521 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1523 #ifdef COREGL_USE_MODULE_TRACEPATH
1524 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1525 #endif // COREGL_USE_MODULE_TRACEPATH
1528 #ifdef COREGL_USE_MODULE_TRACEPATH
1529 static void *trace_hint_vertex_attrib = NULL;
1530 trace_hint_vertex_attrib = tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1531 #endif // COREGL_USE_MODULE_TRACEPATH
1533 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1536 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++)
1538 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i])
1540 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_vertex_array_buf_id[i]))
1544 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1547 STATE_COMPARE(gl_vertex_array_divisor[i])
1549 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribDivisor(i, newctx->gl_vertex_array_divisor[i]))
1552 if (newctx->gl_vertex_array_size[i] != 0)
1554 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1555 newctx->gl_vertex_array_size[i],
1556 newctx->gl_vertex_array_type[i],
1557 newctx->gl_vertex_array_normalized[i],
1558 newctx->gl_vertex_array_stride[i],
1559 newctx->gl_vertex_array_pointer[i]))
1563 if (newctx->gl_vertex_array_integer[0] == GL_TRUE)
1565 if (newctx->gl_vertex_array_type[0] == GL_UNSIGNED_INT)
1567 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4uiv(i, &newctx->gl_vertex_attrib_value_unsigned_integer[4 * i]))
1571 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4iv(i, &newctx->gl_vertex_attrib_value_integer[4 * i]))
1576 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i, &newctx->gl_vertex_attrib_value[4 * i]))
1580 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE)
1582 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1586 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1592 #ifdef COREGL_USE_MODULE_TRACEPATH
1593 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1594 #endif // COREGL_USE_MODULE_TRACEPATH
1597 #ifdef COREGL_USE_MODULE_TRACEPATH
1598 static void *trace_hint_bindbuffers = NULL;
1599 trace_hint_bindbuffers = tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1600 #endif // COREGL_USE_MODULE_TRACEPATH
1602 //------------------//
1604 flag = oldctx->_bind_flag1 | newctx->_bind_flag1;
1607 STATE_COMPARE(gl_array_buffer_binding[0])
1609 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1611 STATE_COMPARE(gl_element_array_buffer_binding[0])
1613 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1616 if (newctx->gl_framebuffer_binding_read_used == 1)
1618 STATE_COMPARE(gl_framebuffer_binding_read[0])
1620 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER, newctx->gl_framebuffer_binding_read[0]))
1622 STATE_COMPARE(gl_framebuffer_binding_draw[0])
1624 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, newctx->gl_framebuffer_binding_draw[0]))
1629 STATE_COMPARE(gl_framebuffer_binding[0])
1631 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER, newctx->gl_framebuffer_binding[0]))
1634 STATE_COMPARE(gl_renderbuffer_binding[0])
1636 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER, newctx->gl_renderbuffer_binding[0]))
1640 //------------------//
1642 flag = oldctx->_bind_flag2 | newctx->_bind_flag2;
1645 STATE_COMPARE(gl_copy_read_buffer_binding[0])
1647 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_READ_BUFFER, newctx->gl_copy_read_buffer_binding[0]))
1649 STATE_COMPARE(gl_copy_write_buffer_binding[0])
1651 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_WRITE_BUFFER, newctx->gl_copy_write_buffer_binding[0]))
1653 STATE_COMPARE(gl_pixel_pack_buffer_binding[0])
1655 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_PACK_BUFFER, newctx->gl_pixel_pack_buffer_binding[0]))
1657 STATE_COMPARE(gl_pixel_unpack_buffer_binding[0])
1659 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, newctx->gl_pixel_unpack_buffer_binding[0]))
1661 STATE_COMPARE(gl_transform_feedback_buffer_binding[0])
1663 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, newctx->gl_transform_feedback_buffer_binding[0]))
1665 STATE_COMPARE(gl_uniform_buffer_binding[0])
1667 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_UNIFORM_BUFFER, newctx->gl_uniform_buffer_binding[0]))
1670 #ifdef COREGL_USE_MODULE_TRACEPATH
1671 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1672 #endif // COREGL_USE_MODULE_TRACEPATH
1675 //------------------//
1678 #ifdef COREGL_USE_MODULE_TRACEPATH
1679 static void *trace_hint_enable_states = NULL;
1680 trace_hint_enable_states = tracepath_api_trace_begin("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1681 #endif // COREGL_USE_MODULE_TRACEPATH
1683 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1686 STATE_COMPARE(gl_blend[0])
1688 if (newctx->gl_blend[0])
1690 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1693 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1695 STATE_COMPARE(gl_cull_face[0])
1697 if (newctx->gl_cull_face[0])
1699 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1702 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1704 STATE_COMPARE(gl_depth_test[0])
1706 if (newctx->gl_depth_test[0])
1708 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1711 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1713 STATE_COMPARE(gl_dither[0])
1715 if (newctx->gl_dither[0])
1717 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1720 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1725 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1728 STATE_COMPARE(gl_polygon_offset_fill[0])
1730 if (newctx->gl_polygon_offset_fill[0])
1732 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1735 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1737 STATE_COMPARE(gl_sample_alpha_to_coverage[0])
1739 if (newctx->gl_sample_alpha_to_coverage[0])
1741 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1744 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1746 STATE_COMPARE(gl_sample_coverage[0])
1748 if (newctx->gl_sample_coverage[0])
1750 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1753 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1755 STATE_COMPARE(gl_scissor_test[0])
1757 if (newctx->gl_scissor_test[0])
1759 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1762 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1764 STATE_COMPARE(gl_stencil_test[0])
1766 if (newctx->gl_stencil_test[0])
1768 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1771 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1776 flag = oldctx->_enable_flag3 | newctx->_enable_flag3;
1779 STATE_COMPARE(gl_primitive_restart_fixed_index[0])
1781 if (newctx->gl_primitive_restart_fixed_index[0])
1783 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1786 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1788 STATE_COMPARE(gl_rasterizer_discard[0])
1790 if (newctx->gl_rasterizer_discard[0])
1792 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_RASTERIZER_DISCARD))
1795 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_RASTERIZER_DISCARD))
1799 #ifdef COREGL_USE_MODULE_TRACEPATH
1800 tracepath_api_trace_end("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1801 #endif // COREGL_USE_MODULE_TRACEPATH
1803 //------------------//
1805 #ifdef COREGL_USE_MODULE_TRACEPATH
1806 static void *trace_hint_clear_viewport = NULL;
1807 trace_hint_clear_viewport = tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1808 #endif // COREGL_USE_MODULE_TRACEPATH
1810 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1814 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint))
1816 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1817 newctx->gl_viewport[1],
1818 newctx->gl_viewport[2],
1819 newctx->gl_viewport[3]))
1822 STATE_COMPARE(gl_current_program[0])
1824 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1826 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf))
1828 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1829 newctx->gl_color_clear_value[1],
1830 newctx->gl_color_clear_value[2],
1831 newctx->gl_color_clear_value[3]))
1837 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1840 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean))
1842 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1843 newctx->gl_color_writemask[1],
1844 newctx->gl_color_writemask[2],
1845 newctx->gl_color_writemask[3]))
1847 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf))
1849 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1850 newctx->gl_depth_range[1]))
1852 STATE_COMPARE(gl_depth_clear_value[0])
1854 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1856 STATE_COMPARE(gl_depth_func[0])
1858 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1860 STATE_COMPARE(gl_depth_writemask[0])
1862 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1864 STATE_COMPARE(gl_cull_face_mode[0])
1866 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1871 #ifdef COREGL_USE_MODULE_TRACEPATH
1872 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1873 #endif // COREGL_USE_MODULE_TRACEPATH
1875 //------------------//
1877 #ifdef COREGL_USE_MODULE_TRACEPATH
1878 static void *trace_hint_bind_textures = NULL;
1879 trace_hint_bind_textures = tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1880 #endif // COREGL_USE_MODULE_TRACEPATH
1882 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1886 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++)
1888 STATE_COMPARE(gl_tex_2d_state[i])
1890 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1891 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D, newctx->gl_tex_2d_state[i]))
1893 STATE_COMPARE(gl_tex_3d_state[i])
1895 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1896 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_3D, newctx->gl_tex_3d_state[i]))
1898 STATE_COMPARE(gl_tex_2d_array_state[i])
1900 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1901 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_ARRAY, newctx->gl_tex_2d_array_state[i]))
1903 STATE_COMPARE(gl_tex_cube_state[i])
1905 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1906 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP, newctx->gl_tex_cube_state[i]))
1908 STATE_COMPARE(gl_tex_external_oes_state[i])
1910 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1911 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_EXTERNAL_OES, newctx->gl_tex_external_oes_state[i]))
1915 // Restore active texture
1916 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1918 STATE_COMPARE(gl_generate_mipmap_hint[0])
1920 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT, newctx->gl_generate_mipmap_hint[0]))
1923 #ifdef COREGL_USE_MODULE_TRACEPATH
1924 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1925 #endif // COREGL_USE_MODULE_TRACEPATH
1927 //------------------//
1928 #ifdef COREGL_USE_MODULE_TRACEPATH
1929 static void *trace_hint_etc = NULL;
1930 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1931 #endif // COREGL_USE_MODULE_TRACEPATH
1933 flag = oldctx->_blend_flag | newctx->_blend_flag;
1936 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf))
1938 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
1939 newctx->gl_blend_color[1],
1940 newctx->gl_blend_color[2],
1941 newctx->gl_blend_color[3]))
1943 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
1944 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
1945 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
1946 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0]))
1948 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
1949 newctx->gl_blend_dst_rgb[0],
1950 newctx->gl_blend_src_alpha[0],
1951 newctx->gl_blend_dst_alpha[0]))
1953 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
1954 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0]))
1956 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
1961 //------------------//
1963 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
1966 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
1967 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
1968 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0]))
1970 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
1971 newctx->gl_stencil_func[0],
1972 newctx->gl_stencil_ref[0],
1973 newctx->gl_stencil_value_mask[0]))
1975 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
1976 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0]) ||
1977 (oldctx->gl_stencil_pass_depth_pass[0] != newctx->gl_stencil_pass_depth_pass[0]))
1979 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
1980 newctx->gl_stencil_fail[0],
1981 newctx->gl_stencil_pass_depth_fail[0],
1982 newctx->gl_stencil_pass_depth_pass[0]))
1985 STATE_COMPARE(gl_stencil_writemask[0])
1987 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT, newctx->gl_stencil_writemask[0]))
1993 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
1996 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
1997 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
1998 (oldctx->gl_stencil_back_value_mask[0] != newctx->gl_stencil_back_value_mask[0]))
2000 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
2001 newctx->gl_stencil_back_func[0],
2002 newctx->gl_stencil_back_ref[0],
2003 newctx->gl_stencil_back_value_mask[0]))
2005 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
2006 (oldctx->gl_stencil_back_pass_depth_fail[0] != newctx->gl_stencil_back_pass_depth_fail[0]) ||
2007 (oldctx->gl_stencil_back_pass_depth_pass[0] != newctx->gl_stencil_back_pass_depth_pass[0]))
2009 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
2010 newctx->gl_stencil_back_fail[0],
2011 newctx->gl_stencil_back_pass_depth_fail[0],
2012 newctx->gl_stencil_back_pass_depth_pass[0]))
2015 STATE_COMPARE(gl_stencil_back_writemask[0])
2017 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK, newctx->gl_stencil_back_writemask[0]))
2019 STATE_COMPARE(gl_stencil_clear_value[0])
2021 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
2025 //------------------//
2027 flag = oldctx->_pixel_flag1 | newctx->_pixel_flag1;
2030 STATE_COMPARE(gl_pack_row_length[0])
2032 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ROW_LENGTH, newctx->gl_pack_row_length[0]))
2034 STATE_COMPARE(gl_pack_skip_rows[0])
2036 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_ROWS, newctx->gl_pack_skip_rows[0]))
2038 STATE_COMPARE(gl_pack_skip_pixels[0])
2040 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_PIXELS, newctx->gl_pack_skip_pixels[0]))
2042 STATE_COMPARE(gl_pack_alignment[0])
2044 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT, newctx->gl_pack_alignment[0]))
2049 flag = oldctx->_pixel_flag2 | newctx->_pixel_flag2;
2052 STATE_COMPARE(gl_unpack_row_length[0])
2054 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ROW_LENGTH, newctx->gl_unpack_row_length[0]))
2056 STATE_COMPARE(gl_unpack_skip_rows[0])
2058 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_ROWS, newctx->gl_unpack_skip_rows[0]))
2060 STATE_COMPARE(gl_unpack_skip_pixels[0])
2062 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_PIXELS, newctx->gl_unpack_skip_pixels[0]))
2064 STATE_COMPARE(gl_unpack_alignment[0])
2066 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT, newctx->gl_unpack_alignment[0]))
2068 STATE_COMPARE(gl_unpack_image_height[0])
2070 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, newctx->gl_unpack_image_height[0]))
2072 STATE_COMPARE(gl_unpack_skip_images[0])
2074 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_IMAGES, newctx->gl_unpack_skip_images[0]))
2078 //------------------//
2080 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
2083 STATE_COMPARE(gl_front_face[0])
2085 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
2087 STATE_COMPARE(gl_line_width[0])
2089 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
2091 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0]) ||
2092 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0]))
2094 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(newctx->gl_polygon_offset_factor[0],
2095 newctx->gl_polygon_offset_units[0]))
2097 if ((oldctx->gl_sample_coverage_value[0] != newctx->gl_sample_coverage_value[0]) ||
2098 (oldctx->gl_sample_coverage_invert[0] != newctx->gl_sample_coverage_invert[0]))
2100 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(newctx->gl_sample_coverage_value[0],
2101 newctx->gl_sample_coverage_invert[0]))
2103 STATE_COMPARE(gl_fragment_shader_derivative_hint[0])
2105 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, newctx->gl_fragment_shader_derivative_hint[0]))
2110 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
2113 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint))
2115 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
2116 newctx->gl_scissor_box[1],
2117 newctx->gl_scissor_box[2],
2118 newctx->gl_scissor_box[3]))
2123 flag = oldctx->_misc_flag3 | newctx->_misc_flag3;
2126 STATE_COMPARE(gl_read_buffer[0])
2128 CHECK_GL_ERROR(_orig_fastpath_glReadBuffer(newctx->gl_read_buffer[0]))
2130 STATES_COMPARE(gl_draw_buffers, 16 * sizeof(GLenum))
2132 int drawBuffSize = 16;
2133 /* If the context has only default framebuffer, then size of glDrawBuffers can only be 1 */
2134 if(fastpath_ostate_has_object_type(&newctx->ostate, GL_OBJECT_TYPE_FRAMEBUFFER) == 0) {
2138 CHECK_GL_ERROR(_orig_fastpath_glDrawBuffers(drawBuffSize, newctx->gl_draw_buffers))
2140 STATE_COMPARE(gl_vertex_array_binding[0])
2142 CHECK_GL_ERROR(_orig_fastpath_glBindVertexArray(newctx->gl_vertex_array_binding[0]))
2145 if (oldctx->gl_transform_feedback_active[0] == GL_TRUE && oldctx->gl_transform_feedback_paused[0] == GL_FALSE)
2147 CHECK_GL_ERROR(_orig_fastpath_glPauseTransformFeedback())
2149 STATE_COMPARE(gl_transform_feedback_binding[0])
2151 CHECK_GL_ERROR(_orig_fastpath_glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, newctx->gl_transform_feedback_binding[0]))
2153 if (newctx->gl_transform_feedback_active[0] == GL_TRUE && newctx->gl_transform_feedback_paused[0] == GL_FALSE)
2155 CHECK_GL_ERROR(_orig_fastpath_glResumeTransformFeedback())
2159 #ifdef COREGL_USE_MODULE_TRACEPATH
2160 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
2161 #endif // COREGL_USE_MODULE_TRACEPATH
2168 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
2169 if (unlikely(trace_state_flag == 1))
2170 fastpath_dump_context_states(newctx, 0);
2171 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
2173 #undef STATE_COMPARE
2174 #undef STATES_COMPARE