| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
| 9 #ifndef GrGLProgram_DEFINED | 9 #ifndef GrGLProgram_DEFINED |
| 10 #define GrGLProgram_DEFINED | 10 #define GrGLProgram_DEFINED |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 destVec[2] = -2.f / fRenderTargetSize.fHeight; | 83 destVec[2] = -2.f / fRenderTargetSize.fHeight; |
| 84 destVec[3] = 1.f; | 84 destVec[3] = 1.f; |
| 85 } else { | 85 } else { |
| 86 destVec[2] = 2.f / fRenderTargetSize.fHeight; | 86 destVec[2] = 2.f / fRenderTargetSize.fHeight; |
| 87 destVec[3] = -1.f; | 87 destVec[3] = -1.f; |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * This function uploads uniforms and calls each GrGLProcessor's setData. It
is called before a | 93 * This function uploads uniforms, calls each GrGLProcessor's setData, and r
etrieves the |
| 94 * draw occurs using the program after the program has already been bound. I
t also uses the | 94 * textures that need to be bound on each unit. It is the caller's responsib
ility to ensure |
| 95 * GrGLGpu object to bind the textures required by the GrGLProcessors. The c
olor and coverage | 95 * the program is bound before calling, and to bind the outgoing textures to
their respective |
| 96 * stages come from GrGLProgramDesc::Build(). | 96 * units upon return. (Each index in the array corresponds to its matching G
L texture unit.) |
| 97 */ | 97 */ |
| 98 void setData(const GrPrimitiveProcessor&, const GrPipeline&, const GrBatchTr
acker&); | 98 void setData(const GrPrimitiveProcessor&, const GrPipeline&, const GrBatchTr
acker&, |
| 99 SkTArray<const GrTextureAccess*>* textureBindings); |
| 99 | 100 |
| 100 protected: | 101 protected: |
| 101 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 102 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 102 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; | 103 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; |
| 103 | 104 |
| 104 GrGLProgram(GrGLGpu*, | 105 GrGLProgram(GrGLGpu*, |
| 105 const GrProgramDesc&, | 106 const GrProgramDesc&, |
| 106 const BuiltinUniformHandles&, | 107 const BuiltinUniformHandles&, |
| 107 GrGLuint programID, | 108 GrGLuint programID, |
| 108 const UniformInfoArray&, | 109 const UniformInfoArray&, |
| 109 GrGLInstalledGeoProc* geometryProcessor, | 110 GrGLInstalledGeoProc* geometryProcessor, |
| 110 GrGLInstalledXferProc* xferProcessor, | 111 GrGLInstalledXferProc* xferProcessor, |
| 111 GrGLInstalledFragProcs* fragmentProcessors); | 112 GrGLInstalledFragProcs* fragmentProcessors, |
| 112 | 113 SkTArray<UniformHandle>* passSamplerUniforms); |
| 113 // Sets the texture units for samplers. | |
| 114 void initSamplerUniforms(); | |
| 115 template <class Proc> | |
| 116 void initSamplers(Proc*, int* texUnitIdx); | |
| 117 | 114 |
| 118 // A templated helper to loop over effects, set the transforms(via subclass)
and bind textures | 115 // A templated helper to loop over effects, set the transforms(via subclass)
and bind textures |
| 119 void setFragmentData(const GrPrimitiveProcessor&, const GrPipeline&); | 116 void setFragmentData(const GrPrimitiveProcessor&, const GrPipeline&, |
| 117 SkTArray<const GrTextureAccess*>* textureBindings); |
| 120 virtual void setTransformData(const GrPrimitiveProcessor&, | 118 virtual void setTransformData(const GrPrimitiveProcessor&, |
| 121 const GrPendingFragmentStage&, | 119 const GrPendingFragmentStage&, |
| 122 int index, | 120 int index, |
| 123 GrGLInstalledFragProc*); | 121 GrGLInstalledFragProc*); |
| 124 template <class Proc> | |
| 125 void bindTextures(const Proc*, const GrProcessor&); | |
| 126 | 122 |
| 127 /* | 123 /* |
| 128 * Legacy NVPR needs a hook here to flush path tex gen settings. | 124 * Legacy NVPR needs a hook here to flush path tex gen settings. |
| 129 * TODO when legacy nvpr is removed, remove this call. | 125 * TODO when legacy nvpr is removed, remove this call. |
| 130 */ | 126 */ |
| 131 virtual void didSetData() {} | 127 virtual void didSetData() {} |
| 132 | 128 |
| 133 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform | 129 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform |
| 134 void setRenderTargetState(const GrPrimitiveProcessor&, const GrPipeline&); | 130 void setRenderTargetState(const GrPrimitiveProcessor&, const GrPipeline&); |
| 135 virtual void onSetRenderTargetState(const GrPrimitiveProcessor&, const GrPip
eline&); | 131 virtual void onSetRenderTargetState(const GrPrimitiveProcessor&, const GrPip
eline&); |
| 136 | 132 |
| 137 // these reflect the current values of uniforms (GL uniform values travel wi
th program) | 133 // these reflect the current values of uniforms (GL uniform values travel wi
th program) |
| 138 RenderTargetState fRenderTargetState; | 134 RenderTargetState fRenderTargetState; |
| 139 GrColor fColor; | 135 GrColor fColor; |
| 140 uint8_t fCoverage; | 136 uint8_t fCoverage; |
| 141 int fDstTextureUnit; | 137 int fDstTextureUnit; |
| 142 BuiltinUniformHandles fBuiltinUniformHandles; | 138 BuiltinUniformHandles fBuiltinUniformHandles; |
| 143 GrGLuint fProgramID; | 139 GrGLuint fProgramID; |
| 144 | 140 |
| 145 // the installed effects | 141 // the installed effects |
| 146 SkAutoTDelete<GrGLInstalledGeoProc> fGeometryProcessor; | 142 SkAutoTDelete<GrGLInstalledGeoProc> fGeometryProcessor; |
| 147 SkAutoTDelete<GrGLInstalledXferProc> fXferProcessor; | 143 SkAutoTDelete<GrGLInstalledXferProc> fXferProcessor; |
| 148 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; | 144 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; |
| 149 | 145 |
| 150 GrProgramDesc fDesc; | 146 GrProgramDesc fDesc; |
| 151 GrGLGpu* fGpu; | 147 GrGLGpu* fGpu; |
| 152 GrGLProgramDataManager fProgramDataManager; | 148 GrGLProgramDataManager fProgramDataManager; |
| 149 SkTArray<UniformHandle> fSamplerUniforms; |
| 153 | 150 |
| 154 friend class GrGLProgramBuilder; | 151 friend class GrGLProgramBuilder; |
| 155 | 152 |
| 156 typedef SkRefCnt INHERITED; | 153 typedef SkRefCnt INHERITED; |
| 157 }; | 154 }; |
| 158 | 155 |
| 159 /* | 156 /* |
| 160 * Below are slight specializations of the program object for the different type
s of programs | 157 * Below are slight specializations of the program object for the different type
s of programs |
| 161 * The default GrGL programs consist of at the very least a vertex and fragment
shader. | 158 * The default GrGL programs consist of at the very least a vertex and fragment
shader. |
| 162 * Legacy Nvpr only has a fragment shader, 1.3+ Nvpr ignores the vertex shader,
but both require | 159 * Legacy Nvpr only has a fragment shader, 1.3+ Nvpr ignores the vertex shader,
but both require |
| 163 * specialized methods for setting transform data. Both types of NVPR also requi
re setting the | 160 * specialized methods for setting transform data. Both types of NVPR also requi
re setting the |
| 164 * projection matrix through a special function call | 161 * projection matrix through a special function call |
| 165 */ | 162 */ |
| 166 class GrGLNvprProgram : public GrGLProgram { | 163 class GrGLNvprProgram : public GrGLProgram { |
| 167 protected: | 164 protected: |
| 168 GrGLNvprProgram(GrGLGpu*, | 165 GrGLNvprProgram(GrGLGpu*, |
| 169 const GrProgramDesc&, | 166 const GrProgramDesc&, |
| 170 const BuiltinUniformHandles&, | 167 const BuiltinUniformHandles&, |
| 171 GrGLuint programID, | 168 GrGLuint programID, |
| 172 const UniformInfoArray&, | 169 const UniformInfoArray&, |
| 173 GrGLInstalledGeoProc*, | 170 GrGLInstalledGeoProc*, |
| 174 GrGLInstalledXferProc* xferProcessor, | 171 GrGLInstalledXferProc* xferProcessor, |
| 175 GrGLInstalledFragProcs* fragmentProcessors); | 172 GrGLInstalledFragProcs* fragmentProcessors, |
| 173 SkTArray<UniformHandle>* passSamplerUniforms); |
| 176 | 174 |
| 177 private: | 175 private: |
| 178 void didSetData() override; | 176 void didSetData() override; |
| 179 virtual void setTransformData(const GrPrimitiveProcessor&, | 177 virtual void setTransformData(const GrPrimitiveProcessor&, |
| 180 const GrPendingFragmentStage&, | 178 const GrPendingFragmentStage&, |
| 181 int index, | 179 int index, |
| 182 GrGLInstalledFragProc*) override; | 180 GrGLInstalledFragProc*) override; |
| 183 virtual void onSetRenderTargetState(const GrPrimitiveProcessor&, const GrPip
eline&); | 181 virtual void onSetRenderTargetState(const GrPrimitiveProcessor&, const GrPip
eline&); |
| 184 | 182 |
| 185 friend class GrGLNvprProgramBuilder; | 183 friend class GrGLNvprProgramBuilder; |
| 186 | 184 |
| 187 typedef GrGLProgram INHERITED; | 185 typedef GrGLProgram INHERITED; |
| 188 }; | 186 }; |
| 189 | 187 |
| 190 #endif | 188 #endif |
| OLD | NEW |