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 GrDebugGL_DEFINED 10 #define GrDebugGL_DEFINED 11 12 #include "SkTArray.h" 13 #include "gl/GrGLInterface.h" 14 15 class GrFakeRefObj; 16 class GrTextureUnitObj; 17 class GrBufferObj; 18 class GrTextureObj; 19 class GrFrameBufferObj; 20 class GrRenderBufferObj; 21 class GrProgramObj; 22 23 //////////////////////////////////////////////////////////////////////////////// 24 // This is the main debugging object. It is a singleton and keeps track of 25 // all the other debug objects. 26 class GrDebugGL { 27 public: 28 enum GrObjTypes { 29 kTexture_ObjTypes = 0, 30 kBuffer_ObjTypes, 31 kRenderBuffer_ObjTypes, 32 kFrameBuffer_ObjTypes, 33 kShader_ObjTypes, 34 kProgram_ObjTypes, 35 kTextureUnit_ObjTypes, 36 kObjTypeCount 37 }; 38 39 GrFakeRefObj *createObj(GrObjTypes type) { 40 GrFakeRefObj *temp = (*gFactoryFunc[type])(); 41 42 fObjects.push_back(temp); 43 44 return temp; 45 } 46 47 GrFakeRefObj *findObject(GrGLuint ID, GrObjTypes type); 48 49 GrGLuint getMaxTextureUnits() const { return kDefaultMaxTextureUnits; } 50 51 void setCurTextureUnit(GrGLuint curTextureUnit) { fCurTextureUnit = curTextureUnit; } 52 GrGLuint getCurTextureUnit() const { return fCurTextureUnit; } 53 54 GrTextureUnitObj *getTextureUnit(int iUnit) { 55 GrAlwaysAssert(0 <= iUnit && kDefaultMaxTextureUnits > iUnit); 56 57 return fTextureUnits[iUnit]; 58 } 59 60 void setArrayBuffer(GrBufferObj *arrayBuffer); 61 GrBufferObj *getArrayBuffer() { return fArrayBuffer; } 62 63 void setElementArrayBuffer(GrBufferObj *elementArrayBuffer); 64 GrBufferObj *getElementArrayBuffer() { return fElementArrayBuffer; } 65 66 void setTexture(GrTextureObj *texture); 67 68 void setFrameBuffer(GrFrameBufferObj *frameBuffer); 69 GrFrameBufferObj *getFrameBuffer() { return fFrameBuffer; } 70 71 void setRenderBuffer(GrRenderBufferObj *renderBuffer); 72 GrRenderBufferObj *getRenderBuffer() { return fRenderBuffer; } 73 74 void useProgram(GrProgramObj *program); 75 76 void setPackRowLength(GrGLint packRowLength) { 77 fPackRowLength = packRowLength; 78 } 79 GrGLint getPackRowLength() const { return fPackRowLength; } 80 81 void setUnPackRowLength(GrGLint unPackRowLength) { 82 fUnPackRowLength = unPackRowLength; 83 } 84 GrGLint getUnPackRowLength() const { return fUnPackRowLength; } 85 86 static GrDebugGL *getInstance() { 87 // someone should admit to actually using this class 88 GrAssert(0 < gStaticRefCount); 89 90 if (NULL == gObj) { 91 gObj = SkNEW(GrDebugGL); 92 } 93 94 return gObj; 95 } 96 97 void report() const; 98 99 static void staticRef() { 100 gStaticRefCount++; 101 } 102 103 static void staticUnRef() { 104 GrAssert(gStaticRefCount > 0); 105 gStaticRefCount--; 106 if (0 == gStaticRefCount) { 107 SkDELETE(gObj); 108 gObj = NULL; 109 } 110 } 111 112 protected: 113 114 private: 115 // the OpenGLES 2.0 spec says this must be >= 2 116 static const GrGLint kDefaultMaxTextureUnits = 8; 117 118 GrGLint fPackRowLength; 119 GrGLint fUnPackRowLength; 120 GrGLuint fMaxTextureUnits; 121 GrGLuint fCurTextureUnit; 122 GrBufferObj * fArrayBuffer; 123 GrBufferObj * fElementArrayBuffer; 124 GrFrameBufferObj *fFrameBuffer; 125 GrRenderBufferObj *fRenderBuffer; 126 GrProgramObj * fProgram; 127 GrTextureObj * fTexture; 128 GrTextureUnitObj *fTextureUnits[kDefaultMaxTextureUnits]; 129 130 typedef GrFakeRefObj *(*Create)(); 131 132 static Create gFactoryFunc[kObjTypeCount]; 133 134 static GrDebugGL* gObj; 135 static int gStaticRefCount; 136 137 // global store of all objects 138 SkTArray<GrFakeRefObj *> fObjects; 139 140 GrDebugGL(); 141 ~GrDebugGL(); 142 }; 143 144 //////////////////////////////////////////////////////////////////////////////// 145 // Helper macro to make creating an object (where you need to get back a derived 146 // type) easier 147 #define GR_CREATE(className, classEnum) \ 148 reinterpret_cast<className *>(GrDebugGL::getInstance()->createObj(classEnum)) 149 150 //////////////////////////////////////////////////////////////////////////////// 151 // Helper macro to make finding objects less painful 152 #define GR_FIND(id, className, classEnum) \ 153 reinterpret_cast<className *>(GrDebugGL::getInstance()->findObject(id, classEnum)) 154 155 #endif // GrDebugGL_DEFINED 156