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

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

Issue 25048002: Express (GLSL expression, possibly known value) pairs as a class (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 void append_tabs(SkString* outAppend, int tabCnt) { 87 void append_tabs(SkString* outAppend, int tabCnt) {
88 static const char kTabs[] = "\t\t\t\t\t\t\t\t"; 88 static const char kTabs[] = "\t\t\t\t\t\t\t\t";
89 while (tabCnt) { 89 while (tabCnt) {
90 int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt); 90 int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt);
91 outAppend->append(kTabs, cnt); 91 outAppend->append(kTabs, cnt);
92 tabCnt -= cnt; 92 tabCnt -= cnt;
93 } 93 }
94 } 94 }
95 } 95 }
96 96
97 GrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend, 97 void GrGLSLMulVarBy4f(SkString* outAppend,
98 int tabCnt, 98 unsigned tabCnt,
99 const char* vec4VarName, 99 const char* vec4VarName,
100 const char* mulFactor, 100 const GrGLSLExpr<4>& mulFactor) {
101 GrSLConstantVec mulFactorDefault) { 101 if (mulFactor.isOnes()) {
102 bool haveFactor = NULL != mulFactor && '\0' != *mulFactor; 102 *outAppend = SkString();
103 }
103 104
104 SkASSERT(NULL != outAppend); 105 append_tabs(outAppend, tabCnt);
105 SkASSERT(NULL != vec4VarName);
106 SkASSERT(kNone_GrSLConstantVec != mulFactorDefault || haveFactor);
107 106
108 if (!haveFactor) { 107 if (mulFactor.isZeros()) {
109 if (kOnes_GrSLConstantVec == mulFactorDefault) { 108 outAppend->appendf("%s = vec4(0);\n", vec4VarName);
110 return kNone_GrSLConstantVec;
111 } else {
112 SkASSERT(kZeros_GrSLConstantVec == mulFactorDefault);
113 append_tabs(outAppend, tabCnt);
114 outAppend->appendf("%s = vec4(0, 0, 0, 0);\n", vec4VarName);
115 return kZeros_GrSLConstantVec;
116 }
117 } 109 }
118 append_tabs(outAppend, tabCnt); 110 outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor.c_str());
119 outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor);
120 return kNone_GrSLConstantVec;
121 } 111 }
122 112
123 GrSLConstantVec GrGLSLGetComponent4f(SkString* outAppend,
124 const char* expr,
125 GrColorComponentFlags component,
126 GrSLConstantVec defaultExpr,
127 bool omitIfConst) {
128 if (NULL == expr || '\0' == *expr) {
129 SkASSERT(defaultExpr != kNone_GrSLConstantVec);
130 if (!omitIfConst) {
131 if (kOnes_GrSLConstantVec == defaultExpr) {
132 outAppend->append("1.0");
133 } else {
134 SkASSERT(kZeros_GrSLConstantVec == defaultExpr);
135 outAppend->append("0.0");
136 }
137 }
138 return defaultExpr;
139 } else {
140 outAppend->appendf("(%s).%c", expr, GrColorComponentFlagToChar(component ));
141 return kNone_GrSLConstantVec;
142 }
143 }
OLDNEW
« src/gpu/gl/GrGLSL.h ('K') | « 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