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.h"
16 Fastpath_Opt_Flag fp_opt = FP_UNKNOWN_PATH;
19 FILE *trace_fp = NULL;
21 GLenum FPGL_Error = GL_NO_ERROR;
23 GLGlueContext_List *gctx_list = NULL;
25 Mutex init_context_mutex = MUTEX_INITIALIZER;
26 GLGlueContext *initial_ctx = NULL;
28 Mutex ctx_list_access_mutex = MUTEX_INITIALIZER;
30 GLContext_List *glctx_list = NULL;
31 static int api_gl_version = COREGL_GLAPI_2;
34 _state_get_texture_states(GLenum pname, GLint *params)
36 GLuint cur_active_tex = 0;
38 AST(initial_ctx != NULL);
40 _orig_fastpath_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
42 for (i = 0; i < initial_ctx->gl_num_tex_units[0]; i++) {
43 _orig_fastpath_glActiveTexture(GL_TEXTURE0 + i);
44 _orig_fastpath_glGetIntegerv(pname, (GLint *)¶ms[i]);
46 _orig_fastpath_glActiveTexture(cur_active_tex);
50 _state_get_draw_buffers(GLenum *params)
52 AST(initial_ctx != NULL);
55 for (i = 0; i < initial_ctx->gl_num_draw_buffers[0]; i++) {
56 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER0 + i, (GLint *)¶ms[i]);
61 _state_get_transform_feedback_buffer_bindings(GLuint *params)
63 AST(initial_ctx != NULL);
66 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0];
68 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, i,
74 _state_get_transform_feedback_buffer_bindings_offset(GLintptr *params)
76 AST(initial_ctx != NULL);
79 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0];
81 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_START, i,
87 _state_get_transform_feedback_buffer_bindings_size(GLsizeiptr *params)
89 AST(initial_ctx != NULL);
92 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0];
94 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE, i,
100 _state_get_uniform_buffer_bindings(GLuint *params)
102 AST(initial_ctx != NULL);
105 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++) {
106 /////////////////////////////////////////////////////////////////////////////////
107 // XXXX : AVOID SEGFAULT in ADRENO
108 ((GLint *)params)[i] = 0;
109 // _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, i, (GLint *)¶ms[i]);
110 /////////////////////////////////////////////////////////////////////////////////
115 _state_get_uniform_buffer_bindings_offset(GLintptr *params)
117 AST(initial_ctx != NULL);
120 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++) {
121 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_START, i, (GLint *)¶ms[i]);
126 _state_get_uniform_buffer_bindings_size(GLsizeiptr *params)
128 AST(initial_ctx != NULL);
131 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++) {
132 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, i, (GLint *)¶ms[i]);
137 fastpath_state_get_draw_buffers(GLenum *params)
139 _state_get_draw_buffers(params);
143 init_modules_fastpath()
145 int fastpath_opt = 0;
146 int fastpath_force_off_opt = 0;
148 COREGL_LOG("[CoreGL] <Fastpath> : ");
150 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
151 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
153 if (fastpath_force_off_opt == 1) {
154 COREGL_LOG("\E[40;31;1m(DISABLED by force option)\E[0m ");
158 switch (fastpath_opt) {
160 COREGL_LOG("(%d) Fastpath enabled...\n", fastpath_opt);
161 fp_opt = FP_FAST_PATH;
164 COREGL_LOG("(%d) Default API path enabled...\n", fastpath_opt);
165 fp_opt = FP_NORMAL_PATH;
169 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
174 deinit_modules_fastpath()
176 GLContext_List *current = NULL;
178 AST(mutex_lock(&ctx_list_access_mutex) == 1);
180 // Destroy remained context & Detect leaks
181 int retry_destroy = 0;
185 current = glctx_list;
187 if (current->cstate != NULL) {
188 COREGL_WRN("\E[40;31;1mContext attached to [dpy=%p|rctx=%p] has not been completely destroyed.(leak)\E[0m\n",
189 current->cstate->rdpy, current->cstate->rctx);
191 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE,
192 EGL_NO_SURFACE, EGL_NO_CONTEXT);
193 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
195 fastpath_remove_context_states_from_list(current->cstate, NULL);
200 glctx_list = current->next;
202 current = glctx_list;
204 if (retry_destroy == 0) break;
209 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
213 init_modules_tstate_fastpath(GLThreadState *tstate)
215 MY_MODULE_TSTATE *tstate_mt = NULL;
217 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
219 tstate_mt->binded_api = EGL_OPENGL_ES_API;
221 tstate->module_data[MY_MODULE_ID] = tstate_mt;
225 deinit_modules_tstate_fastpath(GLThreadState *tstate)
227 if (tstate->module_data[MY_MODULE_ID] != NULL) {
228 free(tstate->module_data[MY_MODULE_ID]);
229 tstate->module_data[MY_MODULE_ID] = NULL;
234 fastpath_apply_overrides()
238 fastpath_apply_overrides_egl(1);
239 fastpath_apply_overrides_gl(1);
244 COREGL_ERR("Invalide GL Override Option!!!\n");
251 fastpath_apply_overrides_egl(int enable)
253 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
254 # include "../../headers/sym_egl.h"
255 #undef _COREGL_SYMBOL
257 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
259 COREGL_OVERRIDE(fastpath_, eglBindAPI);
260 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
262 COREGL_OVERRIDE(fastpath_, eglCreateContext);
263 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
264 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
265 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
266 COREGL_OVERRIDE(fastpath_, eglQueryContext);
267 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
268 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
269 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
270 COREGL_OVERRIDE(fastpath_, eglTerminate);
271 COREGL_OVERRIDE(fastpath_, eglGetCurrentDisplay);
276 fastpath_apply_overrides_gl(int enable)
278 #define _COREGL_START_API(version) api_gl_version = version;
279 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
280 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
281 if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
283 # include "../../headers/sym_gl.h"
284 #undef _COREGL_SYMBOL
285 #undef _COREGL_START_API
286 #undef _COREGL_END_API
288 if (debug_nofp != 1) {
289 if (driver_gl_version >= COREGL_GLAPI_1) {
290 COREGL_OVERRIDE(fastpath_, glClientActiveTexture);
291 COREGL_OVERRIDE(fastpath_, glSampleCoveragex);
292 COREGL_OVERRIDE(fastpath_, glVertexPointer);
295 COREGL_OVERRIDE(fastpath_, glGetError);
296 COREGL_OVERRIDE(fastpath_, glGetString);
298 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
299 COREGL_OVERRIDE(fastpath_, glGetFloatv);
300 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
302 COREGL_OVERRIDE(fastpath_, glActiveTexture);
303 COREGL_OVERRIDE(fastpath_, glGenTextures);
304 COREGL_OVERRIDE(fastpath_, glBindTexture);
305 COREGL_OVERRIDE(fastpath_, glIsTexture);
306 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
307 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
309 COREGL_OVERRIDE(fastpath_, glGenBuffers);
310 COREGL_OVERRIDE(fastpath_, glBindBuffer);
311 COREGL_OVERRIDE(fastpath_, glIsBuffer);
312 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
314 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
315 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
316 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
317 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
318 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
320 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
321 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
322 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
323 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
324 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
326 COREGL_OVERRIDE(fastpath_, glCreateShader);
327 COREGL_OVERRIDE(fastpath_, glCreateProgram);
328 COREGL_OVERRIDE(fastpath_, glAttachShader);
329 COREGL_OVERRIDE(fastpath_, glCompileShader);
330 COREGL_OVERRIDE(fastpath_, glShaderBinary);
331 COREGL_OVERRIDE(fastpath_, glDeleteShader);
332 COREGL_OVERRIDE(fastpath_, glDetachShader);
333 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
334 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
335 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
336 COREGL_OVERRIDE(fastpath_, glIsShader);
337 COREGL_OVERRIDE(fastpath_, glShaderSource);
338 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
339 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
340 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
341 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
342 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
343 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
344 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
345 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
346 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
347 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
348 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
349 COREGL_OVERRIDE(fastpath_, glIsProgram);
350 COREGL_OVERRIDE(fastpath_, glLinkProgram);
351 COREGL_OVERRIDE(fastpath_, glUseProgram);
352 COREGL_OVERRIDE(fastpath_, glValidateProgram);
354 COREGL_OVERRIDE(fastpath_, glBlendColor);
355 COREGL_OVERRIDE(fastpath_, glBlendEquation);
356 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
357 COREGL_OVERRIDE(fastpath_, glBlendFunc);
358 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
359 COREGL_OVERRIDE(fastpath_, glClearColor);
360 COREGL_OVERRIDE(fastpath_, glClearDepthf);
361 COREGL_OVERRIDE(fastpath_, glClearStencil);
362 COREGL_OVERRIDE(fastpath_, glColorMask);
363 COREGL_OVERRIDE(fastpath_, glCullFace);
364 COREGL_OVERRIDE(fastpath_, glDepthFunc);
365 COREGL_OVERRIDE(fastpath_, glDepthMask);
366 COREGL_OVERRIDE(fastpath_, glDepthRangef);
367 COREGL_OVERRIDE(fastpath_, glDisable);
368 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
369 COREGL_OVERRIDE(fastpath_, glEnable);
370 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
371 COREGL_OVERRIDE(fastpath_, glFrontFace);
372 COREGL_OVERRIDE(fastpath_, glHint);
373 COREGL_OVERRIDE(fastpath_, glLineWidth);
374 COREGL_OVERRIDE(fastpath_, glPixelStorei);
375 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
376 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
377 COREGL_OVERRIDE(fastpath_, glScissor);
378 COREGL_OVERRIDE(fastpath_, glStencilFunc);
379 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
380 COREGL_OVERRIDE(fastpath_, glStencilMask);
381 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
382 COREGL_OVERRIDE(fastpath_, glStencilOp);
383 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
384 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
385 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
386 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
387 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
388 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
389 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
390 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
391 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
392 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
393 COREGL_OVERRIDE(fastpath_, glViewport);
395 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
396 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
398 COREGL_OVERRIDE(fastpath_, glUseProgramStagesEXT);
399 COREGL_OVERRIDE(fastpath_, glActiveShaderProgramEXT);
400 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
401 COREGL_OVERRIDE(fastpath_, glProgramUniform1iEXT);
402 COREGL_OVERRIDE(fastpath_, glProgramUniform2iEXT);
403 COREGL_OVERRIDE(fastpath_, glProgramUniform3iEXT);
404 COREGL_OVERRIDE(fastpath_, glProgramUniform4iEXT);
405 COREGL_OVERRIDE(fastpath_, glProgramUniform1fEXT);
406 COREGL_OVERRIDE(fastpath_, glProgramUniform2fEXT);
407 COREGL_OVERRIDE(fastpath_, glProgramUniform3fEXT);
408 COREGL_OVERRIDE(fastpath_, glProgramUniform4fEXT);
409 COREGL_OVERRIDE(fastpath_, glProgramUniform1ivEXT);
410 COREGL_OVERRIDE(fastpath_, glProgramUniform2ivEXT);
411 COREGL_OVERRIDE(fastpath_, glProgramUniform3ivEXT);
412 COREGL_OVERRIDE(fastpath_, glProgramUniform4ivEXT);
413 COREGL_OVERRIDE(fastpath_, glProgramUniform1fvEXT);
414 COREGL_OVERRIDE(fastpath_, glProgramUniform2fvEXT);
415 COREGL_OVERRIDE(fastpath_, glProgramUniform3fvEXT);
416 COREGL_OVERRIDE(fastpath_, glProgramUniform4fvEXT);
417 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fvEXT);
418 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fvEXT);
419 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fvEXT);
421 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
422 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
424 COREGL_OVERRIDE(fastpath_, glBindFramebufferOES);
425 COREGL_OVERRIDE(fastpath_, glBindRenderbufferOES);
426 COREGL_OVERRIDE(fastpath_, glClearBufferfi);
427 COREGL_OVERRIDE(fastpath_, glClearBufferfv);
428 COREGL_OVERRIDE(fastpath_, glClearBufferiv);
429 COREGL_OVERRIDE(fastpath_, glClearBufferuiv);
430 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffersOES);
431 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffersOES);
432 COREGL_OVERRIDE(fastpath_, glDepthRangefOES);
433 COREGL_OVERRIDE(fastpath_, glDepthRangexOES);
434 COREGL_OVERRIDE(fastpath_, glFramebufferParameteri);
435 COREGL_OVERRIDE(fastpath_, glGetFramebufferParameteriv);
436 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbufferOES);
437 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DOES);
438 COREGL_OVERRIDE(fastpath_, glGenFramebuffersOES);
439 COREGL_OVERRIDE(fastpath_, glGenRenderbuffersOES);
440 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameterivOES);
441 COREGL_OVERRIDE(fastpath_, glGetQueryObjecti64vEXT);
442 COREGL_OVERRIDE(fastpath_, glGetQueryObjectivEXT);
443 COREGL_OVERRIDE(fastpath_, glGetQueryObjectui64vEXT);
444 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuivEXT);
445 COREGL_OVERRIDE(fastpath_, glGetQueryivEXT);
446 COREGL_OVERRIDE(fastpath_, glBeginQueryEXT);
447 COREGL_OVERRIDE(fastpath_, glDeleteQueriesEXT);
448 COREGL_OVERRIDE(fastpath_, glGenQueriesEXT);
449 COREGL_OVERRIDE(fastpath_, glIsFramebufferOES);
450 COREGL_OVERRIDE(fastpath_, glIsQueryEXT);
451 COREGL_OVERRIDE(fastpath_, glIsRenderbufferOES);
452 COREGL_OVERRIDE(fastpath_, glBlendEquationOES);
453 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparateOES);
454 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparateOES);
455 COREGL_OVERRIDE(fastpath_, glPolygonOffsetxOES);
456 COREGL_OVERRIDE(fastpath_, glLineWidthxOES);
457 COREGL_OVERRIDE(fastpath_, glSampleCoveragexOES);
458 COREGL_OVERRIDE(fastpath_, glQueryCounterEXT);
459 COREGL_OVERRIDE(fastpath_, glBindVertexArrayOES);
460 COREGL_OVERRIDE(fastpath_, glDeleteVertexArraysOES);
461 COREGL_OVERRIDE(fastpath_, glGenVertexArraysOES);
462 COREGL_OVERRIDE(fastpath_, glIsVertexArrayOES);
463 COREGL_OVERRIDE(fastpath_, glClearDepthfOES );
464 COREGL_OVERRIDE(fastpath_, glClearDepthxOES );
465 /* Start overriding GLES 3.0 */
466 if (driver_gl_version >= COREGL_GLAPI_3) {
467 COREGL_OVERRIDE(fastpath_, glReadBuffer);
469 COREGL_OVERRIDE(fastpath_, glGenQueries);
470 COREGL_OVERRIDE(fastpath_, glDeleteQueries);
471 COREGL_OVERRIDE(fastpath_, glIsQuery);
472 COREGL_OVERRIDE(fastpath_, glBeginQuery);
473 COREGL_OVERRIDE(fastpath_, glGetQueryiv);
474 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
475 COREGL_OVERRIDE(fastpath_, glDrawBuffers);
476 COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
478 COREGL_OVERRIDE(fastpath_, glBindVertexArray);
479 COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
480 COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
481 COREGL_OVERRIDE(fastpath_, glIsVertexArray);
483 COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
485 COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
486 COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
487 COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
488 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
490 COREGL_OVERRIDE(fastpath_, glBindBufferRange);
491 COREGL_OVERRIDE(fastpath_, glBindBufferBase);
492 COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
493 COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
494 COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
495 COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
496 COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
497 COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
498 COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
499 COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
500 COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
501 COREGL_OVERRIDE(fastpath_, glGetStringi);
502 COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
503 COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
504 COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
505 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
506 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
507 COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
508 COREGL_OVERRIDE(fastpath_, glGetInteger64v);
509 COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
510 COREGL_OVERRIDE(fastpath_, glGenSamplers);
511 COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
512 COREGL_OVERRIDE(fastpath_, glIsSampler);
513 COREGL_OVERRIDE(fastpath_, glBindSampler);
514 COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
515 COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
516 COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
517 COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
518 COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
519 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
520 COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
521 COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
522 COREGL_OVERRIDE(fastpath_, glProgramBinary);
523 COREGL_OVERRIDE(fastpath_, glProgramParameteri);
526 if (driver_gl_version >= COREGL_GLAPI_31) {
527 COREGL_OVERRIDE(fastpath_, glCreateShaderProgramv);
528 COREGL_OVERRIDE(fastpath_, glGenProgramPipelines);
529 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineiv);
530 COREGL_OVERRIDE(fastpath_, glBindProgramPipeline);
531 COREGL_OVERRIDE(fastpath_, glDeleteProgramPipelines);
532 COREGL_OVERRIDE(fastpath_, glIsProgramPipeline);
533 COREGL_OVERRIDE(fastpath_, glValidateProgramPipeline);
534 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineInfoLog);
535 COREGL_OVERRIDE(fastpath_, glDispatchCompute);
536 COREGL_OVERRIDE(fastpath_, glDispatchComputeIndirect);
537 COREGL_OVERRIDE(fastpath_, glGetProgramInterfaceiv);
538 COREGL_OVERRIDE(fastpath_, glGetProgramResourceIndex);
539 COREGL_OVERRIDE(fastpath_, glGetProgramResourceName);
540 COREGL_OVERRIDE(fastpath_, glGetProgramResourceiv);
541 COREGL_OVERRIDE(fastpath_, glGetProgramResourceLocation);
542 COREGL_OVERRIDE(fastpath_, glUseProgramStages);
543 COREGL_OVERRIDE(fastpath_, glActiveShaderProgram);
544 COREGL_OVERRIDE(fastpath_, glProgramUniform1iv);
545 COREGL_OVERRIDE(fastpath_, glProgramUniform2iv);
546 COREGL_OVERRIDE(fastpath_, glProgramUniform3iv);
547 COREGL_OVERRIDE(fastpath_, glProgramUniform4iv);
548 COREGL_OVERRIDE(fastpath_, glProgramUniform1fv);
549 COREGL_OVERRIDE(fastpath_, glProgramUniform2fv);
550 COREGL_OVERRIDE(fastpath_, glProgramUniform3fv);
551 COREGL_OVERRIDE(fastpath_, glProgramUniform4fv);
552 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fv);
553 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fv);
554 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fv);
555 COREGL_OVERRIDE(fastpath_, glProgramUniform1i);
556 COREGL_OVERRIDE(fastpath_, glProgramUniform2i);
557 COREGL_OVERRIDE(fastpath_, glProgramUniform3i);
558 COREGL_OVERRIDE(fastpath_, glProgramUniform4i);
559 COREGL_OVERRIDE(fastpath_, glProgramUniform1f);
560 COREGL_OVERRIDE(fastpath_, glProgramUniform2f);
561 COREGL_OVERRIDE(fastpath_, glProgramUniform3f);
562 COREGL_OVERRIDE(fastpath_, glProgramUniform4f);
563 COREGL_OVERRIDE(fastpath_, glProgramUniform1uiv);
564 COREGL_OVERRIDE(fastpath_, glProgramUniform2uiv);
565 COREGL_OVERRIDE(fastpath_, glProgramUniform3uiv);
566 COREGL_OVERRIDE(fastpath_, glProgramUniform4uiv);
567 COREGL_OVERRIDE(fastpath_, glProgramUniform1ui);
568 COREGL_OVERRIDE(fastpath_, glProgramUniform2ui);
569 COREGL_OVERRIDE(fastpath_, glProgramUniform3ui);
570 COREGL_OVERRIDE(fastpath_, glProgramUniform4ui);
571 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x3fv);
572 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x2fv);
573 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x2fv);
574 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x4fv);
575 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x4fv);
576 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x3fv);
577 COREGL_OVERRIDE(fastpath_, glBindImageTexture);
578 COREGL_OVERRIDE(fastpath_, glGetBooleani_v);
579 COREGL_OVERRIDE(fastpath_, glMemoryBarrier);
580 COREGL_OVERRIDE(fastpath_, glMemoryBarrierByRegion);
581 COREGL_OVERRIDE(fastpath_, glTexStorage2DMultisample);
582 COREGL_OVERRIDE(fastpath_, glGetMultisamplefv);
583 COREGL_OVERRIDE(fastpath_, glSampleMaski);
584 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameteriv);
585 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameterfv);
586 COREGL_OVERRIDE(fastpath_, glBindVertexBuffer);
587 COREGL_OVERRIDE(fastpath_, glVertexAttribFormat);
588 COREGL_OVERRIDE(fastpath_, glVertexAttribIFormat);
589 COREGL_OVERRIDE(fastpath_, glVertexAttribBinding);
590 COREGL_OVERRIDE(fastpath_, glVertexBindingDivisor);
593 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
599 static inline GL_Object_Hash_Base *
600 _lock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
603 case GL_OBJECT_TYPE_QUERY:
604 return &ostate->query;
605 case GL_OBJECT_TYPE_TEXTURE:
606 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
607 return &ostate->shared->texture;
608 case GL_OBJECT_TYPE_BUFFER:
609 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
610 return &ostate->shared->buffer;
611 case GL_OBJECT_TYPE_FRAMEBUFFER:
612 return &ostate->framebuffer;
613 case GL_OBJECT_TYPE_RENDERBUFFER:
614 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
615 return &ostate->shared->renderbuffer;
616 case GL_OBJECT_TYPE_PROGRAM:
617 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
618 return &ostate->shared->program;
619 case GL_OBJECT_TYPE_VERTEXARRAY:
620 return &ostate->vertexarray;
621 case GL_OBJECT_TYPE_SAMPLER:
622 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
623 return &ostate->shared->sampler;
624 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
625 return &ostate->transformfeedback;
626 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
627 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
628 return &ostate->shared->programpipeline;
635 _unlock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
638 case GL_OBJECT_TYPE_TEXTURE:
639 case GL_OBJECT_TYPE_BUFFER:
640 case GL_OBJECT_TYPE_RENDERBUFFER:
641 case GL_OBJECT_TYPE_PROGRAM:
642 case GL_OBJECT_TYPE_SAMPLER:
643 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
644 AST(mutex_unlock(&ostate->shared->access_mutex) == 1);
650 static inline GL_Object_Hash_Base *
651 _lock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
654 case GL_OBJECT_TYPE_QUERY:
655 return &ostate->query_real;
656 case GL_OBJECT_TYPE_TEXTURE:
657 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
658 return &ostate->shared->texture_real;
659 case GL_OBJECT_TYPE_BUFFER:
660 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
661 return &ostate->shared->buffer_real;
662 case GL_OBJECT_TYPE_FRAMEBUFFER:
663 return &ostate->framebuffer_real;
664 case GL_OBJECT_TYPE_RENDERBUFFER:
665 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
666 return &ostate->shared->renderbuffer_real;
667 case GL_OBJECT_TYPE_PROGRAM:
668 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
669 return &ostate->shared->program_real;
670 case GL_OBJECT_TYPE_VERTEXARRAY:
671 return &ostate->vertexarray_real;
672 case GL_OBJECT_TYPE_SAMPLER:
673 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
674 return &ostate->shared->sampler_real;
675 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
676 return &ostate->transformfeedback_real;
677 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
678 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
679 return &ostate->shared->programpipeline_real;
686 _unlock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
689 case GL_OBJECT_TYPE_TEXTURE:
690 case GL_OBJECT_TYPE_BUFFER:
691 case GL_OBJECT_TYPE_RENDERBUFFER:
692 case GL_OBJECT_TYPE_PROGRAM:
693 case GL_OBJECT_TYPE_SAMPLER:
694 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
695 AST(mutex_unlock(&ostate->shared->real_access_mutex) == 1);
703 fastpath_add_context_state_to_list(const void *option, const int option_len,
704 GLContextState *cstate, Mutex *mtx)
708 GLContext_List *current = NULL;
709 GLContext_List *newitm = NULL;
711 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
715 tid = get_current_thread();
717 current = glctx_list;
718 while (current != NULL) {
719 if (current->option_len == option_len &&
720 memcmp(current->option, option, option_len) == 0 &&
721 current->thread_id == tid) {
722 AST(current->cstate == cstate);
725 current = current->next;
728 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
729 if (newitm == NULL) {
730 COREGL_ERR("Failed to create context list.\n");
734 newitm->cstate = cstate;
735 newitm->thread_id = tid;
736 newitm->option_len = option_len;
737 newitm->option = (void *)malloc(option_len);
738 memcpy(newitm->option, option, option_len);
740 if (glctx_list != NULL)
741 newitm->next = glctx_list;
750 if (newitm != NULL) {
754 if (cstate != NULL) {
759 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
765 fastpath_get_context_state_from_list(const void *option, const int option_len,
768 GLContextState *ret = NULL;
769 GLContext_List *current = NULL;
772 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
774 tid = get_current_thread();
776 current = glctx_list;
777 while (current != NULL) {
778 if (current->option_len == option_len &&
779 memcmp(current->option, option, option_len) == 0 &&
780 current->thread_id == tid) {
781 ret = current->cstate;
784 current = current->next;
789 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
794 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
797 GLContext_List *olditm = NULL;
798 GLContext_List *current = NULL;
800 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
804 current = glctx_list;
806 while (current != NULL) {
807 if (current->cstate == cstate) {
808 GLContext_List *nextitm = NULL;
809 if (olditm != NULL) {
810 olditm->next = current->next;
811 nextitm = olditm->next;
813 glctx_list = current->next;
814 nextitm = glctx_list;
816 if (current->option != NULL) {
817 AST(current->option_len > 0);
818 free(current->option);
819 current->option = NULL;
820 current->option_len = 0;
828 current = current->next;
833 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
839 #define HASH_INIT(hash_base) \
840 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
841 hash_base.hash_size = GL_OBJECT_HASH_BASE;
844 fastpath_ostate_init(GL_Object_State *ostate)
846 HASH_INIT(ostate->query);
847 HASH_INIT(ostate->framebuffer);
848 HASH_INIT(ostate->vertexarray);
849 HASH_INIT(ostate->transformfeedback);
851 HASH_INIT(ostate->query_real);
852 HASH_INIT(ostate->framebuffer_real);
853 HASH_INIT(ostate->vertexarray_real);
854 HASH_INIT(ostate->transformfeedback_real);
858 fastpath_sostate_init(GL_Shared_Object_State *sostate)
860 mutex_init(&sostate->access_mutex);
862 HASH_INIT(sostate->texture);
863 HASH_INIT(sostate->buffer);
864 HASH_INIT(sostate->renderbuffer);
865 HASH_INIT(sostate->program);
866 HASH_INIT(sostate->sampler);
867 HASH_INIT(sostate->programpipeline);
869 HASH_INIT(sostate->texture_real);
870 HASH_INIT(sostate->buffer_real);
871 HASH_INIT(sostate->renderbuffer_real);
872 HASH_INIT(sostate->program_real);
873 HASH_INIT(sostate->sampler_real);
874 HASH_INIT(sostate->programpipeline_real);
881 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
883 int array_idx = data->hash_key & (hash_base->hash_size - 1);
884 if (hash_base->hash_field[array_idx] == NULL) {
885 hash_base->hash_field[array_idx] = data;
887 GL_Object_Hash *current = hash_base->hash_field[array_idx];
888 while (current->next) {
889 AST(current->hash_key != data->hash_key);
890 current = current->next;
892 current->next = data;
895 hash_base->item_size++;
899 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
902 int array_idx = hash & (hash_base->hash_size - 1);
904 GL_Object_Hash *current = hash_base->hash_field[array_idx];
905 GL_Object_Hash *prev = NULL;
908 if (current->hash_key == hash) {
910 prev->next = current->next;
912 hash_base->hash_field[array_idx] = current->next;
913 hash_base->item_size--;
918 current = current->next;
925 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
927 if (hash_base->item_size == 0) return;
929 for (int i = 0; i < hash_base->hash_size; i++) {
930 if (hash_base->hash_field[i] != NULL) {
931 GL_Object_Hash *current = hash_base->hash_field[i];
933 while (current != NULL) {
934 GL_Object_Hash *current_next = current->next;
936 if (free_data == 1 && current->item != NULL) {
941 hash_base->item_size--;
942 current = current_next;
950 #define HASH_DEINIT(hash_base, free_data) \
951 _free_hash_list(&hash_base, free_data); \
952 free(hash_base.hash_field); \
953 hash_base.hash_size = 0;
956 fastpath_ostate_deinit(GL_Object_State *ostate)
958 HASH_DEINIT(ostate->query, 1);
959 HASH_DEINIT(ostate->framebuffer, 1);
960 HASH_DEINIT(ostate->vertexarray, 1);
961 HASH_DEINIT(ostate->transformfeedback, 1);
963 HASH_DEINIT(ostate->query_real, 0);
964 HASH_DEINIT(ostate->framebuffer_real, 0);
965 HASH_DEINIT(ostate->vertexarray_real, 0);
966 HASH_DEINIT(ostate->transformfeedback_real, 0);
970 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
972 HASH_DEINIT(sostate->texture, 1);
973 HASH_DEINIT(sostate->buffer, 1);
974 HASH_DEINIT(sostate->renderbuffer, 1);
975 HASH_DEINIT(sostate->program, 1);
976 HASH_DEINIT(sostate->sampler, 1);
977 HASH_DEINIT(sostate->programpipeline, 1);
979 HASH_DEINIT(sostate->texture_real, 0);
980 HASH_DEINIT(sostate->buffer_real, 0);
981 HASH_DEINIT(sostate->renderbuffer_real, 0);
982 HASH_DEINIT(sostate->program_real, 0);
983 HASH_DEINIT(sostate->sampler_real, 0);
985 HASH_DEINIT(sostate->programpipeline_real, 0);
992 #define FIND_HASH(hash_base, key, ret) \
994 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
997 if (fh_current->hash_key == (key)) \
1002 fh_current = fh_current->next; \
1007 _ostate_hash_check(GL_Object_Hash_Base *hash_base)
1009 if (hash_base->item_size + 1 < hash_base->hash_size)
1012 int oldsize = hash_base->hash_size;
1013 GL_Object_Hash **oldfield = hash_base->hash_field;
1015 hash_base->hash_size = oldsize << 1;
1016 hash_base->hash_field = (GL_Object_Hash **)calloc(1,
1017 sizeof(GL_Object_Hash *) * hash_base->hash_size);
1018 AST(hash_base->hash_field != NULL);
1020 for (int i = 0; i < oldsize; i++) {
1021 if (oldfield[i] != NULL) {
1022 GL_Object_Hash *current = oldfield[i];
1024 while (current != NULL) {
1025 GL_Object_Hash *current_next = current->next;
1026 _add_hash(hash_base, current);
1027 hash_base->item_size--;
1028 current = current_next;
1037 fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type,
1040 GLuint ret = _COREGL_INT_INIT_VALUE;
1042 GL_Object_Hash_Base *hash_base = NULL;
1043 GL_Object_Hash_Base *hash_base_real = NULL;
1044 int newid = _COREGL_INT_INIT_VALUE;
1046 hash_base = _lock_gl_object_hash(ostate, type);
1047 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1049 newid = hash_base->last_id + 1;
1050 if (newid >= hash_base->hash_size) {
1051 hash_base->is_looped = 1;
1053 hash_base->last_id = 1;
1056 if (hash_base->is_looped != 0) {
1058 int findingid = newid;
1060 for (i = 0; i < hash_base->hash_size; i++) {
1061 GL_Object_Hash *exist_hash = NULL;
1062 FIND_HASH(hash_base, findingid, exist_hash);
1063 if (exist_hash == NULL) {
1068 if (findingid >= hash_base->hash_size) findingid = 1;
1072 hash_base->last_id = newid;
1075 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
1078 newobj->id = (int)type + newid;
1079 newobj->real_id = real_name;
1080 newobj->ref_count = 1;
1083 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1,
1084 sizeof(GL_Object_Hash));
1085 if (newobj_hash == NULL) {
1089 newobj_hash->item = newobj;
1090 newobj_hash->hash_key = newid;
1091 _add_hash(hash_base, newobj_hash);
1093 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1,
1094 sizeof(GL_Object_Hash));
1095 if (newobj_hash_real == NULL) {
1100 newobj_hash_real->item = newobj;
1101 newobj_hash_real->hash_key = real_name;
1102 _add_hash(hash_base_real, newobj_hash_real);
1107 _ostate_hash_check(hash_base);
1108 _ostate_hash_check(hash_base_real);
1113 _unlock_gl_object_hash(ostate, type);
1114 _unlock_gl_object_hash_real(ostate, type);
1118 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
1119 if (((int)(hash)) < 0) { ret = 0; goto finish; } \
1121 GL_Object_Hash *object_hash = NULL; \
1122 FIND_HASH((hash_base), (int)(hash), object_hash); \
1123 if (object_hash == NULL) { ret = 0; goto finish; } \
1124 (object) = object_hash->item; \
1125 if ((object) == NULL) { ret = 0; goto finish; } \
1129 fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type,
1132 GLuint ret = _COREGL_INT_INIT_VALUE;
1134 GL_Object_Hash_Base *hash_base = NULL;
1135 GL_Object_Hash_Base *hash_base_real = NULL;
1136 GL_Object *object = NULL;
1138 hash_base = _lock_gl_object_hash(ostate, type);
1139 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1141 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1143 object->ref_count--;
1145 if (object->ref_count <= 0) {
1146 GL_Object_Hash *object_hash = NULL;
1148 FIND_HASH(hash_base, object->id - (int)type, object_hash);
1149 AST(object_hash != NULL);
1150 _remove_hash(hash_base, object->id - (int)type);
1154 FIND_HASH(hash_base_real, object->real_id, object_hash);
1155 AST(object_hash != NULL);
1156 _remove_hash(hash_base_real, object->real_id);
1168 _unlock_gl_object_hash(ostate, type);
1169 _unlock_gl_object_hash_real(ostate, type);
1174 fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type,
1177 GLuint ret = _COREGL_INT_INIT_VALUE;
1179 GL_Object_Hash_Base *hash_base = NULL;
1180 GL_Object *object = NULL;
1182 hash_base = _lock_gl_object_hash(ostate, type);
1184 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1186 ret = object->real_id;
1190 _unlock_gl_object_hash(ostate, type);
1194 /* Check if the context's state contains object of a given type */
1196 fastpath_ostate_has_object_type(GL_Object_State *ostate, GL_Object_Type type)
1198 GLuint ret = _COREGL_INT_INIT_VALUE;
1200 GL_Object_Hash_Base *hash_base = NULL;
1201 GL_Object *object = NULL;
1202 hash_base = _lock_gl_object_hash(ostate, type);
1204 if (hash_base->hash_field == 0) {
1209 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, 1, object);
1211 ret = object->real_id;
1215 _unlock_gl_object_hash(ostate, type);
1221 fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1222 GLuint glue_name, GLvoid *tag)
1224 GLint ret = _COREGL_INT_INIT_VALUE;
1226 GL_Object_Hash_Base *hash_base = NULL;
1227 GL_Object *object = NULL;
1228 int hash = _COREGL_INT_INIT_VALUE;
1230 hash_base = _lock_gl_object_hash(ostate, type);
1232 hash = glue_name - (int)type;
1234 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
1236 AST(object->tag == NULL);
1242 _unlock_gl_object_hash(ostate, type);
1247 fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1252 GL_Object_Hash_Base *hash_base = NULL;
1253 GL_Object *object = NULL;
1255 hash_base = _lock_gl_object_hash(ostate, type);
1257 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1263 _unlock_gl_object_hash(ostate, type);
1268 fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type,
1271 GLuint ret = _COREGL_INT_INIT_VALUE;
1273 GL_Object_Hash_Base *hash_base_real = NULL;
1274 GL_Object *object = NULL;
1276 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1278 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
1284 _unlock_gl_object_hash_real(ostate, type);
1289 fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type,
1292 GLint ret = _COREGL_INT_INIT_VALUE;
1294 GL_Object_Hash_Base *hash_base = NULL;
1295 GL_Object *object = NULL;
1297 hash_base = _lock_gl_object_hash(ostate, type);
1299 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1301 object->ref_count++;
1306 _unlock_gl_object_hash(ostate, type);
1311 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
1313 static struct timeval tv_last = { 0, 0 };
1315 if (unlikely(trace_state_flag != 1)) return;
1317 if (!force_output) {
1318 struct timeval tv_now = { 0, 0 };
1319 AST(gettimeofday(&tv_now, NULL) == 0);
1320 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC) {
1327 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1328 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n",
1330 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1332 #define PRINTF_CHAR_GLenum "0x%8X"
1333 #define PRINTF_CHAR_GLboolean "%10d"
1334 #define PRINTF_CHAR_GLint "%10d"
1335 #define PRINTF_CHAR_GLsizei "%10u"
1336 #define PRINTF_CHAR_GLuint "%10u"
1337 #define PRINTF_CHAR_GLuintmask "0x%8X"
1338 #define PRINTF_CHAR_GLintptr "%10ld"
1339 #define PRINTF_CHAR_GLsizeiptr "%10ld"
1341 #define PRINTF_CHAR_GLclampf "%10.6f"
1342 #define PRINTF_CHAR_GLfloat "%10.6f"
1344 #define PRINTF_CHAR_GLvoidptr "%10p"
1346 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1348 #define _COREGL_START_API(version) api_gl_version = version;
1349 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1350 #define INITIAL_CTX initial_ctx
1351 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1353 TYPE valuedata[SIZE]; \
1354 TYPE *value = NULL; \
1355 if(api_gl_version <= driver_gl_version) { \
1356 value = valuedata; GET_STMT; value = valuedata; \
1357 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1358 for (int i = 0; i < SIZE; i++) \
1362 TRACE("\n %-30.30s ", "");\
1366 if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
1367 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1368 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1369 if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
1371 TRACE(" \E[40;37;1m)\E[0m\n"); \
1374 # include "coregl_fastpath_state.h"
1377 #undef _COREGL_START_API
1378 #undef _COREGL_END_API
1380 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1390 fastpath_init_context_states(GLGlueContext *ctx)
1394 AST(mutex_lock(&init_context_mutex) == 1);
1397 COREGL_ERR("Context NULL\n");
1402 AST(ctx->initialized == 0);
1403 AST(ctx->ostate.shared != NULL);
1405 if (initial_ctx == NULL) {
1406 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1407 AST(initial_ctx != NULL);
1409 //#define FORCE_DEFAULT_VALUE
1410 #define _COREGL_START_API(version) api_gl_version = version;
1411 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1412 #ifdef FORCE_DEFAULT_VALUE
1413 # define INITIAL_CTX initial_ctx
1414 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1418 TYPE valuedata[SIZE]; \
1419 TYPE *value = NULL; \
1420 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1421 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1422 if(api_gl_version <= driver_gl_version) { \
1423 value = valuedata; DEFAULT_STMT; value = valuedata; \
1424 for (i = 0; i < SIZE; i++) \
1426 if (*((char *)(&value[i])) == 0xcc) \
1428 memset(&value[i], 0xaa, sizeof(TYPE)); \
1429 value = valuedata; DEFAULT_STMT; value = valuedata; \
1430 if (*((char *)(&value[i])) == 0xaa) \
1432 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1436 initial_ctx->NAME[i] = value[i]; \
1441 # include "coregl_fastpath_state.h"
1445 # define INITIAL_CTX initial_ctx
1446 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1447 if (try_step == 1) \
1449 value = valuedata; DEFAULT_STMT; value = valuedata; \
1453 value = valuedata; FALLBACK_STMT; value = valuedata; \
1456 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1461 TYPE valuedata[SIZE]; \
1462 TYPE *value = NULL; \
1463 _sym_glGetError(); \
1464 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1465 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1466 if(api_gl_version <= driver_gl_version) { \
1469 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1470 if (_sym_glGetError() == GL_INVALID_ENUM) \
1472 initial_ctx->NAME##_used = 0; \
1473 value = valuedata; DEFAULT_STMT; value = valuedata; \
1476 initial_ctx->NAME##_used = 1; \
1477 for (i = 0; i < SIZE; i++) \
1479 if (*((char *)(&value[i])) == 0xcc) \
1481 memset(&value[i], 0xaa, sizeof(TYPE)); \
1482 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1483 if (*((char *)(&value[i])) == 0xaa) \
1486 if (try_step == 2) \
1488 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1493 initial_ctx->NAME[i] = value[i]; \
1495 if (try_step != 2) \
1497 value = valuedata; DEFAULT_STMT; value = valuedata; \
1498 for (i = 0; i < SIZE; i++) \
1500 if (initial_ctx->NAME[i] != value[i]) \
1502 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]); \
1507 while (try_step == 2); \
1511 # include "coregl_fastpath_state.h"
1512 # undef SET_GLUE_VALUE
1516 # undef _COREGL_END_API
1517 # undef _COREGL_START_API
1519 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS) {
1520 COREGL_WRN("\E[40;31;1mNumber of vertex attrib is too big! (%d-%d)\E[0m\n",
1521 MAX_VERTEX_ATTRIBS, initial_ctx->gl_num_vertex_attribs[0]);
1523 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS) {
1524 COREGL_WRN("\E[40;31;1mNumber of texture unit is too big! (%d-%d)\E[0m\n",
1525 MAX_TEXTURE_UNITS, initial_ctx->gl_num_tex_units[0]);
1527 if (initial_ctx->gl_num_transform_feedback_separate_attribs[0] >
1528 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS) {
1529 COREGL_WRN("\E[40;31;1mNumber of transform feedback separate attrib is too big! (%d-%d)\E[0m\n",
1530 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
1531 initial_ctx->gl_num_transform_feedback_separate_attribs[0]);
1533 if (initial_ctx->gl_num_uniform_buffer_bindings[0] >
1534 MAX_UNIFORM_BUFFER_BINDINGS) {
1535 COREGL_WRN("\E[40;31;1mNumber of uniform buffer binding is too big! (%d-%d)\E[0m\n",
1536 MAX_UNIFORM_BUFFER_BINDINGS, initial_ctx->gl_num_uniform_buffer_bindings[0]);
1542 #define _COREGL_START_API(version) api_gl_version = version;
1543 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1544 #define INITIAL_CTX initial_ctx
1545 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1548 ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE)); \
1549 if(api_gl_version <= driver_gl_version) { \
1550 for (i = 0; i < SIZE; i++) \
1552 ctx->NAME[i] = initial_ctx->NAME[i]; \
1553 ctx->NAME##_used = initial_ctx->NAME##_used; \
1558 # include "coregl_fastpath_state.h"
1561 #undef _COREGL_START_API
1562 #undef _COREGL_END_API
1565 ctx->initialized = 1;
1570 AST(mutex_unlock(&init_context_mutex) == 1);
1575 #ifdef COREGL_USE_MODULE_TRACEPATH
1576 extern void *tracepath_api_trace_begin(const char *name, void *hint,
1577 int trace_total_time);
1578 extern void *tracepath_api_trace_end(const char *name, void *hint,
1579 int trace_total_time);
1582 #define CHECK_GL_ERROR(func) \
1585 int err = _orig_fastpath_glGetError(); \
1586 if (err != GL_NO_ERROR) \
1588 COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1594 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1597 unsigned char flag = 0;
1600 if (debug_nofp == 1) {
1605 // Return if they're the same
1606 if (oldctx == newctx) {
1611 #define STATE_COMPARE(state) \
1612 if ((oldctx->state) != (newctx->state))
1614 #define STATES_COMPARE(state_ptr, bytes) \
1615 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1618 #ifdef COREGL_USE_MODULE_TRACEPATH
1619 static void *trace_hint_glfinish = NULL;
1620 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)",
1621 trace_hint_glfinish, 0);
1622 #endif // COREGL_USE_MODULE_TRACEPATH
1625 int err = _orig_fastpath_glGetError();
1626 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1627 oldctx->gl_error = err;
1630 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1632 #ifdef COREGL_USE_MODULE_TRACEPATH
1633 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1634 #endif // COREGL_USE_MODULE_TRACEPATH
1637 #ifdef COREGL_USE_MODULE_TRACEPATH
1638 static void *trace_hint_vertex_attrib = NULL;
1639 trace_hint_vertex_attrib =
1640 tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)",
1641 trace_hint_vertex_attrib, 0);
1642 #endif // COREGL_USE_MODULE_TRACEPATH
1644 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1646 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++) {
1647 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i]) {
1648 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1649 newctx->gl_vertex_array_buf_id[i]))
1651 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1654 STATE_COMPARE(gl_vertex_array_divisor[i]) {
1655 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribDivisor(i,
1656 newctx->gl_vertex_array_divisor[i]))
1659 if (newctx->gl_vertex_array_size[i] != 0) {
1660 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1661 newctx->gl_vertex_array_size[i],
1662 newctx->gl_vertex_array_type[i],
1663 newctx->gl_vertex_array_normalized[i],
1664 newctx->gl_vertex_array_stride[i],
1665 newctx->gl_vertex_array_pointer[i]))
1667 if (newctx->gl_vertex_array_integer[0] == GL_TRUE) {
1668 if (newctx->gl_vertex_array_type[0] == GL_UNSIGNED_INT) {
1669 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4uiv(i,
1670 &newctx->gl_vertex_attrib_value_unsigned_integer[4 * i]))
1672 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4iv(i,
1673 &newctx->gl_vertex_attrib_value_integer[4 * i]))
1676 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i,
1677 &newctx->gl_vertex_attrib_value[4 * i]))
1681 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE) {
1682 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1684 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1690 #ifdef COREGL_USE_MODULE_TRACEPATH
1691 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)",
1692 trace_hint_vertex_attrib, 0);
1693 #endif // COREGL_USE_MODULE_TRACEPATH
1696 #ifdef COREGL_USE_MODULE_TRACEPATH
1697 static void *trace_hint_bindbuffers = NULL;
1698 trace_hint_bindbuffers =
1699 tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)",
1700 trace_hint_bindbuffers, 0);
1701 #endif // COREGL_USE_MODULE_TRACEPATH
1703 //------------------//
1705 flag = oldctx->_bind_flag1 | newctx->_bind_flag1;
1707 STATE_COMPARE(gl_array_buffer_binding[0]) {
1708 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1709 newctx->gl_array_buffer_binding[0]))
1711 STATE_COMPARE(gl_element_array_buffer_binding[0]) {
1712 STATE_COMPARE(gl_vertex_array_binding[0]) {
1713 CHECK_GL_ERROR(_orig_fastpath_glBindVertexArray(
1714 newctx->gl_vertex_array_binding[0]))
1716 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1717 newctx->gl_element_array_buffer_binding[0]))
1720 if (newctx->gl_framebuffer_binding_read_used == 1) {
1721 STATE_COMPARE(gl_framebuffer_binding_read[0]) {
1722 if (driver_gl_version >= 2)
1723 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER,
1724 newctx->gl_framebuffer_binding_read[0]))
1726 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_READ_FRAMEBUFFER,
1727 newctx->gl_framebuffer_binding_read[0]))
1729 STATE_COMPARE(gl_framebuffer_binding_draw[0]) {
1730 if (driver_gl_version >= 2)
1731 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1732 newctx->gl_framebuffer_binding_draw[0]))
1734 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_DRAW_FRAMEBUFFER,
1735 newctx->gl_framebuffer_binding_draw[0]))
1738 STATE_COMPARE(gl_framebuffer_binding[0]) {
1739 if (driver_gl_version >= 2)
1740 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER,
1741 newctx->gl_framebuffer_binding[0]))
1743 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_FRAMEBUFFER,
1744 newctx->gl_framebuffer_binding[0]))
1747 STATE_COMPARE(gl_renderbuffer_binding[0]) {
1748 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER,
1749 newctx->gl_renderbuffer_binding[0]))
1753 //------------------//
1755 flag = oldctx->_bind_flag2 | newctx->_bind_flag2;
1757 STATE_COMPARE(gl_copy_read_buffer_binding[0]) {
1758 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_READ_BUFFER,
1759 newctx->gl_copy_read_buffer_binding[0]))
1761 STATE_COMPARE(gl_copy_write_buffer_binding[0]) {
1762 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_WRITE_BUFFER,
1763 newctx->gl_copy_write_buffer_binding[0]))
1765 STATE_COMPARE(gl_pixel_pack_buffer_binding[0]) {
1766 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_PACK_BUFFER,
1767 newctx->gl_pixel_pack_buffer_binding[0]))
1769 STATE_COMPARE(gl_pixel_unpack_buffer_binding[0]) {
1770 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
1771 newctx->gl_pixel_unpack_buffer_binding[0]))
1773 STATE_COMPARE(gl_transform_feedback_buffer_binding[0]) {
1774 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER,
1775 newctx->gl_transform_feedback_buffer_binding[0]))
1777 STATE_COMPARE(gl_uniform_buffer_binding[0]) {
1778 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_UNIFORM_BUFFER,
1779 newctx->gl_uniform_buffer_binding[0]))
1782 #ifdef COREGL_USE_MODULE_TRACEPATH
1783 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)",
1784 trace_hint_bindbuffers, 0);
1785 #endif // COREGL_USE_MODULE_TRACEPATH
1788 //------------------//
1791 #ifdef COREGL_USE_MODULE_TRACEPATH
1792 static void *trace_hint_enable_states = NULL;
1793 trace_hint_enable_states =
1794 tracepath_api_trace_begin("eglMakeCurrent(FP enable states)",
1795 trace_hint_enable_states, 0);
1796 #endif // COREGL_USE_MODULE_TRACEPATH
1798 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1800 STATE_COMPARE(gl_blend[0]) {
1801 if (newctx->gl_blend[0]) {
1802 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1804 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1806 STATE_COMPARE(gl_cull_face[0]) {
1807 if (newctx->gl_cull_face[0]) {
1808 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1810 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1812 STATE_COMPARE(gl_depth_test[0]) {
1813 if (newctx->gl_depth_test[0]) {
1814 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1816 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1818 STATE_COMPARE(gl_dither[0]) {
1819 if (newctx->gl_dither[0]) {
1820 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1822 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1827 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1829 STATE_COMPARE(gl_polygon_offset_fill[0]) {
1830 if (newctx->gl_polygon_offset_fill[0]) {
1831 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1833 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1835 STATE_COMPARE(gl_sample_alpha_to_coverage[0]) {
1836 if (newctx->gl_sample_alpha_to_coverage[0]) {
1837 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1839 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1841 STATE_COMPARE(gl_sample_coverage[0]) {
1842 if (newctx->gl_sample_coverage[0]) {
1843 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1845 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1847 STATE_COMPARE(gl_scissor_test[0]) {
1848 if (newctx->gl_scissor_test[0]) {
1849 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1851 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1853 STATE_COMPARE(gl_stencil_test[0]) {
1854 if (newctx->gl_stencil_test[0]) {
1855 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1857 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1862 flag = oldctx->_enable_flag3 | newctx->_enable_flag3;
1864 STATE_COMPARE(gl_primitive_restart_fixed_index[0]) {
1865 if (newctx->gl_primitive_restart_fixed_index[0]) {
1866 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1868 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1870 STATE_COMPARE(gl_rasterizer_discard[0]) {
1871 if (newctx->gl_rasterizer_discard[0]) {
1872 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_RASTERIZER_DISCARD))
1874 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_RASTERIZER_DISCARD))
1878 #ifdef COREGL_USE_MODULE_TRACEPATH
1879 tracepath_api_trace_end("eglMakeCurrent(FP enable states)",
1880 trace_hint_enable_states, 0);
1881 #endif // COREGL_USE_MODULE_TRACEPATH
1883 //------------------//
1885 #ifdef COREGL_USE_MODULE_TRACEPATH
1886 static void *trace_hint_clear_viewport = NULL;
1887 trace_hint_clear_viewport =
1888 tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)",
1889 trace_hint_clear_viewport, 0);
1890 #endif // COREGL_USE_MODULE_TRACEPATH
1892 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1895 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint)) {
1896 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1897 newctx->gl_viewport[1],
1898 newctx->gl_viewport[2],
1899 newctx->gl_viewport[3]))
1902 STATE_COMPARE(gl_current_program[0]) {
1903 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1905 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf)) {
1906 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1907 newctx->gl_color_clear_value[1],
1908 newctx->gl_color_clear_value[2],
1909 newctx->gl_color_clear_value[3]))
1915 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1917 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean)) {
1918 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1919 newctx->gl_color_writemask[1],
1920 newctx->gl_color_writemask[2],
1921 newctx->gl_color_writemask[3]))
1923 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf)) {
1924 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1925 newctx->gl_depth_range[1]))
1927 STATE_COMPARE(gl_depth_clear_value[0]) {
1928 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1930 STATE_COMPARE(gl_depth_func[0]) {
1931 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1933 STATE_COMPARE(gl_depth_writemask[0]) {
1934 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1936 STATE_COMPARE(gl_cull_face_mode[0]) {
1937 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1942 #ifdef COREGL_USE_MODULE_TRACEPATH
1943 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)",
1944 trace_hint_clear_viewport, 0);
1945 #endif // COREGL_USE_MODULE_TRACEPATH
1947 //------------------//
1949 #ifdef COREGL_USE_MODULE_TRACEPATH
1950 static void *trace_hint_bind_textures = NULL;
1951 trace_hint_bind_textures =
1952 tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)",
1953 trace_hint_bind_textures, 0);
1954 #endif // COREGL_USE_MODULE_TRACEPATH
1956 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1959 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++) {
1960 STATE_COMPARE(gl_tex_2d_state[i]) {
1961 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1962 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D,
1963 newctx->gl_tex_2d_state[i]))
1965 STATE_COMPARE(gl_tex_3d_state[i]) {
1966 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1967 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_3D,
1968 newctx->gl_tex_3d_state[i]))
1970 STATE_COMPARE(gl_tex_2d_array_state[i]) {
1971 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1972 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_ARRAY,
1973 newctx->gl_tex_2d_array_state[i]))
1975 STATE_COMPARE(gl_tex_cube_state[i]) {
1976 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1977 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP,
1978 newctx->gl_tex_cube_state[i]))
1980 STATE_COMPARE(gl_tex_external_oes_state[i]) {
1981 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1982 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_EXTERNAL_OES,
1983 newctx->gl_tex_external_oes_state[i]))
1987 // Restore active texture
1988 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1990 STATE_COMPARE(gl_generate_mipmap_hint[0]) {
1991 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT,
1992 newctx->gl_generate_mipmap_hint[0]))
1995 #ifdef COREGL_USE_MODULE_TRACEPATH
1996 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)",
1997 trace_hint_bind_textures, 0);
1998 #endif // COREGL_USE_MODULE_TRACEPATH
2000 //------------------//
2001 #ifdef COREGL_USE_MODULE_TRACEPATH
2002 static void *trace_hint_etc = NULL;
2003 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)",
2005 #endif // COREGL_USE_MODULE_TRACEPATH
2007 flag = oldctx->_blend_flag | newctx->_blend_flag;
2009 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf)) {
2010 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
2011 newctx->gl_blend_color[1],
2012 newctx->gl_blend_color[2],
2013 newctx->gl_blend_color[3]))
2015 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
2016 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
2017 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
2018 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0])) {
2019 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
2020 newctx->gl_blend_dst_rgb[0],
2021 newctx->gl_blend_src_alpha[0],
2022 newctx->gl_blend_dst_alpha[0]))
2024 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
2025 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0])) {
2026 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(
2027 newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
2032 //------------------//
2034 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
2036 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
2037 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
2038 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0])) {
2039 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
2040 newctx->gl_stencil_func[0],
2041 newctx->gl_stencil_ref[0],
2042 newctx->gl_stencil_value_mask[0]))
2044 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
2045 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0])
2047 (oldctx->gl_stencil_pass_depth_pass[0] !=
2048 newctx->gl_stencil_pass_depth_pass[0])) {
2049 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
2050 newctx->gl_stencil_fail[0],
2051 newctx->gl_stencil_pass_depth_fail[0],
2052 newctx->gl_stencil_pass_depth_pass[0]))
2055 STATE_COMPARE(gl_stencil_writemask[0]) {
2056 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT,
2057 newctx->gl_stencil_writemask[0]))
2063 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
2065 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
2066 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
2067 (oldctx->gl_stencil_back_value_mask[0] !=
2068 newctx->gl_stencil_back_value_mask[0])) {
2069 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
2070 newctx->gl_stencil_back_func[0],
2071 newctx->gl_stencil_back_ref[0],
2072 newctx->gl_stencil_back_value_mask[0]))
2074 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
2075 (oldctx->gl_stencil_back_pass_depth_fail[0] !=
2076 newctx->gl_stencil_back_pass_depth_fail[0]) ||
2077 (oldctx->gl_stencil_back_pass_depth_pass[0] !=
2078 newctx->gl_stencil_back_pass_depth_pass[0])) {
2079 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
2080 newctx->gl_stencil_back_fail[0],
2081 newctx->gl_stencil_back_pass_depth_fail[0],
2082 newctx->gl_stencil_back_pass_depth_pass[0]))
2085 STATE_COMPARE(gl_stencil_back_writemask[0]) {
2086 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK,
2087 newctx->gl_stencil_back_writemask[0]))
2089 STATE_COMPARE(gl_stencil_clear_value[0]) {
2090 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
2094 //------------------//
2096 flag = oldctx->_pixel_flag1 | newctx->_pixel_flag1;
2098 STATE_COMPARE(gl_pack_row_length[0]) {
2099 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ROW_LENGTH,
2100 newctx->gl_pack_row_length[0]))
2102 STATE_COMPARE(gl_pack_skip_rows[0]) {
2103 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_ROWS,
2104 newctx->gl_pack_skip_rows[0]))
2106 STATE_COMPARE(gl_pack_skip_pixels[0]) {
2107 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_PIXELS,
2108 newctx->gl_pack_skip_pixels[0]))
2110 STATE_COMPARE(gl_pack_alignment[0]) {
2111 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT,
2112 newctx->gl_pack_alignment[0]))
2117 flag = oldctx->_pixel_flag2 | newctx->_pixel_flag2;
2119 STATE_COMPARE(gl_unpack_row_length[0]) {
2120 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ROW_LENGTH,
2121 newctx->gl_unpack_row_length[0]))
2123 STATE_COMPARE(gl_unpack_skip_rows[0]) {
2124 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_ROWS,
2125 newctx->gl_unpack_skip_rows[0]))
2127 STATE_COMPARE(gl_unpack_skip_pixels[0]) {
2128 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_PIXELS,
2129 newctx->gl_unpack_skip_pixels[0]))
2131 STATE_COMPARE(gl_unpack_alignment[0]) {
2132 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT,
2133 newctx->gl_unpack_alignment[0]))
2135 STATE_COMPARE(gl_unpack_image_height[0]) {
2136 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,
2137 newctx->gl_unpack_image_height[0]))
2139 STATE_COMPARE(gl_unpack_skip_images[0]) {
2140 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_IMAGES,
2141 newctx->gl_unpack_skip_images[0]))
2145 //------------------//
2147 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
2149 STATE_COMPARE(gl_front_face[0]) {
2150 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
2152 STATE_COMPARE(gl_line_width[0]) {
2153 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
2155 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0])
2157 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0])) {
2158 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(
2159 newctx->gl_polygon_offset_factor[0],
2160 newctx->gl_polygon_offset_units[0]))
2162 if ((oldctx->gl_sample_coverage_value[0] !=
2163 newctx->gl_sample_coverage_value[0]) ||
2164 (oldctx->gl_sample_coverage_invert[0] !=
2165 newctx->gl_sample_coverage_invert[0])) {
2166 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(
2167 newctx->gl_sample_coverage_value[0],
2168 newctx->gl_sample_coverage_invert[0]))
2170 STATE_COMPARE(gl_fragment_shader_derivative_hint[0]) {
2171 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES,
2172 newctx->gl_fragment_shader_derivative_hint[0]))
2177 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
2179 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint)) {
2180 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
2181 newctx->gl_scissor_box[1],
2182 newctx->gl_scissor_box[2],
2183 newctx->gl_scissor_box[3]))
2188 flag = oldctx->_misc_flag3 | newctx->_misc_flag3;
2190 STATE_COMPARE(gl_read_buffer[0]) {
2191 CHECK_GL_ERROR(_orig_fastpath_glReadBuffer(newctx->gl_read_buffer[0]))
2193 STATES_COMPARE(gl_draw_buffers, 16 * sizeof(GLenum)) {
2194 int drawBuffSize = 16;
2195 /* If the context has only default framebuffer, then size of glDrawBuffers can only be 1 */
2196 if (fastpath_ostate_has_object_type(&newctx->ostate,
2197 GL_OBJECT_TYPE_FRAMEBUFFER) == 0) {
2201 CHECK_GL_ERROR(_orig_fastpath_glDrawBuffers(drawBuffSize,
2202 newctx->gl_draw_buffers))
2205 if (oldctx->gl_transform_feedback_active[0] == GL_TRUE &&
2206 oldctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2207 CHECK_GL_ERROR(_orig_fastpath_glPauseTransformFeedback())
2209 STATE_COMPARE(gl_transform_feedback_binding[0]) {
2210 CHECK_GL_ERROR(_orig_fastpath_glBindTransformFeedback(GL_TRANSFORM_FEEDBACK,
2211 newctx->gl_transform_feedback_binding[0]))
2213 if (newctx->gl_transform_feedback_active[0] == GL_TRUE &&
2214 newctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2215 CHECK_GL_ERROR(_orig_fastpath_glResumeTransformFeedback())
2219 #ifdef COREGL_USE_MODULE_TRACEPATH
2220 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
2221 #endif // COREGL_USE_MODULE_TRACEPATH
2228 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
2229 if (unlikely(trace_state_flag == 1))
2230 fastpath_dump_context_states(newctx, 0);
2231 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
2233 #undef STATE_COMPARE
2234 #undef STATES_COMPARE