8#ifndef GrAtlasedShaderHelpers_DEFINED
9#define GrAtlasedShaderHelpers_DEFINED
18 int numTextureSamplers,
19 const char* inTexCoordsName,
20 const char* atlasDimensionsInvName,
29 if (
args.fShaderCaps->fIntegerSupport) {
30 if (numTextureSamplers <= 1) {
31 args.fVertBuilder->codeAppendf(
33 "float2 unormTexCoords = float2(%s.x, %s.y);"
34 , inTexCoordsName, inTexCoordsName);
36 args.fVertBuilder->codeAppendf(
37 "int2 coords = int2(%s.x, %s.y);"
38 "int texIdx = coords.x >> 13;"
39 "float2 unormTexCoords = float2(coords.x & 0x1FFF, coords.y);"
40 , inTexCoordsName, inTexCoordsName);
43 if (numTextureSamplers <= 1) {
44 args.fVertBuilder->codeAppendf(
46 "float2 unormTexCoords = float2(%s.x, %s.y);"
47 , inTexCoordsName, inTexCoordsName);
49 args.fVertBuilder->codeAppendf(
50 "float2 coord = float2(%s.x, %s.y);"
51 "float texIdx = floor(coord.x * exp2(-13));"
52 "float2 unormTexCoords = float2(coord.x - texIdx * exp2(13), coord.y);"
53 , inTexCoordsName, inTexCoordsName);
59 args.fVaryingHandler->addVarying(
"TextureCoords", uv);
60 args.fVertBuilder->codeAppendf(
61 "%s = unormTexCoords * %s;", uv->
vsOut(), atlasDimensionsInvName);
67 const char*
cast =
args.fShaderCaps->fIntegerSupport ?
"float" :
"";
68 args.fVaryingHandler->addVarying(
"TexIndex", texIdx, Interpolation::kCanBeFlat);
69 args.fVertBuilder->codeAppendf(
"%s = %s(texIdx);", texIdx->
vsOut(),
cast);
73 args.fVaryingHandler->addVarying(
"IntTextureCoords", st);
74 args.fVertBuilder->codeAppendf(
"%s = unormTexCoords;", st->
vsOut());
79 int numTextureSamplers,
81 const char* coordName,
82 const char* colorName) {
85 if (numTextureSamplers <= 0) {
86 args.fFragBuilder->codeAppendf(
"%s = float4(1);", colorName);
91 for (
int i = 0;
i < numTextureSamplers-1; ++
i) {
92 args.fFragBuilder->codeAppendf(
"if (%s == %d) { %s = ", texIdx.
fsIn(),
i, colorName);
93 args.fFragBuilder->appendTextureLookup(
args.fTexSamplers[
i],
95 args.fFragBuilder->codeAppend(
"; } else ");
97 args.fFragBuilder->codeAppendf(
"{ %s = ", colorName);
98 args.fFragBuilder->appendTextureLookup(
args.fTexSamplers[numTextureSamplers - 1],
100 args.fFragBuilder->codeAppend(
"; }");
105 int numTextureSamplers,
107 const char* coordName,
108 const char* offsetName,
109 const char* distanceName) {
112 if (numTextureSamplers <= 0) {
113 args.fFragBuilder->codeAppendf(
"%s = half3(1);", distanceName);
118 for (
int i = 0;
i < numTextureSamplers; ++
i) {
119 args.fFragBuilder->codeAppendf(
"if (%s == %d) {", texIdx.
fsIn(),
i);
122 args.fFragBuilder->codeAppendf(
"%s.y = ", distanceName);
123 args.fFragBuilder->appendTextureLookup(
args.fTexSamplers[
i], coordName);
124 args.fFragBuilder->codeAppend(
".r;");
127 args.fFragBuilder->codeAppendf(
"half2 uv_adjusted = half2(%s) - %s;",
128 coordName, offsetName);
129 args.fFragBuilder->codeAppendf(
"%s.x = ", distanceName);
130 args.fFragBuilder->appendTextureLookup(
args.fTexSamplers[
i],
"uv_adjusted");
131 args.fFragBuilder->codeAppend(
".r;");
134 args.fFragBuilder->codeAppendf(
"uv_adjusted = half2(%s) + %s;", coordName, offsetName);
135 args.fFragBuilder->codeAppendf(
"%s.z = ", distanceName);
136 args.fFragBuilder->appendTextureLookup(
args.fTexSamplers[
i],
"uv_adjusted");
137 args.fFragBuilder->codeAppend(
".r;");
139 if (
i < numTextureSamplers-1) {
140 args.fFragBuilder->codeAppend(
"} else ");
142 args.fFragBuilder->codeAppend(
"}");
static void append_index_uv_varyings(GrGeometryProcessor::ProgramImpl::EmitArgs &args, int numTextureSamplers, const char *inTexCoordsName, const char *atlasDimensionsInvName, GrGLSLVarying *uv, GrGLSLVarying *texIdx, GrGLSLVarying *st)
static void append_multitexture_lookup_lcd(GrGeometryProcessor::ProgramImpl::EmitArgs &args, int numTextureSamplers, const GrGLSLVarying &texIdx, const char *coordName, const char *offsetName, const char *distanceName)
static void append_multitexture_lookup(GrGeometryProcessor::ProgramImpl::EmitArgs &args, int numTextureSamplers, const GrGLSLVarying &texIdx, const char *coordName, const char *colorName)
const char * vsOut() const
const char * fsIn() const
void reset(SkSLType type, Scope scope=Scope::kVertToFrag)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args