• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 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 
9 #ifndef GrGLRenderTarget_DEFINED
10 #define GrGLRenderTarget_DEFINED
11 
12 #include "GrGLIRect.h"
13 #include "GrRenderTarget.h"
14 #include "SkScalar.h"
15 
16 class GrGpuGL;
17 class GrGLTexture;
18 class GrGLTexID;
19 
20 class GrGLRenderTarget : public GrRenderTarget {
21 
22 public:
23     // set fTexFBOID to this value to indicate that it is multisampled but
24     // Gr doesn't know how to resolve it.
25     enum { kUnresolvableFBOID = 0 };
26 
27     struct Desc {
28         GrGLuint      fRTFBOID;
29         GrGLuint      fTexFBOID;
30         GrGLuint      fMSColorRenderbufferID;
31         bool          fIsWrapped;
32         GrPixelConfig fConfig;
33         int           fSampleCnt;
34     };
35 
36     // creates a GrGLRenderTarget associated with a texture
37     GrGLRenderTarget(GrGpuGL*          gpu,
38                      const Desc&       desc,
39                      const GrGLIRect&  viewport,
40                      GrGLTexID*        texID,
41                      GrGLTexture*      texture);
42 
43     // creates an independent GrGLRenderTarget
44     GrGLRenderTarget(GrGpuGL*          gpu,
45                      const Desc&       desc,
46                      const GrGLIRect&  viewport);
47 
~GrGLRenderTarget()48     virtual ~GrGLRenderTarget() { this->release(); }
49 
setViewport(const GrGLIRect & rect)50     void setViewport(const GrGLIRect& rect) { fViewport = rect; }
getViewport()51     const GrGLIRect& getViewport() const { return fViewport; }
52 
53     // The following two functions return the same ID when a
54     // texture/render target is multisampled, and different IDs when
55     // it is.
56     // FBO ID used to render into
renderFBOID()57     GrGLuint renderFBOID() const { return fRTFBOID; }
58     // FBO ID that has texture ID attached.
textureFBOID()59     GrGLuint textureFBOID() const { return fTexFBOID; }
60 
61     // override of GrRenderTarget
getRenderTargetHandle()62     virtual GrBackendObject getRenderTargetHandle() const {
63         return this->renderFBOID();
64     }
getRenderTargetResolvedHandle()65     virtual GrBackendObject getRenderTargetResolvedHandle() const {
66         return this->textureFBOID();
67     }
getResolveType()68     virtual ResolveType getResolveType() const {
69 
70         if (!this->isMultisampled() ||
71             fRTFBOID == fTexFBOID) {
72             // catches FBO 0 and non MSAA case
73             return kAutoResolves_ResolveType;
74         } else if (kUnresolvableFBOID == fTexFBOID) {
75             return kCantResolve_ResolveType;
76         } else {
77             return kCanResolve_ResolveType;
78         }
79     }
80 
81 protected:
82     // override of GrResource
83     virtual void onAbandon() SK_OVERRIDE;
84     virtual void onRelease() SK_OVERRIDE;
85 
86 private:
87     GrGLuint      fRTFBOID;
88     GrGLuint      fTexFBOID;
89 
90     GrGLuint      fMSColorRenderbufferID;
91 
92     // when we switch to this render target we want to set the viewport to
93     // only render to to content area (as opposed to the whole allocation) and
94     // we want the rendering to be at top left (GL has origin in bottom left)
95     GrGLIRect fViewport;
96 
97     // non-NULL if this RT was created by Gr with an associated GrGLTexture.
98     GrGLTexID* fTexIDObj;
99 
100     void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID);
101 
102     typedef GrRenderTarget INHERITED;
103 };
104 
105 #endif
106