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 "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
| 10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| (...skipping 2378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2389 GR_GL_REPEAT, | 2389 GR_GL_REPEAT, |
| 2390 GR_GL_MIRRORED_REPEAT | 2390 GR_GL_MIRRORED_REPEAT |
| 2391 }; | 2391 }; |
| 2392 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); | 2392 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); |
| 2393 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); | 2393 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); |
| 2394 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); | 2394 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); |
| 2395 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); | 2395 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); |
| 2396 return gWrapModes[tm]; | 2396 return gWrapModes[tm]; |
| 2397 } | 2397 } |
| 2398 | 2398 |
| 2399 const GrGLenum* GrGLGpu::GetTexParamSwizzle(GrPixelConfig config, const GrGLCaps & caps) { | 2399 static GrGLenum get_component_enum_from_char(char component) { |
| 2400 if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) { | 2400 switch (component) { |
| 2401 if (caps.textureRedSupport()) { | 2401 case 'r': |
| 2402 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE D, GR_GL_RED }; | 2402 return GR_GL_RED; |
| 2403 return gRedSmear; | 2403 case 'g': |
| 2404 } else { | 2404 return GR_GL_GREEN; |
| 2405 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA, | 2405 case 'b': |
| 2406 GR_GL_ALPHA, GR_GL_ALPHA }; | 2406 return GR_GL_BLUE; |
| 2407 return gAlphaSmear; | 2407 case 'a': |
| 2408 } | 2408 return GR_GL_ALPHA; |
| 2409 } else { | 2409 default: |
| 2410 static const GrGLenum gStraight[] = { GR_GL_RED, GR_GL_GREEN, GR_GL_BLUE , GR_GL_ALPHA }; | 2410 SkFAIL("Unsupported component"); |
| 2411 return gStraight; | 2411 return 0; |
| 2412 } | 2412 } |
| 2413 } | 2413 } |
| 2414 | 2414 |
| 2415 void GrGLGpu::GetTexParamSwizzle(GrPixelConfig config, | |
|
bsalomon
2015/11/03 14:45:51
can this be a static function rather than a member
egdaniel
2015/11/03 15:23:56
Done.
| |
| 2416 const GrGLSLCaps& caps, | |
| 2417 GrGLenum* glSwizzle) { | |
| 2418 const char* swizzle = "rgba"; | |
| 2419 if (!caps.mustSwizzleInShader()) { | |
| 2420 swizzle = caps.getSwizzleMap(config); | |
| 2421 } | |
| 2422 | |
| 2423 for (int i = 0; i < 4; ++i) { | |
| 2424 glSwizzle[i] = get_component_enum_from_char(swizzle[i]); | |
| 2425 } | |
| 2426 } | |
| 2427 | |
| 2415 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) { | 2428 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) { |
| 2416 SkASSERT(texture); | 2429 SkASSERT(texture); |
| 2417 | 2430 |
| 2418 #ifdef SK_DEBUG | 2431 #ifdef SK_DEBUG |
| 2419 if (!this->caps()->npotTextureTileSupport()) { | 2432 if (!this->caps()->npotTextureTileSupport()) { |
| 2420 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); | 2433 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); |
| 2421 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); | 2434 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); |
| 2422 if (tileX || tileY) { | 2435 if (tileX || tileY) { |
| 2423 const int w = texture->width(); | 2436 const int w = texture->width(); |
| 2424 const int h = texture->height(); | 2437 const int h = texture->height(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2470 newTexParams.fMagFilter = glMagFilterModes[filterMode]; | 2483 newTexParams.fMagFilter = glMagFilterModes[filterMode]; |
| 2471 | 2484 |
| 2472 if (GrTextureParams::kMipMap_FilterMode == filterMode && | 2485 if (GrTextureParams::kMipMap_FilterMode == filterMode && |
| 2473 texture->texturePriv().mipMapsAreDirty()) { | 2486 texture->texturePriv().mipMapsAreDirty()) { |
| 2474 GL_CALL(GenerateMipmap(target)); | 2487 GL_CALL(GenerateMipmap(target)); |
| 2475 texture->texturePriv().dirtyMipMaps(false); | 2488 texture->texturePriv().dirtyMipMaps(false); |
| 2476 } | 2489 } |
| 2477 | 2490 |
| 2478 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); | 2491 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); |
| 2479 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); | 2492 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); |
| 2480 memcpy(newTexParams.fSwizzleRGBA, | 2493 GetTexParamSwizzle(texture->config(), *this->glCaps().glslCaps(), newTexPara ms.fSwizzleRGBA); |
| 2481 GetTexParamSwizzle(texture->config(), this->glCaps()), | |
| 2482 sizeof(newTexParams.fSwizzleRGBA)); | |
| 2483 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { | 2494 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { |
| 2484 this->setTextureUnit(unitIdx); | 2495 this->setTextureUnit(unitIdx); |
| 2485 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newTexParams.fMa gFilter)); | 2496 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newTexParams.fMa gFilter)); |
| 2486 } | 2497 } |
| 2487 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { | 2498 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { |
| 2488 this->setTextureUnit(unitIdx); | 2499 this->setTextureUnit(unitIdx); |
| 2489 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, newTexParams.fMi nFilter)); | 2500 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, newTexParams.fMi nFilter)); |
| 2490 } | 2501 } |
| 2491 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { | 2502 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { |
| 2492 this->setTextureUnit(unitIdx); | 2503 this->setTextureUnit(unitIdx); |
| 2493 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS) ); | 2504 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS) ); |
| 2494 } | 2505 } |
| 2495 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { | 2506 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { |
| 2496 this->setTextureUnit(unitIdx); | 2507 this->setTextureUnit(unitIdx); |
| 2497 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT) ); | 2508 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT) ); |
| 2498 } | 2509 } |
| 2499 if (this->glCaps().textureSwizzleSupport() && | 2510 if (!this->glCaps().glslCaps()->mustSwizzleInShader() && |
| 2500 (setAll || memcmp(newTexParams.fSwizzleRGBA, | 2511 (setAll || memcmp(newTexParams.fSwizzleRGBA, |
| 2501 oldTexParams.fSwizzleRGBA, | 2512 oldTexParams.fSwizzleRGBA, |
| 2502 sizeof(newTexParams.fSwizzleRGBA)))) { | 2513 sizeof(newTexParams.fSwizzleRGBA)))) { |
| 2503 this->setTextureUnit(unitIdx); | 2514 this->setTextureUnit(unitIdx); |
| 2504 if (this->glStandard() == kGLES_GrGLStandard) { | 2515 if (this->glStandard() == kGLES_GrGLStandard) { |
| 2505 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. | 2516 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. |
| 2506 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; | 2517 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; |
| 2507 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0])); | 2518 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0])); |
| 2508 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1])); | 2519 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1])); |
| 2509 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2])); | 2520 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2])); |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3311 this->setVertexArrayID(gpu, 0); | 3322 this->setVertexArrayID(gpu, 0); |
| 3312 } | 3323 } |
| 3313 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3324 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3314 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3325 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3315 fDefaultVertexArrayAttribState.resize(attrCount); | 3326 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3316 } | 3327 } |
| 3317 attribState = &fDefaultVertexArrayAttribState; | 3328 attribState = &fDefaultVertexArrayAttribState; |
| 3318 } | 3329 } |
| 3319 return attribState; | 3330 return attribState; |
| 3320 } | 3331 } |
| OLD | NEW |