< prev index next >

src/java.desktop/share/native/common/java2d/opengl/OGLBufImgOps.c

Print this page

        

@@ -58,48 +58,10 @@
  *         Early shader-level hardware did not support non-constant sized
  *         arrays but modern hardware should support them (although I
  *         don't know of any simple way to find out, other than to compile
  *         the shader at runtime and see if the drivers complain).
  */
-static const char *convolveShaderSource =
-    // maximum size supported by this shader
-    "const int MAX_KERNEL_SIZE = %s;"
-    // image to be convolved
-    "uniform sampler%s baseImage;"
-    // image edge limits:
-    //   imgEdge.xy = imgMin.xy (anything < will be treated as edge case)
-    //   imgEdge.zw = imgMax.xy (anything > will be treated as edge case)
-    "uniform vec4 imgEdge;"
-    // value for each location in the convolution kernel:
-    //   kernelVals[i].x = offsetX[i]
-    //   kernelVals[i].y = offsetY[i]
-    //   kernelVals[i].z = kernel[i]
-    "uniform vec3 kernelVals[MAX_KERNEL_SIZE];"
-    ""
-    "void main(void)"
-    "{"
-    "    int i;"
-    "    vec4 sum;"
-    ""
-    "    if (any(lessThan(gl_TexCoord[0].st, imgEdge.xy)) ||"
-    "        any(greaterThan(gl_TexCoord[0].st, imgEdge.zw)))"
-    "    {"
-             // (placeholder for edge condition code)
-    "        %s"
-    "    } else {"
-    "        sum = vec4(0.0);"
-    "        for (i = 0; i < MAX_KERNEL_SIZE; i++) {"
-    "            sum +="
-    "                kernelVals[i].z *"
-    "                texture%s(baseImage,"
-    "                          gl_TexCoord[0].st + kernelVals[i].xy);"
-    "        }"
-    "    }"
-    ""
-         // modulate with gl_Color in order to apply extra alpha
-    "    gl_FragColor = sum * gl_Color;"
-    "}";
 
 /**
  * Flags that can be bitwise-or'ed together to control how the shader
  * source code is generated.
  */

@@ -148,12 +110,48 @@
                 "sum = texture%s(baseImage, gl_TexCoord[0].st);",
                 target);
     }
 
     // compose the final source code string from the various pieces
-    sprintf(finalSource, convolveShaderSource,
-            kernelMax, target, edge, target);
+    sprintf(finalSource,
+        // maximum size supported by this shader
+        "const int MAX_KERNEL_SIZE = %s;"
+        // image to be convolved
+        "uniform sampler%s baseImage;"
+        // image edge limits:
+        //   imgEdge.xy = imgMin.xy (anything < will be treated as edge case)
+        //   imgEdge.zw = imgMax.xy (anything > will be treated as edge case)
+        "uniform vec4 imgEdge;"
+        // value for each location in the convolution kernel:
+        //   kernelVals[i].x = offsetX[i]
+        //   kernelVals[i].y = offsetY[i]
+        //   kernelVals[i].z = kernel[i]
+        "uniform vec3 kernelVals[MAX_KERNEL_SIZE];"
+        ""
+        "void main(void)"
+        "{"
+        "    int i;"
+        "    vec4 sum;"
+        ""
+        "    if (any(lessThan(gl_TexCoord[0].st, imgEdge.xy)) ||"
+        "        any(greaterThan(gl_TexCoord[0].st, imgEdge.zw)))"
+        "    {"
+                 // (placeholder for edge condition code)
+        "        %s"
+        "    } else {"
+        "        sum = vec4(0.0);"
+        "        for (i = 0; i < MAX_KERNEL_SIZE; i++) {"
+        "            sum +="
+        "                kernelVals[i].z *"
+        "                texture%s(baseImage,"
+        "                          gl_TexCoord[0].st + kernelVals[i].xy);"
+        "        }"
+        "    }"
+        ""
+             // modulate with gl_Color in order to apply extra alpha
+        "    gl_FragColor = sum * gl_Color;"
+        "}", kernelMax, target, edge, target);
 
     convolveProgram = OGLContext_CreateFragmentProgram(finalSource);
     if (convolveProgram == 0) {
         J2dRlsTraceLn(J2D_TRACE_ERROR,
             "OGLBufImgOps_CreateConvolveProgram: error creating program");

@@ -297,30 +295,10 @@
  * This allows us to build different shader programs (e.g. one for
  * GL_TEXTURE_2D targets, one for GL_TEXTURE_RECTANGLE_ARB targets, and so on)
  * simply by filling in these "holes" with a call to sprintf().  See the
  * OGLBufImgOps_CreateRescaleProgram() method for more details.
  */
-static const char *rescaleShaderSource =
-    // image to be rescaled
-    "uniform sampler%s baseImage;"
-    // vector containing scale factors
-    "uniform vec4 scaleFactors;"
-    // vector containing offsets
-    "uniform vec4 offsets;"
-    ""
-    "void main(void)"
-    "{"
-    "    vec4 srcColor = texture%s(baseImage, gl_TexCoord[0].st);"
-         // (placeholder for un-premult code)
-    "    %s"
-         // rescale source value
-    "    vec4 result = (srcColor * scaleFactors) + offsets;"
-         // (placeholder for re-premult code)
-    "    %s"
-         // modulate with gl_Color in order to apply extra alpha
-    "    gl_FragColor = result * gl_Color;"
-    "}";
 
 /**
  * Flags that can be bitwise-or'ed together to control how the shader
  * source code is generated.
  */

@@ -358,12 +336,30 @@
         preRescale  = "srcColor.rgb /= srcColor.a;";
         postRescale = "result.rgb *= result.a;";
     }
 
     // compose the final source code string from the various pieces
