Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt6 support #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions src/imgui-qt3d/imguimanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
#include <QScissorTest>
#include <QFrameAction>

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
namespace core = Qt3DRender;
#else
namespace core = Qt3DCore;
#endif

class ImguiTextureImageDataGen : public Qt3DRender::QTextureImageDataGenerator
{
public:
Expand Down Expand Up @@ -222,50 +228,50 @@ void ImguiManager::resizePool(CmdListEntry *e, int newSize)
void ImguiManager::updateGeometry(CmdListEntry *e, int idx, uint elemCount, int vertexCount, int indexCount, const void *indexOffset)
{
Qt3DRender::QGeometryRenderer *gr = e->cmds[idx].geomRenderer;
Qt3DRender::QGeometry *g = gr->geometry();
core::QGeometry *g = gr->geometry();

if (!g) {
gr->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
g = new Qt3DRender::QGeometry;
g = new core::QGeometry;

for (int i = 0; i < 4; ++i)
g->addAttribute(new Qt3DRender::QAttribute);
g->addAttribute(new core::QAttribute);

const int vsize = 3; // assumes ImDrawVert was overridden in imconfig.h
Q_ASSERT(sizeof(ImDrawVert) == (vsize + 2) * sizeof(float) + sizeof(ImU32));

const QVector<Qt3DRender::QAttribute *> attrs = g->attributes();
Qt3DRender::QAttribute *attr = attrs[0];
const QVector<core::QAttribute *> attrs = g->attributes();
core::QAttribute *attr = attrs[0];
attr->setBuffer(e->vbuf);
attr->setName(Qt3DRender::QAttribute::defaultPositionAttributeName());
attr->setVertexBaseType(Qt3DRender::QAttribute::Float);
attr->setName(core::QAttribute::defaultPositionAttributeName());
attr->setVertexBaseType(core::QAttribute::Float);
attr->setVertexSize(vsize);
attr->setCount(vertexCount);
attr->setByteOffset(0);
attr->setByteStride(sizeof(ImDrawVert));

attr = attrs[1];
attr->setBuffer(e->vbuf);
attr->setName(Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName());
attr->setVertexBaseType(Qt3DRender::QAttribute::Float);
attr->setName(core::QAttribute::defaultTextureCoordinateAttributeName());
attr->setVertexBaseType(core::QAttribute::Float);
attr->setVertexSize(2);
attr->setCount(vertexCount);
attr->setByteOffset(vsize * sizeof(float));
attr->setByteStride(sizeof(ImDrawVert));

attr = attrs[2];
attr->setBuffer(e->vbuf);
attr->setName(Qt3DRender::QAttribute::defaultColorAttributeName());
attr->setVertexBaseType(Qt3DRender::QAttribute::UnsignedByte);
attr->setName(core::QAttribute::defaultColorAttributeName());
attr->setVertexBaseType(core::QAttribute::UnsignedByte);
attr->setVertexSize(4);
attr->setCount(vertexCount);
attr->setByteOffset((vsize + 2) * sizeof(float));
attr->setByteStride(sizeof(ImDrawVert));

attr = attrs[3];
attr->setBuffer(e->ibuf);
attr->setAttributeType(Qt3DRender::QAttribute::IndexAttribute);
attr->setVertexBaseType(sizeof(ImDrawIdx) == 2 ? Qt3DRender::QAttribute::UnsignedShort : Qt3DRender::QAttribute::UnsignedInt);
attr->setAttributeType(core::QAttribute::IndexAttribute);
attr->setVertexBaseType(sizeof(ImDrawIdx) == 2 ? core::QAttribute::UnsignedShort : core::QAttribute::UnsignedInt);
attr->setVertexSize(1);
attr->setCount(indexCount);
attr->setByteOffset((quintptr) indexOffset);
Expand All @@ -274,10 +280,10 @@ void ImguiManager::updateGeometry(CmdListEntry *e, int idx, uint elemCount, int
gr->setGeometry(g);
} else {
// only update the potentially changing properties afterwards
const QVector<Qt3DRender::QAttribute *> attrs = g->attributes();
const QVector<core::QAttribute *> attrs = g->attributes();
Q_ASSERT(attrs.count() == 4);

Qt3DRender::QAttribute *attr = attrs[0];
core::QAttribute *attr = attrs[0];
attr->setBuffer(e->vbuf);
attr->setCount(vertexCount);

Expand Down Expand Up @@ -323,8 +329,8 @@ void ImguiManager::update3D()
CmdListEntry *e = &m_cmdList[n];

if (!e->vbuf) {
e->vbuf = new Qt3DRender::QBuffer;
e->vbuf->setUsage(Qt3DRender::QBuffer::StreamDraw);
e->vbuf = new core::QBuffer;
e->vbuf->setUsage(core::QBuffer::StreamDraw);
}
// NB! must make a copy in any case, fromRawData would be wrong here
// even if we did not need to insert the dummy z values.
Expand All @@ -350,8 +356,8 @@ void ImguiManager::update3D()
e->vbuf->setData(vdata);

if (!e->ibuf) {
e->ibuf = new Qt3DRender::QBuffer;
e->ibuf->setUsage(Qt3DRender::QBuffer::StreamDraw);
e->ibuf = new core::QBuffer;
e->ibuf->setUsage(core::QBuffer::StreamDraw);
}
// same here
e->ibuf->setData(QByteArray((const char *) cmdList->IdxBuffer.Data, cmdList->IdxBuffer.Size * sizeof(ImDrawIdx)));
Expand Down
16 changes: 14 additions & 2 deletions src/imgui-qt3d/imguimanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,27 @@
#include <functional>
#include <QSize>
#include <QEntity>
#include <QtGlobal>

class ImguiInputEventFilter;

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
namespace core = Qt3DRender;
#else
namespace core = Qt3DCore;
#endif

namespace Qt3DCore {
class QTransform;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
class QBuffer;
#endif
}

namespace Qt3DRender {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
class QBuffer;
#endif
class QTexture2D;
class QMaterial;
class QLayer;
Expand Down Expand Up @@ -150,8 +162,8 @@ class ImguiManager {
};

struct CmdListEntry {
Qt3DRender::QBuffer *vbuf = nullptr;
Qt3DRender::QBuffer *ibuf = nullptr;
core::QBuffer *vbuf = nullptr;
core::QBuffer *ibuf = nullptr;
QVector<CmdEntry> cmds;
int activeSize = 0;
};
Expand Down