OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2012 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 GrGLUniform_DEFINED |
| 9 #define GrGLUniform_DEFINED |
| 10 |
| 11 #include "gl/GrGLShaderVar.h" |
| 12 #include "gl/GrGLSL.h" |
| 13 #include "GrAllocator.h" |
| 14 |
| 15 #include "SkTArray.h" |
| 16 |
| 17 class GrGLContext; |
| 18 class SkMatrix; |
| 19 |
| 20 /** Wrapper for a uniform in a program. |
| 21 */ |
| 22 class GrGLUniform { |
| 23 enum { |
| 24 kUnusedUniform = -1, |
| 25 }; |
| 26 |
| 27 public: |
| 28 GrGLUniform() |
| 29 : fVSLocation(kUnusedUniform) |
| 30 , fFSLocation(kUnusedUniform) { |
| 31 } |
| 32 |
| 33 #if GR_DEBUG |
| 34 void initType(int arrayCount, GrSLType type) { |
| 35 GrAssert(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0); |
| 36 fArrayCount = arrayCount; |
| 37 fType = type; |
| 38 } |
| 39 #endif |
| 40 |
| 41 void initLocations(const GrGLContext& context, GrGLuint programID, const cha
r* name, uint32_t visibility); |
| 42 |
| 43 /** Functions for uploading uniform values. The varities ending in v can be
used to upload to an |
| 44 * array of uniforms. offset + arrayCount must be <= the array count of the
uniform. |
| 45 */ |
| 46 void setSampler(const GrGLContext&, GrGLint texUnit) const; |
| 47 void set1f(const GrGLContext&, GrGLfloat v0) const; |
| 48 void set1fv(const GrGLContext&, int offset, int arrayCount, const GrGLfloat
v[]) const; |
| 49 void set2f(const GrGLContext&, GrGLfloat, GrGLfloat) const; |
| 50 void set2fv(const GrGLContext&, int offset, int arrayCount, const GrGLfloat
v[]) const; |
| 51 void set3f(const GrGLContext&, GrGLfloat, GrGLfloat, GrGLfloat) const; |
| 52 void set3fv(const GrGLContext&, int offset, int arrayCount, const GrGLfloat
v[]) const; |
| 53 void set4f(const GrGLContext&, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) c
onst; |
| 54 void set4fv(const GrGLContext&, int offset, int arrayCount, const GrGLfloat
v[]) const; |
| 55 // matrices are column-major, the first three upload a single matrix, the la
tter three upload |
| 56 // arrayCount matrices into a uniform array. |
| 57 void setMatrix3f(const GrGLContext&, const GrGLfloat matrix[]) const; |
| 58 void setMatrix4f(const GrGLContext&, const GrGLfloat matrix[]) const; |
| 59 void setMatrix3fv(const GrGLContext&, int offset, int arrayCount, const GrGL
float matrices[]) const; |
| 60 void setMatrix4fv(const GrGLContext&, int offset, int arrayCount, const GrGL
float matrices[]) const; |
| 61 |
| 62 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform |
| 63 void setSkMatrix(const GrGLContext&, const SkMatrix&) const; |
| 64 |
| 65 private: |
| 66 GrGLint fVSLocation; |
| 67 GrGLint fFSLocation; |
| 68 #if GR_DEBUG |
| 69 int fArrayCount; |
| 70 GrSLType fType; |
| 71 #endif |
| 72 }; |
| 73 |
| 74 #endif |
OLD | NEW |