< prev index next >
src/java.desktop/share/native/common/java2d/opengl/OGLPaints.c
Print this page
@@ -380,61 +380,10 @@
* The handle to the gradient color table texture object used by the shaders.
*/
static GLuint multiGradientTexID = 0;
/**
- * This is essentially a template of the shader source code that can be used
- * for either LinearGradientPaint or RadialGradientPaint. It includes the
- * structure and some variables that are common to each; the remaining
- * code snippets (for CycleMethod, ColorSpaceType, and mask modulation)
- * are filled in prior to compiling the shader at runtime depending on the
- * paint parameters. See OGLPaints_CreateMultiGradProgram() for more details.
- */
-static const char *multiGradientShaderSource =
- // gradient texture size (in texels)
- "const int TEXTURE_SIZE = %d;"
- // maximum number of fractions/colors supported by this shader
- "const int MAX_FRACTIONS = %d;"
- // size of a single texel
- "const float FULL_TEXEL = (1.0 / float(TEXTURE_SIZE));"
- // size of half of a single texel
- "const float HALF_TEXEL = (FULL_TEXEL / 2.0);"
- // texture containing the gradient colors
- "uniform sampler1D colors;"
- // array of gradient stops/fractions
- "uniform float fractions[MAX_FRACTIONS];"
- // array of scale factors (one for each interval)
- "uniform float scaleFactors[MAX_FRACTIONS-1];"
- // (placeholder for mask variable)
- "%s"
- // (placeholder for Linear/RadialGP-specific variables)
- "%s"
- ""
- "void main(void)"
- "{"
- " float dist;"
- // (placeholder for Linear/RadialGradientPaint-specific code)
- " %s"
- ""
- " float tc;"
- // (placeholder for CycleMethod-specific code)
- " %s"
- ""
- // calculate interpolated color
- " vec4 result = texture1D(colors, tc);"
- ""
- // (placeholder for ColorSpace conversion code)
- " %s"
- ""
- // (placeholder for mask modulation code)
- " %s"
- ""
- // modulate with gl_Color in order to apply extra alpha
- " gl_FragColor = result * gl_Color;"
- "}";
-
-/**
* This code takes a "dist" value as input (as calculated earlier by the
* LGP/RGP-specific code) in the range [0,1] and produces a texture
* coordinate value "tc" that represents the position of the chosen color
* in the one-dimensional gradient texture (also in the range [0,1]).
*
@@ -474,33 +423,10 @@
"}"
// we offset by half a texel so that we find the linearly interpolated
// color between the two texel centers of interest
"tc = HALF_TEXEL + (FULL_TEXEL * relFraction);";
-/** Code for NO_CYCLE that gets plugged into the CycleMethod placeholder. */
-static const char *noCycleCode =
- "if (dist <= 0.0) {"
- " tc = 0.0;"
- "} else if (dist >= 1.0) {"
- " tc = 1.0;"
- "} else {"
- // (placeholder for texcoord calculation)
- " %s"
- "}";
-
-/** Code for REFLECT that gets plugged into the CycleMethod placeholder. */
-static const char *reflectCode =
- "dist = 1.0 - (abs(fract(dist * 0.5) - 0.5) * 2.0);"
- // (placeholder for texcoord calculation)
- "%s";
-
-/** Code for REPEAT that gets plugged into the CycleMethod placeholder. */
-static const char *repeatCode =
- "dist = fract(dist);"
- // (placeholder for texcoord calculation)
- "%s";
-
static void
OGLPaints_InitMultiGradientTexture()
{
GLclampf priority = 1.0f;
@@ -576,20 +502,84 @@
colorSpaceCode =
"result.rgb = 1.055 * pow(result.rgb, vec3(0.416667)) - 0.055;";
}
if (cycleMethod == CYCLE_NONE) {
- sprintf(cycleCode, noCycleCode, texCoordCalcCode);
+ sprintf(cycleCode,
+ /** Code for NO_CYCLE that gets plugged into the CycleMethod placeholder. */
+ "if (dist <= 0.0) {"
+ " tc = 0.0;"
+ "} else if (dist >= 1.0) {"
+ " tc = 1.0;"
+ "} else {"
+ // (placeholder for texcoord calculation)
+ " %s", texCoordCalcCode);
} else if (cycleMethod == CYCLE_REFLECT) {
- sprintf(cycleCode, reflectCode, texCoordCalcCode);
+ sprintf(cycleCode,
+ /** Code for REFLECT that gets plugged into the CycleMethod placeholder. */
+ "dist = 1.0 - (abs(fract(dist * 0.5) - 0.5) * 2.0);"
+ // (placeholder for texcoord calculation)
+ "%s", texCoordCalcCode);
} else { // (cycleMethod == CYCLE_REPEAT)
- sprintf(cycleCode, repeatCode, texCoordCalcCode);
+ sprintf(cycleCode,
+ /** Code for REPEAT that gets plugged into the CycleMethod placeholder. */
+ "dist = fract(dist);"
+ // (placeholder for texcoord calculation)
+ "%s", texCoordCalcCode);
}
// compose the final source code string from the various pieces
- sprintf(finalSource, multiGradientShaderSource,
- MAX_COLORS, maxFractions,
+ sprintf(finalSource,
+/**
+ * This is essentially a template of the shader source code that can be used
+ * for either LinearGradientPaint or RadialGradientPaint. It includes the
+ * structure and some variables that are common to each; the remaining
+ * code snippets (for CycleMethod, ColorSpaceType, and mask modulation)
+ * are filled in prior to compiling the shader at runtime depending on the
+ * paint parameters. See OGLPaints_CreateMultiGradProgram() for more details.
+ */
+ // gradient texture size (in texels)
+ "const int TEXTURE_SIZE = %d;"
+ // maximum number of fractions/colors supported by this shader
+ "const int MAX_FRACTIONS = %d;"
+ // size of a single texel
+ "const float FULL_TEXEL = (1.0 / float(TEXTURE_SIZE));"
+ // size of half of a single texel
+ "const float HALF_TEXEL = (FULL_TEXEL / 2.0);"
+ // texture containing the gradient colors
+ "uniform sampler1D colors;"
+ // array of gradient stops/fractions
+ "uniform float fractions[MAX_FRACTIONS];"
+ // array of scale factors (one for each interval)
+ "uniform float scaleFactors[MAX_FRACTIONS-1];"
+ // (placeholder for mask variable)
+ "%s"
+ // (placeholder for Linear/RadialGP-specific variables)
+ "%s"
+ ""
+ "void main(void)"
+ "{"
+ " float dist;"
+ // (placeholder for Linear/RadialGradientPaint-specific code)
+ " %s"
+ ""
+ " float tc;"
+ // (placeholder for CycleMethod-specific code)
+ " %s"
+ ""
+ // calculate interpolated color
+ " vec4 result = texture1D(colors, tc);"
+ ""
+ // (placeholder for ColorSpace conversion code)
+ " %s"
+ ""
+ // (placeholder for mask modulation code)
+ " %s"
+ ""
+ // modulate with gl_Color in order to apply extra alpha
+ " gl_FragColor = result * gl_Color;"
+ "}", MAX_COLORS, maxFractions,
maskVars, paintVars, distCode,
cycleCode, colorSpaceCode, maskCode);
multiGradProgram = OGLContext_CreateFragmentProgram(finalSource);
if (multiGradProgram == 0) {
< prev index next >