mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
migrated OpenGL code from QGLWidget to QOpenGLWidget, Qt5.4>= required
This commit is contained in:
parent
b8ba1e5b70
commit
15ee566286
@ -67,12 +67,12 @@ shouldOpenPrevious(false)
|
|||||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||||
|
|
||||||
//CONFIG GOTO_FLOW--------------------------------------------------------
|
//CONFIG GOTO_FLOW--------------------------------------------------------
|
||||||
if(QGLFormat::hasOpenGL() && !settings->contains(USE_OPEN_GL))
|
if(!settings->contains(USE_OPEN_GL))
|
||||||
{
|
{
|
||||||
settings->setValue(USE_OPEN_GL,2);
|
settings->setValue(USE_OPEN_GL,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(QGLFormat::hasOpenGL() && (settings->value(USE_OPEN_GL).toBool() == true))
|
if((settings->value(USE_OPEN_GL).toBool() == true))
|
||||||
goToFlow = new GoToFlowGL(this,Configuration::getConfiguration().getFlowType());
|
goToFlow = new GoToFlowGL(this,Configuration::getConfiguration().getFlowType());
|
||||||
else
|
else
|
||||||
goToFlow = new GoToFlow(this,Configuration::getConfiguration().getFlowType());
|
goToFlow = new GoToFlow(this,Configuration::getConfiguration().getFlowType());
|
||||||
|
@ -17,7 +17,7 @@ ClassicComicsView::ClassicComicsView(QWidget *parent)
|
|||||||
//FLOW-----------------------------------------------------------------------
|
//FLOW-----------------------------------------------------------------------
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
if(QGLFormat::hasOpenGL() && (settings->value(USE_OPEN_GL).toBool() == true))
|
if((settings->value(USE_OPEN_GL).toBool() == true))
|
||||||
comicFlow = new ComicFlowWidgetGL(0);
|
comicFlow = new ComicFlowWidgetGL(0);
|
||||||
else
|
else
|
||||||
comicFlow = new ComicFlowWidgetSW(0);
|
comicFlow = new ComicFlowWidgetSW(0);
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include <QGLContext>
|
#include <QGLContext>
|
||||||
#include <QGLPixelBuffer>
|
#include <QGLPixelBuffer>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
/*** Animation Settings ***/
|
/*** Animation Settings ***/
|
||||||
|
|
||||||
/*** Position Configuration ***/
|
/*** Position Configuration ***/
|
||||||
@ -200,7 +200,7 @@ struct Preset pressetYACReaderFlowDownConfig = {
|
|||||||
};
|
};
|
||||||
/*Constructor*/
|
/*Constructor*/
|
||||||
YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p)
|
YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p)
|
||||||
:QGLWidget(QGLFormat(QGL::SampleBuffers), parent),numObjects(0),lazyPopulateObjects(-1),bUseVSync(false),hasBeenInitialized(false)
|
:QOpenGLWidget(/*QOpenGLWidget migration QGLFormat(QGL::SampleBuffers),*/ parent),numObjects(0),lazyPopulateObjects(-1),bUseVSync(false),hasBeenInitialized(false)
|
||||||
{
|
{
|
||||||
updateCount = 0;
|
updateCount = 0;
|
||||||
config = p;
|
config = p;
|
||||||
@ -238,7 +238,10 @@ YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p)
|
|||||||
|
|
||||||
loaderThread->start();*/
|
loaderThread->start();*/
|
||||||
|
|
||||||
QGLFormat f = format();
|
QSurfaceFormat f = format();
|
||||||
|
|
||||||
|
//TODO add antialiasing
|
||||||
|
f.setSamples(4);
|
||||||
f.setVersion(2, 1);
|
f.setVersion(2, 1);
|
||||||
f.setSwapInterval(0);
|
f.setSwapInterval(0);
|
||||||
setFormat(f);
|
setFormat(f);
|
||||||
@ -250,7 +253,7 @@ YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p)
|
|||||||
void YACReaderFlowGL::timerEvent(QTimerEvent * event)
|
void YACReaderFlowGL::timerEvent(QTimerEvent * event)
|
||||||
{
|
{
|
||||||
if(timerId == event->timerId())
|
if(timerId == event->timerId())
|
||||||
updateGL();
|
update();
|
||||||
|
|
||||||
//if(!worker->isRunning())
|
//if(!worker->isRunning())
|
||||||
//worker->start();
|
//worker->start();
|
||||||
@ -298,10 +301,16 @@ void YACReaderFlowGL::initializeGL()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
defaultTexture = bindTexture(QImage(":/images/defaultCover.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
|
defaultTexture = new QOpenGLTexture(QImage(":/images/defaultCover.png"));
|
||||||
markTexture = bindTexture(QImage(":/images/readRibbon.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
|
defaultTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear);
|
||||||
readingTexture = bindTexture(QImage(":/images/readingRibbon.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
|
|
||||||
if(lazyPopulateObjects!=-1)
|
markTexture = new QOpenGLTexture(QImage(":/images/readRibbon.png"));
|
||||||
|
markTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear);
|
||||||
|
|
||||||
|
readingTexture = new QOpenGLTexture(QImage(":/images/readingRibbon.png"));
|
||||||
|
readingTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear);
|
||||||
|
|
||||||
|
if(lazyPopulateObjects!=-1)
|
||||||
populate(lazyPopulateObjects);
|
populate(lazyPopulateObjects);
|
||||||
|
|
||||||
hasBeenInitialized = true;
|
hasBeenInitialized = true;
|
||||||
@ -351,41 +360,41 @@ void YACReaderFlowGL::udpatePerspective(int width, int height)
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/*Private*/
|
/*Private*/
|
||||||
void YACReaderFlowGL::calcPos(CFImage *CF,int pos)
|
void YACReaderFlowGL::calcPos(YACReader3DImage & image, int pos)
|
||||||
{
|
{
|
||||||
if(pos == 0){
|
if(pos == 0){
|
||||||
CF->current = centerPos;
|
image.current = centerPos;
|
||||||
}else{
|
}else{
|
||||||
if(pos > 0){
|
if(pos > 0){
|
||||||
CF->current.x = (config.centerDistance)+(config.xDistance*pos);
|
image.current.x = (config.centerDistance)+(config.xDistance*pos);
|
||||||
CF->current.y = config.yDistance*pos*-1;
|
image.current.y = config.yDistance*pos*-1;
|
||||||
CF->current.z = config.zDistance*pos*-1;
|
image.current.z = config.zDistance*pos*-1;
|
||||||
CF->current.rot = config.rotation;
|
image.current.rot = config.rotation;
|
||||||
}else{
|
}else{
|
||||||
CF->current.x = (config.centerDistance)*-1+(config.xDistance*pos);
|
image.current.x = (config.centerDistance)*-1+(config.xDistance*pos);
|
||||||
CF->current.y = config.yDistance*pos;
|
image.current.y = config.yDistance*pos;
|
||||||
CF->current.z = config.zDistance*pos;
|
image.current.z = config.zDistance*pos;
|
||||||
CF->current.rot = config.rotation*-1;
|
image.current.rot = config.rotation*-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
void YACReaderFlowGL::calcRV(RVect *RV,int pos)
|
void YACReaderFlowGL::calcVector(YACReader3DVector & vector, int pos)
|
||||||
{
|
{
|
||||||
calcPos(&dummy,pos);
|
calcPos(dummy,pos);
|
||||||
|
|
||||||
RV->x = dummy.current.x;
|
|
||||||
RV->y = dummy.current.y;
|
|
||||||
RV->z = dummy.current.z;
|
|
||||||
RV->rot = dummy.current.rot;
|
|
||||||
|
|
||||||
|
vector.x = dummy.current.x;
|
||||||
|
vector.y = dummy.current.y;
|
||||||
|
vector.z = dummy.current.z;
|
||||||
|
vector.rot = dummy.current.rot;
|
||||||
}
|
}
|
||||||
bool YACReaderFlowGL::animate(RVect *Current,RVect to)
|
|
||||||
|
bool YACReaderFlowGL::animate(YACReader3DVector & currentVector,YACReader3DVector & toVector)
|
||||||
{
|
{
|
||||||
float rotDiff = to.rot-Current->rot;
|
float rotDiff = toVector.rot-currentVector.rot;
|
||||||
float xDiff = to.x-Current->x;
|
float xDiff = toVector.x-currentVector.x;
|
||||||
float yDiff = to.y-Current->y;
|
float yDiff = toVector.y-currentVector.y;
|
||||||
float zDiff = to.z-Current->z;
|
float zDiff = toVector.z-currentVector.z;
|
||||||
|
|
||||||
if(fabs(rotDiff) < 0.01
|
if(fabs(rotDiff) < 0.01
|
||||||
&& fabs(xDiff) < 0.001
|
&& fabs(xDiff) < 0.001
|
||||||
@ -394,12 +403,12 @@ bool YACReaderFlowGL::animate(RVect *Current,RVect to)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
//calculate and apply positions
|
//calculate and apply positions
|
||||||
Current->x = Current->x+(xDiff)*config.animationStep;
|
currentVector.x = currentVector.x+(xDiff)*config.animationStep;
|
||||||
Current->y = Current->y+(yDiff)*config.animationStep;
|
currentVector.y = currentVector.y+(yDiff)*config.animationStep;
|
||||||
Current->z = Current->z+(zDiff)*config.animationStep;
|
currentVector.z = currentVector.z+(zDiff)*config.animationStep;
|
||||||
|
|
||||||
if(fabs(rotDiff) > 0.01){
|
if(fabs(rotDiff) > 0.01){
|
||||||
Current->rot = Current->rot+(rotDiff)*(config.animationStep*config.preRotation);
|
currentVector.rot = currentVector.rot+(rotDiff)*(config.animationStep*config.preRotation);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -408,13 +417,13 @@ bool YACReaderFlowGL::animate(RVect *Current,RVect to)
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void YACReaderFlowGL::drawCover(CFImage *CF)
|
void YACReaderFlowGL::drawCover(const YACReader3DImage & image)
|
||||||
{
|
{
|
||||||
float w = CF->width;
|
float w = image.width;
|
||||||
float h = CF->height;
|
float h = image.height;
|
||||||
|
|
||||||
//fadeout
|
//fadeout
|
||||||
float opacity = 1-1/(config.animationFadeOutDist+config.viewRotateLightStrenght*fabs(viewRotate))*fabs(0-CF->current.x);
|
float opacity = 1-1/(config.animationFadeOutDist+config.viewRotateLightStrenght*fabs(viewRotate))*fabs(0-image.current.x);
|
||||||
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(config.cfX,config.cfY,config.cfZ);
|
glTranslatef(config.cfX,config.cfY,config.cfZ);
|
||||||
@ -422,17 +431,17 @@ void YACReaderFlowGL::drawCover(CFImage *CF)
|
|||||||
glRotatef(viewRotate*config.viewAngle+config.cfRY,0,1,0);
|
glRotatef(viewRotate*config.viewAngle+config.cfRY,0,1,0);
|
||||||
glRotatef(config.cfRZ,0,0,1);
|
glRotatef(config.cfRZ,0,0,1);
|
||||||
|
|
||||||
glTranslatef( CF->current.x, CF->current.y, CF->current.z );
|
glTranslatef( image.current.x, image.current.y, image.current.z );
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glRotatef(CF->current.rot,0,1,0);
|
glRotatef(image.current.rot,0,1,0);
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, CF->img);
|
image.texture->bind();
|
||||||
|
|
||||||
//calculate shading
|
//calculate shading
|
||||||
float LShading = ((config.rotation != 0 )?((CF->current.rot < 0)?1-1/config.rotation*CF->current.rot:1):1);
|
float LShading = ((config.rotation != 0 )?((image.current.rot < 0)?1-1/config.rotation*image.current.rot:1):1);
|
||||||
float RShading = ((config.rotation != 0 )?((CF->current.rot > 0)?1-1/(config.rotation*-1)*CF->current.rot:1):1);
|
float RShading = ((config.rotation != 0 )?((image.current.rot > 0)?1-1/(config.rotation*-1)*image.current.rot:1):1);
|
||||||
float LUP = shadingTop+(1-shadingTop)*LShading;
|
float LUP = shadingTop+(1-shadingTop)*LShading;
|
||||||
float LDOWN = shadingBottom+(1-shadingBottom)*LShading;
|
float LDOWN = shadingBottom+(1-shadingBottom)*LShading;
|
||||||
float RUP = shadingTop+(1-shadingTop)*RShading;
|
float RUP = shadingTop+(1-shadingTop)*RShading;
|
||||||
@ -490,13 +499,13 @@ void YACReaderFlowGL::drawCover(CFImage *CF)
|
|||||||
glEnd();
|
glEnd();
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
if(showMarks && loaded[CF->index] && marks[CF->index] != Unread)
|
if(showMarks && loaded[image.index] && marks[image.index] != Unread)
|
||||||
{
|
{
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
if(marks[CF->index] == Read)
|
if(marks[image.index] == Read)
|
||||||
glBindTexture(GL_TEXTURE_2D, markTexture);
|
markTexture->bind();
|
||||||
else
|
else
|
||||||
glBindTexture(GL_TEXTURE_2D, readingTexture);
|
readingTexture->bind();
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
//esquina inferior izquierda
|
//esquina inferior izquierda
|
||||||
@ -543,19 +552,19 @@ void YACReaderFlowGL::draw()
|
|||||||
//Draw right Covers
|
//Draw right Covers
|
||||||
for(count = numObjects-1;count > -1;count--){
|
for(count = numObjects-1;count > -1;count--){
|
||||||
if(count > CS){
|
if(count > CS){
|
||||||
drawCover(&cfImages[count]);
|
drawCover(images[count]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Draw left Covers
|
//Draw left Covers
|
||||||
for(count = 0;count < numObjects-1;count++){
|
for(count = 0;count < numObjects-1;count++){
|
||||||
if(count < CS){
|
if(count < CS){
|
||||||
drawCover(&cfImages[count]);
|
drawCover(images[count]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Draw Center Cover
|
//Draw Center Cover
|
||||||
drawCover(&cfImages[CS]);
|
drawCover(images[CS]);
|
||||||
|
|
||||||
//glDisable(GL_DEPTH_TEST);
|
//glDisable(GL_DEPTH_TEST);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
@ -565,9 +574,17 @@ void YACReaderFlowGL::draw()
|
|||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
glColor4f( 0.3f, 0.3f, 0.3f, 1.0f );
|
//glColor4f( 0.3f, 0.3f, 0.3f, 1.0f );
|
||||||
|
|
||||||
renderText(10, fontSize + 10,QString("%1/%2").arg(currentSelected+1).arg(numObjects),QFont("Arial", fontSize));
|
/*QOpenGLWidget migration renderText(10, fontSize + 10,QString("%1/%2").arg(currentSelected+1).arg(numObjects),QFont("Arial", fontSize));
|
||||||
|
|
||||||
|
QPainter painter;
|
||||||
|
painter.begin(this);
|
||||||
|
|
||||||
|
painter.setPen(QColor(76,76,76));
|
||||||
|
painter.drawText(10,10, QString("%1/%2").arg(currentSelected+1).arg(numObjects));
|
||||||
|
|
||||||
|
painter.end();*/
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
@ -645,8 +662,8 @@ void YACReaderFlowGL::updatePositions()
|
|||||||
|
|
||||||
bool stopAnimation = true;
|
bool stopAnimation = true;
|
||||||
for(count = numObjects-1;count > -1;count--){
|
for(count = numObjects-1;count > -1;count--){
|
||||||
calcRV(&cfImages[count].animEnd,count-currentSelected);
|
calcVector(images[count].animEnd,count-currentSelected);
|
||||||
if(!animate(&cfImages[count].current,cfImages[count].animEnd))
|
if(!animate(images[count].current,images[count].animEnd))
|
||||||
stopAnimation = false;
|
stopAnimation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,7 +672,7 @@ void YACReaderFlowGL::updatePositions()
|
|||||||
viewRotate += (0-viewRotate)*config.viewRotateSub;
|
viewRotate += (0-viewRotate)*config.viewRotateSub;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fabs (cfImages[currentSelected].current.x - cfImages[currentSelected].animEnd.x) < 1)//viewRotate < 0.2)
|
if(fabs (images[currentSelected].current.x - images[currentSelected].animEnd.x) < 1)//viewRotate < 0.2)
|
||||||
{
|
{
|
||||||
cleanupAnimation();
|
cleanupAnimation();
|
||||||
if(updateCount >= 0) //TODO parametrizar
|
if(updateCount >= 0) //TODO parametrizar
|
||||||
@ -675,34 +692,27 @@ void YACReaderFlowGL::updatePositions()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderFlowGL::insert(char *name, GLuint Tex, float x, float y,int item)
|
void YACReaderFlowGL::insert(char *name, QOpenGLTexture * texture, float x, float y,int item)
|
||||||
{
|
{
|
||||||
startAnimationTimer();
|
startAnimationTimer();
|
||||||
|
|
||||||
Q_UNUSED(name)
|
Q_UNUSED(name)
|
||||||
//set a new entry
|
//set a new entry
|
||||||
if(item == -1){
|
if(item == -1){
|
||||||
|
images.push_back(YACReader3DImage());
|
||||||
if(numObjects == 0){
|
|
||||||
cfImages = (CFImage*)malloc(sizeof(CFImage));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cfImages = (CFImage*)realloc(cfImages,(numObjects+1)*sizeof(CFImage));
|
|
||||||
}
|
|
||||||
|
|
||||||
item = numObjects;
|
item = numObjects;
|
||||||
numObjects++;
|
numObjects++;
|
||||||
|
|
||||||
calcRV(&cfImages[item].current,item);
|
calcVector(images[item].current,item);
|
||||||
cfImages[item].current.x += 1;
|
images[item].current.x += 1;
|
||||||
cfImages[item].current.rot = 90;
|
images[item].current.rot = 90;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfImages[item].img = Tex;
|
images[item].texture = texture;
|
||||||
cfImages[item].width = x;
|
images[item].width = x;
|
||||||
cfImages[item].height = y;
|
images[item].height = y;
|
||||||
cfImages[item].index = item;
|
images[item].index = item;
|
||||||
//strcpy(cfImages[item].name,name);
|
//strcpy(cfImages[item].name,name);
|
||||||
|
|
||||||
|
|
||||||
@ -724,34 +734,37 @@ void YACReaderFlowGL::remove(int item)
|
|||||||
currentSelected--;
|
currentSelected--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QOpenGLTexture * texture = images[item].texture;
|
||||||
|
|
||||||
int count = item;
|
int count = item;
|
||||||
while(count <= numObjects-2){
|
while(count <= numObjects-2){
|
||||||
cfImages[count] = cfImages[count+1];
|
images[count].index--;
|
||||||
cfImages[count].index--;
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
images.removeAt(item);
|
||||||
|
|
||||||
cfImages = (CFImage*)realloc(cfImages,numObjects*sizeof(CFImage));
|
if(texture != defaultTexture)
|
||||||
|
delete(texture);
|
||||||
|
|
||||||
numObjects--;
|
numObjects--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Info*/
|
/*Info*/
|
||||||
CFImage YACReaderFlowGL::getCurrentSelected()
|
YACReader3DImage YACReaderFlowGL::getCurrentSelected()
|
||||||
{
|
{
|
||||||
return cfImages[currentSelected];
|
return images[currentSelected];
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderFlowGL::replace(char *name, GLuint Tex, float x, float y,int item)
|
void YACReaderFlowGL::replace(char *name, QOpenGLTexture * texture, float x, float y,int item)
|
||||||
{
|
{
|
||||||
startAnimationTimer();
|
startAnimationTimer();
|
||||||
|
|
||||||
Q_UNUSED(name)
|
Q_UNUSED(name)
|
||||||
if(cfImages[item].index == item)
|
if(images[item].index == item)
|
||||||
{
|
{
|
||||||
cfImages[item].img = Tex;
|
images[item].texture = texture;
|
||||||
cfImages[item].width = x;
|
images[item].width = x;
|
||||||
cfImages[item].height = y;
|
images[item].height = y;
|
||||||
loaded[item]=true;
|
loaded[item]=true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -766,7 +779,8 @@ void YACReaderFlowGL::populate(int n)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0;i<n;i++){
|
for(i = 0;i<n;i++){
|
||||||
insert("cover", defaultTexture, x, y);
|
QString s = "cover";
|
||||||
|
insert(s.toLocal8Bit().data(), defaultTexture, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -793,12 +807,12 @@ void YACReaderFlowGL::reset()
|
|||||||
loaded.clear();
|
loaded.clear();
|
||||||
|
|
||||||
for(int i = 0;i<numObjects;i++){
|
for(int i = 0;i<numObjects;i++){
|
||||||
if(cfImages[i].img != defaultTexture)
|
if(images[i].texture != defaultTexture)
|
||||||
deleteTexture(cfImages[i].img);
|
delete(images[i].texture);
|
||||||
}
|
}
|
||||||
if(numObjects>0)
|
|
||||||
delete[] cfImages;
|
|
||||||
numObjects = 0;
|
numObjects = 0;
|
||||||
|
images.clear();
|
||||||
|
|
||||||
if(!hasBeenInitialized)
|
if(!hasBeenInitialized)
|
||||||
lazyPopulateObjects = -1;
|
lazyPopulateObjects = -1;
|
||||||
@ -947,14 +961,14 @@ void YACReaderFlowGL::useVSync(bool b)
|
|||||||
bUseVSync = b;
|
bUseVSync = b;
|
||||||
if(b)
|
if(b)
|
||||||
{
|
{
|
||||||
QGLFormat f = format();
|
QSurfaceFormat f = format();
|
||||||
f.setVersion(2, 1);
|
f.setVersion(2, 1);
|
||||||
f.setSwapInterval(1);
|
f.setSwapInterval(1);
|
||||||
setFormat(f);
|
setFormat(f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QGLFormat f = format();
|
QSurfaceFormat f = format();
|
||||||
f.setVersion(2, 1);
|
f.setVersion(2, 1);
|
||||||
f.setSwapInterval(0);
|
f.setSwapInterval(0);
|
||||||
setFormat(f);
|
setFormat(f);
|
||||||
@ -1103,7 +1117,7 @@ void YACReaderFlowGL::mousePressEvent(QMouseEvent *event)
|
|||||||
else if(posX <=-0.5)
|
else if(posX <=-0.5)
|
||||||
showPrevious();
|
showPrevious();
|
||||||
} else
|
} else
|
||||||
QGLWidget::mousePressEvent(event);
|
QOpenGLWidget::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderFlowGL::mouseDoubleClickEvent(QMouseEvent* event)
|
void YACReaderFlowGL::mouseDoubleClickEvent(QMouseEvent* event)
|
||||||
@ -1175,19 +1189,21 @@ void YACReaderComicFlowGL::updateImageData()
|
|||||||
{
|
{
|
||||||
float x = 1;
|
float x = 1;
|
||||||
QImage img = worker->result();
|
QImage img = worker->result();
|
||||||
GLuint cover;
|
QOpenGLTexture * texture = new QOpenGLTexture(img);
|
||||||
if(performance == high || performance == ultraHigh)
|
|
||||||
cover = bindTexture(img, GL_TEXTURE_2D,GL_RGB,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
|
if(performance == high || performance == ultraHigh)
|
||||||
|
{
|
||||||
|
texture->setAutoMipMapGenerationEnabled(true);
|
||||||
|
texture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
cover = bindTexture(img, GL_TEXTURE_2D,GL_RGB,QGLContext::LinearFilteringBindOption);
|
{
|
||||||
|
texture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear);
|
||||||
|
}
|
||||||
|
|
||||||
float y = 1 * (float(img.height())/img.width());
|
float y = 1 * (float(img.height())/img.width());
|
||||||
replace("cover", cover, x, y,idx);
|
QString s = "cover";
|
||||||
/*CFImages[idx].width = x;
|
replace(s.toLocal8Bit().data(), texture, x, y,idx);
|
||||||
CFImages[idx].height = y;
|
|
||||||
CFImages[idx].img = worker->resultTexture;
|
|
||||||
strcpy(CFImages[idx].name,"cover");*/
|
|
||||||
//loaded[idx] = true;
|
|
||||||
//numImagesLoaded++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1260,7 +1276,9 @@ YACReaderPageFlowGL::~YACReaderPageFlowGL()
|
|||||||
this->killTimer(timerId);
|
this->killTimer(timerId);
|
||||||
//worker->deleteLater();
|
//worker->deleteLater();
|
||||||
rawImages.clear();
|
rawImages.clear();
|
||||||
free(cfImages);
|
for(int i = 0;i<numObjects;i++){
|
||||||
|
delete(images[i].texture);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -1283,19 +1301,22 @@ void YACReaderPageFlowGL::updateImageData()
|
|||||||
{
|
{
|
||||||
float x = 1;
|
float x = 1;
|
||||||
QImage img = worker->result();
|
QImage img = worker->result();
|
||||||
GLuint cover;
|
QOpenGLTexture * texture = new QOpenGLTexture(img);
|
||||||
if(performance == high || performance == ultraHigh)
|
|
||||||
cover = bindTexture(img, GL_TEXTURE_2D,GL_RGB,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
|
if(performance == high || performance == ultraHigh)
|
||||||
|
{
|
||||||
|
texture->setAutoMipMapGenerationEnabled(true);
|
||||||
|
texture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
cover = bindTexture(img, GL_TEXTURE_2D,GL_RGB,QGLContext::LinearFilteringBindOption);
|
{
|
||||||
|
texture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear);
|
||||||
|
}
|
||||||
|
|
||||||
float y = 1 * (float(img.height())/img.width());
|
float y = 1 * (float(img.height())/img.width());
|
||||||
replace("cover", cover, x, y,idx);
|
QString s = "cover";
|
||||||
/*CFImages[idx].width = x;
|
replace(s.toLocal8Bit().data(), texture, x, y,idx);
|
||||||
CFImages[idx].height = y;
|
|
||||||
CFImages[idx].img = worker->resultTexture;
|
|
||||||
strcpy(CFImages[idx].name,"cover");*/
|
|
||||||
loaded[idx] = true;
|
loaded[idx] = true;
|
||||||
//numImagesLoaded++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1333,12 +1354,6 @@ void YACReaderPageFlowGL::updateImageData()
|
|||||||
|
|
||||||
if(!loaded[i]&&imagesReady[i])//slide(i).isNull())
|
if(!loaded[i]&&imagesReady[i])//slide(i).isNull())
|
||||||
{
|
{
|
||||||
//loader->loadTexture(i);
|
|
||||||
//loaded[i]=true;
|
|
||||||
// schedule thumbnail generation
|
|
||||||
|
|
||||||
//loaded[i]=true;
|
|
||||||
|
|
||||||
worker->generate(i, rawImages.at(i));
|
worker->generate(i, rawImages.at(i));
|
||||||
|
|
||||||
delete[] indexes;
|
delete[] indexes;
|
||||||
@ -1566,18 +1581,3 @@ QImage ImageLoaderByteArrayGL::result()
|
|||||||
{
|
{
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
//WidgetLoader::WidgetLoader(QWidget *parent, QGLWidget * shared)
|
|
||||||
// :QGLWidget(parent,shared)
|
|
||||||
//{
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//void WidgetLoader::loadTexture(int index)
|
|
||||||
//{
|
|
||||||
// QImage image;
|
|
||||||
// bool result = image.load(QString("./cover%1.jpg").arg(index+1));
|
|
||||||
// //image = image.scaledToWidth(128,Qt::SmoothTransformation); //TODO parametrizar
|
|
||||||
// flow->cfImages[index].width = 0.5;
|
|
||||||
// flow->cfImages[index].height = 0.5 * (float(image.height())/image.width());
|
|
||||||
// flow->cfImages[index].img = bindTexture(image, GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
|
|
||||||
//}
|
|
||||||
|
@ -7,9 +7,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <QtOpenGL>
|
#include <QOpenGLWidget>
|
||||||
#include <QGLWidget>
|
#include <QOpenGLFunctions>
|
||||||
#include <QMutex>
|
#include <QOpenGLTexture>
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
#include "pictureflow.h" //TODO mover los tipos de flow de sitio
|
#include "pictureflow.h" //TODO mover los tipos de flow de sitio
|
||||||
|
|
||||||
@ -27,16 +28,16 @@ enum Performance
|
|||||||
};
|
};
|
||||||
|
|
||||||
//Cover Vector
|
//Cover Vector
|
||||||
struct RVect{
|
struct YACReader3DVector{
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
float rot;
|
float rot;
|
||||||
};
|
};
|
||||||
|
|
||||||
//the cover info struct
|
//the image/texture info struct
|
||||||
struct CFImage{
|
struct YACReader3DImage{
|
||||||
GLuint img;
|
QOpenGLTexture * texture;
|
||||||
//char name[256];
|
//char name[256];
|
||||||
|
|
||||||
float width;
|
float width;
|
||||||
@ -44,8 +45,8 @@ struct CFImage{
|
|||||||
|
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
RVect current;
|
YACReader3DVector current;
|
||||||
RVect animEnd;
|
YACReader3DVector animEnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Preset{
|
struct Preset{
|
||||||
@ -103,22 +104,22 @@ extern struct Preset presetYACReaderFlowOverlappedStripeConfig;
|
|||||||
extern struct Preset pressetYACReaderFlowUpConfig;
|
extern struct Preset pressetYACReaderFlowUpConfig;
|
||||||
extern struct Preset pressetYACReaderFlowDownConfig;
|
extern struct Preset pressetYACReaderFlowDownConfig;
|
||||||
|
|
||||||
class YACReaderFlowGL : public QGLWidget
|
class YACReaderFlowGL : public QOpenGLWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
int timerId;
|
int timerId;
|
||||||
/*** System variables ***/
|
/*** System variables ***/
|
||||||
CFImage dummy;
|
YACReader3DImage dummy;
|
||||||
int viewRotateActive;
|
int viewRotateActive;
|
||||||
float stepBackup;
|
float stepBackup;
|
||||||
|
|
||||||
/*functions*/
|
/*functions*/
|
||||||
void calcPos(CFImage *CF,int pos);
|
void calcPos(YACReader3DImage & image, int pos);
|
||||||
void calcRV(RVect *RV,int pos);
|
void calcVector(YACReader3DVector & vector, int pos);
|
||||||
//returns true if the animation is finished for Current
|
//returns true if the animation is finished for Current
|
||||||
bool animate(RVect *Current,RVect to);
|
bool animate(YACReader3DVector ¤tVector, YACReader3DVector &toVector);
|
||||||
void drawCover(CFImage *CF);
|
void drawCover(const YACReader3DImage & image);
|
||||||
|
|
||||||
void udpatePerspective(int width, int height);
|
void udpatePerspective(int width, int height);
|
||||||
|
|
||||||
@ -126,9 +127,9 @@ protected:
|
|||||||
WidgetLoader * loader;
|
WidgetLoader * loader;
|
||||||
int fontSize;
|
int fontSize;
|
||||||
|
|
||||||
GLuint defaultTexture;
|
QOpenGLTexture * defaultTexture;
|
||||||
GLuint markTexture;
|
QOpenGLTexture * markTexture;
|
||||||
GLuint readingTexture;
|
QOpenGLTexture * readingTexture;
|
||||||
void initializeGL();
|
void initializeGL();
|
||||||
void paintGL();
|
void paintGL();
|
||||||
void timerEvent(QTimerEvent *);
|
void timerEvent(QTimerEvent *);
|
||||||
@ -140,7 +141,9 @@ protected:
|
|||||||
QVector<bool> loaded;
|
QVector<bool> loaded;
|
||||||
QVector<YACReaderComicReadStatus> marks;
|
QVector<YACReaderComicReadStatus> marks;
|
||||||
QList<QString> paths;
|
QList<QString> paths;
|
||||||
CFImage * cfImages;
|
|
||||||
|
QVector<YACReader3DImage> images;
|
||||||
|
|
||||||
bool hasBeenInitialized;
|
bool hasBeenInitialized;
|
||||||
|
|
||||||
Performance performance;
|
Performance performance;
|
||||||
@ -153,7 +156,7 @@ protected:
|
|||||||
int currentSelected;
|
int currentSelected;
|
||||||
|
|
||||||
//defines the position of the centered cover
|
//defines the position of the centered cover
|
||||||
RVect centerPos;
|
YACReader3DVector centerPos;
|
||||||
|
|
||||||
/*** Style ***/
|
/*** Style ***/
|
||||||
//sets the amount of shading of the covers in the back (0-1)
|
//sets the amount of shading of the covers in the back (0-1)
|
||||||
@ -201,17 +204,17 @@ public:
|
|||||||
//inserts a new item to the coverflow
|
//inserts a new item to the coverflow
|
||||||
//if item is set to a value > -1 it updates a already set value
|
//if item is set to a value > -1 it updates a already set value
|
||||||
//otherwise a new entry is set
|
//otherwise a new entry is set
|
||||||
void insert(char *name, GLuint Tex, float x, float y,int item = -1);
|
void insert(char *name, QOpenGLTexture * texture, float x, float y, int item = -1);
|
||||||
//removes a item
|
//removes a item
|
||||||
virtual void remove(int item);
|
virtual void remove(int item);
|
||||||
//replaces the texture of the item 'item' with Tex
|
//replaces the texture of the item 'item' with Tex
|
||||||
void replace(char *name, GLuint Tex, float x, float y,int item);
|
void replace(char *name, QOpenGLTexture * texture, float x, float y, int item);
|
||||||
//create n covers with the default nu
|
//create n covers with the default nu
|
||||||
void populate(int n);
|
void populate(int n);
|
||||||
/*Info*/
|
/*Info*/
|
||||||
//retuns the CFImage Struct of the current selected item
|
//retuns the YACReader3DImage Struct of the current selected item
|
||||||
//to read title or textures
|
//to read title or textures
|
||||||
CFImage getCurrentSelected();
|
YACReader3DImage getCurrentSelected();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setCF_RX(int value);
|
void setCF_RX(int value);
|
||||||
@ -282,17 +285,6 @@ signals:
|
|||||||
void selected(unsigned int);
|
void selected(unsigned int);
|
||||||
};
|
};
|
||||||
|
|
||||||
//class WidgetLoader : public QGLWidget
|
|
||||||
//{
|
|
||||||
// Q_OBJECT
|
|
||||||
//public:
|
|
||||||
// WidgetLoader(QWidget *parent, QGLWidget * shared);
|
|
||||||
// YACReaderFlowGL * flow;
|
|
||||||
//public slots:
|
|
||||||
// void loadTexture(int index);
|
|
||||||
//
|
|
||||||
//};
|
|
||||||
|
|
||||||
class YACReaderComicFlowGL : public YACReaderFlowGL
|
class YACReaderComicFlowGL : public YACReaderFlowGL
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -329,8 +321,8 @@ public:
|
|||||||
// returns FALSE if worker is still busy and can't take the task
|
// returns FALSE if worker is still busy and can't take the task
|
||||||
bool busy() const;
|
bool busy() const;
|
||||||
void generate(int index, const QString& fileName);
|
void generate(int index, const QString& fileName);
|
||||||
void reset(){idx = -1;fileName="";};
|
void reset(){idx = -1;fileName="";}
|
||||||
int index() const { return idx; };
|
int index() const { return idx; }
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
QImage result();
|
QImage result();
|
||||||
@ -362,8 +354,8 @@ public:
|
|||||||
// returns FALSE if worker is still busy and can't take the task
|
// returns FALSE if worker is still busy and can't take the task
|
||||||
bool busy() const;
|
bool busy() const;
|
||||||
void generate(int index, const QByteArray& raw);
|
void generate(int index, const QByteArray& raw);
|
||||||
void reset(){idx = -1; rawData.clear();};
|
void reset(){idx = -1; rawData.clear();}
|
||||||
int index() const { return idx; };
|
int index() const { return idx; }
|
||||||
QImage result();
|
QImage result();
|
||||||
YACReaderFlowGL * flow;
|
YACReaderFlowGL * flow;
|
||||||
GLuint resultTexture;
|
GLuint resultTexture;
|
||||||
@ -385,18 +377,4 @@ private:
|
|||||||
QImage img;
|
QImage img;
|
||||||
};
|
};
|
||||||
|
|
||||||
//class TextureLoader : public QThread
|
|
||||||
//{
|
|
||||||
//public:
|
|
||||||
// TextureLoader();
|
|
||||||
// ~TextureLoader();
|
|
||||||
// // returns FALSE if worker is still busy and can't take the task
|
|
||||||
//
|
|
||||||
// YACReaderFlow * flow;
|
|
||||||
// ImageLoader * worker;
|
|
||||||
//protected:
|
|
||||||
// void run();
|
|
||||||
//
|
|
||||||
//};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user