gfxGLDeviceProfiler.cpp
Engine/source/gfx/gl/gfxGLDeviceProfiler.cpp
Classes:
class
class
Public Functions
Detailed Description
Public Functions
initGLProfiler(GFXDevice::GFXDeviceEventType ev)
1 2#include "gui/core/guiCanvas.h" 3#include "console/engineAPI.h" 4#include "gfx/gfxDebugEvent.h" 5 6#include "gfx/gl/gfxGLDevice.h" 7 8#ifndef TORQUE_BASIC_GPU_PROFILER 9 //#define TORQUE_BASIC_GPU_PROFILER 10#endif 11 12class GLTimer 13{ 14public: 15 16 void begin() 17 { 18 glBeginQuery(GL_TIME_ELAPSED, mQueryId); 19 } 20 21 void end() 22 { 23 glEndQuery(GL_TIME_ELAPSED); 24 } 25 26 F64 getTime() 27 { 28 GLuint64 time; 29 glGetQueryObjectui64v(mQueryId, GL_QUERY_RESULT, &time); 30 return static_cast<F64>(time)/1000000.0f; 31 } 32 33 class Data 34 { 35 public: 36 37 Data() {} 38 39 void init() 40 { 41 42 } 43 44 void onBeginFrame() 45 { 46 47 } 48 49 void onEndFrame() 50 { 51 52 } 53 }; 54 55 typedef Data DataType; 56 57 GLTimer(GFXDevice *device, Data &data) : mName(NULL), mData(&data) 58 { 59 glGenQueries(1, &mQueryId); 60 } 61 62 GLTimer() : mName(NULL), mData(NULL), mQueryId(0) 63 { 64 65 } 66 67 GLTimer& operator=(const GLTimer &b) 68 { 69 mName = b.mName; 70 mQueryId = b.mQueryId; 71 return *this; 72 } 73 74 StringTableEntry mName; 75 76protected: 77 Data *mData; 78 GLuint mQueryId; 79 80}; 81 82 83#ifdef TORQUE_BASIC_GPU_PROFILER 84 85#include "gfx/gfxProfiler.h" 86 87 88GFXProfiler<GLTimer> gfxProfiler; 89 90DefineEngineFunction(printGFXGLTimers, void,(), ,"") 91{ 92 gfxProfiler.printTimes(); 93} 94 95#endif 96 97bool initGLProfiler(GFXDevice::GFXDeviceEventType ev) 98{ 99 if(ev != GFXDevice::deInit || GFX->getAdapterType() != OpenGL) 100 return true; 101 102 Con::evaluatef("GlobalActionMap.bindCmd(keyboard, \"alt F4\", \"printGFXGLTimers();\");"); 103 return true; 104} 105 106void GFXGLDevice::enterDebugEvent(ColorI color, const char *name) 107{ 108#ifdef TORQUE_BASIC_GPU_PROFILER 109 gfxProfiler.enterDebugEvent(color, name); 110#endif 111 112 if (mCapabilities.khrDebug) 113 { 114 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, name); 115 } 116 else if(mCapabilities.extDebugMarker) 117 { 118 glPushGroupMarkerEXT(0, name); 119 } 120} 121 122void GFXGLDevice::leaveDebugEvent() 123{ 124#ifdef TORQUE_BASIC_GPU_PROFILER 125 gfxProfiler.leaveDebugEvent(); 126#endif 127 128 if (mCapabilities.khrDebug) 129 { 130 glPopDebugGroup(); 131 } 132 else if(mCapabilities.extDebugMarker) 133 { 134 glPopGroupMarkerEXT(); 135 } 136} 137 138void GFXGLDevice::setDebugMarker(ColorI color, const char *name) 139{ 140 if (mCapabilities.khrDebug) 141 { 142 glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, 143 GL_DEBUG_SEVERITY_NOTIFICATION, -1, name); 144 } 145 else if(mCapabilities.extDebugMarker) 146 { 147 glInsertEventMarkerEXT(0, name); 148 } 149} 150 151#ifdef TORQUE_BASIC_GPU_PROFILER 152 153AFTER_MODULE_INIT(Sim) 154{ 155 // GFXGLDevice Profiler 156 GuiCanvas::getGuiCanvasFrameSignal().notify(&gfxProfiler, &GFXProfiler<GLTimer>::onEndFrame); 157 GFXDevice::getDeviceEventSignal().notify( &initGLProfiler ); 158} 159 160#endif 161