blob: e578e11808868163ce18c41e0093601f78d025bf [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.
cdalton8d988b32016-03-07 15:39:09 -080059 virtual void setMatrix2f(UniformHandle, const float matrix[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070060 virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0;
61 virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0;
cdalton8d988b32016-03-07 15:39:09 -080062 virtual void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070063 virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
64 virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
65
66 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform
egdaniel2829bb72016-02-03 09:52:51 -080067 void setSkMatrix(UniformHandle, const SkMatrix&) const;
egdaniel018fb622015-10-28 07:26:40 -070068
69 // for nvpr only
egdaniel0eafe792015-11-20 14:01:22 -080070 typedef ShaderResourceHandle VaryingHandle;
71 virtual void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070072 const SkMatrix& matrix) const = 0;
73
74protected:
75 GrGLSLProgramDataManager() {}
76
77private:
78
79 typedef SkNoncopyable INHERITED;
80};
81
82#endif