aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-28 13:46:42 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-28 13:46:42 +0000
commitb8eb2e89edf914caf5479baeffcb670d3e93f496 (patch)
tree328527b349cf6cc24c07be4f466ebe35a34c230f /src/gpu/gl
parent51c81123afbf9a09fda43ca2d287fcf4f5593e9c (diff)
Make GrGLShaderBuilder::TextureSampler extract only required info from GrTextureAccess.
This will make it possible to init a TextureSampler without a texture or a specific config. Also unify two separate bitfields of color components in GPU code. Review URL: https://codereview.chromium.org/13121002 git-svn-id: http://skia.googlecode.com/svn/trunk@8428 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/GrGLCaps.cpp4
-rw-r--r--src/gpu/gl/GrGLCaps.h2
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.cpp25
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.h45
4 files changed, 42 insertions, 34 deletions
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 5e555f9653..1f3cf16464 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -462,7 +462,7 @@ void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
return;
#endif
- GrAssert((unsigned)config < kGrPixelConfigCount);
+ GrAssert((unsigned)config < kGrPixelConfigCnt);
GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
int count = fStencilFormats.count();
// we expect a really small number of possible formats so linear search
@@ -485,7 +485,7 @@ bool GrGLCaps::isColorConfigAndStencilFormatVerified(
#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
return false;
#endif
- GrAssert((unsigned)config < kGrPixelConfigCount);
+ GrAssert((unsigned)config < kGrPixelConfigCnt);
int count = fStencilFormats.count();
// we expect a really small number of possible formats so linear search
// should be OK
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 920140f1e6..4599e57bdf 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -252,7 +252,7 @@ private:
}
}
- static const int kNumUints = (kGrPixelConfigCount + 31) / 32;
+ static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
uint32_t fVerifiedColorConfigs[kNumUints];
void markVerified(GrPixelConfig config) {
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index 3808402ab4..a5c96c7dd6 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -40,10 +40,10 @@ inline const char* sample_function_name(GrSLType type, GrGLSLGeneration glslGen)
inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps,
const GrTextureAccess& access) {
if (GrPixelConfigIsAlphaOnly(access.getTexture()->config())) {
- if (caps.textureRedSupport() && (GrTextureAccess::kA_SwizzleFlag & access.swizzleMask())) {
+ if (caps.textureRedSupport() && (kA_GrColorComponentFlag & access.swizzleMask())) {
return true;
}
- if (GrTextureAccess::kRGB_SwizzleMask & access.swizzleMask()) {
+ if (kRGB_GrColorComponentFlags & access.swizzleMask()) {
return true;
}
}
@@ -51,14 +51,15 @@ inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps,
}
void append_swizzle(SkString* outAppend,
- const GrTextureAccess& access,
+ const GrGLShaderBuilder::TextureSampler& texSampler,
const GrGLCaps& caps) {
- const char* swizzle = access.getSwizzle();
+ const char* swizzle = texSampler.swizzle();
char mangledSwizzle[5];
// The swizzling occurs using texture params instead of shader-mangling if ARB_texture_swizzle
// is available.
- if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(access.getTexture()->config())) {
+ if (!caps.textureSwizzleSupport() &&
+ (kA_GrColorComponentFlag == texSampler.configComponentMask())) {
char alphaChar = caps.textureRedSupport() ? 'r' : 'a';
int i;
for (i = 0; '\0' != swizzle[i]; ++i) {
@@ -151,14 +152,13 @@ void GrGLShaderBuilder::appendTextureLookup(SkString* out,
const GrGLShaderBuilder::TextureSampler& sampler,
const char* coordName,
GrSLType varyingType) const {
- GrAssert(NULL != sampler.textureAccess());
GrAssert(NULL != coordName);
out->appendf("%s(%s, %s)",
sample_function_name(varyingType, fCtxInfo.glslGeneration()),
this->getUniformCStr(sampler.fSamplerUniform),
coordName);
- append_swizzle(out, *sampler.textureAccess(), *fCtxInfo.caps());
+ append_swizzle(out, sampler, *fCtxInfo.caps());
}
void GrGLShaderBuilder::appendTextureLookup(ShaderType type,
@@ -191,17 +191,6 @@ GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess(
if (!caps.textureSwizzleSupport() && swizzle_requires_alpha_remapping(caps, access)) {
key = 1;
}
-#if GR_DEBUG
- // Assert that key is set iff the swizzle will be modified.
- SkString origString(access.getSwizzle());
- origString.prepend(".");
- SkString modifiedString;
- append_swizzle(&modifiedString, access, caps);
- if (!modifiedString.size()) {
- modifiedString = ".rgba";
- }
- GrAssert(SkToBool(key) == (modifiedString != origString));
-#endif
return key;
}
diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h
index 9d64143802..d947771b3e 100644
--- a/src/gpu/gl/GrGLShaderBuilder.h
+++ b/src/gpu/gl/GrGLShaderBuilder.h
@@ -10,6 +10,7 @@
#include "GrAllocator.h"
#include "GrBackendEffectFactory.h"
+#include "GrColor.h"
#include "GrEffect.h"
#include "gl/GrGLSL.h"
#include "gl/GrGLUniformManager.h"
@@ -31,31 +32,40 @@ public:
class TextureSampler {
public:
TextureSampler()
- : fTextureAccess(NULL)
- , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) {}
+ : fConfigComponentMask(0)
+ , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) {
+ // we will memcpy the first 4 bytes from passed in swizzle. This ensures the string is
+ // terminated.
+ fSwizzle[4] = '\0';
+ }
TextureSampler(const TextureSampler& other) { *this = other; }
TextureSampler& operator= (const TextureSampler& other) {
- GrAssert(NULL == fTextureAccess);
+ GrAssert(0 == fConfigComponentMask);
GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform);
- fTextureAccess = other.fTextureAccess;
+ fConfigComponentMask = other.fConfigComponentMask;
fSamplerUniform = other.fSamplerUniform;
return *this;
}
- const GrTextureAccess* textureAccess() const { return fTextureAccess; }
+ // bitfield of GrColorComponentFlags present in the texture's config.
+ uint32_t configComponentMask() const { return fConfigComponentMask; }
+
+ const char* swizzle() const { return fSwizzle; }
private:
// The idx param is used to ensure multiple samplers within a single effect have unique
- // uniform names.
- void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) {
- GrAssert(NULL == fTextureAccess);
+ // uniform names. swizzle is a four char max string made up of chars 'r', 'g', 'b', and 'a'.
+ void init(GrGLShaderBuilder* builder,
+ uint32_t configComponentMask,
+ const char* swizzle,
+ int idx) {
+ GrAssert(0 == fConfigComponentMask);
GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform);
GrAssert(NULL != builder);
- GrAssert(NULL != access);
SkString name;
name.printf("Sampler%d_", idx);
fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
@@ -63,14 +73,23 @@ public:
name.c_str());
GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUniform);
- fTextureAccess = access;
+ fConfigComponentMask = configComponentMask;
+ memcpy(fSwizzle, swizzle, 4);
+ }
+
+ void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) {
+ GrAssert(NULL != access);
+ this->init(builder,
+ GrPixelConfigComponentMask(access->getTexture()->config()),
+ access->getSwizzle(),
+ idx);
}
- const GrTextureAccess* fTextureAccess;
+ uint32_t fConfigComponentMask;
+ char fSwizzle[5];
GrGLUniformManager::UniformHandle fSamplerUniform;
- friend class GrGLShaderBuilder; // to access fSamplerUniform
- friend class GrGLProgram; // to construct these and access fSamplerUniform.
+ friend class GrGLShaderBuilder; // to call init().
};
typedef SkTArray<TextureSampler> TextureSamplerArray;