blob: 48ff12d90b86b5f68db2700871eb427febcdb44f [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
28 struct GLRenderTargetIDs {
29 GrGLuint fRTFBOID;
30 GrGLuint fTexFBOID;
31 GrGLuint fStencilRenderbufferID;
32 GrGLuint fMSColorRenderbufferID;
33 bool fOwnIDs;
34 void reset() { memset(this, 0, sizeof(GLRenderTargetIDs)); }
35 };
36
37 GrGLRenderTarget(GrGpuGL* gpu,
38 const GLRenderTargetIDs& ids,
39 GrGLTexID* texID,
40 GrPixelConfig config,
41 GrGLuint stencilBits,
42 bool isMultisampled,
43 const GrGLIRect& fViewport,
44 GrGLTexture* texture);
45
46 virtual ~GrGLRenderTarget() { this->release(); }
47
48 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
49 const GrGLIRect& getViewport() const { return fViewport; }
50
51 // The following two functions return the same ID when a
52 // texture-rendertarget is multisampled, and different IDs when
53 // it is.
54 // FBO ID used to render into
55 GrGLuint renderFBOID() const { return fRTFBOID; }
56 // FBO ID that has texture ID attached.
57 GrGLuint textureFBOID() const { return fTexFBOID; }
58
59 // override of GrRenderTarget
60 virtual intptr_t getRenderTargetHandle() const {
61 return this->renderFBOID();
62 }
63 virtual intptr_t getRenderTargetResolvedHandle() const {
64 return this->textureFBOID();
65 }
66 virtual ResolveType getResolveType() const {
67 if (fRTFBOID == fTexFBOID) {
68 // catches FBO 0 and non MSAA case
69 return kAutoResolves_ResolveType;
70 } else if (kUnresolvableFBOID == fTexFBOID) {
71 return kCantResolve_ResolveType;
72 } else {
73 return kCanResolve_ResolveType;
74 }
75 }
76
77protected:
78 // override of GrResource
79 virtual void onAbandon();
80 virtual void onRelease();
81
82private:
83 GrGLuint fRTFBOID;
84 GrGLuint fTexFBOID;
85 GrGLuint fStencilRenderbufferID;
86 GrGLuint fMSColorRenderbufferID;
87
88 // Should this object delete IDs when it is destroyed or does someone
89 // else own them.
90 bool fOwnIDs;
91
92 // when we switch to this rendertarget 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 typedef GrRenderTarget INHERITED;
101};
102
103#endif