summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-02-13 17:42:10 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-02-13 20:11:22 +0900
commit0a2d8d834ab3b7f0a01b4905250087526435bdbe (patch)
tree675c849da9b0ac912784be25eecf645022d2d003 /src
parent358f2898c5ee321caad32a4779cc577272ec9007 (diff)
evas gl: Partially fix MSAA for GLES 3 drivers
MSAA (multisampled_render_to_texture) support was implemented with GLES 2 in mind, but for GLES 3 it comes as a core feature, not as an extension. Also it relies on renderbuffers, not textures. GL is awesome. Note: MSAA still doesn't work!
Diffstat (limited to 'src')
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_common.h2
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_context.c30
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_core.c90
3 files changed, 79 insertions, 43 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h b/src/modules/evas/engines/gl_common/evas_gl_common.h
index 5a10fd51d7..59549efe84 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -543,6 +543,7 @@ typedef void (*Evas_Gl_Symbols)(void *(*GetProcAddress)(const char *sym));
543 543
544EAPI void __evas_gl_err(int err, const char *file, const char *func, int line, const char *op); 544EAPI void __evas_gl_err(int err, const char *file, const char *func, int line, const char *op);
545 545
546int evas_gl_common_version_check(void);
546void evas_gl_common_tiling_start(Evas_Engine_GL_Context *gc, 547void evas_gl_common_tiling_start(Evas_Engine_GL_Context *gc,
547 int rot, int gw, int gh, 548 int rot, int gw, int gh,
548 int cx, int cy, int cw, int ch, 549 int cx, int cy, int cw, int ch,
@@ -709,6 +710,7 @@ extern void (*glsym_glProgramParameteri) (GLuint a, GLuint b, GLint d);
709extern void (*glsym_glReleaseShaderCompiler)(void); 710extern void (*glsym_glReleaseShaderCompiler)(void);
710extern void *(*glsym_glMapBuffer) (GLenum a, GLenum b); 711extern void *(*glsym_glMapBuffer) (GLenum a, GLenum b);
711extern GLboolean (*glsym_glUnmapBuffer) (GLenum a); 712extern GLboolean (*glsym_glUnmapBuffer) (GLenum a);
713extern void (*glsym_glRenderbufferStorageMultisample)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
712 714
713#ifdef GL_GLES 715#ifdef GL_GLES
714EAPI void * evas_gl_common_eglCreateImage (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list); 716EAPI void * evas_gl_common_eglCreateImage (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
diff --git a/src/modules/evas/engines/gl_common/evas_gl_context.c b/src/modules/evas/engines/gl_common/evas_gl_context.c
index 602dac49c9..3d984e7e63 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_context.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_context.c
@@ -31,6 +31,7 @@ void *(*glsym_glMapBuffer) (GLenum a, GLenum b) = NULL;
31GLboolean (*glsym_glUnmapBuffer) (GLenum a) = NULL; 31GLboolean (*glsym_glUnmapBuffer) (GLenum a) = NULL;
32void (*glsym_glStartTiling) (GLuint a, GLuint b, GLuint c, GLuint d, GLuint e) = NULL; 32void (*glsym_glStartTiling) (GLuint a, GLuint b, GLuint c, GLuint d, GLuint e) = NULL;
33void (*glsym_glEndTiling) (GLuint a) = NULL; 33void (*glsym_glEndTiling) (GLuint a) = NULL;
34void (*glsym_glRenderbufferStorageMultisample)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) = NULL;
34 35
35const char *(*glsym_glGetStringi) (GLenum name, GLuint index) = NULL; 36const char *(*glsym_glGetStringi) (GLenum name, GLuint index) = NULL;
36 37
@@ -289,6 +290,8 @@ evas_gl_symbols(void *(*GetProcAddress)(const char *name))
289 FINDSYM(glsym_glUnmapBuffer, "glUnmapBufferEXT", NULL, glsym_func_boolean); 290 FINDSYM(glsym_glUnmapBuffer, "glUnmapBufferEXT", NULL, glsym_func_boolean);
290 } 291 }
291 292
293 FINDSYM(glsym_glRenderbufferStorageMultisample, "glRenderbufferStorageMultisample", NULL, glsym_func_void);
294
292#ifdef GL_GLES 295#ifdef GL_GLES
293// yes - gl core looking for egl stuff. i know it's odd. a reverse-layer thing 296// yes - gl core looking for egl stuff. i know it's odd. a reverse-layer thing
294// but it will work as the egl/glx layer calls gl core common stuff and thus 297// but it will work as the egl/glx layer calls gl core common stuff and thus
@@ -489,15 +492,14 @@ matrix_ortho(GLfloat *m,
489 m[15] = (m[3] * tx) + (m[7] * ty) + orth; 492 m[15] = (m[3] * tx) + (m[7] * ty) + orth;
490} 493}
491 494
492static int 495int
493_evas_gl_common_version_check(int *gles_ver) 496evas_gl_common_version_check(void)
494{ 497{
495 char *version; 498 char *version;
496 char *tmp; 499 char *tmp;
497 char *tmp2; 500 char *tmp2;
498 int major = 0; 501 int major = 0;
499 int minor = 0; 502 int minor = 0;
500 *gles_ver = 0;
501 503
502 /* 504 /*
503 * glGetString returns a string describing the current GL connection. 505 * glGetString returns a string describing the current GL connection.
@@ -539,8 +541,7 @@ _evas_gl_common_version_check(int *gles_ver)
539 if (strstr(version, "OpenGL ES 3")) 541 if (strstr(version, "OpenGL ES 3"))
540 { 542 {
541 /* Supported */ 543 /* Supported */
542 *gles_ver = 3; 544 return 3;
543 return 1;
544 } 545 }
545 546
546 /* OpenGL ES 2.* ? */ 547 /* OpenGL ES 2.* ? */
@@ -548,8 +549,7 @@ _evas_gl_common_version_check(int *gles_ver)
548 if (strstr(version, "OpenGL ES ")) 549 if (strstr(version, "OpenGL ES "))
549 { 550 {
550 /* Supported */ 551 /* Supported */
551 *gles_ver = 2; 552 return 2;
552 return 1;
553 } 553 }
554 554
555 /* 555 /*
@@ -594,19 +594,16 @@ _evas_gl_common_version_check(int *gles_ver)
594 { 594 {
595 /* Map GL to GLES version: Refer http://en.wikipedia.org/wiki/OpenGL_ES */ 595 /* Map GL to GLES version: Refer http://en.wikipedia.org/wiki/OpenGL_ES */
596 if ((major >= 4) && (minor >= 3)) 596 if ((major >= 4) && (minor >= 3))
597 *gles_ver = 3; 597 return 3;
598 else if ((major > 3) || ((major == 3) && (minor >= 3))) /* >= 3.3 */ 598 else if ((major > 3) || ((major == 3) && (minor >= 3))) /* >= 3.3 */
599 { 599 {
600 const char *exts = NULL; 600 const char *exts = NULL;
601 int num = 0; 601 int num = 0;
602
602 if (_has_ext("GL_ARB_ES3_compatibility", &exts, &num)) 603 if (_has_ext("GL_ARB_ES3_compatibility", &exts, &num))
603 *gles_ver = 3; 604 return 3;
604 else
605 *gles_ver = 2;
606 } 605 }
607 else 606 return 2; /* emulated support */
608 *gles_ver = 2; /* emulated support */
609 return 1;
610 } 607 }
611 608
612 return 0; 609 return 0;
@@ -790,8 +787,9 @@ evas_gl_common_context_new(void)
790 if (!glsym_glGetStringi) 787 if (!glsym_glGetStringi)
791 glsym_glGetStringi = dlsym(RTLD_DEFAULT, "glGetStringi"); 788 glsym_glGetStringi = dlsym(RTLD_DEFAULT, "glGetStringi");
792 789
793 if (!_evas_gl_common_version_check(&gles_version)) 790 gles_version = evas_gl_common_version_check();
794 return NULL; 791 if (!gles_version) return NULL;
792
795 gc = calloc(1, sizeof(Evas_Engine_GL_Context)); 793 gc = calloc(1, sizeof(Evas_Engine_GL_Context));
796 if (!gc) return NULL; 794 if (!gc) return NULL;
797 795
diff --git a/src/modules/evas/engines/gl_common/evas_gl_core.c b/src/modules/evas/engines/gl_common/evas_gl_core.c
index c81d8ec3a7..24e6a48b48 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_core.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_core.c
@@ -266,23 +266,25 @@ _texture_destroy(GLuint *tex)
266static void 266static void
267_texture_attach_2d(GLuint tex, GLenum attach, GLenum attach2, int samples, Evas_GL_Context_Version version) 267_texture_attach_2d(GLuint tex, GLenum attach, GLenum attach2, int samples, Evas_GL_Context_Version version)
268{ 268{
269 if (samples) 269 if (samples && (version == EVAS_GL_GLES_2_X))
270 { 270 {
271#ifdef GL_GLES 271#ifdef GL_GLES
272 //<<< TODO : CHECK EXTENSION SUPPORT>>> 272 if (EXT_FUNC(glFramebufferTexture2DMultisample))
273 EXT_FUNC(glFramebufferTexture2DMultisample)(GL_FRAMEBUFFER, 273 {
274 attach, 274 EXT_FUNC(glFramebufferTexture2DMultisample)(GL_FRAMEBUFFER,
275 GL_TEXTURE_2D, tex, 275 attach,
276 0, samples); 276 GL_TEXTURE_2D, tex,
277 277 0, samples);
278 if (attach2) 278
279 EXT_FUNC(glFramebufferTexture2DMultisample)(GL_FRAMEBUFFER, 279 if (attach2)
280 attach2, 280 EXT_FUNC(glFramebufferTexture2DMultisample)(GL_FRAMEBUFFER,
281 GL_TEXTURE_2D, tex, 281 attach2,
282 0, samples); 282 GL_TEXTURE_2D, tex,
283#else 283 0, samples);
284 ERR("MSAA not supported. Should not have come in here...!"); 284 }
285 else
285#endif 286#endif
287 ERR("MSAA not supported. Should not have come in here...!");
286 } 288 }
287 else if (version == EVAS_GL_GLES_1_X) 289 else if (version == EVAS_GL_GLES_1_X)
288 { 290 {
@@ -435,17 +437,22 @@ _renderbuffer_allocate(GLuint buf, GLenum fmt, int w, int h, int samples)
435{ 437{
436 glBindRenderbuffer(GL_RENDERBUFFER, buf); 438 glBindRenderbuffer(GL_RENDERBUFFER, buf);
437 if (samples) 439 if (samples)
440 {
441 if (glsym_glRenderbufferStorageMultisample)
442 glsym_glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, fmt, w, h);
443 else
444 {
438#ifdef GL_GLES 445#ifdef GL_GLES
439 EXT_FUNC(glRenderbufferStorageMultisample)(GL_RENDERBUFFER, samples, fmt, w, h); 446 if (EXT_FUNC(glRenderbufferStorageMultisample))
440#else 447 EXT_FUNC(glRenderbufferStorageMultisample)(GL_RENDERBUFFER, samples, fmt, w, h);
441 ERR("MSAA not supported. Should not have come in here...!"); 448 else
442#endif 449#endif
450 ERR("MSAA not supported. Should not have come in here...!");
451 }
452 }
443 else 453 else
444 glRenderbufferStorage(GL_RENDERBUFFER, fmt, w, h); 454 glRenderbufferStorage(GL_RENDERBUFFER, fmt, w, h);
445 glBindRenderbuffer(GL_RENDERBUFFER, 0); 455 glBindRenderbuffer(GL_RENDERBUFFER, 0);
446
447 return;
448 samples = 0;
449} 456}
450 457
451static void 458static void
@@ -487,17 +494,21 @@ _fbo_surface_cap_test(GLint color_ifmt, GLenum color_fmt,
487 int depth_stencil = 0; 494 int depth_stencil = 0;
488 int fb_status = 0; 495 int fb_status = 0;
489 int w = 2, h = 2; // Test it with a simple (2,2) surface. Should I test it with NPOT? 496 int w = 2, h = 2; // Test it with a simple (2,2) surface. Should I test it with NPOT?
497 Evas_GL_Context_Version ver = evas_gl_common_version_check();
490 498
491 // Gen FBO 499 // Gen FBO
492 glGenFramebuffers(1, &fbo); 500 glGenFramebuffers(1, &fbo);
493 glBindFramebuffer(GL_FRAMEBUFFER, fbo); 501 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
494 502
503 // FIXME: GLES 3 support for MSAA is NOT IMPLEMENTED!
504 // Needs to use RenderbufferStorageMultisample + FramebufferRenderbuffer
505
495 // Color Buffer Texture 506 // Color Buffer Texture
496 if ((color_ifmt) && (color_fmt)) 507 if ((color_ifmt) && (color_fmt))
497 { 508 {
498 _texture_create(&color_buf); 509 _texture_create(&color_buf);
499 _texture_allocate_2d(color_buf, color_ifmt, color_fmt, GL_UNSIGNED_BYTE, w, h); 510 _texture_allocate_2d(color_buf, color_ifmt, color_fmt, GL_UNSIGNED_BYTE, w, h);
500 _texture_attach_2d(color_buf, GL_COLOR_ATTACHMENT0, 0, mult_samples, EVAS_GL_GLES_2_X); 511 _texture_attach_2d(color_buf, GL_COLOR_ATTACHMENT0, 0, mult_samples, ver);
501 } 512 }
502 513
503 // Check Depth_Stencil Format First 514 // Check Depth_Stencil Format First
@@ -882,8 +893,10 @@ error:
882static int 893static int
883_surface_cap_init(void *eng_data) 894_surface_cap_init(void *eng_data)
884{ 895{
896 int gles_version;
885 int ret = 0; 897 int ret = 0;
886 int max_size = 0; 898 int max_size = 0;
899 int max_samples = 0;
887 900
888 // Do internal make current 901 // Do internal make current
889 if (!_internal_resource_make_current(eng_data, NULL, NULL)) 902 if (!_internal_resource_make_current(eng_data, NULL, NULL))
@@ -899,11 +912,17 @@ _surface_cap_init(void *eng_data)
899 evgl_engine->caps.max_h = max_size; 912 evgl_engine->caps.max_h = max_size;
900 DBG("Max Surface Width: %d Height: %d", evgl_engine->caps.max_w, evgl_engine->caps.max_h); 913 DBG("Max Surface Width: %d Height: %d", evgl_engine->caps.max_w, evgl_engine->caps.max_h);
901 914
915 gles_version = evas_gl_common_version_check();
916
902 // Check for MSAA support 917 // Check for MSAA support
918 if (gles_version == 3)
919 {
920 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
921 INF("MSAA support for GLES 3 is not implemented yet!");
922 max_samples = 0;
923 }
903#ifdef GL_GLES 924#ifdef GL_GLES
904 int max_samples = 0; 925 else if (EXTENSION_SUPPORT(IMG_multisampled_render_to_texture))
905
906 if (EXTENSION_SUPPORT(IMG_multisampled_render_to_texture))
907 { 926 {
908 glGetIntegerv(GL_MAX_SAMPLES_IMG, &max_samples); 927 glGetIntegerv(GL_MAX_SAMPLES_IMG, &max_samples);
909 } 928 }
@@ -911,6 +930,16 @@ _surface_cap_init(void *eng_data)
911 { 930 {
912 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_samples); 931 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_samples);
913 } 932 }
933 else
934 {
935 const char *exts = (const char *) glGetString(GL_EXTENSIONS);
936
937 if (exts && strstr(exts, "EXT_multisampled_render_to_texture"))
938 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_samples);
939 else if (exts && strstr(exts, "IMG_multisampled_render_to_texture"))
940 glGetIntegerv(GL_MAX_SAMPLES_IMG, &max_samples);
941 }
942#endif
914 943
915 if (max_samples >= 2) 944 if (max_samples >= 2)
916 { 945 {
@@ -919,7 +948,6 @@ _surface_cap_init(void *eng_data)
919 evgl_engine->caps.msaa_samples[2] = max_samples; 948 evgl_engine->caps.msaa_samples[2] = max_samples;
920 evgl_engine->caps.msaa_supported = 1; 949 evgl_engine->caps.msaa_supported = 1;
921 } 950 }
922#endif
923 951
924 // Load Surface Cap 952 // Load Surface Cap
925 if (!_surface_cap_cache_load()) 953 if (!_surface_cap_cache_load())
@@ -1493,7 +1521,8 @@ try_again:
1493 1521
1494 if (cfg_index < 0) 1522 if (cfg_index < 0)
1495 { 1523 {
1496 ERR("Unable to find a matching config format."); 1524 ERR("Unable to find a matching config format (depth:%d, stencil:%d, msaa:%d)",
1525 depth_size, stencil_bit, msaa_samples);
1497 if ((stencil_bit > 8) || (depth_size > 24)) 1526 if ((stencil_bit > 8) || (depth_size > 24))
1498 { 1527 {
1499 INF("Please note that Evas GL might not support 32-bit depth or " 1528 INF("Please note that Evas GL might not support 32-bit depth or "
@@ -1508,6 +1537,13 @@ try_again:
1508 DBG("Fallback to depth:%d, stencil:%d", depth_size, stencil_bit); 1537 DBG("Fallback to depth:%d, stencil:%d", depth_size, stencil_bit);
1509 goto try_again; 1538 goto try_again;
1510 } 1539 }
1540 else if (msaa_samples > 0)
1541 {
1542 msaa_samples /= 2;
1543 if (msaa_samples == 1) msaa_samples = 0;
1544 DBG("Fallback to msaa:%d", msaa_samples);
1545 goto try_again;
1546 }
1511 return 0; 1547 return 0;
1512 } 1548 }
1513 else 1549 else