From 4036674952f341dab0695c3b054fefa5bb8cdec1 Mon Sep 17 00:00:00 2001 From: egdaniel Date: Tue, 3 Nov 2015 08:15:28 -0800 Subject: Create swizzle table inside of glsl caps BUG=skia: Review URL: https://codereview.chromium.org/1420033005 --- src/gpu/gl/builders/GrGLShaderBuilder.cpp | 80 +++++++++++++++++-------------- src/gpu/gl/builders/GrGLShaderBuilder.h | 8 ---- 2 files changed, 44 insertions(+), 44 deletions(-) (limited to 'src/gpu/gl/builders') diff --git a/src/gpu/gl/builders/GrGLShaderBuilder.cpp b/src/gpu/gl/builders/GrGLShaderBuilder.cpp index 03dc1667c7..2c00bafcf7 100644 --- a/src/gpu/gl/builders/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLShaderBuilder.cpp @@ -6,47 +6,68 @@ */ #include "GrGLShaderBuilder.h" -#include "gl/GrGLGpu.h" #include "gl/builders/GrGLProgramBuilder.h" #include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLShaderVar.h" #include "glsl/GrGLSLTextureSampler.h" -namespace { -void append_texture_lookup(SkString* out, - GrGLGpu* gpu, - const char* samplerName, - const char* coordName, - uint32_t configComponentMask, - const char* swizzle, - GrSLType varyingType = kVec2f_GrSLType) { +static void map_swizzle(const char* swizzleMap, const char* swizzle, char* mangledSwizzle) { + int i; + for (i = 0; '\0' != swizzle[i]; ++i) { + switch (swizzle[i]) { + case 'r': + mangledSwizzle[i] = swizzleMap[0]; + break; + case 'g': + mangledSwizzle[i] = swizzleMap[1]; + break; + case 'b': + mangledSwizzle[i] = swizzleMap[2]; + break; + case 'a': + mangledSwizzle[i] = swizzleMap[3]; + break; + default: + SkFAIL("Unsupported swizzle"); + } + } + mangledSwizzle[i] ='\0'; +} + +static void append_texture_lookup(SkString* out, + const GrGLSLCaps* glslCaps, + const char* samplerName, + const char* coordName, + GrPixelConfig config, + const char* swizzle, + GrSLType varyingType = kVec2f_GrSLType) { SkASSERT(coordName); out->appendf("%s(%s, %s)", - GrGLSLTexture2DFunctionName(varyingType, gpu->glslGeneration()), + GrGLSLTexture2DFunctionName(varyingType, glslCaps->generation()), samplerName, coordName); char mangledSwizzle[5]; - // The swizzling occurs using texture params instead of shader-mangling if ARB_texture_swizzle - // is available. - if (!gpu->glCaps().textureSwizzleSupport() && - (kA_GrColorComponentFlag == configComponentMask)) { - char alphaChar = gpu->glCaps().textureRedSupport() ? 'r' : 'a'; - int i; - for (i = 0; '\0' != swizzle[i]; ++i) { - mangledSwizzle[i] = alphaChar; + // This refers to any swizzling we may need to get from some backend internal format to the + // format used in GrPixelConfig. Some backends will automatically do the sizzling for us. + if (glslCaps->mustSwizzleInShader()) { + const char* swizzleMap = glslCaps->getSwizzleMap(config); + // if the map is simply 'rgba' then we don't need to do any manual swizzling to get us to + // a GrPixelConfig format. + if (memcmp(swizzleMap, "rgba", 4)) { + // Manually 'swizzle' the swizzle using our mapping + map_swizzle(swizzleMap, swizzle, mangledSwizzle); + swizzle = mangledSwizzle; } - mangledSwizzle[i] ='\0'; - swizzle = mangledSwizzle; } + // For shader prettiness we omit the swizzle rather than appending ".rgba". if (memcmp(swizzle, "rgba", 4)) { out->appendf(".%s", swizzle); } } -} GrGLShaderBuilder::GrGLShaderBuilder(GrGLProgramBuilder* program) : fProgramBuilder(program) @@ -97,10 +118,10 @@ void GrGLShaderBuilder::appendTextureLookup(SkString* out, const char* coordName, GrSLType varyingType) const { append_texture_lookup(out, - fProgramBuilder->gpu(), + fProgramBuilder->glslCaps(), fProgramBuilder->getUniformCStr(sampler.fSamplerUniform), coordName, - sampler.configComponentMask(), + sampler.config(), sampler.swizzle(), varyingType); } @@ -134,19 +155,6 @@ void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { } } -void GrGLShaderBuilder::appendTextureLookup(const char* samplerName, - const char* coordName, - uint32_t configComponentMask, - const char* swizzle) { - append_texture_lookup(&this->code(), - fProgramBuilder->gpu(), - samplerName, - coordName, - configComponentMask, - swizzle, - kVec2f_GrSLType); -} - void GrGLShaderBuilder::addLayoutQualifier(const char* param, InterfaceQualifier interface) { SkASSERT(fProgramBuilder->glslCaps()->generation() >= k330_GrGLSLGeneration || fProgramBuilder->glslCaps()->mustEnableAdvBlendEqs()); diff --git a/src/gpu/gl/builders/GrGLShaderBuilder.h b/src/gpu/gl/builders/GrGLShaderBuilder.h index 2daea1515b..d63a679e8c 100644 --- a/src/gpu/gl/builders/GrGLShaderBuilder.h +++ b/src/gpu/gl/builders/GrGLShaderBuilder.h @@ -125,14 +125,6 @@ protected: typedef GrTAllocator VarArray; void appendDecls(const VarArray& vars, SkString* out) const; - /* - * this super low level function is just for use internally to builders - */ - void appendTextureLookup(const char* samplerName, - const char* coordName, - uint32_t configComponentMask, - const char* swizzle); - /* * A general function which enables an extension in a shader if the feature bit is not present */ -- cgit v1.2.3