GrGLProgramEffects.h revision f1077f916427c99bdec655da4c3b9eea70423685
13390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org/*
23390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org * Copyright 2013 Google Inc.
33390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org *
43390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
53390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org * found in the LICENSE file.
63390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org */
73390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
83390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org#ifndef GrGLProgramEffects_DEFINED
93390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org#define GrGLProgramEffects_DEFINED
103390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
113390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org#include "GrBackendEffectFactory.h"
123390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org#include "GrTexture.h"
133390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org#include "GrTextureAccess.h"
143390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org#include "GrGLUniformManager.h"
153390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
163390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.orgclass GrEffectStage;
17261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.orgclass GrGLVertexProgramEffectsBuilder;
183390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.orgclass GrGLShaderBuilder;
19261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.orgclass GrGLFullShaderBuilder;
206b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.orgclass GrGLFragmentOnlyShaderBuilder;
213390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
223390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org/**
233390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org * This class encapsulates an array of GrGLEffects and their supporting data (coord transforms
243390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org * and textures). It is built with GrGLProgramEffectsBuilder, then used to manage the necessary GL
253390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org * state and shader uniforms.
263390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org */
273390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.orgclass GrGLProgramEffects {
283390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.orgpublic:
293390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    typedef GrBackendEffectFactory::EffectKey EffectKey;
303390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    typedef GrGLUniformManager::UniformHandle UniformHandle;
313390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
323390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    /**
333390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     * These methods generate different portions of an effect's final key.
343390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     */
353390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    static EffectKey GenAttribKey(const GrDrawEffect&);
363390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    static EffectKey GenTransformKey(const GrDrawEffect&);
373390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&);
383390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
39261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    virtual ~GrGLProgramEffects();
403390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
413390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    /**
423390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writes the next
433390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     * available unit to *texUnitIdx when it returns.
443390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     */
453390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    void initSamplers(const GrGLUniformManager&, int* texUnitIdx);
463390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
473390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    /**
483390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     * Calls setData() on each effect, and sets their transformation matrices and texture bindings.
493390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     */
50261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    virtual void setData(GrGpuGL*,
51261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                         const GrGLUniformManager&,
52261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                         const GrEffectStage* effectStages[]) = 0;
533390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
543390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    /**
553390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     * Passed to GrGLEffects so they can add transformed coordinates to their shader code.
563390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     */
573390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    class TransformedCoords {
583390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    public:
596b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org        TransformedCoords(const SkString& name, GrSLType type)
605fd7d5c20a15094da3fb6dc1d59955fd8f3217d7commit-bot@chromium.org            : fName(name), fType(type) {
613390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        }
623390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
633390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        const char* c_str() const { return fName.c_str(); }
643390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        GrSLType type() const { return fType; }
653390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        const SkString& getName() const { return fName; }
663390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
673390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    private:
683390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        SkString fName;
693390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        GrSLType fType;
703390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    };
713390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
723390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    typedef SkTArray<TransformedCoords> TransformedCoordsArray;
733390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
743390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    /**
753390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     * Passed to GrGLEffects so they can add texture reads to their shader code.
763390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     */
773390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    class TextureSampler {
783390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    public:
793390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        TextureSampler(UniformHandle uniform, const GrTextureAccess& access)
803390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org            : fSamplerUniform(uniform)
813390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org            , fConfigComponentMask(GrPixelConfigComponentMask(access.getTexture()->config())) {
823390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org            SkASSERT(0 != fConfigComponentMask);
833390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org            memcpy(fSwizzle, access.getSwizzle(), 5);
843390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        }
853390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
863390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        UniformHandle samplerUniform() const { return fSamplerUniform; }
873390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        // bitfield of GrColorComponentFlags present in the texture's config.
883390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        uint32_t configComponentMask() const { return fConfigComponentMask; }
893390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        const char* swizzle() const { return fSwizzle; }
903390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
913390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    private:
923390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        UniformHandle fSamplerUniform;
933390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        uint32_t      fConfigComponentMask;
943390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        char          fSwizzle[5];
953390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    };
963390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
973390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    typedef SkTArray<TextureSampler> TextureSamplerArray;
983390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
99261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.orgprotected:
100261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    GrGLProgramEffects(int reserveCount)
1013390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        : fGLEffects(reserveCount)
102261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org        , fSamplers(reserveCount) {
103261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    }
104261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
105261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    /**
1066b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's texture accesses and
1076b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * appends the necessary data to the TextureSamplerArray* object so effects can add texture
1086b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * lookups to their code. This method is only meant to be called during the construction phase.
1096b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     */
1106b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    void emitSamplers(GrGLShaderBuilder*, const GrEffectRef&, TextureSamplerArray*);
1116b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
1126b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    /**
113261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org     * Helper for setData(). Binds all the textures for an effect.
114261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org     */
115261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    void bindTextures(GrGpuGL*, const GrEffectRef&, int effectIdx);
116261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
117261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    struct Sampler {
118261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org        SkDEBUGCODE(Sampler() : fTextureUnit(-1) {})
119261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org        UniformHandle fUniform;
120261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org        int           fTextureUnit;
121261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    };
122261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
123261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    SkTArray<GrGLEffect*>                  fGLEffects;
124261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    SkTArray<SkSTArray<4, Sampler, true> > fSamplers;
125261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org};
126261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
127261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org/**
1286b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org * This is an abstract base class for constructing different types of GrGLProgramEffects objects.
1296b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org */
1306b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.orgclass GrGLProgramEffectsBuilder {
1316b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.orgpublic:
132f1077f916427c99bdec655da4c3b9eea70423685mtklein@google.com    virtual ~GrGLProgramEffectsBuilder() { }
133f1077f916427c99bdec655da4c3b9eea70423685mtklein@google.com
1346b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    /**
1356b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Emits the effect's shader code, and stores the necessary uniforms internally.
1366b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     */
1376b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    virtual void emitEffect(const GrEffectStage&,
1386b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                            GrGLProgramEffects::EffectKey,
1396b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                            const char* outColor,
1406b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                            const char* inColor,
1416b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                            int stageIndex) = 0;
1426b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org};
1436b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
1446b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org////////////////////////////////////////////////////////////////////////////////
1456b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
1466b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org/**
147261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org * This is a GrGLProgramEffects implementation that does coord transforms with the vertex shader.
148261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org */
149261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.orgclass GrGLVertexProgramEffects : public GrGLProgramEffects {
150261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.orgpublic:
151261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    virtual void setData(GrGpuGL*,
152261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                         const GrGLUniformManager&,
153261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                         const GrEffectStage* effectStages[]) SK_OVERRIDE;
154261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
155261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.orgprivate:
156261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    friend class GrGLVertexProgramEffectsBuilder;
157261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
158261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords)
159261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org        : INHERITED(reserveCount)
1603390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        , fTransforms(reserveCount)
1613390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        , fHasExplicitLocalCoords(explicitLocalCoords) {
1623390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    }
1633390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
1643390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    /**
1656b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant to only be called
1666b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * during the construction phase.
1676b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     */
1686b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    void emitEffect(GrGLFullShaderBuilder*,
1696b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    const GrEffectStage&,
1706b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    GrGLProgramEffects::EffectKey,
1716b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    const char* outColor,
1726b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    const char* inColor,
1736b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    int stageIndex);
1746b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
1756b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    /**
1766b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Helper for emitEffect(). Emits any attributes an effect may have.
1776b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     */
1786b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    void emitAttributes(GrGLFullShaderBuilder*, const GrEffectStage&);
1796b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
1806b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    /**
1816b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Helper for emitEffect(). Emits code to implement an effect's coord transforms in the VS.
1826b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Varyings are added as an outputs of the VS and inputs to the FS. The varyings may be either a
1836b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * vec2f or vec3f depending upon whether perspective interpolation is required or not. The names
1846b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * of the varyings in the VS and FS as well their types are appended to the
1856b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * TransformedCoordsArray* object, which is in turn passed to the effect's emitCode() function.
1866b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     */
1876b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    void emitTransforms(GrGLFullShaderBuilder*,
1886b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                        const GrEffectRef&,
1896b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                        EffectKey,
1906b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                        TransformedCoordsArray*);
1916b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
1926b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    /**
1933390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     * Helper for setData(). Sets all the transform matrices for an effect.
1943390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     */
1953390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    void setTransformData(const GrGLUniformManager&, const GrDrawEffect&, int effectIdx);
1963390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
1973390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    struct Transform {
1983390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); }
1993390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        UniformHandle fHandle;
2003390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        GrSLType      fType;
2013390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org        SkMatrix      fCurrentValue;
2023390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    };
2033390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
2043390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    SkTArray<SkSTArray<2, Transform, true> > fTransforms;
2053390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    bool                                     fHasExplicitLocalCoords;
206261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
207261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    typedef GrGLProgramEffects INHERITED;
2083390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org};
2093390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
2103390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org/**
2116b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org * This class is used to construct a GrGLVertexProgramEffects* object.
2123390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org */
2136b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.orgclass GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder {
2143390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.orgpublic:
2156b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    GrGLVertexProgramEffectsBuilder(GrGLFullShaderBuilder*, int reserveCount);
216f1077f916427c99bdec655da4c3b9eea70423685mtklein@google.com    virtual ~GrGLVertexProgramEffectsBuilder() { }
2176b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
218261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    virtual void emitEffect(const GrEffectStage&,
219261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                            GrGLProgramEffects::EffectKey,
220261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                            const char* outColor,
221261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                            const char* inColor,
2226b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                            int stageIndex) SK_OVERRIDE;
223261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
224261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    /**
2256b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Finalizes the building process and returns the effect array. After this call, the builder
2266b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * becomes invalid.
227261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org     */
2286b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    GrGLProgramEffects* finish() { return fProgramEffects.detach(); }
2296b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2306b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.orgprivate:
2316b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    GrGLFullShaderBuilder*                  fBuilder;
2326b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    SkAutoTDelete<GrGLVertexProgramEffects> fProgramEffects;
2336b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2346b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    typedef GrGLProgramEffectsBuilder INHERITED;
235261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org};
236261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
2376b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org////////////////////////////////////////////////////////////////////////////////
2386b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
239261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org/**
2406b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org * This is a GrGLProgramEffects implementation that does coord transforms with the the built-in GL
2416b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org * TexGen functionality.
242261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org */
2436b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.orgclass GrGLTexGenProgramEffects : public GrGLProgramEffects {
244261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.orgpublic:
2456b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    virtual void setData(GrGpuGL*,
2466b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                         const GrGLUniformManager&,
2476b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                         const GrEffectStage* effectStages[]) SK_OVERRIDE;
2486b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2496b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.orgprivate:
2506b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    friend class GrGLTexGenProgramEffectsBuilder;
2516b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2526b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    GrGLTexGenProgramEffects(int reserveCount)
2536b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org        : INHERITED(reserveCount)
2546b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org        , fTransforms(reserveCount) {
2556b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    }
2566b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2576b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    /**
2586b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant to only be called
2596b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * during the construction phase.
2606b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     */
2616b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    void emitEffect(GrGLFragmentOnlyShaderBuilder*,
2626b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    const GrEffectStage&,
2636b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    GrGLProgramEffects::EffectKey,
2646b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    const char* outColor,
2656b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    const char* inColor,
2666b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                    int stageIndex);
2676b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2686b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    /**
2696b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Helper for emitEffect(). Allocates texture units from the builder for each transform in an
2706b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * effect. The transforms all use adjacent texture units. They either use two or three of the
2716b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * coordinates at a given texture unit, depending on if they need perspective interpolation.
2726b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[0])') as well as the
2736b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * types are appended to the TransformedCoordsArray* object, which is in turn passed to the
2746b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * effect's emitCode() function.
2756b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     */
2766b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    void setupTexGen(GrGLFragmentOnlyShaderBuilder*,
2776b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                     const GrEffectRef&,
2786b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                     EffectKey,
2796b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                     TransformedCoordsArray*);
2806b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2816b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    /**
2826b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     * Helper for setData(). Sets the TexGen state for each transform in an effect.
2836b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org     */
2846b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    void setTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx);
2856b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2866b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    struct Transforms {
2876b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org        Transforms(EffectKey transformKey, int texCoordIndex)
2886b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org            : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {}
2896b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org        EffectKey fTransformKey;
2906b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org        int fTexCoordIndex;
2916b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    };
2926b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2936b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    SkTArray<Transforms> fTransforms;
2946b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2956b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    typedef GrGLProgramEffects INHERITED;
2966b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org};
2976b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
2986b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org/**
2996b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org * This class is used to construct a GrGLTexGenProgramEffects* object.
3006b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org */
3016b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.orgclass GrGLTexGenProgramEffectsBuilder : public GrGLProgramEffectsBuilder {
3026b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.orgpublic:
3036b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    GrGLTexGenProgramEffectsBuilder(GrGLFragmentOnlyShaderBuilder*, int reserveCount);
304f1077f916427c99bdec655da4c3b9eea70423685mtklein@google.com    virtual ~GrGLTexGenProgramEffectsBuilder() { }
305261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org
306261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    virtual void emitEffect(const GrEffectStage&,
307261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                            GrGLProgramEffects::EffectKey,
308261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                            const char* outColor,
309261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                            const char* inColor,
310261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org                            int stageIndex) SK_OVERRIDE;
3113390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
3123390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    /**
3133390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     * Finalizes the building process and returns the effect array. After this call, the builder
3143390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     * becomes invalid.
3153390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org     */
3163390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org    GrGLProgramEffects* finish() { return fProgramEffects.detach(); }
3173390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
3183390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.orgprivate:
3196b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    GrGLFragmentOnlyShaderBuilder*          fBuilder;
3206b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    SkAutoTDelete<GrGLTexGenProgramEffects> fProgramEffects;
3213390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
322261dc569b6a53729bea6e4e7a0cf2afa980eb82dcommit-bot@chromium.org    typedef GrGLProgramEffectsBuilder INHERITED;
3233390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org};
3243390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org
3253390b9ac9ad69a6e772c2b957d75d19611239025commit-bot@chromium.org#endif
326