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 #include "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) | 118 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) |
119 : GrGpu(context) | 119 : GrGpu(context) |
120 , fGLContext(ctx) { | 120 , fGLContext(ctx) { |
121 | 121 |
122 SkASSERT(ctx.isInitialized()); | 122 SkASSERT(ctx.isInitialized()); |
123 | 123 |
124 fCaps.reset(SkRef(ctx.info().caps())); | 124 fCaps.reset(SkRef(ctx.info().caps())); |
125 | 125 |
126 fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits()); | 126 fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits()); |
| 127 fHWTexGenSettings.reset(ctx.info().caps()->maxFixedFunctionTextureCoords()); |
127 | 128 |
128 fillInConfigRenderableTable(); | 129 fillInConfigRenderableTable(); |
129 | 130 |
130 | 131 |
131 GrGLClearErr(fGLContext.interface()); | 132 GrGLClearErr(fGLContext.interface()); |
132 | 133 |
133 if (gPrintStartupSpew) { | 134 if (gPrintStartupSpew) { |
134 const GrGLubyte* vendor; | 135 const GrGLubyte* vendor; |
135 const GrGLubyte* renderer; | 136 const GrGLubyte* renderer; |
136 const GrGLubyte* version; | 137 const GrGLubyte* version; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 // we don't use the model view matrix. | 371 // we don't use the model view matrix. |
371 GL_CALL(MatrixMode(GR_GL_MODELVIEW)); | 372 GL_CALL(MatrixMode(GR_GL_MODELVIEW)); |
372 GL_CALL(LoadIdentity()); | 373 GL_CALL(LoadIdentity()); |
373 | 374 |
374 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords(); ++i)
{ | 375 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords(); ++i)
{ |
375 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + i)); | 376 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + i)); |
376 GL_CALL(Disable(GR_GL_TEXTURE_GEN_S)); | 377 GL_CALL(Disable(GR_GL_TEXTURE_GEN_S)); |
377 GL_CALL(Disable(GR_GL_TEXTURE_GEN_T)); | 378 GL_CALL(Disable(GR_GL_TEXTURE_GEN_T)); |
378 GL_CALL(Disable(GR_GL_TEXTURE_GEN_Q)); | 379 GL_CALL(Disable(GR_GL_TEXTURE_GEN_Q)); |
379 GL_CALL(Disable(GR_GL_TEXTURE_GEN_R)); | 380 GL_CALL(Disable(GR_GL_TEXTURE_GEN_R)); |
| 381 if (this->caps()->pathStencilingSupport()) { |
| 382 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); |
| 383 } |
| 384 fHWTexGenSettings[i].fMode = GR_GL_NONE; |
| 385 fHWTexGenSettings[i].fNumComponents = 0; |
380 } | 386 } |
| 387 fHWActiveTexGenSets = 0; |
381 } | 388 } |
382 | 389 |
383 // we assume these values | 390 // we assume these values |
384 if (resetBits & kPixelStore_GrGLBackendState) { | 391 if (resetBits & kPixelStore_GrGLBackendState) { |
385 if (this->glCaps().unpackRowLengthSupport()) { | 392 if (this->glCaps().unpackRowLengthSupport()) { |
386 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 393 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
387 } | 394 } |
388 if (this->glCaps().packRowLengthSupport()) { | 395 if (this->glCaps().packRowLengthSupport()) { |
389 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); | 396 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
390 } | 397 } |
(...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2105 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi
zzle[3])); | 2112 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi
zzle[3])); |
2106 } else { | 2113 } else { |
2107 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL
int)); | 2114 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL
int)); |
2108 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara
ms.fSwizzleRGBA); | 2115 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara
ms.fSwizzleRGBA); |
2109 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA,
swizzle)); | 2116 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA,
swizzle)); |
2110 } | 2117 } |
2111 } | 2118 } |
2112 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); | 2119 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
2113 } | 2120 } |
2114 | 2121 |
| 2122 void GrGpuGL::setProjectionMatrix(const SkMatrix& matrix, |
| 2123 const SkISize& renderTargetSize, |
| 2124 GrSurfaceOrigin renderTargetOrigin) { |
| 2125 |
| 2126 SkASSERT(this->glCaps().fixedFunctionSupport()); |
| 2127 |
| 2128 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && |
| 2129 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && |
| 2130 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { |
| 2131 return; |
| 2132 } |
| 2133 |
| 2134 fHWProjectionMatrixState.fViewMatrix = matrix; |
| 2135 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; |
| 2136 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; |
| 2137 |
| 2138 GrGLfloat glMatrix[4 * 4]; |
| 2139 fHWProjectionMatrixState.getGLMatrix<4>(glMatrix); |
| 2140 GL_CALL(MatrixMode(GR_GL_PROJECTION)); |
| 2141 GL_CALL(LoadMatrixf(glMatrix)); |
| 2142 } |
| 2143 |
| 2144 void GrGpuGL::enableTexGen(int unitIdx, |
| 2145 TexGenComponents components, |
| 2146 const GrGLfloat* coefficients) { |
| 2147 |
| 2148 SkASSERT(this->glCaps().fixedFunctionSupport()); |
| 2149 SkASSERT(this->caps()->pathStencilingSupport()); |
| 2150 SkASSERT(components >= kS_TexGenComponents && components <= kSTR_TexGenCompo
nents); |
| 2151 |
| 2152 if (GR_GL_OBJECT_LINEAR == fHWTexGenSettings[unitIdx].fMode && |
| 2153 components == fHWTexGenSettings[unitIdx].fNumComponents && |
| 2154 !memcmp(coefficients, fHWTexGenSettings[unitIdx].fCoefficients, |
| 2155 3 * components * sizeof(GrGLfloat))) { |
| 2156 return; |
| 2157 } |
| 2158 |
| 2159 this->setTextureUnit(unitIdx); |
| 2160 |
| 2161 if (GR_GL_OBJECT_LINEAR != fHWTexGenSettings[unitIdx].fMode) { |
| 2162 for (int i = 0; i < 4; i++) { |
| 2163 GL_CALL(TexGeni(GR_GL_S + i, GR_GL_TEXTURE_GEN_MODE, GR_GL_OBJECT_LI
NEAR)); |
| 2164 } |
| 2165 fHWTexGenSettings[unitIdx].fMode = GR_GL_OBJECT_LINEAR; |
| 2166 } |
| 2167 |
| 2168 for (int i = fHWTexGenSettings[unitIdx].fNumComponents; i < components; i++)
{ |
| 2169 GL_CALL(Enable(GR_GL_TEXTURE_GEN_S + i)); |
| 2170 } |
| 2171 for (int i = components; i < fHWTexGenSettings[unitIdx].fNumComponents; i++)
{ |
| 2172 GL_CALL(Disable(GR_GL_TEXTURE_GEN_S + i)); |
| 2173 } |
| 2174 fHWTexGenSettings[unitIdx].fNumComponents = components; |
| 2175 |
| 2176 for (int i = 0; i < components; i++) { |
| 2177 GrGLfloat plane[] = {coefficients[0 + 3 * i], |
| 2178 coefficients[1 + 3 * i], |
| 2179 0, |
| 2180 coefficients[2 + 3 * i]}; |
| 2181 GL_CALL(TexGenfv(GR_GL_S + i, GR_GL_OBJECT_PLANE, plane)); |
| 2182 } |
| 2183 |
| 2184 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + unitIdx, |
| 2185 GR_GL_OBJECT_LINEAR, |
| 2186 components, |
| 2187 coefficients)); |
| 2188 |
| 2189 memcpy(fHWTexGenSettings[unitIdx].fCoefficients, coefficients, |
| 2190 3 * components * sizeof(GrGLfloat)); |
| 2191 |
| 2192 fHWActiveTexGenSets = SkTMax(fHWActiveTexGenSets, unitIdx); |
| 2193 } |
| 2194 |
| 2195 void GrGpuGL::enableTexGen(int unitIdx, TexGenComponents components, const SkMat
rix& matrix) { |
| 2196 |
| 2197 GrGLfloat coefficients[3 * 3]; |
| 2198 SkASSERT(this->glCaps().fixedFunctionSupport()); |
| 2199 SkASSERT(components >= kS_TexGenComponents && components <= kSTR_TexGenCompo
nents); |
| 2200 |
| 2201 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); |
| 2202 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); |
| 2203 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); |
| 2204 |
| 2205 if (components >= kST_TexGenComponents) { |
| 2206 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); |
| 2207 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); |
| 2208 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); |
| 2209 } |
| 2210 |
| 2211 if (components >= kSTR_TexGenComponents) { |
| 2212 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); |
| 2213 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); |
| 2214 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); |
| 2215 } |
| 2216 |
| 2217 enableTexGen(unitIdx, components, coefficients); |
| 2218 } |
| 2219 |
| 2220 void GrGpuGL::disableUnusedTexGen(int numUsedTexCoordSets) { |
| 2221 |
| 2222 SkASSERT(this->glCaps().fixedFunctionSupport()); |
| 2223 |
| 2224 for (int i = numUsedTexCoordSets; i < fHWActiveTexGenSets; i++) { |
| 2225 if (0 == fHWTexGenSettings[i].fNumComponents) { |
| 2226 continue; |
| 2227 } |
| 2228 |
| 2229 this->setTextureUnit(i); |
| 2230 for (int j = 0; j < fHWTexGenSettings[i].fNumComponents; j++) { |
| 2231 GL_CALL(Disable(GR_GL_TEXTURE_GEN_S + j)); |
| 2232 } |
| 2233 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); |
| 2234 fHWTexGenSettings[i].fNumComponents = 0; |
| 2235 } |
| 2236 |
| 2237 fHWActiveTexGenSets = SkTMin(fHWActiveTexGenSets, numUsedTexCoordSets); |
| 2238 } |
| 2239 |
2115 void GrGpuGL::flushMiscFixedFunctionState() { | 2240 void GrGpuGL::flushMiscFixedFunctionState() { |
2116 | 2241 |
2117 const GrDrawState& drawState = this->getDrawState(); | 2242 const GrDrawState& drawState = this->getDrawState(); |
2118 | 2243 |
2119 if (drawState.isDitherState()) { | 2244 if (drawState.isDitherState()) { |
2120 if (kYes_TriState != fHWDitherEnabled) { | 2245 if (kYes_TriState != fHWDitherEnabled) { |
2121 GL_CALL(Enable(GR_GL_DITHER)); | 2246 GL_CALL(Enable(GR_GL_DITHER)); |
2122 fHWDitherEnabled = kYes_TriState; | 2247 fHWDitherEnabled = kYes_TriState; |
2123 } | 2248 } |
2124 } else { | 2249 } else { |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2588 this->setVertexArrayID(gpu, 0); | 2713 this->setVertexArrayID(gpu, 0); |
2589 } | 2714 } |
2590 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2715 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2591 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2716 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2592 fDefaultVertexArrayAttribState.resize(attrCount); | 2717 fDefaultVertexArrayAttribState.resize(attrCount); |
2593 } | 2718 } |
2594 attribState = &fDefaultVertexArrayAttribState; | 2719 attribState = &fDefaultVertexArrayAttribState; |
2595 } | 2720 } |
2596 return attribState; | 2721 return attribState; |
2597 } | 2722 } |
OLD | NEW |