1 #include "coregl_fastpath.h"
10 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST = NULL;
11 #include "../../headers/sym.h"
14 Fastpath_Opt_Flag fp_opt = FP_UNKNOWN_PATH;
17 FILE *trace_fp = NULL;
19 GLenum FPGL_Error = GL_NO_ERROR;
21 GLGlueContext_List *gctx_list = NULL;
23 Mutex init_context_mutex = MUTEX_INITIALIZER;
24 GLGlueContext *initial_ctx = NULL;
26 Mutex ctx_list_access_mutex = MUTEX_INITIALIZER;
28 GLContext_List *glctx_list = NULL;
31 _state_get_texture_states(GLenum pname, GLint *params)
33 GLuint cur_active_tex = 0;
35 AST(initial_ctx != NULL);
37 _orig_fastpath_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
39 for (i = 0; i < initial_ctx->gl_num_tex_units[0]; i++)
41 _orig_fastpath_glActiveTexture(GL_TEXTURE0 + i);
42 _orig_fastpath_glGetIntegerv(pname, &(((GLint *)params)[i]));
44 _orig_fastpath_glActiveTexture(cur_active_tex);
48 _state_get_draw_buffers(GLenum *params)
50 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER0, &(((GLint *)params)[0]));
51 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER1, &(((GLint *)params)[1]));
52 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER2, &(((GLint *)params)[2]));
53 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER3, &(((GLint *)params)[3]));
54 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER4, &(((GLint *)params)[4]));
55 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER5, &(((GLint *)params)[5]));
56 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER6, &(((GLint *)params)[6]));
57 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER7, &(((GLint *)params)[7]));
58 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER8, &(((GLint *)params)[8]));
59 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER9, &(((GLint *)params)[9]));
60 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER10, &(((GLint *)params)[10]));
61 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER11, &(((GLint *)params)[11]));
62 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER12, &(((GLint *)params)[12]));
63 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER13, &(((GLint *)params)[13]));
64 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER14, &(((GLint *)params)[14]));
65 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER15, &(((GLint *)params)[15]));
69 _state_get_transform_feedback_buffer_bindings(GLuint *params)
71 AST(initial_ctx != NULL);
74 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0]; i++)
76 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, i, &(((GLint *)params)[i]));
81 _state_get_transform_feedback_buffer_bindings_offset(GLintptr *params)
83 AST(initial_ctx != NULL);
86 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0]; i++)
88 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_START, i, &(((GLint *)params)[i]));
93 _state_get_transform_feedback_buffer_bindings_size(GLsizeiptr *params)
95 AST(initial_ctx != NULL);
98 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0]; i++)
100 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE, i, &(((GLint *)params)[i]));
105 _state_get_uniform_buffer_bindings(GLuint *params)
107 AST(initial_ctx != NULL);
110 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++)
112 /////////////////////////////////////////////////////////////////////////////////
113 // XXXX : AVOID SEGFAULT in ADRENO
114 ((GLint *)params)[i] = 0;
115 // _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, i, &(((GLint *)params)[i]));
116 /////////////////////////////////////////////////////////////////////////////////
121 _state_get_uniform_buffer_bindings_offset(GLintptr *params)
123 AST(initial_ctx != NULL);
126 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++)
128 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_START, i, &(((GLint *)params)[i]));
133 _state_get_uniform_buffer_bindings_size(GLsizeiptr *params)
135 AST(initial_ctx != NULL);
138 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++)
140 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, i, &(((GLint *)params)[i]));
145 fastpath_state_get_draw_buffers(GLenum *params)
147 _state_get_draw_buffers(params);
151 init_modules_fastpath()
153 int fastpath_opt = 0;
154 int fastpath_force_off_opt = 0;
156 COREGL_LOG("[CoreGL] <Fastpath> : ");
158 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
159 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
161 if (fastpath_force_off_opt == 1)
163 COREGL_LOG("\E[40;31;1m(DISABLED by force option)\E[0m ");
167 switch (fastpath_opt)
170 COREGL_LOG("(%d) Fastpath enabled...\n", fastpath_opt);
171 fp_opt = FP_FAST_PATH;
174 COREGL_LOG("(%d) Default API path enabled...\n", fastpath_opt);
175 fp_opt = FP_NORMAL_PATH;
179 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
184 deinit_modules_fastpath()
186 GLContext_List *current = NULL;
188 AST(mutex_lock(&ctx_list_access_mutex) == 1);
190 // Destroy remained context & Detect leaks
191 int retry_destroy = 0;
196 current = glctx_list;
199 if (current->cstate != NULL)
201 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);
203 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
204 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
206 fastpath_remove_context_states_from_list(current->cstate, NULL);
211 glctx_list = current->next;
213 current = glctx_list;
215 if (retry_destroy == 0) break;
220 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
224 init_modules_tstate_fastpath(GLThreadState *tstate)
226 MY_MODULE_TSTATE *tstate_mt = NULL;
228 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
230 tstate_mt->binded_api = EGL_OPENGL_ES_API;
232 tstate->module_data[MY_MODULE_ID] = tstate_mt;
236 deinit_modules_tstate_fastpath(GLThreadState *tstate)
238 if (tstate->module_data[MY_MODULE_ID] != NULL)
240 free(tstate->module_data[MY_MODULE_ID]);
241 tstate->module_data[MY_MODULE_ID] = NULL;
246 fastpath_apply_overrides()
251 fastpath_apply_overrides_egl(1);
252 fastpath_apply_overrides_gl(1);
257 COREGL_ERR("Invalide GL Override Option!!!\n");
264 fastpath_apply_overrides_egl(int enable)
266 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
267 # include "../../headers/sym_egl.h"
268 #undef _COREGL_SYMBOL
270 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
272 COREGL_OVERRIDE(fastpath_, eglBindAPI);
273 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
275 COREGL_OVERRIDE(fastpath_, eglCreateContext);
276 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
277 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
278 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
279 COREGL_OVERRIDE(fastpath_, eglQueryContext);
280 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
281 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
282 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
283 COREGL_OVERRIDE(fastpath_, eglTerminate);
288 fastpath_apply_overrides_gl(int enable)
290 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
291 # include "../../headers/sym_gl.h"
292 #undef _COREGL_SYMBOL
296 COREGL_OVERRIDE(fastpath_, glGetError);
297 COREGL_OVERRIDE(fastpath_, glGetString);
299 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
300 COREGL_OVERRIDE(fastpath_, glGetFloatv);
301 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
303 COREGL_OVERRIDE(fastpath_, glActiveTexture);
304 COREGL_OVERRIDE(fastpath_, glGenTextures);
305 COREGL_OVERRIDE(fastpath_, glBindTexture);
306 COREGL_OVERRIDE(fastpath_, glIsTexture);
307 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
308 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
310 COREGL_OVERRIDE(fastpath_, glGenBuffers);
311 COREGL_OVERRIDE(fastpath_, glBindBuffer);
312 COREGL_OVERRIDE(fastpath_, glIsBuffer);
313 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
315 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
316 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
317 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
318 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
319 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
321 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
322 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
323 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
324 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
325 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
327 COREGL_OVERRIDE(fastpath_, glCreateShader);
328 COREGL_OVERRIDE(fastpath_, glCreateProgram);
329 COREGL_OVERRIDE(fastpath_, glAttachShader);
330 COREGL_OVERRIDE(fastpath_, glCompileShader);
331 COREGL_OVERRIDE(fastpath_, glShaderBinary);
332 COREGL_OVERRIDE(fastpath_, glDeleteShader);
333 COREGL_OVERRIDE(fastpath_, glDetachShader);
334 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
335 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
336 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
337 COREGL_OVERRIDE(fastpath_, glIsShader);
338 COREGL_OVERRIDE(fastpath_, glShaderSource);
339 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
340 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
341 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
342 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
343 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
344 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
345 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
346 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
347 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
348 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
349 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
350 COREGL_OVERRIDE(fastpath_, glIsProgram);
351 COREGL_OVERRIDE(fastpath_, glLinkProgram);
352 COREGL_OVERRIDE(fastpath_, glUseProgram);
353 COREGL_OVERRIDE(fastpath_, glValidateProgram);
355 COREGL_OVERRIDE(fastpath_, glBlendColor);
356 COREGL_OVERRIDE(fastpath_, glBlendEquation);
357 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
358 COREGL_OVERRIDE(fastpath_, glBlendFunc);
359 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
360 COREGL_OVERRIDE(fastpath_, glClearColor);
361 COREGL_OVERRIDE(fastpath_, glClearDepthf);
362 COREGL_OVERRIDE(fastpath_, glClearStencil);
363 COREGL_OVERRIDE(fastpath_, glColorMask);
364 COREGL_OVERRIDE(fastpath_, glCullFace);
365 COREGL_OVERRIDE(fastpath_, glDepthFunc);
366 COREGL_OVERRIDE(fastpath_, glDepthMask);
367 COREGL_OVERRIDE(fastpath_, glDepthRangef);
368 COREGL_OVERRIDE(fastpath_, glDisable);
369 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
370 COREGL_OVERRIDE(fastpath_, glEnable);
371 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
372 COREGL_OVERRIDE(fastpath_, glFrontFace);
373 COREGL_OVERRIDE(fastpath_, glHint);
374 COREGL_OVERRIDE(fastpath_, glLineWidth);
375 COREGL_OVERRIDE(fastpath_, glPixelStorei);
376 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
377 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
378 COREGL_OVERRIDE(fastpath_, glScissor);
379 COREGL_OVERRIDE(fastpath_, glStencilFunc);
380 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
381 COREGL_OVERRIDE(fastpath_, glStencilMask);
382 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
383 COREGL_OVERRIDE(fastpath_, glStencilOp);
384 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
385 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
386 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
387 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
388 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
389 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
390 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
391 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
392 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
393 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
394 COREGL_OVERRIDE(fastpath_, glViewport);
397 COREGL_OVERRIDE(fastpath_, glUseProgramStagesEXT);
398 COREGL_OVERRIDE(fastpath_, glActiveShaderProgramEXT);
399 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
400 COREGL_OVERRIDE(fastpath_, glProgramUniform1iEXT);
401 COREGL_OVERRIDE(fastpath_, glProgramUniform2iEXT);
402 COREGL_OVERRIDE(fastpath_, glProgramUniform3iEXT);
403 COREGL_OVERRIDE(fastpath_, glProgramUniform4iEXT);
404 COREGL_OVERRIDE(fastpath_, glProgramUniform1fEXT);
405 COREGL_OVERRIDE(fastpath_, glProgramUniform2fEXT);
406 COREGL_OVERRIDE(fastpath_, glProgramUniform3fEXT);
407 COREGL_OVERRIDE(fastpath_, glProgramUniform4fEXT);
408 COREGL_OVERRIDE(fastpath_, glProgramUniform1ivEXT);
409 COREGL_OVERRIDE(fastpath_, glProgramUniform2ivEXT);
410 COREGL_OVERRIDE(fastpath_, glProgramUniform3ivEXT);
411 COREGL_OVERRIDE(fastpath_, glProgramUniform4ivEXT);
412 COREGL_OVERRIDE(fastpath_, glProgramUniform1fvEXT);
413 COREGL_OVERRIDE(fastpath_, glProgramUniform2fvEXT);
414 COREGL_OVERRIDE(fastpath_, glProgramUniform3fvEXT);
415 COREGL_OVERRIDE(fastpath_, glProgramUniform4fvEXT);
416 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fvEXT);
417 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fvEXT);
418 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fvEXT);
419 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
420 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
421 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
422 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
423 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
425 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
426 COREGL_OVERRIDE(fastpath_, glEGLImageTargetTexture2DOES);
427 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
429 COREGL_OVERRIDE(fastpath_, glReadBuffer);
431 COREGL_OVERRIDE(fastpath_, glGenQueries);
432 COREGL_OVERRIDE(fastpath_, glDeleteQueries);
433 COREGL_OVERRIDE(fastpath_, glIsQuery);
434 COREGL_OVERRIDE(fastpath_, glBeginQuery);
435 COREGL_OVERRIDE(fastpath_, glGetQueryiv);
436 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
437 COREGL_OVERRIDE(fastpath_, glDrawBuffers);
438 COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
440 COREGL_OVERRIDE(fastpath_, glBindVertexArray);
441 COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
442 COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
443 COREGL_OVERRIDE(fastpath_, glIsVertexArray);
445 COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
447 COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
448 COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
449 COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
450 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
452 COREGL_OVERRIDE(fastpath_, glBindBufferRange);
453 COREGL_OVERRIDE(fastpath_, glBindBufferBase);
454 COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
455 COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
456 COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
457 COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
458 COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
459 COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
460 COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
461 COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
462 COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
463 COREGL_OVERRIDE(fastpath_, glGetStringi);
464 COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
465 COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
466 COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
467 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
468 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
469 COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
470 COREGL_OVERRIDE(fastpath_, glGetInteger64v);
471 COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
472 COREGL_OVERRIDE(fastpath_, glGenSamplers);
473 COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
474 COREGL_OVERRIDE(fastpath_, glIsSampler);
475 COREGL_OVERRIDE(fastpath_, glBindSampler);
476 COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
477 COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
478 COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
479 COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
480 COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
481 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
482 COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
483 COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
484 COREGL_OVERRIDE(fastpath_, glProgramBinary);
485 COREGL_OVERRIDE(fastpath_, glProgramParameteri);
490 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
496 static inline GL_Object_Hash_Base *
497 _lock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
501 case GL_OBJECT_TYPE_QUERY:
502 return &ostate->query;
503 case GL_OBJECT_TYPE_TEXTURE:
504 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
505 return &ostate->shared->texture;
506 case GL_OBJECT_TYPE_BUFFER:
507 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
508 return &ostate->shared->buffer;
509 case GL_OBJECT_TYPE_FRAMEBUFFER:
510 return &ostate->framebuffer;
511 case GL_OBJECT_TYPE_RENDERBUFFER:
512 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
513 return &ostate->shared->renderbuffer;
514 case GL_OBJECT_TYPE_PROGRAM:
515 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
516 return &ostate->shared->program;
517 case GL_OBJECT_TYPE_VERTEXARRAY:
518 return &ostate->vertexarray;
519 case GL_OBJECT_TYPE_SAMPLER:
520 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
521 return &ostate->shared->sampler;
522 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
523 return &ostate->transformfeedback;
530 _unlock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
534 case GL_OBJECT_TYPE_TEXTURE:
535 case GL_OBJECT_TYPE_BUFFER:
536 case GL_OBJECT_TYPE_RENDERBUFFER:
537 case GL_OBJECT_TYPE_PROGRAM:
538 case GL_OBJECT_TYPE_SAMPLER:
539 AST(mutex_unlock(&ostate->shared->access_mutex) == 1);
545 static inline GL_Object_Hash_Base *
546 _lock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
550 case GL_OBJECT_TYPE_QUERY:
551 return &ostate->query_real;
552 case GL_OBJECT_TYPE_TEXTURE:
553 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
554 return &ostate->shared->texture_real;
555 case GL_OBJECT_TYPE_BUFFER:
556 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
557 return &ostate->shared->buffer_real;
558 case GL_OBJECT_TYPE_FRAMEBUFFER:
559 return &ostate->framebuffer_real;
560 case GL_OBJECT_TYPE_RENDERBUFFER:
561 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
562 return &ostate->shared->renderbuffer_real;
563 case GL_OBJECT_TYPE_PROGRAM:
564 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
565 return &ostate->shared->program_real;
566 case GL_OBJECT_TYPE_VERTEXARRAY:
567 return &ostate->vertexarray_real;
568 case GL_OBJECT_TYPE_SAMPLER:
569 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
570 return &ostate->shared->sampler_real;
571 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
572 return &ostate->transformfeedback_real;
579 _unlock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
583 case GL_OBJECT_TYPE_TEXTURE:
584 case GL_OBJECT_TYPE_BUFFER:
585 case GL_OBJECT_TYPE_RENDERBUFFER:
586 case GL_OBJECT_TYPE_PROGRAM:
587 case GL_OBJECT_TYPE_SAMPLER:
588 AST(mutex_unlock(&ostate->shared->real_access_mutex) == 1);
596 fastpath_add_context_state_to_list(const void *option, const int option_len, GLContextState *cstate, Mutex *mtx)
600 GLContext_List *current = NULL;
601 GLContext_List *newitm = NULL;
603 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
607 tid = get_current_thread();
609 current = glctx_list;
610 while (current != NULL)
612 if (current->option_len == option_len &&
613 memcmp(current->option, option, option_len) == 0 &&
614 current->thread_id == tid)
616 AST(current->cstate == cstate);
619 current = current->next;
622 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
625 COREGL_ERR("Failed to create context list.\n");
629 newitm->cstate = cstate;
630 newitm->thread_id = tid;
631 newitm->option_len = option_len;
632 newitm->option = (void *)malloc(option_len);
633 memcpy(newitm->option, option, option_len);
635 if (glctx_list != NULL)
636 newitm->next = glctx_list;
657 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
663 fastpath_get_context_state_from_list(const void *option, const int option_len, Mutex *mtx)
665 GLContextState *ret = NULL;
666 GLContext_List *current = NULL;
669 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
671 tid = get_current_thread();
673 current = glctx_list;
674 while (current != NULL)
676 if (current->option_len == option_len &&
677 memcmp(current->option, option, option_len) == 0 &&
678 current->thread_id == tid)
680 ret = current->cstate;
683 current = current->next;
688 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
693 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
697 GLContext_List *olditm = NULL;
698 GLContext_List *current = NULL;
700 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
704 tid = get_current_thread();
705 current = glctx_list;
707 while (current != NULL)
709 if (current->cstate == cstate)
711 GLContext_List *nextitm = NULL;
714 olditm->next = current->next;
715 nextitm = olditm->next;
719 glctx_list = current->next;
720 nextitm = glctx_list;
722 if (current->option != NULL)
724 AST(current->option_len > 0);
725 free(current->option);
726 current->option = NULL;
727 current->option_len = 0;
735 current = current->next;
740 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
746 #define HASH_INIT(hash_base) \
747 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
748 hash_base.hash_size = GL_OBJECT_HASH_BASE;
751 fastpath_ostate_init(GL_Object_State *ostate)
753 HASH_INIT(ostate->query);
754 HASH_INIT(ostate->framebuffer);
755 HASH_INIT(ostate->vertexarray);
756 HASH_INIT(ostate->transformfeedback);
758 HASH_INIT(ostate->query_real);
759 HASH_INIT(ostate->framebuffer_real);
760 HASH_INIT(ostate->vertexarray_real);
761 HASH_INIT(ostate->transformfeedback_real);
765 fastpath_sostate_init(GL_Shared_Object_State *sostate)
767 mutex_init(&sostate->access_mutex);
769 HASH_INIT(sostate->texture);
770 HASH_INIT(sostate->buffer);
771 HASH_INIT(sostate->renderbuffer);
772 HASH_INIT(sostate->program);
773 HASH_INIT(sostate->sampler);
775 HASH_INIT(sostate->texture_real);
776 HASH_INIT(sostate->buffer_real);
777 HASH_INIT(sostate->renderbuffer_real);
778 HASH_INIT(sostate->program_real);
779 HASH_INIT(sostate->sampler_real);
786 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
788 int array_idx = data->hash_key & (hash_base->hash_size - 1);
789 if (hash_base->hash_field[array_idx] == NULL)
791 hash_base->hash_field[array_idx] = data;
795 GL_Object_Hash *current = hash_base->hash_field[array_idx];
798 AST(current->hash_key != data->hash_key);
799 current = current->next;
801 current->next = data;
804 hash_base->item_size++;
808 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
811 int array_idx = hash & (hash_base->hash_size - 1);
813 GL_Object_Hash *current = hash_base->hash_field[array_idx];
814 GL_Object_Hash *prev = NULL;
818 if (current->hash_key == hash)
821 prev->next = current->next;
823 hash_base->hash_field[array_idx] = current->next;
824 hash_base->item_size--;
829 current = current->next;
836 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
838 if (hash_base->item_size == 0) return;
840 for (int i = 0; i < hash_base->hash_size; i++)
842 if (hash_base->hash_field[i] != NULL)
844 GL_Object_Hash *current = hash_base->hash_field[i];
846 while (current != NULL)
848 GL_Object_Hash *current_next = current->next;
850 if (free_data == 1 && current->item != NULL)
856 hash_base->item_size--;
857 current = current_next;
865 #define HASH_DEINIT(hash_base, free_data) \
866 _free_hash_list(&hash_base, free_data); \
867 free(hash_base.hash_field); \
868 hash_base.hash_size = 0;
871 fastpath_ostate_deinit(GL_Object_State *ostate)
873 HASH_DEINIT(ostate->query, 1);
874 HASH_DEINIT(ostate->framebuffer, 1);
875 HASH_DEINIT(ostate->vertexarray, 1);
876 HASH_DEINIT(ostate->transformfeedback, 1);
878 HASH_DEINIT(ostate->query_real, 0);
879 HASH_DEINIT(ostate->framebuffer_real, 0);
880 HASH_DEINIT(ostate->vertexarray_real, 0);
881 HASH_DEINIT(ostate->transformfeedback_real, 0);
885 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
887 HASH_DEINIT(sostate->texture, 1);
888 HASH_DEINIT(sostate->buffer, 1);
889 HASH_DEINIT(sostate->renderbuffer, 1);
890 HASH_DEINIT(sostate->program, 1);
891 HASH_DEINIT(sostate->sampler, 1);
893 HASH_DEINIT(sostate->texture_real, 0);
894 HASH_DEINIT(sostate->buffer_real, 0);
895 HASH_DEINIT(sostate->renderbuffer_real, 0);
896 HASH_DEINIT(sostate->program_real, 0);
897 HASH_DEINIT(sostate->sampler_real, 0);
904 #define FIND_HASH(hash_base, key, ret) \
906 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
909 if (fh_current->hash_key == (key)) \
914 fh_current = fh_current->next; \
919 _ostate_hash_check(GL_Object_Hash_Base *hash_base)
921 if (hash_base->item_size + 1 < hash_base->hash_size)
924 int oldsize = hash_base->hash_size;
925 GL_Object_Hash **oldfield = hash_base->hash_field;
927 hash_base->hash_size = oldsize << 1;
928 hash_base->hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * hash_base->hash_size);
929 AST(hash_base->hash_field != NULL);
931 for (int i = 0; i < oldsize; i++)
933 if (oldfield[i] != NULL)
935 GL_Object_Hash *current = oldfield[i];
937 while (current != NULL)
939 GL_Object_Hash *current_next = current->next;
940 _add_hash(hash_base, current);
941 hash_base->item_size--;
942 current = current_next;
951 fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name)
953 GLuint ret = _COREGL_INT_INIT_VALUE;
955 GL_Object_Hash_Base *hash_base = NULL;
956 GL_Object_Hash_Base *hash_base_real = NULL;
957 int newid = _COREGL_INT_INIT_VALUE;
959 hash_base = _lock_gl_object_hash(ostate, type);
960 hash_base_real = _lock_gl_object_hash_real(ostate, type);
962 newid = hash_base->last_id + 1;
963 if (newid >= hash_base->hash_size)
965 hash_base->is_looped = 1;
967 hash_base->last_id = 1;
970 if (hash_base->is_looped != 0)
973 int findingid = newid;
975 for (i = 0; i < hash_base->hash_size; i++)
977 GL_Object_Hash *exist_hash = NULL;
978 FIND_HASH(hash_base, findingid, exist_hash);
979 if (exist_hash == NULL)
985 if (findingid >= hash_base->hash_size) findingid = 1;
989 hash_base->last_id = newid;
992 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
994 newobj->id = (int)type + newid;
995 newobj->real_id = real_name;
996 newobj->ref_count = 1;
999 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
1000 AST(newobj_hash != NULL);
1001 newobj_hash->item = newobj;
1002 newobj_hash->hash_key = newid;
1003 _add_hash(hash_base, newobj_hash);
1005 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
1006 AST(newobj_hash_real != NULL);
1007 newobj_hash_real->item = newobj;
1008 newobj_hash_real->hash_key = real_name;
1009 _add_hash(hash_base_real, newobj_hash_real);
1012 _ostate_hash_check(hash_base);
1013 _ostate_hash_check(hash_base_real);
1018 _unlock_gl_object_hash(ostate, type);
1019 _unlock_gl_object_hash_real(ostate, type);
1023 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
1024 if (((int)(hash)) < 0) { ret = 0; goto finish; } \
1026 GL_Object_Hash *object_hash = NULL; \
1027 FIND_HASH((hash_base), (int)(hash), object_hash); \
1028 if (object_hash == NULL) { ret = 0; goto finish; } \
1029 (object) = object_hash->item; \
1030 if ((object) == NULL) { ret = 0; goto finish; } \
1034 fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1036 GLuint ret = _COREGL_INT_INIT_VALUE;
1038 GL_Object_Hash_Base *hash_base = NULL;
1039 GL_Object_Hash_Base *hash_base_real = NULL;
1040 GL_Object *object = NULL;
1042 hash_base = _lock_gl_object_hash(ostate, type);
1043 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1045 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1047 object->ref_count--;
1049 if (object->ref_count <= 0)
1051 GL_Object_Hash *object_hash = NULL;
1053 FIND_HASH(hash_base, object->id - (int)type, object_hash);
1054 AST(object_hash != NULL);
1055 _remove_hash(hash_base, object->id - (int)type);
1059 FIND_HASH(hash_base_real, object->real_id, object_hash);
1060 AST(object_hash != NULL);
1061 _remove_hash(hash_base_real, object->real_id);
1073 _unlock_gl_object_hash(ostate, type);
1074 _unlock_gl_object_hash_real(ostate, type);
1079 fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1081 GLuint ret = _COREGL_INT_INIT_VALUE;
1083 GL_Object_Hash_Base *hash_base = NULL;
1084 GL_Object *object = NULL;
1086 hash_base = _lock_gl_object_hash(ostate, type);
1088 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1090 ret = object->real_id;
1094 _unlock_gl_object_hash(ostate, type);
1099 fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag)
1101 GLint ret = _COREGL_INT_INIT_VALUE;
1103 GL_Object_Hash_Base *hash_base = NULL;
1104 GL_Object *object = NULL;
1105 int hash = _COREGL_INT_INIT_VALUE;
1107 hash_base = _lock_gl_object_hash(ostate, type);
1109 hash = glue_name - (int)type;
1111 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
1113 AST(object->tag == NULL);
1119 _unlock_gl_object_hash(ostate, type);
1124 fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1128 GL_Object_Hash_Base *hash_base = NULL;
1129 GL_Object *object = NULL;
1131 hash_base = _lock_gl_object_hash(ostate, type);
1133 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1139 _unlock_gl_object_hash(ostate, type);
1144 fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name)
1146 GLuint ret = _COREGL_INT_INIT_VALUE;
1148 GL_Object_Hash_Base *hash_base_real = NULL;
1149 GL_Object *object = NULL;
1151 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1153 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
1159 _unlock_gl_object_hash_real(ostate, type);
1164 fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1166 GLint ret = _COREGL_INT_INIT_VALUE;
1168 GL_Object_Hash_Base *hash_base = NULL;
1169 GL_Object *object = NULL;
1171 hash_base = _lock_gl_object_hash(ostate, type);
1173 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1175 object->ref_count++;
1180 _unlock_gl_object_hash(ostate, type);
1185 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
1187 static struct timeval tv_last = { 0, 0 };
1189 if (unlikely(trace_state_flag != 1)) return;
1193 struct timeval tv_now = { 0, 0 };
1194 AST(gettimeofday(&tv_now, NULL) == 0);
1195 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC)
1203 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1204 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n", getpid(), ctx);
1205 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1207 #define PRINTF_CHAR_GLenum "%10d"
1208 #define PRINTF_CHAR_GLboolean "%10d"
1209 #define PRINTF_CHAR_GLint "%10d"
1210 #define PRINTF_CHAR_GLsizei "%10u"
1211 #define PRINTF_CHAR_GLuint "%10u"
1212 #define PRINTF_CHAR_GLuintmask "0x%8X"
1213 #define PRINTF_CHAR_GLintptr "0x%8X"
1214 #define PRINTF_CHAR_GLsizeiptr "%10d"
1216 #define PRINTF_CHAR_GLclampf "%10.6f"
1217 #define PRINTF_CHAR_GLfloat "%10.6f"
1219 #define PRINTF_CHAR_GLvoidptr "%10p"
1221 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1223 #define INITIAL_CTX initial_ctx
1224 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1226 TYPE valuedata[SIZE]; \
1227 TYPE *value = NULL; \
1228 value = valuedata; GET_STMT; value = valuedata; \
1229 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1230 for (int i = 0; i < SIZE; i++) \
1234 TRACE("\n %-30.30s ", "");\
1238 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1239 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1241 TRACE(" \E[40;37;1m)\E[0m\n"); \
1243 # include "coregl_fastpath_state.h"
1247 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1257 fastpath_init_context_states(GLGlueContext *ctx)
1261 AST(mutex_lock(&init_context_mutex) == 1);
1265 COREGL_ERR("Context NULL\n");
1270 AST(ctx->initialized == 0);
1271 AST(ctx->ostate.shared != NULL);
1273 if (initial_ctx == NULL)
1275 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1276 AST(initial_ctx != NULL);
1278 //#define FORCE_DEFAULT_VALUE
1279 #ifdef FORCE_DEFAULT_VALUE
1280 # define INITIAL_CTX initial_ctx
1281 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1284 TYPE valuedata[SIZE]; \
1285 TYPE *value = NULL; \
1286 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1287 value = valuedata; DEFAULT_STMT; value = valuedata; \
1288 for (i = 0; i < SIZE; i++) \
1290 if (*((char *)(&value[i])) == 0xcc) \
1292 memset(&value[i], 0xaa, sizeof(TYPE)); \
1293 value = valuedata; DEFAULT_STMT; value = valuedata; \
1294 if (*((char *)(&value[i])) == 0xaa) \
1296 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1300 initial_ctx->NAME[i] = value[i]; \
1303 # include "coregl_fastpath_state.h"
1307 # define INITIAL_CTX initial_ctx
1308 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1309 if (try_step == 1) \
1311 value = valuedata; DEFAULT_STMT; value = valuedata; \
1315 value = valuedata; FALLBACK_STMT; value = valuedata; \
1318 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1322 TYPE valuedata[SIZE]; \
1323 TYPE *value = NULL; \
1324 _sym_glGetError(); \
1325 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1328 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1329 if (_sym_glGetError() == GL_INVALID_ENUM) \
1331 initial_ctx->NAME##_used = 0; \
1332 value = valuedata; DEFAULT_STMT; value = valuedata; \
1335 initial_ctx->NAME##_used = 1; \
1336 for (i = 0; i < SIZE; i++) \
1338 if (*((char *)(&value[i])) == 0xcc) \
1340 memset(&value[i], 0xaa, sizeof(TYPE)); \
1341 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1342 if (*((char *)(&value[i])) == 0xaa) \
1345 if (try_step == 2) \
1347 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1352 initial_ctx->NAME[i] = value[i]; \
1354 if (try_step != 2) \
1356 value = valuedata; DEFAULT_STMT; value = valuedata; \
1357 for (i = 0; i < SIZE; i++) \
1359 if (initial_ctx->NAME[i] != value[i]) \
1361 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]); \
1366 while (try_step == 2); \
1368 # include "coregl_fastpath_state.h"
1369 # undef SET_GLUE_VALUE
1374 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS)
1376 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]);
1378 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS)
1380 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]);
1386 #define INITIAL_CTX initial_ctx
1387 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1388 for (i = 0; i < SIZE; i++) \
1390 ctx->NAME[i] = initial_ctx->NAME[i]; \
1391 ctx->NAME##_used = initial_ctx->NAME##_used; \
1393 # include "coregl_fastpath_state.h"
1398 ctx->initialized = 1;
1403 AST(mutex_unlock(&init_context_mutex) == 1);
1408 #ifdef COREGL_USE_MODULE_TRACEPATH
1409 extern void *tracepath_api_trace_begin(const char *name, void *hint, int trace_total_time);
1410 extern void *tracepath_api_trace_end(const char *name, void *hint, int trace_total_time);
1413 #define CHECK_GL_ERROR(func) \
1416 int err = _orig_fastpath_glGetError(); \
1417 if (err != GL_NO_ERROR) \
1419 COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1425 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1428 unsigned char flag = 0;
1431 if (debug_nofp == 1)
1437 // Return if they're the same
1438 if (oldctx == newctx)
1444 #define STATE_COMPARE(state) \
1445 if ((oldctx->state) != (newctx->state))
1447 #define STATES_COMPARE(state_ptr, bytes) \
1448 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1451 #ifdef COREGL_USE_MODULE_TRACEPATH
1452 static void *trace_hint_glfinish = NULL;
1453 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1454 #endif // COREGL_USE_MODULE_TRACEPATH
1457 int err = _orig_fastpath_glGetError();
1458 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1459 oldctx->gl_error = err;
1462 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1464 #ifdef COREGL_USE_MODULE_TRACEPATH
1465 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1466 #endif // COREGL_USE_MODULE_TRACEPATH
1469 #ifdef COREGL_USE_MODULE_TRACEPATH
1470 static void *trace_hint_vertex_attrib = NULL;
1471 trace_hint_vertex_attrib = tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1472 #endif // COREGL_USE_MODULE_TRACEPATH
1474 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1477 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++)
1479 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i])
1481 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_vertex_array_buf_id[i]))
1485 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1488 STATE_COMPARE(gl_vertex_array_divisor[i])
1490 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribDivisor(i, newctx->gl_vertex_array_divisor[i]))
1493 if (newctx->gl_vertex_array_size[i] != 0)
1495 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1496 newctx->gl_vertex_array_size[i],
1497 newctx->gl_vertex_array_type[i],
1498 newctx->gl_vertex_array_normalized[i],
1499 newctx->gl_vertex_array_stride[i],
1500 newctx->gl_vertex_array_pointer[i]))
1504 if (newctx->gl_vertex_array_integer[0] == GL_TRUE)
1506 if (newctx->gl_vertex_array_type[0] == GL_UNSIGNED_INT)
1508 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4uiv(i, &newctx->gl_vertex_attrib_value_unsigned_integer[4 * i]))
1512 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4iv(i, &newctx->gl_vertex_attrib_value_integer[4 * i]))
1517 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i, &newctx->gl_vertex_attrib_value[4 * i]))
1521 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE)
1523 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1527 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1533 #ifdef COREGL_USE_MODULE_TRACEPATH
1534 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1535 #endif // COREGL_USE_MODULE_TRACEPATH
1538 #ifdef COREGL_USE_MODULE_TRACEPATH
1539 static void *trace_hint_bindbuffers = NULL;
1540 trace_hint_bindbuffers = tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1541 #endif // COREGL_USE_MODULE_TRACEPATH
1543 //------------------//
1545 flag = oldctx->_bind_flag | newctx->_bind_flag;
1548 STATE_COMPARE(gl_array_buffer_binding[0])
1550 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1552 STATE_COMPARE(gl_copy_read_buffer_binding[0])
1554 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_READ_BUFFER, newctx->gl_copy_read_buffer_binding[0]))
1556 STATE_COMPARE(gl_copy_write_buffer_binding[0])
1558 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_WRITE_BUFFER, newctx->gl_copy_write_buffer_binding[0]))
1560 STATE_COMPARE(gl_element_array_buffer_binding[0])
1562 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1564 STATE_COMPARE(gl_pixel_pack_buffer_binding[0])
1566 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_PACK_BUFFER, newctx->gl_pixel_pack_buffer_binding[0]))
1568 STATE_COMPARE(gl_pixel_unpack_buffer_binding[0])
1570 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, newctx->gl_pixel_unpack_buffer_binding[0]))
1572 STATE_COMPARE(gl_transform_feedback_buffer_binding[0])
1574 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, newctx->gl_transform_feedback_buffer_binding[0]))
1576 STATE_COMPARE(gl_uniform_buffer_binding[0])
1578 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_UNIFORM_BUFFER, newctx->gl_uniform_buffer_binding[0]))
1580 // ANGLE_framebuffer_blit BEGIN
1581 if (newctx->gl_framebuffer_binding_read_used == 1)
1583 STATE_COMPARE(gl_framebuffer_binding_read[0])
1585 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, newctx->gl_framebuffer_binding_read[0]))
1587 STATE_COMPARE(gl_framebuffer_binding_draw[0])
1589 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, newctx->gl_framebuffer_binding_draw[0]))
1593 // ANGLE_framebuffer_blit END
1595 STATE_COMPARE(gl_framebuffer_binding[0])
1597 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER, newctx->gl_framebuffer_binding[0]))
1600 STATE_COMPARE(gl_renderbuffer_binding[0])
1602 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER, newctx->gl_renderbuffer_binding[0]))
1606 #ifdef COREGL_USE_MODULE_TRACEPATH
1607 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1608 #endif // COREGL_USE_MODULE_TRACEPATH
1611 //------------------//
1614 #ifdef COREGL_USE_MODULE_TRACEPATH
1615 static void *trace_hint_enable_states = NULL;
1616 trace_hint_enable_states = tracepath_api_trace_begin("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1617 #endif // COREGL_USE_MODULE_TRACEPATH
1619 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1622 STATE_COMPARE(gl_blend[0])
1624 if (newctx->gl_blend[0])
1626 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1629 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1631 STATE_COMPARE(gl_cull_face[0])
1633 if (newctx->gl_cull_face[0])
1635 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1638 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1640 STATE_COMPARE(gl_depth_test[0])
1642 if (newctx->gl_depth_test[0])
1644 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1647 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1649 STATE_COMPARE(gl_dither[0])
1651 if (newctx->gl_dither[0])
1653 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1656 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1661 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1664 STATE_COMPARE(gl_polygon_offset_fill[0])
1666 if (newctx->gl_polygon_offset_fill[0])
1668 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1671 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1673 STATE_COMPARE(gl_sample_alpha_to_coverage[0])
1675 if (newctx->gl_sample_alpha_to_coverage[0])
1677 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1680 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1682 STATE_COMPARE(gl_sample_coverage[0])
1684 if (newctx->gl_sample_coverage[0])
1686 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1689 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1691 STATE_COMPARE(gl_scissor_test[0])
1693 if (newctx->gl_scissor_test[0])
1695 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1698 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1700 STATE_COMPARE(gl_stencil_test[0])
1702 if (newctx->gl_stencil_test[0])
1704 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1707 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1712 flag = oldctx->_enable_flag3 | newctx->_enable_flag3;
1715 STATE_COMPARE(gl_primitive_restart_fixed_index[0])
1717 if (newctx->gl_primitive_restart_fixed_index[0])
1719 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1722 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1724 STATE_COMPARE(gl_rasterizer_discard[0])
1726 if (newctx->gl_rasterizer_discard[0])
1728 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_RASTERIZER_DISCARD))
1731 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_RASTERIZER_DISCARD))
1735 #ifdef COREGL_USE_MODULE_TRACEPATH
1736 tracepath_api_trace_end("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1737 #endif // COREGL_USE_MODULE_TRACEPATH
1739 //------------------//
1741 #ifdef COREGL_USE_MODULE_TRACEPATH
1742 static void *trace_hint_clear_viewport = NULL;
1743 trace_hint_clear_viewport = tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1744 #endif // COREGL_USE_MODULE_TRACEPATH
1746 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1750 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint))
1752 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1753 newctx->gl_viewport[1],
1754 newctx->gl_viewport[2],
1755 newctx->gl_viewport[3]))
1758 STATE_COMPARE(gl_current_program[0])
1760 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1762 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf))
1764 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1765 newctx->gl_color_clear_value[1],
1766 newctx->gl_color_clear_value[2],
1767 newctx->gl_color_clear_value[3]))
1773 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1776 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean))
1778 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1779 newctx->gl_color_writemask[1],
1780 newctx->gl_color_writemask[2],
1781 newctx->gl_color_writemask[3]))
1783 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf))
1785 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1786 newctx->gl_depth_range[1]))
1788 STATE_COMPARE(gl_depth_clear_value[0])
1790 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1792 STATE_COMPARE(gl_depth_func[0])
1794 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1796 STATE_COMPARE(gl_depth_writemask[0])
1798 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1800 STATE_COMPARE(gl_cull_face_mode[0])
1802 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1807 #ifdef COREGL_USE_MODULE_TRACEPATH
1808 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1809 #endif // COREGL_USE_MODULE_TRACEPATH
1811 //------------------//
1813 #ifdef COREGL_USE_MODULE_TRACEPATH
1814 static void *trace_hint_bind_textures = NULL;
1815 trace_hint_bind_textures = tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1816 #endif // COREGL_USE_MODULE_TRACEPATH
1818 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1822 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++)
1824 STATE_COMPARE(gl_tex_2d_state[i])
1826 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1827 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D, newctx->gl_tex_2d_state[i]))
1829 STATE_COMPARE(gl_tex_3d_state[i])
1831 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1832 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_3D, newctx->gl_tex_3d_state[i]))
1834 STATE_COMPARE(gl_tex_2d_array_state[i])
1836 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1837 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_ARRAY, newctx->gl_tex_2d_array_state[i]))
1839 STATE_COMPARE(gl_tex_cube_state[i])
1841 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1842 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP, newctx->gl_tex_cube_state[i]))
1846 // Restore active texture
1847 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1849 STATE_COMPARE(gl_generate_mipmap_hint[0])
1851 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT, newctx->gl_generate_mipmap_hint[0]))
1854 #ifdef COREGL_USE_MODULE_TRACEPATH
1855 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1856 #endif // COREGL_USE_MODULE_TRACEPATH
1858 //------------------//
1859 #ifdef COREGL_USE_MODULE_TRACEPATH
1860 static void *trace_hint_etc = NULL;
1861 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1862 #endif // COREGL_USE_MODULE_TRACEPATH
1864 flag = oldctx->_blend_flag | newctx->_blend_flag;
1867 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf))
1869 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
1870 newctx->gl_blend_color[1],
1871 newctx->gl_blend_color[2],
1872 newctx->gl_blend_color[3]))
1874 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
1875 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
1876 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
1877 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0]))
1879 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
1880 newctx->gl_blend_dst_rgb[0],
1881 newctx->gl_blend_src_alpha[0],
1882 newctx->gl_blend_dst_alpha[0]))
1884 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
1885 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0]))
1887 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
1892 //------------------//
1894 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
1897 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
1898 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
1899 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0]))
1901 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
1902 newctx->gl_stencil_func[0],
1903 newctx->gl_stencil_ref[0],
1904 newctx->gl_stencil_value_mask[0]))
1906 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
1907 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0]) ||
1908 (oldctx->gl_stencil_pass_depth_pass[0] != newctx->gl_stencil_pass_depth_pass[0]))
1910 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
1911 newctx->gl_stencil_fail[0],
1912 newctx->gl_stencil_pass_depth_fail[0],
1913 newctx->gl_stencil_pass_depth_pass[0]))
1916 STATE_COMPARE(gl_stencil_writemask[0])
1918 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT, newctx->gl_stencil_writemask[0]))
1924 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
1927 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
1928 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
1929 (oldctx->gl_stencil_back_value_mask[0] != newctx->gl_stencil_back_value_mask[0]))
1931 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
1932 newctx->gl_stencil_back_func[0],
1933 newctx->gl_stencil_back_ref[0],
1934 newctx->gl_stencil_back_value_mask[0]))
1936 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
1937 (oldctx->gl_stencil_back_pass_depth_fail[0] != newctx->gl_stencil_back_pass_depth_fail[0]) ||
1938 (oldctx->gl_stencil_back_pass_depth_pass[0] != newctx->gl_stencil_back_pass_depth_pass[0]))
1940 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
1941 newctx->gl_stencil_back_fail[0],
1942 newctx->gl_stencil_back_pass_depth_fail[0],
1943 newctx->gl_stencil_back_pass_depth_pass[0]))
1946 STATE_COMPARE(gl_stencil_back_writemask[0])
1948 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK, newctx->gl_stencil_back_writemask[0]))
1950 STATE_COMPARE(gl_stencil_clear_value[0])
1952 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
1956 //------------------//
1958 flag = oldctx->_pixel_flag1 | newctx->_pixel_flag1;
1961 STATE_COMPARE(gl_pack_row_length[0])
1963 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ROW_LENGTH, newctx->gl_pack_row_length[0]))
1965 STATE_COMPARE(gl_pack_skip_rows[0])
1967 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_ROWS, newctx->gl_pack_skip_rows[0]))
1969 STATE_COMPARE(gl_pack_skip_pixels[0])
1971 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_PIXELS, newctx->gl_pack_skip_pixels[0]))
1973 STATE_COMPARE(gl_pack_alignment[0])
1975 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT, newctx->gl_pack_alignment[0]))
1980 flag = oldctx->_pixel_flag2 | newctx->_pixel_flag2;
1983 STATE_COMPARE(gl_unpack_row_length[0])
1985 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ROW_LENGTH, newctx->gl_unpack_row_length[0]))
1987 STATE_COMPARE(gl_unpack_skip_rows[0])
1989 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_ROWS, newctx->gl_unpack_skip_rows[0]))
1991 STATE_COMPARE(gl_unpack_skip_pixels[0])
1993 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_PIXELS, newctx->gl_unpack_skip_pixels[0]))
1995 STATE_COMPARE(gl_unpack_alignment[0])
1997 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT, newctx->gl_unpack_alignment[0]))
1999 STATE_COMPARE(gl_unpack_image_height[0])
2001 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, newctx->gl_unpack_image_height[0]))
2003 STATE_COMPARE(gl_unpack_skip_images[0])
2005 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_IMAGES, newctx->gl_unpack_skip_images[0]))
2009 //------------------//
2011 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
2014 STATE_COMPARE(gl_front_face[0])
2016 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
2018 STATE_COMPARE(gl_line_width[0])
2020 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
2022 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0]) ||
2023 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0]))
2025 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(newctx->gl_polygon_offset_factor[0],
2026 newctx->gl_polygon_offset_units[0]))
2028 if ((oldctx->gl_sample_coverage_value[0] != newctx->gl_sample_coverage_value[0]) ||
2029 (oldctx->gl_sample_coverage_invert[0] != newctx->gl_sample_coverage_invert[0]))
2031 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(newctx->gl_sample_coverage_value[0],
2032 newctx->gl_sample_coverage_invert[0]))
2034 STATE_COMPARE(gl_fragment_shader_derivative_hint[0])
2036 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, newctx->gl_fragment_shader_derivative_hint[0]))
2041 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
2044 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint))
2046 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
2047 newctx->gl_scissor_box[1],
2048 newctx->gl_scissor_box[2],
2049 newctx->gl_scissor_box[3]))
2054 flag = oldctx->_misc_flag3 | newctx->_misc_flag3;
2057 STATE_COMPARE(gl_read_buffer[0])
2059 CHECK_GL_ERROR(_orig_fastpath_glReadBuffer(newctx->gl_read_buffer[0]))
2061 STATES_COMPARE(gl_draw_buffers, 16 * sizeof(GLenum))
2063 CHECK_GL_ERROR(_orig_fastpath_glDrawBuffers(16, newctx->gl_draw_buffers))
2065 STATE_COMPARE(gl_vertex_array_binding[0])
2067 CHECK_GL_ERROR(_orig_fastpath_glBindVertexArray(newctx->gl_vertex_array_binding[0]))
2070 if (oldctx->gl_transform_feedback_active[0] == GL_TRUE && oldctx->gl_transform_feedback_paused[0] == GL_FALSE)
2072 CHECK_GL_ERROR(_orig_fastpath_glPauseTransformFeedback())
2074 STATE_COMPARE(gl_transform_feedback_binding[0])
2076 CHECK_GL_ERROR(_orig_fastpath_glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, newctx->gl_transform_feedback_binding[0]))
2078 if (newctx->gl_transform_feedback_active[0] == GL_TRUE && newctx->gl_transform_feedback_paused[0] == GL_FALSE)
2080 CHECK_GL_ERROR(_orig_fastpath_glResumeTransformFeedback())
2084 #ifdef COREGL_USE_MODULE_TRACEPATH
2085 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
2086 #endif // COREGL_USE_MODULE_TRACEPATH
2093 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
2094 if (unlikely(trace_state_flag == 1))
2095 fastpath_dump_context_states(newctx, 0);
2096 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
2098 #undef STATE_COMPARE
2099 #undef STATES_COMPARE