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
a04770
void Measure::init() {
a04770
	hide = !stack.empty() && stack.back()->hide_subs;
a04770
	hide_subs |= hide;
a04770
	tga = filename.size() > 4 && filename.substr(filename.size()-4, 4) == ".tga";
a04770
	if (!hide)
a04770
		cout << string(stack.size()*2, ' ')
a04770
		     << "begin             "
a04770
			 << filename
a04770
			 << endl << flush;
49e693
	stack.push_back(this);
49e693
	t = clock();
49e693
}
49e693
49e693
Measure::~Measure() {
49e693
	if (!surface && tga) glFinish();
49e693
a04770
	clock_t dt = subs ? subs : clock() - t;
5890eb
	Real ms = 1000.0*(Real)dt/(Real)(CLOCKS_PER_SEC);
f83e6b
a04770
	if (!hide)
a04770
		cout << string((stack.size()-1)*2, ' ') << "end "
a04770
			 << setw(8) << fixed << setprecision(3)
a04770
			 << ms << " ms - "
a04770
			 << filename
a04770
			 << 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();
f29469
	} else
f29469
	if (tga) {
49e693
		glClear(GL_COLOR_BUFFER_BIT);
49e693
		glFinish();
49e693
	}
49e693
49e693
	stack.pop_back();
a04770
	if (!stack.empty()) stack.back()->subs += dt;
49e693
}
49e693