Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: src/gpu/gl/GrGLProgram.h

Issue 299943002: separate view matrix from rt adjustment (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase on tot: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/gl/GrGLProgram.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 SkISize fRenderTargetSize; 96 SkISize fRenderTargetSize;
97 GrSurfaceOrigin fRenderTargetOrigin; 97 GrSurfaceOrigin fRenderTargetOrigin;
98 98
99 MatrixState() { this->invalidate(); } 99 MatrixState() { this->invalidate(); }
100 void invalidate() { 100 void invalidate() {
101 fViewMatrix = SkMatrix::InvalidMatrix(); 101 fViewMatrix = SkMatrix::InvalidMatrix();
102 fRenderTargetSize.fWidth = -1; 102 fRenderTargetSize.fWidth = -1;
103 fRenderTargetSize.fHeight = -1; 103 fRenderTargetSize.fHeight = -1;
104 fRenderTargetOrigin = (GrSurfaceOrigin) -1; 104 fRenderTargetOrigin = (GrSurfaceOrigin) -1;
105 } 105 }
106
107 /**
108 * Gets a matrix that goes from local coords to Skia's device coordinate s.
109 */
106 template<int Size> void getGLMatrix(GrGLfloat* destMatrix) { 110 template<int Size> void getGLMatrix(GrGLfloat* destMatrix) {
111 GrGLGetMatrix<Size>(destMatrix, fViewMatrix);
112 }
113
114 /**
115 * Gets a matrix that goes from local coordinates to GL normalized devic e coords.
116 */
117 template<int Size> void getRTAdjustedGLMatrix(GrGLfloat* destMatrix) {
107 SkMatrix combined; 118 SkMatrix combined;
108 if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { 119 if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) {
109 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1, 120 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
110 0, -SkIntToScalar(2) / fRenderTargetSize.fHeight , SK_Scalar1, 121 0, -SkIntToScalar(2) / fRenderTargetSize.fHeight , SK_Scalar1,
111 0, 0, SkMatrix::I()[8]); 122 0, 0, 1);
112 } else { 123 } else {
113 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1, 124 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
114 0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1, 125 0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1,
115 0, 0, SkMatrix::I()[8]); 126 0, 0, 1);
116 } 127 }
117 combined.preConcat(fViewMatrix); 128 combined.preConcat(fViewMatrix);
118 GrGLGetMatrix<Size>(destMatrix, combined); 129 GrGLGetMatrix<Size>(destMatrix, combined);
119 } 130 }
131
132 /**
133 * Gets a vec4 that adjusts the position from Skia device coords to GL's normalized device
134 * coords. Assuming the transformed position, pos, is a homogeneous vec3 , the vec, v, is
135 * applied as such:
136 * pos.x = dot(v.xy, pos.xz)
137 * pos.y = dot(v.zq, pos.yz)
138 */
139 void getRTAdjustmentVec(GrGLfloat* destVec) {
140 destVec[0] = 2.f / fRenderTargetSize.fWidth;
141 destVec[1] = -1.f;
142 if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) {
143 destVec[2] = -2.f / fRenderTargetSize.fHeight;
144 destVec[3] = 1.f;
145 } else {
146 destVec[2] = 2.f / fRenderTargetSize.fHeight;
147 destVec[3] = -1.f;
148 }
149 }
120 }; 150 };
121 151
122 /** 152 /**
123 * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a 153 * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a
124 * draw occurs using the program after the program has already been bound. I t also uses the 154 * draw occurs using the program after the program has already been bound. I t also uses the
125 * GrGpuGL object to bind the textures required by the GrGLEffects. The colo r and coverage 155 * GrGpuGL object to bind the textures required by the GrGLEffects. The colo r and coverage
126 * stages come from GrGLProgramDesc::Build(). 156 * stages come from GrGLProgramDesc::Build().
127 */ 157 */
128 void setData(GrDrawState::BlendOptFlags, 158 void setData(GrDrawState::BlendOptFlags,
129 const GrEffectStage* colorStages[], 159 const GrEffectStage* colorStages[],
130 const GrEffectStage* coverageStages[], 160 const GrEffectStage* coverageStages[],
131 const GrDeviceCoordTexture* dstCopy, // can be NULL 161 const GrDeviceCoordTexture* dstCopy, // can be NULL
132 SharedGLState*); 162 SharedGLState*);
133 163
134 private: 164 private:
135 typedef GrGLUniformManager::UniformHandle UniformHandle; 165 typedef GrGLUniformManager::UniformHandle UniformHandle;
136 166
137 // handles for uniforms (aside from per-effect samplers) 167 // handles for uniforms (aside from per-effect samplers)
138 struct UniformHandles { 168 struct UniformHandles {
139 UniformHandle fViewMatrixUni; 169 UniformHandle fViewMatrixUni;
170 UniformHandle fRTAdjustmentUni;
140 UniformHandle fColorUni; 171 UniformHandle fColorUni;
141 UniformHandle fCoverageUni; 172 UniformHandle fCoverageUni;
142 173
143 // We use the render target height to provide a y-down frag coord when s pecifying 174 // We use the render target height to provide a y-down frag coord when s pecifying
144 // origin_upper_left is not supported. 175 // origin_upper_left is not supported.
145 UniformHandle fRTHeightUni; 176 UniformHandle fRTHeightUni;
146 177
147 // Uniforms for computing texture coords to do the dst-copy lookup 178 // Uniforms for computing texture coords to do the dst-copy lookup
148 UniformHandle fDstCopyTopLeftUni; 179 UniformHandle fDstCopyTopLeftUni;
149 UniformHandle fDstCopyScaleUni; 180 UniformHandle fDstCopyScaleUni;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 GrGLUniformManager fUniformManager; 228 GrGLUniformManager fUniformManager;
198 UniformHandles fUniformHandles; 229 UniformHandles fUniformHandles;
199 230
200 bool fHasVertexShader; 231 bool fHasVertexShader;
201 int fNumTexCoordSets; 232 int fNumTexCoordSets;
202 233
203 typedef SkRefCnt INHERITED; 234 typedef SkRefCnt INHERITED;
204 }; 235 };
205 236
206 #endif 237 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/gl/GrGLProgram.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698