blob: b059d4665fd3c1e345ed75d8507975e295e62ae2 [file] [log] [blame]
egdaniel018fb622015-10-28 07:26:40 -07001/*
2 * Copyright 2015 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
8#ifndef GrGLSLProgramDataManager_DEFINED
9#define GrGLSLProgramDataManager_DEFINED
10
11#include "SkTypes.h"
12
egdaniel7dc4bd02015-10-29 07:57:01 -070013class SkMatrix;
14
egdaniel018fb622015-10-28 07:26:40 -070015/** Manages the resources used by a shader program.
16 * The resources are objects the program uses to communicate with the
17 * application code.
18 */
19class GrGLSLProgramDataManager : SkNoncopyable {
20public:
21 // Opaque handle to a resource
22 class ShaderResourceHandle {
23 public:
24 ShaderResourceHandle(int value)
25 : fValue(value) {
26 SkASSERT(this->isValid());
27 }
28
29 ShaderResourceHandle()
30 : fValue(kInvalid_ShaderResourceHandle) {
31 }
32
33 bool operator==(const ShaderResourceHandle& other) const { return other.fValue == fValue; }
34 bool isValid() const { return kInvalid_ShaderResourceHandle != fValue; }
35 int toIndex() const { SkASSERT(this->isValid()); return fValue; }
36
37 private:
38 static const int kInvalid_ShaderResourceHandle = -1;
39 int fValue;
40 };
41
42 typedef ShaderResourceHandle UniformHandle;
43
44 virtual ~GrGLSLProgramDataManager() {}
45
46 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
47 * array of uniforms. arrayCount must be <= the array count of the uniform.
48 */
49 virtual void set1f(UniformHandle, float v0) const = 0;
50 virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const = 0;
51 virtual void set2f(UniformHandle, float, float) const = 0;
52 virtual void set2fv(UniformHandle, int arrayCount, const float v[]) const = 0;
53 virtual void set3f(UniformHandle, float, float, float) const = 0;
54 virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const = 0;
55 virtual void set4f(UniformHandle, float, float, float, float) const = 0;
56 virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const = 0;
57 // matrices are column-major, the first three upload a single matrix, the latter three upload
58 // arrayCount matrices into a uniform array.
59 virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0;
60 virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0;
61 virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
62 virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
63
64 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform
egdaniel2829bb72016-02-03 09:52:51 -080065 void setSkMatrix(UniformHandle, const SkMatrix&) const;
egdaniel018fb622015-10-28 07:26:40 -070066
67 // for nvpr only
egdaniel0eafe792015-11-20 14:01:22 -080068 typedef ShaderResourceHandle VaryingHandle;
69 virtual void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070070 const SkMatrix& matrix) const = 0;
71
72protected:
73 GrGLSLProgramDataManager() {}
74
75private:
76
77 typedef SkNoncopyable INHERITED;
78};
79
80#endif