blob: 8d58fc8b9daef491dccad133554d400e639a804a [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
egdaniel167ab912016-05-09 11:03:48 -070011#include "GrResourceHandle.h"
egdaniel018fb622015-10-28 07:26:40 -070012#include "SkTypes.h"
13
egdaniel7dc4bd02015-10-29 07:57:01 -070014class SkMatrix;
brianosman51924752016-09-12 08:50:19 -070015class SkMatrix44;
egdaniel7dc4bd02015-10-29 07:57:01 -070016
egdaniel018fb622015-10-28 07:26:40 -070017/** Manages the resources used by a shader program.
18 * The resources are objects the program uses to communicate with the
19 * application code.
20 */
21class GrGLSLProgramDataManager : SkNoncopyable {
22public:
egdaniel167ab912016-05-09 11:03:48 -070023 GR_DEFINE_RESOURCE_HANDLE_CLASS(UniformHandle);
egdaniel018fb622015-10-28 07:26:40 -070024
25 virtual ~GrGLSLProgramDataManager() {}
26
27 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
28 * array of uniforms. arrayCount must be <= the array count of the uniform.
29 */
fmenozzi497e9e22016-06-21 09:42:12 -070030 virtual void set1i(UniformHandle, int32_t) const = 0;
fmenozzi35a98c72016-07-20 08:26:12 -070031 virtual void set1iv(UniformHandle, int arrayCount, const int v[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070032 virtual void set1f(UniformHandle, float v0) const = 0;
33 virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const = 0;
34 virtual void set2f(UniformHandle, float, float) const = 0;
35 virtual void set2fv(UniformHandle, int arrayCount, const float v[]) const = 0;
36 virtual void set3f(UniformHandle, float, float, float) const = 0;
37 virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const = 0;
38 virtual void set4f(UniformHandle, float, float, float, float) const = 0;
39 virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const = 0;
40 // matrices are column-major, the first three upload a single matrix, the latter three upload
41 // arrayCount matrices into a uniform array.
cdalton8d988b32016-03-07 15:39:09 -080042 virtual void setMatrix2f(UniformHandle, const float matrix[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070043 virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0;
44 virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0;
cdalton8d988b32016-03-07 15:39:09 -080045 virtual void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070046 virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
47 virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
48
49 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform
egdaniel2829bb72016-02-03 09:52:51 -080050 void setSkMatrix(UniformHandle, const SkMatrix&) const;
egdaniel018fb622015-10-28 07:26:40 -070051
brianosman51924752016-09-12 08:50:19 -070052 // convenience method for uploading a SkMatrix44 to a 4x4 matrix uniform
53 void setSkMatrix44(UniformHandle, const SkMatrix44&) const;
54
egdaniel018fb622015-10-28 07:26:40 -070055 // for nvpr only
egdaniel167ab912016-05-09 11:03:48 -070056 GR_DEFINE_RESOURCE_HANDLE_CLASS(VaryingHandle);
egdaniel0eafe792015-11-20 14:01:22 -080057 virtual void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070058 const SkMatrix& matrix) const = 0;
59
60protected:
61 GrGLSLProgramDataManager() {}
62
63private:
egdaniel018fb622015-10-28 07:26:40 -070064 typedef SkNoncopyable INHERITED;
65};
66
67#endif