Chromium Code Reviews| 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 fHWTexGenSettings[i].fMode = GR_GL_NONE; | |
| 382 fHWTexGenSettings[i].fNumComponents = 0; | |
| 380 } | 383 } |
| 384 fHWActiveTexGenUnits = 0; | |
| 381 } | 385 } |
| 382 | 386 |
| 383 // we assume these values | 387 // we assume these values |
| 384 if (resetBits & kPixelStore_GrGLBackendState) { | 388 if (resetBits & kPixelStore_GrGLBackendState) { |
| 385 if (this->glCaps().unpackRowLengthSupport()) { | 389 if (this->glCaps().unpackRowLengthSupport()) { |
| 386 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 390 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 387 } | 391 } |
| 388 if (this->glCaps().packRowLengthSupport()) { | 392 if (this->glCaps().packRowLengthSupport()) { |
| 389 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); | 393 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 390 } | 394 } |
| (...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])); | 2109 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi zzle[3])); |
| 2106 } else { | 2110 } else { |
| 2107 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL int)); | 2111 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL int)); |
| 2108 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara ms.fSwizzleRGBA); | 2112 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara ms.fSwizzleRGBA); |
| 2109 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA, swizzle)); | 2113 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA, swizzle)); |
| 2110 } | 2114 } |
| 2111 } | 2115 } |
| 2112 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); | 2116 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
| 2113 } | 2117 } |
| 2114 | 2118 |
| 2119 void GrGpuGL::setProjectionMatrix(const SkMatrix& matrix, | |
| 2120 const SkISize& renderTargetSize, | |
| 2121 GrSurfaceOrigin renderTargetOrigin) { | |
| 2122 | |
| 2123 SkASSERT(this->glCaps().fixedFunctionSupport()); | |
| 2124 | |
| 2125 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && | |
| 2126 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && | |
| 2127 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { | |
| 2128 return; | |
| 2129 } | |
| 2130 | |
| 2131 fHWProjectionMatrixState.fViewMatrix = matrix; | |
| 2132 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; | |
| 2133 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; | |
| 2134 | |
| 2135 GrGLfloat glMatrix[4 * 4]; | |
| 2136 fHWProjectionMatrixState.getGLMatrix<4>(glMatrix); | |
|
Mark Kilgard
2013/09/10 02:13:48
glMatrixLoadfEXT opportunity
| |
| 2137 GL_CALL(MatrixMode(GR_GL_PROJECTION)); | |
| 2138 GL_CALL(LoadMatrixf(glMatrix)); | |
| 2139 } | |
| 2140 | |
| 2141 void GrGpuGL::enableTexGen(int unitIdx, int numComponents, const GrGLfloat* coef ficients) { | |
| 2142 | |
| 2143 SkASSERT(this->glCaps().fixedFunctionSupport()); | |
| 2144 SkASSERT(numComponents <= 3 && numComponents > 0); | |
| 2145 | |
| 2146 if (GR_GL_OBJECT_LINEAR == fHWTexGenSettings[unitIdx].fMode && | |
| 2147 numComponents == fHWTexGenSettings[unitIdx].fNumComponents && | |
| 2148 !memcmp(coefficients, fHWTexGenSettings[unitIdx].fCoefficients, | |
| 2149 3 * numComponents * sizeof(GrGLfloat))) { | |
| 2150 return; | |
| 2151 } | |
| 2152 | |
|
Mark Kilgard
2013/09/10 02:13:48
It would be nice if we did *either* the fixed-func
bsalomon
2013/09/10 13:51:06
seems reasonable
| |
| 2153 setTextureUnit(unitIdx); | |
|
bsalomon
2013/09/10 13:51:06
style nit: this->setTextureUnit(unitIdx);
(we use
| |
| 2154 | |
|
Mark Kilgard
2013/09/10 02:13:48
Instead of glActiveTexture/glTexGeni/glEnable/glDi
| |
| 2155 if (GR_GL_OBJECT_LINEAR != fHWTexGenSettings[unitIdx].fMode) { | |
| 2156 for (int i = 0; i < 4; i++) { | |
| 2157 GL_CALL(TexGeni(GR_GL_S + i, GR_GL_TEXTURE_GEN_MODE, GR_GL_OBJECT_LI NEAR)); | |
| 2158 } | |
| 2159 fHWTexGenSettings[unitIdx].fMode = GR_GL_OBJECT_LINEAR; | |
| 2160 } | |
| 2161 | |
| 2162 for (int i = fHWTexGenSettings[unitIdx].fNumComponents; i < numComponents; i ++) { | |
| 2163 GL_CALL(Enable(GR_GL_TEXTURE_GEN_S + i)); | |
| 2164 } | |
| 2165 for (int i = numComponents; i < fHWTexGenSettings[unitIdx].fNumComponents; i ++) { | |
| 2166 GL_CALL(Disable(GR_GL_TEXTURE_GEN_S + i)); | |
| 2167 } | |
| 2168 fHWTexGenSettings[unitIdx].fNumComponents = numComponents; | |
| 2169 | |
| 2170 for (int i = 0; i < numComponents; i++) { | |
| 2171 GrGLfloat plane[] = {coefficients[0 + 3 * i], | |
| 2172 coefficients[1 + 3 * i], | |
| 2173 0, | |
| 2174 coefficients[2 + 3 * i]}; | |
| 2175 GL_CALL(TexGenfv(GR_GL_S + i, GR_GL_OBJECT_PLANE, plane)); | |
| 2176 } | |
| 2177 | |
| 2178 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + unitIdx, | |
| 2179 GR_GL_OBJECT_LINEAR, | |
| 2180 numComponents, | |
| 2181 coefficients)); | |
| 2182 | |
| 2183 memcpy(fHWTexGenSettings[unitIdx].fCoefficients, coefficients, | |
| 2184 3 * numComponents * sizeof(GrGLfloat)); | |
| 2185 | |
| 2186 fHWActiveTexGenUnits = SkTMax(fHWActiveTexGenUnits, unitIdx); | |
| 2187 } | |
| 2188 | |
| 2189 void GrGpuGL::enableTexGen(int unitIdx, int numComponents, const SkMatrix& matri x) { | |
| 2190 | |
| 2191 GrGLfloat coefficients[9]; | |
| 2192 SkASSERT(this->glCaps().fixedFunctionSupport()); | |
| 2193 SkASSERT(numComponents <= 3 && numComponents > 0); | |
| 2194 | |
| 2195 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); | |
| 2196 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); | |
| 2197 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); | |
| 2198 | |
| 2199 if (numComponents >= 2) { | |
| 2200 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); | |
| 2201 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); | |
| 2202 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); | |
| 2203 } | |
| 2204 | |
| 2205 if (numComponents >= 3) { | |
| 2206 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); | |
| 2207 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); | |
| 2208 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); | |
| 2209 } | |
| 2210 | |
| 2211 enableTexGen(unitIdx, numComponents, coefficients); | |
| 2212 } | |
| 2213 | |
| 2214 void GrGpuGL::disableUnusedTexGenUnits(int numUsedUnits) { | |
| 2215 | |
| 2216 SkASSERT(this->glCaps().fixedFunctionSupport()); | |
| 2217 | |
| 2218 for (int i = numUsedUnits; i < fHWActiveTexGenUnits; i++) { | |
| 2219 if (!fHWTexGenSettings[i].fNumComponents) { | |
| 2220 continue; | |
| 2221 } | |
| 2222 | |
|
Mark Kilgard
2013/09/10 02:13:48
Again, a lot of glDisable calls or glPathTexGen.
| |
| 2223 setTextureUnit(i); | |
| 2224 for (int j = 0; j < fHWTexGenSettings[i].fNumComponents; j++) { | |
| 2225 GL_CALL(Disable(GR_GL_TEXTURE_GEN_S + j)); | |
| 2226 } | |
| 2227 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); | |
| 2228 fHWTexGenSettings[i].fNumComponents = 0; | |
| 2229 } | |
| 2230 | |
| 2231 fHWActiveTexGenUnits = SkTMin(fHWActiveTexGenUnits, numUsedUnits); | |
| 2232 } | |
| 2233 | |
| 2115 void GrGpuGL::flushMiscFixedFunctionState() { | 2234 void GrGpuGL::flushMiscFixedFunctionState() { |
| 2116 | 2235 |
| 2117 const GrDrawState& drawState = this->getDrawState(); | 2236 const GrDrawState& drawState = this->getDrawState(); |
| 2118 | 2237 |
| 2119 if (drawState.isDitherState()) { | 2238 if (drawState.isDitherState()) { |
| 2120 if (kYes_TriState != fHWDitherEnabled) { | 2239 if (kYes_TriState != fHWDitherEnabled) { |
| 2121 GL_CALL(Enable(GR_GL_DITHER)); | 2240 GL_CALL(Enable(GR_GL_DITHER)); |
| 2122 fHWDitherEnabled = kYes_TriState; | 2241 fHWDitherEnabled = kYes_TriState; |
| 2123 } | 2242 } |
| 2124 } else { | 2243 } else { |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2588 this->setVertexArrayID(gpu, 0); | 2707 this->setVertexArrayID(gpu, 0); |
| 2589 } | 2708 } |
| 2590 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2709 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2591 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2710 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2592 fDefaultVertexArrayAttribState.resize(attrCount); | 2711 fDefaultVertexArrayAttribState.resize(attrCount); |
| 2593 } | 2712 } |
| 2594 attribState = &fDefaultVertexArrayAttribState; | 2713 attribState = &fDefaultVertexArrayAttribState; |
| 2595 } | 2714 } |
| 2596 return attribState; | 2715 return attribState; |
| 2597 } | 2716 } |
| OLD | NEW |