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

Side by Side Diff: src/gpu/gl/GrGLGpu.cpp

Issue 1420033005: Create swizzle table inside of glsl caps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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 | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLProgramDesc.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 #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
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 /** 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 = caps.getSwizzleMap(config);
2421 for (int i = 0; i < 4; ++i) {
2422 glSwizzle[i] = get_component_enum_from_char(swizzle[i]);
2423 }
2424 }
2425
2415 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) { 2426 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) {
2416 SkASSERT(texture); 2427 SkASSERT(texture);
2417 2428
2418 #ifdef SK_DEBUG 2429 #ifdef SK_DEBUG
2419 if (!this->caps()->npotTextureTileSupport()) { 2430 if (!this->caps()->npotTextureTileSupport()) {
2420 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); 2431 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX();
2421 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); 2432 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY();
2422 if (tileX || tileY) { 2433 if (tileX || tileY) {
2423 const int w = texture->width(); 2434 const int w = texture->width();
2424 const int h = texture->height(); 2435 const int h = texture->height();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 newTexParams.fMagFilter = glMagFilterModes[filterMode]; 2481 newTexParams.fMagFilter = glMagFilterModes[filterMode];
2471 2482
2472 if (GrTextureParams::kMipMap_FilterMode == filterMode && 2483 if (GrTextureParams::kMipMap_FilterMode == filterMode &&
2473 texture->texturePriv().mipMapsAreDirty()) { 2484 texture->texturePriv().mipMapsAreDirty()) {
2474 GL_CALL(GenerateMipmap(target)); 2485 GL_CALL(GenerateMipmap(target));
2475 texture->texturePriv().dirtyMipMaps(false); 2486 texture->texturePriv().dirtyMipMaps(false);
2476 } 2487 }
2477 2488
2478 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); 2489 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX());
2479 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); 2490 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY());
2480 memcpy(newTexParams.fSwizzleRGBA, 2491 get_tex_param_swizzle(texture->config(), *this->glCaps().glslCaps(), newTexP arams.fSwizzleRGBA);
2481 GetTexParamSwizzle(texture->config(), this->glCaps()),
2482 sizeof(newTexParams.fSwizzleRGBA));
2483 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { 2492 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) {
2484 this->setTextureUnit(unitIdx); 2493 this->setTextureUnit(unitIdx);
2485 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newTexParams.fMa gFilter)); 2494 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newTexParams.fMa gFilter));
2486 } 2495 }
2487 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { 2496 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) {
2488 this->setTextureUnit(unitIdx); 2497 this->setTextureUnit(unitIdx);
2489 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, newTexParams.fMi nFilter)); 2498 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, newTexParams.fMi nFilter));
2490 } 2499 }
2491 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { 2500 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) {
2492 this->setTextureUnit(unitIdx); 2501 this->setTextureUnit(unitIdx);
2493 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS) ); 2502 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS) );
2494 } 2503 }
2495 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { 2504 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) {
2496 this->setTextureUnit(unitIdx); 2505 this->setTextureUnit(unitIdx);
2497 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT) ); 2506 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT) );
2498 } 2507 }
2499 if (this->glCaps().textureSwizzleSupport() && 2508 if (!this->glCaps().glslCaps()->mustSwizzleInShader() &&
2500 (setAll || memcmp(newTexParams.fSwizzleRGBA, 2509 (setAll || memcmp(newTexParams.fSwizzleRGBA,
2501 oldTexParams.fSwizzleRGBA, 2510 oldTexParams.fSwizzleRGBA,
2502 sizeof(newTexParams.fSwizzleRGBA)))) { 2511 sizeof(newTexParams.fSwizzleRGBA)))) {
2503 this->setTextureUnit(unitIdx); 2512 this->setTextureUnit(unitIdx);
2504 if (this->glStandard() == kGLES_GrGLStandard) { 2513 if (this->glStandard() == kGLES_GrGLStandard) {
2505 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. 2514 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA.
2506 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; 2515 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA;
2507 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0])); 2516 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0]));
2508 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1])); 2517 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1]));
2509 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2])); 2518 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2]));
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
3311 this->setVertexArrayID(gpu, 0); 3320 this->setVertexArrayID(gpu, 0);
3312 } 3321 }
3313 int attrCount = gpu->glCaps().maxVertexAttributes(); 3322 int attrCount = gpu->glCaps().maxVertexAttributes();
3314 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3323 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3315 fDefaultVertexArrayAttribState.resize(attrCount); 3324 fDefaultVertexArrayAttribState.resize(attrCount);
3316 } 3325 }
3317 attribState = &fDefaultVertexArrayAttribState; 3326 attribState = &fDefaultVertexArrayAttribState;
3318 } 3327 }
3319 return attribState; 3328 return attribState;
3320 } 3329 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLProgramDesc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698