blob: 5aeb36dc65b5eaa9fa665ce3f6dbc079c76b8e20 [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef GrGLRenderTarget_DEFINED
11#define GrGLRenderTarget_DEFINED
12
13#include "GrGLIRect.h"
14#include "GrRenderTarget.h"
15#include "GrScalar.h"
16
17class GrGpuGL;
18class GrGLTexture;
19class GrGLTexID;
20
21class GrGLRenderTarget : public GrRenderTarget {
22
23public:
24 // set fTexFBOID to this value to indicate that it is multisampled but
25 // Gr doesn't know how to resolve it.
26 enum { kUnresolvableFBOID = 0 };
27
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000028 struct Desc {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000029 GrGLuint fRTFBOID;
30 GrGLuint fTexFBOID;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000031 GrGLuint fMSColorRenderbufferID;
32 bool fOwnIDs;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000033 GrPixelConfig fConfig;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000034 int fSampleCnt;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000035 };
36
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000037 // creates a GrGLRenderTarget associated with a texture
38 GrGLRenderTarget(GrGpuGL* gpu,
39 const Desc& desc,
40 const GrGLIRect& viewport,
41 GrGLTexID* texID,
42 GrGLTexture* texture);
43
44 // creates an independent GrGLRenderTarget
45 GrGLRenderTarget(GrGpuGL* gpu,
46 const Desc& desc,
47 const GrGLIRect& viewport);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000048
49 virtual ~GrGLRenderTarget() { this->release(); }
50
51 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
52 const GrGLIRect& getViewport() const { return fViewport; }
53
54 // The following two functions return the same ID when a
55 // texture-rendertarget is multisampled, and different IDs when
56 // it is.
57 // FBO ID used to render into
58 GrGLuint renderFBOID() const { return fRTFBOID; }
59 // FBO ID that has texture ID attached.
60 GrGLuint textureFBOID() const { return fTexFBOID; }
61
62 // override of GrRenderTarget
63 virtual intptr_t getRenderTargetHandle() const {
64 return this->renderFBOID();
65 }
66 virtual intptr_t getRenderTargetResolvedHandle() const {
67 return this->textureFBOID();
68 }
69 virtual ResolveType getResolveType() const {
70 if (fRTFBOID == fTexFBOID) {
71 // catches FBO 0 and non MSAA case
72 return kAutoResolves_ResolveType;
73 } else if (kUnresolvableFBOID == fTexFBOID) {
74 return kCantResolve_ResolveType;
75 } else {
76 return kCanResolve_ResolveType;
77 }
78 }
79
80protected:
81 // override of GrResource
82 virtual void onAbandon();
83 virtual void onRelease();
84
85private:
86 GrGLuint fRTFBOID;
87 GrGLuint fTexFBOID;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000088
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000089 GrGLuint fMSColorRenderbufferID;
90
91 // Should this object delete IDs when it is destroyed or does someone
92 // else own them.
93 bool fOwnIDs;
94
95 // when we switch to this rendertarget we want to set the viewport to
96 // only render to to content area (as opposed to the whole allocation) and
97 // we want the rendering to be at top left (GL has origin in bottom left)
98 GrGLIRect fViewport;
99
100 // non-NULL if this RT was created by Gr with an associated GrGLTexture.
101 GrGLTexID* fTexIDObj;
102
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000103 void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID);
104
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000105 typedef GrRenderTarget INHERITED;
106};
107
108#endif