code format
This commit is contained in:
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
QGL Buffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Buffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glbuffer.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
|
||||
|
||||
Buffer::Buffer(GLenum target, GLenum _usage) {
|
||||
target_ = target;
|
||||
usage_ = _usage;
|
||||
buffer_ = 0;
|
||||
target_ = target;
|
||||
usage_ = _usage;
|
||||
buffer_ = 0;
|
||||
prev_size = 0;
|
||||
}
|
||||
|
||||
|
||||
Buffer::~Buffer() {
|
||||
}
|
||||
Buffer::~Buffer() {}
|
||||
|
||||
|
||||
void Buffer::init(QOpenGLExtraFunctions * f) {
|
||||
@@ -49,13 +49,13 @@ void Buffer::destroy(QOpenGLExtraFunctions * f) {
|
||||
|
||||
|
||||
void Buffer::reinit() {
|
||||
buffer_ = 0;
|
||||
buffer_ = 0;
|
||||
prev_size = 0;
|
||||
}
|
||||
|
||||
|
||||
void Buffer::bind(QOpenGLExtraFunctions * f) {
|
||||
//qDebug() << "bind" << target_ << buffer_;
|
||||
// qDebug() << "bind" << target_ << buffer_;
|
||||
f->glBindBuffer(target_, buffer_);
|
||||
}
|
||||
|
||||
@@ -78,10 +78,10 @@ void Buffer::unmap(QOpenGLExtraFunctions * f) {
|
||||
|
||||
bool Buffer::resize(QOpenGLExtraFunctions * f, int new_size) {
|
||||
if (new_size <= 0) return false;
|
||||
//qDebug() << "check resize buffer" << buffer_ << "bytes" << new_size << ", old =" << prev_size;
|
||||
// qDebug() << "check resize buffer" << buffer_ << "bytes" << new_size << ", old =" << prev_size;
|
||||
if (new_size <= prev_size) return false;
|
||||
prev_size = new_size;
|
||||
//qDebug() << "resize buffer " << buffer_ << target_ << "for" << new_size << "bytes";
|
||||
// qDebug() << "resize buffer " << buffer_ << target_ << "for" << new_size << "bytes";
|
||||
f->glBufferData(target_, new_size, 0, usage_);
|
||||
return true;
|
||||
}
|
||||
@@ -89,6 +89,6 @@ bool Buffer::resize(QOpenGLExtraFunctions * f, int new_size) {
|
||||
|
||||
void Buffer::load(QOpenGLExtraFunctions * f, const void * data, int size, int offset) {
|
||||
if (!data || size <= 0) return;
|
||||
//qDebug() << "load buffer" << buffer_ << "bytes" << size;
|
||||
// qDebug() << "load buffer" << buffer_ << "bytes" << size;
|
||||
f->glBufferSubData(target_, offset, size, data);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGL Buffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Buffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLBUFFER_H
|
||||
@@ -22,37 +22,36 @@
|
||||
#include "gltypes.h"
|
||||
|
||||
|
||||
class Buffer
|
||||
{
|
||||
class Buffer {
|
||||
friend class ObjectBase;
|
||||
|
||||
public:
|
||||
Buffer(GLenum target, GLenum usage = GL_DYNAMIC_DRAW);
|
||||
~Buffer();
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
void init(QOpenGLExtraFunctions * f);
|
||||
void destroy(QOpenGLExtraFunctions * f);
|
||||
void reinit();
|
||||
|
||||
void bind (QOpenGLExtraFunctions * f);
|
||||
void release (QOpenGLExtraFunctions * f);
|
||||
void * map (QOpenGLExtraFunctions * f, GLbitfield mode, int size = -1);
|
||||
void unmap (QOpenGLExtraFunctions * f);
|
||||
void bind(QOpenGLExtraFunctions * f);
|
||||
void release(QOpenGLExtraFunctions * f);
|
||||
void * map(QOpenGLExtraFunctions * f, GLbitfield mode, int size = -1);
|
||||
void unmap(QOpenGLExtraFunctions * f);
|
||||
|
||||
// returns true if size changed
|
||||
bool resize (QOpenGLExtraFunctions * f, int new_size);
|
||||
void load (QOpenGLExtraFunctions * f, const void * data, int size, int offset = 0);
|
||||
bool resize(QOpenGLExtraFunctions * f, int new_size);
|
||||
void load(QOpenGLExtraFunctions * f, const void * data, int size, int offset = 0);
|
||||
|
||||
GLuint ID() const {return buffer_;}
|
||||
GLenum usage() const {return usage_;}
|
||||
GLenum target() const {return target_;}
|
||||
void setTarget(GLenum t) {target_ = t;}
|
||||
bool isInit() const {return buffer_ != 0;}
|
||||
GLuint ID() const { return buffer_; }
|
||||
GLenum usage() const { return usage_; }
|
||||
GLenum target() const { return target_; }
|
||||
void setTarget(GLenum t) { target_ = t; }
|
||||
bool isInit() const { return buffer_ != 0; }
|
||||
|
||||
private:
|
||||
GLenum target_, usage_;
|
||||
GLuint buffer_;
|
||||
int prev_size;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
/*
|
||||
QGL CubeTexture
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL CubeTexture
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gltypes.h"
|
||||
#include "glcubemap.h"
|
||||
|
||||
#include "gltypes.h"
|
||||
#include "hdr_p.h"
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
@@ -51,9 +52,9 @@ QVector<QVector3D> loadFileHDR(const QString & path, QSize * size) {
|
||||
qDebug() << "[QGLEngine] File" << path << "has unknown size!";
|
||||
return ret;
|
||||
}
|
||||
sz.setWidth (sl[3].toInt());
|
||||
sz.setWidth(sl[3].toInt());
|
||||
sz.setHeight(sl[1].toInt());
|
||||
//qDebug() << "found size" << sz;
|
||||
// qDebug() << "found size" << sz;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -61,26 +62,23 @@ QVector<QVector3D> loadFileHDR(const QString & path, QSize * size) {
|
||||
f.seek(ts.pos());
|
||||
QDataStream ds(&f);
|
||||
int count = sz.width() * sz.height();
|
||||
QVector<float> data(count*3);
|
||||
if (!RGBE_ReadPixels_RLE(&ds, data.data(), sz.width(), sz.height()))
|
||||
return ret;
|
||||
QVector<float> data(count * 3);
|
||||
if (!RGBE_ReadPixels_RLE(&ds, data.data(), sz.width(), sz.height())) return ret;
|
||||
|
||||
if (size) *size = sz;
|
||||
ret.resize(count);
|
||||
//QColor col;
|
||||
//QImage im(sz, QImage::Format_ARGB32);
|
||||
//QRgb * imdata = (QRgb*)im.bits();
|
||||
// QColor col;
|
||||
// QImage im(sz, QImage::Format_ARGB32);
|
||||
// QRgb * imdata = (QRgb*)im.bits();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
QVector3D p(pow(data[i*3 + 2], 1. / 2.2),
|
||||
pow(data[i*3 + 1], 1. / 2.2),
|
||||
pow(data[i*3 + 0], 1. / 2.2));
|
||||
QVector3D p(pow(data[i * 3 + 2], 1. / 2.2), pow(data[i * 3 + 1], 1. / 2.2), pow(data[i * 3 + 0], 1. / 2.2));
|
||||
ret[i] = p;
|
||||
//col = QColor::fromRgbF(piClamp(p[0], 0.f, 1.f),
|
||||
// col = QColor::fromRgbF(piClamp(p[0], 0.f, 1.f),
|
||||
// piClamp(p[1], 0.f, 1.f),
|
||||
// piClamp(p[2], 0.f, 1.f));
|
||||
//imdata[i] = col.rgb();
|
||||
// imdata[i] = col.rgb();
|
||||
}
|
||||
//im.save("_hdr.png");
|
||||
// im.save("_hdr.png");
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -90,72 +88,71 @@ QVector<QVector3D> faceHDR(const QVector<QVector3D> & data, QSize sz, QSize & fs
|
||||
QVector<QVector3D> ret;
|
||||
if (data.isEmpty() || sz.isNull()) return ret;
|
||||
QRect fr;
|
||||
int fw = sz.width () / 4;
|
||||
int fw = sz.width() / 4;
|
||||
int fh = sz.height() / 3;
|
||||
fsz = QSize(fw, fh);
|
||||
fsz = QSize(fw, fh);
|
||||
ret.reserve(fw * fh);
|
||||
switch (face) {
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
||||
fr.setRect(fw, fh, fw, fh);
|
||||
for (int x = fr.left(); x <= fr.right(); ++x) {
|
||||
for (int y = fr.top(); y <= fr.bottom(); ++y) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
||||
fr.setRect(fw*3, fh, fw, fh);
|
||||
fr.setRect(fw * 3, fh, fw, fh);
|
||||
for (int x = fr.right(); x >= fr.left(); --x) {
|
||||
for (int y = fr.bottom(); y >= fr.top(); --y) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
||||
fr.setRect( 0, fh, fw, fh);
|
||||
fr.setRect(0, fh, fw, fh);
|
||||
for (int y = fr.bottom(); y >= fr.top(); --y) {
|
||||
for (int x = fr.left(); x <= fr.right(); ++x) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
||||
fr.setRect(fw*2, fh, fw, fh);
|
||||
fr.setRect(fw * 2, fh, fw, fh);
|
||||
for (int y = fr.top(); y <= fr.bottom(); ++y) {
|
||||
for (int x = fr.right(); x >= fr.left(); --x) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
||||
fr.setRect(fw, 0, fw, fh);
|
||||
fr.setRect(fw, 0, fw, fh);
|
||||
for (int x = fr.left(); x <= fr.right(); ++x) {
|
||||
for (int y = fr.top(); y <= fr.bottom(); ++y) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
||||
fr.setRect(fw, fh*2, fw, fh);
|
||||
fr.setRect(fw, fh * 2, fw, fh);
|
||||
for (int x = fr.left(); x <= fr.right(); ++x) {
|
||||
for (int y = fr.top(); y <= fr.bottom(); ++y) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
if (fr.isEmpty()) return ret;
|
||||
//qDebug() << ret.size() << fr;
|
||||
// qDebug() << ret.size() << fr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CubeTexture::CubeTexture(QOpenGLExtraFunctions * f_, int _size, const GLenum & _format): f(f_) {
|
||||
size = _size;
|
||||
format_ = _format;
|
||||
id_ = 0;
|
||||
size = _size;
|
||||
format_ = _format;
|
||||
id_ = 0;
|
||||
changed_ = false;
|
||||
}
|
||||
|
||||
@@ -199,9 +196,17 @@ void CubeTexture::loadHDR(const QVector<QVector3D> & data, QSize sz) {
|
||||
QVector<QVector3D> fd;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
fd = faceHDR(data, sz, fsz, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
|
||||
//qDebug() << "load cube" << fd[0];
|
||||
f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format_, fsz.width(), fsz.height(), 0, GL_RGB, GL_FLOAT, fd.isEmpty() ? 0 : fd.constData());
|
||||
//qDebug() << QString::number(GetLastError(), 16);
|
||||
// qDebug() << "load cube" << fd[0];
|
||||
f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
|
||||
0,
|
||||
format_,
|
||||
fsz.width(),
|
||||
fsz.height(),
|
||||
0,
|
||||
GL_RGB,
|
||||
GL_FLOAT,
|
||||
fd.isEmpty() ? 0 : fd.constData());
|
||||
// qDebug() << QString::number(GetLastError(), 16);
|
||||
}
|
||||
f->glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
||||
}
|
||||
@@ -230,4 +235,3 @@ void CubeTexture::load() {
|
||||
}
|
||||
changed_ = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
/*
|
||||
QGL CubeTexture
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL CubeTexture
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLCUBEMAP_H
|
||||
#define GLCUBEMAP_H
|
||||
|
||||
#include "glshaders_types.h"
|
||||
#include "chunkstream.h"
|
||||
#include "glshaders_types.h"
|
||||
|
||||
QVector<QVector3D> loadFileHDR(const QString & path, QSize * size = 0);
|
||||
|
||||
@@ -31,17 +31,23 @@ public:
|
||||
void destroy();
|
||||
void bind(int channel = 0);
|
||||
void release();
|
||||
void resize(int _size) {size = _size; changed_ = true;}
|
||||
void resize(int _size) {
|
||||
size = _size;
|
||||
changed_ = true;
|
||||
}
|
||||
void loadHDR(const QVector<QVector3D> & data, QSize sz);
|
||||
void setFileHDR(const QString & path);
|
||||
QString fileHDR() const {return hdr_path;}
|
||||
GLenum format() const {return format_;}
|
||||
void setFormat(GLenum f) {format_ = f; changed_ = true;}
|
||||
GLuint id() const {return id_;}
|
||||
bool isInit() const {return id_ != 0;}
|
||||
QString fileHDR() const { return hdr_path; }
|
||||
GLenum format() const { return format_; }
|
||||
void setFormat(GLenum f) {
|
||||
format_ = f;
|
||||
changed_ = true;
|
||||
}
|
||||
GLuint id() const { return id_; }
|
||||
bool isInit() const { return id_ != 0; }
|
||||
void load();
|
||||
private:
|
||||
|
||||
private:
|
||||
QOpenGLExtraFunctions * f;
|
||||
bool changed_;
|
||||
int size;
|
||||
|
||||
@@ -1,51 +1,54 @@
|
||||
/*
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glframebuffer.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QTime>
|
||||
|
||||
|
||||
Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments_, bool withDepth, GLenum colorFormat_, GLenum _target)
|
||||
: f(f_), pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
: f(f_)
|
||||
, pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
is_depth = withDepth;
|
||||
target_ = _target;
|
||||
target_ = _target;
|
||||
color_formats.fill(colorFormat_, colorAttachments_);
|
||||
colors.fill(0, colorAttachments_);
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = false;
|
||||
is_changed = false;
|
||||
}
|
||||
|
||||
|
||||
Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth, GLenum _target)
|
||||
: f(f_), pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
is_depth = withDepth;
|
||||
target_ = _target;
|
||||
: f(f_)
|
||||
, pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
is_depth = withDepth;
|
||||
target_ = _target;
|
||||
color_formats = colors_;
|
||||
colors.fill(0, colors_.size());
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = false;
|
||||
is_changed = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +70,7 @@ void Framebuffer::resize(int width, int height, bool force) {
|
||||
if (fbo > 0) deleteGLFramebuffer(fbo);
|
||||
f->glGenFramebuffers(1, &fbo);
|
||||
f->glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
//qDebug() << "resize" << f << wid << hei << fbo;
|
||||
// qDebug() << "resize" << f << wid << hei << fbo;
|
||||
for (int i = 0; i < colors.size(); ++i) {
|
||||
deleteGLTexture(f, colors[i]);
|
||||
createGLTexture(f, colors[i], width, height, color_formats[i], target_);
|
||||
@@ -103,10 +106,10 @@ void Framebuffer::resize(int width, int height, bool force) {
|
||||
void Framebuffer::reinit() {
|
||||
pbo.reinit();
|
||||
colors.fill(0);
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = true;
|
||||
is_changed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,8 +155,7 @@ uint Framebuffer::getPoint() const {
|
||||
uint ret = 0;
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, sizeof(uint));
|
||||
if (map)
|
||||
memcpy(&ret, map, sizeof(uint));
|
||||
if (map) memcpy(&ret, map, sizeof(uint));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -166,8 +168,7 @@ QVector<uint> Framebuffer::getPointsByte() const {
|
||||
ret.resize(pbo_queried);
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(uint));
|
||||
if (map)
|
||||
memcpy(ret.data(), map, pbo_queried * sizeof(uint));
|
||||
if (map) memcpy(ret.data(), map, pbo_queried * sizeof(uint));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -180,8 +181,7 @@ QVector<QVector4D> Framebuffer::getPointsFloat() const {
|
||||
ret.resize(pbo_queried);
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(QVector4D));
|
||||
if (map)
|
||||
memcpy(ret.data(), map, pbo_queried * sizeof(QVector4D));
|
||||
if (map) memcpy(ret.data(), map, pbo_queried * sizeof(QVector4D));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -191,12 +191,11 @@ QVector<QVector4D> Framebuffer::getPointsFloat() const {
|
||||
QImage Framebuffer::getImage() const {
|
||||
QImage ret;
|
||||
if (!pbo.isInit() || (pbo_queried == 0)) return ret;
|
||||
ret = QImage(size(), QImage::Format_RGBA8888);
|
||||
ret = QImage(size(), QImage::Format_RGBA8888);
|
||||
int bytes = width() * height() * 4;
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, bytes);
|
||||
if (map)
|
||||
memcpy(ret.bits(), map, bytes);
|
||||
if (map) memcpy(ret.bits(), map, bytes);
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -277,7 +276,7 @@ void Framebuffer::unsetWriteBuffers() {
|
||||
void Framebuffer::enablePixelBuffer() {
|
||||
pbo.init(f);
|
||||
pbo.bind(f);
|
||||
pbo.resize(f, width()*height()*4*4);
|
||||
pbo.resize(f, width() * height() * 4 * 4);
|
||||
pbo.release(f);
|
||||
}
|
||||
|
||||
@@ -311,14 +310,12 @@ void Framebuffer::bindDepthTexture(int channel) {
|
||||
|
||||
|
||||
void Framebuffer::deleteGLRenderbuffer(GLuint & drbo) {
|
||||
if (drbo != 0)
|
||||
f->glDeleteRenderbuffers(1, &drbo);
|
||||
if (drbo != 0) f->glDeleteRenderbuffers(1, &drbo);
|
||||
drbo = 0;
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::deleteGLFramebuffer(GLuint & fbo) {
|
||||
if (fbo != 0)
|
||||
f->glDeleteFramebuffers(1, &fbo);
|
||||
if (fbo != 0) f->glDeleteFramebuffers(1, &fbo);
|
||||
fbo = 0;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLFRAMEBUFFER_H
|
||||
@@ -22,23 +22,27 @@
|
||||
#include "glbuffer.h"
|
||||
|
||||
|
||||
class Framebuffer
|
||||
{
|
||||
class Framebuffer {
|
||||
friend class FramebufferMipmap;
|
||||
|
||||
public:
|
||||
Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments = 1, bool withDepth = true, GLenum colorFormat = GL_RGBA8, GLenum _target = GL_TEXTURE_2D);
|
||||
Framebuffer(QOpenGLExtraFunctions * f_,
|
||||
int colorAttachments = 1,
|
||||
bool withDepth = true,
|
||||
GLenum colorFormat = GL_RGBA8,
|
||||
GLenum _target = GL_TEXTURE_2D);
|
||||
Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth = true, GLenum _target = GL_TEXTURE_2D);
|
||||
virtual ~Framebuffer();
|
||||
|
||||
GLuint id() const {return fbo;}
|
||||
GLuint colorTexture(int index = 0) const {return colors[index];}
|
||||
GLuint depthTexture() const {return tex_d;}
|
||||
GLenum target() const {return target_;}
|
||||
bool isInit() const {return fbo != 0;}
|
||||
int width() const {return wid;}
|
||||
int height() const {return hei;}
|
||||
QSize size() const {return QSize(wid, hei);}
|
||||
QRect rect() const {return QRect(0, 0, wid, hei);}
|
||||
GLuint id() const { return fbo; }
|
||||
GLuint colorTexture(int index = 0) const { return colors[index]; }
|
||||
GLuint depthTexture() const { return tex_d; }
|
||||
GLenum target() const { return target_; }
|
||||
bool isInit() const { return fbo != 0; }
|
||||
int width() const { return wid; }
|
||||
int height() const { return hei; }
|
||||
QSize size() const { return QSize(wid, hei); }
|
||||
QRect rect() const { return QRect(0, 0, wid, hei); }
|
||||
QImage grab() const;
|
||||
QVector<float> grabF(int index) const;
|
||||
void queryPoint(int index, QPoint p);
|
||||
@@ -48,23 +52,29 @@ public:
|
||||
QVector<uint> getPointsByte() const;
|
||||
QVector<QVector4D> getPointsFloat() const;
|
||||
QImage getImage() const;
|
||||
int queriedPoints() const {return pbo_queried;}
|
||||
void blit(int index_from, GLuint fb_to, int index_to, QRect from, QRect to, GLbitfield mask = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST) const;
|
||||
int queriedPoints() const { return pbo_queried; }
|
||||
void blit(int index_from,
|
||||
GLuint fb_to,
|
||||
int index_to,
|
||||
QRect from,
|
||||
QRect to,
|
||||
GLbitfield mask = GL_COLOR_BUFFER_BIT,
|
||||
GLenum filter = GL_NEAREST) const;
|
||||
|
||||
void resize(int width, int height, bool force = false);
|
||||
void reinit();
|
||||
void bind();
|
||||
void release();
|
||||
void setReadBuffer(int index) {glReadBuffer(GL_COLOR_ATTACHMENT0 + index);}
|
||||
void setReadBuffer(int index) { glReadBuffer(GL_COLOR_ATTACHMENT0 + index); }
|
||||
void setWriteBuffer(int index);
|
||||
void setWriteBuffers(const int * indeces, int count);
|
||||
void setWriteBuffers(const QVector<int> & indeces) {setWriteBuffers(indeces.constData(), indeces.size());}
|
||||
void setWriteBuffers(const QVector<int> & indeces) { setWriteBuffers(indeces.constData(), indeces.size()); }
|
||||
void setWriteBuffers();
|
||||
void unsetWriteBuffers();
|
||||
void enablePixelBuffer();
|
||||
void setColorTextureFiltering(int index, GLenum filter);
|
||||
|
||||
void copyDepthFrom(GLuint tex) {;}
|
||||
void copyDepthFrom(GLuint tex) { ; }
|
||||
void bindColorTexture(int index, int channel = 0);
|
||||
void bindColorTextures();
|
||||
void bindDepthTexture(int channel);
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
/*
|
||||
QGL FramebufferMipmap
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL FramebufferMipmap
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glframebuffer_mipmap.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QTime>
|
||||
|
||||
|
||||
@@ -28,9 +29,7 @@ FramebufferMipmap::FramebufferMipmap(const Framebuffer & fb, int index_from_, in
|
||||
}
|
||||
|
||||
|
||||
FramebufferMipmap::~FramebufferMipmap() {
|
||||
|
||||
}
|
||||
FramebufferMipmap::~FramebufferMipmap() {}
|
||||
|
||||
|
||||
void FramebufferMipmap::resize() {
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGL FramebufferMipmap
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL FramebufferMipmap
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLFRAMEBUFFER_MIPMAP_H
|
||||
@@ -22,20 +22,19 @@
|
||||
#include "glframebuffer.h"
|
||||
|
||||
|
||||
class FramebufferMipmap
|
||||
{
|
||||
class FramebufferMipmap {
|
||||
public:
|
||||
FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels = 2);
|
||||
virtual ~FramebufferMipmap();
|
||||
|
||||
int levelsCount() const {return fbo.size();}
|
||||
int lastLevel() const {return fbo.size() - 1;}
|
||||
Framebuffer & plane(int level) {return *fbo[level];}
|
||||
Framebuffer & lastPlane() {return *fbo[lastLevel()];}
|
||||
int width (int level) const {return fbo[level]->wid;}
|
||||
int height(int level) const {return fbo[level]->hei;}
|
||||
QSize size(int level) const {return fbo[level]->size();}
|
||||
QRect rect(int level) const {return fbo[level]->rect();}
|
||||
int levelsCount() const { return fbo.size(); }
|
||||
int lastLevel() const { return fbo.size() - 1; }
|
||||
Framebuffer & plane(int level) { return *fbo[level]; }
|
||||
Framebuffer & lastPlane() { return *fbo[lastLevel()]; }
|
||||
int width(int level) const { return fbo[level]->wid; }
|
||||
int height(int level) const { return fbo[level]->hei; }
|
||||
QSize size(int level) const { return fbo[level]->size(); }
|
||||
QRect rect(int level) const { return fbo[level]->rect(); }
|
||||
|
||||
void resize();
|
||||
void create();
|
||||
@@ -44,8 +43,7 @@ public:
|
||||
private:
|
||||
int index_from;
|
||||
const Framebuffer & src_fb;
|
||||
QVector<Framebuffer*> fbo;
|
||||
|
||||
QVector<Framebuffer *> fbo;
|
||||
};
|
||||
|
||||
#endif // GLFRAMEBUFFER_MIPMAP_H
|
||||
|
||||
@@ -1,48 +1,47 @@
|
||||
/*
|
||||
QGL Material
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Material
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gltypes.h"
|
||||
#include "gltexture_manager.h"
|
||||
#include "gltypes.h"
|
||||
#include "qglview.h"
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
|
||||
Map::Map() {
|
||||
bitmap_id = 0;
|
||||
bitmap_id = 0;
|
||||
color_amount = 1.f;
|
||||
color_offset = 0.f;
|
||||
bitmap_scale = QPointF(1., 1.);
|
||||
use_bitmap = false;
|
||||
_changed = true;
|
||||
_layer = 0;
|
||||
use_bitmap = false;
|
||||
_changed = true;
|
||||
_layer = 0;
|
||||
}
|
||||
|
||||
|
||||
void Map::setBitmapPath(const QString & p) {
|
||||
bitmap_path = p;
|
||||
_changed = true;
|
||||
_changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Map::load(TextureManager * tm) {
|
||||
if (bitmap_id == 0)
|
||||
bitmap_id = tm->loadTexture(bitmap_path, true, _type == mtNormal);
|
||||
if (bitmap_id == 0) bitmap_id = tm->loadTexture(bitmap_path, true, _type == mtNormal);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,21 +59,19 @@ void Map::copyToQGLMap(QGLMap & m) const {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Material::Material(const QString _name) {
|
||||
setTypes();
|
||||
name = _name;
|
||||
color_diffuse = Qt::white;
|
||||
name = _name;
|
||||
color_diffuse = Qt::white;
|
||||
color_emission = Qt::black;
|
||||
glass = false;
|
||||
glass = false;
|
||||
transparency = reflectivity = 0.f;
|
||||
map_roughness.color_amount = 0.75f;
|
||||
map_metalness.color_amount = 0.25f;
|
||||
iof = 1.f;
|
||||
dispersion = 0.05f;
|
||||
_changed = true;
|
||||
_index = 0;
|
||||
map_roughness.color_amount = 0.75f;
|
||||
map_metalness.color_amount = 0.25f;
|
||||
iof = 1.f;
|
||||
dispersion = 0.05f;
|
||||
_changed = true;
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,63 +86,59 @@ bool Material::hasTransparency() const {
|
||||
|
||||
|
||||
bool Material::isMapsChanged() const {
|
||||
return map_diffuse ._changed ||
|
||||
map_normal ._changed ||
|
||||
map_metalness._changed ||
|
||||
map_roughness._changed ||
|
||||
map_emission ._changed ||
|
||||
map_relief ._changed;
|
||||
return map_diffuse._changed || map_normal._changed || map_metalness._changed || map_roughness._changed || map_emission._changed ||
|
||||
map_relief._changed;
|
||||
}
|
||||
|
||||
|
||||
bool Material::isMapChanged(int type) const {
|
||||
switch (type) {
|
||||
case mtDiffuse : return map_diffuse ._changed;
|
||||
case mtNormal : return map_normal ._changed;
|
||||
case mtDiffuse: return map_diffuse._changed;
|
||||
case mtNormal: return map_normal._changed;
|
||||
case mtMetalness: return map_metalness._changed;
|
||||
case mtRoughness: return map_roughness._changed;
|
||||
case mtEmission : return map_emission ._changed;
|
||||
case mtRelief : return map_relief ._changed;
|
||||
case mtEmission: return map_emission._changed;
|
||||
case mtRelief: return map_relief._changed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Material::load(TextureManager * tm) {
|
||||
map_diffuse .load(tm);
|
||||
map_normal .load(tm);
|
||||
map_diffuse.load(tm);
|
||||
map_normal.load(tm);
|
||||
map_metalness.load(tm);
|
||||
map_roughness.load(tm);
|
||||
map_emission .load(tm);
|
||||
map_relief .load(tm);
|
||||
map_emission.load(tm);
|
||||
map_relief.load(tm);
|
||||
}
|
||||
|
||||
|
||||
void Material::setMapsChanged() {
|
||||
map_diffuse ._changed = true;
|
||||
map_normal ._changed = true;
|
||||
map_diffuse._changed = true;
|
||||
map_normal._changed = true;
|
||||
map_metalness._changed = true;
|
||||
map_roughness._changed = true;
|
||||
map_emission ._changed = true;
|
||||
map_relief ._changed = true;
|
||||
map_emission._changed = true;
|
||||
map_relief._changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Material::setTypes() {
|
||||
map_diffuse ._type = mtDiffuse ;
|
||||
map_normal ._type = mtNormal ;
|
||||
map_diffuse._type = mtDiffuse;
|
||||
map_normal._type = mtNormal;
|
||||
map_metalness._type = mtMetalness;
|
||||
map_roughness._type = mtRoughness;
|
||||
map_emission ._type = mtEmission ;
|
||||
map_relief ._type = mtRelief ;
|
||||
map_emission._type = mtEmission;
|
||||
map_relief._type = mtRelief;
|
||||
}
|
||||
|
||||
|
||||
void Material::detectMaps() {
|
||||
map_diffuse .use_bitmap = !map_diffuse .bitmap_path.isEmpty();
|
||||
map_normal .use_bitmap = !map_normal .bitmap_path.isEmpty();
|
||||
map_diffuse.use_bitmap = !map_diffuse.bitmap_path.isEmpty();
|
||||
map_normal.use_bitmap = !map_normal.bitmap_path.isEmpty();
|
||||
map_metalness.use_bitmap = !map_metalness.bitmap_path.isEmpty();
|
||||
map_roughness.use_bitmap = !map_roughness.bitmap_path.isEmpty();
|
||||
map_emission .use_bitmap = !map_emission .bitmap_path.isEmpty();
|
||||
map_relief .use_bitmap = !map_relief .bitmap_path.isEmpty();
|
||||
map_emission.use_bitmap = !map_emission.bitmap_path.isEmpty();
|
||||
map_relief.use_bitmap = !map_relief.bitmap_path.isEmpty();
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
/*
|
||||
QGL Material
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Material
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLMATERIAL_H
|
||||
#define GLMATERIAL_H
|
||||
|
||||
#include "glshaders_types.h"
|
||||
#include "chunkstream.h"
|
||||
#include "glshaders_types.h"
|
||||
|
||||
|
||||
class Map {
|
||||
public:
|
||||
Map();
|
||||
void setBitmapPath(const QString & p);
|
||||
void clearBitmap() {setBitmapPath(QString());}
|
||||
bool hasBitmap() const {return !bitmap_path.isEmpty();}
|
||||
void clearBitmap() { setBitmapPath(QString()); }
|
||||
bool hasBitmap() const { return !bitmap_path.isEmpty(); }
|
||||
void load(TextureManager * tm);
|
||||
void copyToQGLMap(QGLEngineShaders::QGLMap & m) const;
|
||||
QString bitmap_path;
|
||||
GLuint bitmap_id;
|
||||
GLuint bitmap_id;
|
||||
QPointF bitmap_offset;
|
||||
QPointF bitmap_scale;
|
||||
float color_amount;
|
||||
@@ -62,51 +62,60 @@ public:
|
||||
float reflectivity;
|
||||
float iof;
|
||||
float dispersion;
|
||||
Map map_diffuse ;
|
||||
Map map_normal ;
|
||||
Map map_diffuse;
|
||||
Map map_normal;
|
||||
Map map_metalness;
|
||||
Map map_roughness;
|
||||
Map map_emission ;
|
||||
Map map_relief ;
|
||||
Map map_emission;
|
||||
Map map_relief;
|
||||
bool _changed;
|
||||
int _index;
|
||||
};
|
||||
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Map & m) {
|
||||
inline QDataStream & operator<<(QDataStream & s, const Map & m) {
|
||||
ChunkStream cs;
|
||||
cs.add(1, m.bitmap_path).add(2, m.color_amount).add(3, m.color_offset).add(6, m.bitmap_scale)
|
||||
.add(7, m.use_bitmap);
|
||||
s << cs.data(); return s;
|
||||
cs.add(1, m.bitmap_path).add(2, m.color_amount).add(3, m.color_offset).add(6, m.bitmap_scale).add(7, m.use_bitmap);
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, Map & m) {
|
||||
inline QDataStream & operator>>(QDataStream & s, Map & m) {
|
||||
ChunkStream cs(s);
|
||||
cs.readAll();
|
||||
cs.get(1, m.bitmap_path).get(2, m.color_amount).get(3, m.color_offset).get(6, m.bitmap_scale)
|
||||
.get(7, m.use_bitmap);
|
||||
cs.get(1, m.bitmap_path).get(2, m.color_amount).get(3, m.color_offset).get(6, m.bitmap_scale).get(7, m.use_bitmap);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Material * m) {
|
||||
inline QDataStream & operator<<(QDataStream & s, const Material * m) {
|
||||
ChunkStream cs;
|
||||
cs.add(1, m->name).add(2, m->color_diffuse).add(4, m->color_emission)
|
||||
.add(5, m->transparency).add(6, m->reflectivity).add(7, m->glass).add(8, m->map_diffuse).add(9, m->map_normal)
|
||||
.add(10, m->map_relief).add(11, m->map_metalness).add(12, m->map_roughness).add(13, m->map_emission);
|
||||
s << (cs.data()); return s;
|
||||
cs.add(1, m->name)
|
||||
.add(2, m->color_diffuse)
|
||||
.add(4, m->color_emission)
|
||||
.add(5, m->transparency)
|
||||
.add(6, m->reflectivity)
|
||||
.add(7, m->glass)
|
||||
.add(8, m->map_diffuse)
|
||||
.add(9, m->map_normal)
|
||||
.add(10, m->map_relief)
|
||||
.add(11, m->map_metalness)
|
||||
.add(12, m->map_roughness)
|
||||
.add(13, m->map_emission);
|
||||
s << (cs.data());
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, Material *& m) {
|
||||
inline QDataStream & operator>>(QDataStream & s, Material *& m) {
|
||||
m = new Material();
|
||||
ChunkStream cs(s);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: cs.get(m->name); break;
|
||||
case 2: cs.get(m->color_diffuse); break;
|
||||
case 4: cs.get(m->color_emission); break;
|
||||
case 5: cs.get(m->transparency); break;
|
||||
case 6: cs.get(m->reflectivity); break;
|
||||
case 7: cs.get(m->glass); break;
|
||||
case 8: cs.get(m->map_diffuse); break;
|
||||
case 9: cs.get(m->map_normal); break;
|
||||
case 1: cs.get(m->name); break;
|
||||
case 2: cs.get(m->color_diffuse); break;
|
||||
case 4: cs.get(m->color_emission); break;
|
||||
case 5: cs.get(m->transparency); break;
|
||||
case 6: cs.get(m->reflectivity); break;
|
||||
case 7: cs.get(m->glass); break;
|
||||
case 8: cs.get(m->map_diffuse); break;
|
||||
case 9: cs.get(m->map_normal); break;
|
||||
case 10: cs.get(m->map_relief); break;
|
||||
case 11: cs.get(m->map_metalness); break;
|
||||
case 12: cs.get(m->map_roughness); break;
|
||||
|
||||
185
core/glmesh.cpp
185
core/glmesh.cpp
@@ -1,56 +1,59 @@
|
||||
/*
|
||||
QGL Mesh
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Mesh
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glmesh.h"
|
||||
|
||||
#include "globject.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QTime>
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
//static int _count = 0;
|
||||
// static int _count = 0;
|
||||
|
||||
Mesh::Mesh(GLenum geom_type_): geom_type(geom_type_),
|
||||
buffer_geom(GL_ARRAY_BUFFER, GL_STATIC_DRAW),
|
||||
buffer_ind (GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW) {
|
||||
hash_ = 0;
|
||||
Mesh::Mesh(GLenum geom_type_)
|
||||
: geom_type(geom_type_)
|
||||
, buffer_geom(GL_ARRAY_BUFFER, GL_STATIC_DRAW)
|
||||
, buffer_ind(GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW) {
|
||||
hash_ = 0;
|
||||
changed = hash_changed = true;
|
||||
//qDebug() << "Mesh, now" << ++_count;
|
||||
// qDebug() << "Mesh, now" << ++_count;
|
||||
}
|
||||
|
||||
|
||||
Mesh::~Mesh() {
|
||||
//qDebug() << "~Mesh, now" << --_count;
|
||||
// qDebug() << "~Mesh, now" << --_count;
|
||||
}
|
||||
|
||||
|
||||
Mesh * Mesh::clone() {
|
||||
Mesh * c = new Mesh();
|
||||
c->vertices_ = vertices_ ;
|
||||
c->normals_ = normals_ ;
|
||||
c->texcoords_ = texcoords_;
|
||||
c->triangles_ = triangles_;
|
||||
c->lines_ = lines_;
|
||||
c->geom_type = geom_type;
|
||||
c->hash_ = hash_;
|
||||
Mesh * c = new Mesh();
|
||||
c->vertices_ = vertices_;
|
||||
c->normals_ = normals_;
|
||||
c->texcoords_ = texcoords_;
|
||||
c->triangles_ = triangles_;
|
||||
c->lines_ = lines_;
|
||||
c->geom_type = geom_type;
|
||||
c->hash_ = hash_;
|
||||
c->hash_changed = hash_changed;
|
||||
//qDebug() << "clone VBO";
|
||||
// qDebug() << "clone VBO";
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -58,7 +61,7 @@ Mesh * Mesh::clone() {
|
||||
void Mesh::init(QOpenGLExtraFunctions * f) {
|
||||
if (!isInit()) {
|
||||
buffer_geom.init(f);
|
||||
buffer_ind .init(f);
|
||||
buffer_ind.init(f);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@@ -66,8 +69,8 @@ void Mesh::init(QOpenGLExtraFunctions * f) {
|
||||
|
||||
void Mesh::reinit() {
|
||||
buffer_geom.reinit();
|
||||
buffer_ind .reinit();
|
||||
QMapIterator<int, VertexObject * > it(vao_map);
|
||||
buffer_ind.reinit();
|
||||
QMapIterator<int, VertexObject *> it(vao_map);
|
||||
while (it.hasNext())
|
||||
it.next().value()->reinit();
|
||||
changed = true;
|
||||
@@ -76,9 +79,9 @@ void Mesh::reinit() {
|
||||
|
||||
void Mesh::destroy(QOpenGLExtraFunctions * f) {
|
||||
buffer_geom.destroy(f);
|
||||
buffer_ind .destroy(f);
|
||||
QList<VertexObject*> vaol = vao_map.values();
|
||||
foreach (VertexObject* vao, vaol)
|
||||
buffer_ind.destroy(f);
|
||||
QList<VertexObject *> vaol = vao_map.values();
|
||||
foreach(VertexObject * vao, vaol)
|
||||
vao->destroy(f);
|
||||
qDeleteAll(vao_map);
|
||||
vao_map.clear();
|
||||
@@ -88,12 +91,12 @@ void Mesh::destroy(QOpenGLExtraFunctions * f) {
|
||||
void Mesh::calculateNormals() {
|
||||
normals_.resize(vertices_.size());
|
||||
QVector3D dv1, dv2, n;
|
||||
foreach (const Vector3i & t, triangles_) {
|
||||
foreach(const Vector3i & t, triangles_) {
|
||||
QVector3D & v0(vertices_[t.p0]);
|
||||
QVector3D & v1(vertices_[t.p1]);
|
||||
QVector3D & v2(vertices_[t.p2]);
|
||||
dv1 = v1 - v0, dv2 = v2 - v0;
|
||||
n = QVector3D::crossProduct(dv1, dv2).normalized();
|
||||
n = QVector3D::crossProduct(dv1, dv2).normalized();
|
||||
normals_[t.p0] = n;
|
||||
normals_[t.p1] = n;
|
||||
normals_[t.p2] = n;
|
||||
@@ -104,32 +107,32 @@ void Mesh::calculateNormals() {
|
||||
void Mesh::calculateTangents() {
|
||||
if (vertices_.isEmpty() || texcoords_.isEmpty()) return;
|
||||
if (texcoords_.size() != vertices_.size()) return;
|
||||
tangents_ .resize(vertices_.size());
|
||||
tangents_.resize(vertices_.size());
|
||||
bitangents_.resize(vertices_.size());
|
||||
//qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
// qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
QVector3D dv1, dv2;
|
||||
QVector2D dt1, dt2;
|
||||
QVector3D tan, bitan;
|
||||
foreach (const Vector3i & t, triangles_) {
|
||||
QVector3D & v0(vertices_ [t.p0]);
|
||||
QVector3D & v1(vertices_ [t.p1]);
|
||||
QVector3D & v2(vertices_ [t.p2]);
|
||||
foreach(const Vector3i & t, triangles_) {
|
||||
QVector3D & v0(vertices_[t.p0]);
|
||||
QVector3D & v1(vertices_[t.p1]);
|
||||
QVector3D & v2(vertices_[t.p2]);
|
||||
QVector2D & t0(texcoords_[t.p0]);
|
||||
QVector2D & t1(texcoords_[t.p1]);
|
||||
QVector2D & t2(texcoords_[t.p2]);
|
||||
dv1 = v1 - v0, dv2 = v2 - v0;
|
||||
dt1 = t1 - t0, dt2 = t2 - t0;
|
||||
tan = (dv1 * dt2.y() - dv2 * dt1.y()).normalized();
|
||||
bitan = (dv2 * dt1.x() - dv1 * dt2.x()).normalized();
|
||||
tangents_ [t.p0] = tan;
|
||||
tangents_ [t.p1] = tan;
|
||||
tangents_ [t.p2] = tan;
|
||||
tan = (dv1 * dt2.y() - dv2 * dt1.y()).normalized();
|
||||
bitan = (dv2 * dt1.x() - dv1 * dt2.x()).normalized();
|
||||
tangents_[t.p0] = tan;
|
||||
tangents_[t.p1] = tan;
|
||||
tangents_[t.p2] = tan;
|
||||
bitangents_[t.p0] = bitan;
|
||||
bitangents_[t.p1] = bitan;
|
||||
bitangents_[t.p2] = bitan;
|
||||
//qDebug() << " t" << t << vi << ti << dv1.toQVector3D() << "...";
|
||||
// qDebug() << " t" << t << vi << ti << dv1.toQVector3D() << "...";
|
||||
}
|
||||
//qDebug() << "calculateBinormals" << vcnt << tcnt << tangents_.size();
|
||||
// qDebug() << "calculateBinormals" << vcnt << tcnt << tangents_.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -145,8 +148,7 @@ VertexObject * Mesh::vaoByType(int type) {
|
||||
bool Mesh::rebuffer(QOpenGLExtraFunctions * f) {
|
||||
changed = false;
|
||||
if (vertices_.isEmpty()) return true;
|
||||
if (normals_.isEmpty())
|
||||
calculateNormals();
|
||||
if (normals_.isEmpty()) calculateNormals();
|
||||
calculateTangents();
|
||||
vert_count = qMin(vertices_.size(), normals_.size());
|
||||
vert_count = qMin(vert_count, tangents_.size());
|
||||
@@ -155,11 +157,11 @@ bool Mesh::rebuffer(QOpenGLExtraFunctions * f) {
|
||||
data_.resize(vert_count);
|
||||
for (int i = 0; i < vert_count; ++i) {
|
||||
Vertex & v(data_[i]);
|
||||
v.pos = vertices_ [i];
|
||||
v.normal = normals_ [i];
|
||||
v.tangent = tangents_ [i];
|
||||
v.pos = vertices_[i];
|
||||
v.normal = normals_[i];
|
||||
v.tangent = tangents_[i];
|
||||
v.bitangent = bitangents_[i];
|
||||
v.tex = texcoords_ [i];
|
||||
v.tex = texcoords_[i];
|
||||
}
|
||||
int gsize = data_.size() * sizeof(Vertex);
|
||||
int tsize = triangles_.size() * sizeof(Vector3i);
|
||||
@@ -186,7 +188,7 @@ void Mesh::draw(QOpenGLExtraFunctions * f, int count, int type) {
|
||||
if (isEmpty()) return;
|
||||
if (!isInit()) init(f);
|
||||
if (changed) rebuffer(f);
|
||||
//qDebug() << "draw" << geom_type << vert_count << count;
|
||||
// qDebug() << "draw" << geom_type << vert_count << count;
|
||||
|
||||
VertexObject * vao = vaoByType(type);
|
||||
vao->bindBuffers(f, buffer_geom, buffer_ind);
|
||||
@@ -198,14 +200,14 @@ void Mesh::draw(QOpenGLExtraFunctions * f, int count, int type) {
|
||||
|
||||
|
||||
void Mesh::clear() {
|
||||
vertices_ .clear();
|
||||
normals_ .clear();
|
||||
tangents_ .clear();
|
||||
vertices_.clear();
|
||||
normals_.clear();
|
||||
tangents_.clear();
|
||||
bitangents_.clear();
|
||||
texcoords_ .clear();
|
||||
triangles_ .clear();
|
||||
lines_ .clear();
|
||||
data_ .clear();
|
||||
texcoords_.clear();
|
||||
triangles_.clear();
|
||||
lines_.clear();
|
||||
data_.clear();
|
||||
changed = hash_changed = true;
|
||||
}
|
||||
|
||||
@@ -231,23 +233,23 @@ void Mesh::loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels
|
||||
uint Mesh::hash() const {
|
||||
if (hash_changed) {
|
||||
hash_changed = false;
|
||||
hash_ = qHashBits(vertices_ .constData(), vertices_ .size() * sizeof(QVector3D));
|
||||
hash_ ^= qHashBits(normals_ .constData(), normals_ .size() * sizeof(QVector3D));
|
||||
hash_ = qHashBits(vertices_.constData(), vertices_.size() * sizeof(QVector3D));
|
||||
hash_ ^= qHashBits(normals_.constData(), normals_.size() * sizeof(QVector3D));
|
||||
hash_ ^= qHashBits(texcoords_.constData(), texcoords_.size() * sizeof(QVector2D));
|
||||
hash_ ^= qHashBits(triangles_.constData(), triangles_.size() * sizeof( Vector3i));
|
||||
hash_ ^= qHashBits(lines_ .constData(), lines_ .size() * sizeof( Vector2i));
|
||||
hash_ ^= qHashBits(triangles_.constData(), triangles_.size() * sizeof(Vector3i));
|
||||
hash_ ^= qHashBits(lines_.constData(), lines_.size() * sizeof(Vector2i));
|
||||
}
|
||||
return hash_;
|
||||
}
|
||||
|
||||
|
||||
bool Mesh::isObjectsChanged(int type) const {
|
||||
return (const_cast<Mesh*>(this))->vaoByType(type)->isObjectsChanged();
|
||||
return (const_cast<Mesh *>(this))->vaoByType(type)->isObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
bool Mesh::isSelectionChanged(int type) const {
|
||||
return (const_cast<Mesh*>(this))->vaoByType(type)->isSelectionChanged();
|
||||
return (const_cast<Mesh *>(this))->vaoByType(type)->isSelectionChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -262,14 +264,14 @@ void Mesh::setSelectionChanged(int type, bool yes) {
|
||||
|
||||
|
||||
void Mesh::setAllObjectsChanged(bool yes) {
|
||||
QMapIterator<int, VertexObject * > it(vao_map);
|
||||
QMapIterator<int, VertexObject *> it(vao_map);
|
||||
while (it.hasNext())
|
||||
it.next().value()->setObjectsChanged(yes);
|
||||
}
|
||||
|
||||
|
||||
void Mesh::setAllSelectionChanged(bool yes) {
|
||||
QMapIterator<int, VertexObject * > it(vao_map);
|
||||
QMapIterator<int, VertexObject *> it(vao_map);
|
||||
while (it.hasNext())
|
||||
it.next().value()->setSelectionChanged(yes);
|
||||
}
|
||||
@@ -301,8 +303,7 @@ void Mesh::transformPoints(const QMatrix4x4 & mat) {
|
||||
int vcnt = vertices_.size(), ncnt = normals_.size();
|
||||
for (int i = 0; i < vcnt; ++i) {
|
||||
vertices_[i] = (mat * QVector4D(vertices_[i], 1)).toVector3D();
|
||||
if (i < ncnt)
|
||||
normals_[i] = (mat * QVector4D(normals_[i], 0)).toVector3D();
|
||||
if (i < ncnt) normals_[i] = (mat * QVector4D(normals_[i], 0)).toVector3D();
|
||||
}
|
||||
changed = hash_changed = true;
|
||||
}
|
||||
@@ -326,8 +327,8 @@ void Mesh::append(const Mesh * m) {
|
||||
if (m->isEmpty()) return;
|
||||
if (normals_.isEmpty()) calculateNormals();
|
||||
int vcnt = vertices_.size();
|
||||
vertices_ .append(m->vertices_ );
|
||||
normals_ .append(m->normals_ );
|
||||
vertices_.append(m->vertices_);
|
||||
normals_.append(m->normals_);
|
||||
texcoords_.append(m->texcoords_);
|
||||
QVector<Vector3i> tri = m->triangles_;
|
||||
for (int i = 0; i < tri.size(); ++i)
|
||||
@@ -378,7 +379,7 @@ bool Mesh::loadFromFile(const QString & filename) {
|
||||
Box3D Mesh::boundingBox() const {
|
||||
if (vertices_.isEmpty()) return Box3D();
|
||||
int vcnt = vertices_.size();
|
||||
//qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
// qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
GLfloat mix, miy, miz, max, may, maz;
|
||||
QVector3D v0(vertices_[0]);
|
||||
mix = max = v0.x();
|
||||
@@ -394,9 +395,9 @@ Box3D Mesh::boundingBox() const {
|
||||
if (miz > v.z()) miz = v.z();
|
||||
if (maz < v.z()) maz = v.z();
|
||||
}
|
||||
bound.x = mix;
|
||||
bound.y = miy;
|
||||
bound.z = miz;
|
||||
bound.x = mix;
|
||||
bound.y = miy;
|
||||
bound.z = miz;
|
||||
bound.length = max - mix;
|
||||
bound.width = may - miy;
|
||||
bound.height = maz - miz;
|
||||
@@ -404,26 +405,26 @@ Box3D Mesh::boundingBox() const {
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator <<(QDataStream & s, const Mesh * m) {
|
||||
QDataStream & operator<<(QDataStream & s, const Mesh * m) {
|
||||
ChunkStream cs;
|
||||
//qDebug() << "place VBO" << m.vertices_.size() << m.normals_.size() << m.texcoords_.size() << m.colors_.size() << "...";
|
||||
cs.add(1, m->vertices_).add(2, m->normals_).add(3, m->texcoords_)
|
||||
.add(6, m->triangles_).add(7, m->lines_).add(10, int(m->geom_type));
|
||||
//qDebug() << "place VBO done" << cs.data().size() << "...";
|
||||
s << cs.data(); return s;
|
||||
// qDebug() << "place VBO" << m.vertices_.size() << m.normals_.size() << m.texcoords_.size() << m.colors_.size() << "...";
|
||||
cs.add(1, m->vertices_).add(2, m->normals_).add(3, m->texcoords_).add(6, m->triangles_).add(7, m->lines_).add(10, int(m->geom_type));
|
||||
// qDebug() << "place VBO done" << cs.data().size() << "...";
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator >>(QDataStream & s, Mesh *& m) {
|
||||
QDataStream & operator>>(QDataStream & s, Mesh *& m) {
|
||||
m = new Mesh();
|
||||
ChunkStream cs(s);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1 : cs.get(m->vertices_ ); break;
|
||||
case 2 : cs.get(m->normals_ ); break;
|
||||
case 3 : cs.get(m->texcoords_); break;
|
||||
case 6 : cs.get(m->triangles_); break;
|
||||
case 7 : cs.get(m->lines_ ); break;
|
||||
case 1: cs.get(m->vertices_); break;
|
||||
case 2: cs.get(m->normals_); break;
|
||||
case 3: cs.get(m->texcoords_); break;
|
||||
case 6: cs.get(m->triangles_); break;
|
||||
case 7: cs.get(m->lines_); break;
|
||||
case 10: m->geom_type = cs.getData<int>(); break;
|
||||
}
|
||||
}
|
||||
|
||||
110
core/glmesh.h
110
core/glmesh.h
@@ -1,74 +1,92 @@
|
||||
/*
|
||||
QGL Mesh
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Mesh
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLMESH_H
|
||||
#define GLMESH_H
|
||||
|
||||
#include <chunkstream.h>
|
||||
#include "glvertexobject.h"
|
||||
|
||||
#include <chunkstream.h>
|
||||
|
||||
|
||||
class Mesh {
|
||||
friend QDataStream & operator<<(QDataStream & s, const Mesh * m);
|
||||
friend QDataStream & operator>>(QDataStream & s, Mesh *& m);
|
||||
|
||||
class Mesh
|
||||
{
|
||||
friend QDataStream & operator <<(QDataStream & s, const Mesh * m);
|
||||
friend QDataStream & operator >>(QDataStream & s, Mesh *& m);
|
||||
public:
|
||||
Mesh(GLenum geom_type_ = GL_TRIANGLES);
|
||||
~Mesh();
|
||||
|
||||
Mesh * clone();
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
void init(QOpenGLExtraFunctions * f);
|
||||
void destroy(QOpenGLExtraFunctions * f);
|
||||
bool rebuffer(QOpenGLExtraFunctions * f);
|
||||
void draw (QOpenGLExtraFunctions * f, int count, int type = 0);
|
||||
void draw(QOpenGLExtraFunctions * f, int count, int type = 0);
|
||||
void reinit();
|
||||
void clear();
|
||||
void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object, int type = 0);
|
||||
void loadObjects (QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects, int type = 0);
|
||||
void loadObject(QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object, int type = 0);
|
||||
void loadObjects(QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects, int type = 0);
|
||||
void loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels, int type = 0);
|
||||
|
||||
int verticesCount() const {return vertices_.size();}
|
||||
int trianglesCount() const {return triangles_.size();}
|
||||
int linesCount() const {return lines_.size();}
|
||||
bool isInit() const {return buffer_geom.isInit();}
|
||||
bool isEmpty() const {return vertices_.isEmpty();}
|
||||
int verticesCount() const { return vertices_.size(); }
|
||||
int trianglesCount() const { return triangles_.size(); }
|
||||
int linesCount() const { return lines_.size(); }
|
||||
bool isInit() const { return buffer_geom.isInit(); }
|
||||
bool isEmpty() const { return vertices_.isEmpty(); }
|
||||
uint hash() const;
|
||||
|
||||
bool isObjectsChanged (int type = 0) const;
|
||||
bool isSelectionChanged (int type = 0) const;
|
||||
void setObjectsChanged (int type = 0, bool yes = true);
|
||||
bool isObjectsChanged(int type = 0) const;
|
||||
bool isSelectionChanged(int type = 0) const;
|
||||
void setObjectsChanged(int type = 0, bool yes = true);
|
||||
void setSelectionChanged(int type = 0, bool yes = true);
|
||||
void setAllObjectsChanged (bool yes = true);
|
||||
void setAllObjectsChanged(bool yes = true);
|
||||
void setAllSelectionChanged(bool yes = true);
|
||||
|
||||
QVector<QVector3D> & vertices () {changed = hash_changed = true; return vertices_;}
|
||||
QVector<QVector3D> & normals () {changed = hash_changed = true; return normals_;}
|
||||
QVector<QVector2D> & texcoords() {changed = hash_changed = true; return texcoords_;}
|
||||
QVector< Vector3i> & indicesTriangles() {changed = hash_changed = true; return triangles_;}
|
||||
QVector< Vector2i> & indicesLines () {changed = hash_changed = true; return lines_;}
|
||||
QVector<QVector3D> & vertices() {
|
||||
changed = hash_changed = true;
|
||||
return vertices_;
|
||||
}
|
||||
QVector<QVector3D> & normals() {
|
||||
changed = hash_changed = true;
|
||||
return normals_;
|
||||
}
|
||||
QVector<QVector2D> & texcoords() {
|
||||
changed = hash_changed = true;
|
||||
return texcoords_;
|
||||
}
|
||||
QVector<Vector3i> & indicesTriangles() {
|
||||
changed = hash_changed = true;
|
||||
return triangles_;
|
||||
}
|
||||
QVector<Vector2i> & indicesLines() {
|
||||
changed = hash_changed = true;
|
||||
return lines_;
|
||||
}
|
||||
|
||||
void translatePoints(const QVector3D & dp);
|
||||
void translatePoints(const double & x, const double & y, const double & z) {translatePoints(QVector3D(x, y, z));}
|
||||
void scalePoints (const QVector3D & dp);
|
||||
void scalePoints (const double & s) {scalePoints(QVector3D(s, s, s));}
|
||||
void rotatePoints (const double & angle, const QVector3D & a);
|
||||
void rotatePoints (const double & angle, const double & x, const double & y, const double & z) {rotatePoints(angle, QVector3D(x, y, z));}
|
||||
void translatePoints(const double & x, const double & y, const double & z) { translatePoints(QVector3D(x, y, z)); }
|
||||
void scalePoints(const QVector3D & dp);
|
||||
void scalePoints(const double & s) { scalePoints(QVector3D(s, s, s)); }
|
||||
void rotatePoints(const double & angle, const QVector3D & a);
|
||||
void rotatePoints(const double & angle, const double & x, const double & y, const double & z) {
|
||||
rotatePoints(angle, QVector3D(x, y, z));
|
||||
}
|
||||
void transformPoints(const QMatrix4x4 & mat);
|
||||
void flipNormals();
|
||||
void append(const Mesh * m);
|
||||
@@ -85,13 +103,13 @@ private:
|
||||
|
||||
QVector<QVector3D> vertices_, normals_, tangents_, bitangents_;
|
||||
QVector<QVector2D> texcoords_;
|
||||
QVector< Vector3i> triangles_;
|
||||
QVector< Vector2i> lines_;
|
||||
QVector<Vector3i> triangles_;
|
||||
QVector<Vector2i> lines_;
|
||||
|
||||
QVector<QGLEngineShaders::Vertex> data_;
|
||||
GLenum geom_type;
|
||||
Buffer buffer_geom, buffer_ind;
|
||||
QMap<int, VertexObject * > vao_map;
|
||||
QMap<int, VertexObject *> vao_map;
|
||||
mutable uint hash_;
|
||||
mutable bool hash_changed;
|
||||
int vert_count;
|
||||
@@ -99,7 +117,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
QDataStream & operator <<(QDataStream & s, const Mesh * m);
|
||||
QDataStream & operator >>(QDataStream & s, Mesh *& m);
|
||||
QDataStream & operator<<(QDataStream & s, const Mesh * m);
|
||||
QDataStream & operator>>(QDataStream & s, Mesh *& m);
|
||||
|
||||
#endif // GLMESH_H
|
||||
|
||||
@@ -1,34 +1,36 @@
|
||||
/*
|
||||
QGL Primitives
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Primitives
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "glprimitives.h"
|
||||
|
||||
#include "glmesh.h"
|
||||
|
||||
|
||||
Mesh * Primitive::plane(float width, float length) {
|
||||
Mesh * ret = new Mesh();
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector3i> & i(ret->indicesTriangles ());
|
||||
QVector<Vector3i> & i(ret->indicesTriangles());
|
||||
float hw = width / 2.f, hl = length / 2.f;
|
||||
for (int j = 0; j < 4; ++j) n << QVector3D(0., 0., 1.);
|
||||
t << QVector2D(0., 0.) << QVector2D(0., 1.) << QVector2D(1., 1.) << QVector2D(1., 0.);
|
||||
for (int j = 0; j < 4; ++j)
|
||||
n << QVector3D(0., 0., 1.);
|
||||
t << QVector2D(0., 0.) << QVector2D(0., 1.) << QVector2D(1., 1.) << QVector2D(1., 0.);
|
||||
v << QVector3D(-hw, -hl, 0.) << QVector3D(-hw, hl, 0.) << QVector3D(hw, hl, 0.) << QVector3D(hw, -hl, 0.);
|
||||
i << Vector3i(0, 2, 1) << Vector3i(0, 3, 2);
|
||||
return ret;
|
||||
@@ -38,17 +40,18 @@ Mesh * Primitive::plane(float width, float length) {
|
||||
Mesh * Primitive::cube(float width, float length, float height) {
|
||||
Mesh * ret = new Mesh();
|
||||
QVector3D scale(width, length, height);
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector3i> & i(ret->indicesTriangles ());
|
||||
QVector<Vector3i> & i(ret->indicesTriangles());
|
||||
float hs = 0.5f;
|
||||
int si = 0;
|
||||
int si = 0;
|
||||
QMatrix4x4 mat;
|
||||
|
||||
si = v.size();
|
||||
for (int j = 0; j < 4; ++j) n << QVector3D(0., -1., 0.);
|
||||
t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.);
|
||||
for (int j = 0; j < 4; ++j)
|
||||
n << QVector3D(0., -1., 0.);
|
||||
t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.);
|
||||
v << QVector3D(-hs, -hs, -hs) << QVector3D(hs, -hs, -hs) << QVector3D(hs, -hs, hs) << QVector3D(-hs, -hs, hs);
|
||||
i << Vector3i(si + 0, si + 1, si + 2) << Vector3i(si + 0, si + 2, si + 3);
|
||||
|
||||
@@ -60,21 +63,21 @@ Mesh * Primitive::cube(float width, float length, float height) {
|
||||
n << cn;
|
||||
v << mat.map(QVector4D(v[j])).toVector3D();
|
||||
}
|
||||
t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.);
|
||||
t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.);
|
||||
i << Vector3i(si + 0, si + 1, si + 2) << Vector3i(si + 0, si + 2, si + 3);
|
||||
}
|
||||
|
||||
mat.setToIdentity();
|
||||
mat.rotate(90., 1., 0.,0.);
|
||||
mat.rotate(90., 1., 0., 0.);
|
||||
for (int r = 0; r < 2; ++r) {
|
||||
si = v.size();
|
||||
mat.rotate(180., 1., 0.,0.);
|
||||
mat.rotate(180., 1., 0., 0.);
|
||||
QVector3D cn = mat.map(n[0]);
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
n << cn;
|
||||
v << mat.map(QVector4D(v[j])).toVector3D();
|
||||
}
|
||||
t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.);
|
||||
t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.);
|
||||
i << Vector3i(si + 0, si + 1, si + 2) << Vector3i(si + 0, si + 2, si + 3);
|
||||
}
|
||||
|
||||
@@ -87,10 +90,10 @@ Mesh * Primitive::cube(float width, float length, float height) {
|
||||
|
||||
Mesh * Primitive::ellipsoid(int segments_wl, int segments_h, float radius, float end_angle) {
|
||||
Mesh * ret = new Mesh();
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector3i> & ind(ret->indicesTriangles());
|
||||
QVector<Vector3i> & ind(ret->indicesTriangles());
|
||||
int hseg = segments_h + 1, wlseg = segments_wl + 1;
|
||||
double crw, crl, a, ch, twl;
|
||||
double eang = deg2rad * end_angle;
|
||||
@@ -99,16 +102,16 @@ Mesh * Primitive::ellipsoid(int segments_wl, int segments_h, float radius, float
|
||||
for (int i = 0; i <= hseg; i++) {
|
||||
ch = -cos((double)i / hseg * M_PI);
|
||||
cp.setZ(ch * radius);
|
||||
twl = sqrt(1. - ch * ch);
|
||||
crw = twl * radius;
|
||||
crl = twl * radius;
|
||||
twl = sqrt(1. - ch * ch);
|
||||
crw = twl * radius;
|
||||
crl = twl * radius;
|
||||
int cvcnt = wlseg * 2;
|
||||
for (int j = 0; j < cvcnt; j++) {
|
||||
a = (double)j / (cvcnt - 1) * eang;
|
||||
cp.setX(crl * cos(a));
|
||||
cp.setY(crw * sin(a));
|
||||
v << cp;
|
||||
t << QVector2D((double)j / (cvcnt - 1), ch/2.f + 0.5f);
|
||||
t << QVector2D((double)j / (cvcnt - 1), ch / 2.f + 0.5f);
|
||||
n << cp.normalized();
|
||||
int si = v.size() - 1;
|
||||
if (j > 0 && i > 0) {
|
||||
@@ -118,7 +121,7 @@ Mesh * Primitive::ellipsoid(int segments_wl, int segments_h, float radius, float
|
||||
}
|
||||
}
|
||||
if (end_angle < 360.) {
|
||||
Mesh * cap = Primitive::disc(segments_h+1, radius, 180);
|
||||
Mesh * cap = Primitive::disc(segments_h + 1, radius, 180);
|
||||
cap->rotatePoints(90, 0, 1, 0);
|
||||
cap->rotatePoints(-90, 0, 0, 1);
|
||||
ret->append(cap);
|
||||
@@ -133,10 +136,10 @@ Mesh * Primitive::ellipsoid(int segments_wl, int segments_h, float radius, float
|
||||
|
||||
Mesh * Primitive::disc(int segments, float radius, float end_angle) {
|
||||
Mesh * ret = new Mesh();
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector3i> & ind(ret->indicesTriangles());
|
||||
QVector<Vector3i> & ind(ret->indicesTriangles());
|
||||
|
||||
segments = qMax(segments + 1, 4);
|
||||
QVector3D cp;
|
||||
@@ -173,10 +176,10 @@ QVector3D coneNormal(double r, double height, double ang) {
|
||||
|
||||
Mesh * Primitive::cone(int segments, float radius, float height) {
|
||||
Mesh * ret = new Mesh();
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector3i> & ind(ret->indicesTriangles());
|
||||
QVector<Vector3i> & ind(ret->indicesTriangles());
|
||||
|
||||
int seg = qMax(segments + 1, 4);
|
||||
QVector3D cp;
|
||||
@@ -194,8 +197,7 @@ Mesh * Primitive::cone(int segments, float radius, float height) {
|
||||
t << QVector2D((double)i / (seg - 1), 0.f);
|
||||
n << coneNormal(radius, height, a);
|
||||
int si = v.size() - 1;
|
||||
if (i > 0)
|
||||
ind << Vector3i(si - 1, si - 2, si);
|
||||
if (i > 0) ind << Vector3i(si - 1, si - 2, si);
|
||||
}
|
||||
|
||||
Mesh * cap = Primitive::disc(segments, radius);
|
||||
@@ -209,10 +211,10 @@ Mesh * Primitive::cone(int segments, float radius, float height) {
|
||||
|
||||
Mesh * Primitive::cylinder(int segments, float radius, float height, float end_angle) {
|
||||
Mesh * ret = new Mesh();
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector3i> & ind(ret->indicesTriangles());
|
||||
QVector<Vector3i> & ind(ret->indicesTriangles());
|
||||
|
||||
int seg = qMax(segments + 1, 4);
|
||||
QVector3D cp, norm;
|
||||
@@ -229,7 +231,8 @@ Mesh * Primitive::cylinder(int segments, float radius, float height, float end_a
|
||||
v << cp;
|
||||
t << QVector2D((double)i / (seg - 1), 0.f);
|
||||
t << QVector2D((double)i / (seg - 1), 1.f);
|
||||
n << norm; n << norm;
|
||||
n << norm;
|
||||
n << norm;
|
||||
int si = v.size() - 1;
|
||||
if (i > 0) {
|
||||
ind << Vector3i(si - 2, si - 1, si);
|
||||
@@ -248,7 +251,7 @@ Mesh * Primitive::cylinder(int segments, float radius, float height, float end_a
|
||||
if (end_angle < 360.) {
|
||||
Mesh * cap = Primitive::plane(radius, height);
|
||||
cap->rotatePoints(90, 1, 0, 0);
|
||||
cap->translatePoints(radius/2, 0, height/2);
|
||||
cap->translatePoints(radius / 2, 0, height / 2);
|
||||
ret->append(cap);
|
||||
cap->flipNormals();
|
||||
cap->rotatePoints(end_angle, 0, 0, 1);
|
||||
@@ -263,8 +266,8 @@ Mesh * Primitive::cylinder(int segments, float radius, float height, float end_a
|
||||
Mesh * Primitive::arrow(int segments, float thick, float angle) {
|
||||
double cone_r = 1.5 * thick;
|
||||
double cone_h = 2. * cone_r / tan(angle * deg2rad);
|
||||
Mesh * ret = new Mesh();
|
||||
Mesh * m = Primitive::cylinder(segments, thick / 2., 1. - cone_h);
|
||||
Mesh * ret = new Mesh();
|
||||
Mesh * m = Primitive::cylinder(segments, thick / 2., 1. - cone_h);
|
||||
ret->append(m);
|
||||
delete m;
|
||||
m = Primitive::cone(segments, cone_r, cone_h);
|
||||
@@ -277,10 +280,10 @@ Mesh * Primitive::arrow(int segments, float thick, float angle) {
|
||||
|
||||
Mesh * Primitive::torus(int segments_main, int segments_second, float radius_main, float radius_second, float end_angle) {
|
||||
Mesh * ret = new Mesh();
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector3i> & ind(ret->indicesTriangles());
|
||||
QVector<Vector3i> & ind(ret->indicesTriangles());
|
||||
|
||||
QVector<QVector3D> cv, cn;
|
||||
QVector<QVector2D> ct;
|
||||
@@ -315,7 +318,7 @@ Mesh * Primitive::torus(int segments_main, int segments_second, float radius_mai
|
||||
pcnt = v.size();
|
||||
}
|
||||
if (end_angle < 360.) {
|
||||
Mesh * cap = Primitive::disc(segments_second-1, radius_second);
|
||||
Mesh * cap = Primitive::disc(segments_second - 1, radius_second);
|
||||
cap->rotatePoints(90, 1, 0, 0);
|
||||
cap->translatePoints(radius_main, 0, 0);
|
||||
ret->append(cap);
|
||||
@@ -328,22 +331,20 @@ Mesh * Primitive::torus(int segments_main, int segments_second, float radius_mai
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Mesh * Primitive::cubeFrame(float width, float length, float height) {
|
||||
Mesh * ret = new Mesh(GL_LINES);
|
||||
QVector3D scale(width, length, height);
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector2i> & i(ret->indicesLines());
|
||||
QVector<Vector2i> & i(ret->indicesLines());
|
||||
float hs = 0.5f;
|
||||
v << QVector3D(-hs, -hs, -hs) << QVector3D(-hs, hs, -hs) << QVector3D( hs, hs, -hs) << QVector3D( hs, -hs, -hs);
|
||||
v << QVector3D(-hs, -hs, hs) << QVector3D(-hs, hs, hs) << QVector3D( hs, hs, hs) << QVector3D( hs, -hs, hs);
|
||||
v << QVector3D(-hs, -hs, -hs) << QVector3D(-hs, hs, -hs) << QVector3D(hs, hs, -hs) << QVector3D(hs, -hs, -hs);
|
||||
v << QVector3D(-hs, -hs, hs) << QVector3D(-hs, hs, hs) << QVector3D(hs, hs, hs) << QVector3D(hs, -hs, hs);
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
v[j] *= scale;
|
||||
t << QVector2D(0, 0);
|
||||
n << QVector3D(0,0,1);
|
||||
n << QVector3D(0, 0, 1);
|
||||
}
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
i << Vector2i(j, (j + 1) % 4);
|
||||
@@ -356,10 +357,10 @@ Mesh * Primitive::cubeFrame(float width, float length, float height) {
|
||||
|
||||
Mesh * Primitive::ellipsoidFrame(int segments_wl, int segments_h, float radius) {
|
||||
Mesh * ret = new Mesh(GL_LINES);
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector2i> & ind(ret->indicesLines());
|
||||
QVector<Vector2i> & ind(ret->indicesLines());
|
||||
int hseg = segments_h + 1, wlseg = segments_wl + 1;
|
||||
double crw, crl, a, ch, twl;
|
||||
|
||||
@@ -367,16 +368,16 @@ Mesh * Primitive::ellipsoidFrame(int segments_wl, int segments_h, float radius)
|
||||
for (int i = 0; i <= hseg; i++) {
|
||||
ch = -cos((double)i / hseg * M_PI);
|
||||
cp.setZ(ch * radius);
|
||||
twl = sqrt(1. - ch * ch);
|
||||
crw = twl * radius;
|
||||
crl = twl * radius;
|
||||
twl = sqrt(1. - ch * ch);
|
||||
crw = twl * radius;
|
||||
crl = twl * radius;
|
||||
int cvcnt = wlseg * 2;
|
||||
for (int j = 0; j < cvcnt; j++) {
|
||||
a = (double)j / (cvcnt - 1) * M_2PI;
|
||||
cp.setX(crl * cos(a));
|
||||
cp.setY(crw * sin(a));
|
||||
v << cp;
|
||||
t << QVector2D((double)j / (cvcnt - 1), ch/2.f + 0.5f);
|
||||
t << QVector2D((double)j / (cvcnt - 1), ch / 2.f + 0.5f);
|
||||
n << cp.normalized();
|
||||
int si = v.size() - 1;
|
||||
if (j > 0 && i > 0) {
|
||||
@@ -391,10 +392,10 @@ Mesh * Primitive::ellipsoidFrame(int segments_wl, int segments_h, float radius)
|
||||
|
||||
Mesh * Primitive::coneFrame(int segments, float radius, float height) {
|
||||
Mesh * ret = new Mesh(GL_LINES);
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector2i> & ind(ret->indicesLines());
|
||||
QVector<Vector2i> & ind(ret->indicesLines());
|
||||
|
||||
int seg = qMax(segments + 1, 4);
|
||||
QVector3D cp;
|
||||
@@ -424,13 +425,13 @@ Mesh * Primitive::coneFrame(int segments, float radius, float height) {
|
||||
|
||||
Mesh * Primitive::lineFrame(QVector3D p0, QVector3D p1) {
|
||||
Mesh * ret = new Mesh(GL_LINES);
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector3D> & v(ret->vertices());
|
||||
QVector<QVector3D> & n(ret->normals());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector2i> & ind(ret->indicesLines());
|
||||
QVector<Vector2i> & ind(ret->indicesLines());
|
||||
v << p0 << p1;
|
||||
n << QVector3D(0,0,1) << QVector3D(0,0,1);
|
||||
t << QVector2D(0,0) << QVector2D(1,0);
|
||||
n << QVector3D(0, 0, 1) << QVector3D(0, 0, 1);
|
||||
t << QVector2D(0, 0) << QVector2D(1, 0);
|
||||
ind << Vector2i(0, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGL Primitives
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Primitives
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLPRIMITIVE_CUBE_H
|
||||
@@ -50,6 +50,6 @@ Mesh * ellipsoidFrame(int segments_wl, int segments_h, float radius = 1.);
|
||||
|
||||
Mesh * coneFrame(int segments, float radius = 1., float height = 1.);
|
||||
|
||||
}
|
||||
} // namespace Primitive
|
||||
|
||||
#endif // GLPRIMITIVE_CUBE_H
|
||||
|
||||
@@ -1,35 +1,41 @@
|
||||
/*
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "glshaders.h"
|
||||
|
||||
#include "glshaders_headers.h"
|
||||
#include "gltypes.h"
|
||||
#include "qglview.h"
|
||||
#include "glshaders.h"
|
||||
#include "glshaders_headers.h"
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
|
||||
bool addShader(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, QString & content, const QString & file, bool add_qgl, const QString & defs) {
|
||||
bool addShader(QOpenGLShaderProgram * prog,
|
||||
QOpenGLShader::ShaderType type,
|
||||
QString & content,
|
||||
const QString & file,
|
||||
bool add_qgl,
|
||||
const QString & defs) {
|
||||
if (type == 0 || content.isEmpty()) {
|
||||
content.clear();
|
||||
return true;
|
||||
}
|
||||
//qDebug() << "[QGLEngine] Shader" << file << "found" << (QOpenGLShader::ShaderTypeBit)(int)type << "section ...";
|
||||
// qDebug() << "[QGLEngine] Shader" << file << "found" << (QOpenGLShader::ShaderTypeBit)(int)type << "section ...";
|
||||
if (add_qgl) {
|
||||
switch (type) {
|
||||
case QOpenGLShader::Fragment:
|
||||
@@ -37,12 +43,8 @@ bool addShader(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, QStr
|
||||
content.prepend(qgl_uniform);
|
||||
content.prepend(qgl_structs);
|
||||
break;
|
||||
case QOpenGLShader::Vertex :
|
||||
content.prepend(qgl_vertex_head );
|
||||
break;
|
||||
case QOpenGLShader::Geometry:
|
||||
content.prepend(qgl_geometry_head);
|
||||
break;
|
||||
case QOpenGLShader::Vertex: content.prepend(qgl_vertex_head); break;
|
||||
case QOpenGLShader::Geometry: content.prepend(qgl_geometry_head); break;
|
||||
}
|
||||
}
|
||||
content.prepend(defs);
|
||||
@@ -57,15 +59,14 @@ bool addShader(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, QStr
|
||||
QString prepareDefines(const QStringList & defines) {
|
||||
if (defines.isEmpty()) return QString();
|
||||
QString ret;
|
||||
foreach (QString s, defines)
|
||||
foreach(QString s, defines)
|
||||
ret.append("#define " + s + "\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl, const QStringList & defines) {
|
||||
if (!prog)
|
||||
prog = new QOpenGLShaderProgram();
|
||||
if (!prog) prog = new QOpenGLShaderProgram();
|
||||
QFile f(file);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
qDebug() << "[QGLEngine] Shader" << file << "Error: can`t open file!";
|
||||
@@ -76,7 +77,7 @@ bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QStr
|
||||
QOpenGLShader::ShaderType type = QOpenGLShader::ShaderType();
|
||||
while (!ts.atEnd()) {
|
||||
line = ts.readLine();
|
||||
pl = line.trimmed().remove(' ').remove('\t').mid(2).toLower();
|
||||
pl = line.trimmed().remove(' ').remove('\t').mid(2).toLower();
|
||||
pl.chop(2);
|
||||
if (pl == "vertex" || pl == "vert") {
|
||||
if (!addShader(prog, type, cur_shader, file, add_qgl, defs)) return false;
|
||||
@@ -117,14 +118,13 @@ bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QStr
|
||||
|
||||
|
||||
bool QGLEngineShaders::loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl, const QStringList & defines) {
|
||||
if (!prog)
|
||||
prog = new QOpenGLShaderProgram();
|
||||
if (!prog) prog = new QOpenGLShaderProgram();
|
||||
prog->removeAllShaders();
|
||||
QString cur_shader, defs = prepareDefines(defines);
|
||||
foreach (QString f, files) {
|
||||
foreach(QString f, files) {
|
||||
QFileInfo fi(f);
|
||||
QOpenGLShader::ShaderType type = QOpenGLShader::ShaderType();
|
||||
if (fi.suffix().toLower() == "vert") type = QOpenGLShader::Vertex ;
|
||||
if (fi.suffix().toLower() == "vert") type = QOpenGLShader::Vertex;
|
||||
if (fi.suffix().toLower() == "frag") type = QOpenGLShader::Fragment;
|
||||
if (fi.suffix().toLower() == "geom") type = QOpenGLShader::Geometry;
|
||||
if (type == 0) continue;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLSHADERS_H
|
||||
@@ -26,6 +26,6 @@ namespace QGLEngineShaders {
|
||||
bool loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl = true, const QStringList & defines = QStringList());
|
||||
bool loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl = true, const QStringList & defines = QStringList());
|
||||
|
||||
}
|
||||
} // namespace QGLEngineShaders
|
||||
|
||||
#endif // GLSHADERS_H
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLSHADERS_HEADERS_H
|
||||
@@ -21,32 +21,30 @@
|
||||
|
||||
namespace QGLEngineShaders {
|
||||
|
||||
const int max_materials = 128;
|
||||
const int max_lights = 256 ;
|
||||
const int max_materials = 128;
|
||||
const int max_lights = 256;
|
||||
|
||||
const char qgl_common_head[] =
|
||||
"#version 400 core\n"
|
||||
"";
|
||||
const char qgl_common_head[] = "#version 400 core\n"
|
||||
"";
|
||||
|
||||
const char qgl_vertex_head[] =
|
||||
"layout(location = 1 ) in vec3 qgl_Vertex ;\n"
|
||||
"layout(location = 2 ) in vec3 qgl_Normal ;\n"
|
||||
"layout(location = 3 ) in vec3 qgl_Tangent ;\n"
|
||||
"layout(location = 4 ) in vec3 qgl_Bitangent ;\n"
|
||||
"layout(location = 5 ) in vec2 qgl_Texture ;\n"
|
||||
"layout(location = 6 ) in uint qgl_Material ;\n"
|
||||
"layout(location = 7 ) in uint qgl_ObjectSelected;\n"
|
||||
"layout(location = 8 ) in uint qgl_ObjectID ;\n"
|
||||
"layout(location = 9 ) in vec4 qgl_ObjectColor ;\n"
|
||||
"layout(location = 10) in mat4 qgl_ModelMatrix ;\n"
|
||||
"out vec2 qgl_FragTexture;\n"
|
||||
"flat out uint qgl_MaterialIndex;\n"
|
||||
"uniform mat4 qgl_ViewMatrix;\n"
|
||||
"uniform mat4 qgl_ViewProjMatrix;\n"
|
||||
"mat3 qgl_getNormalMatrix() {return inverse(mat3(qgl_ViewMatrix * qgl_ModelMatrix));}\n"
|
||||
"mat3 qgl_getTangentMatrix() {return mat3(qgl_ViewMatrix * qgl_ModelMatrix);}\n"
|
||||
"vec4 qgl_ftransform() {return qgl_ViewProjMatrix * (qgl_ModelMatrix * vec4(qgl_Vertex, 1));}\n"
|
||||
"";
|
||||
const char qgl_vertex_head[] = "layout(location = 1 ) in vec3 qgl_Vertex ;\n"
|
||||
"layout(location = 2 ) in vec3 qgl_Normal ;\n"
|
||||
"layout(location = 3 ) in vec3 qgl_Tangent ;\n"
|
||||
"layout(location = 4 ) in vec3 qgl_Bitangent ;\n"
|
||||
"layout(location = 5 ) in vec2 qgl_Texture ;\n"
|
||||
"layout(location = 6 ) in uint qgl_Material ;\n"
|
||||
"layout(location = 7 ) in uint qgl_ObjectSelected;\n"
|
||||
"layout(location = 8 ) in uint qgl_ObjectID ;\n"
|
||||
"layout(location = 9 ) in vec4 qgl_ObjectColor ;\n"
|
||||
"layout(location = 10) in mat4 qgl_ModelMatrix ;\n"
|
||||
"out vec2 qgl_FragTexture;\n"
|
||||
"flat out uint qgl_MaterialIndex;\n"
|
||||
"uniform mat4 qgl_ViewMatrix;\n"
|
||||
"uniform mat4 qgl_ViewProjMatrix;\n"
|
||||
"mat3 qgl_getNormalMatrix() {return inverse(mat3(qgl_ViewMatrix * qgl_ModelMatrix));}\n"
|
||||
"mat3 qgl_getTangentMatrix() {return mat3(qgl_ViewMatrix * qgl_ModelMatrix);}\n"
|
||||
"vec4 qgl_ftransform() {return qgl_ViewProjMatrix * (qgl_ModelMatrix * vec4(qgl_Vertex, 1));}\n"
|
||||
"";
|
||||
|
||||
const char qgl_fragment_head[] =
|
||||
"in vec2 qgl_FragTexture;\n"
|
||||
@@ -63,59 +61,56 @@ const char qgl_fragment_head[] =
|
||||
"#define qgl_FragColor qgl_FragData[0]\n"
|
||||
"";
|
||||
|
||||
const char qgl_geometry_head[] =
|
||||
"";
|
||||
const char qgl_geometry_head[] = "";
|
||||
|
||||
const char qgl_structs[] =
|
||||
"#define QGL_MAPS_COUNT 6\n"
|
||||
"#define QGL_MAP_DIFFUSE 0\n"
|
||||
"#define QGL_MAP_NORMAL 1\n"
|
||||
"#define QGL_MAP_METALNESS 2\n"
|
||||
"#define QGL_MAP_ROUGHNESS 3\n"
|
||||
"#define QGL_MAP_EMISSION 4\n"
|
||||
"#define QGL_MAP_RELIEF 5\n"
|
||||
"#define QGL_TEXTURE_ARRAY_EMPTY 0\n"
|
||||
"#define QGL_TEXTURE_ARRAY_MAPS 1\n"
|
||||
"struct QGLMap {\n"
|
||||
" float offset;\n"
|
||||
" float amount;\n"
|
||||
" vec2 scale;\n"
|
||||
" uint array_index;\n"
|
||||
" uint map_index;\n"
|
||||
"};\n"
|
||||
"struct QGLMaterial {\n"
|
||||
" vec4 color_diffuse;\n"
|
||||
" vec4 color_emission;\n"
|
||||
" float transparency;\n"
|
||||
" float reflectivity;\n"
|
||||
" float iof;\n"
|
||||
" float dispersion;\n"
|
||||
" QGLMap map[QGL_MAPS_COUNT];\n"
|
||||
"};\n"
|
||||
"struct QGLLightParameter {\n"
|
||||
" vec4 color;\n"
|
||||
" vec4 decay_intensity;\n"
|
||||
" vec4 angles;\n"
|
||||
"};\n"
|
||||
"struct QGLLightPosition {\n"
|
||||
" vec4 position;\n"
|
||||
" vec4 direction;\n"
|
||||
"};\n"
|
||||
"";
|
||||
const char qgl_structs[] = "#define QGL_MAPS_COUNT 6\n"
|
||||
"#define QGL_MAP_DIFFUSE 0\n"
|
||||
"#define QGL_MAP_NORMAL 1\n"
|
||||
"#define QGL_MAP_METALNESS 2\n"
|
||||
"#define QGL_MAP_ROUGHNESS 3\n"
|
||||
"#define QGL_MAP_EMISSION 4\n"
|
||||
"#define QGL_MAP_RELIEF 5\n"
|
||||
"#define QGL_TEXTURE_ARRAY_EMPTY 0\n"
|
||||
"#define QGL_TEXTURE_ARRAY_MAPS 1\n"
|
||||
"struct QGLMap {\n"
|
||||
" float offset;\n"
|
||||
" float amount;\n"
|
||||
" vec2 scale;\n"
|
||||
" uint array_index;\n"
|
||||
" uint map_index;\n"
|
||||
"};\n"
|
||||
"struct QGLMaterial {\n"
|
||||
" vec4 color_diffuse;\n"
|
||||
" vec4 color_emission;\n"
|
||||
" float transparency;\n"
|
||||
" float reflectivity;\n"
|
||||
" float iof;\n"
|
||||
" float dispersion;\n"
|
||||
" QGLMap map[QGL_MAPS_COUNT];\n"
|
||||
"};\n"
|
||||
"struct QGLLightParameter {\n"
|
||||
" vec4 color;\n"
|
||||
" vec4 decay_intensity;\n"
|
||||
" vec4 angles;\n"
|
||||
"};\n"
|
||||
"struct QGLLightPosition {\n"
|
||||
" vec4 position;\n"
|
||||
" vec4 direction;\n"
|
||||
"};\n"
|
||||
"";
|
||||
|
||||
const char qgl_uniform[] =
|
||||
"layout (std140) uniform QGLMaterialData {\n"
|
||||
" QGLMaterial qgl_material[128];\n"
|
||||
"};\n"
|
||||
"layout (std140) uniform QGLLightParameterData {\n"
|
||||
" QGLLightParameter qgl_light_parameter[256];\n"
|
||||
"};\n"
|
||||
"layout (std140) uniform QGLLightPositionData {\n"
|
||||
" QGLLightPosition qgl_light_position[256];\n"
|
||||
"};\n"
|
||||
"uniform sampler2DArray qgl_texture_array[2];\n"
|
||||
"";
|
||||
const char qgl_uniform[] = "layout (std140) uniform QGLMaterialData {\n"
|
||||
" QGLMaterial qgl_material[128];\n"
|
||||
"};\n"
|
||||
"layout (std140) uniform QGLLightParameterData {\n"
|
||||
" QGLLightParameter qgl_light_parameter[256];\n"
|
||||
"};\n"
|
||||
"layout (std140) uniform QGLLightPositionData {\n"
|
||||
" QGLLightPosition qgl_light_position[256];\n"
|
||||
"};\n"
|
||||
"uniform sampler2DArray qgl_texture_array[2];\n"
|
||||
"";
|
||||
|
||||
}
|
||||
} // namespace QGLEngineShaders
|
||||
|
||||
#endif // GLSHADERS_HEADERS_H
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
/*
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "glshaders_types.h"
|
||||
|
||||
|
||||
QGLEngineShaders::QGLMap::QGLMap() {
|
||||
offset = 0.;
|
||||
amount = 1.;
|
||||
scale = QVector2D(1., 1.);
|
||||
offset = 0.;
|
||||
amount = 1.;
|
||||
scale = QVector2D(1., 1.);
|
||||
array_index = map_index = 0;
|
||||
}
|
||||
|
||||
|
||||
QGLEngineShaders::QGLMaterial::QGLMaterial() {
|
||||
color_diffuse = QVector4D(1., 1., 1., 0.);
|
||||
color_emission = QVector4D(0., 0., 0., 0.);
|
||||
transparency = 0.;
|
||||
reflectivity = 0.;
|
||||
iof = 0.;
|
||||
dispersion = 0.;
|
||||
color_diffuse = QVector4D(1., 1., 1., 0.);
|
||||
color_emission = QVector4D(0., 0., 0., 0.);
|
||||
transparency = 0.;
|
||||
reflectivity = 0.;
|
||||
iof = 0.;
|
||||
dispersion = 0.;
|
||||
map[mtNormal].map_index = emrBlue;
|
||||
map[mtRoughness].amount = 0.75;
|
||||
map[mtMetalness].amount = 0.25;
|
||||
@@ -41,57 +41,60 @@ QGLEngineShaders::QGLMaterial::QGLMaterial() {
|
||||
|
||||
|
||||
void QGLEngineShaders::prepareDrawGeom(QOpenGLExtraFunctions * f) {
|
||||
//qDebug() << "prepareDrawGeom";
|
||||
// qDebug() << "prepareDrawGeom";
|
||||
|
||||
f->glEnableVertexAttribArray(pos_loc );
|
||||
f->glEnableVertexAttribArray(normal_loc );
|
||||
f->glEnableVertexAttribArray(tangent_loc );
|
||||
f->glEnableVertexAttribArray(pos_loc);
|
||||
f->glEnableVertexAttribArray(normal_loc);
|
||||
f->glEnableVertexAttribArray(tangent_loc);
|
||||
f->glEnableVertexAttribArray(bitangent_loc);
|
||||
f->glEnableVertexAttribArray(tex_loc );
|
||||
f->glEnableVertexAttribArray(tex_loc);
|
||||
|
||||
int size = sizeof(Vertex);
|
||||
f->glVertexAttribPointer(pos_loc , 3, GL_FLOAT, GL_FALSE, size, (const void *)pos_offset );
|
||||
f->glVertexAttribPointer(normal_loc , 3, GL_FLOAT, GL_FALSE, size, (const void *)normal_offset );
|
||||
f->glVertexAttribPointer(tangent_loc , 3, GL_FLOAT, GL_FALSE, size, (const void *)tangent_offset );
|
||||
f->glVertexAttribPointer(pos_loc, 3, GL_FLOAT, GL_FALSE, size, (const void *)pos_offset);
|
||||
f->glVertexAttribPointer(normal_loc, 3, GL_FLOAT, GL_FALSE, size, (const void *)normal_offset);
|
||||
f->glVertexAttribPointer(tangent_loc, 3, GL_FLOAT, GL_FALSE, size, (const void *)tangent_offset);
|
||||
f->glVertexAttribPointer(bitangent_loc, 3, GL_FLOAT, GL_FALSE, size, (const void *)bitangent_offset);
|
||||
f->glVertexAttribPointer(tex_loc , 2, GL_FLOAT, GL_FALSE, size, (const void *)tex_offset );
|
||||
f->glVertexAttribPointer(tex_loc, 2, GL_FLOAT, GL_FALSE, size, (const void *)tex_offset);
|
||||
}
|
||||
|
||||
|
||||
void QGLEngineShaders::prepareDrawObj(QOpenGLExtraFunctions * f) {
|
||||
//qDebug() << "prepareDrawObj";
|
||||
// qDebug() << "prepareDrawObj";
|
||||
|
||||
f->glEnableVertexAttribArray(material_loc );
|
||||
f->glEnableVertexAttribArray(material_loc);
|
||||
f->glEnableVertexAttribArray(object_id_loc);
|
||||
f->glEnableVertexAttribArray(color_loc );
|
||||
f->glEnableVertexAttribArray(color_loc);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
f->glEnableVertexAttribArray(modelmatrix_loc + i);
|
||||
}
|
||||
|
||||
GLsizei size = sizeof(Object);
|
||||
f->glVertexAttribIPointer(material_loc , 1, GL_UNSIGNED_INT , size, (const void *)material_offset );
|
||||
f->glVertexAttribIPointer(object_id_loc, 1, GL_UNSIGNED_INT , size, (const void *)object_id_offset);
|
||||
f->glVertexAttribPointer (color_loc , 4, GL_FLOAT, GL_FALSE, size, (const void *)color_offset );
|
||||
f->glVertexAttribIPointer(material_loc, 1, GL_UNSIGNED_INT, size, (const void *)material_offset);
|
||||
f->glVertexAttribIPointer(object_id_loc, 1, GL_UNSIGNED_INT, size, (const void *)object_id_offset);
|
||||
f->glVertexAttribPointer(color_loc, 4, GL_FLOAT, GL_FALSE, size, (const void *)color_offset);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
f->glVertexAttribPointer(modelmatrix_loc + i, 4, GL_FLOAT, GL_FALSE, size, (const void *)(modelmatrix_offset + sizeof(QVector4D)*i));
|
||||
f->glVertexAttribPointer(modelmatrix_loc + i,
|
||||
4,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
size,
|
||||
(const void *)(modelmatrix_offset + sizeof(QVector4D) * i));
|
||||
}
|
||||
|
||||
f->glVertexAttribDivisor(material_loc , 1);
|
||||
f->glVertexAttribDivisor(material_loc, 1);
|
||||
f->glVertexAttribDivisor(object_id_loc, 1);
|
||||
f->glVertexAttribDivisor(color_loc , 1);
|
||||
f->glVertexAttribDivisor(color_loc, 1);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
f->glVertexAttribDivisor(modelmatrix_loc + i, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void QGLEngineShaders::prepareDrawSel(QOpenGLExtraFunctions * f) {
|
||||
//qDebug() << "prepareDrawObj";
|
||||
// qDebug() << "prepareDrawObj";
|
||||
|
||||
f->glEnableVertexAttribArray(is_selected_loc);
|
||||
GLsizei size = 1;
|
||||
f->glVertexAttribIPointer(is_selected_loc, 1, GL_UNSIGNED_BYTE, size, (const void *)is_selected_offset);
|
||||
f->glVertexAttribDivisor(is_selected_loc, 1);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLSHADERS_TYPES_H
|
||||
@@ -27,32 +27,32 @@ namespace QGLEngineShaders {
|
||||
/// VBO
|
||||
|
||||
// geometry
|
||||
const GLsizei pos_offset = 0;
|
||||
const GLsizei normal_offset = sizeof(QVector3D) + pos_offset ;
|
||||
const GLsizei tangent_offset = sizeof(QVector3D) + normal_offset ;
|
||||
const GLsizei bitangent_offset = sizeof(QVector3D) + tangent_offset ;
|
||||
const GLsizei tex_offset = sizeof(QVector3D) + bitangent_offset;
|
||||
const GLsizei pos_offset = 0;
|
||||
const GLsizei normal_offset = sizeof(QVector3D) + pos_offset;
|
||||
const GLsizei tangent_offset = sizeof(QVector3D) + normal_offset;
|
||||
const GLsizei bitangent_offset = sizeof(QVector3D) + tangent_offset;
|
||||
const GLsizei tex_offset = sizeof(QVector3D) + bitangent_offset;
|
||||
|
||||
// object
|
||||
const GLsizei material_offset = 0;
|
||||
const GLsizei object_id_offset = sizeof(GLuint ) + material_offset ;
|
||||
const GLsizei color_offset = sizeof(GLuint ) + object_id_offset ;
|
||||
const GLsizei object_id_offset = sizeof(GLuint) + material_offset;
|
||||
const GLsizei color_offset = sizeof(GLuint) + object_id_offset;
|
||||
const GLsizei modelmatrix_offset = sizeof(QVector4D) + color_offset;
|
||||
|
||||
const GLsizei is_selected_offset = 0;
|
||||
|
||||
const GLuint pos_loc = 1 ; // qgl_Vertex
|
||||
const GLuint normal_loc = 2 ; // qgl_Normal
|
||||
const GLuint tangent_loc = 3 ; // qgl_Tangent
|
||||
const GLuint bitangent_loc = 4 ; // qgl_Bitangent
|
||||
const GLuint tex_loc = 5 ; // qgl_Texture
|
||||
const GLuint pos_loc = 1; // qgl_Vertex
|
||||
const GLuint normal_loc = 2; // qgl_Normal
|
||||
const GLuint tangent_loc = 3; // qgl_Tangent
|
||||
const GLuint bitangent_loc = 4; // qgl_Bitangent
|
||||
const GLuint tex_loc = 5; // qgl_Texture
|
||||
|
||||
const GLuint material_loc = 6 ; // qgl_Material
|
||||
const GLuint object_id_loc = 8 ; // qgl_ObjectID
|
||||
const GLuint color_loc = 9 ; // qgl_ObjectColor
|
||||
const GLuint modelmatrix_loc = 10; // qgl_ModelViewProjectionMatrix
|
||||
const GLuint material_loc = 6; // qgl_Material
|
||||
const GLuint object_id_loc = 8; // qgl_ObjectID
|
||||
const GLuint color_loc = 9; // qgl_ObjectColor
|
||||
const GLuint modelmatrix_loc = 10; // qgl_ModelViewProjectionMatrix
|
||||
|
||||
const GLuint is_selected_loc = 7 ; // qgl_ObjectSelected
|
||||
const GLuint is_selected_loc = 7; // qgl_ObjectSelected
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Vertex {
|
||||
@@ -65,13 +65,13 @@ struct Vertex {
|
||||
struct Object {
|
||||
Object() {
|
||||
material = object_id = 0;
|
||||
color = QVector4D(1,1,1,1);
|
||||
color = QVector4D(1, 1, 1, 1);
|
||||
QMatrix4x4().copyDataTo(modelmatrix);
|
||||
}
|
||||
GLuint material;
|
||||
GLuint object_id;
|
||||
GLuint material;
|
||||
GLuint object_id;
|
||||
QVector4D color;
|
||||
GLfloat modelmatrix[16];
|
||||
GLfloat modelmatrix[16];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
@@ -87,7 +87,7 @@ enum BindingPoints {
|
||||
enum MapType {
|
||||
mtDiffuse = 0,
|
||||
mtNormal = 1,
|
||||
mtMetalness = 2,
|
||||
mtMetalness = 2,
|
||||
mtRoughness = 3,
|
||||
mtEmission = 4,
|
||||
mtRelief = 5,
|
||||
@@ -124,7 +124,7 @@ struct QGLMaterial {
|
||||
struct QGLLightParameter {
|
||||
QVector4D color;
|
||||
QVector4D decay_intensity; // [^0, ^1, ^2, intensity]
|
||||
QVector4D angles; // [start, cos(start), end, cos(end)]
|
||||
QVector4D angles; // [start, cos(start), end, cos(end)]
|
||||
};
|
||||
struct QGLLightPosition {
|
||||
QVector4D position;
|
||||
@@ -133,10 +133,10 @@ struct QGLLightPosition {
|
||||
#pragma pack(pop)
|
||||
|
||||
void prepareDrawGeom(QOpenGLExtraFunctions * f);
|
||||
void prepareDrawObj (QOpenGLExtraFunctions * f);
|
||||
void prepareDrawSel (QOpenGLExtraFunctions * f);
|
||||
void prepareDrawObj(QOpenGLExtraFunctions * f);
|
||||
void prepareDrawSel(QOpenGLExtraFunctions * f);
|
||||
|
||||
|
||||
}
|
||||
} // namespace QGLEngineShaders
|
||||
|
||||
#endif // GLSHADERS_TYPES_H
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
QGL Texture2DArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Texture2DArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "gltexturearray.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
|
||||
|
||||
Texture2DArray::Texture2DArray(bool filter) {
|
||||
target_ = GL_TEXTURE_2D_ARRAY;
|
||||
texture_ = 0;
|
||||
layers_ = 0;
|
||||
target_ = GL_TEXTURE_2D_ARRAY;
|
||||
texture_ = 0;
|
||||
layers_ = 0;
|
||||
filtering_ = filter;
|
||||
}
|
||||
|
||||
|
||||
Texture2DArray::~Texture2DArray() {
|
||||
}
|
||||
Texture2DArray::~Texture2DArray() {}
|
||||
|
||||
|
||||
void Texture2DArray::init(QOpenGLExtraFunctions * f) {
|
||||
@@ -50,7 +50,7 @@ void Texture2DArray::destroy(QOpenGLExtraFunctions * f) {
|
||||
|
||||
void Texture2DArray::reinit() {
|
||||
texture_ = 0;
|
||||
layers_ = 0;
|
||||
layers_ = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ void Texture2DArray::release(QOpenGLExtraFunctions * f) {
|
||||
bool Texture2DArray::resize(QOpenGLExtraFunctions * f, QSize new_size, int layers_count) {
|
||||
if (new_size.isNull() || layers_count <= 0) return false;
|
||||
if ((size_ == new_size) && (layers_ >= layers_count)) return false;
|
||||
size_ = new_size;
|
||||
size_ = new_size;
|
||||
layers_ = layers_count;
|
||||
f->glBindTexture(target_, texture_);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
@@ -88,10 +88,9 @@ bool Texture2DArray::resize(QOpenGLExtraFunctions * f, QSize new_size, int layer
|
||||
|
||||
void Texture2DArray::load(QOpenGLExtraFunctions * f, const QImage & image, int layer) {
|
||||
if (image.isNull() || size_.isNull() || layer < 0 || layer >= layers_) return;
|
||||
QImage im = image.mirrored(false, true)
|
||||
.scaled(size_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)
|
||||
.convertToFormat(QImage::Format_RGBA8888);
|
||||
//qDebug() << "Texture2DArray::load image" << image.size() << "to layer" << layer;
|
||||
QImage im =
|
||||
image.mirrored(false, true).scaled(size_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation).convertToFormat(QImage::Format_RGBA8888);
|
||||
// qDebug() << "Texture2DArray::load image" << image.size() << "to layer" << layer;
|
||||
f->glTexSubImage3D(target_, 0, 0, 0, layer, size_.width(), size_.height(), 1, GL_RGBA, GL_UNSIGNED_BYTE, im.constBits());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGL Texture2DArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Texture2DArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLTEXTUREARRAY_H
|
||||
@@ -22,26 +22,25 @@
|
||||
#include "gltypes.h"
|
||||
|
||||
|
||||
class Texture2DArray
|
||||
{
|
||||
class Texture2DArray {
|
||||
public:
|
||||
Texture2DArray(bool filter);
|
||||
~Texture2DArray();
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
void init(QOpenGLExtraFunctions * f);
|
||||
void destroy(QOpenGLExtraFunctions * f);
|
||||
void reinit();
|
||||
|
||||
void bind (QOpenGLExtraFunctions * f, int channel = 0);
|
||||
void release (QOpenGLExtraFunctions * f);
|
||||
void bind(QOpenGLExtraFunctions * f, int channel = 0);
|
||||
void release(QOpenGLExtraFunctions * f);
|
||||
|
||||
// returns true if size changed
|
||||
bool resize (QOpenGLExtraFunctions * f, QSize new_size, int layers_count);
|
||||
void load (QOpenGLExtraFunctions * f, const QImage & image, int layer);
|
||||
void mipmaps (QOpenGLExtraFunctions * f);
|
||||
bool resize(QOpenGLExtraFunctions * f, QSize new_size, int layers_count);
|
||||
void load(QOpenGLExtraFunctions * f, const QImage & image, int layer);
|
||||
void mipmaps(QOpenGLExtraFunctions * f);
|
||||
|
||||
GLuint ID() const {return texture_;}
|
||||
bool isInit() const {return texture_ != 0;}
|
||||
GLuint ID() const { return texture_; }
|
||||
bool isInit() const { return texture_ != 0; }
|
||||
|
||||
private:
|
||||
GLenum target_;
|
||||
|
||||
@@ -1,36 +1,50 @@
|
||||
/*
|
||||
QGL Transform
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Transform
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "gltransform.h"
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
inline void composeQMatrix4x4(const QVector3D & position, const QVector3D & orientation, const QVector3D & scale, QMatrix4x4 &m) {
|
||||
inline void composeQMatrix4x4(const QVector3D & position, const QVector3D & orientation, const QVector3D & scale, QMatrix4x4 & m) {
|
||||
const QMatrix3x3 rot3x3(Transform::toRotationMatrix(orientation));
|
||||
|
||||
// set up final matrix with scale, rotation and translation
|
||||
m(0, 0) = scale.x() * rot3x3(0, 0); m(0, 1) = scale.y() * rot3x3(0, 1); m(0, 2) = scale.z() * rot3x3(0, 2); m(0, 3) = position.x();
|
||||
m(1, 0) = scale.x() * rot3x3(1, 0); m(1, 1) = scale.y() * rot3x3(1, 1); m(1, 2) = scale.z() * rot3x3(1, 2); m(1, 3) = position.y();
|
||||
m(2, 0) = scale.x() * rot3x3(2, 0); m(2, 1) = scale.y() * rot3x3(2, 1); m(2, 2) = scale.z() * rot3x3(2, 2); m(2, 3) = position.z();
|
||||
m(0, 0) = scale.x() * rot3x3(0, 0);
|
||||
m(0, 1) = scale.y() * rot3x3(0, 1);
|
||||
m(0, 2) = scale.z() * rot3x3(0, 2);
|
||||
m(0, 3) = position.x();
|
||||
m(1, 0) = scale.x() * rot3x3(1, 0);
|
||||
m(1, 1) = scale.y() * rot3x3(1, 1);
|
||||
m(1, 2) = scale.z() * rot3x3(1, 2);
|
||||
m(1, 3) = position.y();
|
||||
m(2, 0) = scale.x() * rot3x3(2, 0);
|
||||
m(2, 1) = scale.y() * rot3x3(2, 1);
|
||||
m(2, 2) = scale.z() * rot3x3(2, 2);
|
||||
m(2, 3) = position.z();
|
||||
// no projection term
|
||||
m(3, 0) = 0.0f; m(3, 1) = 0.0f; m(3, 2) = 0.0f; m(3, 3) = 1.0f;
|
||||
m(3, 0) = 0.0f;
|
||||
m(3, 1) = 0.0f;
|
||||
m(3, 2) = 0.0f;
|
||||
m(3, 3) = 1.0f;
|
||||
}
|
||||
|
||||
inline void decomposeQMatrix3x3(const QMatrix3x3 & m, QMatrix3x3 & Q, QVector3D & D, QVector3D & U) {
|
||||
@@ -62,24 +76,24 @@ inline void decomposeQMatrix3x3(const QMatrix3x3 & m, QMatrix3x3 & Q, QVector3D
|
||||
|
||||
// build orthogonal matrix Q
|
||||
float invLen = 1.0f / std::sqrt(m(0, 0) * m(0, 0) + m(1, 0) * m(1, 0) + m(2, 0) * m(2, 0));
|
||||
Q(0, 0) = m(0, 0) * invLen;
|
||||
Q(1, 0) = m(1, 0) * invLen;
|
||||
Q(2, 0) = m(2, 0) * invLen;
|
||||
Q(0, 0) = m(0, 0) * invLen;
|
||||
Q(1, 0) = m(1, 0) * invLen;
|
||||
Q(2, 0) = m(2, 0) * invLen;
|
||||
|
||||
float dot = Q(0, 0) * m(0, 1) + Q(1, 0) * m(1, 1) + Q(2, 0) * m(2, 1);
|
||||
Q(0, 1) = m(0, 1) - dot * Q(0, 0);
|
||||
Q(1, 1) = m(1, 1) - dot * Q(1, 0);
|
||||
Q(2, 1) = m(2, 1) - dot * Q(2, 0);
|
||||
invLen = 1.0f / std::sqrt(Q(0, 1) * Q(0, 1) + Q(1, 1) * Q(1, 1) + Q(2, 1) * Q(2, 1));
|
||||
float dot = Q(0, 0) * m(0, 1) + Q(1, 0) * m(1, 1) + Q(2, 0) * m(2, 1);
|
||||
Q(0, 1) = m(0, 1) - dot * Q(0, 0);
|
||||
Q(1, 1) = m(1, 1) - dot * Q(1, 0);
|
||||
Q(2, 1) = m(2, 1) - dot * Q(2, 0);
|
||||
invLen = 1.0f / std::sqrt(Q(0, 1) * Q(0, 1) + Q(1, 1) * Q(1, 1) + Q(2, 1) * Q(2, 1));
|
||||
Q(0, 1) *= invLen;
|
||||
Q(1, 1) *= invLen;
|
||||
Q(2, 1) *= invLen;
|
||||
|
||||
dot = Q(0, 0) * m(0, 2) + Q(1, 0) * m(1, 2) + Q(2, 0) * m(2, 2);
|
||||
dot = Q(0, 0) * m(0, 2) + Q(1, 0) * m(1, 2) + Q(2, 0) * m(2, 2);
|
||||
Q(0, 2) = m(0, 2) - dot * Q(0, 0);
|
||||
Q(1, 2) = m(1, 2) - dot * Q(1, 0);
|
||||
Q(2, 2) = m(2, 2) - dot * Q(2, 0);
|
||||
dot = Q(0, 1) * m(0, 2) + Q(1, 1) * m(1, 2) + Q(2, 1) * m(2, 2);
|
||||
dot = Q(0, 1) * m(0, 2) + Q(1, 1) * m(1, 2) + Q(2, 1) * m(2, 2);
|
||||
Q(0, 2) -= dot * Q(0, 1);
|
||||
Q(1, 2) -= dot * Q(1, 1);
|
||||
Q(2, 2) -= dot * Q(2, 1);
|
||||
@@ -89,11 +103,9 @@ inline void decomposeQMatrix3x3(const QMatrix3x3 & m, QMatrix3x3 & Q, QVector3D
|
||||
Q(2, 2) *= invLen;
|
||||
|
||||
// guarantee that orthogonal matrix has determinant 1 (no reflections)
|
||||
const float det = Q(0, 0) * Q(1, 1) * Q(2, 2) + Q(0, 1) * Q(1, 2) * Q(2, 0) +
|
||||
Q(0, 2) * Q(1, 0) * Q(2, 1) - Q(0, 2) * Q(1, 1) * Q(2, 0) -
|
||||
Q(0, 1) * Q(1, 0) * Q(2, 2) - Q(0, 0) * Q(1, 2) * Q(2, 1);
|
||||
if (det < 0.0f)
|
||||
Q *= -1.0f;
|
||||
const float det = Q(0, 0) * Q(1, 1) * Q(2, 2) + Q(0, 1) * Q(1, 2) * Q(2, 0) + Q(0, 2) * Q(1, 0) * Q(2, 1) -
|
||||
Q(0, 2) * Q(1, 1) * Q(2, 0) - Q(0, 1) * Q(1, 0) * Q(2, 2) - Q(0, 0) * Q(1, 2) * Q(2, 1);
|
||||
if (det < 0.0f) Q *= -1.0f;
|
||||
|
||||
// build "right" matrix R
|
||||
QMatrix3x3 R(Qt::Uninitialized);
|
||||
@@ -105,30 +117,26 @@ inline void decomposeQMatrix3x3(const QMatrix3x3 & m, QMatrix3x3 & Q, QVector3D
|
||||
R(2, 2) = Q(0, 2) * m(0, 2) + Q(1, 2) * m(1, 2) + Q(2, 2) * m(2, 2);
|
||||
|
||||
// the scaling component
|
||||
D[0] = R(0, 0);
|
||||
D[1] = R(1, 1);
|
||||
D[2] = R(2, 2);
|
||||
D[0] = R(0, 0);
|
||||
D[1] = R(1, 1);
|
||||
D[2] = R(2, 2);
|
||||
|
||||
// the shear component
|
||||
U[0] = R(0, 1) / D[0];
|
||||
U[1] = R(0, 2) / D[0];
|
||||
U[2] = R(1, 2) / D[1];
|
||||
U[0] = R(0, 1) / D[0];
|
||||
U[1] = R(0, 2) / D[0];
|
||||
U[2] = R(1, 2) / D[1];
|
||||
}
|
||||
|
||||
inline bool hasScale(const QMatrix4x4 &m) {
|
||||
inline bool hasScale(const QMatrix4x4 & m) {
|
||||
// If the columns are orthonormal and form a right-handed system, then there is no scale
|
||||
float t(m.determinant());
|
||||
if (!qFuzzyIsNull(t - 1.0f))
|
||||
return true;
|
||||
if (!qFuzzyIsNull(t - 1.0f)) return true;
|
||||
t = m(0, 0) * m(0, 0) + m(1, 0) * m(1, 0) + m(2, 0) * m(2, 0);
|
||||
if (!qFuzzyIsNull(t - 1.0f))
|
||||
return true;
|
||||
if (!qFuzzyIsNull(t - 1.0f)) return true;
|
||||
t = m(0, 1) * m(0, 1) + m(1, 1) * m(1, 1) + m(2, 1) * m(2, 1);
|
||||
if (!qFuzzyIsNull(t - 1.0f))
|
||||
return true;
|
||||
if (!qFuzzyIsNull(t - 1.0f)) return true;
|
||||
t = m(0, 2) * m(0, 2) + m(1, 2) * m(1, 2) + m(2, 2) * m(2, 2);
|
||||
if (!qFuzzyIsNull(t - 1.0f))
|
||||
return true;
|
||||
if (!qFuzzyIsNull(t - 1.0f)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -142,64 +150,57 @@ inline void decomposeQMatrix4x4(const QMatrix4x4 & m, QVector3D & position, QVec
|
||||
decomposeQMatrix3x3(m3x3, rot3x3, scale, position);
|
||||
} else {
|
||||
// we know there is no scaling part; no need for QDU decomposition
|
||||
scale = QVector3D(1.0f, 1.0f, 1.0f);
|
||||
scale = QVector3D(1.0f, 1.0f, 1.0f);
|
||||
rot3x3 = m3x3;
|
||||
}
|
||||
orientation = Transform::fromRotationMatrix(rot3x3);
|
||||
position = QVector3D(m(0, 3), m(1, 3), m(2, 3));
|
||||
position = QVector3D(m(0, 3), m(1, 3), m(2, 3));
|
||||
}
|
||||
|
||||
|
||||
Transform::Transform(): m_scale(1.0f, 1.0f, 1.0f), m_translation(), m_eulerRotationAngles(), m_matrixDirty(false) {}
|
||||
|
||||
|
||||
Transform::Transform(): m_scale(1.0f, 1.0f, 1.0f),
|
||||
m_translation(), m_eulerRotationAngles(), m_matrixDirty(false) {
|
||||
}
|
||||
|
||||
|
||||
Transform & Transform::operator =(const Transform & t) {
|
||||
m_scale = t.m_scale;
|
||||
m_translation = t.m_translation;
|
||||
Transform & Transform::operator=(const Transform & t) {
|
||||
m_scale = t.m_scale;
|
||||
m_translation = t.m_translation;
|
||||
m_eulerRotationAngles = t.m_eulerRotationAngles;
|
||||
m_matrixDirty = true;
|
||||
m_matrixDirty = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Transform::setMatrix(const QMatrix4x4 & m) {
|
||||
if (m != matrix()) {
|
||||
m_matrix = m;
|
||||
m_matrix = m;
|
||||
m_matrixDirty = false;
|
||||
QVector3D s;
|
||||
QVector3D t;
|
||||
QVector3D r;
|
||||
decomposeQMatrix4x4(m, t, r, s);
|
||||
m_scale = s;
|
||||
m_translation = t;
|
||||
m_scale = s;
|
||||
m_translation = t;
|
||||
m_eulerRotationAngles = r;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Transform::setRotationX(float r) {
|
||||
if (m_eulerRotationAngles.x() == r)
|
||||
return;
|
||||
if (m_eulerRotationAngles.x() == r) return;
|
||||
m_eulerRotationAngles.setX(r);
|
||||
m_matrixDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void Transform::setRotationY(float r) {
|
||||
if (m_eulerRotationAngles.y() == r)
|
||||
return;
|
||||
if (m_eulerRotationAngles.y() == r) return;
|
||||
m_eulerRotationAngles.setY(r);
|
||||
m_matrixDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void Transform::setRotationZ(float r) {
|
||||
if (m_eulerRotationAngles.z() == r)
|
||||
return;
|
||||
if (m_eulerRotationAngles.z() == r) return;
|
||||
m_eulerRotationAngles.setZ(r);
|
||||
m_matrixDirty = true;
|
||||
}
|
||||
@@ -230,7 +231,7 @@ QMatrix4x4 Transform::matrixRotateScale() const {
|
||||
|
||||
|
||||
QVector3D Transform::direction() const {
|
||||
return matrixRotate().mapVector(QVector3D(0,0,-1)).normalized();
|
||||
return matrixRotate().mapVector(QVector3D(0, 0, -1)).normalized();
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +239,7 @@ void Transform::buildMatrix() const {
|
||||
if (m_matrixDirty) {
|
||||
composeQMatrix4x4(m_translation, m_eulerRotationAngles, m_scale, m_matrix);
|
||||
composeQMatrix4x4(QVector3D(), m_eulerRotationAngles, m_scale, m_matrixWT);
|
||||
composeQMatrix4x4(QVector3D(), m_eulerRotationAngles, QVector3D(1,1,1), m_matrixR);
|
||||
composeQMatrix4x4(QVector3D(), m_eulerRotationAngles, QVector3D(1, 1, 1), m_matrixR);
|
||||
composeQMatrix4x4(QVector3D(), QVector3D(), m_scale, m_matrixS);
|
||||
m_matrixDirty = false;
|
||||
}
|
||||
@@ -262,7 +263,7 @@ float Transform::rotationZ() const {
|
||||
|
||||
void Transform::setScale(const QVector3D & s) {
|
||||
if (s != m_scale) {
|
||||
m_scale = s;
|
||||
m_scale = s;
|
||||
m_matrixDirty = true;
|
||||
}
|
||||
}
|
||||
@@ -305,7 +306,7 @@ float Transform::scale() const {
|
||||
void Transform::setRotation(const QVector3D & r) {
|
||||
if (r != m_eulerRotationAngles) {
|
||||
m_eulerRotationAngles = r;
|
||||
m_matrixDirty = true;
|
||||
m_matrixDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,17 +363,19 @@ QQuaternion Transform::fromAxisAndAngle(float x, float y, float z, float angle)
|
||||
}
|
||||
|
||||
|
||||
QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1, float angle1,
|
||||
const QVector3D & axis2, float angle2) {
|
||||
QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1, float angle1, const QVector3D & axis2, float angle2) {
|
||||
const QQuaternion q1 = QQuaternion::fromAxisAndAngle(axis1, angle1);
|
||||
const QQuaternion q2 = QQuaternion::fromAxisAndAngle(axis2, angle2);
|
||||
return q2 * q1;
|
||||
}
|
||||
|
||||
|
||||
QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1, float angle1,
|
||||
const QVector3D & axis2, float angle2,
|
||||
const QVector3D & axis3, float angle3) {
|
||||
QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1,
|
||||
float angle1,
|
||||
const QVector3D & axis2,
|
||||
float angle2,
|
||||
const QVector3D & axis3,
|
||||
float angle3) {
|
||||
const QQuaternion q1 = QQuaternion::fromAxisAndAngle(axis1, angle1);
|
||||
const QQuaternion q2 = QQuaternion::fromAxisAndAngle(axis2, angle2);
|
||||
const QQuaternion q3 = QQuaternion::fromAxisAndAngle(axis3, angle3);
|
||||
@@ -398,16 +401,16 @@ QVector3D Transform::fromDirection(QVector3D d, float pitch) {
|
||||
|
||||
|
||||
QVector3D Transform::fromRotationMatrix(const QMatrix3x3 & m) {
|
||||
float sy = sqrt(m(0,0) * m(0,0) + m(1,0) * m(1,0));
|
||||
float sy = sqrt(m(0, 0) * m(0, 0) + m(1, 0) * m(1, 0));
|
||||
bool singular = sy < 1.E-6; // If
|
||||
float x, y, z;
|
||||
if (!singular) {
|
||||
x = atan2( m(2,1), m(2,2));
|
||||
y = atan2(-m(2,0), sy);
|
||||
z = atan2( m(1,0), m(0,0));
|
||||
x = atan2(m(2, 1), m(2, 2));
|
||||
y = atan2(-m(2, 0), sy);
|
||||
z = atan2(m(1, 0), m(0, 0));
|
||||
} else {
|
||||
x = atan2(-m(1,2), m(1,1));
|
||||
y = atan2(-m(2,0), sy);
|
||||
x = atan2(-m(1, 2), m(1, 1));
|
||||
y = atan2(-m(2, 0), sy);
|
||||
z = 0.;
|
||||
}
|
||||
return QVector3D(x, y, z) * rad2deg;
|
||||
@@ -419,7 +422,7 @@ QMatrix3x3 Transform::toRotationMatrix(const QVector3D & r) {
|
||||
if (r.z() != 0.f) m.rotate(r.z(), 0., 0., 1.);
|
||||
if (r.y() != 0.f) m.rotate(r.y(), 0., 1., 0.);
|
||||
if (r.x() != 0.f) m.rotate(r.x(), 1., 0., 0.);
|
||||
return m.toGenericMatrix<3,3>();
|
||||
return m.toGenericMatrix<3, 3>();
|
||||
}
|
||||
|
||||
|
||||
@@ -433,8 +436,20 @@ QMatrix4x4 Transform::rotateAround(const QVector3D & point, float angle, const Q
|
||||
|
||||
|
||||
QMatrix4x4 Transform::rotateFromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis) {
|
||||
return QMatrix4x4(xAxis.x(), yAxis.x(), zAxis.x(), 0.0f,
|
||||
xAxis.y(), yAxis.y(), zAxis.y(), 0.0f,
|
||||
xAxis.z(), yAxis.z(), zAxis.z(), 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f);
|
||||
return QMatrix4x4(xAxis.x(),
|
||||
yAxis.x(),
|
||||
zAxis.x(),
|
||||
0.0f,
|
||||
xAxis.y(),
|
||||
yAxis.y(),
|
||||
zAxis.y(),
|
||||
0.0f,
|
||||
xAxis.z(),
|
||||
yAxis.z(),
|
||||
zAxis.z(),
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
1.0f);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGL Transform
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Transform
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLTRANSFORM_H
|
||||
@@ -26,10 +26,11 @@
|
||||
|
||||
|
||||
class Transform {
|
||||
friend QDataStream & operator >>(QDataStream & s, Transform & v);
|
||||
friend QDataStream & operator>>(QDataStream & s, Transform & v);
|
||||
|
||||
public:
|
||||
Transform();
|
||||
Transform & operator =(const Transform & t);
|
||||
Transform & operator=(const Transform & t);
|
||||
|
||||
float scale() const;
|
||||
QVector3D scale3D() const;
|
||||
@@ -45,7 +46,7 @@ public:
|
||||
float rotationY() const;
|
||||
float rotationZ() const;
|
||||
|
||||
void setScale(float s) {setScale(QVector3D(s, s, s));}
|
||||
void setScale(float s) { setScale(QVector3D(s, s, s)); }
|
||||
void setScale(const QVector3D & s);
|
||||
void setScaleX(float s);
|
||||
void setScaleY(float s);
|
||||
@@ -62,17 +63,15 @@ public:
|
||||
void setTranslationZ(float t);
|
||||
|
||||
void setMatrix(const QMatrix4x4 & matrix);
|
||||
void setDirty(bool yes = true) {m_matrixDirty = yes;}
|
||||
void setDirty(bool yes = true) { m_matrixDirty = yes; }
|
||||
|
||||
|
||||
static QQuaternion fromAxisAndAngle(const QVector3D & axis, float angle);
|
||||
static QQuaternion fromAxisAndAngle(float x, float y, float z, float angle);
|
||||
|
||||
static QQuaternion fromAxesAndAngles(const QVector3D & axis1, float angle1,
|
||||
const QVector3D & axis2, float angle2);
|
||||
static QQuaternion fromAxesAndAngles(const QVector3D & axis1, float angle1,
|
||||
const QVector3D & axis2, float angle2,
|
||||
const QVector3D & axis3, float angle3);
|
||||
static QQuaternion fromAxesAndAngles(const QVector3D & axis1, float angle1, const QVector3D & axis2, float angle2);
|
||||
static QQuaternion
|
||||
fromAxesAndAngles(const QVector3D & axis1, float angle1, const QVector3D & axis2, float angle2, const QVector3D & axis3, float angle3);
|
||||
static QQuaternion fromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis);
|
||||
|
||||
static QVector3D fromDirection(QVector3D d, float pitch = 0.f);
|
||||
@@ -91,14 +90,14 @@ protected:
|
||||
|
||||
mutable QMatrix4x4 m_matrix, m_matrixWT, m_matrixR, m_matrixS;
|
||||
mutable bool m_matrixDirty;
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Transform & v) {
|
||||
s << v.matrix(); return s;
|
||||
inline QDataStream & operator<<(QDataStream & s, const Transform & v) {
|
||||
s << v.matrix();
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, Transform & v) {
|
||||
inline QDataStream & operator>>(QDataStream & s, Transform & v) {
|
||||
QMatrix4x4 m;
|
||||
s >> m;
|
||||
v.setMatrix(m);
|
||||
|
||||
178
core/gltypes.cpp
178
core/gltypes.cpp
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
QGLView Types
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGLView Types
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "glcamera.h"
|
||||
#include "qglview.h"
|
||||
#include "gltexture_manager.h"
|
||||
#include "qglview.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
@@ -37,15 +37,14 @@ QString readCharsUntilNull(QDataStream & s) {
|
||||
|
||||
QString findFile(const QString & file, const QStringList & pathes) {
|
||||
QFileInfo fi(QString(file).replace("\\", "/"));
|
||||
//qDebug() << "search" << file << "in" << pathes;
|
||||
// qDebug() << "search" << file << "in" << pathes;
|
||||
if (fi.exists()) return fi.absoluteFilePath();
|
||||
QString fn = fi.fileName();
|
||||
if (fn.contains("/")) fn = fn.mid(fn.lastIndexOf("/"));
|
||||
foreach (QString p, pathes) {
|
||||
foreach(QString p, pathes) {
|
||||
QFileInfoList fil = QDir(p).entryInfoList(QStringList(fn), QDir::Files | QDir::NoDotAndDotDot);
|
||||
//qDebug() << "findFile" << fn << "in" << p << "->" << fil.size();
|
||||
if (!fil.isEmpty())
|
||||
return fil[0].absoluteFilePath();
|
||||
// qDebug() << "findFile" << fn << "in" << p << "->" << fil.size();
|
||||
if (!fil.isEmpty()) return fil[0].absoluteFilePath();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
@@ -55,21 +54,27 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x,
|
||||
glSetPolygonMode(GL_FILL);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
int loc = prog ? prog->attributeLocation("qgl_Color") : -1,
|
||||
locv = prog ? prog->attributeLocation("qgl_Vertex") : -1,
|
||||
loct = prog ? prog->attributeLocation("qgl_Texture") : -1,
|
||||
locc = prog ? prog->attributeLocation("view_corner") : -1;
|
||||
int loc = prog ? prog->attributeLocation("qgl_Color") : -1, locv = prog ? prog->attributeLocation("qgl_Vertex") : -1,
|
||||
loct = prog ? prog->attributeLocation("qgl_Texture") : -1, locc = prog ? prog->attributeLocation("view_corner") : -1;
|
||||
QOpenGLFunctions * glFuncs = QOpenGLContext::currentContext()->functions();
|
||||
if (prog) {
|
||||
static const GLfloat cols [] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f};
|
||||
static const GLfloat verts[] = {x, y, x+w, y, x, y+h, x+w, y+h};
|
||||
static const GLfloat texs [] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f};
|
||||
GLfloat vcs[] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
|
||||
static const GLfloat cols[] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f};
|
||||
static const GLfloat verts[] = {x, y, x + w, y, x, y + h, x + w, y + h};
|
||||
static const GLfloat texs[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f};
|
||||
GLfloat vcs[] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
|
||||
if (corner_dirs) {
|
||||
vcs[0] = corner_dirs[0].x(); vcs[1] = corner_dirs[0].y(); vcs[2] = corner_dirs[0].z();
|
||||
vcs[3] = corner_dirs[1].x(); vcs[4] = corner_dirs[1].y(); vcs[5] = corner_dirs[1].z();
|
||||
vcs[6] = corner_dirs[2].x(); vcs[7] = corner_dirs[2].y(); vcs[8] = corner_dirs[2].z();
|
||||
vcs[9] = corner_dirs[3].x(); vcs[10] = corner_dirs[3].y(); vcs[11] = corner_dirs[3].z();
|
||||
vcs[0] = corner_dirs[0].x();
|
||||
vcs[1] = corner_dirs[0].y();
|
||||
vcs[2] = corner_dirs[0].z();
|
||||
vcs[3] = corner_dirs[1].x();
|
||||
vcs[4] = corner_dirs[1].y();
|
||||
vcs[5] = corner_dirs[1].z();
|
||||
vcs[6] = corner_dirs[2].x();
|
||||
vcs[7] = corner_dirs[2].y();
|
||||
vcs[8] = corner_dirs[2].z();
|
||||
vcs[9] = corner_dirs[3].x();
|
||||
vcs[10] = corner_dirs[3].y();
|
||||
vcs[11] = corner_dirs[3].z();
|
||||
}
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
@@ -92,10 +97,14 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x,
|
||||
} else {
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
||||
glTexCoord2f(0.f, 0.f); glVertex2f(x, y);
|
||||
glTexCoord2f(1.f, 0.f); glVertex2f(x+w, y);
|
||||
glTexCoord2f(0.f, 1.f); glVertex2f(x, y+h);
|
||||
glTexCoord2f(1.f, 1.f); glVertex2f(x+w, y+h);
|
||||
glTexCoord2f(0.f, 0.f);
|
||||
glVertex2f(x, y);
|
||||
glTexCoord2f(1.f, 0.f);
|
||||
glVertex2f(x + w, y);
|
||||
glTexCoord2f(0.f, 1.f);
|
||||
glVertex2f(x, y + h);
|
||||
glTexCoord2f(1.f, 1.f);
|
||||
glVertex2f(x + w, y + h);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
@@ -140,15 +149,13 @@ void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, int width, int hei
|
||||
f->glTexImage2D(target, 0, format, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nullptr);
|
||||
else {
|
||||
int type = GL_UNSIGNED_BYTE;
|
||||
int fmt = GL_RGBA;
|
||||
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGBA32F || format == GL_RGBA16F)
|
||||
type = GL_FLOAT;
|
||||
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGB8 || format == GL_RGB)
|
||||
fmt = GL_RGB;
|
||||
int fmt = GL_RGBA;
|
||||
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGBA32F || format == GL_RGBA16F) type = GL_FLOAT;
|
||||
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGB8 || format == GL_RGB) fmt = GL_RGB;
|
||||
f->glTexImage2D(target, 0, format, width, height, 0, fmt, type, nullptr);
|
||||
//qDebug() << "glTexImage2D" << width << height << QString::number(t, 16);
|
||||
// qDebug() << "glTexImage2D" << width << height << QString::number(t, 16);
|
||||
}
|
||||
//qDebug() << QString::number(glGetError(), 16);
|
||||
// qDebug() << QString::number(glGetError(), 16);
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +181,7 @@ void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, const QImage & ima
|
||||
if (target == GL_TEXTURE_1D || target == GL_TEXTURE_2D || target == GL_TEXTURE_3D) {
|
||||
f->glGenerateMipmap(target);
|
||||
}
|
||||
//qDebug() << target << format << tex << im.width() << im.height() << im.bits() << QString::number(glGetError(), 16);
|
||||
// qDebug() << target << format << tex << im.width() << im.height() << im.bits() << QString::number(glGetError(), 16);
|
||||
}
|
||||
|
||||
|
||||
@@ -216,14 +223,15 @@ QImage rotateQImageRight(const QImage & im) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QColor colorFromString(const QString & str) {
|
||||
QString s = str.trimmed();
|
||||
int i = s.indexOf("\t");
|
||||
int i = s.indexOf("\t");
|
||||
float r, g, b;
|
||||
r = s.left(i).toFloat(); s = s.right(s.length() - i - 1); i = s.indexOf("\t");
|
||||
g = s.left(i).toFloat(); s = s.right(s.length() - i - 1);
|
||||
r = s.left(i).toFloat();
|
||||
s = s.right(s.length() - i - 1);
|
||||
i = s.indexOf("\t");
|
||||
g = s.left(i).toFloat();
|
||||
s = s.right(s.length() - i - 1);
|
||||
b = s.toFloat();
|
||||
return QColor(r * 255.f, g * 255.f, b * 255.f);
|
||||
}
|
||||
@@ -232,9 +240,12 @@ QColor colorFromString(const QString & str) {
|
||||
QVector3D orthToVector(const QVector3D & v, const float & scale) {
|
||||
if (v.isNull()) return QVector3D();
|
||||
QVector3D rv, fn, sn;
|
||||
if (v.x() != 0.f) rv.setZ(1.);
|
||||
else if (v.y() != 0.f) rv.setX(1.);
|
||||
else rv.setY(1.);
|
||||
if (v.x() != 0.f)
|
||||
rv.setZ(1.);
|
||||
else if (v.y() != 0.f)
|
||||
rv.setX(1.);
|
||||
else
|
||||
rv.setY(1.);
|
||||
fn = QVector3D::crossProduct(v, rv).normalized();
|
||||
sn = QVector3D::crossProduct(v, fn).normalized();
|
||||
return fn * urand(scale) + sn * urand(scale);
|
||||
@@ -268,18 +279,22 @@ void lengthenVector(QVector3D & v, const float & l) {
|
||||
|
||||
Vector2i::Vector2i(const QString & str) {
|
||||
QString s = str.trimmed();
|
||||
int i = s.indexOf("\t");
|
||||
p0 = s.left(i).toInt(); s = s.right(s.length() - i - 1);
|
||||
p1 = s.toInt();
|
||||
int i = s.indexOf("\t");
|
||||
p0 = s.left(i).toInt();
|
||||
s = s.right(s.length() - i - 1);
|
||||
p1 = s.toInt();
|
||||
}
|
||||
|
||||
|
||||
Vector3i::Vector3i(const QString & str) {
|
||||
QString s = str.trimmed();
|
||||
int i = s.indexOf("\t");
|
||||
p0 = s.left(i).toInt(); s = s.right(s.length() - i - 1); i = s.indexOf("\t");
|
||||
p1 = s.left(i).toInt(); s = s.right(s.length() - i - 1);
|
||||
p2 = s.toInt();
|
||||
int i = s.indexOf("\t");
|
||||
p0 = s.left(i).toInt();
|
||||
s = s.right(s.length() - i - 1);
|
||||
i = s.indexOf("\t");
|
||||
p1 = s.left(i).toInt();
|
||||
s = s.right(s.length() - i - 1);
|
||||
p2 = s.toInt();
|
||||
}
|
||||
|
||||
|
||||
@@ -305,8 +320,6 @@ void glClearFramebuffer(const QColor & color, bool depth) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Box3D::Box3D(const QVector<QVector3D> & points) {
|
||||
x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f;
|
||||
if (points.isEmpty()) return;
|
||||
@@ -315,13 +328,16 @@ Box3D::Box3D(const QVector<QVector3D> & points) {
|
||||
iy = ay = points[0].y();
|
||||
iz = az = points[0].z();
|
||||
for (int i = 1; i < points.size(); ++i) {
|
||||
ix = qMin<float>(ix, points[i].x()); ax = qMax<float>(ax, points[i].x());
|
||||
iy = qMin<float>(iy, points[i].y()); ay = qMax<float>(ay, points[i].y());
|
||||
iz = qMin<float>(iz, points[i].z()); az = qMax<float>(az, points[i].z());
|
||||
ix = qMin<float>(ix, points[i].x());
|
||||
ax = qMax<float>(ax, points[i].x());
|
||||
iy = qMin<float>(iy, points[i].y());
|
||||
ay = qMax<float>(ay, points[i].y());
|
||||
iz = qMin<float>(iz, points[i].z());
|
||||
az = qMax<float>(az, points[i].z());
|
||||
}
|
||||
x = ix;
|
||||
y = iy;
|
||||
z = iz;
|
||||
x = ix;
|
||||
y = iy;
|
||||
z = iz;
|
||||
length = ax - ix;
|
||||
width = ay - iy;
|
||||
height = az - iz;
|
||||
@@ -331,32 +347,42 @@ Box3D::Box3D(const QVector<QVector3D> & points) {
|
||||
QVector<QVector3D> Box3D::corners() const {
|
||||
QVector<QVector3D> ret;
|
||||
ret << QVector3D(x, y, z) << QVector3D(x, y + width, z) << QVector3D(x, y, z + height) << QVector3D(x, y + width, z + height)
|
||||
<< QVector3D(x + length, y, z) << QVector3D(x + length, y + width, z)
|
||||
<< QVector3D(x + length, y, z + height) << QVector3D(x + length, y + width, z + height);
|
||||
<< QVector3D(x + length, y, z) << QVector3D(x + length, y + width, z) << QVector3D(x + length, y, z + height)
|
||||
<< QVector3D(x + length, y + width, z + height);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Box3D & Box3D::operator |=(const Box3D & o) {
|
||||
Box3D & Box3D::operator|=(const Box3D & o) {
|
||||
if (o.isEmpty()) return *this;
|
||||
if (isEmpty()) *this = o;
|
||||
if (isEmpty())
|
||||
*this = o;
|
||||
else {
|
||||
GLfloat mx = x + length, my = y + width, mz = z + height;
|
||||
GLfloat omx = o.x + o.length, omy = o.y + o.width, omz = o.z + o.height;
|
||||
x = qMin(x, o.x); y = qMin(y, o.y); z = qMin(z, o.z);
|
||||
mx = qMax(mx, omx); my = qMax(my, omy); mz = qMax(mz, omz);
|
||||
length = mx - x; width = my - y; height = mz - z;
|
||||
x = qMin(x, o.x);
|
||||
y = qMin(y, o.y);
|
||||
z = qMin(z, o.z);
|
||||
mx = qMax(mx, omx);
|
||||
my = qMax(my, omy);
|
||||
mz = qMax(mz, omz);
|
||||
length = mx - x;
|
||||
width = my - y;
|
||||
height = mz - z;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
QVector3D vectorFromString(const QString & str) {
|
||||
QTextStream s(const_cast<QString*>(&str), QIODevice::ReadOnly);
|
||||
QTextStream s(const_cast<QString *>(&str), QIODevice::ReadOnly);
|
||||
QVector3D ret;
|
||||
float f(0.f);
|
||||
s >> f; ret.setX(f);
|
||||
s >> f; ret.setY(f);
|
||||
s >> f; ret.setZ(f);
|
||||
s >> f;
|
||||
ret.setX(f);
|
||||
s >> f;
|
||||
ret.setY(f);
|
||||
s >> f;
|
||||
ret.setZ(f);
|
||||
return ret;
|
||||
}
|
||||
|
||||
451
core/gltypes.h
451
core/gltypes.h
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGLView Types
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGLView Types
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLTYPES_H
|
||||
@@ -30,9 +30,9 @@
|
||||
#endif
|
||||
#ifndef WINDOWS
|
||||
# ifndef QNX
|
||||
# ifndef MAC
|
||||
# define LINUX
|
||||
# endif
|
||||
# ifndef MAC
|
||||
# define LINUX
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if __GNUC__
|
||||
@@ -43,49 +43,50 @@
|
||||
|
||||
|
||||
#include <QObject>
|
||||
//#ifndef WINDOWS
|
||||
//# ifdef MAC
|
||||
//# include <OpenGL/gl.h>
|
||||
//# include <OpenGL/glu.h>
|
||||
//# include <GLUT/glut.h>
|
||||
//# else
|
||||
//# include <GL/gl.h>
|
||||
//# include <GL/glext.h>
|
||||
//# include <GL/glu.h>
|
||||
//# endif
|
||||
//#endif
|
||||
// #ifndef WINDOWS
|
||||
// # ifdef MAC
|
||||
// # include <OpenGL/gl.h>
|
||||
// # include <OpenGL/glu.h>
|
||||
// # include <GLUT/glut.h>
|
||||
// # else
|
||||
// # include <GL/gl.h>
|
||||
// # include <GL/glext.h>
|
||||
// # include <GL/glu.h>
|
||||
// # endif
|
||||
// #endif
|
||||
#include <QColor>
|
||||
#include <QDataStream>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QImage>
|
||||
#include <QMatrix4x4>
|
||||
#include <QMutex>
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QOpenGLShader>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <qopenglext.h>
|
||||
#include <cmath>
|
||||
#include <float.h>
|
||||
#include <QMatrix4x4>
|
||||
#include <QDebug>
|
||||
#include <QDataStream>
|
||||
#include <QColor>
|
||||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QImage>
|
||||
#include <QMutex>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <cmath>
|
||||
#include <float.h>
|
||||
#include <qopenglext.h>
|
||||
#ifndef QNX
|
||||
# include <cmath>
|
||||
# include <complex>
|
||||
# include <cmath>
|
||||
# include <complex>
|
||||
#else
|
||||
# include <math.h>
|
||||
# include <complex.h>
|
||||
# include <complex.h>
|
||||
# include <math.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include "qglengine_version.h"
|
||||
#include "qglengine_core_export.h"
|
||||
#include "qglengine_version.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
//#ifdef WINDOWS
|
||||
//# define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
||||
//# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
||||
//#endif
|
||||
// #ifdef WINDOWS
|
||||
// # define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
||||
// # define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
||||
// #endif
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
@@ -116,53 +117,131 @@ const float deg2rad = atanf(1.f) / 45.f;
|
||||
const float rad2deg = 45.f / atanf(1.f);
|
||||
|
||||
# ifdef WINDOWS
|
||||
inline int random() {return rand();}
|
||||
inline int random() {
|
||||
return rand();
|
||||
}
|
||||
# endif
|
||||
#else
|
||||
#define random randomi
|
||||
# define random randomi
|
||||
#endif
|
||||
|
||||
#ifdef CC_VC
|
||||
inline float round(const float & v) {return floor(v + 0.5);}
|
||||
inline float round(const float & v) {
|
||||
return floor(v + 0.5);
|
||||
}
|
||||
#endif
|
||||
inline float randomu() {return float(random()) / RAND_MAX;}
|
||||
inline float randomu() {
|
||||
return float(random()) / RAND_MAX;
|
||||
}
|
||||
|
||||
inline const QSizeF operator *(const QSizeF & f, const QSizeF & s) {return QSizeF(f.width() * s.width(), f.height() * s.height());}
|
||||
inline const QSizeF operator*(const QSizeF & f, const QSizeF & s) {
|
||||
return QSizeF(f.width() * s.width(), f.height() * s.height());
|
||||
}
|
||||
#ifndef PIP_VERSION
|
||||
template<typename T> inline void piSwap(T & f, T & s) {T t(f); f = s; s = t;}
|
||||
template<typename Type> inline Type piMin(const Type & f, const Type & s) {return (f > s) ? s : f;}
|
||||
template<typename Type> inline Type piMin(const Type & f, const Type & s, const Type & t) {return (f < s && f < t) ? f : ((s < t) ? s : t);}
|
||||
template<typename Type> inline Type piMax(const Type & f, const Type & s) {return (f < s) ? s : f;}
|
||||
template<typename Type> inline Type piMax(const Type & f, const Type & s, const Type & t) {return (f > s && f > t) ? f : ((s > t) ? s : t);}
|
||||
template<typename Type> inline Type piClamp(const Type & v, const Type & min, const Type & max) {return (v > max ? max : (v < min ? min : v));}
|
||||
inline ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);}
|
||||
inline uint letobe_i(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
template<typename T>
|
||||
inline void piSwap(T & f, T & s) {
|
||||
T t(f);
|
||||
f = s;
|
||||
s = t;
|
||||
}
|
||||
template<typename Type>
|
||||
inline Type piMin(const Type & f, const Type & s) {
|
||||
return (f > s) ? s : f;
|
||||
}
|
||||
template<typename Type>
|
||||
inline Type piMin(const Type & f, const Type & s, const Type & t) {
|
||||
return (f < s && f < t) ? f : ((s < t) ? s : t);
|
||||
}
|
||||
template<typename Type>
|
||||
inline Type piMax(const Type & f, const Type & s) {
|
||||
return (f < s) ? s : f;
|
||||
}
|
||||
template<typename Type>
|
||||
inline Type piMax(const Type & f, const Type & s, const Type & t) {
|
||||
return (f > s && f > t) ? f : ((s > t) ? s : t);
|
||||
}
|
||||
template<typename Type>
|
||||
inline Type piClamp(const Type & v, const Type & min, const Type & max) {
|
||||
return (v > max ? max : (v < min ? min : v));
|
||||
}
|
||||
inline ushort letobe_s(ushort v) {
|
||||
return (v << 8) | (v >> 8);
|
||||
}
|
||||
inline uint letobe_i(const uint & v) {
|
||||
return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);
|
||||
}
|
||||
#endif
|
||||
// return [-1, 1]
|
||||
inline float urand(const float & scale = 1.) {return ((float)rand() / RAND_MAX - .5f) * (scale + scale);}
|
||||
inline float urand(const float & scale = 1.) {
|
||||
return ((float)rand() / RAND_MAX - .5f) * (scale + scale);
|
||||
}
|
||||
// return [0, 1]
|
||||
inline float uprand(const float & scale = 1.) {return ((float)rand() / RAND_MAX) * scale;}
|
||||
inline float uprand(const float & scale = 1.) {
|
||||
return ((float)rand() / RAND_MAX) * scale;
|
||||
}
|
||||
QString readCharsUntilNull(QDataStream & s);
|
||||
QString findFile(const QString & file, const QStringList & pathes);
|
||||
inline QColor operator *(const QColor & c, float v) {return QColor(piClamp<int>(c.red() * v, 0, 255), piClamp<int>(c.green() * v, 0, 255), piClamp<int>(c.blue() * v, 0, 255), piClamp<int>(c.alpha() * v, 0, 255));}
|
||||
inline QColor operator /(const QColor & c, float v) {return QColor(piClamp<int>(c.red() / v, 0, 255), piClamp<int>(c.green() / v, 0, 255), piClamp<int>(c.blue() / v, 0, 255), piClamp<int>(c.alpha() / v, 0, 255));}
|
||||
inline QColor operator*(const QColor & c, float v) {
|
||||
return QColor(piClamp<int>(c.red() * v, 0, 255),
|
||||
piClamp<int>(c.green() * v, 0, 255),
|
||||
piClamp<int>(c.blue() * v, 0, 255),
|
||||
piClamp<int>(c.alpha() * v, 0, 255));
|
||||
}
|
||||
inline QColor operator/(const QColor & c, float v) {
|
||||
return QColor(piClamp<int>(c.red() / v, 0, 255),
|
||||
piClamp<int>(c.green() / v, 0, 255),
|
||||
piClamp<int>(c.blue() / v, 0, 255),
|
||||
piClamp<int>(c.alpha() / v, 0, 255));
|
||||
}
|
||||
|
||||
|
||||
inline void qglColor(const QColor & c) {glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());}
|
||||
inline void glClearError() {int c = 100; while (glGetError() != GL_NO_ERROR && --c > 0) glGetError();}
|
||||
inline void glSetCapEnabled(GLenum cap, bool on = true) {if (on) glEnable(cap); else glDisable(cap);}
|
||||
inline void glSetPolygonMode(GLenum mode) {glPolygonMode(GL_FRONT_AND_BACK, mode);}
|
||||
inline void deleteGLTexture(QOpenGLExtraFunctions * f, GLuint & tex) {if (tex != 0) f->glDeleteTextures(1, &tex); tex = 0;}
|
||||
inline void qglColor(const QColor & c) {
|
||||
glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());
|
||||
}
|
||||
inline void glClearError() {
|
||||
int c = 100;
|
||||
while (glGetError() != GL_NO_ERROR && --c > 0)
|
||||
glGetError();
|
||||
}
|
||||
inline void glSetCapEnabled(GLenum cap, bool on = true) {
|
||||
if (on)
|
||||
glEnable(cap);
|
||||
else
|
||||
glDisable(cap);
|
||||
}
|
||||
inline void glSetPolygonMode(GLenum mode) {
|
||||
glPolygonMode(GL_FRONT_AND_BACK, mode);
|
||||
}
|
||||
inline void deleteGLTexture(QOpenGLExtraFunctions * f, GLuint & tex) {
|
||||
if (tex != 0) f->glDeleteTextures(1, &tex);
|
||||
tex = 0;
|
||||
}
|
||||
void glEnableDepth();
|
||||
void glDisableDepth();
|
||||
void glClearFramebuffer(const QColor & color = Qt::black, bool depth = true);
|
||||
void glDrawQuad(QOpenGLShaderProgram * prog = nullptr, QVector4D * corner_dirs = nullptr, GLfloat x = -1.f, GLfloat y = -1.f, GLfloat w = 2.f, GLfloat h = 2.f);
|
||||
void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, int width, int height, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D);
|
||||
void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, const QImage & image, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D);
|
||||
void glDrawQuad(QOpenGLShaderProgram * prog = nullptr,
|
||||
QVector4D * corner_dirs = nullptr,
|
||||
GLfloat x = -1.f,
|
||||
GLfloat y = -1.f,
|
||||
GLfloat w = 2.f,
|
||||
GLfloat h = 2.f);
|
||||
void createGLTexture(QOpenGLExtraFunctions * f,
|
||||
GLuint & tex,
|
||||
int width,
|
||||
int height,
|
||||
const GLenum & format = GL_RGBA,
|
||||
const GLenum & target = GL_TEXTURE_2D);
|
||||
void createGLTexture(QOpenGLExtraFunctions * f,
|
||||
GLuint & tex,
|
||||
const QImage & image,
|
||||
const GLenum & format = GL_RGBA,
|
||||
const GLenum & target = GL_TEXTURE_2D);
|
||||
QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_);
|
||||
QImage rotateQImageLeft(const QImage & im);
|
||||
QImage rotateQImageRight(const QImage & im);
|
||||
inline QImage rotateQImage180(const QImage & im) {return im.mirrored(true, true);}
|
||||
inline QImage rotateQImage180(const QImage & im) {
|
||||
return im.mirrored(true, true);
|
||||
}
|
||||
|
||||
class QGLView;
|
||||
class MouseController;
|
||||
@@ -192,7 +271,7 @@ enum RenderPass {
|
||||
rpTransparent,
|
||||
};
|
||||
|
||||
typedef QList<ObjectBase*> ObjectBaseList;
|
||||
typedef QList<ObjectBase *> ObjectBaseList;
|
||||
|
||||
struct Box3D {
|
||||
GLfloat x;
|
||||
@@ -204,101 +283,215 @@ struct Box3D {
|
||||
GLfloat angle_z;
|
||||
GLfloat angle_xy;
|
||||
GLfloat angle_roll;
|
||||
Box3D() {x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f;}
|
||||
Box3D(const QVector3D & center, GLfloat hwid, GLfloat hlen, GLfloat hhei) {x = center.x() - hwid; y = center.y() - hlen; z = center.z() - hhei; width = 2 * hwid; length = 2 * hlen; height = 2 * hhei; angle_z = angle_xy = angle_roll = 0.f;}
|
||||
Box3D() { x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f; }
|
||||
Box3D(const QVector3D & center, GLfloat hwid, GLfloat hlen, GLfloat hhei) {
|
||||
x = center.x() - hwid;
|
||||
y = center.y() - hlen;
|
||||
z = center.z() - hhei;
|
||||
width = 2 * hwid;
|
||||
length = 2 * hlen;
|
||||
height = 2 * hhei;
|
||||
angle_z = angle_xy = angle_roll = 0.f;
|
||||
}
|
||||
Box3D(const QVector<QVector3D> & points);
|
||||
bool isEmpty() const {return (qAbs(width) < 1E-6f) && (qAbs(length) < 1E-6f) && (qAbs(height) < 1E-6f);}
|
||||
QVector3D randomPoint() const {return QVector3D(uprand(length) + x, uprand(width) + y, uprand(height) + z);}
|
||||
QVector3D pos() const {return QVector3D(x, y, z);}
|
||||
QVector3D size() const {return QVector3D(length, width, height);}
|
||||
QVector3D center() const {return QVector3D(length / 2.f + x, width / 2.f + y, height / 2.f + z);}
|
||||
QVector3D angles() const {return QVector3D(angle_xy, angle_roll, angle_z);}
|
||||
bool isEmpty() const { return (qAbs(width) < 1E-6f) && (qAbs(length) < 1E-6f) && (qAbs(height) < 1E-6f); }
|
||||
QVector3D randomPoint() const { return QVector3D(uprand(length) + x, uprand(width) + y, uprand(height) + z); }
|
||||
QVector3D pos() const { return QVector3D(x, y, z); }
|
||||
QVector3D size() const { return QVector3D(length, width, height); }
|
||||
QVector3D center() const { return QVector3D(length / 2.f + x, width / 2.f + y, height / 2.f + z); }
|
||||
QVector3D angles() const { return QVector3D(angle_xy, angle_roll, angle_z); }
|
||||
QVector<QVector3D> corners() const;
|
||||
void setPos(const QVector3D & p) {x = p.x(); y = p.y(); z = p.z();}
|
||||
void setAngles(const QVector3D & a) {angle_xy = a.x(); angle_roll = a.y(); angle_z = a.z();}
|
||||
void setSize(const QVector3D & s) {length = s.x(); width = s.y(); height = s.z();}
|
||||
Box3D & moveTo(const QVector3D & v) {x = v.x(); y = v.y(); z = v.z(); return *this;}
|
||||
Box3D & move(const QVector3D & v) {x += v.x(); y += v.y(); z += v.z(); return *this;}
|
||||
Box3D movedTo(const QVector3D & v) const {Box3D t(*this); t.x = v.x(); t.y = v.y(); t.z = v.z(); return t;}
|
||||
Box3D moved(const QVector3D & v) const {Box3D t(*this); t.x += v.x(); t.y += v.y(); t.z += v.z(); return t;}
|
||||
Box3D & operator |=(const Box3D & o);
|
||||
void setPos(const QVector3D & p) {
|
||||
x = p.x();
|
||||
y = p.y();
|
||||
z = p.z();
|
||||
}
|
||||
void setAngles(const QVector3D & a) {
|
||||
angle_xy = a.x();
|
||||
angle_roll = a.y();
|
||||
angle_z = a.z();
|
||||
}
|
||||
void setSize(const QVector3D & s) {
|
||||
length = s.x();
|
||||
width = s.y();
|
||||
height = s.z();
|
||||
}
|
||||
Box3D & moveTo(const QVector3D & v) {
|
||||
x = v.x();
|
||||
y = v.y();
|
||||
z = v.z();
|
||||
return *this;
|
||||
}
|
||||
Box3D & move(const QVector3D & v) {
|
||||
x += v.x();
|
||||
y += v.y();
|
||||
z += v.z();
|
||||
return *this;
|
||||
}
|
||||
Box3D movedTo(const QVector3D & v) const {
|
||||
Box3D t(*this);
|
||||
t.x = v.x();
|
||||
t.y = v.y();
|
||||
t.z = v.z();
|
||||
return t;
|
||||
}
|
||||
Box3D moved(const QVector3D & v) const {
|
||||
Box3D t(*this);
|
||||
t.x += v.x();
|
||||
t.y += v.y();
|
||||
t.z += v.z();
|
||||
return t;
|
||||
}
|
||||
Box3D & operator|=(const Box3D & o);
|
||||
};
|
||||
|
||||
inline QDebug operator <<(QDebug d, const Box3D & v) {d << "Box3D {start (" << v.x << "," << v.y << "," << v.z << "), size (" << v.length << "," << v.width << "," << v.height << ")}"; return d;}
|
||||
inline QDebug operator<<(QDebug d, const Box3D & v) {
|
||||
d << "Box3D {start (" << v.x << "," << v.y << "," << v.z << "), size (" << v.length << "," << v.width << "," << v.height << ")}";
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Vector2i {
|
||||
Vector2i(int p0_ = 0, int p1_ = 0) {p0 = p0_; p1 = p1_;}
|
||||
Vector2i(int p0_ = 0, int p1_ = 0) {
|
||||
p0 = p0_;
|
||||
p1 = p1_;
|
||||
}
|
||||
Vector2i(const QString & str);
|
||||
Vector2i movedX(const int & o) {return Vector2i(p0 + o, p1);}
|
||||
Vector2i movedY(const int & o) {return Vector2i(p0, p1 + o);}
|
||||
Vector2i moved(const int & x, const int & y) {return Vector2i(p0 + x, p1 + y);}
|
||||
Vector2i movedX(const int & o) { return Vector2i(p0 + o, p1); }
|
||||
Vector2i movedY(const int & o) { return Vector2i(p0, p1 + o); }
|
||||
Vector2i moved(const int & x, const int & y) { return Vector2i(p0 + x, p1 + y); }
|
||||
GLint p0;
|
||||
GLint p1;
|
||||
bool operator ==(const Vector2i & o) const {return p0 == o.p0 && p1 == o.p1;}
|
||||
bool operator !=(const Vector2i & o) const {return p0 != o.p0 || p1 != o.p1;}
|
||||
void operator +=(int v) {p0 += v; p1 += v;}
|
||||
QVector2D toQVector2D() const {return QVector2D(p0, p1);}
|
||||
bool operator==(const Vector2i & o) const { return p0 == o.p0 && p1 == o.p1; }
|
||||
bool operator!=(const Vector2i & o) const { return p0 != o.p0 || p1 != o.p1; }
|
||||
void operator+=(int v) {
|
||||
p0 += v;
|
||||
p1 += v;
|
||||
}
|
||||
QVector2D toQVector2D() const { return QVector2D(p0, p1); }
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
inline Vector2i operator +(const Vector2i & f, const Vector2i & s) {return Vector2i(f.p0 + s.p0, f.p1 + s.p1);}
|
||||
inline Vector2i operator -(const Vector2i & f, const Vector2i & s) {return Vector2i(f.p0 - s.p0, f.p1 - s.p1);}
|
||||
inline Vector2i operator /(const Vector2i & f, const int & s) {return Vector2i(f.p0 / s, f.p1 / s);}
|
||||
inline uint qHash(const Vector2i & v) {return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24));}
|
||||
inline QDebug operator <<(QDebug d, const Vector2i & v) {d.nospace() << "{" << v.p0 << ", " << v.p1 << "}"; return d.space();}
|
||||
inline Vector2i operator+(const Vector2i & f, const Vector2i & s) {
|
||||
return Vector2i(f.p0 + s.p0, f.p1 + s.p1);
|
||||
}
|
||||
inline Vector2i operator-(const Vector2i & f, const Vector2i & s) {
|
||||
return Vector2i(f.p0 - s.p0, f.p1 - s.p1);
|
||||
}
|
||||
inline Vector2i operator/(const Vector2i & f, const int & s) {
|
||||
return Vector2i(f.p0 / s, f.p1 / s);
|
||||
}
|
||||
inline uint qHash(const Vector2i & v) {
|
||||
return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24));
|
||||
}
|
||||
inline QDebug operator<<(QDebug d, const Vector2i & v) {
|
||||
d.nospace() << "{" << v.p0 << ", " << v.p1 << "}";
|
||||
return d.space();
|
||||
}
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Vector2i & v) {s << v.p0 << v.p1; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, Vector2i & v) {s >> v.p0 >> v.p1; return s;}
|
||||
inline QDataStream & operator<<(QDataStream & s, const Vector2i & v) {
|
||||
s << v.p0 << v.p1;
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, Vector2i & v) {
|
||||
s >> v.p0 >> v.p1;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Vector3i {
|
||||
Vector3i(int p0_ = 0, int p1_ = 0, int p2_ = 0) {p0 = p0_; p1 = p1_; p2 = p2_;}
|
||||
Vector3i(int p0_ = 0, int p1_ = 0, int p2_ = 0) {
|
||||
p0 = p0_;
|
||||
p1 = p1_;
|
||||
p2 = p2_;
|
||||
}
|
||||
Vector3i(const QString & str);
|
||||
Vector3i movedX(const int & o) {return Vector3i(p0 + o, p1, p2);}
|
||||
Vector3i movedY(const int & o) {return Vector3i(p0, p1 + o, p2);}
|
||||
Vector3i movedZ(const int & o) {return Vector3i(p0, p1, p2 + o);}
|
||||
Vector3i moved(const int & x, const int & y, const int & z) {return Vector3i(p0 + x, p1 + y, p2 + z);}
|
||||
Vector3i movedX(const int & o) { return Vector3i(p0 + o, p1, p2); }
|
||||
Vector3i movedY(const int & o) { return Vector3i(p0, p1 + o, p2); }
|
||||
Vector3i movedZ(const int & o) { return Vector3i(p0, p1, p2 + o); }
|
||||
Vector3i moved(const int & x, const int & y, const int & z) { return Vector3i(p0 + x, p1 + y, p2 + z); }
|
||||
GLint p0;
|
||||
GLint p1;
|
||||
GLint p2;
|
||||
bool operator ==(const Vector3i & o) const {return p0 == o.p0 && p1 == o.p1 && p2 == o.p2;}
|
||||
bool operator !=(const Vector3i & o) const {return p0 != o.p0 || p1 != o.p1 || p2 != o.p2;}
|
||||
void operator +=(int v) {p0 += v; p1 += v; p2 += v;}
|
||||
QVector3D toQVector3D() const {return QVector3D(p0, p1, p2);}
|
||||
bool operator==(const Vector3i & o) const { return p0 == o.p0 && p1 == o.p1 && p2 == o.p2; }
|
||||
bool operator!=(const Vector3i & o) const { return p0 != o.p0 || p1 != o.p1 || p2 != o.p2; }
|
||||
void operator+=(int v) {
|
||||
p0 += v;
|
||||
p1 += v;
|
||||
p2 += v;
|
||||
}
|
||||
QVector3D toQVector3D() const { return QVector3D(p0, p1, p2); }
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
inline Vector3i operator +(const Vector3i & f, const Vector3i & s) {return Vector3i(f.p0 + s.p0, f.p1 + s.p1, f.p2 + s.p2);}
|
||||
inline Vector3i operator -(const Vector3i & f, const Vector3i & s) {return Vector3i(f.p0 - s.p0, f.p1 - s.p1, f.p2 - s.p2);}
|
||||
inline Vector3i operator /(const Vector3i & f, const int & s) {return Vector3i(f.p0 / s, f.p1 / s, f.p2 / s);}
|
||||
inline uint qHash(const Vector3i & v) {return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24)) ^ ((v.p2 << 16) | (v.p2 >> 16));}
|
||||
inline QDebug operator <<(QDebug d, const Vector3i & v) {d.nospace() << "{" << v.p0 << ", " << v.p1 << ", " << v.p2 << "}"; return d.space();}
|
||||
inline Vector3i operator+(const Vector3i & f, const Vector3i & s) {
|
||||
return Vector3i(f.p0 + s.p0, f.p1 + s.p1, f.p2 + s.p2);
|
||||
}
|
||||
inline Vector3i operator-(const Vector3i & f, const Vector3i & s) {
|
||||
return Vector3i(f.p0 - s.p0, f.p1 - s.p1, f.p2 - s.p2);
|
||||
}
|
||||
inline Vector3i operator/(const Vector3i & f, const int & s) {
|
||||
return Vector3i(f.p0 / s, f.p1 / s, f.p2 / s);
|
||||
}
|
||||
inline uint qHash(const Vector3i & v) {
|
||||
return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24)) ^ ((v.p2 << 16) | (v.p2 >> 16));
|
||||
}
|
||||
inline QDebug operator<<(QDebug d, const Vector3i & v) {
|
||||
d.nospace() << "{" << v.p0 << ", " << v.p1 << ", " << v.p2 << "}";
|
||||
return d.space();
|
||||
}
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Vector3i & v) {s << v.p0 << v.p1 << v.p2; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, Vector3i & v) {s >> v.p0 >> v.p1 >> v.p2; return s;}
|
||||
inline QDataStream & operator<<(QDataStream & s, const Vector3i & v) {
|
||||
s << v.p0 << v.p1 << v.p2;
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, Vector3i & v) {
|
||||
s >> v.p0 >> v.p1 >> v.p2;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
QVector3D vectorFromString(const QString & str);
|
||||
QColor colorFromString(const QString & str);
|
||||
inline QVector4D QColor2QVector(const QColor & c) {return QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF());}
|
||||
inline QVector4D QColor2QVector(const QColor & c) {
|
||||
return QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF());
|
||||
}
|
||||
inline float cosABV(const QVector3D & v0, const QVector3D & v1) {
|
||||
float l = v0.length() * v1.length();
|
||||
if (l == 0.f) return 0.;
|
||||
return (QVector3D::dotProduct(v0, v1)) / l;
|
||||
}
|
||||
inline void normalizeAngleRad(float & a) {while (a < 0.) a += M_2PI; while (a >= M_2PI) a -= M_2PI;}
|
||||
inline void normalizeAngleDeg360(float & a) {while (a < 0.) a += 360. ; while (a >= 360. ) a -= 360. ;}
|
||||
inline QVector3D projection(const QVector3D & v, const QVector3D & to) {return to.normalized() * v.length() * cosABV(v, to);}
|
||||
inline void normalizeAngleRad(float & a) {
|
||||
while (a < 0.)
|
||||
a += M_2PI;
|
||||
while (a >= M_2PI)
|
||||
a -= M_2PI;
|
||||
}
|
||||
inline void normalizeAngleDeg360(float & a) {
|
||||
while (a < 0.)
|
||||
a += 360.;
|
||||
while (a >= 360.)
|
||||
a -= 360.;
|
||||
}
|
||||
inline QVector3D projection(const QVector3D & v, const QVector3D & to) {
|
||||
return to.normalized() * v.length() * cosABV(v, to);
|
||||
}
|
||||
QVector3D orthToVector(const QVector3D & v, const float & scale = 1.);
|
||||
QVector3D rotateVector(const QVector3D & v, const QVector3D & a);
|
||||
void setVectorLength(QVector3D & v, const float & l);
|
||||
void lengthenVector(QVector3D & v, const float & l);
|
||||
inline float squareLength(const QVector3D & from, const QVector3D & to) {return (to.x() - from.x())*(to.x() - from.x()) + (to.y() - from.y())*(to.y() - from.y()) + (to.z() - from.z())*(to.z() - from.z());}
|
||||
inline QVector3D directionFromAngles(const QVector3D & a) {return rotateVector(QVector3D(1., 0., 0.), a);}
|
||||
inline float frac(const float & x, const float & b) {return x - int(x / b) * b;}
|
||||
inline float squareLength(const QVector3D & from, const QVector3D & to) {
|
||||
return (to.x() - from.x()) * (to.x() - from.x()) + (to.y() - from.y()) * (to.y() - from.y()) +
|
||||
(to.z() - from.z()) * (to.z() - from.z());
|
||||
}
|
||||
inline QVector3D directionFromAngles(const QVector3D & a) {
|
||||
return rotateVector(QVector3D(1., 0., 0.), a);
|
||||
}
|
||||
inline float frac(const float & x, const float & b) {
|
||||
return x - int(x / b) * b;
|
||||
}
|
||||
|
||||
|
||||
#endif // GLTYPES_H
|
||||
|
||||
@@ -1,39 +1,37 @@
|
||||
/*
|
||||
QGL VertexObject
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL VertexObject
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glvertexobject.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
|
||||
VertexObject::VertexObject():
|
||||
buffer_obj (GL_ARRAY_BUFFER, GL_STREAM_DRAW),
|
||||
buffer_sel (GL_ARRAY_BUFFER, GL_STREAM_DRAW) {
|
||||
vao_ = 0;
|
||||
buffers_binded = false;
|
||||
VertexObject::VertexObject(): buffer_obj(GL_ARRAY_BUFFER, GL_STREAM_DRAW), buffer_sel(GL_ARRAY_BUFFER, GL_STREAM_DRAW) {
|
||||
vao_ = 0;
|
||||
buffers_binded = false;
|
||||
objects_changed = selected_changed = true;
|
||||
}
|
||||
|
||||
|
||||
VertexObject::~VertexObject() {
|
||||
}
|
||||
VertexObject::~VertexObject() {}
|
||||
|
||||
|
||||
void VertexObject::init(QOpenGLExtraFunctions * f) {
|
||||
@@ -59,13 +57,13 @@ void VertexObject::reinit() {
|
||||
vao_ = 0;
|
||||
buffer_obj.reinit();
|
||||
buffer_sel.reinit();
|
||||
buffers_binded = false;
|
||||
buffers_binded = false;
|
||||
objects_changed = selected_changed = true;
|
||||
}
|
||||
|
||||
|
||||
void VertexObject::bind(QOpenGLExtraFunctions * f) {
|
||||
//qDebug() << "bind" << target_ << buffer_;
|
||||
// qDebug() << "bind" << target_ << buffer_;
|
||||
f->glBindVertexArray(vao_);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGL VertexObject
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL VertexObject
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLVERTEXOBJECT_H
|
||||
@@ -23,33 +23,32 @@
|
||||
#include "glshaders_types.h"
|
||||
|
||||
|
||||
class VertexObject
|
||||
{
|
||||
class VertexObject {
|
||||
public:
|
||||
VertexObject();
|
||||
~VertexObject();
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
void init(QOpenGLExtraFunctions * f);
|
||||
void destroy(QOpenGLExtraFunctions * f);
|
||||
void reinit();
|
||||
|
||||
void bind (QOpenGLExtraFunctions * f);
|
||||
void release (QOpenGLExtraFunctions * f);
|
||||
void bind(QOpenGLExtraFunctions * f);
|
||||
void release(QOpenGLExtraFunctions * f);
|
||||
|
||||
void bindBuffers (QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem, bool force = false);
|
||||
void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object);
|
||||
void loadObjects (QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects);
|
||||
void bindBuffers(QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem, bool force = false);
|
||||
void loadObject(QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object);
|
||||
void loadObjects(QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects);
|
||||
void loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels);
|
||||
|
||||
void draw(QOpenGLExtraFunctions * f, GLenum geom_type, int vert_cout, int obj_count);
|
||||
|
||||
GLuint ID() const {return vao_;}
|
||||
bool isInit() const {return vao_ != 0;}
|
||||
GLuint ID() const { return vao_; }
|
||||
bool isInit() const { return vao_ != 0; }
|
||||
|
||||
bool isObjectsChanged() const {return objects_changed;}
|
||||
bool isSelectionChanged() const {return selected_changed;}
|
||||
void setObjectsChanged(bool yes = true) {objects_changed = yes;}
|
||||
void setSelectionChanged(bool yes = true) {selected_changed = yes;}
|
||||
bool isObjectsChanged() const { return objects_changed; }
|
||||
bool isSelectionChanged() const { return selected_changed; }
|
||||
void setObjectsChanged(bool yes = true) { objects_changed = yes; }
|
||||
void setSelectionChanged(bool yes = true) { selected_changed = yes; }
|
||||
|
||||
private:
|
||||
void loadBuffer(QOpenGLExtraFunctions * f, Buffer & buf, const void * data, int size);
|
||||
|
||||
114
core/hdr.cpp
114
core/hdr.cpp
@@ -1,41 +1,41 @@
|
||||
/*
|
||||
QGL HDR
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL HDR
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "hdr_p.h"
|
||||
#include <qmath.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <qmath.h>
|
||||
|
||||
#define RGBE_DATA_RED 2
|
||||
#define RGBE_DATA_GREEN 1
|
||||
#define RGBE_DATA_BLUE 0
|
||||
#define RGBE_DATA_RED 2
|
||||
#define RGBE_DATA_GREEN 1
|
||||
#define RGBE_DATA_BLUE 0
|
||||
/* number of floats per pixel */
|
||||
#define RGBE_DATA_SIZE 3
|
||||
#define RGBE_DATA_SIZE 3
|
||||
|
||||
|
||||
void rgbe2float(float *red, float *green, float *blue, uchar rgbe[4]) {
|
||||
void rgbe2float(float * red, float * green, float * blue, uchar rgbe[4]) {
|
||||
float f;
|
||||
if (rgbe[3]) {
|
||||
f = static_cast<float>(ldexp(1.0,rgbe[3]-(int)(128+8)));
|
||||
*red = rgbe[0] * f;
|
||||
f = static_cast<float>(ldexp(1.0, rgbe[3] - (int)(128 + 8)));
|
||||
*red = rgbe[0] * f;
|
||||
*green = rgbe[1] * f;
|
||||
*blue = rgbe[2] * f;
|
||||
}
|
||||
else
|
||||
*blue = rgbe[2] * f;
|
||||
} else
|
||||
*red = *green = *blue = 0.0;
|
||||
}
|
||||
|
||||
@@ -43,10 +43,9 @@ void rgbe2float(float *red, float *green, float *blue, uchar rgbe[4]) {
|
||||
/* simple read routine. will not correctly handle run length encoding */
|
||||
bool RGBE_ReadPixels(QDataStream * fp, float * data, int numpixels) {
|
||||
uchar rgbe[4];
|
||||
while(numpixels-- > 0) {
|
||||
if (fp->readRawData((char*)rgbe, sizeof(rgbe)) < 1)
|
||||
return false;
|
||||
rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE],rgbe);
|
||||
while (numpixels-- > 0) {
|
||||
if (fp->readRawData((char *)rgbe, sizeof(rgbe)) < 1) return false;
|
||||
rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE], rgbe);
|
||||
data += RGBE_DATA_SIZE;
|
||||
}
|
||||
return true;
|
||||
@@ -59,50 +58,48 @@ bool RGBE_ReadPixels_RLE(QDataStream * fp, float * data, int scanline_width, int
|
||||
uchar buf[2];
|
||||
QByteArray scanline_buffer;
|
||||
|
||||
if ((scanline_width < 8)||(scanline_width > 0x7fff))
|
||||
/* run length encoding is not allowed so read flat*/
|
||||
return RGBE_ReadPixels(fp,data,scanline_width*num_scanlines);
|
||||
scanline_buffer.resize(4*scanline_width);
|
||||
if ((scanline_width < 8) || (scanline_width > 0x7fff)) /* run length encoding is not allowed so read flat*/
|
||||
return RGBE_ReadPixels(fp, data, scanline_width * num_scanlines);
|
||||
scanline_buffer.resize(4 * scanline_width);
|
||||
/* read in each successive scanline */
|
||||
while(num_scanlines > 0) {
|
||||
if (fp->readRawData((char*)rgbe,sizeof(rgbe)) < 1) {
|
||||
while (num_scanlines > 0) {
|
||||
if (fp->readRawData((char *)rgbe, sizeof(rgbe)) < 1) {
|
||||
return false;
|
||||
}
|
||||
if ((rgbe[0] != 2)||(rgbe[1] != 2)||(rgbe[2] & 0x80)) {
|
||||
if ((rgbe[0] != 2) || (rgbe[1] != 2) || (rgbe[2] & 0x80)) {
|
||||
/* this file is not run length encoded */
|
||||
rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],&data[RGBE_DATA_BLUE],rgbe);
|
||||
rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE], rgbe);
|
||||
data += RGBE_DATA_SIZE;
|
||||
return RGBE_ReadPixels(fp,data,scanline_width*num_scanlines-1);
|
||||
return RGBE_ReadPixels(fp, data, scanline_width * num_scanlines - 1);
|
||||
}
|
||||
if ((((int)rgbe[2])<<8 | rgbe[3]) != scanline_width) {
|
||||
if ((((int)rgbe[2]) << 8 | rgbe[3]) != scanline_width) {
|
||||
return false;
|
||||
}
|
||||
ptr = (uchar*)scanline_buffer.data();
|
||||
ptr = (uchar *)scanline_buffer.data();
|
||||
/* read each of the four channels for the scanline into the buffer */
|
||||
for(i=0;i<4;i++) {
|
||||
ptr_end = (uchar*)scanline_buffer.data() + ((i+1)*scanline_width);
|
||||
while(ptr < ptr_end) {
|
||||
if (fp->readRawData((char*)buf,sizeof(buf[0])*2) < 1) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
ptr_end = (uchar *)scanline_buffer.data() + ((i + 1) * scanline_width);
|
||||
while (ptr < ptr_end) {
|
||||
if (fp->readRawData((char *)buf, sizeof(buf[0]) * 2) < 1) {
|
||||
return false;
|
||||
}
|
||||
if (buf[0] > 128) {
|
||||
/* a run of the same value */
|
||||
count = buf[0]-128;
|
||||
if ((count == 0)||(count > ptr_end - ptr)) {
|
||||
return false;
|
||||
}
|
||||
while(count-- > 0)
|
||||
*ptr++ = buf[1];
|
||||
}
|
||||
else {
|
||||
/* a run of the same value */
|
||||
count = buf[0] - 128;
|
||||
if ((count == 0) || (count > ptr_end - ptr)) {
|
||||
return false;
|
||||
}
|
||||
while (count-- > 0)
|
||||
*ptr++ = buf[1];
|
||||
} else {
|
||||
/* a non-run */
|
||||
count = buf[0];
|
||||
if ((count == 0)||(count > ptr_end - ptr)) {
|
||||
if ((count == 0) || (count > ptr_end - ptr)) {
|
||||
return false;
|
||||
}
|
||||
*ptr++ = buf[1];
|
||||
if (--count > 0) {
|
||||
if (fp->readRawData((char*)ptr,sizeof(*ptr)*count) < 1) {
|
||||
if (fp->readRawData((char *)ptr, sizeof(*ptr) * count) < 1) {
|
||||
return false;
|
||||
}
|
||||
ptr += count;
|
||||
@@ -111,13 +108,12 @@ bool RGBE_ReadPixels_RLE(QDataStream * fp, float * data, int scanline_width, int
|
||||
}
|
||||
}
|
||||
/* now convert data from buffer into floats */
|
||||
for(i=0;i<scanline_width;i++) {
|
||||
for (i = 0; i < scanline_width; i++) {
|
||||
rgbe[0] = scanline_buffer[i];
|
||||
rgbe[1] = scanline_buffer[i+scanline_width];
|
||||
rgbe[2] = scanline_buffer[i+2*scanline_width];
|
||||
rgbe[3] = scanline_buffer[i+3*scanline_width];
|
||||
rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],
|
||||
&data[RGBE_DATA_BLUE],rgbe);
|
||||
rgbe[1] = scanline_buffer[i + scanline_width];
|
||||
rgbe[2] = scanline_buffer[i + 2 * scanline_width];
|
||||
rgbe[3] = scanline_buffer[i + 3 * scanline_width];
|
||||
rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE], rgbe);
|
||||
data += RGBE_DATA_SIZE;
|
||||
}
|
||||
num_scanlines--;
|
||||
|
||||
24
core/hdr_p.h
24
core/hdr_p.h
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
QGL HDR
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL HDR
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HDR_P_H
|
||||
|
||||
Reference in New Issue
Block a user