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) : 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 90DefineConsoleFunction(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 113void GFXGLDevice::leaveDebugEvent() 114{ 115#ifdef TORQUE_BASIC_GPU_PROFILER 116 gfxProfiler.leaveDebugEvent(); 117#endif 118} 119 120void GFXGLDevice::setDebugMarker(ColorI color, const char *name) 121{ 122 123} 124 125#ifdef TORQUE_BASIC_GPU_PROFILER 126 127AFTER_MODULE_INIT(Sim) 128{ 129 // GFXGLDevice Profiler 130 GuiCanvas::getGuiCanvasFrameSignal().notify(&gfxProfiler, &GFXProfiler<GLTimer>::onEndFrame); 131 GFXDevice::getDeviceEventSignal().notify( &initGLProfiler ); 132} 133 134#endif 135
