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

Unified Diff: src/gpu/gl/GrGLShaderBuilder.cpp

Issue 24853002: Make GPU coord transforms automatic (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLShaderBuilder.cpp
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index f4ffb4dd2ce2f071743c9c3d08b3edb7abaa4d56..313ad863c346379cecdf75f2934e1f43b778b342 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -8,6 +8,7 @@
#include "gl/GrGLShaderBuilder.h"
#include "gl/GrGLProgram.h"
#include "gl/GrGLUniformHandle.h"
+#include "GrCoordTransform.h"
#include "GrDrawEffect.h"
#include "GrGpuGL.h"
#include "GrTexture.h"
@@ -347,9 +348,8 @@ void GrGLShaderBuilder::fsAppendTextureLookupAndModulate(
GrGLSLModulatef<4>(&fFSCode, modulation, lookup.c_str());
}
-GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess(
- const GrTextureAccess& access,
- const GrGLCaps& caps) {
+GrGLShaderBuilder::EffectKey GrGLShaderBuilder::KeyForTextureAccess(const GrTextureAccess& access,
+ const GrGLCaps& caps) {
uint32_t configComponentMask = GrPixelConfigComponentMask(access.getTexture()->config());
if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.swizzleMask())) {
return 1;
@@ -440,6 +440,21 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t vi
return h;
}
+SkString GrGLShaderBuilder::ensureFSCoords2D(const TransformedCoordsArray& coords, int index) {
+ if (kVec3f_GrSLType != coords[index].type()) {
+ SkASSERT(kVec2f_GrSLType == coords[index].type());
+ return coords[index].getName();
+ }
+
+ SkString coords2D("coords2D");
+ if (0 != index) {
+ coords2D.appendf("_%i", index);
+ }
+ this->fsCodeAppendf("\tvec2 %s = %s.xy / %s.z;",
+ coords2D.c_str(), coords[index].c_str(), coords[index].c_str());
+ return coords2D;
+}
+
const char* GrGLShaderBuilder::fragmentPosition() {
if (fCodeStage.inStageCode()) {
const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect();
@@ -559,10 +574,11 @@ void GrGLShaderBuilder::appendUniformDecls(ShaderVisibility visibility,
void GrGLShaderBuilder::emitEffects(
const GrEffectStage* effectStages[],
- const GrBackendEffectFactory::EffectKey effectKeys[],
+ const EffectKey effectKeys[],
int effectCnt,
SkString* fsInOutColor,
GrSLConstantVec* fsInOutColorKnownValue,
+ SkTArray<GrGLCoordTransform, false>* effectCoordTransformArrays[],
SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[],
GrGLEffect* glEffects[]) {
bool effectEmitted = false;
@@ -577,6 +593,17 @@ void GrGLShaderBuilder::emitEffects(
CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
+ int numTransforms = effect->numTransforms();
+ SkSTArray<8, GrGLCoordTransform::TransformedCoords> transformedCoords;
+ transformedCoords.push_back_n(numTransforms);
+ EffectKey transformKey = GrBackendEffectFactory::GetTransformKey(effectKeys[e]);
+ for (int c = 0; c < numTransforms; ++c) {
+ GrGLCoordTransform& ct = effectCoordTransformArrays[e]->push_back();
+ EffectKey key = (transformKey >> (c * GrGLCoordTransform::kKeyBits)) &
+ (GrGLCoordTransform::kKeyMask);
+ ct.emitCode(this, key, &transformedCoords[c], c);
+ }
+
int numTextures = effect->numTextures();
SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers;
textureSamplers.push_back_n(numTextures);
@@ -584,6 +611,7 @@ void GrGLShaderBuilder::emitEffects(
textureSamplers[t].init(this, &effect->textureAccess(t), t);
effectSamplerHandles[e]->push_back(textureSamplers[t].fSamplerUniform);
}
+
GrDrawEffect drawEffect(stage, NULL != fVertexBuilder.get()
&& fVertexBuilder->hasExplicitLocalCoords());
@@ -625,6 +653,7 @@ void GrGLShaderBuilder::emitEffects(
effectKeys[e],
outColor.c_str(),
inColor.isEmpty() ? NULL : inColor.c_str(),
+ transformedCoords,
textureSamplers);
if (NULL != fVertexBuilder.get()) {
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698