Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: src/gpu/gl/GrGLSL.cpp

Issue 13895006: Expand modulate, add, subtract, extract component glsl helpers. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLSL.h ('k') | src/gpu/gl/GrGLSL_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrGLSL.h" 8 #include "GrGLSL.h"
9 #include "GrGLShaderVar.h" 9 #include "GrGLShaderVar.h"
10 #include "SkString.h" 10 #include "SkString.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const char* GrGLSLVectorNonhomogCoords(int count) { 80 const char* GrGLSLVectorNonhomogCoords(int count) {
81 static const char* NONHOMOGS[] = {"ERROR", "", ".x", ".xy", ".xyz"}; 81 static const char* NONHOMOGS[] = {"ERROR", "", ".x", ".xy", ".xyz"};
82 GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(NONHOMOGS)); 82 GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(NONHOMOGS));
83 return NONHOMOGS[count]; 83 return NONHOMOGS[count];
84 } 84 }
85 85
86 const char* GrGLSLVectorNonhomogCoords(GrSLType type) { 86 const char* GrGLSLVectorNonhomogCoords(GrSLType type) {
87 return GrGLSLVectorNonhomogCoords(GrSLTypeToVecLength(type)); 87 return GrGLSLVectorNonhomogCoords(GrSLTypeToVecLength(type));
88 } 88 }
89 89
90 GrSLConstantVec GrGLSLModulate4f(SkString* outAppend, 90 namespace {
91 const char* in0, 91 void append_tabs(SkString* outAppend, int tabCnt) {
92 const char* in1, 92 static const char kTabs[] = "\t\t\t\t\t\t\t\t";
93 GrSLConstantVec default0, 93 while (tabCnt) {
94 GrSLConstantVec default1) { 94 int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt);
95 GrAssert(NULL != outAppend); 95 outAppend->append(kTabs, cnt);
96 96 tabCnt -= cnt;
97 bool has0 = NULL != in0 && '\0' != *in0;
98 bool has1 = NULL != in1 && '\0' != *in1;
99
100 GrAssert(has0 || kNone_GrSLConstantVec != default0);
101 GrAssert(has1 || kNone_GrSLConstantVec != default1);
102
103 if (!has0 && !has1) {
104 GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0);
105 GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1);
106 if (kZeros_GrSLConstantVec == default0 || kZeros_GrSLConstantVec == defa ult1) {
107 outAppend->append(GrGLSLZerosVecf(4));
108 return kZeros_GrSLConstantVec;
109 } else {
110 // both inputs are ones vectors
111 outAppend->append(GrGLSLOnesVecf(4));
112 return kOnes_GrSLConstantVec;
113 } 97 }
114 } else if (!has0) {
115 GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0);
116 if (kZeros_GrSLConstantVec == default0) {
117 outAppend->append(GrGLSLZerosVecf(4));
118 return kZeros_GrSLConstantVec;
119 } else {
120 outAppend->appendf("vec4(%s)", in1);
121 return kNone_GrSLConstantVec;
122 }
123 } else if (!has1) {
124 GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1);
125 if (kZeros_GrSLConstantVec == default1) {
126 outAppend->append(GrGLSLZerosVecf(4));
127 return kZeros_GrSLConstantVec;
128 } else {
129 outAppend->appendf("vec4(%s)", in0);
130 return kNone_GrSLConstantVec;
131 }
132 } else {
133 outAppend->appendf("vec4(%s * %s)", in0, in1);
134 return kNone_GrSLConstantVec;
135 } 98 }
136 } 99 }
137 100
138 namespace {
139 void append_tabs(SkString* outAppend, int tabCnt) {
140 static const char kTabs[] = "\t\t\t\t\t\t\t\t";
141 while (tabCnt) {
142 int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt);
143 outAppend->append(kTabs, cnt);
144 tabCnt -= cnt;
145 }
146 }
147 }
148
149 GrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend, 101 GrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend,
150 int tabCnt, 102 int tabCnt,
151 const char* vec4VarName, 103 const char* vec4VarName,
152 const char* mulFactor, 104 const char* mulFactor,
153 GrSLConstantVec mulFactorDefault) { 105 GrSLConstantVec mulFactorDefault) {
154 bool haveFactor = NULL != mulFactor && '\0' != *mulFactor; 106 bool haveFactor = NULL != mulFactor && '\0' != *mulFactor;
155 107
156 GrAssert(NULL != outAppend); 108 GrAssert(NULL != outAppend);
157 GrAssert(NULL != vec4VarName); 109 GrAssert(NULL != vec4VarName);
158 GrAssert(kNone_GrSLConstantVec != mulFactorDefault || haveFactor); 110 GrAssert(kNone_GrSLConstantVec != mulFactorDefault || haveFactor);
159 111
160 if (!haveFactor) { 112 if (!haveFactor) {
161 if (kOnes_GrSLConstantVec == mulFactorDefault) { 113 if (kOnes_GrSLConstantVec == mulFactorDefault) {
162 return kNone_GrSLConstantVec; 114 return kNone_GrSLConstantVec;
163 } else { 115 } else {
164 GrAssert(kZeros_GrSLConstantVec == mulFactorDefault); 116 GrAssert(kZeros_GrSLConstantVec == mulFactorDefault);
165 append_tabs(outAppend, tabCnt); 117 append_tabs(outAppend, tabCnt);
166 outAppend->appendf("%s = vec4(0, 0, 0, 0);\n", vec4VarName); 118 outAppend->appendf("%s = vec4(0, 0, 0, 0);\n", vec4VarName);
167 return kZeros_GrSLConstantVec; 119 return kZeros_GrSLConstantVec;
168 } 120 }
169 } 121 }
170 append_tabs(outAppend, tabCnt); 122 append_tabs(outAppend, tabCnt);
171 outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor); 123 outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor);
172 return kNone_GrSLConstantVec; 124 return kNone_GrSLConstantVec;
173 } 125 }
174 126
175 GrSLConstantVec GrGLSLAdd4f(SkString* outAppend, 127 GrSLConstantVec GrGLSLGetComponent4f(SkString* outAppend,
176 const char* in0, 128 const char* expr,
177 const char* in1, 129 GrColorComponentFlags component,
178 GrSLConstantVec default0, 130 GrSLConstantVec defaultExpr,
179 GrSLConstantVec default1) { 131 bool omitIfConst) {
180 GrAssert(NULL != outAppend); 132 if (NULL == expr || '\0' == *expr) {
181 133 GrAssert(defaultExpr != kNone_GrSLConstantVec);
182 bool has0 = NULL != in0 && '\0' != *in0; 134 if (!omitIfConst) {
183 bool has1 = NULL != in1 && '\0' != *in1; 135 if (kOnes_GrSLConstantVec == defaultExpr) {
184 136 outAppend->append("1.0");
185 if (!has0 && !has1) { 137 } else {
186 GrAssert(kZeros_GrSLConstantVec == default0); 138 GrAssert(kZeros_GrSLConstantVec == defaultExpr);
187 GrAssert(kZeros_GrSLConstantVec == default1); 139 outAppend->append("0.0");
188 outAppend->append(GrGLSLZerosVecf(4)); 140 }
189 return kZeros_GrSLConstantVec; 141 }
190 } else if (!has0) { 142 return defaultExpr;
191 GrAssert(kZeros_GrSLConstantVec == default0);
192 outAppend->appendf("vec4(%s)", in1);
193 return kNone_GrSLConstantVec;
194 } else if (!has1) {
195 GrAssert(kZeros_GrSLConstantVec == default1);
196 outAppend->appendf("vec4(%s)", in0);
197 return kNone_GrSLConstantVec;
198 } else { 143 } else {
199 outAppend->appendf("(vec4(%s) + vec4(%s))", in0, in1); 144 outAppend->appendf("(%s).%c", expr, GrColorComponentFlagToChar(component ));
200 return kNone_GrSLConstantVec; 145 return kNone_GrSLConstantVec;
201 } 146 }
202 } 147 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLSL.h ('k') | src/gpu/gl/GrGLSL_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698