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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2012 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef GrGLEffect_DEFINED
michael@0 9 #define GrGLEffect_DEFINED
michael@0 10
michael@0 11 #include "GrBackendEffectFactory.h"
michael@0 12 #include "GrGLProgramEffects.h"
michael@0 13 #include "GrGLShaderBuilder.h"
michael@0 14 #include "GrGLShaderVar.h"
michael@0 15 #include "GrGLSL.h"
michael@0 16
michael@0 17 /** @file
michael@0 18 This file contains specializations for OpenGL of the shader stages declared in
michael@0 19 include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitting the
michael@0 20 GLSL code that implements a GrEffect and for uploading uniforms at draw time. If they don't
michael@0 21 always emit the same GLSL code, they must have a function:
michael@0 22 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&)
michael@0 23 that is used to implement a program cache. When two GrEffects produce the same key this means
michael@0 24 that their GrGLEffects would emit the same GLSL code.
michael@0 25
michael@0 26 The GrGLEffect subclass must also have a constructor of the form:
michael@0 27 EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrDrawEffect&)
michael@0 28 The effect held by the GrDrawEffect is guaranteed to be of the type that generated the
michael@0 29 GrGLEffect subclass instance.
michael@0 30
michael@0 31 These objects are created by the factory object returned by the GrEffect::getFactory().
michael@0 32 */
michael@0 33
michael@0 34 class GrDrawEffect;
michael@0 35 class GrGLTexture;
michael@0 36 class GrGLVertexEffect;
michael@0 37
michael@0 38 class GrGLEffect {
michael@0 39
michael@0 40 public:
michael@0 41 typedef GrBackendEffectFactory::EffectKey EffectKey;
michael@0 42 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
michael@0 43 typedef GrGLProgramEffects::TextureSampler TextureSampler;
michael@0 44 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray;
michael@0 45
michael@0 46 enum {
michael@0 47 kNoEffectKey = GrBackendEffectFactory::kNoEffectKey,
michael@0 48 // the number of bits in EffectKey available to GenKey
michael@0 49 kEffectKeyBits = GrBackendEffectFactory::kEffectKeyBits,
michael@0 50 };
michael@0 51
michael@0 52 GrGLEffect(const GrBackendEffectFactory& factory)
michael@0 53 : fFactory(factory)
michael@0 54 , fIsVertexEffect(false) {
michael@0 55 }
michael@0 56
michael@0 57 virtual ~GrGLEffect() {}
michael@0 58
michael@0 59 /** Called when the program stage should insert its code into the shaders. The code in each
michael@0 60 shader will be in its own block ({}) and so locally scoped names will not collide across
michael@0 61 stages.
michael@0 62
michael@0 63 @param builder Interface used to emit code in the shaders.
michael@0 64 @param drawEffect A wrapper on the effect that generated this program stage.
michael@0 65 @param key The key that was computed by GenKey() from the generating GrEffect.
michael@0 66 Only the bits indicated by GrBackendEffectFactory::kEffectKeyBits are
michael@0 67 guaranteed to match the value produced by GenKey();
michael@0 68 @param outputColor A predefined vec4 in the FS in which the stage should place its output
michael@0 69 color (or coverage).
michael@0 70 @param inputColor A vec4 that holds the input color to the stage in the FS. This may be
michael@0 71 NULL in which case the implied input is solid white (all ones).
michael@0 72 TODO: Better system for communicating optimization info (e.g. input
michael@0 73 color is solid white, trans black, known to be opaque, etc.) that allows
michael@0 74 the effect to communicate back similar known info about its output.
michael@0 75 @param samplers One entry for each GrTextureAccess of the GrEffect that generated the
michael@0 76 GrGLEffect. These can be passed to the builder to emit texture
michael@0 77 reads in the generated code.
michael@0 78 */
michael@0 79 virtual void emitCode(GrGLShaderBuilder* builder,
michael@0 80 const GrDrawEffect& drawEffect,
michael@0 81 EffectKey key,
michael@0 82 const char* outputColor,
michael@0 83 const char* inputColor,
michael@0 84 const TransformedCoordsArray& coords,
michael@0 85 const TextureSamplerArray& samplers) = 0;
michael@0 86
michael@0 87 /** A GrGLEffect instance can be reused with any GrEffect that produces the same stage
michael@0 88 key; this function reads data from a stage and uploads any uniform variables required
michael@0 89 by the shaders created in emitCode(). The GrEffect installed in the GrEffectStage is
michael@0 90 guaranteed to be of the same type that created this GrGLEffect and to have an identical
michael@0 91 EffectKey as the one that created this GrGLEffect. Effects that use local coords have
michael@0 92 to consider whether the GrEffectStage's coord change matrix should be used. When explicit
michael@0 93 local coordinates are used it can be ignored. */
michael@0 94 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) {}
michael@0 95
michael@0 96 const char* name() const { return fFactory.name(); }
michael@0 97
michael@0 98 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { return 0; }
michael@0 99
michael@0 100 /** Used by the system when generating shader code, to see if this effect can be downcasted to
michael@0 101 the internal GrGLVertexEffect type */
michael@0 102 bool isVertexEffect() const { return fIsVertexEffect; }
michael@0 103
michael@0 104 protected:
michael@0 105 const GrBackendEffectFactory& fFactory;
michael@0 106
michael@0 107 private:
michael@0 108 friend class GrGLVertexEffect; // to set fIsVertexEffect
michael@0 109
michael@0 110 bool fIsVertexEffect;
michael@0 111 };
michael@0 112
michael@0 113 #endif

mercurial