blob: 3d64fabd37bbd3eab6afd08e553be4c6228fdc5f [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;
31 GrGLuint fStencilRenderbufferID;
32 GrGLuint fMSColorRenderbufferID;
33 bool fOwnIDs;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000034 GrPixelConfig fConfig;
35 int fStencilBits;
36 int fSampleCnt;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000037 };
38
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000039 // creates a GrGLRenderTarget associated with a texture
40 GrGLRenderTarget(GrGpuGL* gpu,
41 const Desc& desc,
42 const GrGLIRect& viewport,
43 GrGLTexID* texID,
44 GrGLTexture* texture);
45
46 // creates an independent GrGLRenderTarget
47 GrGLRenderTarget(GrGpuGL* gpu,
48 const Desc& desc,
49 const GrGLIRect& viewport);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000050
51 virtual ~GrGLRenderTarget() { this->release(); }
52
53 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
54 const GrGLIRect& getViewport() const { return fViewport; }
55
56 // The following two functions return the same ID when a
57 // texture-rendertarget is multisampled, and different IDs when
58 // it is.
59 // FBO ID used to render into
60 GrGLuint renderFBOID() const { return fRTFBOID; }
61 // FBO ID that has texture ID attached.
62 GrGLuint textureFBOID() const { return fTexFBOID; }
63
64 // override of GrRenderTarget
65 virtual intptr_t getRenderTargetHandle() const {
66 return this->renderFBOID();
67 }
68 virtual intptr_t getRenderTargetResolvedHandle() const {
69 return this->textureFBOID();
70 }
71 virtual ResolveType getResolveType() const {
72 if (fRTFBOID == fTexFBOID) {
73 // catches FBO 0 and non MSAA case
74 return kAutoResolves_ResolveType;
75 } else if (kUnresolvableFBOID == fTexFBOID) {
76 return kCantResolve_ResolveType;
77 } else {
78 return kCanResolve_ResolveType;
79 }
80 }
81
82protected:
83 // override of GrResource
84 virtual void onAbandon();
85 virtual void onRelease();
86
87private:
88 GrGLuint fRTFBOID;
89 GrGLuint fTexFBOID;
90 GrGLuint fStencilRenderbufferID;
91 GrGLuint fMSColorRenderbufferID;
92
93 // Should this object delete IDs when it is destroyed or does someone
94 // else own them.
95 bool fOwnIDs;
96
97 // when we switch to this rendertarget we want to set the viewport to
98 // only render to to content area (as opposed to the whole allocation) and
99 // we want the rendering to be at top left (GL has origin in bottom left)
100 GrGLIRect fViewport;
101
102 // non-NULL if this RT was created by Gr with an associated GrGLTexture.
103 GrGLTexID* fTexIDObj;
104
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000105 void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID);
106
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000107 typedef GrRenderTarget INHERITED;
108};
109
110#endif