Home | History | Annotate | Download | only in gl
      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 "SkScalar.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 
     27     struct Desc {
     28         GrGLuint         fRTFBOID;
     29         GrGLuint         fTexFBOID;
     30         GrGLuint         fMSColorRenderbufferID;
     31         bool             fIsWrapped;
     32         GrPixelConfig    fConfig;
     33         int              fSampleCnt;
     34         GrSurfaceOrigin  fOrigin;
     35         bool             fCheckAllocation;
     36     };
     37 
     38     // creates a GrGLRenderTarget associated with a texture
     39     GrGLRenderTarget(GrGpuGL*          gpu,
     40                      const Desc&       desc,
     41                      const GrGLIRect&  viewport,
     42                      GrGLTexID*        texID,
     43                      GrGLTexture*      texture);
     44 
     45     // creates an independent GrGLRenderTarget
     46     GrGLRenderTarget(GrGpuGL*          gpu,
     47                      const Desc&       desc,
     48                      const GrGLIRect&  viewport);
     49 
     50     virtual ~GrGLRenderTarget() { this->release(); }
     51 
     52     void setViewport(const GrGLIRect& rect) { fViewport = rect; }
     53     const GrGLIRect& getViewport() const { return fViewport; }
     54 
     55     // The following two functions return the same ID when a
     56     // texture/render target is multisampled, and different IDs when
     57     // it is.
     58     // FBO ID used to render into
     59     GrGLuint renderFBOID() const { return fRTFBOID; }
     60     // FBO ID that has texture ID attached.
     61     GrGLuint textureFBOID() const { return fTexFBOID; }
     62 
     63     // override of GrRenderTarget
     64     virtual GrBackendObject getRenderTargetHandle() const {
     65         return this->renderFBOID();
     66     }
     67     virtual GrBackendObject getRenderTargetResolvedHandle() const {
     68         return this->textureFBOID();
     69     }
     70     virtual ResolveType getResolveType() const {
     71 
     72         if (!this->isMultisampled() ||
     73             fRTFBOID == fTexFBOID) {
     74             // catches FBO 0 and non MSAA case
     75             return kAutoResolves_ResolveType;
     76         } else if (kUnresolvableFBOID == fTexFBOID) {
     77             return kCantResolve_ResolveType;
     78         } else {
     79             return kCanResolve_ResolveType;
     80         }
     81     }
     82 
     83 protected:
     84     // override of GrResource
     85     virtual void onAbandon() SK_OVERRIDE;
     86     virtual void onRelease() SK_OVERRIDE;
     87 
     88 private:
     89     GrGLuint      fRTFBOID;
     90     GrGLuint      fTexFBOID;
     91 
     92     GrGLuint      fMSColorRenderbufferID;
     93 
     94     // when we switch to this render target we want to set the viewport to
     95     // only render to to content area (as opposed to the whole allocation) and
     96     // we want the rendering to be at top left (GL has origin in bottom left)
     97     GrGLIRect fViewport;
     98 
     99     // non-NULL if this RT was created by Gr with an associated GrGLTexture.
    100     SkAutoTUnref<GrGLTexID> fTexIDObj;
    101 
    102     void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID);
    103 
    104     typedef GrRenderTarget INHERITED;
    105 };
    106 
    107 #endif
    108