Skip to content

Instantly share code, notes, and snippets.

@mortennobel
Created May 14, 2018 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mortennobel/6dd68f400ff6a3b6a986d2f7013bf9e0 to your computer and use it in GitHub Desktop.
Save mortennobel/6dd68f400ff6a3b6a986d2f7013bf9e0 to your computer and use it in GitHub Desktop.
Profile OpenGL
#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