1 #include "coregl_fastpath.h"
10 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST = NULL;
11 #include "../../headers/sym.h"
14 Fastpath_Opt_Flag fp_opt = FP_UNKNOWN_PATH;
17 FILE *trace_fp = NULL;
19 GLenum FPGL_Error = GL_NO_ERROR;
21 GLGlueContext_List *gctx_list = NULL;
23 Mutex init_context_mutex = MUTEX_INITIALIZER;
24 GLGlueContext *initial_ctx = NULL;
26 Mutex ctx_list_access_mutex = MUTEX_INITIALIZER;
28 GLContext_List *glctx_list = NULL;
29 static int api_gl_version = COREGL_GLAPI_2;
32 _state_get_texture_states(GLenum pname, GLint *params)
34 GLuint cur_active_tex = 0;
36 AST(initial_ctx != NULL);
38 _orig_fastpath_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
40 for (i = 0; i < initial_ctx->gl_num_tex_units[0]; i++) {
41 _orig_fastpath_glActiveTexture(GL_TEXTURE0 + i);
42 _orig_fastpath_glGetIntegerv(pname, (GLint *)¶ms[i]);
44 _orig_fastpath_glActiveTexture(cur_active_tex);
48 _state_get_draw_buffers(GLenum *params)
50 AST(initial_ctx != NULL);
53 for (i = 0; i < initial_ctx->gl_num_draw_buffers[0]; i++) {
54 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER0 + i, (GLint *)¶ms[i]);
59 _state_get_transform_feedback_buffer_bindings(GLuint *params)
61 AST(initial_ctx != NULL);
64 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0];
66 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, i,
72 _state_get_transform_feedback_buffer_bindings_offset(GLintptr *params)
74 AST(initial_ctx != NULL);
77 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0];
79 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_START, i,
85 _state_get_transform_feedback_buffer_bindings_size(GLsizeiptr *params)
87 AST(initial_ctx != NULL);
90 for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0];
92 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE, i,
98 _state_get_uniform_buffer_bindings(GLuint *params)
100 AST(initial_ctx != NULL);
103 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++) {
104 /////////////////////////////////////////////////////////////////////////////////
105 // XXXX : AVOID SEGFAULT in ADRENO
106 ((GLint *)params)[i] = 0;
107 // _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, i, (GLint *)¶ms[i]);
108 /////////////////////////////////////////////////////////////////////////////////
113 _state_get_uniform_buffer_bindings_offset(GLintptr *params)
115 AST(initial_ctx != NULL);
118 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++) {
119 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_START, i, (GLint *)¶ms[i]);
124 _state_get_uniform_buffer_bindings_size(GLsizeiptr *params)
126 AST(initial_ctx != NULL);
129 for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++) {
130 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, i, (GLint *)¶ms[i]);
135 fastpath_state_get_draw_buffers(GLenum *params)
137 _state_get_draw_buffers(params);
141 init_modules_fastpath()
143 int fastpath_opt = 0;
144 int fastpath_force_off_opt = 0;
146 COREGL_LOG("[CoreGL] <Fastpath> : ");
148 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
149 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
151 if (fastpath_force_off_opt == 1) {
152 COREGL_LOG("\E[40;31;1m(DISABLED by force option)\E[0m ");
156 switch (fastpath_opt) {
158 COREGL_LOG("(%d) Fastpath enabled...\n", fastpath_opt);
159 fp_opt = FP_FAST_PATH;
162 COREGL_LOG("(%d) Default API path enabled...\n", fastpath_opt);
163 fp_opt = FP_NORMAL_PATH;
167 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
172 deinit_modules_fastpath()
174 GLContext_List *current = NULL;
176 AST(mutex_lock(&ctx_list_access_mutex) == 1);
178 // Destroy remained context & Detect leaks
179 int retry_destroy = 0;
183 current = glctx_list;
185 if (current->cstate != NULL) {
186 COREGL_WRN("\E[40;31;1mContext attached to [dpy=%p|rctx=%p] has not been completely destroyed.(leak)\E[0m\n",
187 current->cstate->rdpy, current->cstate->rctx);
189 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE,
190 EGL_NO_SURFACE, EGL_NO_CONTEXT);
191 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
193 fastpath_remove_context_states_from_list(current->cstate, NULL);
198 glctx_list = current->next;
200 current = glctx_list;
202 if (retry_destroy == 0) break;
207 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
211 init_modules_tstate_fastpath(GLThreadState *tstate)
213 MY_MODULE_TSTATE *tstate_mt = NULL;
215 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
217 tstate_mt->binded_api = EGL_OPENGL_ES_API;
219 tstate->module_data[MY_MODULE_ID] = tstate_mt;
223 deinit_modules_tstate_fastpath(GLThreadState *tstate)
225 if (tstate->module_data[MY_MODULE_ID] != NULL) {
226 free(tstate->module_data[MY_MODULE_ID]);
227 tstate->module_data[MY_MODULE_ID] = NULL;
232 fastpath_apply_overrides()
236 fastpath_apply_overrides_egl(1);
237 fastpath_apply_overrides_gl(1);
242 COREGL_ERR("Invalide GL Override Option!!!\n");
249 fastpath_apply_overrides_egl(int enable)
251 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
252 # include "../../headers/sym_egl.h"
253 #undef _COREGL_SYMBOL
255 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
257 COREGL_OVERRIDE(fastpath_, eglBindAPI);
258 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
260 COREGL_OVERRIDE(fastpath_, eglCreateContext);
261 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
262 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
263 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
264 COREGL_OVERRIDE(fastpath_, eglQueryContext);
265 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
266 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
267 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
268 COREGL_OVERRIDE(fastpath_, eglTerminate);
269 COREGL_OVERRIDE(fastpath_, eglGetCurrentDisplay);
274 fastpath_apply_overrides_gl(int enable)
276 #define _COREGL_START_API(version) api_gl_version = version;
277 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
278 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
279 if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
281 # include "../../headers/sym_gl.h"
282 #undef _COREGL_SYMBOL
283 #undef _COREGL_START_API
284 #undef _COREGL_END_API
286 if (debug_nofp != 1) {
287 COREGL_OVERRIDE(fastpath_, glGetError);
288 COREGL_OVERRIDE(fastpath_, glGetString);
290 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
291 COREGL_OVERRIDE(fastpath_, glGetFloatv);
292 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
294 COREGL_OVERRIDE(fastpath_, glActiveTexture);
295 COREGL_OVERRIDE(fastpath_, glGenTextures);
296 COREGL_OVERRIDE(fastpath_, glBindTexture);
297 COREGL_OVERRIDE(fastpath_, glIsTexture);
298 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
299 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
301 COREGL_OVERRIDE(fastpath_, glGenBuffers);
302 COREGL_OVERRIDE(fastpath_, glBindBuffer);
303 COREGL_OVERRIDE(fastpath_, glIsBuffer);
304 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
306 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
307 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
308 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
309 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
310 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
312 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
313 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
314 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
315 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
316 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
318 COREGL_OVERRIDE(fastpath_, glCreateShader);
319 COREGL_OVERRIDE(fastpath_, glCreateProgram);
320 COREGL_OVERRIDE(fastpath_, glAttachShader);
321 COREGL_OVERRIDE(fastpath_, glCompileShader);
322 COREGL_OVERRIDE(fastpath_, glShaderBinary);
323 COREGL_OVERRIDE(fastpath_, glDeleteShader);
324 COREGL_OVERRIDE(fastpath_, glDetachShader);
325 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
326 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
327 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
328 COREGL_OVERRIDE(fastpath_, glIsShader);
329 COREGL_OVERRIDE(fastpath_, glShaderSource);
330 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
331 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
332 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
333 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
334 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
335 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
336 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
337 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
338 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
339 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
340 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
341 COREGL_OVERRIDE(fastpath_, glIsProgram);
342 COREGL_OVERRIDE(fastpath_, glLinkProgram);
343 COREGL_OVERRIDE(fastpath_, glUseProgram);
344 COREGL_OVERRIDE(fastpath_, glValidateProgram);
346 COREGL_OVERRIDE(fastpath_, glBlendColor);
347 COREGL_OVERRIDE(fastpath_, glBlendEquation);
348 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
349 COREGL_OVERRIDE(fastpath_, glBlendFunc);
350 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
351 COREGL_OVERRIDE(fastpath_, glClearColor);
352 COREGL_OVERRIDE(fastpath_, glClearDepthf);
353 COREGL_OVERRIDE(fastpath_, glClearStencil);
354 COREGL_OVERRIDE(fastpath_, glColorMask);
355 COREGL_OVERRIDE(fastpath_, glCullFace);
356 COREGL_OVERRIDE(fastpath_, glDepthFunc);
357 COREGL_OVERRIDE(fastpath_, glDepthMask);
358 COREGL_OVERRIDE(fastpath_, glDepthRangef);
359 COREGL_OVERRIDE(fastpath_, glDisable);
360 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
361 COREGL_OVERRIDE(fastpath_, glEnable);
362 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
363 COREGL_OVERRIDE(fastpath_, glFrontFace);
364 COREGL_OVERRIDE(fastpath_, glHint);
365 COREGL_OVERRIDE(fastpath_, glLineWidth);
366 COREGL_OVERRIDE(fastpath_, glPixelStorei);
367 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
368 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
369 COREGL_OVERRIDE(fastpath_, glScissor);
370 COREGL_OVERRIDE(fastpath_, glStencilFunc);
371 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
372 COREGL_OVERRIDE(fastpath_, glStencilMask);
373 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
374 COREGL_OVERRIDE(fastpath_, glStencilOp);
375 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
376 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
377 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
378 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
379 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
380 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
381 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
382 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
383 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
384 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
385 COREGL_OVERRIDE(fastpath_, glViewport);
387 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
388 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
390 COREGL_OVERRIDE(fastpath_, glUseProgramStagesEXT);
391 COREGL_OVERRIDE(fastpath_, glActiveShaderProgramEXT);
392 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
393 COREGL_OVERRIDE(fastpath_, glProgramUniform1iEXT);
394 COREGL_OVERRIDE(fastpath_, glProgramUniform2iEXT);
395 COREGL_OVERRIDE(fastpath_, glProgramUniform3iEXT);
396 COREGL_OVERRIDE(fastpath_, glProgramUniform4iEXT);
397 COREGL_OVERRIDE(fastpath_, glProgramUniform1fEXT);
398 COREGL_OVERRIDE(fastpath_, glProgramUniform2fEXT);
399 COREGL_OVERRIDE(fastpath_, glProgramUniform3fEXT);
400 COREGL_OVERRIDE(fastpath_, glProgramUniform4fEXT);
401 COREGL_OVERRIDE(fastpath_, glProgramUniform1ivEXT);
402 COREGL_OVERRIDE(fastpath_, glProgramUniform2ivEXT);
403 COREGL_OVERRIDE(fastpath_, glProgramUniform3ivEXT);
404 COREGL_OVERRIDE(fastpath_, glProgramUniform4ivEXT);
405 COREGL_OVERRIDE(fastpath_, glProgramUniform1fvEXT);
406 COREGL_OVERRIDE(fastpath_, glProgramUniform2fvEXT);
407 COREGL_OVERRIDE(fastpath_, glProgramUniform3fvEXT);
408 COREGL_OVERRIDE(fastpath_, glProgramUniform4fvEXT);
409 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fvEXT);
410 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fvEXT);
411 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fvEXT);
413 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
414 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
416 COREGL_OVERRIDE(fastpath_, glBindFramebufferOES);
417 COREGL_OVERRIDE(fastpath_, glBindRenderbufferOES);
418 COREGL_OVERRIDE(fastpath_, glClearBufferfi);
419 COREGL_OVERRIDE(fastpath_, glClearBufferfv);
420 COREGL_OVERRIDE(fastpath_, glClearBufferiv);
421 COREGL_OVERRIDE(fastpath_, glClearBufferuiv);
422 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffersOES);
423 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffersOES);
424 COREGL_OVERRIDE(fastpath_, glDepthRangefOES);
425 COREGL_OVERRIDE(fastpath_, glDepthRangexOES);
426 COREGL_OVERRIDE(fastpath_, glFramebufferParameteri);
427 COREGL_OVERRIDE(fastpath_, glGetFramebufferParameteriv);
428 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbufferOES);
429 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DOES);
430 COREGL_OVERRIDE(fastpath_, glGenFramebuffersOES);
431 COREGL_OVERRIDE(fastpath_, glGenRenderbuffersOES);
432 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameterivOES);
433 COREGL_OVERRIDE(fastpath_, glGetQueryObjecti64vEXT);
434 COREGL_OVERRIDE(fastpath_, glGetQueryObjectivEXT);
435 COREGL_OVERRIDE(fastpath_, glGetQueryObjectui64vEXT);
436 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuivEXT);
437 COREGL_OVERRIDE(fastpath_, glGetQueryivEXT);
438 COREGL_OVERRIDE(fastpath_, glBeginQueryEXT);
439 COREGL_OVERRIDE(fastpath_, glDeleteQueriesEXT);
440 COREGL_OVERRIDE(fastpath_, glGenQueriesEXT);
441 COREGL_OVERRIDE(fastpath_, glIsFramebufferOES);
442 COREGL_OVERRIDE(fastpath_, glIsQueryEXT);
443 COREGL_OVERRIDE(fastpath_, glIsRenderbufferOES);
444 COREGL_OVERRIDE(fastpath_, glBlendEquationOES);
445 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparateOES);
446 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparateOES);
447 COREGL_OVERRIDE(fastpath_, glPolygonOffsetxOES);
448 COREGL_OVERRIDE(fastpath_, glLineWidthxOES);
449 COREGL_OVERRIDE(fastpath_, glSampleCoveragexOES);
450 COREGL_OVERRIDE(fastpath_, glQueryCounterEXT);
451 COREGL_OVERRIDE(fastpath_, glBindVertexArrayOES);
452 COREGL_OVERRIDE(fastpath_, glDeleteVertexArraysOES);
453 COREGL_OVERRIDE(fastpath_, glGenVertexArraysOES);
454 COREGL_OVERRIDE(fastpath_, glIsVertexArrayOES);
455 COREGL_OVERRIDE(fastpath_, glClearDepthfOES );
456 COREGL_OVERRIDE(fastpath_, glClearDepthxOES );
457 /* Start overriding GLES 3.0 */
458 if (driver_gl_version >= COREGL_GLAPI_3) {
459 COREGL_OVERRIDE(fastpath_, glReadBuffer);
461 COREGL_OVERRIDE(fastpath_, glGenQueries);
462 COREGL_OVERRIDE(fastpath_, glDeleteQueries);
463 COREGL_OVERRIDE(fastpath_, glIsQuery);
464 COREGL_OVERRIDE(fastpath_, glBeginQuery);
465 COREGL_OVERRIDE(fastpath_, glGetQueryiv);
466 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
467 COREGL_OVERRIDE(fastpath_, glDrawBuffers);
468 COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
470 COREGL_OVERRIDE(fastpath_, glBindVertexArray);
471 COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
472 COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
473 COREGL_OVERRIDE(fastpath_, glIsVertexArray);
475 COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
477 COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
478 COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
479 COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
480 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
482 COREGL_OVERRIDE(fastpath_, glBindBufferRange);
483 COREGL_OVERRIDE(fastpath_, glBindBufferBase);
484 COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
485 COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
486 COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
487 COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
488 COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
489 COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
490 COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
491 COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
492 COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
493 COREGL_OVERRIDE(fastpath_, glGetStringi);
494 COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
495 COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
496 COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
497 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
498 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
499 COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
500 COREGL_OVERRIDE(fastpath_, glGetInteger64v);
501 COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
502 COREGL_OVERRIDE(fastpath_, glGenSamplers);
503 COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
504 COREGL_OVERRIDE(fastpath_, glIsSampler);
505 COREGL_OVERRIDE(fastpath_, glBindSampler);
506 COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
507 COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
508 COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
509 COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
510 COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
511 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
512 COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
513 COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
514 COREGL_OVERRIDE(fastpath_, glProgramBinary);
515 COREGL_OVERRIDE(fastpath_, glProgramParameteri);
518 if (driver_gl_version >= COREGL_GLAPI_31) {
519 COREGL_OVERRIDE(fastpath_, glCreateShaderProgramv);
520 COREGL_OVERRIDE(fastpath_, glGenProgramPipelines);
521 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineiv);
522 COREGL_OVERRIDE(fastpath_, glBindProgramPipeline);
523 COREGL_OVERRIDE(fastpath_, glDeleteProgramPipelines);
524 COREGL_OVERRIDE(fastpath_, glIsProgramPipeline);
525 COREGL_OVERRIDE(fastpath_, glValidateProgramPipeline);
526 COREGL_OVERRIDE(fastpath_, glGetProgramPipelineInfoLog);
527 COREGL_OVERRIDE(fastpath_, glDispatchCompute);
528 COREGL_OVERRIDE(fastpath_, glDispatchComputeIndirect);
529 COREGL_OVERRIDE(fastpath_, glGetProgramInterfaceiv);
530 COREGL_OVERRIDE(fastpath_, glGetProgramResourceIndex);
531 COREGL_OVERRIDE(fastpath_, glGetProgramResourceName);
532 COREGL_OVERRIDE(fastpath_, glGetProgramResourceiv);
533 COREGL_OVERRIDE(fastpath_, glGetProgramResourceLocation);
534 COREGL_OVERRIDE(fastpath_, glUseProgramStages);
535 COREGL_OVERRIDE(fastpath_, glActiveShaderProgram);
536 COREGL_OVERRIDE(fastpath_, glProgramUniform1iv);
537 COREGL_OVERRIDE(fastpath_, glProgramUniform2iv);
538 COREGL_OVERRIDE(fastpath_, glProgramUniform3iv);
539 COREGL_OVERRIDE(fastpath_, glProgramUniform4iv);
540 COREGL_OVERRIDE(fastpath_, glProgramUniform1fv);
541 COREGL_OVERRIDE(fastpath_, glProgramUniform2fv);
542 COREGL_OVERRIDE(fastpath_, glProgramUniform3fv);
543 COREGL_OVERRIDE(fastpath_, glProgramUniform4fv);
544 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fv);
545 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fv);
546 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fv);
547 COREGL_OVERRIDE(fastpath_, glProgramUniform1i);
548 COREGL_OVERRIDE(fastpath_, glProgramUniform2i);
549 COREGL_OVERRIDE(fastpath_, glProgramUniform3i);
550 COREGL_OVERRIDE(fastpath_, glProgramUniform4i);
551 COREGL_OVERRIDE(fastpath_, glProgramUniform1f);
552 COREGL_OVERRIDE(fastpath_, glProgramUniform2f);
553 COREGL_OVERRIDE(fastpath_, glProgramUniform3f);
554 COREGL_OVERRIDE(fastpath_, glProgramUniform4f);
555 COREGL_OVERRIDE(fastpath_, glProgramUniform1uiv);
556 COREGL_OVERRIDE(fastpath_, glProgramUniform2uiv);
557 COREGL_OVERRIDE(fastpath_, glProgramUniform3uiv);
558 COREGL_OVERRIDE(fastpath_, glProgramUniform4uiv);
559 COREGL_OVERRIDE(fastpath_, glProgramUniform1ui);
560 COREGL_OVERRIDE(fastpath_, glProgramUniform2ui);
561 COREGL_OVERRIDE(fastpath_, glProgramUniform3ui);
562 COREGL_OVERRIDE(fastpath_, glProgramUniform4ui);
563 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x3fv);
564 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x2fv);
565 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x2fv);
566 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2x4fv);
567 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3x4fv);
568 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4x3fv);
569 COREGL_OVERRIDE(fastpath_, glBindImageTexture);
570 COREGL_OVERRIDE(fastpath_, glGetBooleani_v);
571 COREGL_OVERRIDE(fastpath_, glMemoryBarrier);
572 COREGL_OVERRIDE(fastpath_, glMemoryBarrierByRegion);
573 COREGL_OVERRIDE(fastpath_, glTexStorage2DMultisample);
574 COREGL_OVERRIDE(fastpath_, glGetMultisamplefv);
575 COREGL_OVERRIDE(fastpath_, glSampleMaski);
576 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameteriv);
577 COREGL_OVERRIDE(fastpath_, glGetTexLevelParameterfv);
578 COREGL_OVERRIDE(fastpath_, glBindVertexBuffer);
579 COREGL_OVERRIDE(fastpath_, glVertexAttribFormat);
580 COREGL_OVERRIDE(fastpath_, glVertexAttribIFormat);
581 COREGL_OVERRIDE(fastpath_, glVertexAttribBinding);
582 COREGL_OVERRIDE(fastpath_, glVertexBindingDivisor);
585 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
591 static inline GL_Object_Hash_Base *
592 _lock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
595 case GL_OBJECT_TYPE_QUERY:
596 return &ostate->query;
597 case GL_OBJECT_TYPE_TEXTURE:
598 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
599 return &ostate->shared->texture;
600 case GL_OBJECT_TYPE_BUFFER:
601 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
602 return &ostate->shared->buffer;
603 case GL_OBJECT_TYPE_FRAMEBUFFER:
604 return &ostate->framebuffer;
605 case GL_OBJECT_TYPE_RENDERBUFFER:
606 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
607 return &ostate->shared->renderbuffer;
608 case GL_OBJECT_TYPE_PROGRAM:
609 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
610 return &ostate->shared->program;
611 case GL_OBJECT_TYPE_VERTEXARRAY:
612 return &ostate->vertexarray;
613 case GL_OBJECT_TYPE_SAMPLER:
614 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
615 return &ostate->shared->sampler;
616 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
617 return &ostate->transformfeedback;
618 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
619 AST(mutex_lock(&ostate->shared->access_mutex) == 1);
620 return &ostate->shared->programpipeline;
627 _unlock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
630 case GL_OBJECT_TYPE_TEXTURE:
631 case GL_OBJECT_TYPE_BUFFER:
632 case GL_OBJECT_TYPE_RENDERBUFFER:
633 case GL_OBJECT_TYPE_PROGRAM:
634 case GL_OBJECT_TYPE_SAMPLER:
635 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
636 AST(mutex_unlock(&ostate->shared->access_mutex) == 1);
642 static inline GL_Object_Hash_Base *
643 _lock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
646 case GL_OBJECT_TYPE_QUERY:
647 return &ostate->query_real;
648 case GL_OBJECT_TYPE_TEXTURE:
649 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
650 return &ostate->shared->texture_real;
651 case GL_OBJECT_TYPE_BUFFER:
652 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
653 return &ostate->shared->buffer_real;
654 case GL_OBJECT_TYPE_FRAMEBUFFER:
655 return &ostate->framebuffer_real;
656 case GL_OBJECT_TYPE_RENDERBUFFER:
657 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
658 return &ostate->shared->renderbuffer_real;
659 case GL_OBJECT_TYPE_PROGRAM:
660 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
661 return &ostate->shared->program_real;
662 case GL_OBJECT_TYPE_VERTEXARRAY:
663 return &ostate->vertexarray_real;
664 case GL_OBJECT_TYPE_SAMPLER:
665 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
666 return &ostate->shared->sampler_real;
667 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
668 return &ostate->transformfeedback_real;
669 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
670 AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
671 return &ostate->shared->programpipeline_real;
678 _unlock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
681 case GL_OBJECT_TYPE_TEXTURE:
682 case GL_OBJECT_TYPE_BUFFER:
683 case GL_OBJECT_TYPE_RENDERBUFFER:
684 case GL_OBJECT_TYPE_PROGRAM:
685 case GL_OBJECT_TYPE_SAMPLER:
686 case GL_OBJECT_TYPE_PROGRAMPIPELINE:
687 AST(mutex_unlock(&ostate->shared->real_access_mutex) == 1);
695 fastpath_add_context_state_to_list(const void *option, const int option_len,
696 GLContextState *cstate, Mutex *mtx)
700 GLContext_List *current = NULL;
701 GLContext_List *newitm = NULL;
703 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
707 tid = get_current_thread();
709 current = glctx_list;
710 while (current != NULL) {
711 if (current->option_len == option_len &&
712 memcmp(current->option, option, option_len) == 0 &&
713 current->thread_id == tid) {
714 AST(current->cstate == cstate);
717 current = current->next;
720 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
721 if (newitm == NULL) {
722 COREGL_ERR("Failed to create context list.\n");
726 newitm->cstate = cstate;
727 newitm->thread_id = tid;
728 newitm->option_len = option_len;
729 newitm->option = (void *)malloc(option_len);
730 memcpy(newitm->option, option, option_len);
732 if (glctx_list != NULL)
733 newitm->next = glctx_list;
742 if (newitm != NULL) {
746 if (cstate != NULL) {
751 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
757 fastpath_get_context_state_from_list(const void *option, const int option_len,
760 GLContextState *ret = NULL;
761 GLContext_List *current = NULL;
764 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
766 tid = get_current_thread();
768 current = glctx_list;
769 while (current != NULL) {
770 if (current->option_len == option_len &&
771 memcmp(current->option, option, option_len) == 0 &&
772 current->thread_id == tid) {
773 ret = current->cstate;
776 current = current->next;
781 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
786 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
789 GLContext_List *olditm = NULL;
790 GLContext_List *current = NULL;
792 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
796 current = glctx_list;
798 while (current != NULL) {
799 if (current->cstate == cstate) {
800 GLContext_List *nextitm = NULL;
801 if (olditm != NULL) {
802 olditm->next = current->next;
803 nextitm = olditm->next;
805 glctx_list = current->next;
806 nextitm = glctx_list;
808 if (current->option != NULL) {
809 AST(current->option_len > 0);
810 free(current->option);
811 current->option = NULL;
812 current->option_len = 0;
820 current = current->next;
825 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
831 #define HASH_INIT(hash_base) \
832 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
833 hash_base.hash_size = GL_OBJECT_HASH_BASE;
836 fastpath_ostate_init(GL_Object_State *ostate)
838 HASH_INIT(ostate->query);
839 HASH_INIT(ostate->framebuffer);
840 HASH_INIT(ostate->vertexarray);
841 HASH_INIT(ostate->transformfeedback);
843 HASH_INIT(ostate->query_real);
844 HASH_INIT(ostate->framebuffer_real);
845 HASH_INIT(ostate->vertexarray_real);
846 HASH_INIT(ostate->transformfeedback_real);
850 fastpath_sostate_init(GL_Shared_Object_State *sostate)
852 mutex_init(&sostate->access_mutex);
854 HASH_INIT(sostate->texture);
855 HASH_INIT(sostate->buffer);
856 HASH_INIT(sostate->renderbuffer);
857 HASH_INIT(sostate->program);
858 HASH_INIT(sostate->sampler);
859 HASH_INIT(sostate->programpipeline);
861 HASH_INIT(sostate->texture_real);
862 HASH_INIT(sostate->buffer_real);
863 HASH_INIT(sostate->renderbuffer_real);
864 HASH_INIT(sostate->program_real);
865 HASH_INIT(sostate->sampler_real);
866 HASH_INIT(sostate->programpipeline_real);
873 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
875 int array_idx = data->hash_key & (hash_base->hash_size - 1);
876 if (hash_base->hash_field[array_idx] == NULL) {
877 hash_base->hash_field[array_idx] = data;
879 GL_Object_Hash *current = hash_base->hash_field[array_idx];
880 while (current->next) {
881 AST(current->hash_key != data->hash_key);
882 current = current->next;
884 current->next = data;
887 hash_base->item_size++;
891 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
894 int array_idx = hash & (hash_base->hash_size - 1);
896 GL_Object_Hash *current = hash_base->hash_field[array_idx];
897 GL_Object_Hash *prev = NULL;
900 if (current->hash_key == hash) {
902 prev->next = current->next;
904 hash_base->hash_field[array_idx] = current->next;
905 hash_base->item_size--;
910 current = current->next;
917 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
919 if (hash_base->item_size == 0) return;
921 for (int i = 0; i < hash_base->hash_size; i++) {
922 if (hash_base->hash_field[i] != NULL) {
923 GL_Object_Hash *current = hash_base->hash_field[i];
925 while (current != NULL) {
926 GL_Object_Hash *current_next = current->next;
928 if (free_data == 1 && current->item != NULL) {
933 hash_base->item_size--;
934 current = current_next;
942 #define HASH_DEINIT(hash_base, free_data) \
943 _free_hash_list(&hash_base, free_data); \
944 free(hash_base.hash_field); \
945 hash_base.hash_size = 0;
948 fastpath_ostate_deinit(GL_Object_State *ostate)
950 HASH_DEINIT(ostate->query, 1);
951 HASH_DEINIT(ostate->framebuffer, 1);
952 HASH_DEINIT(ostate->vertexarray, 1);
953 HASH_DEINIT(ostate->transformfeedback, 1);
955 HASH_DEINIT(ostate->query_real, 0);
956 HASH_DEINIT(ostate->framebuffer_real, 0);
957 HASH_DEINIT(ostate->vertexarray_real, 0);
958 HASH_DEINIT(ostate->transformfeedback_real, 0);
962 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
964 HASH_DEINIT(sostate->texture, 1);
965 HASH_DEINIT(sostate->buffer, 1);
966 HASH_DEINIT(sostate->renderbuffer, 1);
967 HASH_DEINIT(sostate->program, 1);
968 HASH_DEINIT(sostate->sampler, 1);
969 HASH_DEINIT(sostate->programpipeline, 1);
971 HASH_DEINIT(sostate->texture_real, 0);
972 HASH_DEINIT(sostate->buffer_real, 0);
973 HASH_DEINIT(sostate->renderbuffer_real, 0);
974 HASH_DEINIT(sostate->program_real, 0);
975 HASH_DEINIT(sostate->sampler_real, 0);
977 HASH_DEINIT(sostate->programpipeline_real, 0);
984 #define FIND_HASH(hash_base, key, ret) \
986 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
989 if (fh_current->hash_key == (key)) \
994 fh_current = fh_current->next; \
999 _ostate_hash_check(GL_Object_Hash_Base *hash_base)
1001 if (hash_base->item_size + 1 < hash_base->hash_size)
1004 int oldsize = hash_base->hash_size;
1005 GL_Object_Hash **oldfield = hash_base->hash_field;
1007 hash_base->hash_size = oldsize << 1;
1008 hash_base->hash_field = (GL_Object_Hash **)calloc(1,
1009 sizeof(GL_Object_Hash *) * hash_base->hash_size);
1010 AST(hash_base->hash_field != NULL);
1012 for (int i = 0; i < oldsize; i++) {
1013 if (oldfield[i] != NULL) {
1014 GL_Object_Hash *current = oldfield[i];
1016 while (current != NULL) {
1017 GL_Object_Hash *current_next = current->next;
1018 _add_hash(hash_base, current);
1019 hash_base->item_size--;
1020 current = current_next;
1029 fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type,
1032 GLuint ret = _COREGL_INT_INIT_VALUE;
1034 GL_Object_Hash_Base *hash_base = NULL;
1035 GL_Object_Hash_Base *hash_base_real = NULL;
1036 int newid = _COREGL_INT_INIT_VALUE;
1038 hash_base = _lock_gl_object_hash(ostate, type);
1039 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1041 newid = hash_base->last_id + 1;
1042 if (newid >= hash_base->hash_size) {
1043 hash_base->is_looped = 1;
1045 hash_base->last_id = 1;
1048 if (hash_base->is_looped != 0) {
1050 int findingid = newid;
1052 for (i = 0; i < hash_base->hash_size; i++) {
1053 GL_Object_Hash *exist_hash = NULL;
1054 FIND_HASH(hash_base, findingid, exist_hash);
1055 if (exist_hash == NULL) {
1060 if (findingid >= hash_base->hash_size) findingid = 1;
1064 hash_base->last_id = newid;
1067 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
1070 newobj->id = (int)type + newid;
1071 newobj->real_id = real_name;
1072 newobj->ref_count = 1;
1075 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1,
1076 sizeof(GL_Object_Hash));
1077 if (newobj_hash == NULL) {
1081 newobj_hash->item = newobj;
1082 newobj_hash->hash_key = newid;
1083 _add_hash(hash_base, newobj_hash);
1085 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1,
1086 sizeof(GL_Object_Hash));
1087 if (newobj_hash_real == NULL) {
1092 newobj_hash_real->item = newobj;
1093 newobj_hash_real->hash_key = real_name;
1094 _add_hash(hash_base_real, newobj_hash_real);
1099 _ostate_hash_check(hash_base);
1100 _ostate_hash_check(hash_base_real);
1105 _unlock_gl_object_hash(ostate, type);
1106 _unlock_gl_object_hash_real(ostate, type);
1110 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
1111 if (((int)(hash)) < 0) { ret = 0; goto finish; } \
1113 GL_Object_Hash *object_hash = NULL; \
1114 FIND_HASH((hash_base), (int)(hash), object_hash); \
1115 if (object_hash == NULL) { ret = 0; goto finish; } \
1116 (object) = object_hash->item; \
1117 if ((object) == NULL) { ret = 0; goto finish; } \
1121 fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type,
1124 GLuint ret = _COREGL_INT_INIT_VALUE;
1126 GL_Object_Hash_Base *hash_base = NULL;
1127 GL_Object_Hash_Base *hash_base_real = NULL;
1128 GL_Object *object = NULL;
1130 hash_base = _lock_gl_object_hash(ostate, type);
1131 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1133 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1135 object->ref_count--;
1137 if (object->ref_count <= 0) {
1138 GL_Object_Hash *object_hash = NULL;
1140 FIND_HASH(hash_base, object->id - (int)type, object_hash);
1141 AST(object_hash != NULL);
1142 _remove_hash(hash_base, object->id - (int)type);
1146 FIND_HASH(hash_base_real, object->real_id, object_hash);
1147 AST(object_hash != NULL);
1148 _remove_hash(hash_base_real, object->real_id);
1160 _unlock_gl_object_hash(ostate, type);
1161 _unlock_gl_object_hash_real(ostate, type);
1166 fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type,
1169 GLuint ret = _COREGL_INT_INIT_VALUE;
1171 GL_Object_Hash_Base *hash_base = NULL;
1172 GL_Object *object = NULL;
1174 hash_base = _lock_gl_object_hash(ostate, type);
1176 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1178 ret = object->real_id;
1182 _unlock_gl_object_hash(ostate, type);
1186 /* Check if the context's state contains object of a given type */
1188 fastpath_ostate_has_object_type(GL_Object_State *ostate, GL_Object_Type type)
1190 GLuint ret = _COREGL_INT_INIT_VALUE;
1192 GL_Object_Hash_Base *hash_base = NULL;
1193 GL_Object *object = NULL;
1194 hash_base = _lock_gl_object_hash(ostate, type);
1196 if (hash_base->hash_field == 0) {
1201 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, 1, object);
1203 ret = object->real_id;
1207 _unlock_gl_object_hash(ostate, type);
1213 fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1214 GLuint glue_name, GLvoid *tag)
1216 GLint ret = _COREGL_INT_INIT_VALUE;
1218 GL_Object_Hash_Base *hash_base = NULL;
1219 GL_Object *object = NULL;
1220 int hash = _COREGL_INT_INIT_VALUE;
1222 hash_base = _lock_gl_object_hash(ostate, type);
1224 hash = glue_name - (int)type;
1226 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
1228 AST(object->tag == NULL);
1234 _unlock_gl_object_hash(ostate, type);
1239 fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type,
1244 GL_Object_Hash_Base *hash_base = NULL;
1245 GL_Object *object = NULL;
1247 hash_base = _lock_gl_object_hash(ostate, type);
1249 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1255 _unlock_gl_object_hash(ostate, type);
1260 fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type,
1263 GLuint ret = _COREGL_INT_INIT_VALUE;
1265 GL_Object_Hash_Base *hash_base_real = NULL;
1266 GL_Object *object = NULL;
1268 hash_base_real = _lock_gl_object_hash_real(ostate, type);
1270 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
1276 _unlock_gl_object_hash_real(ostate, type);
1281 fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type,
1284 GLint ret = _COREGL_INT_INIT_VALUE;
1286 GL_Object_Hash_Base *hash_base = NULL;
1287 GL_Object *object = NULL;
1289 hash_base = _lock_gl_object_hash(ostate, type);
1291 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1293 object->ref_count++;
1298 _unlock_gl_object_hash(ostate, type);
1303 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
1305 static struct timeval tv_last = { 0, 0 };
1307 if (unlikely(trace_state_flag != 1)) return;
1309 if (!force_output) {
1310 struct timeval tv_now = { 0, 0 };
1311 AST(gettimeofday(&tv_now, NULL) == 0);
1312 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC) {
1319 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1320 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n",
1322 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1324 #define PRINTF_CHAR_GLenum "0x%8X"
1325 #define PRINTF_CHAR_GLboolean "%10d"
1326 #define PRINTF_CHAR_GLint "%10d"
1327 #define PRINTF_CHAR_GLsizei "%10u"
1328 #define PRINTF_CHAR_GLuint "%10u"
1329 #define PRINTF_CHAR_GLuintmask "0x%8X"
1330 #define PRINTF_CHAR_GLintptr "%10ld"
1331 #define PRINTF_CHAR_GLsizeiptr "%10ld"
1333 #define PRINTF_CHAR_GLclampf "%10.6f"
1334 #define PRINTF_CHAR_GLfloat "%10.6f"
1336 #define PRINTF_CHAR_GLvoidptr "%10p"
1338 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1340 #define _COREGL_START_API(version) api_gl_version = version;
1341 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1342 #define INITIAL_CTX initial_ctx
1343 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1345 TYPE valuedata[SIZE]; \
1346 TYPE *value = NULL; \
1347 if(api_gl_version <= driver_gl_version) { \
1348 value = valuedata; GET_STMT; value = valuedata; \
1349 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1350 for (int i = 0; i < SIZE; i++) \
1354 TRACE("\n %-30.30s ", "");\
1358 if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
1359 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1360 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1361 if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
1363 TRACE(" \E[40;37;1m)\E[0m\n"); \
1366 # include "coregl_fastpath_state.h"
1369 #undef _COREGL_START_API
1370 #undef _COREGL_END_API
1372 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1382 fastpath_init_context_states(GLGlueContext *ctx)
1386 AST(mutex_lock(&init_context_mutex) == 1);
1389 COREGL_ERR("Context NULL\n");
1394 AST(ctx->initialized == 0);
1395 AST(ctx->ostate.shared != NULL);
1397 if (initial_ctx == NULL) {
1398 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1399 AST(initial_ctx != NULL);
1401 //#define FORCE_DEFAULT_VALUE
1402 #define _COREGL_START_API(version) api_gl_version = version;
1403 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1404 #ifdef FORCE_DEFAULT_VALUE
1405 # define INITIAL_CTX initial_ctx
1406 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1410 TYPE valuedata[SIZE]; \
1411 TYPE *value = NULL; \
1412 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1413 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1414 if(api_gl_version <= driver_gl_version) { \
1415 value = valuedata; DEFAULT_STMT; value = valuedata; \
1416 for (i = 0; i < SIZE; i++) \
1418 if (*((char *)(&value[i])) == 0xcc) \
1420 memset(&value[i], 0xaa, sizeof(TYPE)); \
1421 value = valuedata; DEFAULT_STMT; value = valuedata; \
1422 if (*((char *)(&value[i])) == 0xaa) \
1424 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1428 initial_ctx->NAME[i] = value[i]; \
1433 # include "coregl_fastpath_state.h"
1437 # define INITIAL_CTX initial_ctx
1438 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1439 if (try_step == 1) \
1441 value = valuedata; DEFAULT_STMT; value = valuedata; \
1445 value = valuedata; FALLBACK_STMT; value = valuedata; \
1448 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1453 TYPE valuedata[SIZE]; \
1454 TYPE *value = NULL; \
1455 _sym_glGetError(); \
1456 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1457 initial_ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE));\
1458 if(api_gl_version <= driver_gl_version) { \
1461 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1462 if (_sym_glGetError() == GL_INVALID_ENUM) \
1464 initial_ctx->NAME##_used = 0; \
1465 value = valuedata; DEFAULT_STMT; value = valuedata; \
1468 initial_ctx->NAME##_used = 1; \
1469 for (i = 0; i < SIZE; i++) \
1471 if (*((char *)(&value[i])) == 0xcc) \
1473 memset(&value[i], 0xaa, sizeof(TYPE)); \
1474 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1475 if (*((char *)(&value[i])) == 0xaa) \
1478 if (try_step == 2) \
1480 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1485 initial_ctx->NAME[i] = value[i]; \
1487 if (try_step != 2) \
1489 value = valuedata; DEFAULT_STMT; value = valuedata; \
1490 for (i = 0; i < SIZE; i++) \
1492 if (initial_ctx->NAME[i] != value[i]) \
1494 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]); \
1499 while (try_step == 2); \
1503 # include "coregl_fastpath_state.h"
1504 # undef SET_GLUE_VALUE
1508 # undef _COREGL_END_API
1509 # undef _COREGL_START_API
1511 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS) {
1512 COREGL_WRN("\E[40;31;1mNumber of vertex attrib is too big! (%d-%d)\E[0m\n",
1513 MAX_VERTEX_ATTRIBS, initial_ctx->gl_num_vertex_attribs[0]);
1515 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS) {
1516 COREGL_WRN("\E[40;31;1mNumber of texture unit is too big! (%d-%d)\E[0m\n",
1517 MAX_TEXTURE_UNITS, initial_ctx->gl_num_tex_units[0]);
1519 if (initial_ctx->gl_num_transform_feedback_separate_attribs[0] >
1520 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS) {
1521 COREGL_WRN("\E[40;31;1mNumber of transform feedback separate attrib is too big! (%d-%d)\E[0m\n",
1522 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
1523 initial_ctx->gl_num_transform_feedback_separate_attribs[0]);
1525 if (initial_ctx->gl_num_uniform_buffer_bindings[0] >
1526 MAX_UNIFORM_BUFFER_BINDINGS) {
1527 COREGL_WRN("\E[40;31;1mNumber of uniform buffer binding is too big! (%d-%d)\E[0m\n",
1528 MAX_UNIFORM_BUFFER_BINDINGS, initial_ctx->gl_num_uniform_buffer_bindings[0]);
1534 #define _COREGL_START_API(version) api_gl_version = version;
1535 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1536 #define INITIAL_CTX initial_ctx
1537 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1540 ctx->NAME = (TYPE *)calloc(SIZE, sizeof(TYPE)); \
1541 if(api_gl_version <= driver_gl_version) { \
1542 for (i = 0; i < SIZE; i++) \
1544 ctx->NAME[i] = initial_ctx->NAME[i]; \
1545 ctx->NAME##_used = initial_ctx->NAME##_used; \
1550 # include "coregl_fastpath_state.h"
1553 #undef _COREGL_START_API
1554 #undef _COREGL_END_API
1557 ctx->initialized = 1;
1562 AST(mutex_unlock(&init_context_mutex) == 1);
1567 #ifdef COREGL_USE_MODULE_TRACEPATH
1568 extern void *tracepath_api_trace_begin(const char *name, void *hint,
1569 int trace_total_time);
1570 extern void *tracepath_api_trace_end(const char *name, void *hint,
1571 int trace_total_time);
1574 #define CHECK_GL_ERROR(func) \
1577 int err = _orig_fastpath_glGetError(); \
1578 if (err != GL_NO_ERROR) \
1580 COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1586 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1589 unsigned char flag = 0;
1592 if (debug_nofp == 1) {
1597 // Return if they're the same
1598 if (oldctx == newctx) {
1603 #define STATE_COMPARE(state) \
1604 if ((oldctx->state) != (newctx->state))
1606 #define STATES_COMPARE(state_ptr, bytes) \
1607 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1610 #ifdef COREGL_USE_MODULE_TRACEPATH
1611 static void *trace_hint_glfinish = NULL;
1612 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)",
1613 trace_hint_glfinish, 0);
1614 #endif // COREGL_USE_MODULE_TRACEPATH
1617 int err = _orig_fastpath_glGetError();
1618 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1619 oldctx->gl_error = err;
1622 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1624 #ifdef COREGL_USE_MODULE_TRACEPATH
1625 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1626 #endif // COREGL_USE_MODULE_TRACEPATH
1629 #ifdef COREGL_USE_MODULE_TRACEPATH
1630 static void *trace_hint_vertex_attrib = NULL;
1631 trace_hint_vertex_attrib =
1632 tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)",
1633 trace_hint_vertex_attrib, 0);
1634 #endif // COREGL_USE_MODULE_TRACEPATH
1636 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1638 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++) {
1639 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i]) {
1640 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1641 newctx->gl_vertex_array_buf_id[i]))
1643 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1646 STATE_COMPARE(gl_vertex_array_divisor[i]) {
1647 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribDivisor(i,
1648 newctx->gl_vertex_array_divisor[i]))
1651 if (newctx->gl_vertex_array_size[i] != 0) {
1652 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1653 newctx->gl_vertex_array_size[i],
1654 newctx->gl_vertex_array_type[i],
1655 newctx->gl_vertex_array_normalized[i],
1656 newctx->gl_vertex_array_stride[i],
1657 newctx->gl_vertex_array_pointer[i]))
1659 if (newctx->gl_vertex_array_integer[0] == GL_TRUE) {
1660 if (newctx->gl_vertex_array_type[0] == GL_UNSIGNED_INT) {
1661 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4uiv(i,
1662 &newctx->gl_vertex_attrib_value_unsigned_integer[4 * i]))
1664 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4iv(i,
1665 &newctx->gl_vertex_attrib_value_integer[4 * i]))
1668 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i,
1669 &newctx->gl_vertex_attrib_value[4 * i]))
1673 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE) {
1674 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1676 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1682 #ifdef COREGL_USE_MODULE_TRACEPATH
1683 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)",
1684 trace_hint_vertex_attrib, 0);
1685 #endif // COREGL_USE_MODULE_TRACEPATH
1688 #ifdef COREGL_USE_MODULE_TRACEPATH
1689 static void *trace_hint_bindbuffers = NULL;
1690 trace_hint_bindbuffers =
1691 tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)",
1692 trace_hint_bindbuffers, 0);
1693 #endif // COREGL_USE_MODULE_TRACEPATH
1695 //------------------//
1697 flag = oldctx->_bind_flag1 | newctx->_bind_flag1;
1699 STATE_COMPARE(gl_array_buffer_binding[0]) {
1700 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER,
1701 newctx->gl_array_buffer_binding[0]))
1703 STATE_COMPARE(gl_element_array_buffer_binding[0]) {
1704 STATE_COMPARE(gl_vertex_array_binding[0]) {
1705 CHECK_GL_ERROR(_orig_fastpath_glBindVertexArray(
1706 newctx->gl_vertex_array_binding[0]))
1708 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1709 newctx->gl_element_array_buffer_binding[0]))
1712 if (newctx->gl_framebuffer_binding_read_used == 1) {
1713 STATE_COMPARE(gl_framebuffer_binding_read[0]) {
1714 if (driver_gl_version >= 2)
1715 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER,
1716 newctx->gl_framebuffer_binding_read[0]))
1718 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_READ_FRAMEBUFFER,
1719 newctx->gl_framebuffer_binding_read[0]))
1721 STATE_COMPARE(gl_framebuffer_binding_draw[0]) {
1722 if (driver_gl_version >= 2)
1723 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1724 newctx->gl_framebuffer_binding_draw[0]))
1726 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_DRAW_FRAMEBUFFER,
1727 newctx->gl_framebuffer_binding_draw[0]))
1730 STATE_COMPARE(gl_framebuffer_binding[0]) {
1731 if (driver_gl_version >= 2)
1732 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER,
1733 newctx->gl_framebuffer_binding[0]))
1735 CHECK_GL_ERROR(_orig_fastpath_glBindFramebufferOES(GL_FRAMEBUFFER,
1736 newctx->gl_framebuffer_binding[0]))
1739 STATE_COMPARE(gl_renderbuffer_binding[0]) {
1740 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER,
1741 newctx->gl_renderbuffer_binding[0]))
1745 //------------------//
1747 flag = oldctx->_bind_flag2 | newctx->_bind_flag2;
1749 STATE_COMPARE(gl_copy_read_buffer_binding[0]) {
1750 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_READ_BUFFER,
1751 newctx->gl_copy_read_buffer_binding[0]))
1753 STATE_COMPARE(gl_copy_write_buffer_binding[0]) {
1754 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_WRITE_BUFFER,
1755 newctx->gl_copy_write_buffer_binding[0]))
1757 STATE_COMPARE(gl_pixel_pack_buffer_binding[0]) {
1758 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_PACK_BUFFER,
1759 newctx->gl_pixel_pack_buffer_binding[0]))
1761 STATE_COMPARE(gl_pixel_unpack_buffer_binding[0]) {
1762 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
1763 newctx->gl_pixel_unpack_buffer_binding[0]))
1765 STATE_COMPARE(gl_transform_feedback_buffer_binding[0]) {
1766 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER,
1767 newctx->gl_transform_feedback_buffer_binding[0]))
1769 STATE_COMPARE(gl_uniform_buffer_binding[0]) {
1770 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_UNIFORM_BUFFER,
1771 newctx->gl_uniform_buffer_binding[0]))
1774 #ifdef COREGL_USE_MODULE_TRACEPATH
1775 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)",
1776 trace_hint_bindbuffers, 0);
1777 #endif // COREGL_USE_MODULE_TRACEPATH
1780 //------------------//
1783 #ifdef COREGL_USE_MODULE_TRACEPATH
1784 static void *trace_hint_enable_states = NULL;
1785 trace_hint_enable_states =
1786 tracepath_api_trace_begin("eglMakeCurrent(FP enable states)",
1787 trace_hint_enable_states, 0);
1788 #endif // COREGL_USE_MODULE_TRACEPATH
1790 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1792 STATE_COMPARE(gl_blend[0]) {
1793 if (newctx->gl_blend[0]) {
1794 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1796 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1798 STATE_COMPARE(gl_cull_face[0]) {
1799 if (newctx->gl_cull_face[0]) {
1800 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1802 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1804 STATE_COMPARE(gl_depth_test[0]) {
1805 if (newctx->gl_depth_test[0]) {
1806 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1808 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1810 STATE_COMPARE(gl_dither[0]) {
1811 if (newctx->gl_dither[0]) {
1812 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1814 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1819 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1821 STATE_COMPARE(gl_polygon_offset_fill[0]) {
1822 if (newctx->gl_polygon_offset_fill[0]) {
1823 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1825 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1827 STATE_COMPARE(gl_sample_alpha_to_coverage[0]) {
1828 if (newctx->gl_sample_alpha_to_coverage[0]) {
1829 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1831 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1833 STATE_COMPARE(gl_sample_coverage[0]) {
1834 if (newctx->gl_sample_coverage[0]) {
1835 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1837 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1839 STATE_COMPARE(gl_scissor_test[0]) {
1840 if (newctx->gl_scissor_test[0]) {
1841 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1843 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1845 STATE_COMPARE(gl_stencil_test[0]) {
1846 if (newctx->gl_stencil_test[0]) {
1847 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1849 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1854 flag = oldctx->_enable_flag3 | newctx->_enable_flag3;
1856 STATE_COMPARE(gl_primitive_restart_fixed_index[0]) {
1857 if (newctx->gl_primitive_restart_fixed_index[0]) {
1858 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1860 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1862 STATE_COMPARE(gl_rasterizer_discard[0]) {
1863 if (newctx->gl_rasterizer_discard[0]) {
1864 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_RASTERIZER_DISCARD))
1866 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_RASTERIZER_DISCARD))
1870 #ifdef COREGL_USE_MODULE_TRACEPATH
1871 tracepath_api_trace_end("eglMakeCurrent(FP enable states)",
1872 trace_hint_enable_states, 0);
1873 #endif // COREGL_USE_MODULE_TRACEPATH
1875 //------------------//
1877 #ifdef COREGL_USE_MODULE_TRACEPATH
1878 static void *trace_hint_clear_viewport = NULL;
1879 trace_hint_clear_viewport =
1880 tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)",
1881 trace_hint_clear_viewport, 0);
1882 #endif // COREGL_USE_MODULE_TRACEPATH
1884 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1887 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint)) {
1888 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1889 newctx->gl_viewport[1],
1890 newctx->gl_viewport[2],
1891 newctx->gl_viewport[3]))
1894 STATE_COMPARE(gl_current_program[0]) {
1895 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1897 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf)) {
1898 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1899 newctx->gl_color_clear_value[1],
1900 newctx->gl_color_clear_value[2],
1901 newctx->gl_color_clear_value[3]))
1907 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1909 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean)) {
1910 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1911 newctx->gl_color_writemask[1],
1912 newctx->gl_color_writemask[2],
1913 newctx->gl_color_writemask[3]))
1915 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf)) {
1916 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1917 newctx->gl_depth_range[1]))
1919 STATE_COMPARE(gl_depth_clear_value[0]) {
1920 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1922 STATE_COMPARE(gl_depth_func[0]) {
1923 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1925 STATE_COMPARE(gl_depth_writemask[0]) {
1926 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1928 STATE_COMPARE(gl_cull_face_mode[0]) {
1929 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1934 #ifdef COREGL_USE_MODULE_TRACEPATH
1935 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)",
1936 trace_hint_clear_viewport, 0);
1937 #endif // COREGL_USE_MODULE_TRACEPATH
1939 //------------------//
1941 #ifdef COREGL_USE_MODULE_TRACEPATH
1942 static void *trace_hint_bind_textures = NULL;
1943 trace_hint_bind_textures =
1944 tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)",
1945 trace_hint_bind_textures, 0);
1946 #endif // COREGL_USE_MODULE_TRACEPATH
1948 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1951 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++) {
1952 STATE_COMPARE(gl_tex_2d_state[i]) {
1953 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1954 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D,
1955 newctx->gl_tex_2d_state[i]))
1957 STATE_COMPARE(gl_tex_3d_state[i]) {
1958 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1959 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_3D,
1960 newctx->gl_tex_3d_state[i]))
1962 STATE_COMPARE(gl_tex_2d_array_state[i]) {
1963 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1964 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_ARRAY,
1965 newctx->gl_tex_2d_array_state[i]))
1967 STATE_COMPARE(gl_tex_cube_state[i]) {
1968 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1969 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP,
1970 newctx->gl_tex_cube_state[i]))
1972 STATE_COMPARE(gl_tex_external_oes_state[i]) {
1973 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1974 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_EXTERNAL_OES,
1975 newctx->gl_tex_external_oes_state[i]))
1979 // Restore active texture
1980 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1982 STATE_COMPARE(gl_generate_mipmap_hint[0]) {
1983 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT,
1984 newctx->gl_generate_mipmap_hint[0]))
1987 #ifdef COREGL_USE_MODULE_TRACEPATH
1988 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)",
1989 trace_hint_bind_textures, 0);
1990 #endif // COREGL_USE_MODULE_TRACEPATH
1992 //------------------//
1993 #ifdef COREGL_USE_MODULE_TRACEPATH
1994 static void *trace_hint_etc = NULL;
1995 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)",
1997 #endif // COREGL_USE_MODULE_TRACEPATH
1999 flag = oldctx->_blend_flag | newctx->_blend_flag;
2001 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf)) {
2002 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
2003 newctx->gl_blend_color[1],
2004 newctx->gl_blend_color[2],
2005 newctx->gl_blend_color[3]))
2007 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
2008 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
2009 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
2010 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0])) {
2011 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
2012 newctx->gl_blend_dst_rgb[0],
2013 newctx->gl_blend_src_alpha[0],
2014 newctx->gl_blend_dst_alpha[0]))
2016 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
2017 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0])) {
2018 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(
2019 newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
2024 //------------------//
2026 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
2028 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
2029 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
2030 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0])) {
2031 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
2032 newctx->gl_stencil_func[0],
2033 newctx->gl_stencil_ref[0],
2034 newctx->gl_stencil_value_mask[0]))
2036 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
2037 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0])
2039 (oldctx->gl_stencil_pass_depth_pass[0] !=
2040 newctx->gl_stencil_pass_depth_pass[0])) {
2041 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
2042 newctx->gl_stencil_fail[0],
2043 newctx->gl_stencil_pass_depth_fail[0],
2044 newctx->gl_stencil_pass_depth_pass[0]))
2047 STATE_COMPARE(gl_stencil_writemask[0]) {
2048 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT,
2049 newctx->gl_stencil_writemask[0]))
2055 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
2057 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
2058 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
2059 (oldctx->gl_stencil_back_value_mask[0] !=
2060 newctx->gl_stencil_back_value_mask[0])) {
2061 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
2062 newctx->gl_stencil_back_func[0],
2063 newctx->gl_stencil_back_ref[0],
2064 newctx->gl_stencil_back_value_mask[0]))
2066 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
2067 (oldctx->gl_stencil_back_pass_depth_fail[0] !=
2068 newctx->gl_stencil_back_pass_depth_fail[0]) ||
2069 (oldctx->gl_stencil_back_pass_depth_pass[0] !=
2070 newctx->gl_stencil_back_pass_depth_pass[0])) {
2071 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
2072 newctx->gl_stencil_back_fail[0],
2073 newctx->gl_stencil_back_pass_depth_fail[0],
2074 newctx->gl_stencil_back_pass_depth_pass[0]))
2077 STATE_COMPARE(gl_stencil_back_writemask[0]) {
2078 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK,
2079 newctx->gl_stencil_back_writemask[0]))
2081 STATE_COMPARE(gl_stencil_clear_value[0]) {
2082 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
2086 //------------------//
2088 flag = oldctx->_pixel_flag1 | newctx->_pixel_flag1;
2090 STATE_COMPARE(gl_pack_row_length[0]) {
2091 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ROW_LENGTH,
2092 newctx->gl_pack_row_length[0]))
2094 STATE_COMPARE(gl_pack_skip_rows[0]) {
2095 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_ROWS,
2096 newctx->gl_pack_skip_rows[0]))
2098 STATE_COMPARE(gl_pack_skip_pixels[0]) {
2099 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_PIXELS,
2100 newctx->gl_pack_skip_pixels[0]))
2102 STATE_COMPARE(gl_pack_alignment[0]) {
2103 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT,
2104 newctx->gl_pack_alignment[0]))
2109 flag = oldctx->_pixel_flag2 | newctx->_pixel_flag2;
2111 STATE_COMPARE(gl_unpack_row_length[0]) {
2112 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ROW_LENGTH,
2113 newctx->gl_unpack_row_length[0]))
2115 STATE_COMPARE(gl_unpack_skip_rows[0]) {
2116 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_ROWS,
2117 newctx->gl_unpack_skip_rows[0]))
2119 STATE_COMPARE(gl_unpack_skip_pixels[0]) {
2120 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_PIXELS,
2121 newctx->gl_unpack_skip_pixels[0]))
2123 STATE_COMPARE(gl_unpack_alignment[0]) {
2124 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT,
2125 newctx->gl_unpack_alignment[0]))
2127 STATE_COMPARE(gl_unpack_image_height[0]) {
2128 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,
2129 newctx->gl_unpack_image_height[0]))
2131 STATE_COMPARE(gl_unpack_skip_images[0]) {
2132 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_IMAGES,
2133 newctx->gl_unpack_skip_images[0]))
2137 //------------------//
2139 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
2141 STATE_COMPARE(gl_front_face[0]) {
2142 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
2144 STATE_COMPARE(gl_line_width[0]) {
2145 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
2147 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0])
2149 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0])) {
2150 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(
2151 newctx->gl_polygon_offset_factor[0],
2152 newctx->gl_polygon_offset_units[0]))
2154 if ((oldctx->gl_sample_coverage_value[0] !=
2155 newctx->gl_sample_coverage_value[0]) ||
2156 (oldctx->gl_sample_coverage_invert[0] !=
2157 newctx->gl_sample_coverage_invert[0])) {
2158 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(
2159 newctx->gl_sample_coverage_value[0],
2160 newctx->gl_sample_coverage_invert[0]))
2162 STATE_COMPARE(gl_fragment_shader_derivative_hint[0]) {
2163 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES,
2164 newctx->gl_fragment_shader_derivative_hint[0]))
2169 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
2171 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint)) {
2172 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
2173 newctx->gl_scissor_box[1],
2174 newctx->gl_scissor_box[2],
2175 newctx->gl_scissor_box[3]))
2180 flag = oldctx->_misc_flag3 | newctx->_misc_flag3;
2182 STATE_COMPARE(gl_read_buffer[0]) {
2183 CHECK_GL_ERROR(_orig_fastpath_glReadBuffer(newctx->gl_read_buffer[0]))
2185 STATES_COMPARE(gl_draw_buffers, 16 * sizeof(GLenum)) {
2186 int drawBuffSize = 16;
2187 /* If the context has only default framebuffer, then size of glDrawBuffers can only be 1 */
2188 if (fastpath_ostate_has_object_type(&newctx->ostate,
2189 GL_OBJECT_TYPE_FRAMEBUFFER) == 0) {
2193 CHECK_GL_ERROR(_orig_fastpath_glDrawBuffers(drawBuffSize,
2194 newctx->gl_draw_buffers))
2197 if (oldctx->gl_transform_feedback_active[0] == GL_TRUE &&
2198 oldctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2199 CHECK_GL_ERROR(_orig_fastpath_glPauseTransformFeedback())
2201 STATE_COMPARE(gl_transform_feedback_binding[0]) {
2202 CHECK_GL_ERROR(_orig_fastpath_glBindTransformFeedback(GL_TRANSFORM_FEEDBACK,
2203 newctx->gl_transform_feedback_binding[0]))
2205 if (newctx->gl_transform_feedback_active[0] == GL_TRUE &&
2206 newctx->gl_transform_feedback_paused[0] == GL_FALSE) {
2207 CHECK_GL_ERROR(_orig_fastpath_glResumeTransformFeedback())
2211 #ifdef COREGL_USE_MODULE_TRACEPATH
2212 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
2213 #endif // COREGL_USE_MODULE_TRACEPATH
2220 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
2221 if (unlikely(trace_state_flag == 1))
2222 fastpath_dump_context_states(newctx, 0);
2223 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
2225 #undef STATE_COMPARE
2226 #undef STATES_COMPARE