-    sprintf(finalSource, rescaleShaderSource,
-            target, target, preRescale, postRescale);
+    sprintf(finalSource,
+        // image to be rescaled
+        "uniform sampler%s baseImage;"
+        // vector containing scale factors
+        "uniform vec4 scaleFactors;"
+        // vector containing offsets
+        "uniform vec4 offsets;"
+        ""
+        "void main(void)"
+        "{"
+        "    vec4 srcColor = texture%s(baseImage, gl_TexCoord[0].st);"
+             // (placeholder for un-premult code)
+        "    %s"
+             // rescale source value
+        "    vec4 result = (srcColor * scaleFactors) + offsets;"
+             // (placeholder for re-premult code)
+        "    %s"
+             // modulate with gl_Color in order to apply extra alpha
+        "    gl_FragColor = result * gl_Color;"
+        "}", target, target, preRescale, postRescale);
 
     rescaleProgram = OGLContext_CreateFragmentProgram(finalSource);
     if (rescaleProgram == 0) {
         J2dRlsTraceLn(J2D_TRACE_ERROR,
             "OGLBufImgOps_CreateRescaleProgram: error creating program");

@@ -503,39 +499,10 @@
  * This allows us to build different shader programs (e.g. one for
  * GL_TEXTURE_2D targets, one for GL_TEXTURE_RECTANGLE_ARB targets, and so on)
  * simply by filling in these "holes" with a call to sprintf().  See the
  * OGLBufImgOps_CreateLookupProgram() method for more details.
  */
-static const char *lookupShaderSource =
-    // source image (bound to texture unit 0)
-    "uniform sampler%s baseImage;"
-    // lookup table (bound to texture unit 1)
-    "uniform sampler2D lookupTable;"
-    // offset subtracted from source index prior to lookup step
-    "uniform vec4 offset;"
-    ""
-    "void main(void)"
-    "{"
-    "    vec4 srcColor = texture%s(baseImage, gl_TexCoord[0].st);"
-         // (placeholder for un-premult code)
-    "    %s"
-         // subtract offset from original index
-    "    vec4 srcIndex = srcColor - offset;"
-         // use source value as input to lookup table (note that
-         // "v" texcoords are hardcoded to hit texel centers of
-         // each row/band in texture)
-    "    vec4 result;"
-    "    result.r = texture2D(lookupTable, vec2(srcIndex.r, 0.125)).r;"
-    "    result.g = texture2D(lookupTable, vec2(srcIndex.g, 0.375)).r;"
-    "    result.b = texture2D(lookupTable, vec2(srcIndex.b, 0.625)).r;"
-         // (placeholder for alpha store code)
-    "    %s"
-         // (placeholder for re-premult code)
-    "    %s"
-         // modulate with gl_Color in order to apply extra alpha
-    "    gl_FragColor = result * gl_Color;"
-    "}";
 
 /**
  * Flags that can be bitwise-or'ed together to control how the shader
  * source code is generated.
  */

@@ -590,12 +557,39 @@
         preLookup  = "srcColor.rgb /= srcColor.a;";
         postLookup = "result.rgb *= result.a;";
     }
 
     // compose the final source code string from the various pieces
-    sprintf(finalSource, lookupShaderSource,
-            target, target, preLookup, alpha, postLookup);
+    sprintf(finalSource,
+    // source image (bound to texture unit 0)
+        "uniform sampler%s baseImage;"
+        // lookup table (bound to texture unit 1)
+        "uniform sampler2D lookupTable;"
+        // offset subtracted from source index prior to lookup step
+        "uniform vec4 offset;"
+        ""
+        "void main(void)"
+        "{"
+        "    vec4 srcColor = texture%s(baseImage, gl_TexCoord[0].st);"
+             // (placeholder for un-premult code)
+        "    %s"
+             // subtract offset from original index
+        "    vec4 srcIndex = srcColor - offset;"
+             // use source value as input to lookup table (note that
+             // "v" texcoords are hardcoded to hit texel centers of
+             // each row/band in texture)
+        "    vec4 result;"
+        "    result.r = texture2D(lookupTable, vec2(srcIndex.r, 0.125)).r;"
+        "    result.g = texture2D(lookupTable, vec2(srcIndex.g, 0.375)).r;"
+        "    result.b = texture2D(lookupTable, vec2(srcIndex.b, 0.625)).r;"
+             // (placeholder for alpha store code)
+        "    %s"
+             // (placeholder for re-premult code)
+        "    %s"
+             // modulate with gl_Color in order to apply extra alpha
+        "    gl_FragColor = result * gl_Color;"
+        "}", target, target, preLookup, alpha, postLookup);
 
     lookupProgram = OGLContext_CreateFragmentProgram(finalSource);
     if (lookupProgram == 0) {
         J2dRlsTraceLn(J2D_TRACE_ERROR,
             "OGLBufImgOps_CreateLookupProgram: error creating program");
< prev index next >