| OLD | NEW |
| 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 #ifndef GrGLShaderVar_DEFINED | 8 #ifndef GrGLShaderVar_DEFINED |
| 9 #define GrGLShaderVar_DEFINED | 9 #define GrGLShaderVar_DEFINED |
| 10 | 10 |
| 11 #include "GrGLContext.h" | |
| 12 #include "GrShaderVar.h" | 11 #include "GrShaderVar.h" |
| 12 #include "../glsl/GrGLSL.h" |
| 13 #include "../glsl/GrGLSLCaps.h" |
| 13 | 14 |
| 14 #define USE_UNIFORM_FLOAT_ARRAYS true | 15 #define USE_UNIFORM_FLOAT_ARRAYS true |
| 15 | 16 |
| 16 /** | 17 /** |
| 17 * Represents a variable in a shader | 18 * Represents a variable in a shader |
| 18 */ | 19 */ |
| 19 class GrGLShaderVar : public GrShaderVar { | 20 class GrGLShaderVar : public GrShaderVar { |
| 20 public: | 21 public: |
| 21 /** | 22 /** |
| 22 * See GL_ARB_fragment_coord_conventions. | 23 * See GL_ARB_fragment_coord_conventions. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 Origin getOrigin() const { return fOrigin; } | 149 Origin getOrigin() const { return fOrigin; } |
| 149 | 150 |
| 150 /** | 151 /** |
| 151 * Set the origin of the var | 152 * Set the origin of the var |
| 152 */ | 153 */ |
| 153 void setOrigin(Origin origin) { fOrigin = origin; } | 154 void setOrigin(Origin origin) { fOrigin = origin; } |
| 154 | 155 |
| 155 /** | 156 /** |
| 156 * Write a declaration of this variable to out. | 157 * Write a declaration of this variable to out. |
| 157 */ | 158 */ |
| 158 void appendDecl(const GrGLContextInfo& ctxInfo, SkString* out) const { | 159 void appendDecl(const GrGLSLCaps* glslCaps, SkString* out) const { |
| 159 SkASSERT(kDefault_GrSLPrecision == fPrecision || GrSLTypeIsFloatType(fTy
pe)); | 160 SkASSERT(kDefault_GrSLPrecision == fPrecision || GrSLTypeIsFloatType(fTy
pe)); |
| 160 if (kUpperLeft_Origin == fOrigin) { | 161 if (kUpperLeft_Origin == fOrigin) { |
| 161 // this is the only place where we specify a layout modifier. If we
use other layout | 162 // this is the only place where we specify a layout modifier. If we
use other layout |
| 162 // modifiers in the future then they should be placed in a list. | 163 // modifiers in the future then they should be placed in a list. |
| 163 out->append("layout(origin_upper_left) "); | 164 out->append("layout(origin_upper_left) "); |
| 164 } | 165 } |
| 165 if (this->getTypeModifier() != kNone_TypeModifier) { | 166 if (this->getTypeModifier() != kNone_TypeModifier) { |
| 166 out->append(TypeModifierString(this->getTypeModifier(), ctxInfo.glslG
eneration())); | 167 out->append(TypeModifierString(glslCaps, this->getTypeModifier())); |
| 167 out->append(" "); | 168 out->append(" "); |
| 168 } | 169 } |
| 169 out->append(PrecisionString(fPrecision, ctxInfo.standard())); | 170 out->append(PrecisionString(glslCaps, fPrecision)); |
| 170 GrSLType effectiveType = this->getType(); | 171 GrSLType effectiveType = this->getType(); |
| 171 if (this->isArray()) { | 172 if (this->isArray()) { |
| 172 if (this->isUnsizedArray()) { | 173 if (this->isUnsizedArray()) { |
| 173 out->appendf("%s %s[]", | 174 out->appendf("%s %s[]", |
| 174 GrGLSLTypeString(effectiveType), | 175 GrGLSLTypeString(effectiveType), |
| 175 this->getName().c_str()); | 176 this->getName().c_str()); |
| 176 } else { | 177 } else { |
| 177 SkASSERT(this->getArrayCount() > 0); | 178 SkASSERT(this->getArrayCount() > 0); |
| 178 out->appendf("%s %s[%d]", | 179 out->appendf("%s %s[%d]", |
| 179 GrGLSLTypeString(effectiveType), | 180 GrGLSLTypeString(effectiveType), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 194 fUseUniformFloatArrays ? "" : ".x"); | 195 fUseUniformFloatArrays ? "" : ".x"); |
| 195 } | 196 } |
| 196 | 197 |
| 197 void appendArrayAccess(const char* indexName, SkString* out) const { | 198 void appendArrayAccess(const char* indexName, SkString* out) const { |
| 198 out->appendf("%s[%s]%s", | 199 out->appendf("%s[%s]%s", |
| 199 this->getName().c_str(), | 200 this->getName().c_str(), |
| 200 indexName, | 201 indexName, |
| 201 fUseUniformFloatArrays ? "" : ".x"); | 202 fUseUniformFloatArrays ? "" : ".x"); |
| 202 } | 203 } |
| 203 | 204 |
| 204 static const char* PrecisionString(GrSLPrecision p, GrGLStandard standard) { | 205 static const char* PrecisionString(const GrGLSLCaps* glslCaps, GrSLPrecision
p) { |
| 205 // Desktop GLSL has added precision qualifiers but they don't do anythin
g. | 206 // Desktop GLSL has added precision qualifiers but they don't do anythin
g. |
| 206 if (kGLES_GrGLStandard == standard) { | 207 if (glslCaps->usesPrecisionModifiers()) { |
| 207 switch (p) { | 208 switch (p) { |
| 208 case kLow_GrSLPrecision: | 209 case kLow_GrSLPrecision: |
| 209 return "lowp "; | 210 return "lowp "; |
| 210 case kMedium_GrSLPrecision: | 211 case kMedium_GrSLPrecision: |
| 211 return "mediump "; | 212 return "mediump "; |
| 212 case kHigh_GrSLPrecision: | 213 case kHigh_GrSLPrecision: |
| 213 return "highp "; | 214 return "highp "; |
| 214 default: | 215 default: |
| 215 SkFAIL("Unexpected precision type."); | 216 SkFAIL("Unexpected precision type."); |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 return ""; | 219 return ""; |
| 219 } | 220 } |
| 220 | 221 |
| 221 private: | 222 private: |
| 222 static const char* TypeModifierString(TypeModifier t, GrGLSLGeneration gen)
{ | 223 static const char* TypeModifierString(const GrGLSLCaps* glslCaps, TypeModifi
er t) { |
| 224 GrGLSLGeneration gen = glslCaps->generation(); |
| 223 switch (t) { | 225 switch (t) { |
| 224 case kNone_TypeModifier: | 226 case kNone_TypeModifier: |
| 225 return ""; | 227 return ""; |
| 226 case kIn_TypeModifier: | 228 case kIn_TypeModifier: |
| 227 return "in"; | 229 return "in"; |
| 228 case kInOut_TypeModifier: | 230 case kInOut_TypeModifier: |
| 229 return "inout"; | 231 return "inout"; |
| 230 case kOut_TypeModifier: | 232 case kOut_TypeModifier: |
| 231 return "out"; | 233 return "out"; |
| 232 case kUniform_TypeModifier: | 234 case kUniform_TypeModifier: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 245 | 247 |
| 246 Origin fOrigin; | 248 Origin fOrigin; |
| 247 /// Work around driver bugs on some hardware that don't correctly | 249 /// Work around driver bugs on some hardware that don't correctly |
| 248 /// support uniform float [] | 250 /// support uniform float [] |
| 249 bool fUseUniformFloatArrays; | 251 bool fUseUniformFloatArrays; |
| 250 | 252 |
| 251 typedef GrShaderVar INHERITED; | 253 typedef GrShaderVar INHERITED; |
| 252 }; | 254 }; |
| 253 | 255 |
| 254 #endif | 256 #endif |
| OLD | NEW |