blob: 5eea9f49290d3d1073867be621b847f549031c45 [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"
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000014
tomhudson@google.com168e6342012-04-18 17:49:20 +000015class GrContext;
tomhudson@google.com168e6342012-04-18 17:49:20 +000016
17/** Provides custom vertex shader, fragment shader, uniform data for a
bsalomon@google.com289efe02012-05-21 20:57:59 +000018 particular stage of the Ganesh shading pipeline.
19 Subclasses must have a function that produces a human-readable name:
20 static const char* Name();
21 */
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000022class GrCustomStage : public GrRefCnt {
tomhudson@google.com168e6342012-04-18 17:49:20 +000023
24public:
bsalomon@google.comae4f96a2012-05-18 19:54:48 +000025 typedef GrProgramStageFactory::StageKey StageKey;
tomhudson@google.com168e6342012-04-18 17:49:20 +000026
27 GrCustomStage();
28 virtual ~GrCustomStage();
29
30 /** If given an input texture that is/is not opaque, is this
31 stage guaranteed to produce an opaque output? */
32 virtual bool isOpaque(bool inputTextureIsOpaque) const;
33
bsalomon@google.comae4f96a2012-05-18 19:54:48 +000034 /** This object, besides creating back-end-specific helper
35 objects, is used for run-time-type-identification. The factory should be
36 an instance of templated class, GrTProgramStageFactory. It is templated
37 on the subclass of GrCustomStage. The subclass must have a nested type
38 (or typedef) named GLProgramStage which will be the subclass of
39 GrGLProgramStage created by the factory.
40
41 Example:
42 class MyCustomStage : public GrCustomStage {
43 ...
44 virtual const GrProgramStageFactory& getFactory() const
45 SK_OVERRIDE {
46 return GrTProgramStageFactory<MyCustomStage>::getInstance();
47 }
48 ...
49 };
50 */
51 virtual const GrProgramStageFactory& getFactory() const = 0;
tomhudson@google.comb88bbd22012-05-01 12:48:07 +000052
53 /** Returns true if the other custom stage will generate
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000054 equal output.
55 Must only be called if the two are already known to be of the
56 same type (i.e. they return the same value from getFactory()).
57 For equivalence (that they will generate the same
58 shader, but perhaps have different uniforms), check equality
59 of the stageKey produced by the GrProgramStageFactory. */
bsalomon@google.comb505a122012-05-31 18:40:36 +000060 virtual bool isEqual(const GrCustomStage&) const = 0;
tomhudson@google.com168e6342012-04-18 17:49:20 +000061
bsalomon@google.com4196c0e2012-05-29 19:44:14 +000062 /** Human-meaningful string to identify this effect; may be embedded
bsalomon@google.com289efe02012-05-21 20:57:59 +000063 in generated shader code. */
64 const char* name() const { return this->getFactory().name(); }
65
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000066private:
67
68 typedef GrRefCnt INHERITED;
tomhudson@google.com168e6342012-04-18 17:49:20 +000069};
70
71#endif