| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGLProgramBuilder_DEFINED | 8 #ifndef GrGLProgramBuilder_DEFINED |
| 9 #define GrGLProgramBuilder_DEFINED | 9 #define GrGLProgramBuilder_DEFINED |
| 10 | 10 |
| 11 #include "GrPipeline.h" | 11 #include "GrPipeline.h" |
| 12 #include "gl/GrGLProgramDataManager.h" | 12 #include "gl/GrGLProgramDataManager.h" |
| 13 #include "gl/GrGLUniformHandler.h" |
| 13 #include "gl/GrGLVaryingHandler.h" | 14 #include "gl/GrGLVaryingHandler.h" |
| 14 #include "glsl/GrGLSLPrimitiveProcessor.h" | 15 #include "glsl/GrGLSLPrimitiveProcessor.h" |
| 15 #include "glsl/GrGLSLProgramBuilder.h" | 16 #include "glsl/GrGLSLProgramBuilder.h" |
| 16 #include "glsl/GrGLSLProgramDataManager.h" | 17 #include "glsl/GrGLSLProgramDataManager.h" |
| 17 #include "glsl/GrGLSLTextureSampler.h" | 18 #include "glsl/GrGLSLTextureSampler.h" |
| 18 #include "glsl/GrGLSLXferProcessor.h" | 19 #include "glsl/GrGLSLXferProcessor.h" |
| 19 | 20 |
| 20 class GrFragmentProcessor; | 21 class GrFragmentProcessor; |
| 21 class GrGLContextInfo; | 22 class GrGLContextInfo; |
| 22 class GrGLSLShaderBuilder; | 23 class GrGLSLShaderBuilder; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 51 public: | 52 public: |
| 52 /** Generates a shader program. | 53 /** Generates a shader program. |
| 53 * | 54 * |
| 54 * The program implements what is specified in the stages given as input. | 55 * The program implements what is specified in the stages given as input. |
| 55 * After successful generation, the builder result objects are available | 56 * After successful generation, the builder result objects are available |
| 56 * to be used. | 57 * to be used. |
| 57 * @return true if generation was successful. | 58 * @return true if generation was successful. |
| 58 */ | 59 */ |
| 59 static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*); | 60 static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*); |
| 60 | 61 |
| 61 const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override { | |
| 62 return fUniforms[u.toIndex()].fVariable; | |
| 63 } | |
| 64 | |
| 65 const char* getUniformCStr(UniformHandle u) const override { | |
| 66 return this->getUniformVariable(u).c_str(); | |
| 67 } | |
| 68 | |
| 69 const GrGLSLCaps* glslCaps() const override; | 62 const GrGLSLCaps* glslCaps() const override; |
| 70 | 63 |
| 71 GrGLGpu* gpu() const { return fGpu; } | 64 GrGLGpu* gpu() const { return fGpu; } |
| 72 | 65 |
| 73 private: | 66 private: |
| 74 typedef GrGLProgramDataManager::UniformInfo UniformInfo; | |
| 75 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; | |
| 76 | |
| 77 GrGLProgramBuilder(GrGLGpu*, const DrawArgs&); | 67 GrGLProgramBuilder(GrGLGpu*, const DrawArgs&); |
| 78 | 68 |
| 79 UniformHandle internalAddUniformArray(uint32_t visibility, | |
| 80 GrSLType type, | |
| 81 GrSLPrecision precision, | |
| 82 const char* name, | |
| 83 bool mangleName, | |
| 84 int arrayCount, | |
| 85 const char** outName) override; | |
| 86 | |
| 87 // Generates a possibly mangled name for a stage variable and writes it to t
he fragment shader. | 69 // Generates a possibly mangled name for a stage variable and writes it to t
he fragment shader. |
| 88 // If GrGLSLExpr4 has a valid name then it will use that instead | 70 // If GrGLSLExpr4 has a valid name then it will use that instead |
| 89 void nameExpression(GrGLSLExpr4*, const char* baseName); | 71 void nameExpression(GrGLSLExpr4*, const char* baseName); |
| 90 bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage
); | 72 bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage
); |
| 91 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu
t); | 73 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu
t); |
| 92 void emitAndInstallProc(const GrFragmentProcessor&, | 74 void emitAndInstallProc(const GrFragmentProcessor&, |
| 93 int index, | 75 int index, |
| 94 const GrGLSLExpr4& input, | 76 const GrGLSLExpr4& input, |
| 95 GrGLSLExpr4* output); | 77 GrGLSLExpr4* output); |
| 96 | 78 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 126 GrGLProgram* finalize(); | 108 GrGLProgram* finalize(); |
| 127 void bindProgramResourceLocations(GrGLuint programID); | 109 void bindProgramResourceLocations(GrGLuint programID); |
| 128 bool checkLinkStatus(GrGLuint programID); | 110 bool checkLinkStatus(GrGLuint programID); |
| 129 void resolveProgramResourceLocations(GrGLuint programID); | 111 void resolveProgramResourceLocations(GrGLuint programID); |
| 130 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs
); | 112 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs
); |
| 131 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); | 113 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); |
| 132 | 114 |
| 133 // Subclasses create different programs | 115 // Subclasses create different programs |
| 134 GrGLProgram* createProgram(GrGLuint programID); | 116 GrGLProgram* createProgram(GrGLuint programID); |
| 135 | 117 |
| 136 void onAppendUniformDecls(ShaderVisibility visibility, SkString* out) const
override; | 118 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } |
| 137 | 119 const GrGLSLUniformHandler* uniformHandler() const override { return &fUnifo
rmHandler; } |
| 138 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } | 120 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } |
| 139 | 121 |
| 140 // reset is called by program creator between each processor's emit code. I
t increments the | 122 // reset is called by program creator between each processor's emit code. I
t increments the |
| 141 // stage offset for variable name mangling, and also ensures verfication var
iables in the | 123 // stage offset for variable name mangling, and also ensures verfication var
iables in the |
| 142 // fragment shader are cleared. | 124 // fragment shader are cleared. |
| 143 void reset() { | 125 void reset() { |
| 144 this->addStage(); | 126 this->addStage(); |
| 145 fFS.reset(); | 127 fFS.reset(); |
| 146 } | 128 } |
| 147 void addStage() { fStageIndex++; } | 129 void addStage() { fStageIndex++; } |
| 148 | 130 |
| 149 class AutoStageAdvance { | 131 class AutoStageAdvance { |
| 150 public: | 132 public: |
| 151 AutoStageAdvance(GrGLProgramBuilder* pb) | 133 AutoStageAdvance(GrGLProgramBuilder* pb) |
| 152 : fPB(pb) { | 134 : fPB(pb) { |
| 153 fPB->reset(); | 135 fPB->reset(); |
| 154 // Each output to the fragment processor gets its own code section | 136 // Each output to the fragment processor gets its own code section |
| 155 fPB->fFS.nextStage(); | 137 fPB->fFS.nextStage(); |
| 156 } | 138 } |
| 157 ~AutoStageAdvance() {} | 139 ~AutoStageAdvance() {} |
| 158 private: | 140 private: |
| 159 GrGLProgramBuilder* fPB; | 141 GrGLProgramBuilder* fPB; |
| 160 }; | 142 }; |
| 161 | 143 |
| 162 GrGLInstalledGeoProc* fGeometryProcessor; | 144 GrGLInstalledGeoProc* fGeometryProcessor; |
| 163 GrGLInstalledXferProc* fXferProcessor; | 145 GrGLInstalledXferProc* fXferProcessor; |
| 164 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; | 146 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; |
| 165 | 147 |
| 166 GrGLGpu* fGpu; | 148 GrGLGpu* fGpu; |
| 167 UniformInfoArray fUniforms; | |
| 168 GrGLSLPrimitiveProcessor::TransformsIn fCoordTransforms; | 149 GrGLSLPrimitiveProcessor::TransformsIn fCoordTransforms; |
| 169 GrGLSLPrimitiveProcessor::TransformsOut fOutCoords; | 150 GrGLSLPrimitiveProcessor::TransformsOut fOutCoords; |
| 151 typedef GrGLSLUniformHandler::UniformHandle UniformHandle; |
| 170 SkTArray<UniformHandle> fSamplerUniforms; | 152 SkTArray<UniformHandle> fSamplerUniforms; |
| 171 | 153 |
| 172 GrGLVaryingHandler fVaryingHandler; | 154 GrGLVaryingHandler fVaryingHandler; |
| 173 | 155 GrGLUniformHandler fUniformHandler; |
| 174 friend class GrGLVaryingHandler; | |
| 175 | 156 |
| 176 typedef GrGLSLProgramBuilder INHERITED; | 157 typedef GrGLSLProgramBuilder INHERITED; |
| 177 }; | 158 }; |
| 178 #endif | 159 #endif |
| OLD | NEW |