Set clang-format argument options.
This commit is contained in:
parent
7fac6bafb4
commit
c86a7744b3
@ -9,7 +9,6 @@ AlignEscapedNewlines: Left
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
@ -21,8 +20,10 @@ InsertBraces: true
|
||||
IndentAccessModifiers: true
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
BreakBeforeBraces: Linux
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeTernaryOperators: true
|
||||
|
@ -19,7 +19,8 @@ DebugConsole::DebugConsole(QWidget * owner, const QString & key) :
|
||||
{
|
||||
}
|
||||
|
||||
DebugConsole::DebugConsole(QWidget * owner, const QString & key,
|
||||
DebugConsole::DebugConsole(QWidget * owner,
|
||||
const QString & key,
|
||||
const QString & name)
|
||||
{
|
||||
ui_ = new Ui::DebugConsole;
|
||||
|
@ -36,9 +36,13 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent)
|
||||
// Add GUI 'view' toolbar option to show debug console.
|
||||
ui_->menuView->addAction(qtkWidget->getActionToggleConsole());
|
||||
// Refresh GUI widgets when scene or objects are updated.
|
||||
connect(qtkWidget->getScene(), &Qtk::Scene::sceneUpdated, this,
|
||||
connect(qtkWidget->getScene(),
|
||||
&Qtk::Scene::sceneUpdated,
|
||||
this,
|
||||
&MainWindow::refreshScene);
|
||||
connect(qtkWidget, &Qtk::QtkWidget::objectFocusChanged, ui_->qtk__ToolBox,
|
||||
connect(qtkWidget,
|
||||
&Qtk::QtkWidget::objectFocusChanged,
|
||||
ui_->qtk__ToolBox,
|
||||
&Qtk::ToolBox::updateFocus);
|
||||
}
|
||||
|
||||
|
@ -231,9 +231,10 @@ void QtkScene::init()
|
||||
// Building more complex objects for showing examples of lighting techniques
|
||||
|
||||
/* Test alien Model with phong lighting and specular mapping. */
|
||||
model = addObject(new Qtk::Model(
|
||||
"alienTest", ":/models/models/alien-hominid/alien.obj",
|
||||
":/shaders/model-specular.vert", ":/shaders/model-specular.frag"));
|
||||
model = addObject(new Qtk::Model("alienTest",
|
||||
":/models/models/alien-hominid/alien.obj",
|
||||
":/shaders/model-specular.vert",
|
||||
":/shaders/model-specular.frag"));
|
||||
model->getTransform().setTranslation(3.0f, -1.0f, 10.0f);
|
||||
model->getTransform().scale(0.15f);
|
||||
model->setUniform("uMaterial.ambient", QVector3D(1.0f, 1.0f, 1.0f));
|
||||
@ -257,9 +258,10 @@ void QtkScene::init()
|
||||
mesh->setColor(GREEN);
|
||||
|
||||
/* Test spartan Model with phong lighting, specular and normal mapping. */
|
||||
model = addObject(new Qtk::Model(
|
||||
"spartanTest", ":/models/models/spartan/spartan.obj",
|
||||
":/shaders/model-normals.vert", ":/shaders/model-normals.frag"));
|
||||
model = addObject(new Qtk::Model("spartanTest",
|
||||
":/models/models/spartan/spartan.obj",
|
||||
":/shaders/model-normals.vert",
|
||||
":/shaders/model-normals.frag"));
|
||||
model->getTransform().setTranslation(0.0f, -1.0f, 10.0f);
|
||||
model->getTransform().scale(2.0f);
|
||||
model->setUniform("uMaterial.ambient", QVector3D(1.0f, 1.0f, 1.0f));
|
||||
@ -493,8 +495,8 @@ void QtkScene::update()
|
||||
|
||||
// Rotate lighting example cubes
|
||||
mTestPhong->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
MeshRenderer::getInstance("noLight")->getTransform().rotate(0.75f, 0.5f, 0.3f,
|
||||
0.2f);
|
||||
MeshRenderer::getInstance("noLight")->getTransform().rotate(
|
||||
0.75f, 0.5f, 0.3f, 0.2f);
|
||||
mTestAmbient->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
mTestDiffuse->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
mTestSpecular->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
|
@ -88,7 +88,9 @@ void QtkWidget::initializeGL()
|
||||
mDebugLogger = new QOpenGLDebugLogger(this);
|
||||
if (mDebugLogger->initialize()) {
|
||||
qDebug() << "GL_DEBUG Debug Logger" << mDebugLogger << "\n";
|
||||
connect(mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), this,
|
||||
connect(mDebugLogger,
|
||||
SIGNAL(messageLogged(QOpenGLDebugMessage)),
|
||||
this,
|
||||
SLOT(messageLogged(QOpenGLDebugMessage)));
|
||||
mDebugLogger->startLogging();
|
||||
}
|
||||
@ -109,8 +111,8 @@ void QtkWidget::initializeGL()
|
||||
void QtkWidget::resizeGL(int width, int height)
|
||||
{
|
||||
Scene::getProjectionMatrix().setToIdentity();
|
||||
Scene::getProjectionMatrix().perspective(45.0f, float(width) / float(height),
|
||||
0.1f, 1000.0f);
|
||||
Scene::getProjectionMatrix().perspective(
|
||||
45.0f, float(width) / float(height), 0.1f, 1000.0f);
|
||||
}
|
||||
|
||||
void QtkWidget::paintGL()
|
||||
@ -126,7 +128,9 @@ void QtkWidget::setScene(Scene * scene)
|
||||
{
|
||||
if (mScene != Q_NULLPTR) {
|
||||
delete mScene;
|
||||
connect(scene, &Scene::sceneUpdated, MainWindow::getMainWindow(),
|
||||
connect(scene,
|
||||
&Scene::sceneUpdated,
|
||||
MainWindow::getMainWindow(),
|
||||
&MainWindow::refreshScene);
|
||||
}
|
||||
|
||||
|
@ -74,13 +74,19 @@ void ToolBox::createPageProperties(const Object * object)
|
||||
rowLayout->addWidget(spinBox);
|
||||
|
||||
if (i == 0) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
connect(spinBox,
|
||||
&QDoubleSpinBox::valueChanged,
|
||||
object,
|
||||
&Object::setTranslationX);
|
||||
} else if (i == 1) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
connect(spinBox,
|
||||
&QDoubleSpinBox::valueChanged,
|
||||
object,
|
||||
&Object::setTranslationY);
|
||||
} else if (i == 2) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
connect(spinBox,
|
||||
&QDoubleSpinBox::valueChanged,
|
||||
object,
|
||||
&Object::setTranslationZ);
|
||||
}
|
||||
}
|
||||
@ -97,14 +103,14 @@ void ToolBox::createPageProperties(const Object * object)
|
||||
rowLayout->addWidget(spinBox);
|
||||
|
||||
if (i == 0) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setScaleX);
|
||||
connect(
|
||||
spinBox, &QDoubleSpinBox::valueChanged, object, &Object::setScaleX);
|
||||
} else if (i == 1) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setScaleY);
|
||||
connect(
|
||||
spinBox, &QDoubleSpinBox::valueChanged, object, &Object::setScaleY);
|
||||
} else if (i == 2) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setScaleZ);
|
||||
connect(
|
||||
spinBox, &QDoubleSpinBox::valueChanged, object, &Object::setScaleZ);
|
||||
}
|
||||
}
|
||||
layout->addRow(rowLayout);
|
||||
|
@ -19,7 +19,9 @@ Qtk::TreeView::TreeView(QWidget * parent) :
|
||||
QDockWidget(parent), ui(new Ui::TreeView)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->treeWidget, &QTreeWidget::itemDoubleClicked, this,
|
||||
connect(ui->treeWidget,
|
||||
&QTreeWidget::itemDoubleClicked,
|
||||
this,
|
||||
&TreeView::itemFocus);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,9 @@
|
||||
* Constructors, Destructors
|
||||
******************************************************************************/
|
||||
|
||||
WidgetPlugin::WidgetPlugin(QString group, QString class_name, QString include,
|
||||
WidgetPlugin::WidgetPlugin(QString group,
|
||||
QString class_name,
|
||||
QString include,
|
||||
WidgetPlugin::Factory factory) :
|
||||
m_group(std::move(group)), m_className(std::move(class_name)),
|
||||
m_includeFile(std::move(include)), m_factory(std::move(factory)),
|
||||
|
@ -27,7 +27,9 @@ class QDESIGNER_WIDGET_EXPORT WidgetPlugin :
|
||||
* Contructors / Destructors
|
||||
**************************************************************************/
|
||||
|
||||
WidgetPlugin(QString group, QString class_name, QString include,
|
||||
WidgetPlugin(QString group,
|
||||
QString class_name,
|
||||
QString include,
|
||||
Factory factory);
|
||||
|
||||
explicit WidgetPlugin(QObject * parent = nullptr);
|
||||
|
@ -23,13 +23,19 @@ WidgetPluginCollection::WidgetPluginCollection(QObject * parent) :
|
||||
{
|
||||
m_collection = {
|
||||
new WidgetPlugin(
|
||||
m_collectionName, "Qtk::QtkWidget", "qtkwidget.h",
|
||||
m_collectionName,
|
||||
"Qtk::QtkWidget",
|
||||
"qtkwidget.h",
|
||||
[](QWidget * parent) { return new Qtk::QtkWidget(parent); }),
|
||||
new WidgetPlugin(
|
||||
m_collectionName, "Qtk::TreeView", "treeview.h",
|
||||
m_collectionName,
|
||||
"Qtk::TreeView",
|
||||
"treeview.h",
|
||||
[](QWidget * parent) { return new Qtk::TreeView(parent); }),
|
||||
new WidgetPlugin(
|
||||
m_collectionName, "Qtk::ToolBox", "toolbox.h",
|
||||
m_collectionName,
|
||||
"Qtk::ToolBox",
|
||||
"toolbox.h",
|
||||
[](QWidget * parent) { return new Qtk::ToolBox(parent); }),
|
||||
};
|
||||
}
|
||||
|
@ -21,8 +21,10 @@ Qtk::MeshRenderer::MeshManager Qtk::MeshRenderer::sInstances;
|
||||
* Constructors / Destructors
|
||||
******************************************************************************/
|
||||
|
||||
MeshRenderer::MeshRenderer(const char * name, Vertices vertices,
|
||||
Indices indices, DrawMode mode) :
|
||||
MeshRenderer::MeshRenderer(const char * name,
|
||||
Vertices vertices,
|
||||
Indices indices,
|
||||
DrawMode mode) :
|
||||
MeshRenderer(name, ShapeBase(mode, std::move(vertices), std::move(indices)))
|
||||
{
|
||||
}
|
||||
@ -90,9 +92,11 @@ void MeshRenderer::init()
|
||||
mProgram.setAttributeBuffer(0, GL_FLOAT, 0, 3, sizeof(QVector3D));
|
||||
// Enable color attribute, setting offset to total size of vertices()
|
||||
mProgram.enableAttributeArray(1);
|
||||
mProgram.setAttributeBuffer(1, GL_FLOAT,
|
||||
mProgram.setAttributeBuffer(1,
|
||||
GL_FLOAT,
|
||||
getVertices().size() * sizeof(getVertices()[0]),
|
||||
3, sizeof(QVector3D));
|
||||
3,
|
||||
sizeof(QVector3D));
|
||||
|
||||
mVBO.release();
|
||||
|
||||
@ -116,7 +120,9 @@ void MeshRenderer::draw()
|
||||
glDrawArrays(mDrawType, 0, getVertices().size());
|
||||
} else if (mShape.mDrawMode == QTK_DRAW_ELEMENTS
|
||||
|| mShape.mDrawMode == QTK_DRAW_ELEMENTS_NORMALS) {
|
||||
glDrawElements(mDrawType, mShape.mIndices.size(), GL_UNSIGNED_INT,
|
||||
glDrawElements(mDrawType,
|
||||
mShape.mIndices.size(),
|
||||
GL_UNSIGNED_INT,
|
||||
mShape.mIndices.data());
|
||||
}
|
||||
|
||||
@ -179,7 +185,8 @@ void MeshRenderer::setShaders(const std::string & vert,
|
||||
init();
|
||||
}
|
||||
|
||||
void MeshRenderer::setUniformMVP(const char * model, const char * view,
|
||||
void MeshRenderer::setUniformMVP(const char * model,
|
||||
const char * view,
|
||||
const char * projection)
|
||||
{
|
||||
ShaderBindScope lock(&mProgram, mBound);
|
||||
@ -209,8 +216,8 @@ void MeshRenderer::setColor(const QVector3D & color)
|
||||
init();
|
||||
}
|
||||
|
||||
void MeshRenderer::setAttributeBuffer(int location, GLenum type, int offset,
|
||||
int tupleSize, int stride)
|
||||
void MeshRenderer::setAttributeBuffer(
|
||||
int location, GLenum type, int offset, int tupleSize, int stride)
|
||||
{
|
||||
ShaderBindScope lock(&mProgram, mBound);
|
||||
mVAO.bind();
|
||||
|
@ -40,7 +40,9 @@ namespace Qtk
|
||||
* @param indices Indicess to use for initializes geometry shape.
|
||||
* @param mode OpenGL draw mode. Supported modes are prefixed with QTK_*
|
||||
*/
|
||||
MeshRenderer(const char * name, Vertices vertices, Indices indices,
|
||||
MeshRenderer(const char * name,
|
||||
Vertices vertices,
|
||||
Indices indices,
|
||||
DrawMode mode = QTK_DRAW_ARRAYS);
|
||||
|
||||
/**
|
||||
@ -197,8 +199,8 @@ namespace Qtk
|
||||
* @param stride Stride between groups of elements in the buffer.
|
||||
* For example (x, y) data stride is `2 * sizeof(type)`
|
||||
*/
|
||||
void setAttributeBuffer(int location, GLenum type, int offset,
|
||||
int tupleSize, int stride = 0);
|
||||
void setAttributeBuffer(
|
||||
int location, GLenum type, int offset, int tupleSize, int stride = 0);
|
||||
|
||||
/*************************************************************************
|
||||
* Accessors
|
||||
|
@ -80,10 +80,10 @@ void Model::loadModel(const std::string & path)
|
||||
// + And flipping texture UVs, etc..
|
||||
// Assimp options: http://assimp.sourceforge.net/lib_html/postprocess_8h.html
|
||||
const aiScene * scene = import.ReadFile(
|
||||
path.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs
|
||||
| aiProcess_GenSmoothNormals
|
||||
| aiProcess_CalcTangentSpace | aiProcess_OptimizeMeshes
|
||||
| aiProcess_SplitLargeMeshes);
|
||||
path.c_str(),
|
||||
aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenSmoothNormals
|
||||
| aiProcess_CalcTangentSpace | aiProcess_OptimizeMeshes
|
||||
| aiProcess_SplitLargeMeshes);
|
||||
|
||||
// If there were errors, print and return
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE
|
||||
@ -208,7 +208,10 @@ ModelMesh Model::processMesh(aiMesh * mesh, const aiScene * scene)
|
||||
textures.insert(textures.end(), normalMaps.begin(), normalMaps.end());
|
||||
}
|
||||
|
||||
return {vertices, indices, textures, mVertexShader.c_str(),
|
||||
return {vertices,
|
||||
indices,
|
||||
textures,
|
||||
mVertexShader.c_str(),
|
||||
mFragmentShader.c_str()};
|
||||
}
|
||||
|
||||
@ -239,7 +242,8 @@ ModelMesh::Textures Model::loadMaterialTextures(aiMaterial * mat,
|
||||
if (!skip) {
|
||||
ModelTexture texture;
|
||||
texture.mTexture = OpenGLTextureFactory::initTexture(
|
||||
std::string(mDirectory + '/' + fileName.C_Str()).c_str(), false,
|
||||
std::string(mDirectory + '/' + fileName.C_Str()).c_str(),
|
||||
false,
|
||||
false);
|
||||
texture.mID = texture.mTexture->textureId();
|
||||
texture.mType = typeName;
|
||||
|
@ -53,7 +53,8 @@ namespace Qtk
|
||||
* @param vertexShader Optional path to custom vertex shader.
|
||||
* @param fragmentShader Optional path to custom fragment shader.
|
||||
*/
|
||||
inline Model(const char * name, const char * path,
|
||||
inline Model(const char * name,
|
||||
const char * path,
|
||||
const char * vertexShader = ":/shaders/model-basic.vert",
|
||||
const char * fragmentShader = ":/shaders/model-basic.frag") :
|
||||
Object(name, QTK_MODEL), mModelPath(path),
|
||||
@ -87,7 +88,8 @@ namespace Qtk
|
||||
* @param flipX Flip the texture along the X axis
|
||||
* @param flipY Flip the texture along the Y axis
|
||||
*/
|
||||
void flipTexture(const std::string & fileName, bool flipX = false,
|
||||
void flipTexture(const std::string & fileName,
|
||||
bool flipX = false,
|
||||
bool flipY = true);
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -58,8 +58,8 @@ void ModelMesh::draw(QOpenGLShaderProgram & shader)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// Draw the mesh
|
||||
glDrawElements(GL_TRIANGLES, mIndices.size(), GL_UNSIGNED_INT,
|
||||
mIndices.data());
|
||||
glDrawElements(
|
||||
GL_TRIANGLES, mIndices.size(), GL_UNSIGNED_INT, mIndices.data());
|
||||
|
||||
// Release shader, textures
|
||||
for (const auto & texture : mTextures) {
|
||||
@ -104,29 +104,31 @@ void ModelMesh::initMesh(const char * vert, const char * frag)
|
||||
|
||||
// Positions
|
||||
mProgram->enableAttributeArray(0);
|
||||
mProgram->setAttributeBuffer(0, GL_FLOAT, offsetof(ModelVertex, mPosition), 3,
|
||||
sizeof(ModelVertex));
|
||||
mProgram->setAttributeBuffer(
|
||||
0, GL_FLOAT, offsetof(ModelVertex, mPosition), 3, sizeof(ModelVertex));
|
||||
|
||||
// Normals
|
||||
mProgram->enableAttributeArray(1);
|
||||
mProgram->setAttributeBuffer(1, GL_FLOAT, offsetof(ModelVertex, mNormal), 3,
|
||||
sizeof(ModelVertex));
|
||||
mProgram->setAttributeBuffer(
|
||||
1, GL_FLOAT, offsetof(ModelVertex, mNormal), 3, sizeof(ModelVertex));
|
||||
|
||||
// Texture Coordinates
|
||||
mProgram->enableAttributeArray(2);
|
||||
mProgram->setAttributeBuffer(2, GL_FLOAT,
|
||||
offsetof(ModelVertex, mTextureCoord), 2,
|
||||
mProgram->setAttributeBuffer(2,
|
||||
GL_FLOAT,
|
||||
offsetof(ModelVertex, mTextureCoord),
|
||||
2,
|
||||
sizeof(ModelVertex));
|
||||
|
||||
// Vertex tangents
|
||||
mProgram->enableAttributeArray(3);
|
||||
mProgram->setAttributeBuffer(3, GL_FLOAT, offsetof(ModelVertex, mTangent), 3,
|
||||
sizeof(ModelVertex));
|
||||
mProgram->setAttributeBuffer(
|
||||
3, GL_FLOAT, offsetof(ModelVertex, mTangent), 3, sizeof(ModelVertex));
|
||||
|
||||
// Vertex bitangents
|
||||
mProgram->enableAttributeArray(4);
|
||||
mProgram->setAttributeBuffer(4, GL_FLOAT, offsetof(ModelVertex, mBitangent),
|
||||
3, sizeof(ModelVertex));
|
||||
mProgram->setAttributeBuffer(
|
||||
4, GL_FLOAT, offsetof(ModelVertex, mBitangent), 3, sizeof(ModelVertex));
|
||||
|
||||
mProgram->release();
|
||||
mVBO->release();
|
||||
|
@ -94,7 +94,9 @@ namespace Qtk
|
||||
* @param vertexShader Path to vertex shader for this ModelMesh.
|
||||
* @param fragmentShader Path to fragment shader for this ModelMesh.
|
||||
*/
|
||||
ModelMesh(Vertices vertices, Indices indices, Textures textures,
|
||||
ModelMesh(Vertices vertices,
|
||||
Indices indices,
|
||||
Textures textures,
|
||||
const char * vertexShader = ":/model-basic.vert",
|
||||
const char * fragmentShader = ":/model-basic.frag") :
|
||||
mProgram(new QOpenGLShaderProgram),
|
||||
|
@ -149,7 +149,8 @@ namespace Qtk
|
||||
mShape.mTexCoords = value;
|
||||
}
|
||||
|
||||
virtual inline void setTexture(const char * path, bool flipX = false,
|
||||
virtual inline void setTexture(const char * path,
|
||||
bool flipX = false,
|
||||
bool flipY = false)
|
||||
{
|
||||
mTexture.setTexture(path, flipX, flipY);
|
||||
@ -172,38 +173,41 @@ namespace Qtk
|
||||
|
||||
inline void setScaleX(double x)
|
||||
{
|
||||
mTransform.setScale(x, mTransform.getScale().y(),
|
||||
mTransform.getScale().z());
|
||||
mTransform.setScale(
|
||||
x, mTransform.getScale().y(), mTransform.getScale().z());
|
||||
}
|
||||
|
||||
inline void setScaleY(double y)
|
||||
{
|
||||
mTransform.setScale(mTransform.getScale().x(), y,
|
||||
mTransform.getScale().z());
|
||||
mTransform.setScale(
|
||||
mTransform.getScale().x(), y, mTransform.getScale().z());
|
||||
}
|
||||
|
||||
inline void setScaleZ(double z)
|
||||
{
|
||||
mTransform.setScale(mTransform.getScale().x(),
|
||||
mTransform.getScale().y(), z);
|
||||
mTransform.setScale(
|
||||
mTransform.getScale().x(), mTransform.getScale().y(), z);
|
||||
}
|
||||
|
||||
inline void setTranslationX(double x)
|
||||
{
|
||||
mTransform.setTranslation(x, mTransform.getTranslation().y(),
|
||||
mTransform.setTranslation(x,
|
||||
mTransform.getTranslation().y(),
|
||||
mTransform.getTranslation().z());
|
||||
}
|
||||
|
||||
inline void setTranslationY(double y)
|
||||
{
|
||||
mTransform.setTranslation(mTransform.getTranslation().x(), y,
|
||||
mTransform.setTranslation(mTransform.getTranslation().x(),
|
||||
y,
|
||||
mTransform.getTranslation().z());
|
||||
}
|
||||
|
||||
inline void setTranslationZ(double z)
|
||||
{
|
||||
mTransform.setTranslation(mTransform.getTranslation().x(),
|
||||
mTransform.getTranslation().y(), z);
|
||||
mTransform.getTranslation().y(),
|
||||
z);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -115,8 +115,11 @@ namespace Qtk
|
||||
* @param t Texture coordinates for this shape.
|
||||
* @param n Normals for this shape.
|
||||
*/
|
||||
explicit ShapeBase(DrawMode mode = QTK_DRAW_ARRAYS, Vertices v = {},
|
||||
Indices i = {}, Colors c = {}, TexCoords t = {},
|
||||
explicit ShapeBase(DrawMode mode = QTK_DRAW_ARRAYS,
|
||||
Vertices v = {},
|
||||
Indices i = {},
|
||||
Colors c = {},
|
||||
TexCoords t = {},
|
||||
Normals n = {}) :
|
||||
mDrawMode(mode), mVertices(std::move(v)), mColors(std::move(c)),
|
||||
mIndices(std::move(i)), mTexCoords(std::move(t)),
|
||||
|
@ -17,9 +17,13 @@ using namespace Qtk;
|
||||
******************************************************************************/
|
||||
|
||||
Skybox::Skybox(const std::string & name) :
|
||||
Skybox(":/textures/skybox/right.png", ":/textures/skybox/top.png",
|
||||
":/textures/skybox/front.png", ":/textures/skybox/left.png",
|
||||
":/textures/skybox/bottom.png", ":/textures/skybox/back.png", name)
|
||||
Skybox(":/textures/skybox/right.png",
|
||||
":/textures/skybox/top.png",
|
||||
":/textures/skybox/front.png",
|
||||
":/textures/skybox/left.png",
|
||||
":/textures/skybox/bottom.png",
|
||||
":/textures/skybox/back.png",
|
||||
name)
|
||||
{
|
||||
}
|
||||
|
||||
@ -29,18 +33,24 @@ Skybox::Skybox(QOpenGLTexture * cubeMap, const std::string & name)
|
||||
init();
|
||||
}
|
||||
|
||||
Skybox::Skybox(const std::string & right, const std::string & top,
|
||||
const std::string & front, const std::string & left,
|
||||
const std::string & bottom, const std::string & back,
|
||||
Skybox::Skybox(const std::string & right,
|
||||
const std::string & top,
|
||||
const std::string & front,
|
||||
const std::string & left,
|
||||
const std::string & bottom,
|
||||
const std::string & back,
|
||||
const std::string & name) :
|
||||
mVBO(QOpenGLBuffer::VertexBuffer),
|
||||
mVertices(Cube(QTK_DRAW_ELEMENTS).getVertices()),
|
||||
mIndices(Cube(QTK_DRAW_ELEMENTS).getIndexData())
|
||||
{
|
||||
init();
|
||||
mTexture.setCubeMap(QImage(right.c_str()).mirrored(), QImage(top.c_str()),
|
||||
QImage(front.c_str()), QImage(left.c_str()),
|
||||
QImage(bottom.c_str()), QImage(back.c_str()));
|
||||
mTexture.setCubeMap(QImage(right.c_str()).mirrored(),
|
||||
QImage(top.c_str()),
|
||||
QImage(front.c_str()),
|
||||
QImage(left.c_str()),
|
||||
QImage(bottom.c_str()),
|
||||
QImage(back.c_str()));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
@ -59,8 +69,8 @@ void Skybox::draw()
|
||||
mProgram.setUniformValue("uProjectionMatrix", Scene::getProjectionMatrix());
|
||||
mProgram.setUniformValue("uViewMatrix", Scene::getCamera().toMatrix());
|
||||
mProgram.setUniformValue("uTexture", 0);
|
||||
glDrawElements(GL_TRIANGLES, mIndices.size(), GL_UNSIGNED_INT,
|
||||
mIndices.data());
|
||||
glDrawElements(
|
||||
GL_TRIANGLES, mIndices.size(), GL_UNSIGNED_INT, mIndices.data());
|
||||
|
||||
mTexture.getOpenGLTexture().bind();
|
||||
mProgram.release();
|
||||
|
@ -64,9 +64,12 @@ namespace Qtk
|
||||
* @param back Image to use for the back side of the Skybox.
|
||||
* @param name The objectName to use for this Skybox.
|
||||
*/
|
||||
Skybox(const std::string & right, const std::string & top,
|
||||
const std::string & front, const std::string & left,
|
||||
const std::string & bottom, const std::string & back,
|
||||
Skybox(const std::string & right,
|
||||
const std::string & top,
|
||||
const std::string & front,
|
||||
const std::string & left,
|
||||
const std::string & bottom,
|
||||
const std::string & back,
|
||||
const std::string & name = "Skybox");
|
||||
|
||||
~Skybox() = default;
|
||||
|
@ -14,7 +14,8 @@
|
||||
|
||||
using namespace Qtk;
|
||||
|
||||
QImage OpenGLTextureFactory::initImage(const char * image, bool flipX,
|
||||
QImage OpenGLTextureFactory::initImage(const char * image,
|
||||
bool flipX,
|
||||
bool flipY)
|
||||
{
|
||||
// Qt6 limits loaded images to 256MB by default
|
||||
@ -28,7 +29,8 @@ QImage OpenGLTextureFactory::initImage(const char * image, bool flipX,
|
||||
}
|
||||
|
||||
QOpenGLTexture * OpenGLTextureFactory::initTexture(const char * texture,
|
||||
bool flipX, bool flipY)
|
||||
bool flipX,
|
||||
bool flipY)
|
||||
{
|
||||
QImage image = initImage(texture, flipX, flipY);
|
||||
auto newTexture = new QOpenGLTexture(QOpenGLTexture::Target2D);
|
||||
@ -41,21 +43,35 @@ QOpenGLTexture * OpenGLTextureFactory::initTexture(const char * texture,
|
||||
|
||||
QOpenGLTexture * OpenGLTextureFactory::initCubeMap(const char * tile)
|
||||
{
|
||||
return initCubeMap(QImage(tile), QImage(tile), QImage(tile), QImage(tile),
|
||||
QImage(tile), QImage(tile));
|
||||
return initCubeMap(QImage(tile),
|
||||
QImage(tile),
|
||||
QImage(tile),
|
||||
QImage(tile),
|
||||
QImage(tile),
|
||||
QImage(tile));
|
||||
}
|
||||
|
||||
QOpenGLTexture * OpenGLTextureFactory::initCubeMap(
|
||||
const char * right, const char * top, const char * front, const char * left,
|
||||
const char * bottom, const char * back)
|
||||
QOpenGLTexture * OpenGLTextureFactory::initCubeMap(const char * right,
|
||||
const char * top,
|
||||
const char * front,
|
||||
const char * left,
|
||||
const char * bottom,
|
||||
const char * back)
|
||||
{
|
||||
return initCubeMap(QImage(right), QImage(top), QImage(front), QImage(left),
|
||||
QImage(bottom), QImage(back));
|
||||
return initCubeMap(QImage(right),
|
||||
QImage(top),
|
||||
QImage(front),
|
||||
QImage(left),
|
||||
QImage(bottom),
|
||||
QImage(back));
|
||||
}
|
||||
|
||||
QOpenGLTexture * OpenGLTextureFactory::initCubeMap(
|
||||
const QImage & right, const QImage & top, const QImage & front,
|
||||
const QImage & left, const QImage & bottom, const QImage & back)
|
||||
QOpenGLTexture * OpenGLTextureFactory::initCubeMap(const QImage & right,
|
||||
const QImage & top,
|
||||
const QImage & front,
|
||||
const QImage & left,
|
||||
const QImage & bottom,
|
||||
const QImage & back)
|
||||
{
|
||||
auto texture = new QOpenGLTexture(QOpenGLTexture::TargetCubeMap);
|
||||
std::vector<QImage> faceTextures = {right, top, front, left, bottom, back};
|
||||
@ -64,9 +80,12 @@ QOpenGLTexture * OpenGLTextureFactory::initCubeMap(
|
||||
texture->bind();
|
||||
// For each cube map face
|
||||
std::vector<QOpenGLTexture::CubeMapFace> faces = {
|
||||
QOpenGLTexture::CubeMapPositiveX, QOpenGLTexture::CubeMapPositiveY,
|
||||
QOpenGLTexture::CubeMapPositiveZ, QOpenGLTexture::CubeMapNegativeX,
|
||||
QOpenGLTexture::CubeMapNegativeY, QOpenGLTexture::CubeMapNegativeZ};
|
||||
QOpenGLTexture::CubeMapPositiveX,
|
||||
QOpenGLTexture::CubeMapPositiveY,
|
||||
QOpenGLTexture::CubeMapPositiveZ,
|
||||
QOpenGLTexture::CubeMapNegativeX,
|
||||
QOpenGLTexture::CubeMapNegativeY,
|
||||
QOpenGLTexture::CubeMapNegativeZ};
|
||||
int i = 0;
|
||||
for (const auto & face : faces) {
|
||||
QImage faceImage(faceTextures[i]);
|
||||
@ -79,13 +98,17 @@ QOpenGLTexture * OpenGLTextureFactory::initCubeMap(
|
||||
// On the first iteration, set format and allocate texture storage
|
||||
if (face == QOpenGLTexture::CubeMapPositiveX) {
|
||||
// This also needs to happen on the first iteration, anyways
|
||||
texture->setSize(faceImage.width(), faceImage.height(),
|
||||
faceImage.depth());
|
||||
texture->setSize(
|
||||
faceImage.width(), faceImage.height(), faceImage.depth());
|
||||
texture->setFormat(QOpenGLTexture::RGBA8_UNorm);
|
||||
texture->allocateStorage();
|
||||
}
|
||||
|
||||
texture->setData(0, 0, face, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8,
|
||||
texture->setData(0,
|
||||
0,
|
||||
face,
|
||||
QOpenGLTexture::RGBA,
|
||||
QOpenGLTexture::UInt8,
|
||||
faceImage.constBits());
|
||||
i++;
|
||||
}
|
||||
|
@ -80,7 +80,8 @@ namespace Qtk
|
||||
* @param flipY If true the image will be flipped on Y axis.
|
||||
* @return QImage object.
|
||||
*/
|
||||
static QImage initImage(const char * image, bool flipX = false,
|
||||
static QImage initImage(const char * image,
|
||||
bool flipX = false,
|
||||
bool flipY = false);
|
||||
|
||||
/**
|
||||
@ -108,9 +109,12 @@ namespace Qtk
|
||||
* @param back Path to image for the back side of the CubeMap.
|
||||
* @return Pointer to an initialized QOpenGLTexture object.
|
||||
*/
|
||||
static QOpenGLTexture * initCubeMap(
|
||||
const QImage & right, const QImage & top, const QImage & front,
|
||||
const QImage & left, const QImage & bottom, const QImage & back);
|
||||
static QOpenGLTexture * initCubeMap(const QImage & right,
|
||||
const QImage & top,
|
||||
const QImage & front,
|
||||
const QImage & left,
|
||||
const QImage & bottom,
|
||||
const QImage & back);
|
||||
|
||||
/**
|
||||
* CubeMap factory for tiling the same image on all sides.
|
||||
@ -133,8 +137,10 @@ namespace Qtk
|
||||
* @param back Path to image for the back side of the CubeMap.
|
||||
* @return Pointer to an initialized QOpenGLTexture object.
|
||||
*/
|
||||
static QOpenGLTexture * initCubeMap(const char * right, const char * top,
|
||||
const char * front, const char * left,
|
||||
static QOpenGLTexture * initCubeMap(const char * right,
|
||||
const char * top,
|
||||
const char * front,
|
||||
const char * left,
|
||||
const char * bottom,
|
||||
const char * back);
|
||||
|
||||
@ -188,7 +194,8 @@ namespace Qtk
|
||||
* @param flipX True if texture is to be flipped on the X axis.
|
||||
* @param flipY True if texture is to be flipped on the Y axis.
|
||||
*/
|
||||
explicit Texture(const char * path, bool flipX = false,
|
||||
explicit Texture(const char * path,
|
||||
bool flipX = false,
|
||||
bool flipY = false) :
|
||||
mOpenGLTexture(OpenGLTextureFactory::initTexture(path, flipX, flipY)),
|
||||
mPath(path)
|
||||
@ -244,7 +251,8 @@ namespace Qtk
|
||||
* @param flipX True if texture is to be flipped on the X axis.
|
||||
* @param flipY True if texture is to be flipped on the Y axis.
|
||||
*/
|
||||
inline void setTexture(const std::string & path, bool flipX = false,
|
||||
inline void setTexture(const std::string & path,
|
||||
bool flipX = false,
|
||||
bool flipY = false)
|
||||
{
|
||||
setTexture(path.c_str(), flipX, flipY);
|
||||
@ -255,7 +263,8 @@ namespace Qtk
|
||||
* @param flipX True if texture is to be flipped on the X axis.
|
||||
* @param flipY True if texture is to be flipped on the Y axis.
|
||||
*/
|
||||
inline void setTexture(const char * path, bool flipX = false,
|
||||
inline void setTexture(const char * path,
|
||||
bool flipX = false,
|
||||
bool flipY = false)
|
||||
{
|
||||
mOpenGLTexture = OpenGLTextureFactory::initTexture(path, flipX, flipY);
|
||||
@ -283,12 +292,15 @@ namespace Qtk
|
||||
* @param bottom Path to texture to use for bottom cube map side.
|
||||
* @param back Path to texture to use for back cube map side.
|
||||
*/
|
||||
virtual inline void setCubeMap(const char * right, const char * top,
|
||||
const char * front, const char * left,
|
||||
const char * bottom, const char * back)
|
||||
virtual inline void setCubeMap(const char * right,
|
||||
const char * top,
|
||||
const char * front,
|
||||
const char * left,
|
||||
const char * bottom,
|
||||
const char * back)
|
||||
{
|
||||
mOpenGLTexture = OpenGLTextureFactory::initCubeMap(right, top, front,
|
||||
left, bottom, back);
|
||||
mOpenGLTexture = OpenGLTextureFactory::initCubeMap(
|
||||
right, top, front, left, bottom, back);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -301,12 +313,15 @@ namespace Qtk
|
||||
* @param bottom Path to texture to use for bottom cube map side.
|
||||
* @param back Path to texture to use for back cube map side.
|
||||
*/
|
||||
virtual inline void setCubeMap(const QImage & right, const QImage & top,
|
||||
const QImage & front, const QImage & left,
|
||||
const QImage & bottom, const QImage & back)
|
||||
virtual inline void setCubeMap(const QImage & right,
|
||||
const QImage & top,
|
||||
const QImage & front,
|
||||
const QImage & left,
|
||||
const QImage & bottom,
|
||||
const QImage & back)
|
||||
{
|
||||
mOpenGLTexture = OpenGLTextureFactory::initCubeMap(right, top, front,
|
||||
left, bottom, back);
|
||||
mOpenGLTexture = OpenGLTextureFactory::initCubeMap(
|
||||
right, top, front, left, bottom, back);
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user