improved performance using my own tga load function always instead of QImage

improved Profiler
This commit is contained in:
Anakin 2017-01-30 16:00:14 +01:00
parent d1c68e8ba6
commit 4342260e6d
4 changed files with 125 additions and 119 deletions

View File

@ -2,9 +2,10 @@
#ifdef _DEBUG
#include <QElapsedTimer.h>
#include <QString>
#include <iostream>
#define TIC Profiler::getInstance().startTimer();
#define TOC Profiler::getInstance().takeTime();
#define TIC(val) Profiler::getInstance().startTimer(val);
#define TOC(val) Profiler::getInstance().takeTime(val);
class Profiler
{
@ -21,16 +22,17 @@
return instance;
}
void startTimer() {
void startTimer(QString position = "") {
std::cout << "from: " << position.toStdString() << std::endl;
timer.restart();
};
void takeTime() {
std::cout << "time elapsed: " << timer.elapsed() << std::endl;
void takeTime(QString position = "") {
std::cout << "to: "<< position.toStdString() << " time elapsed: " << timer.elapsed() << std::endl;
};
};
#else
#define TIC
#define TOC
#define TIC(val)
#define TOC(val)
#endif

View File

@ -3,12 +3,11 @@
#include <QImage>
#include <QColor>
#include "..\Header\Profiler.h"
QImage loadTga(QString filePath, bool &success)
{
QImage img;
if (!img.load(filePath))
{
// open the file
std::fstream fsPicture(filePath.toStdString().c_str(), std::ios::in | std::ios::binary);
@ -133,7 +132,7 @@ QImage loadTga(QString filePath, bool &success)
}
fsPicture.close();
}
success = true;
return img;
}

View File

@ -3,6 +3,8 @@
#include "..\Header\OutputDevice.h"
#include <QColor>
#include "..\Header\Profiler.h"
// helper function to save data from file to any variable type
#define F2V(variableName) reinterpret_cast<char*>(&variableName)
@ -278,7 +280,6 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
curMat->flags[i] = (std::uint8_t)(flag << (7 - i)) >> 7;
curMat->transparent = curMat->flags[2] || curMat->flags[3] || curMat->flags[4] || curMat->flags[6] || curMat->rendertype == 4;
}
// texture 0
@ -310,7 +311,6 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
if (!m_materials->back().tx1d.isEmpty())
loadTexture(m_materials->back().texture1, m_filepath, m_materials->back().tx1d);
}
// texture 2
@ -719,6 +719,7 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position)
void MshFile::loadTexture(QOpenGLTexture *& destination, QString filepath, QString& filename)
{
bool loadSuccess(false);
QImage img = loadTga(filepath + "/" + filename, loadSuccess);
if (!loadSuccess)

View File

@ -428,8 +428,12 @@ void OglViewerWidget::setAmbCoef(double value)
void OglViewerWidget::setHeadlight(bool value)
{
m_light.headlight = value;
if (m_lightOn)
if (m_lightOn && value)
{
updateLightPosition();
update();
}
}
void OglViewerWidget::setBackfaceCulling(bool value)