GrGLSLVertexGeoBuilder.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2017 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. #ifndef GrGLSLVertexGeoBuilder_DEFINED
  8. #define GrGLSLVertexGeoBuilder_DEFINED
  9. #include "src/gpu/glsl/GrGLSLShaderBuilder.h"
  10. /**
  11. * Base class for vertex and geometry shader builders. This is the stage that computes input
  12. * geometry for the rasterizer.
  13. */
  14. class GrGLSLVertexGeoBuilder : public GrGLSLShaderBuilder {
  15. protected:
  16. GrGLSLVertexGeoBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
  17. void emitNormalizedSkPosition(const char* devPos, const char* rtAdjustName,
  18. GrSLType devPosType = GrSLType::kFloat2_GrSLType) {
  19. this->emitNormalizedSkPosition(&this->code(), devPos, rtAdjustName, devPosType);
  20. }
  21. void emitNormalizedSkPosition(SkString* out, const char* devPos, const char* rtAdjustName,
  22. GrSLType devPosType = GrSLType::kFloat2_GrSLType);
  23. friend class GrGLSLGeometryProcessor;
  24. typedef GrGLSLShaderBuilder INHERITED;
  25. };
  26. class GrGLSLVertexBuilder : public GrGLSLVertexGeoBuilder {
  27. public:
  28. GrGLSLVertexBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
  29. private:
  30. void onFinalize() override;
  31. friend class GrGLProgramBuilder;
  32. typedef GrGLSLVertexGeoBuilder INHERITED;
  33. };
  34. class GrGLSLGeometryBuilder : public GrGLSLVertexGeoBuilder {
  35. public:
  36. GrGLSLGeometryBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
  37. enum class InputType {
  38. kPoints,
  39. kLines,
  40. kLinesAdjacency,
  41. kTriangles,
  42. kTrianglesAdjacency
  43. };
  44. enum class OutputType {
  45. kPoints,
  46. kLineStrip,
  47. kTriangleStrip
  48. };
  49. void configure(InputType, OutputType, int maxVertices, int numInvocations = 1);
  50. bool isConfigured() const { return fNumInvocations; }
  51. void emitVertex(const char* devPos, const char* rtAdjustName,
  52. GrSLType devPosType = GrSLType::kFloat2_GrSLType) {
  53. this->emitVertex(&this->code(), devPos, rtAdjustName, devPosType);
  54. }
  55. void emitVertex(SkString* out, const char* devPos, const char* rtAdjustName,
  56. GrSLType devPosType = GrSLType::kFloat2_GrSLType);
  57. void endPrimitive();
  58. private:
  59. void onFinalize() override;
  60. int fNumInvocations = 0;
  61. friend class GrGLProgramBuilder;
  62. typedef GrGLSLVertexGeoBuilder INHERITED;
  63. };
  64. #endif