Blame c++/contourgl/measure.cpp

49e693
/*
49e693
    ......... 2015 Ivan Mahonin
49e693
49e693
    This program is free software: you can redistribute it and/or modify
49e693
    it under the terms of the GNU General Public License as published by
49e693
    the Free Software Foundation, either version 3 of the License, or
49e693
    (at your option) any later version.
49e693
49e693
    This program is distributed in the hope that it will be useful,
49e693
    but WITHOUT ANY WARRANTY; without even the implied warranty of
49e693
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
49e693
    GNU General Public License for more details.
49e693
49e693
    You should have received a copy of the GNU General Public License
49e693
    along with this program.  If not, see <http: licenses="" www.gnu.org="">.</http:>
49e693
*/
49e693
49e693
#include <iostream></iostream>
49e693
#include <iomanip></iomanip>
49e693
49e693
#include "measure.h"
49e693
#include "utils.h"
49e693
#include "glcontext.h"
49e693
49e693
49e693
using namespace std;
49e693
49e693
49e693
std::vector<measure*> Measure::stack;</measure*>
49e693
49e693
49e693
Measure::Measure(const std::string &filename):
49e693
	filename(filename),
49e693
	surface(),
49e693
	tga(filename.size() > 4 && filename.substr(filename.size()-4, 4) == ".tga"),
49e693
	sub_tasks(),
49e693
	t()
49e693
{
49e693
	stack.push_back(this);
49e693
	t = clock();
49e693
}
49e693
49e693
Measure::Measure(const std::string &filename, Surface &surface):
49e693
	filename(filename),
49e693
	surface(&surface),
49e693
	tga(filename.size() > 4 && filename.substr(filename.size()-4, 4) == ".tga"),
49e693
	sub_tasks(),
49e693
	t()
49e693
{
d989ab
	cout << string(stack.size()*2, ' ') << "begin " << filename;
49e693
	stack.push_back(this);
49e693
	t = clock();
49e693
}
49e693
49e693
Measure::~Measure() {
49e693
	if (!surface && tga) glFinish();
49e693
49e693
	clock_t dt = sub_tasks ? sub_tasks : clock() - t;
49e693
	Real ms = 1000.0*(Real)(clock() - t)/(Real)(CLOCKS_PER_SEC);
f83e6b
49e693
	cout << setw(8) << fixed << setprecision(3)
d989ab
	     << string(stack.size()*2, ' ') << "end "
f83e6b
		 << ms << " ms - "
f83e6b
		 << filename
f83e6b
		 << endl << flush;
49e693
49e693
	if (tga) {
49e693
		if (surface)
49e693
			Utils::save_surface(*surface, filename);
49e693
		else
49e693
			Utils::save_viewport(filename);
49e693
	}
49e693
49e693
	if (surface) {
49e693
		surface->clear();
49e693
	} else {
49e693
		glClear(GL_COLOR_BUFFER_BIT);
49e693
		glFinish();
49e693
	}
49e693
49e693
	stack.pop_back();
49e693
	if (!stack.empty()) stack.back()->sub_tasks += dt;
49e693
}
49e693