OGLplus (0.52.0) a C++ wrapper for OpenGL

standalone/002_amd_perf_monitor.cpp

Shows simple usage of the AMD_performance_monitor extensionCopyright 2008-2014 Matus Chochlik. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <cassert>
#include <iostream>
#include <GL/glew.h>
#include <GL/glut.h>
#include <oglplus/all.hpp>
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100,100);
glutCreateWindow("OGLplus+GLUT+GLEW");
if(glewInit() == GLEW_OK) try
{
glGetError();
namespace se = oglplus::smart_enums;
const char* f1[2] = {" +--", " `--"};
const char* f2[2] = {" |", " "};
const char* f3[2] = {" +--", " `--"};
const char* f4[2] = {" |", ""};
auto groups = apm.GetGroups();
auto gi=groups.begin(), ge=groups.end();
std::cout << "--+-{Performance monitor groups}" << std::endl;
if(gi != ge) std::cout << " |" << std::endl;
while(gi != ge)
{
auto group = *gi;
++gi;
const int fgi = (gi == ge)?1:0;
std::cout << f1[fgi] << "+-[";
std::cout << group.GetString();
std::cout << "]" << std::endl;
std::cout << f2[fgi] << f4[0] << std::endl;
GLint max;
auto counters = group.GetCounters(max);
auto ci=counters.begin(), ce=counters.end();
while(ci != ce)
{
auto counter = *ci;
++ci;
const int fci = (ci == ce)?1:0;
std::cout << f2[fgi] << f3[fci] << "(";
std::cout << counter.GetString();
std::cout << ") [";
std::cout << EnumValueName(counter.Type());
std::cout << "]" << std::endl;
std::cout << f2[fgi] << f4[fci] << std::endl;
}
if(fgi != 0)
{
mon.SelectCounters(true, counters);
mon.Begin();
// Imagine some heavy duty rendering here
mon.End();
if(mon.ResultAvailable())
{
std::vector<oglplus::PerfMonitorAMDResult>
values;
mon.Result(values);
auto ri=values.begin(), re=values.end();
while(ri != re)
{
auto counter = ri->Counter();
auto type = counter.Type();
std::cout << counter.GetString();
std::cout << " [";
std::cout << EnumValueName(type);
std::cout << "] = ";
if(type == se::UnsignedInt())
std::cout << ri->Low();
else if(type == se::Float())
std::cout << ri->Float();
else if(type == se::Percentage())
std::cout << ri->Float() << "%";
else if(type == se::UnsignedInt64())
std::cout << "too big";
std::cout << std::endl;
++ri;
}
}
}
}
return 0;
}
catch(oglplus::Error& err)
{
std::cerr
<< "Error (in "
<< err.GLFunc()
<< "'): "
<< err.what()
<< " ["
<< err.SourceFile()
<< ":"
<< err.SourceLine()
<< "] "
<< std::endl;
}
return 1;
}

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).