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

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: addressing review comments 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
« 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return "#version 150\n"; 56 return "#version 150\n";
57 } else { 57 } else {
58 return "#version 150 compatibility\n"; 58 return "#version 150 compatibility\n";
59 } 59 }
60 default: 60 default:
61 GrCrash("Unknown GL version."); 61 GrCrash("Unknown GL version.");
62 return ""; // suppress warning 62 return ""; // suppress warning
63 } 63 }
64 } 64 }
65 65
66 const char* GrGLSLVectorHomogCoord(int count) {
67 static const char* HOMOGS[] = {"ERROR", "", ".y", ".z", ".w"};
68 SkASSERT(count >= 1 && count < (int)GR_ARRAY_COUNT(HOMOGS));
69 return HOMOGS[count];
70 }
71
72 const char* GrGLSLVectorHomogCoord(GrSLType type) {
73 return GrGLSLVectorHomogCoord(GrSLTypeToVecLength(type));
74 }
75
76 const char* GrGLSLVectorNonhomogCoords(int count) {
77 static const char* NONHOMOGS[] = {"ERROR", "", ".x", ".xy", ".xyz"};
78 SkASSERT(count >= 1 && count < (int)GR_ARRAY_COUNT(NONHOMOGS));
79 return NONHOMOGS[count];
80 }
81
82 const char* GrGLSLVectorNonhomogCoords(GrSLType type) {
83 return GrGLSLVectorNonhomogCoords(GrSLTypeToVecLength(type));
84 }
85
86 namespace { 66 namespace {
87 void append_tabs(SkString* outAppend, int tabCnt) { 67 void append_tabs(SkString* outAppend, int tabCnt) {
88 static const char kTabs[] = "\t\t\t\t\t\t\t\t"; 68 static const char kTabs[] = "\t\t\t\t\t\t\t\t";
89 while (tabCnt) { 69 while (tabCnt) {
90 int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt); 70 int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt);
91 outAppend->append(kTabs, cnt); 71 outAppend->append(kTabs, cnt);
92 tabCnt -= cnt; 72 tabCnt -= cnt;
93 } 73 }
94 } 74 }
95 } 75 }
96 76
97 GrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend, 77 void GrGLSLMulVarBy4f(SkString* outAppend,
98 int tabCnt, 78 unsigned tabCnt,
99 const char* vec4VarName, 79 const char* vec4VarName,
100 const char* mulFactor, 80 const GrGLSLExpr<4>& mulFactor) {
101 GrSLConstantVec mulFactorDefault) { 81 if (mulFactor.isOnes()) {
102 bool haveFactor = NULL != mulFactor && '\0' != *mulFactor; 82 *outAppend = SkString();
83 }
103 84
104 SkASSERT(NULL != outAppend); 85 append_tabs(outAppend, tabCnt);
105 SkASSERT(NULL != vec4VarName);
106 SkASSERT(kNone_GrSLConstantVec != mulFactorDefault || haveFactor);
107 86
108 if (!haveFactor) { 87 if (mulFactor.isZeros()) {
109 if (kOnes_GrSLConstantVec == mulFactorDefault) { 88 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 } 89 }
118 append_tabs(outAppend, tabCnt); 90 outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor.c_str());
119 outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor);
120 return kNone_GrSLConstantVec;
121 } 91 }
122 92
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
« 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