blob: 30e3d0c4808e2d851f79ca18fb986023c1fb181b [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"
Ben Wagnerd5148e32018-07-16 17:44:06 -040012#include "SkNoncopyable.h"
egdaniel018fb622015-10-28 07:26:40 -070013#include "SkTypes.h"
14
egdaniel7dc4bd02015-10-29 07:57:01 -070015class SkMatrix;
brianosman51924752016-09-12 08:50:19 -070016class SkMatrix44;
egdaniel7dc4bd02015-10-29 07:57:01 -070017
egdaniel018fb622015-10-28 07:26:40 -070018/** Manages the resources used by a shader program.
19 * The resources are objects the program uses to communicate with the
20 * application code.
21 */
22class GrGLSLProgramDataManager : SkNoncopyable {
23public:
egdaniel167ab912016-05-09 11:03:48 -070024 GR_DEFINE_RESOURCE_HANDLE_CLASS(UniformHandle);
egdaniel018fb622015-10-28 07:26:40 -070025
26 virtual ~GrGLSLProgramDataManager() {}
27
28 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
29 * array of uniforms. arrayCount must be <= the array count of the uniform.
30 */
fmenozzi497e9e22016-06-21 09:42:12 -070031 virtual void set1i(UniformHandle, int32_t) const = 0;
fmenozzi35a98c72016-07-20 08:26:12 -070032 virtual void set1iv(UniformHandle, int arrayCount, const int v[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070033 virtual void set1f(UniformHandle, float v0) const = 0;
34 virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const = 0;
Michael Ludwig779ed022018-08-28 17:20:07 -040035 virtual void set2i(UniformHandle, int32_t, int32_t) const = 0;
36 virtual void set2iv(UniformHandle, int arrayCount, const int v[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070037 virtual void set2f(UniformHandle, float, float) const = 0;
38 virtual void set2fv(UniformHandle, int arrayCount, const float v[]) const = 0;
Michael Ludwig779ed022018-08-28 17:20:07 -040039 virtual void set3i(UniformHandle, int32_t, int32_t, int32_t) const = 0;
40 virtual void set3iv(UniformHandle, int arrayCount, const int v[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070041 virtual void set3f(UniformHandle, float, float, float) const = 0;
42 virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const = 0;
Michael Ludwig779ed022018-08-28 17:20:07 -040043 virtual void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const = 0;
44 virtual void set4iv(UniformHandle, int arrayCount, const int v[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070045 virtual void set4f(UniformHandle, float, float, float, float) const = 0;
46 virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const = 0;
47 // matrices are column-major, the first three upload a single matrix, the latter three upload
48 // arrayCount matrices into a uniform array.
cdalton8d988b32016-03-07 15:39:09 -080049 virtual void setMatrix2f(UniformHandle, const float matrix[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070050 virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0;
51 virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0;
cdalton8d988b32016-03-07 15:39:09 -080052 virtual void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
egdaniel018fb622015-10-28 07:26:40 -070053 virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
54 virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
55
56 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform
egdaniel2829bb72016-02-03 09:52:51 -080057 void setSkMatrix(UniformHandle, const SkMatrix&) const;
egdaniel018fb622015-10-28 07:26:40 -070058
brianosman51924752016-09-12 08:50:19 -070059 // convenience method for uploading a SkMatrix44 to a 4x4 matrix uniform
60 void setSkMatrix44(UniformHandle, const SkMatrix44&) const;
61
egdaniel018fb622015-10-28 07:26:40 -070062 // for nvpr only
egdaniel167ab912016-05-09 11:03:48 -070063 GR_DEFINE_RESOURCE_HANDLE_CLASS(VaryingHandle);
egdaniel0eafe792015-11-20 14:01:22 -080064 virtual void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070065 const SkMatrix& matrix) const = 0;
66
67protected:
68 GrGLSLProgramDataManager() {}
69
70private:
egdaniel018fb622015-10-28 07:26:40 -070071 typedef SkNoncopyable INHERITED;
72};
73
74#endif