| 1 |
/* |
| 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 GrGLUniformHandler_DEFINED |
| 9 |
#define GrGLUniformHandler_DEFINED |
| 10 |
|
| 11 |
#include "include/gpu/ganesh/gl/GrGLTypes.h" |
| 12 |
#include "include/private/base/SkTArray.h" |
| 13 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 14 |
#include "src/gpu/Swizzle.h" |
| 15 |
#include "src/gpu/ganesh/GrSamplerState.h" |
| 16 |
#include "src/gpu/ganesh/GrShaderVar.h" |
| 17 |
#include "src/gpu/ganesh/gl/GrGLProgramDataManager.h" |
| 18 |
#include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.h" |
| 19 |
|
| 20 |
#include <cstdint> |
| 21 |
|
| 22 |
class GrBackendFormat; |
| 23 |
class GrGLCaps; |
| 24 |
class GrGLGpu; |
| 25 |
class GrGLSLProgramBuilder; |
| 26 |
class GrProcessor; |
| 27 |
class SkString; |
| 28 |
enum class SkSLType : char; |
| 29 |
struct GrShaderCaps; |
| 30 |
|
| 31 |
class GrGLUniformHandler : public GrGLSLUniformHandler { |
| 32 |
public: |
| 33 |
static const int kUniformsPerBlock = 8; |
| 34 |
|
| 35 |
const GrShaderVar& getUniformVariable(UniformHandle u) const override { |
| 36 |
return fUniforms.item(u.toIndex()).fVariable; |
| 37 |
} |
| 38 |
|
| 39 |
const char* getUniformCStr(UniformHandle u) const override { |
| 40 |
return this->getUniformVariable(u).c_str(); |
| 41 |
} |
| 42 |
|
| 43 |
int numUniforms() const override { |
| 44 |
return fUniforms.count(); |
| 45 |
} |
| 46 |
|
| 47 |
UniformInfo& uniform(int idx) override { |
| 48 |
return fUniforms.item(idx); |
| 49 |
} |
| 50 |
const UniformInfo& uniform(int idx) const override { |
| 51 |
return fUniforms.item(idx); |
| 52 |
} |
| 53 |
|
| 54 |
private: |
| 55 |
explicit GrGLUniformHandler(GrGLSLProgramBuilder* program) |
| 56 |
: INHERITED(program) |
| 57 |
, fUniforms(kUniformsPerBlock) |
| 58 |
, fSamplers(kUniformsPerBlock) {} |
| 59 |
|
| 60 |
UniformHandle internalAddUniformArray(const GrProcessor* owner, |
| 61 |
uint32_t visibility, |
| 62 |
SkSLType type, |
| 63 |
const char* name, |
| 64 |
bool mangleName, |
| 65 |
int arrayCount, |
| 66 |
const char** outName) override; |
| 67 |
|
| 68 |
SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const skgpu::Swizzle&, |
| 69 |
const char* name, const GrShaderCaps*) override; |
| 70 |
|
| 71 |
const char* samplerVariable(SamplerHandle handle) const override { |
| 72 |
return fSamplers.item(handle.toIndex()).fVariable.c_str(); |
| 73 |
} |
| 74 |
|
| 75 |
skgpu::Swizzle samplerSwizzle(SamplerHandle handle) const override { |
| 76 |
return fSamplerSwizzles[handle.toIndex()]; |
| 77 |
} |
| 78 |
|
| 79 |
void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; |
| 80 |
|
| 81 |
// Manually set uniform locations for all our uniforms. |
| 82 |
void bindUniformLocations(GrGLuint programID, const GrGLCaps& caps); |
| 83 |
|
| 84 |
// Updates the loction of the Uniforms if we cannot bind uniform locations manually |
| 85 |
void getUniformLocations(GrGLuint programID, const GrGLCaps& caps, bool force); |
| 86 |
|
| 87 |
const GrGLGpu* glGpu() const; |
| 88 |
|
| 89 |
typedef GrGLProgramDataManager::GLUniformInfo GLUniformInfo; |
| 90 |
typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; |
| 91 |
|
| 92 |
UniformInfoArray fUniforms; |
| 93 |
UniformInfoArray fSamplers; |
| 94 |
skia_private::TArray<skgpu::Swizzle> fSamplerSwizzles; |
| 95 |
|
| 96 |
friend class GrGLProgramBuilder; |
| 97 |
|
| 98 |
using INHERITED = GrGLSLUniformHandler; |
| 99 |
}; |
| 100 |
|
| 101 |
#endif |