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" |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 14 | #include "SkScalar.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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 { |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame^] | 28 | GrGLuint fRTFBOID; |
| 29 | GrGLuint fTexFBOID; |
| 30 | GrGLuint fMSColorRenderbufferID; |
| 31 | bool fIsWrapped; |
| 32 | GrPixelConfig fConfig; |
| 33 | int fSampleCnt; |
| 34 | GrSurfaceOrigin fOrigin; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 37 | // 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.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 48 | |
| 49 | virtual ~GrGLRenderTarget() { this->release(); } |
| 50 | |
| 51 | void setViewport(const GrGLIRect& rect) { fViewport = rect; } |
| 52 | const GrGLIRect& getViewport() const { return fViewport; } |
| 53 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 54 | // The following two functions return the same ID when a |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 55 | // texture/render target is multisampled, and different IDs when |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 62 | // override of GrRenderTarget |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame] | 63 | virtual GrBackendObject getRenderTargetHandle() const { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 64 | return this->renderFBOID(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 65 | } |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame] | 66 | virtual GrBackendObject getRenderTargetResolvedHandle() const { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 67 | return this->textureFBOID(); |
| 68 | } |
| 69 | virtual ResolveType getResolveType() const { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 70 | |
| 71 | if (!this->isMultisampled() || |
| 72 | fRTFBOID == fTexFBOID) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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 | |
| 82 | protected: |
| 83 | // override of GrResource |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 84 | virtual void onAbandon() SK_OVERRIDE; |
| 85 | virtual void onRelease() SK_OVERRIDE; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | GrGLuint fRTFBOID; |
| 89 | GrGLuint fTexFBOID; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 90 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 91 | GrGLuint fMSColorRenderbufferID; |
| 92 | |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 93 | // when we switch to this render target we want to set the viewport to |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 94 | // only render to to content area (as opposed to the whole allocation) and |
| 95 | // we want the rendering to be at top left (GL has origin in bottom left) |
| 96 | GrGLIRect fViewport; |
| 97 | |
| 98 | // non-NULL if this RT was created by Gr with an associated GrGLTexture. |
| 99 | GrGLTexID* fTexIDObj; |
| 100 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 101 | void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID); |
| 102 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 103 | typedef GrRenderTarget INHERITED; |
| 104 | }; |
| 105 | |
| 106 | #endif |