michael@0: michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrDebugGL_DEFINED michael@0: #define GrDebugGL_DEFINED michael@0: michael@0: #include "SkTArray.h" michael@0: #include "gl/GrGLInterface.h" michael@0: michael@0: class GrBufferObj; michael@0: class GrFakeRefObj; michael@0: class GrFrameBufferObj; michael@0: class GrProgramObj; michael@0: class GrRenderBufferObj; michael@0: class GrTextureObj; michael@0: class GrTextureUnitObj; michael@0: class GrVertexArrayObj; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // This is the main debugging object. It is a singleton and keeps track of michael@0: // all the other debug objects. michael@0: class GrDebugGL { michael@0: public: michael@0: enum GrObjTypes { michael@0: kTexture_ObjTypes = 0, michael@0: kBuffer_ObjTypes, michael@0: kRenderBuffer_ObjTypes, michael@0: kFrameBuffer_ObjTypes, michael@0: kShader_ObjTypes, michael@0: kProgram_ObjTypes, michael@0: kTextureUnit_ObjTypes, michael@0: kVertexArray_ObjTypes, michael@0: kObjTypeCount michael@0: }; michael@0: michael@0: GrFakeRefObj *createObj(GrObjTypes type) { michael@0: GrFakeRefObj *temp = (*gFactoryFunc[type])(); michael@0: michael@0: fObjects.push_back(temp); michael@0: michael@0: return temp; michael@0: } michael@0: michael@0: GrFakeRefObj *findObject(GrGLuint ID, GrObjTypes type); michael@0: michael@0: GrGLuint getMaxTextureUnits() const { return kDefaultMaxTextureUnits; } michael@0: michael@0: void setCurTextureUnit(GrGLuint curTextureUnit) { fCurTextureUnit = curTextureUnit; } michael@0: GrGLuint getCurTextureUnit() const { return fCurTextureUnit; } michael@0: michael@0: GrTextureUnitObj *getTextureUnit(int iUnit) { michael@0: GrAlwaysAssert(0 <= iUnit && kDefaultMaxTextureUnits > iUnit); michael@0: michael@0: return fTextureUnits[iUnit]; michael@0: } michael@0: michael@0: void setArrayBuffer(GrBufferObj *arrayBuffer); michael@0: GrBufferObj *getArrayBuffer() { return fArrayBuffer; } michael@0: michael@0: void setElementArrayBuffer(GrBufferObj *elementArrayBuffer); michael@0: GrBufferObj *getElementArrayBuffer() { return fElementArrayBuffer; } michael@0: michael@0: void setVertexArray(GrVertexArrayObj* vertexArray); michael@0: GrVertexArrayObj* getVertexArray() { return fVertexArray; } michael@0: michael@0: void setTexture(GrTextureObj *texture); michael@0: michael@0: void setFrameBuffer(GrFrameBufferObj *frameBuffer); michael@0: GrFrameBufferObj *getFrameBuffer() { return fFrameBuffer; } michael@0: michael@0: void setRenderBuffer(GrRenderBufferObj *renderBuffer); michael@0: GrRenderBufferObj *getRenderBuffer() { return fRenderBuffer; } michael@0: michael@0: void useProgram(GrProgramObj *program); michael@0: michael@0: void setPackRowLength(GrGLint packRowLength) { michael@0: fPackRowLength = packRowLength; michael@0: } michael@0: GrGLint getPackRowLength() const { return fPackRowLength; } michael@0: michael@0: void setUnPackRowLength(GrGLint unPackRowLength) { michael@0: fUnPackRowLength = unPackRowLength; michael@0: } michael@0: GrGLint getUnPackRowLength() const { return fUnPackRowLength; } michael@0: michael@0: static GrDebugGL *getInstance() { michael@0: // someone should admit to actually using this class michael@0: SkASSERT(0 < gStaticRefCount); michael@0: michael@0: if (NULL == gObj) { michael@0: gObj = SkNEW(GrDebugGL); michael@0: } michael@0: michael@0: return gObj; michael@0: } michael@0: michael@0: void report() const; michael@0: michael@0: static void staticRef() { michael@0: gStaticRefCount++; michael@0: } michael@0: michael@0: static void staticUnRef() { michael@0: SkASSERT(gStaticRefCount > 0); michael@0: gStaticRefCount--; michael@0: if (0 == gStaticRefCount) { michael@0: SkDELETE(gObj); michael@0: gObj = NULL; michael@0: } michael@0: } michael@0: michael@0: protected: michael@0: michael@0: private: michael@0: // the OpenGLES 2.0 spec says this must be >= 2 michael@0: static const GrGLint kDefaultMaxTextureUnits = 8; michael@0: michael@0: GrGLint fPackRowLength; michael@0: GrGLint fUnPackRowLength; michael@0: GrGLuint fCurTextureUnit; michael@0: GrBufferObj* fArrayBuffer; michael@0: GrBufferObj* fElementArrayBuffer; michael@0: GrFrameBufferObj* fFrameBuffer; michael@0: GrRenderBufferObj* fRenderBuffer; michael@0: GrProgramObj* fProgram; michael@0: GrTextureObj* fTexture; michael@0: GrTextureUnitObj *fTextureUnits[kDefaultMaxTextureUnits]; michael@0: GrVertexArrayObj *fVertexArray; michael@0: michael@0: typedef GrFakeRefObj *(*Create)(); michael@0: michael@0: static Create gFactoryFunc[kObjTypeCount]; michael@0: michael@0: static GrDebugGL* gObj; michael@0: static int gStaticRefCount; michael@0: michael@0: // global store of all objects michael@0: SkTArray fObjects; michael@0: michael@0: GrDebugGL(); michael@0: ~GrDebugGL(); michael@0: }; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Helper macro to make creating an object (where you need to get back a derived michael@0: // type) easier michael@0: #define GR_CREATE(className, classEnum) \ michael@0: reinterpret_cast(GrDebugGL::getInstance()->createObj(classEnum)) michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Helper macro to make finding objects less painful michael@0: #define GR_FIND(id, className, classEnum) \ michael@0: reinterpret_cast(GrDebugGL::getInstance()->findObject(id, classEnum)) michael@0: michael@0: #endif // GrDebugGL_DEFINED