1 2 /* 3 * Copyright 2012 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 #ifndef GrFBBindableObj_DEFINED 10 #define GrFBBindableObj_DEFINED 11 12 #include "SkTDArray.h" 13 #include "GrFakeRefObj.h" 14 15 //////////////////////////////////////////////////////////////////////////////// 16 // A common base class for render buffers and textures 17 class GrFBBindableObj : public GrFakeRefObj { 18 19 public: 20 GrFBBindableObj() 21 : GrFakeRefObj() { 22 } 23 24 virtual ~GrFBBindableObj() { 25 GrAlwaysAssert(0 == fColorReferees.count()); 26 GrAlwaysAssert(0 == fDepthReferees.count()); 27 GrAlwaysAssert(0 == fStencilReferees.count()); 28 } 29 30 void setColorBound(GrFakeRefObj *referee) { 31 fColorReferees.append(1, &referee); 32 } 33 void resetColorBound(GrFakeRefObj *referee) { 34 int index = fColorReferees.find(referee); 35 GrAlwaysAssert(0 <= index); 36 fColorReferees.removeShuffle(index); 37 } 38 bool getColorBound(GrFakeRefObj *referee) const { 39 int index = fColorReferees.find(referee); 40 return 0 <= index; 41 } 42 bool getColorBound() const { 43 return 0 != fColorReferees.count(); 44 } 45 46 void setDepthBound(GrFakeRefObj *referee) { 47 fDepthReferees.append(1, &referee); 48 } 49 void resetDepthBound(GrFakeRefObj *referee) { 50 int index = fDepthReferees.find(referee); 51 GrAlwaysAssert(0 <= index); 52 fDepthReferees.removeShuffle(index); 53 } 54 bool getDepthBound(GrFakeRefObj *referee) const { 55 int index = fDepthReferees.find(referee); 56 return 0 <= index; 57 } 58 bool getDepthBound() const { 59 return 0 != fDepthReferees.count(); 60 } 61 62 void setStencilBound(GrFakeRefObj *referee) { 63 fStencilReferees.append(1, &referee); 64 } 65 void resetStencilBound(GrFakeRefObj *referee) { 66 int index = fStencilReferees.find(referee); 67 GrAlwaysAssert(0 <= index); 68 fStencilReferees.removeShuffle(index); 69 } 70 bool getStencilBound(GrFakeRefObj *referee) const { 71 int index = fStencilReferees.find(referee); 72 return 0 <= index; 73 } 74 bool getStencilBound() const { 75 return 0 != fStencilReferees.count(); 76 } 77 78 79 protected: 80 private: 81 SkTDArray<GrFakeRefObj *> fColorReferees; // frame buffers that use this as a color buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D") 82 SkTDArray<GrFakeRefObj *> fDepthReferees; // frame buffers that use this as a depth buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D") 83 SkTDArray<GrFakeRefObj *> fStencilReferees; // frame buffers that use this as a stencil buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D") 84 85 typedef GrFakeRefObj INHERITED; 86 }; 87 88 #endif // GrFBBindableObj_DEFINED 89