GrShaderVar.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/GrShaderCaps.h"
  8. #include "src/gpu/GrShaderVar.h"
  9. static const char* type_modifier_string(GrShaderVar::TypeModifier t) {
  10. switch (t) {
  11. case GrShaderVar::kNone_TypeModifier: return "";
  12. case GrShaderVar::kIn_TypeModifier: return "in";
  13. case GrShaderVar::kInOut_TypeModifier: return "inout";
  14. case GrShaderVar::kOut_TypeModifier: return "out";
  15. case GrShaderVar::kUniform_TypeModifier: return "uniform";
  16. }
  17. SK_ABORT("Unknown shader variable type modifier.");
  18. return "";
  19. }
  20. void GrShaderVar::setIOType(GrIOType ioType) {
  21. switch (ioType) {
  22. case kRW_GrIOType:
  23. return;
  24. case kRead_GrIOType:
  25. this->addModifier("readonly");
  26. return;
  27. case kWrite_GrIOType:
  28. this->addModifier("writeonly");
  29. return;
  30. }
  31. SK_ABORT("Unknown io type.");
  32. }
  33. void GrShaderVar::appendDecl(const GrShaderCaps* shaderCaps, SkString* out) const {
  34. SkString layout = fLayoutQualifier;
  35. if (!fLayoutQualifier.isEmpty()) {
  36. out->appendf("layout(%s) ", fLayoutQualifier.c_str());
  37. }
  38. out->append(fExtraModifiers);
  39. if (this->getTypeModifier() != kNone_TypeModifier) {
  40. out->append(type_modifier_string(this->getTypeModifier()));
  41. out->append(" ");
  42. }
  43. GrSLType effectiveType = this->getType();
  44. if (this->isArray()) {
  45. if (this->isUnsizedArray()) {
  46. out->appendf("%s %s[]", GrGLSLTypeString(effectiveType), this->getName().c_str());
  47. } else {
  48. SkASSERT(this->getArrayCount() > 0);
  49. out->appendf("%s %s[%d]",
  50. GrGLSLTypeString(effectiveType),
  51. this->getName().c_str(),
  52. this->getArrayCount());
  53. }
  54. } else {
  55. out->appendf("%s %s", GrGLSLTypeString(effectiveType), this->getName().c_str());
  56. }
  57. }