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

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

Issue 1431433003: Move shader compiling to ProgramBuilder and various ShaderBuilder cleanups. (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
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) {
2400 if (caps.glslCaps()->textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(con fig)) {
2401 if (caps.glslCaps()->textureRedSupport()) {
2402 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE D, GR_GL_RED };
2403 return gRedSmear;
2404 } else {
2405 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA,
2406 GR_GL_ALPHA, GR_GL_ALPHA };
2407 return gAlphaSmear;
2408 }
2409 } else {
2410 static const GrGLenum gStraight[] = { GR_GL_RED, GR_GL_GREEN, GR_GL_BLUE , GR_GL_ALPHA };
2411 return gStraight;
2412 }
2413 }
2414
2399 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) { 2415 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) {
2400 SkASSERT(texture); 2416 SkASSERT(texture);
2401 2417
2402 #ifdef SK_DEBUG 2418 #ifdef SK_DEBUG
2403 if (!this->caps()->npotTextureTileSupport()) { 2419 if (!this->caps()->npotTextureTileSupport()) {
2404 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); 2420 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX();
2405 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); 2421 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY();
2406 if (tileX || tileY) { 2422 if (tileX || tileY) {
2407 const int w = texture->width(); 2423 const int w = texture->width();
2408 const int h = texture->height(); 2424 const int h = texture->height();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 2471
2456 if (GrTextureParams::kMipMap_FilterMode == filterMode && 2472 if (GrTextureParams::kMipMap_FilterMode == filterMode &&
2457 texture->texturePriv().mipMapsAreDirty()) { 2473 texture->texturePriv().mipMapsAreDirty()) {
2458 GL_CALL(GenerateMipmap(target)); 2474 GL_CALL(GenerateMipmap(target));
2459 texture->texturePriv().dirtyMipMaps(false); 2475 texture->texturePriv().dirtyMipMaps(false);
2460 } 2476 }
2461 2477
2462 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); 2478 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX());
2463 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); 2479 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY());
2464 memcpy(newTexParams.fSwizzleRGBA, 2480 memcpy(newTexParams.fSwizzleRGBA,
2465 GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps ()), 2481 GetTexParamSwizzle(texture->config(), this->glCaps()),
2466 sizeof(newTexParams.fSwizzleRGBA)); 2482 sizeof(newTexParams.fSwizzleRGBA));
2467 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { 2483 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) {
2468 this->setTextureUnit(unitIdx); 2484 this->setTextureUnit(unitIdx);
2469 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));
2470 } 2486 }
2471 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { 2487 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) {
2472 this->setTextureUnit(unitIdx); 2488 this->setTextureUnit(unitIdx);
2473 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));
2474 } 2490 }
2475 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { 2491 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) {
2476 this->setTextureUnit(unitIdx); 2492 this->setTextureUnit(unitIdx);
2477 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS) ); 2493 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS) );
2478 } 2494 }
2479 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { 2495 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) {
2480 this->setTextureUnit(unitIdx); 2496 this->setTextureUnit(unitIdx);
2481 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT) ); 2497 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT) );
2482 } 2498 }
2483 if (this->glCaps().textureSwizzleSupport() && 2499 if (this->glCaps().glslCaps()->textureSwizzleSupport() &&
2484 (setAll || memcmp(newTexParams.fSwizzleRGBA, 2500 (setAll || memcmp(newTexParams.fSwizzleRGBA,
2485 oldTexParams.fSwizzleRGBA, 2501 oldTexParams.fSwizzleRGBA,
2486 sizeof(newTexParams.fSwizzleRGBA)))) { 2502 sizeof(newTexParams.fSwizzleRGBA)))) {
2487 this->setTextureUnit(unitIdx); 2503 this->setTextureUnit(unitIdx);
2488 if (this->glStandard() == kGLES_GrGLStandard) { 2504 if (this->glStandard() == kGLES_GrGLStandard) {
2489 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. 2505 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA.
2490 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; 2506 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA;
2491 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0])); 2507 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0]));
2492 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1])); 2508 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1]));
2493 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2])); 2509 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2]));
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2629 } else { 2645 } else {
2630 *internalFormat = GR_GL_RGBA; 2646 *internalFormat = GR_GL_RGBA;
2631 } 2647 }
2632 *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; 2648 *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
2633 break; 2649 break;
2634 case kIndex_8_GrPixelConfig: 2650 case kIndex_8_GrPixelConfig:
2635 // no sized/unsized internal format distinction here 2651 // no sized/unsized internal format distinction here
2636 *internalFormat = GR_GL_PALETTE8_RGBA8; 2652 *internalFormat = GR_GL_PALETTE8_RGBA8;
2637 break; 2653 break;
2638 case kAlpha_8_GrPixelConfig: 2654 case kAlpha_8_GrPixelConfig:
2639 if (this->glCaps().textureRedSupport()) { 2655 if (this->glCaps().glslCaps()->textureRedSupport()) {
2640 *internalFormat = GR_GL_RED; 2656 *internalFormat = GR_GL_RED;
2641 *externalFormat = GR_GL_RED; 2657 *externalFormat = GR_GL_RED;
2642 if (getSizedInternalFormat) { 2658 if (getSizedInternalFormat) {
2643 *internalFormat = GR_GL_R8; 2659 *internalFormat = GR_GL_R8;
2644 } else { 2660 } else {
2645 *internalFormat = GR_GL_RED; 2661 *internalFormat = GR_GL_RED;
2646 } 2662 }
2647 *externalType = GR_GL_UNSIGNED_BYTE; 2663 *externalType = GR_GL_UNSIGNED_BYTE;
2648 } else { 2664 } else {
2649 *internalFormat = GR_GL_ALPHA; 2665 *internalFormat = GR_GL_ALPHA;
(...skipping 30 matching lines...) Expand all
2680 *internalFormat = GR_GL_COMPRESSED_RGBA_ASTC_12x12_KHR; 2696 *internalFormat = GR_GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
2681 break; 2697 break;
2682 2698
2683 case kRGBA_float_GrPixelConfig: 2699 case kRGBA_float_GrPixelConfig:
2684 *internalFormat = GR_GL_RGBA32F; 2700 *internalFormat = GR_GL_RGBA32F;
2685 *externalFormat = GR_GL_RGBA; 2701 *externalFormat = GR_GL_RGBA;
2686 *externalType = GR_GL_FLOAT; 2702 *externalType = GR_GL_FLOAT;
2687 break; 2703 break;
2688 2704
2689 case kAlpha_half_GrPixelConfig: 2705 case kAlpha_half_GrPixelConfig:
2690 if (this->glCaps().textureRedSupport()) { 2706 if (this->glCaps().glslCaps()->textureRedSupport()) {
2691 if (getSizedInternalFormat) { 2707 if (getSizedInternalFormat) {
2692 *internalFormat = GR_GL_R16F; 2708 *internalFormat = GR_GL_R16F;
2693 } else { 2709 } else {
2694 *internalFormat = GR_GL_RED; 2710 *internalFormat = GR_GL_RED;
2695 } 2711 }
2696 *externalFormat = GR_GL_RED; 2712 *externalFormat = GR_GL_RED;
2697 } else { 2713 } else {
2698 if (getSizedInternalFormat) { 2714 if (getSizedInternalFormat) {
2699 *internalFormat = GR_GL_ALPHA16F; 2715 *internalFormat = GR_GL_ALPHA16F;
2700 } else { 2716 } else {
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
3295 this->setVertexArrayID(gpu, 0); 3311 this->setVertexArrayID(gpu, 0);
3296 } 3312 }
3297 int attrCount = gpu->glCaps().maxVertexAttributes(); 3313 int attrCount = gpu->glCaps().maxVertexAttributes();
3298 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3314 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3299 fDefaultVertexArrayAttribState.resize(attrCount); 3315 fDefaultVertexArrayAttribState.resize(attrCount);
3300 } 3316 }
3301 attribState = &fDefaultVertexArrayAttribState; 3317 attribState = &fDefaultVertexArrayAttribState;
3302 } 3318 }
3303 return attribState; 3319 return attribState;
3304 } 3320 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698