Changeset 104255 in webkit


Ignore:
Timestamp:
Jan 5, 2012 5:29:15 PM (12 years ago)
Author:
noam.rosenthal@nokia.com
Message:

[Qt][Texmap] Convert shaders in TextureMapperGL to use a macro
https://bugs.webkit.org/show_bug.cgi?id=75598

Use VERTEX_SHADER() and FRAGMENT_SHADER() macros, instead of quoted string literals when
declaring shaders in TextureMapperGL.

We need two macros to account for the differences between OpenGL and OpenGL ES2.

Reviewed by Martin Robinson.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r104254 r104255  
     12012-01-05  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Qt][Texmap] Convert shaders in TextureMapperGL to use a macro
     4        https://bugs.webkit.org/show_bug.cgi?id=75598
     5
     6        Use VERTEX_SHADER() and FRAGMENT_SHADER() macros, instead of quoted string literals when
     7        declaring shaders in TextureMapperGL.
     8
     9        We need two macros to account for the differences between OpenGL and OpenGL ES2.
     10
     11        Reviewed by Martin Robinson.
     12
    1132012-01-05  Ryosuke Niwa  <rniwa@webkit.org>
    214
  • trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp

    r103735 r104255  
    318318#endif
    319319
     320#define VERTEX_SHADER(src...) OES2_PRECISION_DEFINITIONS#src
     321#define FRAGMENT_SHADER(src...) OES2_PRECISION_DEFINITIONS\
     322                                OES2_FRAGMENT_SHADER_DEFAULT_PRECISION\
     323                                #src
     324
    320325    const char* fragmentShaderSourceOpacityAndMask =
    321             OES2_PRECISION_DEFINITIONS
    322             OES2_FRAGMENT_SHADER_DEFAULT_PRECISION
    323 "               uniform sampler2D SourceTexture, MaskTexture;                       \n"
    324 "               uniform lowp float Opacity;                                         \n"
    325 "               varying highp vec2 OutTexCoordSource, OutTexCoordMask;              \n"
    326 "               void main(void)                                                     \n"
    327 "               {                                                                   \n"
    328 "                   lowp vec4 color = texture2D(SourceTexture, OutTexCoordSource);  \n"
    329 "                   lowp vec4 maskColor = texture2D(MaskTexture, OutTexCoordMask);  \n"
    330 "                   lowp float o = Opacity * maskColor.a;                           \n"
    331 "                   gl_FragColor = vec4(color.rgb * o, color.a * o);                \n"
    332 "               }                                                                   \n";
     326        FRAGMENT_SHADER(
     327            uniform sampler2D SourceTexture, MaskTexture;
     328            uniform lowp float Opacity;
     329            varying highp vec2 OutTexCoordSource, OutTexCoordMask;
     330            void main(void)
     331            {
     332                lowp vec4 color = texture2D(SourceTexture, OutTexCoordSource);
     333                lowp vec4 maskColor = texture2D(MaskTexture, OutTexCoordMask);
     334                lowp float fragmentAlpha = Opacity * maskColor.a;
     335                gl_FragColor = vec4(color.rgb * fragmentAlpha, color.a * fragmentAlpha);
     336            }
     337        );
    333338
    334339    const char* vertexShaderSourceOpacityAndMask =
    335             OES2_PRECISION_DEFINITIONS
    336 "               uniform mat4 InMatrix, InSourceMatrix, InMaskMatrix;            \n"
    337 "               attribute vec4 InVertex;                                        \n"
    338 "               varying highp vec2 OutTexCoordSource, OutTexCoordMask;          \n"
    339 "               void main(void)                                                 \n"
    340 "               {                                                               \n"
    341 "                   OutTexCoordSource = vec2(InSourceMatrix * InVertex);        \n"
    342 "                   OutTexCoordMask = vec2(InMaskMatrix * InVertex);            \n"
    343 "                   gl_Position = InMatrix * InVertex;                          \n"
    344 "               }                                                               \n";
     340        VERTEX_SHADER(
     341            uniform mat4 InMatrix, InSourceMatrix, InMaskMatrix;
     342            attribute vec4 InVertex;
     343            varying highp vec2 OutTexCoordSource, OutTexCoordMask;
     344            void main(void)
     345            {
     346                OutTexCoordSource = vec2(InSourceMatrix * InVertex);
     347                OutTexCoordMask = vec2(InMaskMatrix * InVertex);
     348                gl_Position = InMatrix * InVertex;
     349            }
     350        );
    345351
    346352    const char* fragmentShaderSourceSimple =
    347             OES2_PRECISION_DEFINITIONS
    348             OES2_FRAGMENT_SHADER_DEFAULT_PRECISION
    349 "               uniform sampler2D SourceTexture;                                    \n"
    350 "               uniform lowp float Opacity;                                         \n"
    351 "               varying highp vec2 OutTexCoordSource;                               \n"
    352 "               void main(void)                                                     \n"
    353 "               {                                                                   \n"
    354 "                   lowp vec4 color = texture2D(SourceTexture, OutTexCoordSource);  \n"
    355 "                   gl_FragColor = vec4(color.rgb * Opacity, color.a * Opacity);    \n"
    356 "               }                                                                   \n";
     353        FRAGMENT_SHADER(
     354            uniform sampler2D SourceTexture;
     355            uniform lowp float Opacity;
     356            varying highp vec2 OutTexCoordSource;
     357            void main(void)
     358            {
     359                lowp vec4 color = texture2D(SourceTexture, OutTexCoordSource);
     360                gl_FragColor = vec4(color.rgb * Opacity, color.a * Opacity);
     361            }
     362        );
    357363
    358364    const char* vertexShaderSourceSimple =
    359             OES2_PRECISION_DEFINITIONS
    360 "               uniform mat4 InMatrix, InSourceMatrix;                      \n"
    361 "               attribute vec4 InVertex;                                    \n"
    362 "               varying highp vec2 OutTexCoordSource;                       \n"
    363 "               void main(void)                                             \n"
    364 "               {                                                           \n"
    365 "                   OutTexCoordSource = vec2(InSourceMatrix * InVertex);    \n"
    366 "                   gl_Position = InMatrix * InVertex;                      \n"
    367 "               }                                                           \n";
    368 
     365        VERTEX_SHADER(
     366            uniform mat4 InMatrix, InSourceMatrix;
     367            attribute vec4 InVertex;
     368            varying highp vec2 OutTexCoordSource;
     369            void main(void)
     370            {
     371                OutTexCoordSource = vec2(InSourceMatrix * InVertex);
     372                gl_Position = InMatrix * InVertex;
     373            }
     374        );
    369375    const char* fragmentShaderSourceClip =
    370             OES2_FRAGMENT_SHADER_DEFAULT_PRECISION
    371 "               void main(void) { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); }                                ";
     376        FRAGMENT_SHADER(
     377            void main(void)
     378            {
     379                gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
     380            }
     381        );
    372382
    373383    const char* vertexShaderSourceClip =
    374 "               uniform mat4 InMatrix;                                      \n"
    375 "               attribute vec4 InVertex;                                    \n"
    376 "               void main(void) { gl_Position = InMatrix * InVertex; }      ";
     384        VERTEX_SHADER(
     385            uniform mat4 InMatrix;
     386            attribute vec4 InVertex;
     387            void main(void)
     388            {
     389                gl_Position = InMatrix * InVertex;
     390            }
     391        );
    377392
    378393
Note: See TracChangeset for help on using the changeset viewer.