1 #include "coregl_fastpath.h"
12 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST = NULL;
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_num_tex_units[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_num_draw_buffers[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_num_transform_feedback_separate_attribs[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_num_transform_feedback_separate_attribs[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_num_transform_feedback_separate_attribs[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_num_uniform_buffer_bindings[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_num_uniform_buffer_bindings[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_num_uniform_buffer_bindings[0]; i++) {
134 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, i, (GLint *)¶ms[i]);
139 fastpath_state_get_draw_buffers(GLenum *params)
141 _state_get_draw_buffers(params);
145 init_modules_fastpath()
147 int fastpath_opt = 0;
148 int fastpath_force_off_opt = 0;
150 COREGL_LOG("[CoreGL] <Fastpath> : ");
152 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
153 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
155 if (fastpath_force_off_opt == 1) {
156 COREGL_LOG("\E[40;31;1m(DISABLED by force option)\E[0m ");
160 switch (fastpath_opt) {
162 COREGL_LOG("(%d) Fastpath enabled...\n", fastpath_opt);
163 fp_opt = FP_FAST_PATH;
166 COREGL_LOG("(%d) Default API path enabled...\n", fastpath_opt);
167 fp_opt = FP_NORMAL_PATH;
171 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
176 deinit_modules_fastpath()
178 GLContext_List *current = NULL;
180 AST(mutex_lock(&ctx_list_access_mutex) == 1);
182 // Destroy remained context & Detect leaks
183 int retry_destroy = 0;
187 current = glctx_list;
189 if (current->cstate != NULL) {
190 COREGL_WRN("\E[40;31;1mContext attached to [dpy=%p|rctx=%p] has not been completely destroyed.(leak)\E[0m\n",
191 current->cstate->rdpy, current->cstate->rctx);
193 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE,
194 EGL_NO_SURFACE, EGL_NO_CONTEXT);
195 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
197 fastpath_remove_context_states_from_list(current->cstate, NULL);
202 glctx_list = current->next;
204 current = glctx_list;
206 if (retry_destroy == 0) break;
211 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
215 init_modules_tstate_fastpath(GLThreadState *tstate)
217 MY_MODULE_TSTATE *tstate_mt = NULL;
219 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
221 tstate_mt->binded_api = EGL_OPENGL_ES_API;
223 tstate->module_data[MY_MODULE_ID] = tstate_mt;
227 deinit_modules_tstate_fastpath(GLThreadState *tstate)
229 if (tstate->module_data[MY_MODULE_ID] != NULL) {
230 free(tstate->module_data[MY_MODULE_ID]);
231 tstate->module_data[MY_MODULE_ID] = NULL;
236 fastpath_apply_overrides()
240 fastpath_apply_overrides_egl(1);
241 fastpath_apply_overrides_gl(1);
246 COREGL_ERR("Invalide GL Override Option!!!\n");
253 fastpath_apply_overrides_egl(int enable)
255 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
256 # include "../../headers/sym_egl.h"
257 #undef _COREGL_SYMBOL
259 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
261 COREGL_OVERRIDE(fastpath_, eglBindAPI);
262 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
264 COREGL_OVERRIDE(fastpath_, eglCreateContext);
265 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
266 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
267 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
268 COREGL_OVERRIDE(fastpath_, eglQueryContext);
269 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
270 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
271 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
272 COREGL_OVERRIDE(fastpath_, eglTerminate);
273 COREGL_OVERRIDE(fastpath_, eglGetCurrentDisplay);
278 fastpath_apply_overrides_gl(int enable)
280 #define _COREGL_START_API(version) api_gl_version = version;
281 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
282 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
283 if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
285 # include "../../headers/sym_gl2.h"
286 # include "../../headers/sym_gl_common.h"
287 #undef _COREGL_SYMBOL
288 #undef _COREGL_START_API
289 #undef _COREGL_END_API
291 if (debug_nofp != 1) {
292 COREGL_OVERRIDE(fastpath_, glGetError);
293 COREGL_OVERRIDE(fastpath_, glGetString);
295 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
296 COREGL_OVERRIDE(fastpath_, glGetFloatv);
297 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
299 COREGL_OVERRIDE(fastpath_, glActiveTexture);
300 COREGL_OVERRIDE(fastpath_, glGenTextures);
301 COREGL_OVERRIDE(fastpath_, glBindTexture);
302 COREGL_OVERRIDE(fastpath_, glIsTexture);
303 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
304 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
306 COREGL_OVERRIDE(fastpath_, glGenBuffers);
307 COREGL_OVERRIDE(fastpath_, glBindBuffer);
308 COREGL_OVERRIDE(fastpath_, glIsBuffer);
309 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
311 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
312 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
313 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
314 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
315 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
317 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
318 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
319 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
320 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
321 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
323 COREGL_OVERRIDE(fastpath_, glCreateShader);
324 COREGL_OVERRIDE(fastpath_, glCreateProgram);
325 COREGL_OVERRIDE(fastpath_, glAttachShader);
326 COREGL_OVERRIDE(fastpath_, glCompileShader);
327 COREGL_OVERRIDE(fastpath_, glShaderBinary);
328 COREGL_OVERRIDE(fastpath_, glDeleteShader);
329 COREGL_OVERRIDE(fastpath_, glDetachShader);
330 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
331 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
332 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
333 COREGL_OVERRIDE(fastpath_, glIsShader);
334 COREGL_OVERRIDE(fastpath_, glShaderSource);
335 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
336 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
337 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
338 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
339 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
340 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
341 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
342 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
343 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
344 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
345 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
346 COREGL_OVERRIDE(fastpath_, glIsProgram);
347 COREGL_OVERRIDE(fastpath_, glLinkProgram);
348 COREGL_OVERRIDE(fastpath_, glUseProgram);
349 COREGL_OVERRIDE(fastpath_, glValidateProgram);
351 COREGL_OVERRIDE(fastpath_, glBlendColor);
352 COREGL_OVERRIDE(fastpath_, glBlendEquation);
353 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
354 COREGL_OVERRIDE(fastpath_, glBlendFunc);
355 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
356 COREGL_OVERRIDE(fastpath_, glClearColor);
357 COREGL_OVERRIDE(fastpath_, glClearDepthf);
358 COREGL_OVERRIDE(fastpath_, glClearStencil);
359 COREGL_OVERRIDE(fastpath_, glColorMask);
360 COREGL_OVERRIDE(fastpath_, glCullFace);
361 COREGL_OVERRIDE(fastpath_, glDepthFunc);
362 COREGL_OVERRIDE(fastpath_, glDepthMask);
363 COREGL_OVERRIDE(fastpath_, glDepthRangef);
364 COREGL_OVERRIDE(fastpath_, glDisable);
365 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
366 COREGL_OVERRIDE(fastpath_, glEnable);
367 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
368 COREGL_OVERRIDE(fastpath_, glFrontFace);
369 COREGL_OVERRIDE(fastpath_, glHint);
370 COREGL_OVERRIDE(fastpath_, glLineWidth);
371 COREGL_OVERRIDE(fastpath_, glPixelStorei);
372 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
373 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
374 COREGL_OVERRIDE(fastpath_, glScissor);
375 COREGL_OVERRIDE(fastpath_, glStencilFunc);
376 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
377 COREGL_OVERRIDE(fastpath_, glStencilMask);
378 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
379 COREGL_OVERRIDE(fastpath_, glStencilOp);
380 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
381 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
382 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
383 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
384 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
385 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
386 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
387 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
388 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
389 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
390 COREGL_OVERRIDE(fastpath_, glViewport);
392 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
393 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
395 COREGL_OVERRIDE(fastpath_, glUseProgramStagesEXT);
396 COREGL_OVERRIDE(fastpath_, glActiveShaderProgramEXT);
397 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
398 COREGL_OVERRIDE(fastpath_, glProgramUniform1iEXT);
399 COREGL_OVERRIDE(fastpath_, glProgramUniform2iEXT);
400 COREGL_OVERRIDE(fastpath_, glProgramUniform3iEXT);
401 COREGL_OVERRIDE(fastpath_, glProgramUniform4iEXT);
402 COREGL_OVERRIDE(fastpath_, glProgramUniform1fEXT);
403 COREGL_OVERRIDE(fastpath_, glProgramUniform2fEXT);
404 COREGL_OVERRIDE(fastpath_, glProgramUniform3fEXT);
405 COREGL_OVERRIDE(fastpath_, glProgramUniform4fEXT);
406 COREGL_OVERRIDE(fastpath_, glProgramUniform1ivEXT);
407 COREGL_OVERRIDE(fastpath_, glProgramUniform2ivEXT);
408 COREGL_OVERRIDE(fastpath_, glProgramUniform3ivEXT);
409 COREGL_OVERRIDE(fastpath_, glProgramUniform4ivEXT);
410 COREGL_OVERRIDE(fastpath_, glProgramUniform1fvEXT);
411 COREGL_OVERRIDE(fastpath_, glProgramUniform2fvEXT);
412 COREGL_OVERRIDE(fastpath_, glProgramUniform3fvEXT);
413 COREGL_OVERRIDE(fastpath_, glProgramUniform4fvEXT);
414 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fvEXT);
415 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fvEXT);
416 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fvEXT);
418 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
419 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
421 COREGL_OVERRIDE(fastpath_, glBindFramebufferOES);
422 COREGL_OVERRIDE(fastpath_, glBindRenderbufferOES);
423 COREGL_OVERRIDE(fastpath_, glClearBufferfi);
424 COREGL_OVERRIDE(fastpath_, glClearBufferfv);
425 COREGL_OVERRIDE(fastpath_, glClearBufferiv);
426 COREGL_OVERRIDE(fastpath_, glClearBufferuiv);
427 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffersOES);
428 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffersOES);
429 COREGL_OVERRIDE(fastpath_, glDepthRangefOES);
430 COREGL_OVERRIDE(fastpath_, glDepthRangexOES);
431 COREGL_OVERRIDE(fastpath_, glFramebufferParameteri);
432 COREGL_OVERRIDE(fastpath_, glGetFramebufferParameteriv);
433 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbufferOES);
434 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DOES);
435 COREGL_OVERRIDE(fastpath_, glGenFramebuffersOES);
436 COREGL_OVERRIDE(fastpath_, glGenRenderbuffersOES);
437 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameterivOES);
438 COREGL_OVERRIDE(fastpath_, glGetQueryObjecti64vEXT);
439 COREGL_OVERRIDE(fastpath_, glGetQueryObjectivEXT);
440 COREGL_OVERRIDE(fastpath_, glGetQueryObjectui64vEXT);
441 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuivEXT);
442 COREGL_OVERRIDE(fastpath_, glGetQueryivEXT);
443 COREGL_OVERRIDE(fastpath_, glBeginQueryEXT);
444 COREGL_OVERRIDE(fastpath_, glDeleteQueriesEXT);
445 COREGL_OVERRIDE(fastpath_, glGenQueriesEXT);
446 COREGL_OVERRIDE(fastpath_, glIsFramebufferOES);
447 COREGL_OVERRIDE(fastpath_, glIsQueryEXT);
448 COREGL_OVERRIDE(fastpath_, glIsRenderbufferOES);
449 COREGL_OVERRIDE(fastpath_, glBlendEquationOES);
450 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparateOES);
451 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparateOES);
452 COREGL_OVERRIDE(fastpath_, glPolygonOffsetxOES);
453 COREGL_OVERRIDE(fastpath_, glLineWidthxOES);
454 COREGL_OVERRIDE(fastpath_, glSampleCoveragexOES);
455 COREGL_OVERRIDE(fastpath_, glQueryCounterEXT);
456 COREGL_OVERRIDE(fastpath_, glBindVertexArrayOES);
457 COREGL_OVERRIDE(fastpath_, glDeleteVertexArraysOES);
458 COREGL_OVERRIDE(fastpath_, glGenVertexArraysOES);
459 COREGL_OVERRIDE(fastpath_, glIsVertexArrayOES);
460 COREGL_OVERRIDE(fastpath_, glClearDepthfOES );
461 COREGL_OVERRIDE(fastpath_, glClearDepthxOES );
462 /* Start overriding GLES 3.0 */
463 if (driver_gl_version >= COREGL_GLAPI_3) {
464 COREGL_OVERRIDE(fastpath_, glReadBuffer);
466 COREGL_OVERRIDE(fastpath_, glGenQueries);
467 COREGL_OVERRIDE(fastpath_, glDeleteQueries);
468 COREGL_OVERRIDE(fastpath_, glIsQuery);
469 COREGL_OVERRIDE(fastpath_, glBeginQuery);
470 COREGL_OVERRIDE(fastpath_, glGetQueryiv);
471 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
472 COREGL_OVERRIDE(fastpath_, glDrawBuffers);
473 COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
475 COREGL_OVERRIDE(fastpath_, glBindVertexArray);
476 COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
477 COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
478 COREGL_OVERRIDE(fastpath_, glIsVertexArray);
480 COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
482 COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
483 COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
484 COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
485 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
487 COREGL_OVERRIDE(fastpath_, glBindBufferRange);
488 COREGL_OVERRIDE(fastpath_, glBindBufferBase);
489 COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
490 COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
491 COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
492 COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
493 COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
494 COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
495 COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
496 COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
497 COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
498 COREGL_OVERRIDE(fastpath_, glGetStringi);
499 COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
500 COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
501 COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
502 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
503 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
504 COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
505 COREGL_OVERRIDE(fastpath_, glGetInteger64v);
506 COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
507 COREGL_OVERRIDE(fastpath_, glGenSamplers);
508 COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
509 COREGL_OVERRIDE(fastpath_, glIsSampler);
510 COREGL_OVERRIDE(fastpath_, glBindSampler);
511 COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
512 COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
513 COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
514 COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
515 COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
516 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
517 COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
518 COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
519 COREGL_OVERRIDE(fastpath_, glProgramBinary);
520 COREGL_OVERRIDE(fastpath_, glProgramParameteri);
523 if (driver_gl_version >= COREGL_GLAPI_31) {
524 COREGL_OVERRIDE(fastpath_, glCreateShaderProgramv);
525 COREGL_OVERRIDE(fastpath_, glGenProgramPipelines);
526 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineiv);
527 COREGL_OVERRIDE(fastpath_, glBindProgramPipeline);
528 COREGL_OVERRIDE(fastpath_, glDeleteProgramPipelines);
529 COREGL_OVERRIDE(fastpath_, glIsProgramPipeline);
530 COREGL_OVERRIDE(fastpath_, glValidateProgramPipeline);
531 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineInfoLog);
532 COREGL_OVERRIDE(fastpath_, glDispatchCompute);
533 COREGL_OVERRIDE(fastpath_, glDispatchComputeIndirect);
534 COREGL_OVERRIDE(fastpath_, glGetProgramInterfaceiv);
535 COREGL_OVERRIDE(fastpath_, glGetProgramResourceIndex);
536 COREGL_OVERRIDE(fastpath_, glGetProgramResourceName);
537 COREGL_OVERRIDE(fastpath_, glGetProgramResourceiv);
538 COREGL_OVERRIDE(fastpath_, glGetProgramResourceLocation);
539 COREGL_OVERRIDE(fastpath_, glUseProgramStages);
540 COREGL_OVERRIDE(fastpath_, glActiveShaderProgram);
541 COREGL_OVERRIDE(fastpath_, glProgramUniform1iv);
542 COREGL_OVERRIDE(fastpath_, glProgramUniform2iv);
543 COREGL_OVERRIDE(fastpath_, glProgramUniform3iv);
544 COREGL_OVERRIDE(fastpath_, glProgramUniform4iv);
545 COREGL_OVERRIDE(fastpath_, glProgramUniform1fv);
546 COREGL_OVERRIDE(fastpath_, glProgramUniform2fv);
547 COREGL_OVERRIDE(fastpath_, glProgramUniform3fv);
548 COREGL_OVERRIDE(fastpath_, glProgramUniform4fv);
549 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fv);
550 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fv);
551 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fv);
552 COREGL_OVERRIDE(fastpath_, glProgramUniform1i);
553 COREGL_OVERRIDE(fastpath_, glProgramUniform2i);
554 COREGL_OVERRIDE(fastpath_, glProgramUniform3i);
555 COREGL_OVERRIDE(fastpath_, glProgramUniform4i);
556 COREGL_OVERRIDE(fastpath_, glProgramUniform1f);
557 COREGL_OVERRIDE(fastpath_, glProgramUniform2f);
558 COREGL_OVERRIDE(fastpath_, glProgramUniform3f);
559 COREGL_OVERRIDE(fastpath_, glProgramUniform4f);
560 COREGL_OVERRIDE(fastpath_, glProgramUniform1uiv);
561 COREGL_OVERRIDE(fastpath_, glProgramUniform2uiv);
562 COREGL_OVERRIDE(fastpath_, glProgramUniform3uiv);
563 COREGL_OVERRIDE(fastpath_, glProgramUniform4uiv);
564 COREGL_OVERRIDE(fastpath_, glProgramUniform1ui);
565 COREGL_OVERRIDE(fastpath_, glProgramUniform2ui);
566 COREGL_OVERRIDE(fastpath_, glProgramUniform3ui);
567 COREGL_OVERRIDE(fastpath_, glProgramUniform4ui);
568 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x3fv);
569 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x2fv);
570 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x2fv);
571 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x4fv);
572 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x4fv);
573 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x3fv);
574 COREGL_OVERRIDE(fastpath_, glBindImageTexture);
575 COREGL_OVERRIDE(fastpath_, glGetBooleani_v);
576 COREGL_OVERRIDE(fastpath_, glMemoryBarrier);
577 COREGL_OVERRIDE(fastpath_, glMemoryBarrierByRegion);
578 COREGL_OVERRIDE(fastpath_, glTexStorage2DMultisample);
579 COREGL_OVERRIDE(fastpath_, glGetMultisamplefv);
580 COREGL_OVERRIDE(fastpath_, glSampleMaski);
581 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameteriv);
582 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameterfv);
583 COREGL_OVERRIDE(fastpath_, glBindVertexBuffer);
584 COREGL_OVERRIDE(fastpath_, glVertexAttribFormat);
585 COREGL_OVERRIDE(fastpath_, glVertexAttribIFormat);
586 COREGL_OVERRIDE(fastpath_, glVertexAttribBinding);
587 COREGL_OVERRIDE(fastpath_, glVertexBindingDivisor);
590 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
596 static inline GL_Object_Hash_Base *
597 _lock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
600 case GL_OBJECT_TYPE_QUERY:
601 return &ostate->query;
602 case GL_OBJECT_TYPE_TEXTURE:
603 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
604 return &ostate->shared->texture;
605 case GL_OBJECT_TYPE_BUFFER:
606 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
607 return &ostate->shared->buffer;
608 case GL_OBJECT_TYPE_FRAMEBUFFER:
609 return &ostate->framebuffer;
610 case GL_OBJECT_TYPE_RENDERBUFFER:
611 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
612 return &ostate->shared->renderbuffer;
613 case GL_OBJECT_TYPE_PROGRAM:
614 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
615 return &ostate->shared->program;
616 case GL_OBJECT_TYPE_VERTEXARRAY:
617 return &ostate->vertexarray;
618 case GL_OBJECT_TYPE_SAMPLER:
619 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
620 return &ostate->shared->sampler;
621 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
622 return &ostate->transformfeedback;
623 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
624 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
625 return &ostate->shared->programpipeline;
632 _unlock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
635 case GL_OBJECT_TYPE_TEXTURE:
636 case GL_OBJECT_TYPE_BUFFER:
637 case GL_OBJECT_TYPE_RENDERBUFFER:
638 case GL_OBJECT_TYPE_PROGRAM:
639 case GL_OBJECT_TYPE_SAMPLER:
640 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
641 AST(mutex_unlock(&ostate->shared->access_mutex) == 1);
647 static inline GL_Object_Hash_Base *
648 _lock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
651 case GL_OBJECT_TYPE_QUERY:
652 return &ostate->query_real;
653 case GL_OBJECT_TYPE_TEXTURE:
654 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
655 return &ostate->shared->texture_real;
656 case GL_OBJECT_TYPE_BUFFER:
657 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
658 return &ostate->shared->buffer_real;
659 case GL_OBJECT_TYPE_FRAMEBUFFER:
660 return &ostate->framebuffer_real;
661 case GL_OBJECT_TYPE_RENDERBUFFER:
662 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
663 return &ostate->shared->renderbuffer_real;
664 case GL_OBJECT_TYPE_PROGRAM:
665 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
666 return &ostate->shared->program_real;
667 case GL_OBJECT_TYPE_VERTEXARRAY:
668 return &ostate->vertexarray_real;
669 case GL_OBJECT_TYPE_SAMPLER:
670 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
671 return &ostate->shared->sampler_real;
672 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
673 return &ostate->transformfeedback_real;
674 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
675 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
676 return &ostate->shared->programpipeline_real;
683 _unlock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
686 case GL_OBJECT_TYPE_TEXTURE:
687 case GL_OBJECT_TYPE_BUFFER:
688 case GL_OBJECT_TYPE_RENDERBUFFER:
689 case GL_OBJECT_TYPE_PROGRAM:
690 case GL_OBJECT_TYPE_SAMPLER:
691 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
692 AST(mutex_unlock(&ostate->shared->real_access_mutex) == 1);
700 fastpath_add_context_state_to_list(const void *option, const int option_len,
701 GLContextState *cstate, Mutex *mtx)
705 GLContext_List *current = NULL;
706 GLContext_List *newitm = NULL;
708 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
712 tid = get_current_thread();
714 current = glctx_list;
715 while (current != NULL) {
716 if (current->option_len == option_len &&
717 memcmp(current->option, option, option_len) == 0 &&
718 current->thread_id == tid) {
719 AST(current->cstate == cstate);
722 current = current->next;
725 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
726 if (newitm == NULL) {
727 COREGL_ERR("Failed to create context list.\n");
731 newitm->cstate = cstate;
732 newitm->thread_id = tid;
733 newitm->option_len = option_len;
734 newitm->option = (void *)malloc(option_len);
735 memcpy(newitm->option, option, option_len);
737 if (glctx_list != NULL)
738 newitm->next = glctx_list;
747 if (newitm != NULL) {
751 if (cstate != NULL) {
756 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
762 fastpath_get_context_state_from_list(const void *option, const int option_len,
765 GLContextState *ret = NULL;
766 GLContext_List *current = NULL;
769 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
771 tid = get_current_thread();
773 current = glctx_list;
774 while (current != NULL) {
775 if (current->option_len == option_len &&
776 memcmp(current->option, option, option_len) == 0 &&
777 current->thread_id == tid) {
778 ret = current->cstate;
781 current = current->next;
786 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
791 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
794 GLContext_List *olditm = NULL;
795 GLContext_List *current = NULL;
797 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
801 current = glctx_list;
803 while (current != NULL) {
804 if (current->cstate == cstate) {
805 GLContext_List *nextitm = NULL;
806 if (olditm != NULL) {
807 olditm->next = current->next;
808 nextitm = olditm->next;
810 glctx_list = current->next;
811 nextitm = glctx_list;
813 if (current->option != NULL) {
814 AST(current->option_len > 0);
815 free(current->option);
816 current->option = NULL;
817 current->option_len = 0;
825 current = current->next;
830 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
836 #define HASH_INIT(hash_base) \
837 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
838 hash_base.hash_size = GL_OBJECT_HASH_BASE;
841 fastpath_ostate_init(GL_Object_State *ostate)
843 HASH_INIT(ostate->query);
844 HASH_INIT(ostate->framebuffer);
845 HASH_INIT(ostate->vertexarray);
846 HASH_INIT(ostate->transformfeedback);
848 HASH_INIT(ostate->query_real);
849 HASH_INIT(ostate->framebuffer_real);
850 HASH_INIT(ostate->vertexarray_real);
851 HASH_INIT(ostate->transformfeedback_real);
855 fastpath_sostate_init(GL_Shared_Object_State *sostate)
857 mutex_init(&sostate->access_mutex);
859 HASH_INIT(sostate->texture);
860 HASH_INIT(sostate->buffer);
861 HASH_INIT(sostate->renderbuffer);
862 HASH_INIT(sostate->program);
863 HASH_INIT(sostate->sampler);
864 HASH_INIT(sostate->programpipeline);
866 HASH_INIT(sostate->texture_real);
867 HASH_INIT(sostate->buffer_real);
868 HASH_INIT(sostate->renderbuffer_real);
869 HASH_INIT(sostate->program_real);
870 HASH_INIT(sostate->sampler_real);
871 HASH_INIT(sostate->programpipeline_real);
878 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
880 int array_idx = data->hash_key & (hash_base->hash_size - 1);
881 if (hash_base->hash_field[array_idx] == NULL) {
882 hash_base->hash_field[array_idx] = data;
884 GL_Object_Hash *current = hash_base->hash_field[array_idx];
885 while (current->next) {
886 AST(current->hash_key != data->hash_key);
887 current = current->next;
889 current->next = data;
892 hash_base->item_size++;
896 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
899 int array_idx = hash & (hash_base->hash_size - 1);
901 GL_Object_Hash *current = hash_base->hash_field[array_idx];
902 GL_Object_Hash *prev = NULL;
905 if (current->hash_key == hash) {
907 prev->next = current->next;
909 hash_base->hash_field[array_idx] = current->next;
910 hash_base->item_size--;
915 current = current->next;
922 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
924 if (hash_base->item_size == 0) return;
926 for (int i = 0; i < hash_base->hash_size; i++) {
927 if (hash_base->hash_field[i] != NULL) {
928 GL_Object_Hash *current = hash_base->hash_field[i];
930 while (current != NULL) {
931 GL_Object_Hash *current_next = current->next;
933 if (free_data == 1 && current->item != NULL) {
938 hash_base->item_size--;
939 current = current_next;
947 #define HASH_DEINIT(hash_base, free_data) \
948 _free_hash_list(&hash_base, free_data); \
949 free(hash_base.hash_field); \
950 hash_base.hash_size = 0;
953 fastpath_ostate_deinit(GL_Object_State *ostate)
955 HASH_DEINIT(ostate->query, 1);
956 HASH_DEINIT(ostate->framebuffer, 1);
957 HASH_DEINIT(ostate->vertexarray, 1);
958 HASH_DEINIT(ostate->transformfeedback, 1);
960 HASH_DEINIT(ostate->query_real, 0);
961 HASH_DEINIT(ostate->framebuffer_real, 0);
962 HASH_DEINIT(ostate->vertexarray_real, 0);
963 HASH_DEINIT(ostate->transformfeedback_real, 0);
967 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
969 HASH_DEINIT(sostate->texture, 1);
970 HASH_DEINIT(sostate->buffer, 1);
971 HASH_DEINIT(sostate->renderbuffer, 1);
972 HASH_DEINIT(sostate->program, 1);
973 HASH_DEINIT(sostate->sampler, 1);
974 HASH_DEINIT(sostate->programpipeline, 1);
976 HASH_DEINIT(sostate->texture_real, 0);
977 HASH_DEINIT(sostate->buffer_real, 0);
978 HASH_DEINIT(sostate->renderbuffer_real, 0);
979 HASH_DEINIT(sostate->program_real, 0);
980 HASH_DEINIT(sostate->sampler_real, 0);
982 HASH_DEINIT(sostate->programpipeline_real, 0);
989 #define FIND_HASH(hash_base, key, ret) \
991 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
994 if (fh_current->hash_key == (key)) \
999 fh_current = fh_current->next; \
1004 _ostate_hash_check(GL_Object_Hash_Base *hash_base)
1006 if (hash_base->item_size + 1 < hash_base->hash_size)
1009 int oldsize = hash_base->hash_size;
1010 GL_Object_Hash **oldfield = hash_base->hash_field;
1012 hash_base->hash_size = oldsize << 1;
1013 hash_base->hash_field = (GL_Object_Hash **)calloc(1,
1014 sizeof(GL_Object_Hash *) * hash_base->hash_size);
1015 AST(hash_base->hash_field != NULL);
1017 for (int i = 0; i < oldsize; i++) {
1018 if (oldfield[i] != NULL) {
1019 GL_Object_Hash *current = oldfield[i];
1021 while (current != NULL) {
1022 GL_Object_Hash *current_next = current->next;
1023 _add_hash(hash_base, current);
1024 hash_base->item_size--;
1025 current = current_next;
1034 fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type,
1037 GLuint ret = _COREGL_INT_INIT_VALUE;
1039 GL_Object_Hash_Base *hash_base = NULL;
1040 GL_Object_Hash_Base *hash_base_real = NULL;
1041 int newid = _COREGL_INT_INIT_VALUE;
1043 hash_base = _lock_gl_object_hash(ostate, type);
1044 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1046 newid = hash_base->last_id + 1;
1047 if (newid >= hash_base->hash_size) {
1048 hash_base->is_looped = 1;
1050 hash_base->last_id = 1;
1053 if (hash_base->is_looped != 0) {
1055 int findingid = newid;
1057 for (i = 0; i < hash_base->hash_size; i++) {
1058 GL_Object_Hash *exist_hash = NULL;
1059 FIND_HASH(hash_base, findingid, exist_hash);
1060 if (exist_hash == NULL) {
1065 if (findingid >= hash_base->hash_size) findingid = 1;
1069 hash_base->last_id = newid;
1072 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
1075 newobj->id = (int)type + newid;
1076 newobj->real_id = real_name;
1077 newobj->ref_count = 1;
1080 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1,
1081 sizeof(GL_Object_Hash));
1082 if (newobj_hash == NULL) {
1086 newobj_hash->item = newobj;
1087 newobj_hash->hash_key = newid;
1088 _add_hash(hash_base, newobj_hash);
1090 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1,
1091 sizeof(GL_Object_Hash));
1092 if (newobj_hash_real == NULL) {
1097 newobj_hash_real->item = newobj;
1098 newobj_hash_real->hash_key = real_name;
1099 _add_hash(hash_base_real, newobj_hash_real);
1104 _ostate_hash_check(hash_base);
1105 _ostate_hash_check(hash_base_real);
1110 _unlock_gl_object_hash(ostate, type);
1111 _unlock_gl_object_hash_real(ostate, type);
1115 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
1116 if (((int)(hash)) < 0) { ret = 0; goto finish; } \
1118 GL_Object_Hash *object_hash = NULL; \
1119 FIND_HASH((hash_base), (int)(hash), object_hash); \
1120 if (object_hash == NULL) { ret = 0; goto finish; } \
1121 (object) = object_hash->item; \
1122 if ((object) == NULL) { ret = 0; goto finish; } \
1126 fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type,
1129 GLuint ret = _COREGL_INT_INIT_VALUE;
1131 GL_Object_Hash_Base *hash_base = NULL;
1132 GL_Object_Hash_Base *hash_base_real = NULL;
1133 GL_Object *object = NULL;
1135 hash_base = _lock_gl_object_hash(ostate, type);
1136 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1138 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1140 object->ref_count--;
1142 if (object->ref_count <= 0) {
1143 GL_Object_Hash *object_hash = NULL;
1145 FIND_HASH(hash_base, object->id - (int)type, object_hash);
1146 AST(object_hash != NULL);
1147 _remove_hash(hash_base, object->id - (int)type);
1151 FIND_HASH(hash_base_real, object->real_id, object_hash);
1152 AST(object_hash != NULL);
1153 _remove_hash(hash_base_real, object->real_id);
1165 _unlock_gl_object_hash(ostate, type);
1166 _unlock_gl_object_hash_real(ostate, type);
1171 fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type,
1174 GLuint ret = _COREGL_INT_INIT_VALUE;
1176 GL_Object_Hash_Base *hash_base = NULL;
1177 GL_Object *object = NULL;
1179 hash_base = _lock_gl_object_hash(ostate, type);
1181 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1183 ret = object->real_id;
1187 _unlock_gl_object_hash(ostate, type);
1191 /* Check if the context's state contains object of a given type */
1193 fastpath_ostate_has_object_type(GL_Object_State *ostate, GL_Object_Type type)
1195 GLuint ret = _COREGL_INT_INIT_VALUE;
1197 GL_Object_Hash_Base *hash_base = NULL;
1198 GL_Object *object = NULL;
1199 hash_base = _lock_gl_object_hash(ostate, type);
1201 if (hash_base->hash_field == 0) {
1206 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, 1, object);
1208 ret = object->real_id;
1212 _unlock_gl_object_hash(ostate, type);
1218 fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1219 GLuint glue_name, GLvoid *tag)
1221 GLint ret = _COREGL_INT_INIT_VALUE;
1223 GL_Object_Hash_Base *hash_base = NULL;
1224 GL_Object *object = NULL;
1225 int hash = _COREGL_INT_INIT_VALUE;
1227 hash_base = _lock_gl_object_hash(ostate, type);
1229 hash = glue_name - (int)type;
1231 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
1233 AST(object->tag == NULL);
1239 _unlock_gl_object_hash(ostate, type);
1244 fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1249 GL_Object_Hash_Base *hash_base = NULL;
1250 GL_Object *object = NULL;
1252 hash_base = _lock_gl_object_hash(ostate, type);
1254 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1260 _unlock_gl_object_hash(ostate, type);
1265 fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type,
1268 GLuint ret = _COREGL_INT_INIT_VALUE;
1270 GL_Object_Hash_Base *hash_base_real = NULL;
1271 GL_Object *object = NULL;
1273 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1275 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
1281 _unlock_gl_object_hash_real(ostate, type);
1286 fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type,
1289 GLint ret = _COREGL_INT_INIT_VALUE;
1291 GL_Object_Hash_Base *hash_base = NULL;
1292 GL_Object *object = NULL;
1294 hash_base = _lock_gl_object_hash(ostate, type);
1296 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1298 object->ref_count++;
1303 _unlock_gl_object_hash(ostate, type);
1308 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
1310 static struct timeval tv_last = { 0, 0 };
1312 if (unlikely(trace_state_flag != 1)) return;
1314 if (!force_output) {
1315 struct timeval tv_now = { 0, 0 };
1316 AST(gettimeofday(&tv_now, NULL) == 0);
1317 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC) {
1324 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1325 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n",
1327 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1329 #define PRINTF_CHAR_GLenum "0x%8X"
1330 #define PRINTF_CHAR_GLboolean "%10d"
1331 #define PRINTF_CHAR_GLint "%10d"
1332 #define PRINTF_CHAR_GLsizei "%10u"
1333 #define PRINTF_CHAR_GLuint "%10u"
1334 #define PRINTF_CHAR_GLuintmask "0x%8X"
1335 #define PRINTF_CHAR_GLintptr "%10ld"
1336 #define PRINTF_CHAR_GLsizeiptr "%10ld"
1338 #define PRINTF_CHAR_GLclampf "%10.6f"
1339 #define PRINTF_CHAR_GLfloat "%10.6f"
1341 #define PRINTF_CHAR_GLvoidptr "%10p"
1343 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1345 #define _COREGL_START_API(version) api_gl_version = version;
1346 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1347 #define INITIAL_CTX initial_ctx
1348 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1350 TYPE valuedata[SIZE]; \
1351 TYPE *value = NULL; \
1352 if(api_gl_version <= driver_gl_version) { \
1353 value = valuedata; GET_STMT; value = valuedata; \
1354 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1355 for (int i = 0; i < SIZE; i++) \
1359 TRACE("\n %-30.30s ", "");\
1363 if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
1364 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1365 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1366 if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
1368 TRACE(" \E[40;37;1m)\E[0m\n"); \
1371 # include "coregl_fastpath_state.h"
1374 #undef _COREGL_START_API
1375 #undef _COREGL_END_API
1377 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1387 fastpath_init_context_states(GLGlueContext *ctx)
1391 AST(mutex_lock(&init_context_mutex) == 1);
1394 COREGL_ERR("Context NULL\n");
1399 AST(ctx->initialized == 0);
1400 AST(ctx->ostate.shared != NULL);
1402 if (initial_ctx == NULL) {
1403 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1404 AST(initial_ctx != NULL);
1406 //#define FORCE_DEFAULT_VALUE
1407 #define _COREGL_START_API(version) api_gl_version = version;
1408 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1409 #ifdef FORCE_DEFAULT_VALUE
1410 # define INITIAL_CTX initial_ctx
1411 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1415 TYPE valuedata[SIZE]; \
1416 TYPE *value = NULL; \
1417 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1418 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1419 if(api_gl_version <= driver_gl_version) { \
1420 value = valuedata; DEFAULT_STMT; value = valuedata; \
1421 for (i = 0; i < SIZE; i++) \
1423 if (*((char *)(&value[i])) == 0xcc) \
1425 memset(&value[i], 0xaa, sizeof(TYPE)); \
1426 value = valuedata; DEFAULT_STMT; value = valuedata; \
1427 if (*((char *)(&value[i])) == 0xaa) \
1429 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1433 initial_ctx->NAME[i] = value[i]; \
1438 # include "coregl_fastpath_state.h"
1442 # define INITIAL_CTX initial_ctx
1443 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1444 if (try_step == 1) \
1446 value = valuedata; DEFAULT_STMT; value = valuedata; \
1450 value = valuedata; FALLBACK_STMT; value = valuedata; \
1453 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1458 TYPE valuedata[SIZE]; \
1459 TYPE *value = NULL; \
1460 _sym_glGetError(); \
1461 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1462 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1463 if(api_gl_version <= driver_gl_version) { \
1466 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1467 if (_sym_glGetError() == GL_INVALID_ENUM) \
1469 initial_ctx->NAME##_used = 0; \
1470 value = valuedata; DEFAULT_STMT; value = valuedata; \
1473 initial_ctx->NAME##_used = 1; \
1474 for (i = 0; i < SIZE; i++) \
1476 if (*((char *)(&value[i])) == 0xcc) \
1478 memset(&value[i], 0xaa, sizeof(TYPE)); \
1479 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1480 if (*((char *)(&value[i])) == 0xaa) \
1483 if (try_step == 2) \
1485 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1490 initial_ctx->NAME[i] = value[i]; \
1492 if (try_step != 2) \
1494 value = valuedata; DEFAULT_STMT; value = valuedata; \
1495 for (i = 0; i < SIZE; i++) \
1497 if (initial_ctx->NAME[i] != value[i]) \
1499 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]); \
1504 while (try_step == 2); \
1508 # include "coregl_fastpath_state.h"
1509 # undef SET_GLUE_VALUE
1513 # undef _COREGL_END_API
1514 # undef _COREGL_START_API
1516 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS) {
1517 COREGL_WRN("\E[40;31;1mNumber of vertex attrib is too big! (%d-%d)\E[0m\n",
1518 MAX_VERTEX_ATTRIBS, initial_ctx->gl_num_vertex_attribs[0]);
1520 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS) {
1521 COREGL_WRN("\E[40;31;1mNumber of texture unit is too big! (%d-%d)\E[0m\n",
1522 MAX_TEXTURE_UNITS, initial_ctx->gl_num_tex_units[0]);
1524 if (initial_ctx->gl_num_transform_feedback_separate_attribs[0] >
1525 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS) {
1526 COREGL_WRN("\E[40;31;1mNumber of transform feedback separate attrib is too big! (%d-%d)\E[0m\n",
1527 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
1528 initial_ctx->gl_num_transform_feedback_separate_attribs[0]);
1530 if (initial_ctx->gl_num_uniform_buffer_bindings[0] >
1531 MAX_UNIFORM_BUFFER_BINDINGS) {
1532 COREGL_WRN("\E[40;31;1mNumber of uniform buffer binding is too big! (%d-%d)\E[0m\n",
1533 MAX_UNIFORM_BUFFER_BINDINGS, initial_ctx->gl_num_uniform_buffer_bindings[0]);
1539 #define _COREGL_START_API(version) api_gl_version = version;
1540 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1541 #define INITIAL_CTX initial_ctx
1542 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1545 ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE)); \
1546 if(api_gl_version <= driver_gl_version) { \
1547 for (i = 0; i < SIZE; i++) \
1549 ctx->NAME[i] = initial_ctx->NAME[i]; \
1550 ctx->NAME##_used = initial_ctx->NAME##_used; \
1555 # include "coregl_fastpath_state.h"
1558 #undef _COREGL_START_API
1559 #undef _COREGL_END_API
1562 ctx->initialized = 1;
1567 AST(mutex_unlock(&init_context_mutex) == 1);
1572 #ifdef COREGL_USE_MODULE_TRACEPATH
1573 extern void *tracepath_api_trace_begin(const char *name, void *hint,
1574 int trace_total_time);
1575 extern void *tracepath_api_trace_end(const char *name, void *hint,
1576 int trace_total_time);
1579 #define CHECK_GL_ERROR(func) \
1582 int err = _orig_fastpath_glGetError(); \
1583 if (err != GL_NO_ERROR) \
1585 COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1591 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1594 unsigned char flag = 0;
1597 if (debug_nofp == 1) {
1602 // Return if they're the same
1603 if (oldctx == newctx) {
1608 #define STATE_COMPARE(state) \
1609 if ((oldctx->state) != (newctx->state))
1611 #define STATES_COMPARE(state_ptr, bytes) \
1612 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1615 #ifdef COREGL_USE_MODULE_TRACEPATH
1616 static void *trace_hint_glfinish = NULL;
1617 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)",
1618 trace_hint_glfinish, 0);
1619 #endif // COREGL_USE_MODULE_TRACEPATH
1622 int err = _orig_fastpath_glGetError();
1623 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1624 oldctx->gl_error = err;
1627 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1629 #ifdef COREGL_USE_MODULE_TRACEPATH
1630 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1631 #endif // COREGL_USE_MODULE_TRACEPATH
1634 #ifdef COREGL_USE_MODULE_TRACEPATH
1635 static void *trace_hint_vertex_attrib = NULL;
1636 trace_hint_vertex_attrib =
1637 tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)",
1638 trace_hint_vertex_attrib, 0);
1639 #endif // COREGL_USE_MODULE_TRACEPATH
1641 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1643 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++) {
1644 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i]) {
1645 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1646 newctx->gl_vertex_array_buf_id[i]))
1648 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1651 STATE_COMPARE(gl_vertex_array_divisor[i]) {
1652 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribDivisor(i,
1653 newctx->gl_vertex_array_divisor[i]))
1656 if (newctx->gl_vertex_array_size[i] != 0) {
1657 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1658 newctx->gl_vertex_array_size[i],
1659 newctx->gl_vertex_array_type[i],
1660 newctx->gl_vertex_array_normalized[i],
1661 newctx->gl_vertex_array_stride[i],
1662 newctx->gl_vertex_array_pointer[i]))
1664 if (newctx->gl_vertex_array_integer[0] == GL_TRUE) {
1665 if (newctx->gl_vertex_array_type[0] == GL_UNSIGNED_INT) {
1666 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4uiv(i,
1667 &newctx->gl_vertex_attrib_value_unsigned_integer[4 * i]))
1669 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4iv(i,
1670 &newctx->gl_vertex_attrib_value_integer[4 * i]))
1673 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i,
1674 &newctx->gl_vertex_attrib_value[4 * i]))
1678 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE) {
1679 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1681 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1687 #ifdef COREGL_USE_MODULE_TRACEPATH
1688 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)",
1689 trace_hint_vertex_attrib, 0);
1690 #endif // COREGL_USE_MODULE_TRACEPATH
1693 #ifdef COREGL_USE_MODULE_TRACEPATH
1694 static void *trace_hint_bindbuffers = NULL;
1695 trace_hint_bindbuffers =
1696 tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)",
1697 trace_hint_bindbuffers, 0);
1698 #endif // COREGL_USE_MODULE_TRACEPATH
1700 //------------------//
1702 flag = oldctx->_bind_flag1 | newctx->_bind_flag1;
1704 STATE_COMPARE(gl_array_buffer_binding[0]) {
1705 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1706 newctx->gl_array_buffer_binding[0]))
1708 STATE_COMPARE(gl_element_array_buffer_binding[0]) {
1709 STATE_COMPARE(gl_vertex_array_binding[0]) {
1710 CHECK_GL_ERROR(_orig_fastpath_glBindVertexArray(
1711 newctx->gl_vertex_array_binding[0]))
1713 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1714 newctx->gl_element_array_buffer_binding[0]))
1717 if (newctx->gl_framebuffer_binding_read_used == 1) {
1718 STATE_COMPARE(gl_framebuffer_binding_read[0]) {
1719 if (driver_gl_version >= 2)
1720 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER,
1721 newctx->gl_framebuffer_binding_read[0]))
1723 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_READ_FRAMEBUFFER,
1724 newctx->gl_framebuffer_binding_read[0]))
1726 STATE_COMPARE(gl_framebuffer_binding_draw[0]) {
1727 if (driver_gl_version >= 2)
1728 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1729 newctx->gl_framebuffer_binding_draw[0]))
1731 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_DRAW_FRAMEBUFFER,
1732 newctx->gl_framebuffer_binding_draw[0]))
1735 STATE_COMPARE(gl_framebuffer_binding[0]) {
1736 if (driver_gl_version >= 2)
1737 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER,
1738 newctx->gl_framebuffer_binding[0]))
1740 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_FRAMEBUFFER,
1741 newctx->gl_framebuffer_binding[0]))
1744 STATE_COMPARE(gl_renderbuffer_binding[0]) {
1745 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER,
1746 newctx->gl_renderbuffer_binding[0]))
1750 //------------------//
1752 flag = oldctx->_bind_flag2 | newctx->_bind_flag2;
1754 STATE_COMPARE(gl_copy_read_buffer_binding[0]) {
1755 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_READ_BUFFER,
1756 newctx->gl_copy_read_buffer_binding[0]))
1758 STATE_COMPARE(gl_copy_write_buffer_binding[0]) {
1759 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_WRITE_BUFFER,
1760 newctx->gl_copy_write_buffer_binding[0]))
1762 STATE_COMPARE(gl_pixel_pack_buffer_binding[0]) {
1763 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_PACK_BUFFER,
1764 newctx->gl_pixel_pack_buffer_binding[0]))
1766 STATE_COMPARE(gl_pixel_unpack_buffer_binding[0]) {
1767 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
1768 newctx->gl_pixel_unpack_buffer_binding[0]))
1770 STATE_COMPARE(gl_transform_feedback_buffer_binding[0]) {
1771 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER,
1772 newctx->gl_transform_feedback_buffer_binding[0]))
1774 STATE_COMPARE(gl_uniform_buffer_binding[0]) {
1775 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_UNIFORM_BUFFER,
1776 newctx->gl_uniform_buffer_binding[0]))
1779 #ifdef COREGL_USE_MODULE_TRACEPATH
1780 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)",
1781 trace_hint_bindbuffers, 0);
1782 #endif // COREGL_USE_MODULE_TRACEPATH
1785 //------------------//
1788 #ifdef COREGL_USE_MODULE_TRACEPATH
1789 static void *trace_hint_enable_states = NULL;
1790 trace_hint_enable_states =
1791 tracepath_api_trace_begin("eglMakeCurrent(FP enable states)",
1792 trace_hint_enable_states, 0);
1793 #endif // COREGL_USE_MODULE_TRACEPATH
1795 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1797 STATE_COMPARE(gl_blend[0]) {
1798 if (newctx->gl_blend[0]) {
1799 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1801 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1803 STATE_COMPARE(gl_cull_face[0]) {
1804 if (newctx->gl_cull_face[0]) {
1805 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1807 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1809 STATE_COMPARE(gl_depth_test[0]) {
1810 if (newctx->gl_depth_test[0]) {
1811 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1813 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1815 STATE_COMPARE(gl_dither[0]) {
1816 if (newctx->gl_dither[0]) {
1817 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1819 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1824 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1826 STATE_COMPARE(gl_polygon_offset_fill[0]) {
1827 if (newctx->gl_polygon_offset_fill[0]) {
1828 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1830 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1832 STATE_COMPARE(gl_sample_alpha_to_coverage[0]) {
1833 if (newctx->gl_sample_alpha_to_coverage[0]) {
1834 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1836 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1838 STATE_COMPARE(gl_sample_coverage[0]) {
1839 if (newctx->gl_sample_coverage[0]) {
1840 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1842 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1844 STATE_COMPARE(gl_scissor_test[0]) {
1845 if (newctx->gl_scissor_test[0]) {
1846 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1848 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1850 STATE_COMPARE(gl_stencil_test[0]) {
1851 if (newctx->gl_stencil_test[0]) {
1852 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1854 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1859 flag = oldctx->_enable_flag3 | newctx->_enable_flag3;
1861 STATE_COMPARE(gl_primitive_restart_fixed_index[0]) {
1862 if (newctx->gl_primitive_restart_fixed_index[0]) {
1863 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1865 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1867 STATE_COMPARE(gl_rasterizer_discard[0]) {
1868 if (newctx->gl_rasterizer_discard[0]) {
1869 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_RASTERIZER_DISCARD))
1871 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_RASTERIZER_DISCARD))
1875 #ifdef COREGL_USE_MODULE_TRACEPATH
1876 tracepath_api_trace_end("eglMakeCurrent(FP enable states)",
1877 trace_hint_enable_states, 0);
1878 #endif // COREGL_USE_MODULE_TRACEPATH
1880 //------------------//
1882 #ifdef COREGL_USE_MODULE_TRACEPATH
1883 static void *trace_hint_clear_viewport = NULL;
1884 trace_hint_clear_viewport =
1885 tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)",
1886 trace_hint_clear_viewport, 0);
1887 #endif // COREGL_USE_MODULE_TRACEPATH
1889 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1892 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint)) {
1893 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1894 newctx->gl_viewport[1],
1895 newctx->gl_viewport[2],
1896 newctx->gl_viewport[3]))
1899 STATE_COMPARE(gl_current_program[0]) {
1900 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1902 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf)) {
1903 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1904 newctx->gl_color_clear_value[1],
1905 newctx->gl_color_clear_value[2],
1906 newctx->gl_color_clear_value[3]))
1912 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1914 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean)) {
1915 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1916 newctx->gl_color_writemask[1],
1917 newctx->gl_color_writemask[2],
1918 newctx->gl_color_writemask[3]))
1920 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf)) {
1921 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1922 newctx->gl_depth_range[1]))
1924 STATE_COMPARE(gl_depth_clear_value[0]) {
1925 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1927 STATE_COMPARE(gl_depth_func[0]) {
1928 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1930 STATE_COMPARE(gl_depth_writemask[0]) {
1931 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1933 STATE_COMPARE(gl_cull_face_mode[0]) {
1934 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1939 #ifdef COREGL_USE_MODULE_TRACEPATH
1940 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)",
1941 trace_hint_clear_viewport, 0);
1942 #endif // COREGL_USE_MODULE_TRACEPATH
1944 //------------------//
1946 #ifdef COREGL_USE_MODULE_TRACEPATH
1947 static void *trace_hint_bind_textures = NULL;
1948 trace_hint_bind_textures =
1949 tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)",
1950 trace_hint_bind_textures, 0);
1951 #endif // COREGL_USE_MODULE_TRACEPATH
1953 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1956 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++) {
1957 STATE_COMPARE(gl_tex_2d_state[i]) {
1958 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1959 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D,
1960 newctx->gl_tex_2d_state[i]))
1962 STATE_COMPARE(gl_tex_3d_state[i]) {
1963 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1964 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_3D,
1965 newctx->gl_tex_3d_state[i]))
1967 STATE_COMPARE(gl_tex_2d_array_state[i]) {
1968 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1969 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_ARRAY,
1970 newctx->gl_tex_2d_array_state[i]))
1972 STATE_COMPARE(gl_tex_cube_state[i]) {
1973 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1974 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP,
1975 newctx->gl_tex_cube_state[i]))
1977 STATE_COMPARE(gl_tex_external_oes_state[i]) {
1978 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1979 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_EXTERNAL_OES,
1980 newctx->gl_tex_external_oes_state[i]))
1984 // Restore active texture
1985 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1987 STATE_COMPARE(gl_generate_mipmap_hint[0]) {
1988 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT,
1989 newctx->gl_generate_mipmap_hint[0]))
1992 #ifdef COREGL_USE_MODULE_TRACEPATH
1993 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)",
1994 trace_hint_bind_textures, 0);
1995 #endif // COREGL_USE_MODULE_TRACEPATH
1997 //------------------//
1998 #ifdef COREGL_USE_MODULE_TRACEPATH
1999 static void *trace_hint_etc = NULL;
2000 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)",
2002 #endif // COREGL_USE_MODULE_TRACEPATH
2004 flag = oldctx->_blend_flag | newctx->_blend_flag;
2006 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf)) {
2007 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
2008 newctx->gl_blend_color[1],
2009 newctx->gl_blend_color[2],
2010 newctx->gl_blend_color[3]))
2012 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
2013 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
2014 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
2015 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0])) {
2016 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
2017 newctx->gl_blend_dst_rgb[0],
2018 newctx->gl_blend_src_alpha[0],
2019 newctx->gl_blend_dst_alpha[0]))
2021 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
2022 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0])) {
2023 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(
2024 newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
2029 //------------------//
2031 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
2033 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
2034 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
2035 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0])) {
2036 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
2037 newctx->gl_stencil_func[0],
2038 newctx->gl_stencil_ref[0],
2039 newctx->gl_stencil_value_mask[0]))
2041 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
2042 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0])
2044 (oldctx->gl_stencil_pass_depth_pass[0] !=
2045 newctx->gl_stencil_pass_depth_pass[0])) {
2046 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
2047 newctx->gl_stencil_fail[0],
2048 newctx->gl_stencil_pass_depth_fail[0],
2049 newctx->gl_stencil_pass_depth_pass[0]))
2052 STATE_COMPARE(gl_stencil_writemask[0]) {
2053 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT,
2054 newctx->gl_stencil_writemask[0]))
2060 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
2062 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
2063 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
2064 (oldctx->gl_stencil_back_value_mask[0] !=
2065 newctx->gl_stencil_back_value_mask[0])) {
2066 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
2067 newctx->gl_stencil_back_func[0],
2068 newctx->gl_stencil_back_ref[0],
2069 newctx->gl_stencil_back_value_mask[0]))
2071 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
2072 (oldctx->gl_stencil_back_pass_depth_fail[0] !=
2073 newctx->gl_stencil_back_pass_depth_fail[0]) ||
2074 (oldctx->gl_stencil_back_pass_depth_pass[0] !=
2075 newctx->gl_stencil_back_pass_depth_pass[0])) {
2076 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
2077 newctx->gl_stencil_back_fail[0],
2078 newctx->gl_stencil_back_pass_depth_fail[0],
2079 newctx->gl_stencil_back_pass_depth_pass[0]))
2082 STATE_COMPARE(gl_stencil_back_writemask[0]) {
2083 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK,
2084 newctx->gl_stencil_back_writemask[0]))
2086 STATE_COMPARE(gl_stencil_clear_value[0]) {
2087 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
2091 //------------------//
2093 flag = oldctx->_pixel_flag1 | newctx->_pixel_flag1;
2095 STATE_COMPARE(gl_pack_row_length[0]) {
2096 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ROW_LENGTH,
2097 newctx->gl_pack_row_length[0]))
2099 STATE_COMPARE(gl_pack_skip_rows[0]) {
2100 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_ROWS,
2101 newctx->gl_pack_skip_rows[0]))
2103 STATE_COMPARE(gl_pack_skip_pixels[0]) {
2104 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_PIXELS,
2105 newctx->gl_pack_skip_pixels[0]))
2107 STATE_COMPARE(gl_pack_alignment[0]) {
2108 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT,
2109 newctx->gl_pack_alignment[0]))
2114 flag = oldctx->_pixel_flag2 | newctx->_pixel_flag2;
2116 STATE_COMPARE(gl_unpack_row_length[0]) {
2117 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ROW_LENGTH,
2118 newctx->gl_unpack_row_length[0]))
2120 STATE_COMPARE(gl_unpack_skip_rows[0]) {
2121 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_ROWS,
2122 newctx->gl_unpack_skip_rows[0]))
2124 STATE_COMPARE(gl_unpack_skip_pixels[0]) {
2125 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_PIXELS,
2126 newctx->gl_unpack_skip_pixels[0]))
2128 STATE_COMPARE(gl_unpack_alignment[0]) {
2129 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT,
2130 newctx->gl_unpack_alignment[0]))
2132 STATE_COMPARE(gl_unpack_image_height[0]) {
2133 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,
2134 newctx->gl_unpack_image_height[0]))
2136 STATE_COMPARE(gl_unpack_skip_images[0]) {
2137 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_IMAGES,
2138 newctx->gl_unpack_skip_images[0]))
2142 //------------------//
2144 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
2146 STATE_COMPARE(gl_front_face[0]) {
2147 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
2149 STATE_COMPARE(gl_line_width[0]) {
2150 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
2152 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0])
2154 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0])) {
2155 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(
2156 newctx->gl_polygon_offset_factor[0],
2157 newctx->gl_polygon_offset_units[0]))
2159 if ((oldctx->gl_sample_coverage_value[0] !=
2160 newctx->gl_sample_coverage_value[0]) ||
2161 (oldctx->gl_sample_coverage_invert[0] !=
2162 newctx->gl_sample_coverage_invert[0])) {
2163 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(
2164 newctx->gl_sample_coverage_value[0],
2165 newctx->gl_sample_coverage_invert[0]))
2167 STATE_COMPARE(gl_fragment_shader_derivative_hint[0]) {
2168 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES,
2169 newctx->gl_fragment_shader_derivative_hint[0]))
2174 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
2176 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint)) {
2177 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
2178 newctx->gl_scissor_box[1],
2179 newctx->gl_scissor_box[2],
2180 newctx->gl_scissor_box[3]))
2185 flag = oldctx->_misc_flag3 | newctx->_misc_flag3;
2187 STATE_COMPARE(gl_read_buffer[0]) {
2188 CHECK_GL_ERROR(_orig_fastpath_glReadBuffer(newctx->gl_read_buffer[0]))
2190 STATES_COMPARE(gl_draw_buffers, 16 * sizeof(GLenum)) {
2191 int drawBuffSize = 16;
2192 /* If the context has only default framebuffer, then size of glDrawBuffers can only be 1 */
2193 if (fastpath_ostate_has_object_type(&newctx->ostate,
2194 GL_OBJECT_TYPE_FRAMEBUFFER) == 0) {
2198 CHECK_GL_ERROR(_orig_fastpath_glDrawBuffers(drawBuffSize,
2199 newctx->gl_draw_buffers))
2202 if (oldctx->gl_transform_feedback_active[0] == GL_TRUE &&
2203 oldctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2204 CHECK_GL_ERROR(_orig_fastpath_glPauseTransformFeedback())
2206 STATE_COMPARE(gl_transform_feedback_binding[0]) {
2207 CHECK_GL_ERROR(_orig_fastpath_glBindTransformFeedback(GL_TRANSFORM_FEEDBACK,
2208 newctx->gl_transform_feedback_binding[0]))
2210 if (newctx->gl_transform_feedback_active[0] == GL_TRUE &&
2211 newctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2212 CHECK_GL_ERROR(_orig_fastpath_glResumeTransformFeedback())
2216 #ifdef COREGL_USE_MODULE_TRACEPATH
2217 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
2218 #endif // COREGL_USE_MODULE_TRACEPATH
2225 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
2226 if (unlikely(trace_state_flag == 1))
2227 fastpath_dump_context_states(newctx, 0);
2228 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
2230 #undef STATE_COMPARE
2231 #undef STATES_COMPARE