blob: 908b10d6ec19491a9ecc2cd96e8a56e86afaaa69 [file] [log] [blame]
tomhudson@google.com168e6342012-04-18 17:49:20 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrCustomStage_DEFINED
9#define GrCustomStage_DEFINED
10
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000011#include "GrRefCnt.h"
bsalomon@google.comae4f96a2012-05-18 19:54:48 +000012#include "GrNoncopyable.h"
13#include "GrProgramStageFactory.h"
14#include "SkTemplates.h"
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000015
tomhudson@google.com168e6342012-04-18 17:49:20 +000016class GrContext;
tomhudson@google.com168e6342012-04-18 17:49:20 +000017
18/** Provides custom vertex shader, fragment shader, uniform data for a
bsalomon@google.comae4f96a2012-05-18 19:54:48 +000019 particular stage of the Ganesh shading pipeline. */
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000020class GrCustomStage : public GrRefCnt {
tomhudson@google.com168e6342012-04-18 17:49:20 +000021
22public:
bsalomon@google.comae4f96a2012-05-18 19:54:48 +000023 typedef GrProgramStageFactory::StageKey StageKey;
tomhudson@google.com168e6342012-04-18 17:49:20 +000024
25 GrCustomStage();
26 virtual ~GrCustomStage();
27
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000028 /** Human-meaningful string to identify this effect; may be embedded
29 in generated shader code. */
30 virtual const char* name() const = 0;
31
tomhudson@google.com168e6342012-04-18 17:49:20 +000032 /** If given an input texture that is/is not opaque, is this
33 stage guaranteed to produce an opaque output? */
34 virtual bool isOpaque(bool inputTextureIsOpaque) const;
35
bsalomon@google.comae4f96a2012-05-18 19:54:48 +000036 /** This object, besides creating back-end-specific helper
37 objects, is used for run-time-type-identification. The factory should be
38 an instance of templated class, GrTProgramStageFactory. It is templated
39 on the subclass of GrCustomStage. The subclass must have a nested type
40 (or typedef) named GLProgramStage which will be the subclass of
41 GrGLProgramStage created by the factory.
42
43 Example:
44 class MyCustomStage : public GrCustomStage {
45 ...
46 virtual const GrProgramStageFactory& getFactory() const
47 SK_OVERRIDE {
48 return GrTProgramStageFactory<MyCustomStage>::getInstance();
49 }
50 ...
51 };
52 */
53 virtual const GrProgramStageFactory& getFactory() const = 0;
tomhudson@google.comb88bbd22012-05-01 12:48:07 +000054
55 /** Returns true if the other custom stage will generate
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000056 equal output.
57 Must only be called if the two are already known to be of the
58 same type (i.e. they return the same value from getFactory()).
59 For equivalence (that they will generate the same
60 shader, but perhaps have different uniforms), check equality
61 of the stageKey produced by the GrProgramStageFactory. */
62 virtual bool isEqual(const GrCustomStage *) const = 0;
tomhudson@google.com168e6342012-04-18 17:49:20 +000063
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000064private:
65
66 typedef GrRefCnt INHERITED;
tomhudson@google.com168e6342012-04-18 17:49:20 +000067};
68
69#endif