1 #include "coregl_fastpath.h"
11 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST = NULL;
12 # include "../headers/sym_gl1.h"
13 # include "../headers/sym_gl2.h"
14 # include "../headers/sym_gl_common.h"
15 # include "../headers/sym_egl.h"
18 Fastpath_Opt_Flag fp_opt = FP_UNKNOWN_PATH;
21 FILE *trace_fp = NULL;
23 GLenum FPGL_Error = GL_NO_ERROR;
25 GLGlueContext_List *gctx_list = NULL;
27 Mutex init_context_mutex = MUTEX_INITIALIZER;
28 GLGlueContext *initial_ctx = NULL;
30 Mutex ctx_list_access_mutex = MUTEX_INITIALIZER;
32 GLContext_List *glctx_list = NULL;
33 static int api_gl_version = COREGL_GLAPI_2;
36 _state_get_texture_states(GLenum pname, GLint *params)
38 GLuint cur_active_tex = 0;
40 AST(initial_ctx != NULL);
42 _orig_fastpath_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
44 for (i = 0; i < initial_ctx->gl_tex_units_num[0]; i++) {
45 _orig_fastpath_glActiveTexture(GL_TEXTURE0 + i);
46 _orig_fastpath_glGetIntegerv(pname, (GLint *)¶ms[i]);
48 _orig_fastpath_glActiveTexture(cur_active_tex);
52 _state_get_draw_buffers(GLenum *params)
54 AST(initial_ctx != NULL);
57 for (i = 0; i < initial_ctx->gl_draw_buffers_num[0]; i++) {
58 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER0 + i, (GLint *)¶ms[i]);
63 _state_get_transform_feedback_buffer_bindings(GLuint *params)
65 AST(initial_ctx != NULL);
68 for (i = 0; i < initial_ctx->gl_transform_feedback_buffer_binding_num[0];
70 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, i,
76 _state_get_transform_feedback_buffer_bindings_offset(GLintptr *params)
78 AST(initial_ctx != NULL);
81 for (i = 0; i < initial_ctx->gl_transform_feedback_buffer_binding_num[0];
83 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_START, i,
89 _state_get_transform_feedback_buffer_bindings_size(GLsizeiptr *params)
91 AST(initial_ctx != NULL);
94 for (i = 0; i < initial_ctx->gl_transform_feedback_buffer_binding_num[0];
96 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE, i,
102 _state_get_uniform_buffer_bindings(GLuint *params)
104 AST(initial_ctx != NULL);
107 for (i = 0; i < initial_ctx->gl_uniform_buffer_binding_num[0]; i++) {
108 /////////////////////////////////////////////////////////////////////////////////
109 // XXXX : AVOID SEGFAULT in ADRENO
110 ((GLint *)params)[i] = 0;
111 // _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, i, (GLint *)¶ms[i]);
112 /////////////////////////////////////////////////////////////////////////////////
117 _state_get_uniform_buffer_bindings_offset(GLintptr *params)
119 AST(initial_ctx != NULL);
122 for (i = 0; i < initial_ctx->gl_uniform_buffer_binding_num[0]; i++) {
123 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_START, i, (GLint *)¶ms[i]);
128 _state_get_uniform_buffer_bindings_size(GLsizeiptr *params)
130 AST(initial_ctx != NULL);
133 for (i = 0; i < initial_ctx->gl_uniform_buffer_binding_num[0]; i++) {
134 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, i, (GLint *)¶ms[i]);
138 /* shader storage buffer */
140 _state_get_shader_storage_buffer_bindings(GLuint *params)
142 AST(initial_ctx != NULL);
145 for (i = 0; i < initial_ctx->gl_shader_storage_buffer_binding_num[0]; i++) {
146 _orig_fastpath_glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_BINDING, i,
147 (GLint *)¶ms[i]);
152 _state_get_shader_storage_buffer_bindings_offset(GLintptr *params)
154 AST(initial_ctx != NULL);
157 for (i = 0; i < initial_ctx->gl_shader_storage_buffer_binding_num[0]; i++) {
158 _orig_fastpath_glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_START, i,
159 (GLint *)¶ms[i]);
164 _state_get_shader_storage_buffer_bindings_size(GLsizeiptr *params)
166 AST(initial_ctx != NULL);
169 for (i = 0; i < initial_ctx->gl_shader_storage_buffer_binding_num[0]; i++) {
170 _orig_fastpath_glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_SIZE, i,
171 (GLint *)¶ms[i]);
175 /* atomic counter buffer */
177 _state_get_atomic_counter_buffer_bindings(GLuint *params)
179 AST(initial_ctx != NULL);
182 for (i = 0; i < initial_ctx->gl_atomic_counter_buffer_binding_num[0]; i++) {
183 _orig_fastpath_glGetIntegeri_v(GL_ATOMIC_COUNTER_BUFFER_BINDING, i,
184 (GLint *)¶ms[i]);
189 _state_get_atomic_counter_buffer_bindings_offset(GLintptr *params)
191 AST(initial_ctx != NULL);
194 for (i = 0; i < initial_ctx->gl_atomic_counter_buffer_binding_num[0]; i++) {
195 _orig_fastpath_glGetIntegeri_v(GL_ATOMIC_COUNTER_BUFFER_START, i,
196 (GLint *)¶ms[i]);
201 _state_get_atomic_counter_buffer_bindings_size(GLsizeiptr *params)
203 AST(initial_ctx != NULL);
206 for (i = 0; i < initial_ctx->gl_atomic_counter_buffer_binding_num[0]; i++) {
207 _orig_fastpath_glGetIntegeri_v(GL_ATOMIC_COUNTER_BUFFER_SIZE, i,
208 (GLint *)¶ms[i]);
213 fastpath_state_get_draw_buffers(GLenum *params)
215 _state_get_draw_buffers(params);
219 init_modules_fastpath()
221 int fastpath_opt = 0;
222 int fastpath_force_off_opt = 0;
224 COREGL_DBG("<Fastpath> : ");
226 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
227 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
229 if (fastpath_force_off_opt == 1) {
230 COREGL_DBG("DISABLED by force option");
234 switch (fastpath_opt) {
236 COREGL_DBG("(%d) Fastpath enabled...", fastpath_opt);
237 fp_opt = FP_FAST_PATH;
240 COREGL_DBG("(%d) Default API path enabled...", fastpath_opt);
241 fp_opt = FP_NORMAL_PATH;
245 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
250 deinit_modules_fastpath()
252 GLContext_List *current = NULL;
254 AST(mutex_lock(&ctx_list_access_mutex) == 1);
256 // Destroy remained context & Detect leaks
257 int retry_destroy = 0;
261 current = glctx_list;
263 if (current->cstate != NULL) {
264 COREGL_WARN("Context attached to [dpy=%p|rctx=%p] has not been completely destroyed.(leak)",
265 current->cstate->rdpy, current->cstate->rctx);
267 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE,
268 EGL_NO_SURFACE, EGL_NO_CONTEXT);
269 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
271 fastpath_remove_context_states_from_list(current->cstate, NULL);
276 glctx_list = current->next;
278 current = glctx_list;
280 if (retry_destroy == 0) break;
285 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
289 init_modules_tstate_fastpath(GLThreadState *tstate)
291 MY_MODULE_TSTATE *tstate_mt = NULL;
293 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
295 if (tstate_mt == NULL) return;
297 tstate_mt->binded_api = EGL_OPENGL_ES_API;
299 tstate->module_data[MY_MODULE_ID] = tstate_mt;
303 deinit_modules_tstate_fastpath(GLThreadState *tstate)
305 if (tstate->module_data[MY_MODULE_ID] != NULL) {
306 free(tstate->module_data[MY_MODULE_ID]);
307 tstate->module_data[MY_MODULE_ID] = NULL;
312 fastpath_apply_overrides()
316 fastpath_apply_overrides_egl(1);
317 fastpath_apply_overrides_gl(1);
322 COREGL_ERR("Invalide GL Override Option!!!");
329 fastpath_apply_overrides_egl(int enable)
331 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
332 # include "../headers/sym_egl.h"
333 #undef _COREGL_SYMBOL
335 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
337 COREGL_OVERRIDE(fastpath_, eglBindAPI);
338 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
340 COREGL_OVERRIDE(fastpath_, eglCreateContext);
341 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
342 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
343 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
344 COREGL_OVERRIDE(fastpath_, eglQueryContext);
345 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
346 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
347 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
348 COREGL_OVERRIDE(fastpath_, eglTerminate);
349 COREGL_OVERRIDE(fastpath_, eglGetCurrentDisplay);
354 fastpath_apply_overrides_gl(int enable)
356 #define _COREGL_START_API(version) api_gl_version = version;
357 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
358 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
359 if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
361 # include "../headers/sym_gl1.h"
362 # include "../headers/sym_gl2.h"
363 # include "../headers/sym_gl_common.h"
364 #undef _COREGL_SYMBOL
365 #undef _COREGL_START_API
366 #undef _COREGL_END_API
368 if (debug_nofp != 1) {
369 if (driver_gl_version >= COREGL_GLAPI_1) {
370 COREGL_OVERRIDE(fastpath_, glClientActiveTexture);
371 COREGL_OVERRIDE(fastpath_, glSampleCoveragex);
374 COREGL_OVERRIDE(fastpath_, glGetError);
375 COREGL_OVERRIDE(fastpath_, glGetString);
377 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
378 COREGL_OVERRIDE(fastpath_, glGetFloatv);
380 COREGL_OVERRIDE(fastpath_, glActiveTexture);
381 COREGL_OVERRIDE(fastpath_, glGenTextures);
382 COREGL_OVERRIDE(fastpath_, glBindTexture);
383 COREGL_OVERRIDE(fastpath_, glIsTexture);
384 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
385 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
387 COREGL_OVERRIDE(fastpath_, glGenBuffers);
388 COREGL_OVERRIDE(fastpath_, glBindBuffer);
389 COREGL_OVERRIDE(fastpath_, glIsBuffer);
390 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
392 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
393 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
394 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
395 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
396 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
398 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
399 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
400 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
401 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
402 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
404 COREGL_OVERRIDE(fastpath_, glCreateShader);
405 COREGL_OVERRIDE(fastpath_, glCreateProgram);
406 COREGL_OVERRIDE(fastpath_, glAttachShader);
407 COREGL_OVERRIDE(fastpath_, glCompileShader);
408 COREGL_OVERRIDE(fastpath_, glShaderBinary);
409 COREGL_OVERRIDE(fastpath_, glDeleteShader);
410 COREGL_OVERRIDE(fastpath_, glDetachShader);
411 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
412 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
413 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
414 COREGL_OVERRIDE(fastpath_, glIsShader);
415 COREGL_OVERRIDE(fastpath_, glShaderSource);
416 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
417 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
418 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
419 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
420 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
421 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
422 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
423 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
424 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
425 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
426 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
427 COREGL_OVERRIDE(fastpath_, glIsProgram);
428 COREGL_OVERRIDE(fastpath_, glLinkProgram);
429 COREGL_OVERRIDE(fastpath_, glUseProgram);
430 COREGL_OVERRIDE(fastpath_, glValidateProgram);
432 COREGL_OVERRIDE(fastpath_, glBlendColor);
433 COREGL_OVERRIDE(fastpath_, glBlendEquation);
434 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
435 COREGL_OVERRIDE(fastpath_, glBlendFunc);
436 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
437 COREGL_OVERRIDE(fastpath_, glClearColor);
438 COREGL_OVERRIDE(fastpath_, glClearDepthf);
439 COREGL_OVERRIDE(fastpath_, glClearStencil);
440 COREGL_OVERRIDE(fastpath_, glColorMask);
441 COREGL_OVERRIDE(fastpath_, glColorMaski);
442 COREGL_OVERRIDE(fastpath_, glColorMaskiOES);
443 COREGL_OVERRIDE(fastpath_, glCullFace);
444 COREGL_OVERRIDE(fastpath_, glDepthFunc);
445 COREGL_OVERRIDE(fastpath_, glDepthMask);
446 COREGL_OVERRIDE(fastpath_, glDepthRangef);
447 COREGL_OVERRIDE(fastpath_, glDisable);
448 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
449 COREGL_OVERRIDE(fastpath_, glEnable);
450 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
451 COREGL_OVERRIDE(fastpath_, glFrontFace);
452 COREGL_OVERRIDE(fastpath_, glHint);
453 COREGL_OVERRIDE(fastpath_, glLineWidth);
454 COREGL_OVERRIDE(fastpath_, glPixelStorei);
455 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
456 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
457 COREGL_OVERRIDE(fastpath_, glScissor);
458 COREGL_OVERRIDE(fastpath_, glStencilFunc);
459 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
460 COREGL_OVERRIDE(fastpath_, glStencilMask);
461 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
462 COREGL_OVERRIDE(fastpath_, glStencilOp);
463 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
464 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
465 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
466 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
467 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
468 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
469 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
470 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
471 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
472 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
473 COREGL_OVERRIDE(fastpath_, glViewport);
475 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
476 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
478 COREGL_OVERRIDE(fastpath_, glUseProgramStagesEXT);
479 COREGL_OVERRIDE(fastpath_, glActiveShaderProgramEXT);
480 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
481 COREGL_OVERRIDE(fastpath_, glProgramUniform1iEXT);
482 COREGL_OVERRIDE(fastpath_, glProgramUniform2iEXT);
483 COREGL_OVERRIDE(fastpath_, glProgramUniform3iEXT);
484 COREGL_OVERRIDE(fastpath_, glProgramUniform4iEXT);
485 COREGL_OVERRIDE(fastpath_, glProgramUniform1fEXT);
486 COREGL_OVERRIDE(fastpath_, glProgramUniform2fEXT);
487 COREGL_OVERRIDE(fastpath_, glProgramUniform3fEXT);
488 COREGL_OVERRIDE(fastpath_, glProgramUniform4fEXT);
489 COREGL_OVERRIDE(fastpath_, glProgramUniform1ivEXT);
490 COREGL_OVERRIDE(fastpath_, glProgramUniform2ivEXT);
491 COREGL_OVERRIDE(fastpath_, glProgramUniform3ivEXT);
492 COREGL_OVERRIDE(fastpath_, glProgramUniform4ivEXT);
493 COREGL_OVERRIDE(fastpath_, glProgramUniform1fvEXT);
494 COREGL_OVERRIDE(fastpath_, glProgramUniform2fvEXT);
495 COREGL_OVERRIDE(fastpath_, glProgramUniform3fvEXT);
496 COREGL_OVERRIDE(fastpath_, glProgramUniform4fvEXT);
497 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fvEXT);
498 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fvEXT);
499 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fvEXT);
501 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
502 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
504 COREGL_OVERRIDE(fastpath_, glBindFramebufferOES);
505 COREGL_OVERRIDE(fastpath_, glBindRenderbufferOES);
506 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffersOES);
507 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffersOES);
508 COREGL_OVERRIDE(fastpath_, glDepthRangefOES);
509 COREGL_OVERRIDE(fastpath_, glDepthRangexOES);
510 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbufferOES);
511 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DOES);
512 COREGL_OVERRIDE(fastpath_, glGenFramebuffersOES);
513 COREGL_OVERRIDE(fastpath_, glGenRenderbuffersOES);
514 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameterivOES);
515 COREGL_OVERRIDE(fastpath_, glGetQueryObjecti64vEXT);
516 COREGL_OVERRIDE(fastpath_, glGetQueryObjectivEXT);
517 COREGL_OVERRIDE(fastpath_, glGetQueryObjectui64vEXT);
518 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuivEXT);
519 COREGL_OVERRIDE(fastpath_, glGetQueryivEXT);
520 COREGL_OVERRIDE(fastpath_, glBeginQueryEXT);
521 COREGL_OVERRIDE(fastpath_, glDeleteQueriesEXT);
522 COREGL_OVERRIDE(fastpath_, glGenQueriesEXT);
523 COREGL_OVERRIDE(fastpath_, glIsFramebufferOES);
524 COREGL_OVERRIDE(fastpath_, glIsQueryEXT);
525 COREGL_OVERRIDE(fastpath_, glIsRenderbufferOES);
526 COREGL_OVERRIDE(fastpath_, glBlendEquationOES);
527 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparateOES);
528 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparateOES);
529 COREGL_OVERRIDE(fastpath_, glPolygonOffsetxOES);
530 COREGL_OVERRIDE(fastpath_, glLineWidthxOES);
531 COREGL_OVERRIDE(fastpath_, glSampleCoveragexOES);
532 COREGL_OVERRIDE(fastpath_, glQueryCounterEXT);
533 COREGL_OVERRIDE(fastpath_, glBindVertexArrayOES);
534 COREGL_OVERRIDE(fastpath_, glDeleteVertexArraysOES);
535 COREGL_OVERRIDE(fastpath_, glGenVertexArraysOES);
536 COREGL_OVERRIDE(fastpath_, glIsVertexArrayOES);
537 COREGL_OVERRIDE(fastpath_, glClearDepthfOES);
538 COREGL_OVERRIDE(fastpath_, glClearDepthxOES);
539 COREGL_OVERRIDE(fastpath_, glGetVertexAttribiv);
540 COREGL_OVERRIDE(fastpath_, glTexBufferOES);
541 COREGL_OVERRIDE(fastpath_, glFramebufferTextureEXT);
542 COREGL_OVERRIDE(fastpath_, glFramebufferTextureOES);
543 COREGL_OVERRIDE(fastpath_, glTexBufferRangeOES);
544 COREGL_OVERRIDE(fastpath_, glSamplerParameterIuivOES);
545 COREGL_OVERRIDE(fastpath_, glSamplerParameterIivOES);
546 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterIuivOES);
547 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterIivOES);
548 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterIivEXT);
549 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterIuivEXT);
550 COREGL_OVERRIDE(fastpath_, glSamplerParameterIivEXT);
551 COREGL_OVERRIDE(fastpath_, glSamplerParameterIuivEXT);
552 COREGL_OVERRIDE(fastpath_, glTexBufferRangeEXT);
553 COREGL_OVERRIDE(fastpath_, glTexBufferEXT);
554 COREGL_OVERRIDE(fastpath_, glFramebufferTextureMultiviewOVR);
555 COREGL_OVERRIDE(fastpath_, glFramebufferTextureMultisampleMultiviewOVR);
556 /* Start overriding GLES 3.0 */
557 if (driver_gl_version >= COREGL_GLAPI_3) {
558 COREGL_OVERRIDE(fastpath_, glReadBuffer);
560 COREGL_OVERRIDE(fastpath_, glGenQueries);
561 COREGL_OVERRIDE(fastpath_, glDeleteQueries);
562 COREGL_OVERRIDE(fastpath_, glIsQuery);
563 COREGL_OVERRIDE(fastpath_, glBeginQuery);
564 COREGL_OVERRIDE(fastpath_, glGetQueryiv);
565 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
566 COREGL_OVERRIDE(fastpath_, glDrawBuffers);
567 COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
569 COREGL_OVERRIDE(fastpath_, glBindVertexArray);
570 COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
571 COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
572 COREGL_OVERRIDE(fastpath_, glIsVertexArray);
574 COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
576 COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
577 COREGL_OVERRIDE(fastpath_, glBeginTransformFeedback);
578 COREGL_OVERRIDE(fastpath_, glEndTransformFeedback);
579 COREGL_OVERRIDE(fastpath_, glPauseTransformFeedback);
580 COREGL_OVERRIDE(fastpath_, glResumeTransformFeedback);
581 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
582 COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
583 COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
584 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
586 COREGL_OVERRIDE(fastpath_, glBindBufferRange);
587 COREGL_OVERRIDE(fastpath_, glBindBufferBase);
588 COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
589 COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
590 COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
591 COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
592 COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
593 COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
594 COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
595 COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
596 COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
597 COREGL_OVERRIDE(fastpath_, glGetStringi);
598 COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
599 COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
600 COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
601 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
602 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
603 COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
604 COREGL_OVERRIDE(fastpath_, glGetInteger64v);
605 COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
606 COREGL_OVERRIDE(fastpath_, glGenSamplers);
607 COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
608 COREGL_OVERRIDE(fastpath_, glIsSampler);
609 COREGL_OVERRIDE(fastpath_, glBindSampler);
610 COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
611 COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
612 COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
613 COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
614 COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
615 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
616 COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
617 COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
618 COREGL_OVERRIDE(fastpath_, glProgramBinary);
619 COREGL_OVERRIDE(fastpath_, glProgramParameteri);
622 if (driver_gl_version >= COREGL_GLAPI_31) {
623 COREGL_OVERRIDE(fastpath_, glCreateShaderProgramv);
624 COREGL_OVERRIDE(fastpath_, glGenProgramPipelines);
625 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineiv);
626 COREGL_OVERRIDE(fastpath_, glBindProgramPipeline);
627 COREGL_OVERRIDE(fastpath_, glDeleteProgramPipelines);
628 COREGL_OVERRIDE(fastpath_, glIsProgramPipeline);
629 COREGL_OVERRIDE(fastpath_, glValidateProgramPipeline);
630 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineInfoLog);
631 COREGL_OVERRIDE(fastpath_, glDispatchCompute);
632 COREGL_OVERRIDE(fastpath_, glDispatchComputeIndirect);
633 COREGL_OVERRIDE(fastpath_, glGetProgramInterfaceiv);
634 COREGL_OVERRIDE(fastpath_, glGetProgramResourceIndex);
635 COREGL_OVERRIDE(fastpath_, glGetProgramResourceName);
636 COREGL_OVERRIDE(fastpath_, glGetProgramResourceiv);
637 COREGL_OVERRIDE(fastpath_, glGetProgramResourceLocation);
638 COREGL_OVERRIDE(fastpath_, glUseProgramStages);
639 COREGL_OVERRIDE(fastpath_, glActiveShaderProgram);
640 COREGL_OVERRIDE(fastpath_, glProgramUniform1iv);
641 COREGL_OVERRIDE(fastpath_, glProgramUniform2iv);
642 COREGL_OVERRIDE(fastpath_, glProgramUniform3iv);
643 COREGL_OVERRIDE(fastpath_, glProgramUniform4iv);
644 COREGL_OVERRIDE(fastpath_, glProgramUniform1fv);
645 COREGL_OVERRIDE(fastpath_, glProgramUniform2fv);
646 COREGL_OVERRIDE(fastpath_, glProgramUniform3fv);
647 COREGL_OVERRIDE(fastpath_, glProgramUniform4fv);
648 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fv);
649 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fv);
650 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fv);
651 COREGL_OVERRIDE(fastpath_, glProgramUniform1i);
652 COREGL_OVERRIDE(fastpath_, glProgramUniform2i);
653 COREGL_OVERRIDE(fastpath_, glProgramUniform3i);
654 COREGL_OVERRIDE(fastpath_, glProgramUniform4i);
655 COREGL_OVERRIDE(fastpath_, glProgramUniform1f);
656 COREGL_OVERRIDE(fastpath_, glProgramUniform2f);
657 COREGL_OVERRIDE(fastpath_, glProgramUniform3f);
658 COREGL_OVERRIDE(fastpath_, glProgramUniform4f);
659 COREGL_OVERRIDE(fastpath_, glProgramUniform1uiv);
660 COREGL_OVERRIDE(fastpath_, glProgramUniform2uiv);
661 COREGL_OVERRIDE(fastpath_, glProgramUniform3uiv);
662 COREGL_OVERRIDE(fastpath_, glProgramUniform4uiv);
663 COREGL_OVERRIDE(fastpath_, glProgramUniform1ui);
664 COREGL_OVERRIDE(fastpath_, glProgramUniform2ui);
665 COREGL_OVERRIDE(fastpath_, glProgramUniform3ui);
666 COREGL_OVERRIDE(fastpath_, glProgramUniform4ui);
667 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x3fv);
668 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x2fv);
669 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x2fv);
670 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x4fv);
671 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x4fv);
672 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x3fv);
673 COREGL_OVERRIDE(fastpath_, glBindImageTexture);
674 COREGL_OVERRIDE(fastpath_, glGetBooleani_v);
675 COREGL_OVERRIDE(fastpath_, glGetMultisamplefv);
676 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameteriv);
677 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameterfv);
678 COREGL_OVERRIDE(fastpath_, glBindVertexBuffer);
681 if (driver_gl_version >= COREGL_GLAPI_32) {
682 COREGL_OVERRIDE(fastpath_, glBlendEquationi);
683 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparatei);
684 COREGL_OVERRIDE(fastpath_, glTexBuffer);
685 COREGL_OVERRIDE(fastpath_, glTexBufferRange);
686 COREGL_OVERRIDE(fastpath_, glFramebufferTexture);
687 COREGL_OVERRIDE(fastpath_, glGetnUniformfv);
688 COREGL_OVERRIDE(fastpath_, glGetnUniformiv);
689 COREGL_OVERRIDE(fastpath_, glGetnUniformuiv);
690 COREGL_OVERRIDE(fastpath_, glSamplerParameterIiv);
691 COREGL_OVERRIDE(fastpath_, glSamplerParameterIuiv);
692 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterIiv);
693 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterIuiv);
696 COREGL_DBG("SKIP GL FASTPATH...");
702 static inline GL_Object_Hash_Base *
703 _lock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
706 case GL_OBJECT_TYPE_QUERY:
707 return &ostate->query;
708 case GL_OBJECT_TYPE_TEXTURE:
709 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
710 return &ostate->shared->texture;
711 case GL_OBJECT_TYPE_BUFFER:
712 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
713 return &ostate->shared->buffer;
714 case GL_OBJECT_TYPE_FRAMEBUFFER:
715 return &ostate->framebuffer;
716 case GL_OBJECT_TYPE_RENDERBUFFER:
717 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
718 return &ostate->shared->renderbuffer;
719 case GL_OBJECT_TYPE_PROGRAM:
720 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
721 return &ostate->shared->program;
722 case GL_OBJECT_TYPE_VERTEXARRAY:
723 return &ostate->vertexarray;
724 case GL_OBJECT_TYPE_SAMPLER:
725 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
726 return &ostate->shared->sampler;
727 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
728 return &ostate->transformfeedback;
729 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
730 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
731 return &ostate->shared->programpipeline;
738 _unlock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
741 case GL_OBJECT_TYPE_TEXTURE:
742 case GL_OBJECT_TYPE_BUFFER:
743 case GL_OBJECT_TYPE_RENDERBUFFER:
744 case GL_OBJECT_TYPE_PROGRAM:
745 case GL_OBJECT_TYPE_SAMPLER:
746 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
747 AST(mutex_unlock(&ostate->shared->access_mutex) == 1);
753 static inline GL_Object_Hash_Base *
754 _lock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
757 case GL_OBJECT_TYPE_QUERY:
758 return &ostate->query_real;
759 case GL_OBJECT_TYPE_TEXTURE:
760 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
761 return &ostate->shared->texture_real;
762 case GL_OBJECT_TYPE_BUFFER:
763 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
764 return &ostate->shared->buffer_real;
765 case GL_OBJECT_TYPE_FRAMEBUFFER:
766 return &ostate->framebuffer_real;
767 case GL_OBJECT_TYPE_RENDERBUFFER:
768 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
769 return &ostate->shared->renderbuffer_real;
770 case GL_OBJECT_TYPE_PROGRAM:
771 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
772 return &ostate->shared->program_real;
773 case GL_OBJECT_TYPE_VERTEXARRAY:
774 return &ostate->vertexarray_real;
775 case GL_OBJECT_TYPE_SAMPLER:
776 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
777 return &ostate->shared->sampler_real;
778 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
779 return &ostate->transformfeedback_real;
780 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
781 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
782 return &ostate->shared->programpipeline_real;
789 _unlock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
792 case GL_OBJECT_TYPE_TEXTURE:
793 case GL_OBJECT_TYPE_BUFFER:
794 case GL_OBJECT_TYPE_RENDERBUFFER:
795 case GL_OBJECT_TYPE_PROGRAM:
796 case GL_OBJECT_TYPE_SAMPLER:
797 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
798 AST(mutex_unlock(&ostate->shared->real_access_mutex) == 1);
806 fastpath_add_context_state_to_list(const void *option, const int option_len,
807 GLContextState *cstate, Mutex *mtx)
811 GLContext_List *current = NULL;
812 GLContext_List *newitm = NULL;
814 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
818 tid = get_current_thread();
820 current = glctx_list;
821 while (current != NULL) {
822 if (current->option_len == option_len &&
823 memcmp(current->option, option, option_len) == 0 &&
824 current->thread_id == tid) {
825 AST(current->cstate == cstate);
828 current = current->next;
831 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
832 if (newitm == NULL) {
833 COREGL_ERR("Failed to create context list.");
837 newitm->cstate = cstate;
838 newitm->thread_id = tid;
839 newitm->option_len = option_len;
840 newitm->option = (void *)malloc(option_len);
841 memcpy(newitm->option, option, option_len);
843 if (glctx_list != NULL)
844 newitm->next = glctx_list;
853 if (newitm != NULL) {
857 if (cstate != NULL) {
862 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
868 fastpath_get_context_state_from_list(const void *option, const int option_len,
871 GLContextState *ret = NULL;
872 GLContext_List *current = NULL;
875 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
877 tid = get_current_thread();
879 current = glctx_list;
880 while (current != NULL) {
881 if (current->option_len == option_len &&
882 memcmp(current->option, option, option_len) == 0 &&
883 current->thread_id == tid) {
884 ret = current->cstate;
887 current = current->next;
892 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
897 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
900 GLContext_List *olditm = NULL;
901 GLContext_List *current = NULL;
903 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
907 current = glctx_list;
909 while (current != NULL) {
910 if (current->cstate == cstate) {
911 GLContext_List *nextitm = NULL;
912 if (olditm != NULL) {
913 olditm->next = current->next;
914 nextitm = olditm->next;
916 glctx_list = current->next;
917 nextitm = glctx_list;
919 if (current->option != NULL) {
920 AST(current->option_len > 0);
921 free(current->option);
922 current->option = NULL;
923 current->option_len = 0;
931 current = current->next;
936 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
942 #define HASH_INIT(hash_base) \
943 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
944 hash_base.hash_size = GL_OBJECT_HASH_BASE;
947 fastpath_ostate_init(GL_Object_State *ostate)
949 HASH_INIT(ostate->query);
950 HASH_INIT(ostate->framebuffer);
951 HASH_INIT(ostate->vertexarray);
952 HASH_INIT(ostate->transformfeedback);
954 HASH_INIT(ostate->query_real);
955 HASH_INIT(ostate->framebuffer_real);
956 HASH_INIT(ostate->vertexarray_real);
957 HASH_INIT(ostate->transformfeedback_real);
961 fastpath_sostate_init(GL_Shared_Object_State *sostate)
963 mutex_init(&sostate->access_mutex);
965 HASH_INIT(sostate->texture);
966 HASH_INIT(sostate->buffer);
967 HASH_INIT(sostate->renderbuffer);
968 HASH_INIT(sostate->program);
969 HASH_INIT(sostate->sampler);
970 HASH_INIT(sostate->programpipeline);
972 HASH_INIT(sostate->texture_real);
973 HASH_INIT(sostate->buffer_real);
974 HASH_INIT(sostate->renderbuffer_real);
975 HASH_INIT(sostate->program_real);
976 HASH_INIT(sostate->sampler_real);
977 HASH_INIT(sostate->programpipeline_real);
984 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
986 int array_idx = data->hash_key & (hash_base->hash_size - 1);
987 if (hash_base->hash_field[array_idx] == NULL) {
988 hash_base->hash_field[array_idx] = data;
990 GL_Object_Hash *current = hash_base->hash_field[array_idx];
991 while (current->next) {
992 AST(current->hash_key != data->hash_key);
993 current = current->next;
995 current->next = data;
998 hash_base->item_size++;
1002 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
1005 int array_idx = hash & (hash_base->hash_size - 1);
1007 GL_Object_Hash *current = hash_base->hash_field[array_idx];
1008 GL_Object_Hash *prev = NULL;
1011 if (current->hash_key == hash) {
1013 prev->next = current->next;
1015 hash_base->hash_field[array_idx] = current->next;
1016 hash_base->item_size--;
1021 current = current->next;
1028 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
1030 if (hash_base->item_size == 0) return;
1032 for (int i = 0; i < hash_base->hash_size; i++) {
1033 if (hash_base->hash_field[i] != NULL) {
1034 GL_Object_Hash *current = hash_base->hash_field[i];
1036 while (current != NULL) {
1037 GL_Object_Hash *current_next = current->next;
1039 if (free_data == 1 && current->item != NULL) {
1040 free(current->item);
1044 hash_base->item_size--;
1045 current = current_next;
1053 #define HASH_DEINIT(hash_base, free_data) \
1054 _free_hash_list(&hash_base, free_data); \
1055 free(hash_base.hash_field); \
1056 hash_base.hash_size = 0;
1059 fastpath_ostate_deinit(GL_Object_State *ostate)
1061 HASH_DEINIT(ostate->query, 1);
1062 HASH_DEINIT(ostate->framebuffer, 1);
1063 HASH_DEINIT(ostate->vertexarray, 1);
1064 HASH_DEINIT(ostate->transformfeedback, 1);
1066 HASH_DEINIT(ostate->query_real, 0);
1067 HASH_DEINIT(ostate->framebuffer_real, 0);
1068 HASH_DEINIT(ostate->vertexarray_real, 0);
1069 HASH_DEINIT(ostate->transformfeedback_real, 0);
1073 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
1075 HASH_DEINIT(sostate->texture, 1);
1076 HASH_DEINIT(sostate->buffer, 1);
1077 HASH_DEINIT(sostate->renderbuffer, 1);
1078 HASH_DEINIT(sostate->program, 1);
1079 HASH_DEINIT(sostate->sampler, 1);
1080 HASH_DEINIT(sostate->programpipeline, 1);
1082 HASH_DEINIT(sostate->texture_real, 0);
1083 HASH_DEINIT(sostate->buffer_real, 0);
1084 HASH_DEINIT(sostate->renderbuffer_real, 0);
1085 HASH_DEINIT(sostate->program_real, 0);
1086 HASH_DEINIT(sostate->sampler_real, 0);
1088 HASH_DEINIT(sostate->programpipeline_real, 0);
1095 #define FIND_HASH(hash_base, key, ret) \
1097 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
1100 if (fh_current->hash_key == (key)) \
1105 fh_current = fh_current->next; \
1110 _ostate_hash_check(GL_Object_Hash_Base *hash_base)
1112 if (hash_base->item_size + 1 < hash_base->hash_size)
1115 int oldsize = hash_base->hash_size;
1116 GL_Object_Hash **oldfield = hash_base->hash_field;
1118 hash_base->hash_size = oldsize << 1;
1119 hash_base->hash_field = (GL_Object_Hash **)calloc(1,
1120 sizeof(GL_Object_Hash *) * hash_base->hash_size);
1121 AST(hash_base->hash_field != NULL);
1123 for (int i = 0; i < oldsize; i++) {
1124 if (oldfield[i] != NULL) {
1125 GL_Object_Hash *current = oldfield[i];
1127 while (current != NULL) {
1128 GL_Object_Hash *current_next = current->next;
1129 _add_hash(hash_base, current);
1130 hash_base->item_size--;
1131 current = current_next;
1140 fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type,
1143 GLuint ret = _COREGL_INT_INIT_VALUE;
1145 GL_Object_Hash_Base *hash_base = NULL;
1146 GL_Object_Hash_Base *hash_base_real = NULL;
1147 int newid = _COREGL_INT_INIT_VALUE;
1149 hash_base = _lock_gl_object_hash(ostate, type);
1150 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1152 newid = hash_base->last_id + 1;
1153 if (newid >= hash_base->hash_size) {
1154 hash_base->is_looped = 1;
1156 hash_base->last_id = 1;
1159 if (hash_base->is_looped != 0) {
1161 int findingid = newid;
1163 for (i = 0; i < hash_base->hash_size; i++) {
1164 GL_Object_Hash *exist_hash = NULL;
1165 FIND_HASH(hash_base, findingid, exist_hash);
1166 if (exist_hash == NULL) {
1171 if (findingid >= hash_base->hash_size) findingid = 1;
1175 hash_base->last_id = newid;
1178 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
1181 newobj->id = (int)type + newid;
1182 newobj->real_id = real_name;
1183 newobj->ref_count = 1;
1186 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1,
1187 sizeof(GL_Object_Hash));
1188 if (newobj_hash == NULL) {
1192 newobj_hash->item = newobj;
1193 newobj_hash->hash_key = newid;
1194 _add_hash(hash_base, newobj_hash);
1196 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1,
1197 sizeof(GL_Object_Hash));
1198 if (newobj_hash_real == NULL) {
1203 newobj_hash_real->item = newobj;
1204 newobj_hash_real->hash_key = real_name;
1205 _add_hash(hash_base_real, newobj_hash_real);
1210 _ostate_hash_check(hash_base);
1211 _ostate_hash_check(hash_base_real);
1216 _unlock_gl_object_hash(ostate, type);
1217 _unlock_gl_object_hash_real(ostate, type);
1221 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
1222 if (((int)(hash)) < 0) { ret = 0; goto finish; } \
1224 GL_Object_Hash *object_hash = NULL; \
1225 FIND_HASH((hash_base), (int)(hash), object_hash); \
1226 if (object_hash == NULL) { ret = 0; goto finish; } \
1227 (object) = object_hash->item; \
1228 if ((object) == NULL) { ret = 0; goto finish; } \
1232 fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type,
1235 GLuint ret = _COREGL_INT_INIT_VALUE;
1237 GL_Object_Hash_Base *hash_base = NULL;
1238 GL_Object_Hash_Base *hash_base_real = NULL;
1239 GL_Object *object = NULL;
1241 hash_base = _lock_gl_object_hash(ostate, type);
1242 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1244 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1246 object->ref_count--;
1248 if (object->ref_count <= 0) {
1249 GL_Object_Hash *object_hash = NULL;
1251 FIND_HASH(hash_base, object->id - (int)type, object_hash);
1252 AST(object_hash != NULL);
1253 _remove_hash(hash_base, object->id - (int)type);
1257 FIND_HASH(hash_base_real, object->real_id, object_hash);
1258 AST(object_hash != NULL);
1259 _remove_hash(hash_base_real, object->real_id);
1271 _unlock_gl_object_hash(ostate, type);
1272 _unlock_gl_object_hash_real(ostate, type);
1277 fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type,
1280 GLuint ret = _COREGL_INT_INIT_VALUE;
1282 GL_Object_Hash_Base *hash_base = NULL;
1283 GL_Object *object = NULL;
1285 hash_base = _lock_gl_object_hash(ostate, type);
1287 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1289 ret = object->real_id;
1293 _unlock_gl_object_hash(ostate, type);
1297 /* Check if the context's state contains object of a given type */
1299 fastpath_ostate_has_object_type(GL_Object_State *ostate, GL_Object_Type type)
1301 GLuint ret = _COREGL_INT_INIT_VALUE;
1303 GL_Object_Hash_Base *hash_base = NULL;
1304 GL_Object *object = NULL;
1305 hash_base = _lock_gl_object_hash(ostate, type);
1307 if (hash_base->hash_field == 0) {
1312 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, 1, object);
1314 ret = object->real_id;
1318 _unlock_gl_object_hash(ostate, type);
1324 fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1325 GLuint glue_name, GLvoid *tag)
1327 GLint ret = _COREGL_INT_INIT_VALUE;
1329 GL_Object_Hash_Base *hash_base = NULL;
1330 GL_Object *object = NULL;
1331 int hash = _COREGL_INT_INIT_VALUE;
1333 hash_base = _lock_gl_object_hash(ostate, type);
1335 hash = glue_name - (int)type;
1337 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
1339 AST(object->tag == NULL);
1345 _unlock_gl_object_hash(ostate, type);
1350 fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1355 GL_Object_Hash_Base *hash_base = NULL;
1356 GL_Object *object = NULL;
1358 hash_base = _lock_gl_object_hash(ostate, type);
1360 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1366 _unlock_gl_object_hash(ostate, type);
1371 fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type,
1374 GLuint ret = _COREGL_INT_INIT_VALUE;
1376 GL_Object_Hash_Base *hash_base_real = NULL;
1377 GL_Object *object = NULL;
1379 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1381 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
1387 _unlock_gl_object_hash_real(ostate, type);
1392 fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type,
1395 GLint ret = _COREGL_INT_INIT_VALUE;
1397 GL_Object_Hash_Base *hash_base = NULL;
1398 GL_Object *object = NULL;
1400 hash_base = _lock_gl_object_hash(ostate, type);
1402 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1404 object->ref_count++;
1409 _unlock_gl_object_hash(ostate, type);
1414 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
1416 static struct timeval tv_last = { 0, 0 };
1418 if (unlikely(get_trace_state_flag() != 1)) return;
1420 if (!force_output) {
1421 struct timeval tv_now = { 0, 0 };
1422 AST(gettimeofday(&tv_now, NULL) == 0);
1423 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC) {
1430 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1431 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n",
1433 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1435 #define PRINTF_CHAR_GLenum "0x%8X"
1436 #define PRINTF_CHAR_GLboolean "%10d"
1437 #define PRINTF_CHAR_GLint "%10d"
1438 #define PRINTF_CHAR_GLsizei "%10u"
1439 #define PRINTF_CHAR_GLuint "%10u"
1440 #define PRINTF_CHAR_GLuintmask "0x%8X"
1441 #define PRINTF_CHAR_GLintptr "%10ld"
1442 #define PRINTF_CHAR_GLsizeiptr "%10ld"
1444 #define PRINTF_CHAR_GLclampf "%10.6f"
1445 #define PRINTF_CHAR_GLfloat "%10.6f"
1447 #define PRINTF_CHAR_GLvoidptr "%10p"
1449 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1451 #define _COREGL_START_API(version) api_gl_version = version;
1452 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1453 #define INITIAL_CTX initial_ctx
1454 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1456 TYPE valuedata[SIZE]; \
1457 TYPE *value = NULL; \
1458 if(api_gl_version <= driver_gl_version) { \
1459 value = valuedata; GET_STMT; value = valuedata; \
1461 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1462 for (int i = 0; i < SIZE; i++) \
1466 TRACE("\n %-30.30s ", "");\
1470 if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
1471 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1472 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1473 if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
1475 TRACE(" \E[40;37;1m)\E[0m\n"); \
1478 # include "coregl_fastpath_state.h"
1481 #undef _COREGL_START_API
1482 #undef _COREGL_END_API
1484 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1494 fastpath_init_context_states(GLGlueContext *ctx)
1498 AST(mutex_lock(&init_context_mutex) == 1);
1501 COREGL_ERR("Context NULL");
1506 AST(ctx->initialized == 0);
1507 AST(ctx->ostate.shared != NULL);
1509 if (initial_ctx == NULL) {
1510 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1511 AST(initial_ctx != NULL);
1513 //#define FORCE_DEFAULT_VALUE
1514 #define _COREGL_START_API(version) api_gl_version = version;
1515 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1516 #ifdef FORCE_DEFAULT_VALUE
1517 # define INITIAL_CTX initial_ctx
1518 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1522 TYPE valuedata[SIZE]; \
1523 TYPE *value = NULL; \
1524 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1525 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1526 initial_ctx->NAME##_updated = (GLboolean *)calloc(SIZE, sizeof(GLboolean)); \
1527 if(api_gl_version <= driver_gl_version) { \
1528 value = valuedata; DEFAULT_STMT; value = valuedata; \
1529 for (i = 0; i < SIZE; i++) \
1531 if (*((char *)(&value[i])) == 0xcc) \
1533 memset(&value[i], 0xaa, sizeof(TYPE)); \
1534 value = valuedata; DEFAULT_STMT; value = valuedata; \
1535 if (*((char *)(&value[i])) == 0xaa) \
1537 COREGL_WARN("GL-state '"#NAME"' cannot be retrieved"); \
1541 initial_ctx->NAME[i] = value[i]; \
1542 initial_ctx->NAME##_updated[i] = GL_FALSE; \
1547 # include "coregl_fastpath_state.h"
1551 # define INITIAL_CTX initial_ctx
1552 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1553 if (try_step == 1) \
1555 value = valuedata; DEFAULT_STMT; value = valuedata; \
1559 value = valuedata; FALLBACK_STMT; value = valuedata; \
1562 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1567 TYPE valuedata[SIZE]; \
1568 TYPE *value = NULL; \
1569 _sym_glGetError(); \
1570 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1571 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1572 initial_ctx->NAME##_updated = (GLboolean *)calloc(SIZE, sizeof(GLboolean)); \
1573 if(api_gl_version <= driver_gl_version) { \
1576 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1577 if (_sym_glGetError() == GL_INVALID_ENUM) \
1579 initial_ctx->NAME##_used = 0; \
1580 value = valuedata; DEFAULT_STMT; value = valuedata; \
1583 initial_ctx->NAME##_used = 1; \
1584 for (i = 0; i < SIZE; i++) \
1586 if (*((char *)(&value[i])) == 0xcc) \
1588 memset(&value[i], 0xaa, sizeof(TYPE)); \
1589 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1590 if (*((char *)(&value[i])) == 0xaa) \
1593 if (try_step == 2) \
1595 COREGL_WARN("GL-state '"#NAME"' cannot be retrieved"); \
1600 initial_ctx->NAME[i] = value[i]; \
1601 initial_ctx->NAME##_updated[i] = GL_FALSE; \
1603 if (try_step != 2) \
1605 value = valuedata; DEFAULT_STMT; value = valuedata; \
1606 for (i = 0; i < SIZE; i++) \
1608 if (initial_ctx->NAME[i] != value[i]) \
1610 COREGL_WARN("GL-state '"#NAME"'[%d] value ["PRINTF_CHAR(TYPE)"] is different from SPEC-DEFAULT ["PRINTF_CHAR(TYPE)"]", i, initial_ctx->NAME[i], value[i]); \
1615 while (try_step == 2); \
1619 # include "coregl_fastpath_state.h"
1620 # undef SET_GLUE_VALUE
1624 # undef _COREGL_END_API
1625 # undef _COREGL_START_API
1627 if (initial_ctx->gl_vertex_attribs_num[0] > MAX_VERTEX_ATTRIBS) {
1628 COREGL_WARN("Number of vertex attrib is too big! (%d-%d)",
1629 MAX_VERTEX_ATTRIBS, initial_ctx->gl_vertex_attribs_num[0]);
1631 if (initial_ctx->gl_tex_units_num[0] > MAX_TEXTURE_UNITS) {
1632 COREGL_WARN("Number of texture unit is too big! (%d-%d)",
1633 MAX_TEXTURE_UNITS, initial_ctx->gl_tex_units_num[0]);
1635 if (initial_ctx->gl_transform_feedback_buffer_binding_num[0] >
1636 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS) {
1637 COREGL_WARN("Number of transform feedback separate attrib is too big! (%d-%d)",
1638 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
1639 initial_ctx->gl_transform_feedback_buffer_binding_num[0]);
1641 if (initial_ctx->gl_uniform_buffer_binding_num[0] >
1642 MAX_UNIFORM_BUFFER_BINDINGS) {
1643 COREGL_WARN("Number of uniform buffer binding is too big! (%d-%d)",
1644 MAX_UNIFORM_BUFFER_BINDINGS, initial_ctx->gl_uniform_buffer_binding_num[0]);
1646 if (initial_ctx->gl_shader_storage_buffer_binding_num[0] >
1647 MAX_SHADER_STORAGE_BUFFER_BINDINGS) {
1648 COREGL_WARN("Number of shader storage buffer binding is too big! (%d-%d)",
1649 MAX_SHADER_STORAGE_BUFFER_BINDINGS,
1650 initial_ctx->gl_shader_storage_buffer_binding_num[0]);
1652 if (initial_ctx->gl_atomic_counter_buffer_binding_num[0] >
1653 MAX_ATOMIC_COUNTER_BUFFER_BINDING) {
1654 COREGL_WARN("Number of uniform buffer binding is too big! (%d-%d)",
1655 MAX_ATOMIC_COUNTER_BUFFER_BINDING,
1656 initial_ctx->gl_atomic_counter_buffer_binding_num[0]);
1662 #define _COREGL_START_API(version) api_gl_version = version;
1663 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1664 #define INITIAL_CTX initial_ctx
1665 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1668 ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE)); \
1669 ctx->NAME##_updated = (GLboolean *)calloc(SIZE, sizeof(GLboolean)); \
1670 if(api_gl_version <= driver_gl_version) { \
1671 for (i = 0; i < SIZE; i++) \
1673 ctx->NAME[i] = initial_ctx->NAME[i]; \
1674 ctx->NAME##_used = initial_ctx->NAME##_used; \
1675 ctx->NAME##_updated[i] = initial_ctx->NAME##_updated[i]; \
1680 # include "coregl_fastpath_state.h"
1683 #undef _COREGL_START_API
1684 #undef _COREGL_END_API
1687 ctx->initialized = 1;
1692 AST(mutex_unlock(&init_context_mutex) == 1);
1697 #ifdef COREGL_USE_MODULE_TRACEPATH
1698 extern void *tracepath_api_trace_begin(const char *name, void *hint, int trace_total_time);
1699 extern void *tracepath_api_trace_end(const char *name, void *hint, int trace_total_time);
1702 #define CHECK_GL_ERROR(func) \
1705 int err = _orig_fastpath_glGetError(); \
1706 if (err != GL_NO_ERROR) { \
1707 COREGL_ERR("(GL %p) : %s returns GL error 0x%X", oldctx->cstate, #func, err); \
1712 #define STATE_COMPARE(state) (oldctx->state != newctx->state)
1713 #define STATES_COMPARE(state_ptr, bytes) (memcmp(oldctx->state_ptr, newctx->state_ptr, bytes) != 0)
1716 fastpath_check_context_vertex_attribs(GLGlueContext *oldctx, GLGlueContext *newctx)
1720 if(!(oldctx->_vattrib_flag | newctx->_vattrib_flag)) {
1724 for (i = 0; i < oldctx->gl_vertex_attribs_num[0]; i++) {
1725 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i]) {
1726 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1727 newctx->gl_vertex_array_buf_id[i]))
1729 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1732 if STATE_COMPARE(gl_vertex_array_divisor[i]) {
1733 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribDivisor(i,
1734 newctx->gl_vertex_array_divisor[i]))
1737 if (newctx->gl_vertex_array_size[i] != 0) {
1738 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1739 newctx->gl_vertex_array_size[i],
1740 newctx->gl_vertex_array_type[i],
1741 newctx->gl_vertex_array_normalized[i],
1742 newctx->gl_vertex_array_stride[i],
1743 newctx->gl_vertex_array_pointer[i]))
1745 if (newctx->gl_vertex_array_integer[0] == GL_TRUE) {
1746 if (newctx->gl_vertex_array_type[0] == GL_UNSIGNED_INT) {
1747 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4uiv(i,
1748 &newctx->gl_vertex_attrib_value_unsigned_integer[4 * i]))
1750 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4iv(i,
1751 &newctx->gl_vertex_attrib_value_integer[4 * i]))
1754 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i,
1755 &newctx->gl_vertex_attrib_value[4 * i]))
1759 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE) {
1760 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1762 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1770 fastpath_check_context_bind_1(GLGlueContext *oldctx, GLGlueContext *newctx)
1772 if(!(oldctx->_bind_flag1 | newctx->_bind_flag1)) {
1776 if STATE_COMPARE(gl_array_buffer_binding[0]) {
1777 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1778 newctx->gl_array_buffer_binding[0]))
1781 if STATE_COMPARE(gl_element_array_buffer_binding[0]) {
1782 if STATE_COMPARE(gl_vertex_array_binding[0]) {
1783 CHECK_GL_ERROR(_orig_fastpath_glBindVertexArray(
1784 newctx->gl_vertex_array_binding[0]))
1786 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1787 newctx->gl_element_array_buffer_binding[0]))
1790 if (newctx->gl_framebuffer_binding_read_used == 1 &&
1791 newctx->gl_framebuffer_binding_draw_used == 1) {
1792 if STATE_COMPARE(gl_framebuffer_binding_read[0]) {
1793 if (driver_gl_version >= 2) {
1794 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER,
1795 newctx->gl_framebuffer_binding_read[0]))
1797 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_READ_FRAMEBUFFER,
1798 newctx->gl_framebuffer_binding_read[0]))
1802 if STATE_COMPARE(gl_framebuffer_binding_draw[0]) {
1803 if (driver_gl_version >= 2) {
1804 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1805 newctx->gl_framebuffer_binding_draw[0]))
1807 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_DRAW_FRAMEBUFFER,
1808 newctx->gl_framebuffer_binding_draw[0]))
1812 if STATE_COMPARE(gl_framebuffer_binding[0]) {
1813 if (driver_gl_version >= 2) {
1814 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER,
1815 newctx->gl_framebuffer_binding[0]))
1817 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_FRAMEBUFFER,
1818 newctx->gl_framebuffer_binding[0]))
1823 if STATE_COMPARE(gl_renderbuffer_binding[0]) {
1824 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER,
1825 newctx->gl_renderbuffer_binding[0]))
1832 fastpath_check_context_bind_2(GLGlueContext *oldctx, GLGlueContext *newctx)
1836 if(!(oldctx->_bind_flag2 | newctx->_bind_flag2)) {
1840 if STATE_COMPARE(gl_copy_read_buffer_binding[0]) {
1841 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_READ_BUFFER,
1842 newctx->gl_copy_read_buffer_binding[0]))
1845 if STATE_COMPARE(gl_copy_write_buffer_binding[0]) {
1846 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_WRITE_BUFFER,
1847 newctx->gl_copy_write_buffer_binding[0]))
1850 if STATE_COMPARE(gl_pixel_pack_buffer_binding[0]) {
1851 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_PACK_BUFFER,
1852 newctx->gl_pixel_pack_buffer_binding[0]))
1855 if STATE_COMPARE(gl_pixel_unpack_buffer_binding[0]) {
1856 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
1857 newctx->gl_pixel_unpack_buffer_binding[0]))
1860 if STATE_COMPARE(gl_transform_feedback_buffer_binding[0]) {
1861 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER,
1862 newctx->gl_transform_feedback_buffer_binding[0]))
1865 if STATE_COMPARE(gl_uniform_buffer_binding[0]) {
1866 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_UNIFORM_BUFFER,
1867 newctx->gl_uniform_buffer_binding[0]))
1869 /* handle states set in fastpath_glBindBufferBase() */
1870 for (i = 0; i < newctx->gl_transform_feedback_buffer_binding_num[0]; i++) {
1871 if STATE_COMPARE(gl_transform_feedback_buffer_binding_array[i]) {
1872 CHECK_GL_ERROR(_orig_fastpath_glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, i,
1873 newctx->gl_transform_feedback_buffer_binding_array[i]))
1877 for (i = 0; i < newctx->gl_uniform_buffer_binding_num[0]; i++) {
1878 if STATE_COMPARE(gl_uniform_buffer_binding_array[i]) {
1879 CHECK_GL_ERROR(_orig_fastpath_glBindBufferBase(GL_UNIFORM_BUFFER, i,
1880 newctx->gl_uniform_buffer_binding_array[i]))
1888 fastpath_check_context_bind_3(GLGlueContext *oldctx, GLGlueContext *newctx)
1892 if(!(oldctx->_bind_flag3 | newctx->_bind_flag3)) {
1896 if STATE_COMPARE(gl_shader_storage_buffer_binding[0]) {
1897 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_SHADER_STORAGE_BUFFER,
1898 newctx->gl_shader_storage_buffer_binding[0]))
1901 if STATE_COMPARE(gl_atomic_counter_buffer_binding[0]) {
1902 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ATOMIC_COUNTER_BUFFER,
1903 newctx->gl_atomic_counter_buffer_binding[0]))
1906 if STATE_COMPARE(gl_draw_indirect_buffer_binding[0]) {
1907 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_DRAW_INDIRECT_BUFFER,
1908 newctx->gl_draw_indirect_buffer_binding[0]))
1911 if STATE_COMPARE(gl_dispatch_indirect_buffer_binding[0]) {
1912 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER,
1913 newctx->gl_dispatch_indirect_buffer_binding[0]))
1916 if STATE_COMPARE(gl_texture_buffer_binding[0]) {
1917 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TEXTURE_BUFFER,
1918 newctx->gl_texture_buffer_binding[0]))
1921 /* handle states set in fastpath_glBindBufferBase() */
1922 for (i = 0; i < newctx->gl_shader_storage_buffer_binding_num[0]; i++) {
1923 if STATE_COMPARE(gl_shader_storage_buffer_binding_array[i]) {
1924 CHECK_GL_ERROR(_orig_fastpath_glBindBufferBase(GL_SHADER_STORAGE_BUFFER, i,
1925 newctx->gl_shader_storage_buffer_binding_array[i]))
1929 for (i = 0; i < newctx->gl_atomic_counter_buffer_binding_num[0]; i++) {
1930 if STATE_COMPARE(gl_atomic_counter_buffer_binding_array[i]) {
1931 CHECK_GL_ERROR(_orig_fastpath_glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, i,
1932 newctx->gl_atomic_counter_buffer_binding_array[i]))
1940 fastpath_check_context_bind_4(GLGlueContext *oldctx, GLGlueContext *newctx)
1944 if(!(oldctx->_bind_flag4 | newctx->_bind_flag4)) {
1948 /* handle states set in fastpath_BindBufferRrange() */
1949 for (i = 0; i < newctx->gl_transform_feedback_buffer_binding_num[0]; i++) {
1950 if (STATE_COMPARE(gl_transform_feedback_buffer_range_binding_array[i]) ||
1951 STATE_COMPARE(gl_transform_feedback_buffer_range_binding_array_offset[i]) ||
1952 STATE_COMPARE(gl_transform_feedback_buffer_range_binding_array_size[i])) {
1953 CHECK_GL_ERROR(_orig_fastpath_glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i,
1954 newctx->gl_transform_feedback_buffer_range_binding_array[i],
1955 newctx->gl_transform_feedback_buffer_range_binding_array_offset[i],
1956 newctx->gl_transform_feedback_buffer_range_binding_array_size[i]))
1960 for (i = 0; i < newctx->gl_uniform_buffer_binding_num[0]; i++) {
1961 if (STATE_COMPARE(gl_uniform_buffer_range_binding_array[i]) ||
1962 STATE_COMPARE(gl_uniform_buffer_range_binding_array_offset[i]) ||
1963 STATE_COMPARE(gl_uniform_buffer_range_binding_array_size[i])) {
1964 CHECK_GL_ERROR(_orig_fastpath_glBindBufferRange(GL_UNIFORM_BUFFER, i,
1965 newctx->gl_uniform_buffer_range_binding_array[i],
1966 newctx->gl_uniform_buffer_range_binding_array_offset[i],
1967 newctx->gl_uniform_buffer_range_binding_array_size[i]))
1971 for (i = 0; i < newctx->gl_shader_storage_buffer_binding_num[0]; i++) {
1972 if (STATE_COMPARE(gl_shader_storage_buffer_range_binding_array[i]) ||
1973 STATE_COMPARE(gl_shader_storage_buffer_range_binding_array_offset[i]) ||
1974 STATE_COMPARE(gl_shader_storage_buffer_range_binding_array_size[i])) {
1975 CHECK_GL_ERROR(_orig_fastpath_glBindBufferRange(GL_SHADER_STORAGE_BUFFER, i,
1976 newctx->gl_shader_storage_buffer_range_binding_array[i],
1977 newctx->gl_shader_storage_buffer_range_binding_array_offset[i],
1978 newctx->gl_shader_storage_buffer_range_binding_array_size[i]))
1982 for (i = 0; i < newctx->gl_atomic_counter_buffer_binding_num[0]; i++) {
1983 if (STATE_COMPARE(gl_atomic_counter_buffer_range_binding_array[i]) ||
1984 STATE_COMPARE(gl_atomic_counter_buffer_range_binding_array_offset[i]) ||
1985 STATE_COMPARE(gl_atomic_counter_buffer_range_binding_array_size[i])) {
1986 CHECK_GL_ERROR(_orig_fastpath_glBindBufferRange(GL_ATOMIC_COUNTER_BUFFER, i,
1987 newctx->gl_atomic_counter_buffer_range_binding_array[i],
1988 newctx->gl_atomic_counter_buffer_range_binding_array_offset[i],
1989 newctx->gl_atomic_counter_buffer_range_binding_array_size[i]))
1997 fastpath_check_context_enable_1(GLGlueContext *oldctx, GLGlueContext *newctx)
1999 if(!(oldctx->_enable_flag1 | newctx->_enable_flag1)) {
2003 if STATE_COMPARE(gl_blend[0]) {
2004 if (newctx->gl_blend[0]) {
2005 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
2007 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
2011 if STATE_COMPARE(gl_cull_face[0]) {
2012 if (newctx->gl_cull_face[0]) {
2013 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
2015 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
2019 if STATE_COMPARE(gl_depth_test[0]) {
2020 if (newctx->gl_depth_test[0]) {
2021 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
2023 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
2027 if STATE_COMPARE(gl_dither[0]) {
2028 if (newctx->gl_dither[0]) {
2029 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
2031 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
2039 fastpath_check_context_enable_2(GLGlueContext *oldctx, GLGlueContext *newctx)
2041 if(!(oldctx->_enable_flag2 | newctx->_enable_flag2)) {
2045 if STATE_COMPARE(gl_polygon_offset_fill[0]) {
2046 if (newctx->gl_polygon_offset_fill[0]) {
2047 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
2049 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
2053 if STATE_COMPARE(gl_sample_alpha_to_coverage[0]) {
2054 if (newctx->gl_sample_alpha_to_coverage[0]) {
2055 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
2057 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
2061 if STATE_COMPARE(gl_sample_coverage[0]) {
2062 if (newctx->gl_sample_coverage[0]) {
2063 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
2065 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
2069 if STATE_COMPARE(gl_scissor_test[0]) {
2070 if (newctx->gl_scissor_test[0]) {
2071 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
2073 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
2077 if STATE_COMPARE(gl_stencil_test[0]) {
2078 if (newctx->gl_stencil_test[0]) {
2079 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
2081 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
2085 if STATE_COMPARE(gl_sample_shading_oes[0]) {
2086 if (newctx->gl_sample_shading_oes[0]) {
2087 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_SHADING_OES))
2089 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_SHADING_OES))
2093 if STATE_COMPARE(gl_sample_mask[0]) {
2094 if (newctx->gl_sample_mask[0]) {
2095 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_MASK))
2097 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_MASK))
2105 fastpath_check_context_enable_3(GLGlueContext *oldctx, GLGlueContext *newctx)
2107 if(!(oldctx->_enable_flag3 | newctx->_enable_flag3)) {
2111 if STATE_COMPARE(gl_primitive_restart_fixed_index[0]) {
2112 if (newctx->gl_primitive_restart_fixed_index[0]) {
2113 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
2115 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
2119 if STATE_COMPARE(gl_rasterizer_discard[0]) {
2120 if (newctx->gl_rasterizer_discard[0]) {
2121 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_RASTERIZER_DISCARD))
2123 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_RASTERIZER_DISCARD))
2127 if STATE_COMPARE(gl_blend_advanced_coherent_khr[0]) {
2128 if (newctx->gl_blend_advanced_coherent_khr[0]) {
2129 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND_ADVANCED_COHERENT_KHR))
2131 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND_ADVANCED_COHERENT_KHR))
2139 fastpath_check_context_clear_1(GLGlueContext *oldctx, GLGlueContext *newctx)
2141 if(!(oldctx->_clear_flag1 | newctx->_clear_flag1)) {
2146 if STATES_COMPARE(gl_viewport, 4 * sizeof(GLint)) {
2147 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
2148 newctx->gl_viewport[1],
2149 newctx->gl_viewport[2],
2150 newctx->gl_viewport[3]))
2153 if STATE_COMPARE(gl_current_program[0]) {
2154 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
2157 if STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf)) {
2158 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
2159 newctx->gl_color_clear_value[1],
2160 newctx->gl_color_clear_value[2],
2161 newctx->gl_color_clear_value[3]))
2168 fastpath_check_context_clear_2(GLGlueContext *oldctx, GLGlueContext *newctx)
2172 if(!(oldctx->_clear_flag2 | newctx->_clear_flag2)) {
2176 if STATES_COMPARE(gl_color_writemask, 4 * GL_CLOR_WRITEMASK_NUM * sizeof(GLboolean)) {
2177 for (i = 0; i < GL_CLOR_WRITEMASK_NUM; i++) {
2178 if(NULL != _orig_fastpath_glColorMaski) {
2179 CHECK_GL_ERROR(_orig_fastpath_glColorMaski(i,
2180 (newctx->gl_color_writemask + i)[0],
2181 (newctx->gl_color_writemask + i)[1],
2182 (newctx->gl_color_writemask + i)[2],
2183 (newctx->gl_color_writemask + i)[3]))
2188 if STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf)) {
2189 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
2190 newctx->gl_depth_range[1]))
2193 if STATE_COMPARE(gl_depth_clear_value[0]) {
2194 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
2197 if STATE_COMPARE(gl_depth_func[0]) {
2198 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
2201 if STATE_COMPARE(gl_depth_writemask[0]) {
2202 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
2205 if STATE_COMPARE(gl_cull_face_mode[0]) {
2206 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
2213 fastpath_check_context_tex_1(GLGlueContext *oldctx, GLGlueContext *newctx)
2217 if(!(oldctx->_tex_flag1 | newctx->_tex_flag1)) {
2221 for (i = 0; i < oldctx->gl_tex_units_num[0]; i++) {
2222 if STATE_COMPARE(gl_tex_2d_state[i]) {
2223 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2224 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D,
2225 newctx->gl_tex_2d_state[i]))
2228 if STATE_COMPARE(gl_tex_3d_state[i]) {
2229 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2230 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_3D,
2231 newctx->gl_tex_3d_state[i]))
2234 if STATE_COMPARE(gl_tex_2d_array_state[i]) {
2235 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2236 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_ARRAY,
2237 newctx->gl_tex_2d_array_state[i]))
2240 if STATE_COMPARE(gl_tex_cube_state[i]) {
2241 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2242 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP,
2243 newctx->gl_tex_cube_state[i]))
2246 if STATE_COMPARE(gl_tex_external_oes_state[i]) {
2247 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2248 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_EXTERNAL_OES,
2249 newctx->gl_tex_external_oes_state[i]))
2253 /* Restore active texture */
2254 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
2256 if STATE_COMPARE(gl_generate_mipmap_hint[0]) {
2257 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT,
2258 newctx->gl_generate_mipmap_hint[0]))
2265 fastpath_check_context_tex_2(GLGlueContext *oldctx, GLGlueContext *newctx)
2269 if(!(oldctx->_tex_flag2 | newctx->_tex_flag2)) {
2273 for (i = 0; i < oldctx->gl_tex_units_num[0]; i++) {
2274 if STATE_COMPARE(gl_tex_buffer_ext_state[i]) {
2275 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2276 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_BUFFER_EXT,
2277 newctx->gl_tex_buffer_ext_state[i]))
2280 if STATE_COMPARE(gl_tex_2d_multisample_state[i]) {
2281 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2282 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE,
2283 newctx->gl_tex_2d_multisample_state[i]))
2286 if STATE_COMPARE(gl_tex_cube_map_array_ext_state[i]) {
2287 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2288 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY_EXT,
2289 newctx->gl_tex_cube_map_array_ext_state[i]))
2292 if STATE_COMPARE(gl_tex_2d_multisample_array_oes_state[i]) {
2293 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
2294 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES,
2295 newctx->gl_tex_2d_multisample_array_oes_state[i]))
2303 fastpath_check_context_blend(GLGlueContext *oldctx, GLGlueContext *newctx)
2305 if(!(oldctx->_blend_flag | newctx->_blend_flag)) {
2309 if STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf)) {
2310 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
2311 newctx->gl_blend_color[1],
2312 newctx->gl_blend_color[2],
2313 newctx->gl_blend_color[3]))
2316 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
2317 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
2318 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
2319 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0])) {
2320 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
2321 newctx->gl_blend_dst_rgb[0],
2322 newctx->gl_blend_src_alpha[0],
2323 newctx->gl_blend_dst_alpha[0]))
2326 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
2327 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0])) {
2328 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(
2329 newctx->gl_blend_equation_rgb[0],
2330 newctx->gl_blend_equation_alpha[0]))
2337 fastpath_check_context_stencil_1(GLGlueContext *oldctx, GLGlueContext *newctx)
2339 if(!(oldctx->_stencil_flag1 | newctx->_stencil_flag1)) {
2343 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
2344 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
2345 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0])) {
2346 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
2347 newctx->gl_stencil_func[0],
2348 newctx->gl_stencil_ref[0],
2349 newctx->gl_stencil_value_mask[0]))
2352 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
2353 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0]) ||
2354 (oldctx->gl_stencil_pass_depth_pass[0] != newctx->gl_stencil_pass_depth_pass[0])) {
2355 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
2356 newctx->gl_stencil_fail[0],
2357 newctx->gl_stencil_pass_depth_fail[0],
2358 newctx->gl_stencil_pass_depth_pass[0]))
2361 if STATE_COMPARE(gl_stencil_writemask[0]) {
2362 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT,
2363 newctx->gl_stencil_writemask[0]))
2370 fastpath_check_context_stencil_2(GLGlueContext *oldctx, GLGlueContext *newctx)
2372 if(!(oldctx->_stencil_flag2 | newctx->_stencil_flag2)) {
2376 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
2377 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
2378 (oldctx->gl_stencil_back_value_mask[0] != newctx->gl_stencil_back_value_mask[0])) {
2379 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
2380 newctx->gl_stencil_back_func[0],
2381 newctx->gl_stencil_back_ref[0],
2382 newctx->gl_stencil_back_value_mask[0]))
2385 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
2386 (oldctx->gl_stencil_back_pass_depth_fail[0] != newctx->gl_stencil_back_pass_depth_fail[0]) ||
2387 (oldctx->gl_stencil_back_pass_depth_pass[0] != newctx->gl_stencil_back_pass_depth_pass[0])) {
2388 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
2389 newctx->gl_stencil_back_fail[0],
2390 newctx->gl_stencil_back_pass_depth_fail[0],
2391 newctx->gl_stencil_back_pass_depth_pass[0]))
2394 if STATE_COMPARE(gl_stencil_back_writemask[0]) {
2395 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK,
2396 newctx->gl_stencil_back_writemask[0]))
2399 if STATE_COMPARE(gl_stencil_clear_value[0]) {
2400 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
2407 fastpath_check_context_pixel_1(GLGlueContext *oldctx, GLGlueContext *newctx)
2409 if(!(oldctx->_pixel_flag1 | newctx->_pixel_flag1)) {
2413 if STATE_COMPARE(gl_pack_row_length[0]) {
2414 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ROW_LENGTH,
2415 newctx->gl_pack_row_length[0]))
2418 if STATE_COMPARE(gl_pack_skip_rows[0]) {
2419 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_ROWS,
2420 newctx->gl_pack_skip_rows[0]))
2423 if STATE_COMPARE(gl_pack_skip_pixels[0]) {
2424 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_PIXELS,
2425 newctx->gl_pack_skip_pixels[0]))
2428 if STATE_COMPARE(gl_pack_alignment[0]) {
2429 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT,
2430 newctx->gl_pack_alignment[0]))
2437 fastpath_check_context_pixel_2(GLGlueContext *oldctx, GLGlueContext *newctx)
2439 if(!(oldctx->_pixel_flag2 | newctx->_pixel_flag2)) {
2443 if STATE_COMPARE(gl_unpack_row_length[0]) {
2444 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ROW_LENGTH,
2445 newctx->gl_unpack_row_length[0]))
2448 if STATE_COMPARE(gl_unpack_skip_rows[0]) {
2449 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_ROWS,
2450 newctx->gl_unpack_skip_rows[0]))
2453 if STATE_COMPARE(gl_unpack_skip_pixels[0]) {
2454 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_PIXELS,
2455 newctx->gl_unpack_skip_pixels[0]))
2458 if STATE_COMPARE(gl_unpack_alignment[0]) {
2459 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT,
2460 newctx->gl_unpack_alignment[0]))
2463 if STATE_COMPARE(gl_unpack_image_height[0]) {
2464 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,
2465 newctx->gl_unpack_image_height[0]))
2468 if STATE_COMPARE(gl_unpack_skip_images[0]) {
2469 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_IMAGES,
2470 newctx->gl_unpack_skip_images[0]))
2477 fastpath_check_context_misc_1(GLGlueContext *oldctx, GLGlueContext *newctx)
2479 if(!(oldctx->_misc_flag1 | newctx->_misc_flag1)) {
2483 if STATE_COMPARE(gl_front_face[0]) {
2484 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
2487 if STATE_COMPARE(gl_line_width[0]) {
2488 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
2491 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0]) ||
2492 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0])) {
2493 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(
2494 newctx->gl_polygon_offset_factor[0],
2495 newctx->gl_polygon_offset_units[0]))
2498 if ((oldctx->gl_sample_coverage_value[0] != newctx->gl_sample_coverage_value[0]) ||
2499 (oldctx->gl_sample_coverage_invert[0] != newctx->gl_sample_coverage_invert[0])) {
2500 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(
2501 newctx->gl_sample_coverage_value[0],
2502 newctx->gl_sample_coverage_invert[0]))
2505 if STATE_COMPARE(gl_fragment_shader_derivative_hint[0]) {
2506 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES,
2507 newctx->gl_fragment_shader_derivative_hint[0]))
2514 fastpath_check_context_misc_2(GLGlueContext *oldctx, GLGlueContext *newctx)
2516 if(!(oldctx->_misc_flag2 | newctx->_misc_flag2)) {
2520 if STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint)) {
2521 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
2522 newctx->gl_scissor_box[1],
2523 newctx->gl_scissor_box[2],
2524 newctx->gl_scissor_box[3]))
2531 fastpath_check_context_misc_3(GLGlueContext *oldctx, GLGlueContext *newctx)
2533 if(!(oldctx->_misc_flag3 | newctx->_misc_flag3)) {
2537 if STATE_COMPARE(gl_read_buffer[0]) {
2538 CHECK_GL_ERROR(_orig_fastpath_glReadBuffer(newctx->gl_read_buffer[0]))
2541 if STATES_COMPARE(gl_draw_buffers, oldctx->gl_draw_buffers_num[0] * sizeof(GLenum)) {
2542 int drawBuffSize = 16;
2543 /* If the context has only default framebuffer, then size of glDrawBuffers can only be 1 */
2544 if (fastpath_ostate_has_object_type(&newctx->ostate, GL_OBJECT_TYPE_FRAMEBUFFER) == 0) {
2548 CHECK_GL_ERROR(_orig_fastpath_glDrawBuffers(drawBuffSize, newctx->gl_draw_buffers))
2551 if (oldctx->gl_transform_feedback_active[0] == GL_TRUE &&
2552 oldctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2553 CHECK_GL_ERROR(_orig_fastpath_glPauseTransformFeedback())
2556 if STATE_COMPARE(gl_transform_feedback_binding[0]) {
2557 CHECK_GL_ERROR(_orig_fastpath_glBindTransformFeedback(GL_TRANSFORM_FEEDBACK,
2558 newctx->gl_transform_feedback_binding[0]))
2561 if (newctx->gl_transform_feedback_active[0] == GL_TRUE &&
2562 newctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2563 CHECK_GL_ERROR(_orig_fastpath_glResumeTransformFeedback())
2569 #ifdef COREGL_USE_MODULE_TRACEPATH
2570 #define TRACEPATH_API_TRACE_BEGIN(funcname, hint, trace_total_time) \
2571 tracepath_api_trace_begin(funcname, hint, trace_total_time)
2572 #define TRACEPATH_API_TRACE_END(funcname, hint, trace_total_time) \
2573 tracepath_api_trace_end(funcname, hint, trace_total_time)
2575 #define TRACEPATH_API_TRACE_BEGIN(funcname, hint, trace_total_time)
2576 #define TRACEPATH_API_TRACE_END(funcname, hint, trace_total_time)
2580 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
2584 if (debug_nofp == 1) {
2589 /* Return if they're the same */
2590 if (oldctx == newctx) {
2595 static void *trace_hint_glfinish = NULL;
2596 trace_hint_glfinish = TRACEPATH_API_TRACE_BEGIN("eglMakeCurrent(FP glFinish)",
2597 trace_hint_glfinish, 0);
2599 int err = _orig_fastpath_glGetError();
2600 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR) {
2601 oldctx->gl_error = err;
2604 CHECK_GL_ERROR(_orig_fastpath_glFlush())
2606 TRACEPATH_API_TRACE_END("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
2608 static void *trace_hint_vertex_attrib = NULL;
2609 trace_hint_vertex_attrib = TRACEPATH_API_TRACE_BEGIN("eglMakeCurrent(FP vertex attrib)",
2610 trace_hint_vertex_attrib, 0);
2612 if(!fastpath_check_context_vertex_attribs(oldctx, newctx)) {
2616 TRACEPATH_API_TRACE_END("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
2618 static void *trace_hint_bindbuffers = NULL;
2619 trace_hint_bindbuffers = TRACEPATH_API_TRACE_BEGIN("eglMakeCurrent(FP bind buffers)",
2620 trace_hint_bindbuffers, 0);
2622 if(!fastpath_check_context_bind_1(oldctx, newctx)) {
2626 if(!fastpath_check_context_bind_2(oldctx, newctx)) {
2630 if(!fastpath_check_context_bind_3(oldctx, newctx)) {
2634 if(!fastpath_check_context_bind_4(oldctx, newctx)) {
2638 TRACEPATH_API_TRACE_END("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
2640 static void *trace_hint_enable_states = NULL;
2641 trace_hint_enable_states = TRACEPATH_API_TRACE_BEGIN("eglMakeCurrent(FP enable states)",
2642 trace_hint_enable_states, 0);
2644 if(!fastpath_check_context_enable_1(oldctx, newctx)) {
2648 if(!fastpath_check_context_enable_2(oldctx, newctx)) {
2652 if(!fastpath_check_context_enable_3(oldctx, newctx)) {
2656 TRACEPATH_API_TRACE_END("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
2658 static void *trace_hint_clear_viewport = NULL;
2659 trace_hint_clear_viewport = TRACEPATH_API_TRACE_BEGIN("eglMakeCurrent(FP clear/viewport)",
2660 trace_hint_clear_viewport, 0);
2662 if(!fastpath_check_context_clear_1(oldctx, newctx)) {
2666 if(!fastpath_check_context_clear_2(oldctx, newctx)) {
2670 TRACEPATH_API_TRACE_END("eglMakeCurrent(FP clear/viewport)",
2671 trace_hint_clear_viewport, 0);
2673 static void *trace_hint_bind_textures = NULL;
2674 trace_hint_bind_textures = TRACEPATH_API_TRACE_BEGIN("eglMakeCurrent(FP bind textures)",
2675 trace_hint_bind_textures, 0);
2677 if(!fastpath_check_context_tex_1(oldctx, newctx)) {
2681 if(!fastpath_check_context_tex_2(oldctx, newctx)) {
2685 TRACEPATH_API_TRACE_END("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
2687 static void *trace_hint_etc = NULL;
2688 trace_hint_etc = TRACEPATH_API_TRACE_BEGIN("eglMakeCurrent(FP etc.)",
2691 if(!fastpath_check_context_blend(oldctx, newctx)) {
2695 if(!fastpath_check_context_stencil_1(oldctx, newctx)) {
2699 if(!fastpath_check_context_stencil_2(oldctx, newctx)) {
2703 if(!fastpath_check_context_pixel_1(oldctx, newctx)) {
2707 if(!fastpath_check_context_pixel_2(oldctx, newctx)) {
2711 if(!fastpath_check_context_misc_1(oldctx, newctx)) {
2715 if(!fastpath_check_context_misc_2(oldctx, newctx)) {
2719 if(!fastpath_check_context_misc_3(oldctx, newctx)) {
2723 TRACEPATH_API_TRACE_END("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
2729 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
2730 if (unlikely(get_trace_state_flag() == 1)) {
2731 fastpath_dump_context_states(newctx, 0);
2734 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
2736 #undef STATE_COMPARE
2737 #undef STATES_COMPARE