Skip to content

Instantly share code, notes, and snippets.

@zlatnaspirala
Forked from mortennobel/opengl-profile.cpp
Created September 12, 2019 12:44
Show Gist options
  • Save zlatnaspirala/acf7661f5c5cf89578c8197c1d7dc4d3 to your computer and use it in GitHub Desktop.
Save zlatnaspirala/acf7661f5c5cf89578c8197c1d7dc4d3 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