bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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 "GrScalar.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 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 27 | struct Desc { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 28 | GrGLuint fRTFBOID; |
| 29 | GrGLuint fTexFBOID; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 30 | GrGLuint fMSColorRenderbufferID; |
| 31 | bool fOwnIDs; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 32 | GrPixelConfig fConfig; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 33 | int fSampleCnt; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 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); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 47 | |
| 48 | virtual ~GrGLRenderTarget() { this->release(); } |
| 49 | |
| 50 | void setViewport(const GrGLIRect& rect) { fViewport = rect; } |
| 51 | const GrGLIRect& getViewport() const { return fViewport; } |
| 52 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 53 | // The following two functions return the same ID when a |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 54 | // texture-rendertarget is multisampled, and different IDs when |
| 55 | // it is. |
| 56 | // FBO ID used to render into |
| 57 | GrGLuint renderFBOID() const { return fRTFBOID; } |
| 58 | // FBO ID that has texture ID attached. |
| 59 | GrGLuint textureFBOID() const { return fTexFBOID; } |
| 60 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 61 | // override of GrRenderTarget |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame^] | 62 | virtual GrBackendObject getRenderTargetHandle() const { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 63 | return this->renderFBOID(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 64 | } |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame^] | 65 | virtual GrBackendObject getRenderTargetResolvedHandle() const { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 66 | return this->textureFBOID(); |
| 67 | } |
| 68 | virtual ResolveType getResolveType() const { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 69 | |
| 70 | if (!this->isMultisampled() || |
| 71 | fRTFBOID == fTexFBOID) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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 |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 83 | virtual void onAbandon() SK_OVERRIDE; |
| 84 | virtual void onRelease() SK_OVERRIDE; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 85 | |
| 86 | private: |
| 87 | GrGLuint fRTFBOID; |
| 88 | GrGLuint fTexFBOID; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 89 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 90 | GrGLuint fMSColorRenderbufferID; |
| 91 | |
| 92 | // Should this object delete IDs when it is destroyed or does someone |
| 93 | // else own them. |
| 94 | bool fOwnIDs; |
| 95 | |
| 96 | // when we switch to this rendertarget we want to set the viewport to |
| 97 | // only render to to content area (as opposed to the whole allocation) and |
| 98 | // we want the rendering to be at top left (GL has origin in bottom left) |
| 99 | GrGLIRect fViewport; |
| 100 | |
| 101 | // non-NULL if this RT was created by Gr with an associated GrGLTexture. |
| 102 | GrGLTexID* fTexIDObj; |
| 103 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 104 | void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID); |
| 105 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 106 | typedef GrRenderTarget INHERITED; |
| 107 | }; |
| 108 | |
| 109 | #endif |