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 static GrGLenum get_component_enum_from_char(char component) { | 2399 const GrGLenum* GrGLGpu::GetTexParamSwizzle(GrPixelConfig config, const GrGLCaps
& caps) { |
2400 switch (component) { | 2400 if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) { |
2401 case 'r': | 2401 if (caps.textureRedSupport()) { |
2402 return GR_GL_RED; | 2402 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE
D, GR_GL_RED }; |
2403 case 'g': | 2403 return gRedSmear; |
2404 return GR_GL_GREEN; | 2404 } else { |
2405 case 'b': | 2405 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA, |
2406 return GR_GL_BLUE; | 2406 GR_GL_ALPHA, GR_GL_ALPHA }; |
2407 case 'a': | 2407 return gAlphaSmear; |
2408 return GR_GL_ALPHA; | 2408 } |
2409 default: | 2409 } else { |
2410 SkFAIL("Unsupported component"); | 2410 static const GrGLenum gStraight[] = { GR_GL_RED, GR_GL_GREEN, GR_GL_BLUE
, GR_GL_ALPHA }; |
2411 return 0; | 2411 return gStraight; |
2412 } | 2412 } |
2413 } | 2413 } |
2414 | 2414 |
2415 /** If texture swizzling is available using tex parameters then it is preferred
over mangling | |
2416 the generated shader code. This potentially allows greater reuse of cached sha
ders. */ | |
2417 static void get_tex_param_swizzle(GrPixelConfig config, | |
2418 const GrGLSLCaps& caps, | |
2419 GrGLenum* glSwizzle) { | |
2420 const char* swizzle = "rgba"; | |
2421 if (!caps.mustSwizzleInShader()) { | |
2422 swizzle = caps.getSwizzleMap(config); | |
2423 } | |
2424 | |
2425 for (int i = 0; i < 4; ++i) { | |
2426 glSwizzle[i] = get_component_enum_from_char(swizzle[i]); | |
2427 } | |
2428 } | |
2429 | |
2430 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
e* texture) { | 2415 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
e* texture) { |
2431 SkASSERT(texture); | 2416 SkASSERT(texture); |
2432 | 2417 |
2433 #ifdef SK_DEBUG | 2418 #ifdef SK_DEBUG |
2434 if (!this->caps()->npotTextureTileSupport()) { | 2419 if (!this->caps()->npotTextureTileSupport()) { |
2435 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); | 2420 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); |
2436 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); | 2421 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); |
2437 if (tileX || tileY) { | 2422 if (tileX || tileY) { |
2438 const int w = texture->width(); | 2423 const int w = texture->width(); |
2439 const int h = texture->height(); | 2424 const int h = texture->height(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2485 newTexParams.fMagFilter = glMagFilterModes[filterMode]; | 2470 newTexParams.fMagFilter = glMagFilterModes[filterMode]; |
2486 | 2471 |
2487 if (GrTextureParams::kMipMap_FilterMode == filterMode && | 2472 if (GrTextureParams::kMipMap_FilterMode == filterMode && |
2488 texture->texturePriv().mipMapsAreDirty()) { | 2473 texture->texturePriv().mipMapsAreDirty()) { |
2489 GL_CALL(GenerateMipmap(target)); | 2474 GL_CALL(GenerateMipmap(target)); |
2490 texture->texturePriv().dirtyMipMaps(false); | 2475 texture->texturePriv().dirtyMipMaps(false); |
2491 } | 2476 } |
2492 | 2477 |
2493 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); | 2478 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); |
2494 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); | 2479 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); |
2495 get_tex_param_swizzle(texture->config(), *this->glCaps().glslCaps(), newTexP
arams.fSwizzleRGBA); | 2480 memcpy(newTexParams.fSwizzleRGBA, |
| 2481 GetTexParamSwizzle(texture->config(), this->glCaps()), |
| 2482 sizeof(newTexParams.fSwizzleRGBA)); |
2496 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { | 2483 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { |
2497 this->setTextureUnit(unitIdx); | 2484 this->setTextureUnit(unitIdx); |
2498 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newTexParams.fMa
gFilter)); | 2485 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newTexParams.fMa
gFilter)); |
2499 } | 2486 } |
2500 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { | 2487 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { |
2501 this->setTextureUnit(unitIdx); | 2488 this->setTextureUnit(unitIdx); |
2502 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, newTexParams.fMi
nFilter)); | 2489 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, newTexParams.fMi
nFilter)); |
2503 } | 2490 } |
2504 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { | 2491 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { |
2505 this->setTextureUnit(unitIdx); | 2492 this->setTextureUnit(unitIdx); |
2506 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS)
); | 2493 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS)
); |
2507 } | 2494 } |
2508 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { | 2495 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { |
2509 this->setTextureUnit(unitIdx); | 2496 this->setTextureUnit(unitIdx); |
2510 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT)
); | 2497 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT)
); |
2511 } | 2498 } |
2512 if (!this->glCaps().glslCaps()->mustSwizzleInShader() && | 2499 if (this->glCaps().textureSwizzleSupport() && |
2513 (setAll || memcmp(newTexParams.fSwizzleRGBA, | 2500 (setAll || memcmp(newTexParams.fSwizzleRGBA, |
2514 oldTexParams.fSwizzleRGBA, | 2501 oldTexParams.fSwizzleRGBA, |
2515 sizeof(newTexParams.fSwizzleRGBA)))) { | 2502 sizeof(newTexParams.fSwizzleRGBA)))) { |
2516 this->setTextureUnit(unitIdx); | 2503 this->setTextureUnit(unitIdx); |
2517 if (this->glStandard() == kGLES_GrGLStandard) { | 2504 if (this->glStandard() == kGLES_GrGLStandard) { |
2518 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. | 2505 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. |
2519 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; | 2506 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; |
2520 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0])); | 2507 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0])); |
2521 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1])); | 2508 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1])); |
2522 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2])); | 2509 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2])); |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3324 this->setVertexArrayID(gpu, 0); | 3311 this->setVertexArrayID(gpu, 0); |
3325 } | 3312 } |
3326 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3313 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3327 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3314 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3328 fDefaultVertexArrayAttribState.resize(attrCount); | 3315 fDefaultVertexArrayAttribState.resize(attrCount); |
3329 } | 3316 } |
3330 attribState = &fDefaultVertexArrayAttribState; | 3317 attribState = &fDefaultVertexArrayAttribState; |
3331 } | 3318 } |
3332 return attribState; | 3319 return attribState; |
3333 } | 3320 } |
OLD | NEW |