From 26fcb34ea2911558a792be107b0fb4370875ded4 Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Mon, 4 Aug 2014 16:18:18 +0100 Subject: [PATCH] Fixing the text shader default prefix to match actual shader [Problem] [Cause] [Solution] Change-Id: I119e3d055f66c8951fad9dc411c9f1a6d92be400 --- .../dali-test-suite-utils/test-gl-abstraction.h | 5 ++ automated-tests/src/dali/utc-Dali-ShaderEffect.cpp | 80 ++++++++-------------- .../render/shader-source/custom-font-prefix.txt | 3 - .../render/shader-source/distance-field-font.txt | 3 + 4 files changed, 35 insertions(+), 56 deletions(-) diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h index 13705f7..be9a3cf 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h @@ -761,6 +761,11 @@ public: } } + inline std::string GetShaderSource(GLuint shader) + { + return mShaderSources[shader]; + } + inline void StencilFunc(GLenum func, GLint ref, GLuint mask) { } diff --git a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp index 43735f3..e57f493 100644 --- a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp +++ b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp @@ -37,26 +37,16 @@ namespace { static const char* VertexSource = -"void main()\n" -"{\n" -" gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n" -" vTexCoord = aTexCoord;\n" -"}\n"; +"This is a custom vertex shader\n" +"made on purpose to look nothing like a normal vertex shader inside dali\n"; static const char* FragmentSource = -"void main()\n" -"{\n" -" gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n" -"}\n"; +"This is a custom fragment shader\n" +"made on purpose to look nothing like a normal fragment shader inside dali\n"; static const char* FragmentSourceUsingExtensions = -"void main()\n" -"{\n" -" float floatValue = 0.5f;\n" -" float test = fwidth(floatValue);\n" -" gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n" -" gl_FragColor.a *= test;\n" -"}\n"; +"This is a custom fragment shader using extensions\n" +"made on purpose to look nothing like a normal fragment shader inside dali\n"; const int GETSOURCE_BUFFER_SIZE = 0x10000; @@ -202,26 +192,25 @@ int UtcDaliShaderEffectMethodNew04(void) GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled(); bool testResult = false; - // we should have compiled 4 shaders. - if (lastShaderCompiledAfter - lastShaderCompiledBefore == 4) - { - char testVertexSourceResult[GETSOURCE_BUFFER_SIZE]; - char testFragmentSourceResult[GETSOURCE_BUFFER_SIZE]; + // we should have compiled 2 shaders. + DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION ); - // we are interested in the first two. - GLuint vertexShaderId = lastShaderCompiledBefore + 1; - GLuint fragmentShaderId = lastShaderCompiledBefore + 2; + char testVertexSourceResult[GETSOURCE_BUFFER_SIZE]; + char testFragmentSourceResult[GETSOURCE_BUFFER_SIZE]; - GLsizei lengthVertexResult; - GLsizei lengthFragmentResult; + // we are interested in the first two. + GLuint vertexShaderId = lastShaderCompiledBefore + 1; + GLuint fragmentShaderId = lastShaderCompiledBefore + 2; - application.GetGlAbstraction().GetShaderSource(vertexShaderId, GETSOURCE_BUFFER_SIZE, &lengthVertexResult, testVertexSourceResult); - application.GetGlAbstraction().GetShaderSource(fragmentShaderId, GETSOURCE_BUFFER_SIZE, &lengthFragmentResult, testFragmentSourceResult); + GLsizei lengthVertexResult; + GLsizei lengthFragmentResult; - int vertexShaderHasPrefix = strncmp(testVertexSourceResult, "#define ", strlen("#define ")); - int fragmentShaderHasPrefix = strncmp(testFragmentSourceResult, "#define ", strlen("#define ")); - testResult = (vertexShaderHasPrefix == 0) && (fragmentShaderHasPrefix == 0); - } + application.GetGlAbstraction().GetShaderSource(vertexShaderId, GETSOURCE_BUFFER_SIZE, &lengthVertexResult, testVertexSourceResult); + application.GetGlAbstraction().GetShaderSource(fragmentShaderId, GETSOURCE_BUFFER_SIZE, &lengthFragmentResult, testFragmentSourceResult); + + int vertexShaderHasPrefix = strncmp(testVertexSourceResult, "#define ", strlen("#define ")); + int fragmentShaderHasPrefix = strncmp(testFragmentSourceResult, "#define ", strlen("#define ")); + testResult = (vertexShaderHasPrefix == 0) && (fragmentShaderHasPrefix == 0); DALI_TEST_CHECK(testResult); } @@ -287,24 +276,14 @@ int UtcDaliShaderEffectMethodDelete01(void) { TestApplication application; - // Only want to test the first few characters - std::string customFontPrefixVertShader = - "\n" - " attribute mediump vec3 aPosition;\n" - " attribute mediump vec2 aTexCoord;\n"; - - // get the default shaders built, this is not required but makes it // easier to debug the TET case and isolate the custom shader compilation. application.SendNotification(); application.Render(); - application.SendNotification(); - application.Render(); - // create a new shader effect // the vertex and fragment shader will be cached in the ShaderFactory - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource); + ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); // destroy the shader effect effect.Reset(); @@ -321,20 +300,15 @@ int UtcDaliShaderEffectMethodDelete01(void) // get the vertex shader (compiled before fragment shader). // this last shaders compiled is for text. - GLuint vertexShaderId = lastShaderCompiled-1; - GLsizei lengthVertexResult; + GLuint vertexShaderId = lastShaderCompiled - 1; - char testVertexSourceResult[GETSOURCE_BUFFER_SIZE]; - application.GetGlAbstraction().GetShaderSource(vertexShaderId, GETSOURCE_BUFFER_SIZE, &lengthVertexResult, testVertexSourceResult); - - // compare the first 40 bytes of the vertex shader sent to be compiled, with - // the shader string that ended up being compiled (in the render task) + // compare the vertex shader sent to be compiled, with the shader string that ended up being compiled // this is to confirm the string hasn't been deleted / corrupted. - int testPassed = strncmp( testVertexSourceResult , customFontPrefixVertShader.c_str(), 40 ) ; + std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( vertexShaderId ); + DALI_TEST_EQUALS( VertexSource, + actualVertexShader.substr( actualVertexShader.length() - strlen( VertexSource ) ), TEST_LOCATION ); - DALI_TEST_CHECK( testPassed == 0 ); END_TEST; - } int UtcDaliShaderEffectMethodSetUniformFloat(void) diff --git a/dali/internal/render/shader-source/custom-font-prefix.txt b/dali/internal/render/shader-source/custom-font-prefix.txt index eb0b269..6bf642d 100644 --- a/dali/internal/render/shader-source/custom-font-prefix.txt +++ b/dali/internal/render/shader-source/custom-font-prefix.txt @@ -23,9 +23,6 @@ - - #extension GL_OES_standard_derivatives : enable - uniform mediump sampler2D sTexture; uniform highp vec4 sTextureRect; uniform lowp vec4 uColor; diff --git a/dali/internal/render/shader-source/distance-field-font.txt b/dali/internal/render/shader-source/distance-field-font.txt index 23de397..267852b 100644 --- a/dali/internal/render/shader-source/distance-field-font.txt +++ b/dali/internal/render/shader-source/distance-field-font.txt @@ -3,7 +3,10 @@ attribute mediump vec3 aPosition; attribute mediump vec2 aTexCoord; + uniform mediump mat4 uModelView; + uniform mediump mat4 uProjection; uniform mediump mat4 uMvpMatrix; + uniform mediump mat3 uNormalMatrix; uniform lowp vec4 uColor; uniform lowp vec4 uTextColor; -- 2.7.4