From: Jinhyung Jo Date: Thu, 7 Dec 2017 07:46:56 +0000 (+0900) Subject: YaGL: hot fix web app broken issue on macOS. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=708bf5de36608796e1046a58ada92f796156ac54;p=sdk%2Femulator%2Fqemu.git YaGL: hot fix web app broken issue on macOS. A bug in emulator-yagl causes a shader compile error on macOS. I make an emergency patch for this specific situation. Note: If we can build a new platform(emulator-yagl with patch), this commit can be reverted. Change-Id: I706c4067af4d6721b8aa6c69832bce7580252ca3 Signed-off-by: Jinhyung Jo --- diff --git a/hw/yagl/yagl_apis/gles/yagl_host_gles_calls.c b/hw/yagl/yagl_apis/gles/yagl_host_gles_calls.c index af3efbd..66bd7a4 100644 --- a/hw/yagl/yagl_apis/gles/yagl_host_gles_calls.c +++ b/hw/yagl/yagl_apis/gles/yagl_host_gles_calls.c @@ -1724,7 +1724,73 @@ void yagl_host_glDetachShader(GLuint program, void yagl_host_glCompileShader(GLuint shader) { +#ifndef CONFIG_DARWIN gles_api_ts->driver->CompileShader(yagl_gles_object_get(shader)); +#else + GLint tmp = 0; + + YAGL_LOG_FUNC_SET(glCompileShader); + + gles_api_ts->driver->CompileShader(yagl_gles_object_get(shader)); + + gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_COMPILE_STATUS, &tmp); + if (tmp == GL_FALSE) { + char *buff; + char *substring; + const char textue2d_err[] = "undeclared identifier 'texture2D'"; + const char texture_lookup_define[] = "#define TextureLookup texture2D"; + + tmp = 0; + gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_INFO_LOG_LENGTH, &tmp); + buff = g_malloc0(tmp); + gles_api_ts->driver->GetShaderInfoLog(yagl_gles_object_get(shader), tmp, NULL, buff); + if (gles_api_ts->driver->gl_version < yagl_gl_3_2 || + strstr(buff, textue2d_err) == NULL) { + YAGL_LOG_ERROR("Unable to compile shader %s", buff); + g_free(buff); + return; + } + YAGL_LOG_DEBUG("Unable to compile shader %s", buff); + g_free(buff); + + tmp = 0; + gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_SHADER_SOURCE_LENGTH, &tmp); + buff = g_malloc0(tmp); + gles_api_ts->driver->GetShaderSource(yagl_gles_object_get(shader), tmp, NULL, buff); + YAGL_LOG_DEBUG("Shader Source: \n%s", buff); + + substring = strstr(buff, texture_lookup_define); + if (substring) { + const GLchar *strings[1]; + GLint lenghts[1]; + + /* texture2D -> texture\n\n */ + substring[strlen(texture_lookup_define) - 1] = '\n'; + substring[strlen(texture_lookup_define) - 2] = '\n'; + + strings[0] = buff; + lenghts[0] = tmp - 1; + + gles_api_ts->driver->ShaderSource(yagl_gles_object_get(shader), + 1, + strings, + lenghts); + gles_api_ts->driver->CompileShader(yagl_gles_object_get(shader)); + gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_COMPILE_STATUS, &tmp); + if (!tmp) { + YAGL_LOG_ERROR("Unable to compile the patched shader source: \n%s", buff); + g_free(buff); + + tmp = 0; + gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_INFO_LOG_LENGTH, &tmp); + buff = g_malloc0(tmp); + gles_api_ts->driver->GetShaderInfoLog(yagl_gles_object_get(shader), tmp, NULL, buff); + YAGL_LOG_ERROR("Cause of compilation failure: %s", buff); + } + } + g_free(buff); + } +#endif } void yagl_host_glBindAttribLocation(GLuint program, diff --git a/hw/yagl/yagl_drivers/gles_ogl/yagl_gles_ogl.c b/hw/yagl/yagl_drivers/gles_ogl/yagl_gles_ogl.c index 15cff43..70e2558 100644 --- a/hw/yagl/yagl_drivers/gles_ogl/yagl_gles_ogl.c +++ b/hw/yagl/yagl_drivers/gles_ogl/yagl_gles_ogl.c @@ -117,6 +117,7 @@ struct yagl_gles_driver *yagl_gles_ogl_create(struct yagl_dyn_lib *dyn_lib, YAGL_GLES_OGL_GET_PROC(driver, GetProgramInfoLog, glGetProgramInfoLog); YAGL_GLES_OGL_GET_PROC(driver, GetShaderiv, glGetShaderiv); YAGL_GLES_OGL_GET_PROC(driver, GetShaderInfoLog, glGetShaderInfoLog); + YAGL_GLES_OGL_GET_PROC(driver, GetShaderSource, glGetShaderSource); YAGL_GLES_OGL_GET_PROC(driver, GetUniformfv, glGetUniformfv); YAGL_GLES_OGL_GET_PROC(driver, GetUniformiv, glGetUniformiv); YAGL_GLES_OGL_GET_PROC(driver, GetUniformLocation, glGetUniformLocation); diff --git a/hw/yagl/yagl_gles_driver.h b/hw/yagl/yagl_gles_driver.h index 22eafbd..6e64f7a 100644 --- a/hw/yagl/yagl_gles_driver.h +++ b/hw/yagl/yagl_gles_driver.h @@ -183,6 +183,7 @@ struct yagl_gles_driver YAGL_GLES_DRIVER_FUNC4(GetProgramInfoLog, GLuint, GLsizei, GLsizei*, GLchar*, program, bufsize, length, infolog) YAGL_GLES_DRIVER_FUNC3(GetShaderiv, GLuint, GLenum, GLint*, shader, pname, params) YAGL_GLES_DRIVER_FUNC4(GetShaderInfoLog, GLuint, GLsizei, GLsizei*, GLchar*, shader, bufsize, length, infolog) + YAGL_GLES_DRIVER_FUNC4(GetShaderSource, GLuint, GLsizei, GLsizei*, GLchar*, shader, bufsize, length, source) YAGL_GLES_DRIVER_FUNC3(GetUniformfv, GLuint, GLint, GLfloat*, program, location, params) YAGL_GLES_DRIVER_FUNC3(GetUniformiv, GLuint, GLint, GLint*, program, location, params) YAGL_GLES_DRIVER_FUNC_RET2(int, GetUniformLocation, GLuint, const GLchar*, program, name)