-
-
Save zlatnaspirala/acf7661f5c5cf89578c8197c1d7dc4d3 to your computer and use it in GitHub Desktop.
Profile OpenGL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chrono> | |
#include <iostream> | |
#ifdef __APPLE__ | |
#include <OpenGL/gl.h> | |
#include <OpenGL/glu.h> | |
#include <GLUT/glut.h> | |
#else | |
#ifdef _WIN32 | |
#include <windows.h> | |
#endif | |
#include <GL/gl.h> | |
#include <GL/glu.h> | |
#include <GL/glut.h> | |
#endif | |
void draw(){ | |
typedef std::chrono::high_resolution_clock Clock; | |
using FpSeconds = std::chrono::duration<float, std::chrono::seconds::period>; | |
glFinish(); // execute all previous GPU commands | |
auto startTime = Clock::now(); | |
// open gl commands to be profiled | |
glFinish(); // execute all GPU commands | |
auto endTime = Clock::now(); | |
float deltaTime = std::chrono::duration_cast<FpSeconds>(endTime - startTime).count(); | |
std::cout << "Total time "<<deltaTime<<"s"<<std::endl; | |
} | |
int main(){ | |
// setup opengl context here | |
draw(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment