gfx/skia/trunk/src/gpu/gl/GrGLEffect.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLEffect.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,113 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef GrGLEffect_DEFINED
    1.12 +#define GrGLEffect_DEFINED
    1.13 +
    1.14 +#include "GrBackendEffectFactory.h"
    1.15 +#include "GrGLProgramEffects.h"
    1.16 +#include "GrGLShaderBuilder.h"
    1.17 +#include "GrGLShaderVar.h"
    1.18 +#include "GrGLSL.h"
    1.19 +
    1.20 +/** @file
    1.21 +    This file contains specializations for OpenGL of the shader stages declared in
    1.22 +    include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitting the
    1.23 +    GLSL code that implements a GrEffect and for uploading uniforms at draw time. If they don't
    1.24 +    always emit the same GLSL code, they must have a function:
    1.25 +        static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&)
    1.26 +    that is used to implement a program cache. When two GrEffects produce the same key this means
    1.27 +    that their GrGLEffects would emit the same GLSL code.
    1.28 +
    1.29 +    The GrGLEffect subclass must also have a constructor of the form:
    1.30 +        EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrDrawEffect&)
    1.31 +    The effect held by the GrDrawEffect is guaranteed to be of the type that generated the
    1.32 +    GrGLEffect subclass instance.
    1.33 +
    1.34 +    These objects are created by the factory object returned by the GrEffect::getFactory().
    1.35 +*/
    1.36 +
    1.37 +class GrDrawEffect;
    1.38 +class GrGLTexture;
    1.39 +class GrGLVertexEffect;
    1.40 +
    1.41 +class GrGLEffect {
    1.42 +
    1.43 +public:
    1.44 +    typedef GrBackendEffectFactory::EffectKey EffectKey;
    1.45 +    typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
    1.46 +    typedef GrGLProgramEffects::TextureSampler TextureSampler;
    1.47 +    typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray;
    1.48 +
    1.49 +    enum {
    1.50 +        kNoEffectKey = GrBackendEffectFactory::kNoEffectKey,
    1.51 +        // the number of bits in EffectKey available to GenKey
    1.52 +        kEffectKeyBits = GrBackendEffectFactory::kEffectKeyBits,
    1.53 +    };
    1.54 +
    1.55 +    GrGLEffect(const GrBackendEffectFactory& factory)
    1.56 +        : fFactory(factory)
    1.57 +        , fIsVertexEffect(false) {
    1.58 +    }
    1.59 +
    1.60 +    virtual ~GrGLEffect() {}
    1.61 +
    1.62 +    /** Called when the program stage should insert its code into the shaders. The code in each
    1.63 +        shader will be in its own block ({}) and so locally scoped names will not collide across
    1.64 +        stages.
    1.65 +
    1.66 +        @param builder      Interface used to emit code in the shaders.
    1.67 +        @param drawEffect   A wrapper on the effect that generated this program stage.
    1.68 +        @param key          The key that was computed by GenKey() from the generating GrEffect.
    1.69 +                            Only the bits indicated by GrBackendEffectFactory::kEffectKeyBits are
    1.70 +                            guaranteed to match the value produced by GenKey();
    1.71 +        @param outputColor  A predefined vec4 in the FS in which the stage should place its output
    1.72 +                            color (or coverage).
    1.73 +        @param inputColor   A vec4 that holds the input color to the stage in the FS. This may be
    1.74 +                            NULL in which case the implied input is solid white (all ones).
    1.75 +                            TODO: Better system for communicating optimization info (e.g. input
    1.76 +                            color is solid white, trans black, known to be opaque, etc.) that allows
    1.77 +                            the effect to communicate back similar known info about its output.
    1.78 +        @param samplers     One entry for each GrTextureAccess of the GrEffect that generated the
    1.79 +                            GrGLEffect. These can be passed to the builder to emit texture
    1.80 +                            reads in the generated code.
    1.81 +        */
    1.82 +    virtual void emitCode(GrGLShaderBuilder* builder,
    1.83 +                          const GrDrawEffect& drawEffect,
    1.84 +                          EffectKey key,
    1.85 +                          const char* outputColor,
    1.86 +                          const char* inputColor,
    1.87 +                          const TransformedCoordsArray& coords,
    1.88 +                          const TextureSamplerArray& samplers) = 0;
    1.89 +
    1.90 +    /** A GrGLEffect instance can be reused with any GrEffect that produces the same stage
    1.91 +        key; this function reads data from a stage and uploads any uniform variables required
    1.92 +        by the shaders created in emitCode(). The GrEffect installed in the GrEffectStage is
    1.93 +        guaranteed to be of the same type that created this GrGLEffect and to have an identical
    1.94 +        EffectKey as the one that created this GrGLEffect. Effects that use local coords have
    1.95 +        to consider whether the GrEffectStage's coord change matrix should be used. When explicit
    1.96 +        local coordinates are used it can be ignored. */
    1.97 +    virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) {}
    1.98 +
    1.99 +    const char* name() const { return fFactory.name(); }
   1.100 +
   1.101 +    static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { return 0; }
   1.102 +
   1.103 +    /** Used by the system when generating shader code, to see if this effect can be downcasted to
   1.104 +        the internal GrGLVertexEffect type */
   1.105 +    bool isVertexEffect() const { return fIsVertexEffect; }
   1.106 +
   1.107 +protected:
   1.108 +    const GrBackendEffectFactory& fFactory;
   1.109 +
   1.110 +private:
   1.111 +    friend class GrGLVertexEffect; // to set fIsVertexEffect
   1.112 +
   1.113 +    bool fIsVertexEffect;
   1.114 +};
   1.115 +
   1.116 +#endif

mercurial