summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanne Kangas <janne.kangas@qt.io>2020-02-07 11:32:25 +0200
committerJanne Kangas <janne.kangas@qt.io>2020-02-11 14:40:05 +0200
commit7ee97f3489bb1cba4095e58d4aa5241de772dc7b (patch)
tree6bacb9a0ae6aa385fd69d7915f1174e82188a13b
parent2dff84fddcffde95e882faceb45d5797dc5c63b9 (diff)
Add size and format to textureid query
Returns texture size and format for layer and material textures. Add corresponding test. Task-id: QT3DS-4005 Change-Id: I773715712dc78cf511f6c4d0095f5491834df311 Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/api/studio3d/q3dspresentation.cpp19
-rw-r--r--src/api/studio3d/q3dspresentation.h2
-rw-r--r--src/engine/Qt3DSRuntimeView.cpp17
-rw-r--r--src/engine/Qt3DSRuntimeView.h1
-rw-r--r--src/runtime/Qt3DSIScriptBridge.h3
-rw-r--r--src/runtime/Qt3DSQmlEngine.cpp34
-rw-r--r--src/runtimerender/Qt3DSRenderer.h5
-rw-r--r--src/runtimerender/rendererimpl/Qt3DSRendererImpl.cpp34
-rw-r--r--src/runtimerender/rendererimpl/Qt3DSRendererImpl.h5
-rw-r--r--src/viewer/Qt3DSViewerApp.cpp10
-rw-r--r--src/viewer/Qt3DSViewerApp.h2
-rw-r--r--tests/auto/studio3d/q3dssurfaceviewer/tst_q3dssurfaceviewer.cpp60
-rw-r--r--tests/auto/studio3d/shared/maps/OpenfootageNET_garage-512.hdrbin0 -> 422659 bytes
-rw-r--r--tests/auto/studio3d/shared/shared_presentations.qrc1
14 files changed, 192 insertions, 1 deletions
diff --git a/src/api/studio3d/q3dspresentation.cpp b/src/api/studio3d/q3dspresentation.cpp
index 0270e42..e6cc423 100644
--- a/src/api/studio3d/q3dspresentation.cpp
+++ b/src/api/studio3d/q3dspresentation.cpp
@@ -1025,6 +1025,25 @@ uint Q3DSPresentation::textureId(const QString &elementPath)
}
/*!
+ \since Qt 3D Studio 2.7
+ Returns the OpenGL texture id associated with a layer or an image specified
+ by \a elementPath. Texture \a size and \a format are returned in corresponding parameters.
+
+ For example, \c{Scene.Layer} returns the texture id of a layer while
+ \c{Scene.Layer.Rectangle.Material.diffusemap} returns the texture id of
+ an image or a subpresentation.
+ */
+uint Q3DSPresentation::textureId(const QString &elementPath, QSize &size, GLenum &format)
+{
+ if (d_ptr->m_viewerApp)
+ return d_ptr->m_viewerApp->textureId(elementPath, size, format);
+
+ size = {};
+ format = GL_INVALID_ENUM;
+ return 0;
+}
+
+/*!
Activate or deactivate the presentation identified by \a id depending
on the value of \a active.
*/
diff --git a/src/api/studio3d/q3dspresentation.h b/src/api/studio3d/q3dspresentation.h
index 1e8dedf..44bcad5 100644
--- a/src/api/studio3d/q3dspresentation.h
+++ b/src/api/studio3d/q3dspresentation.h
@@ -38,6 +38,7 @@
#include <QtCore/qstringlist.h>
#include <QtStudio3D/q3dsdatainput.h>
#include <QtStudio3D/q3dsdataoutput.h>
+#include <QtGui/qopengl.h>
QT_BEGIN_NAMESPACE
@@ -130,6 +131,7 @@ public:
void addImageProvider(const QString &providerId, QQmlImageProviderBase *provider);
uint textureId(const QString &elementPath);
+ uint textureId(const QString &elementPath, QSize &size, GLenum &format);
public Q_SLOTS:
void setSource(const QUrl &source);
diff --git a/src/engine/Qt3DSRuntimeView.cpp b/src/engine/Qt3DSRuntimeView.cpp
index 7cebdd6..c3dc8e1 100644
--- a/src/engine/Qt3DSRuntimeView.cpp
+++ b/src/engine/Qt3DSRuntimeView.cpp
@@ -53,6 +53,8 @@
#include "foundation/Qt3DSSimpleTypes.h"
#include "foundation/TrackingAllocator.h"
#include "foundation/Qt3DSPerfTimer.h"
+#include <QtGui/qopengl.h>
+
// For perf log timestamp
#include <time.h>
#include "Qt3DSArray.h"
@@ -229,6 +231,7 @@ public:
void deleteMeshes(const QStringList &meshNames) override;
void addImageProvider(const QString &providerId, QQmlImageProviderBase *provider) override;
uint textureId(const QString &elementPath) override;
+ uint textureId(const QString &elementPath, QSize &size, GLenum &format) override;
void SetAttribute(const char *elementPath, const char *attributeName,
const char *value) override;
bool GetAttribute(const char *elementPath, const char *attributeName, void *value) override;
@@ -779,6 +782,20 @@ uint CRuntimeView::textureId(const QString &elementPath)
return 0;
}
+uint CRuntimeView::textureId(const QString &elementPath, QSize &size, GLenum &format)
+{
+ if (m_Application) {
+ Q3DStudio::CQmlEngine &theBridgeEngine
+ = static_cast<Q3DStudio::CQmlEngine &>(m_RuntimeFactoryCore->GetScriptEngineQml());
+ return theBridgeEngine.textureId(elementPath,
+ &m_RuntimeFactory->GetQt3DSRenderContext().GetRenderer(),
+ size, format);
+ }
+ size = {};
+ format = GL_INVALID_ENUM;
+ return 0;
+}
+
void CRuntimeView::SetAttribute(const char *elementPath, const char *attributeName,
const char *value)
{
diff --git a/src/engine/Qt3DSRuntimeView.h b/src/engine/Qt3DSRuntimeView.h
index e114633..822efdc 100644
--- a/src/engine/Qt3DSRuntimeView.h
+++ b/src/engine/Qt3DSRuntimeView.h
@@ -231,6 +231,7 @@ public:
virtual void deleteMeshes(const QStringList &meshNames) = 0;
virtual void addImageProvider(const QString &providerId, QQmlImageProviderBase *provider) = 0;
virtual uint textureId(const QString &elementPath) = 0;
+ virtual uint textureId(const QString &elementPath, QSize &size, GLenum &format) = 0;
virtual void SetAttribute(const char *elementPath, const char *attributeName,
const char *value) = 0;
virtual bool GetAttribute(const char *elementPath, const char *attributeName, void *value) = 0;
diff --git a/src/runtime/Qt3DSIScriptBridge.h b/src/runtime/Qt3DSIScriptBridge.h
index 246dc81..9eedfc5 100644
--- a/src/runtime/Qt3DSIScriptBridge.h
+++ b/src/runtime/Qt3DSIScriptBridge.h
@@ -38,6 +38,7 @@
#include <QtCore/qvariant.h>
#include <QtCore/qvector.h>
#include <QtCore/qstringlist.h>
+#include <QtGui/qopengl.h>
QT_BEGIN_NAMESPACE
class QQmlImageProviderBase;
@@ -189,6 +190,8 @@ public: // Elements
qt3ds::render::IBufferManager *bufferManager) = 0;
virtual uint textureId(const QString &elementPath,
qt3ds::render::IQt3DSRenderer *renderer) = 0;
+ virtual uint textureId(const QString &elementPath, qt3ds::render::IQt3DSRenderer *renderer,
+ QSize &size, GLenum &format) = 0;
public: // Components
virtual void GotoSlide(const char *component, const char *slideName,
diff --git a/src/runtime/Qt3DSQmlEngine.cpp b/src/runtime/Qt3DSQmlEngine.cpp
index 1cadb3d..6730e6e 100644
--- a/src/runtime/Qt3DSQmlEngine.cpp
+++ b/src/runtime/Qt3DSQmlEngine.cpp
@@ -452,6 +452,8 @@ public:
qt3ds::render::IBufferManager *bufferManager) override;
uint textureId(const QString &elementPath,
qt3ds::render::IQt3DSRenderer *renderer) override;
+ uint textureId(const QString &elementPath, qt3ds::render::IQt3DSRenderer *renderer, QSize &size,
+ GLenum &format) override;
void GotoSlide(const char *component, const char *slideName,
const SScriptEngineGotoSlideArgs &inArgs) override;
@@ -1862,6 +1864,38 @@ uint CQmlEngineImpl::textureId(const QString &elementPath,
return 0;
}
+uint CQmlEngineImpl::textureId(const QString &elementPath, qt3ds::render::IQt3DSRenderer *renderer,
+ QSize &size, GLenum &format)
+{
+ TElement *elem = getTarget(elementPath.toUtf8().constData());
+ if (elem) {
+ auto translator = static_cast<qt3ds::render::Qt3DSTranslator *>(elem->GetAssociation());
+ if (translator) {
+ qt3ds::render::GraphObjectTypes::Enum elemType = translator->GetUIPType();
+ if (elemType == qt3ds::render::GraphObjectTypes::Layer) {
+ auto layer = static_cast<qt3ds::render::SLayer *>(&translator->RenderObject());
+ auto texdetails = renderer->getLayerTextureDetails(*layer);
+ size = QSize(texdetails.m_Width, texdetails.m_Height);
+ // Assume that NVRenderTextureFormats enums match GL texture format enums
+ format = renderer->getTextureGlFormat(texdetails.m_Format);
+ return renderer->getLayerTextureId(*layer);
+ } else if (elemType == qt3ds::render::GraphObjectTypes::Image) {
+ auto image = static_cast<qt3ds::render::SImage *>(&translator->RenderObject());
+ if (image->m_TextureData.m_Texture) {
+ auto texdetails = image->m_TextureData.m_Texture->GetTextureDetails();
+ size = QSize(texdetails.m_Width, texdetails.m_Height);
+ format = renderer->getTextureGlFormat(texdetails.m_Format);
+ return static_cast<uint>(reinterpret_cast<size_t>(
+ image->m_TextureData.m_Texture->GetTextureObjectHandle()));
+ }
+ }
+ }
+ }
+ size = {};
+ format = GL_INVALID_ENUM;
+ return 0;
+}
+
void CQmlEngineImpl::GotoSlide(const char *component, const char *slideName,
const SScriptEngineGotoSlideArgs &inArgs)
{
diff --git a/src/runtimerender/Qt3DSRenderer.h b/src/runtimerender/Qt3DSRenderer.h
index 2e6e6aa..336baab 100644
--- a/src/runtimerender/Qt3DSRenderer.h
+++ b/src/runtimerender/Qt3DSRenderer.h
@@ -40,6 +40,7 @@
#include "Qt3DSRenderCamera.h"
#include "render/Qt3DSRenderBaseTypes.h"
#include "Qt3DSRenderRay.h"
+#include <QtGui/qopengl.h>
namespace qt3ds {
namespace render {
@@ -171,6 +172,10 @@ namespace render {
virtual uint getLayerTextureId(SLayer &layer) = 0;
+ virtual GLenum getTextureGlFormat(NVRenderTextureFormats::Enum internalFormat) = 0;
+
+ virtual STextureDetails getLayerTextureDetails(SLayer &layer) = 0;
+
// Roughly equivalent of gluPickMatrix, allows users to setup a perspective transform that
// will draw some sub component
// of the layer. Used in combination with an expected viewport of 0,0,width,height the
diff --git a/src/runtimerender/rendererimpl/Qt3DSRendererImpl.cpp b/src/runtimerender/rendererimpl/Qt3DSRendererImpl.cpp
index 104bd09..300980c 100644
--- a/src/runtimerender/rendererimpl/Qt3DSRendererImpl.cpp
+++ b/src/runtimerender/rendererimpl/Qt3DSRendererImpl.cpp
@@ -57,6 +57,7 @@
#include "Qt3DSRenderPath.h"
#include "Qt3DSRenderShaderCodeGeneratorV2.h"
#include "Qt3DSRenderDefaultMaterialShaderGenerator.h"
+#include "backends/gl/Qt3DSOpenGLUtil.h"
#include <stdlib.h>
#ifdef _WIN32
@@ -983,6 +984,39 @@ namespace render {
return 0;
}
+ GLenum Qt3DSRendererImpl::getTextureGlFormat(NVRenderTextureFormats::Enum internalFormat)
+ {
+ auto ctxType = m_Context->GetRenderContextType();
+ GLConversion conversion;
+ GLenum glInternalFormat, glformat, gltype;
+
+ if (NVRenderTextureFormats::isUncompressedTextureFormat(internalFormat)) {
+ conversion.fromUncompressedTextureFormatToGL(ctxType, internalFormat,
+ glformat, gltype, glInternalFormat);
+ return glInternalFormat;
+ } else if (NVRenderTextureFormats::isCompressedTextureFormat(internalFormat)) {
+ return conversion.fromCompressedTextureFormatToGL(internalFormat);
+ } else if (NVRenderTextureFormats::isDepthTextureFormat(internalFormat)) {
+ conversion.fromDepthTextureFormatToGL(ctxType, internalFormat, glformat,
+ gltype, glInternalFormat);
+ return glInternalFormat;
+ } else {
+ return GL_INVALID_ENUM;
+ }
+ }
+
+ STextureDetails Qt3DSRendererImpl::getLayerTextureDetails(SLayer &inLayer)
+ {
+ SLayerRenderData *theData = GetOrCreateLayerRenderDataForNode(inLayer);
+
+ if (theData->m_LayerCachedTexture)
+ return theData->m_LayerCachedTexture->GetTextureDetails();
+ if (theData->m_LayerTexture)
+ return theData->m_LayerTexture->GetTextureDetails();
+
+ return {};
+ }
+
Option<SLayerPickSetup> Qt3DSRendererImpl::GetLayerPickSetup(SLayer &inLayer,
const QT3DSVec2 &inMouseCoords,
const QSize &inPickDims)
diff --git a/src/runtimerender/rendererimpl/Qt3DSRendererImpl.h b/src/runtimerender/rendererimpl/Qt3DSRendererImpl.h
index 792d71e..99b0b51 100644
--- a/src/runtimerender/rendererimpl/Qt3DSRendererImpl.h
+++ b/src/runtimerender/rendererimpl/Qt3DSRendererImpl.h
@@ -388,6 +388,10 @@ namespace render {
uint getLayerTextureId(SLayer &layer) override;
+ STextureDetails getLayerTextureDetails(SLayer &inLayer) override;
+
+ GLenum getTextureGlFormat(NVRenderTextureFormats::Enum internalFormat) override;
+
Option<SLayerPickSetup> GetLayerPickSetup(SLayer &inLayer,
const QT3DSVec2 &inMouseCoords,
const QSize &inPickDims) override;
@@ -566,7 +570,6 @@ namespace render {
Option<QT3DSVec2> GetLayerMouseCoords(SLayer &inLayer, const QT3DSVec2 &inMouseCoords,
const QT3DSVec2 &inViewportDimensions,
bool forceImageIntersect = false) const override;
-
protected:
Option<QT3DSVec2> GetLayerMouseCoords(SLayerRenderData &inLayer, const QT3DSVec2 &inMouseCoords,
const QT3DSVec2 &inViewportDimensions,
diff --git a/src/viewer/Qt3DSViewerApp.cpp b/src/viewer/Qt3DSViewerApp.cpp
index ae671d0..5b3ba4a 100644
--- a/src/viewer/Qt3DSViewerApp.cpp
+++ b/src/viewer/Qt3DSViewerApp.cpp
@@ -1064,6 +1064,16 @@ uint Q3DSViewerApp::textureId(const QString &elementPath)
return m_Impl.m_view->textureId(elementPath);
}
+uint Q3DSViewerApp::textureId(const QString &elementPath, QSize &size, GLenum &format)
+{
+ if (!m_Impl.m_view) {
+ size = {};
+ format = GL_INVALID_ENUM;
+ return 0;
+ }
+ return m_Impl.m_view->textureId(elementPath, size, format);
+}
+
Q3DSViewerApp &Q3DSViewerApp::Create(void *glContext, Q3DStudio::IAudioPlayer *inAudioPlayer,
QElapsedTimer *startupTimer)
{
diff --git a/src/viewer/Qt3DSViewerApp.h b/src/viewer/Qt3DSViewerApp.h
index a23b5f9..0aa8ade 100644
--- a/src/viewer/Qt3DSViewerApp.h
+++ b/src/viewer/Qt3DSViewerApp.h
@@ -42,6 +42,7 @@
#include <QtCore/qvector.h>
#include <QtCore/qstringlist.h>
#include <QtGui/qsurfaceformat.h>
+#include <QtGui/qopengl.h>
QT_BEGIN_NAMESPACE
class QQmlImageProviderBase;
@@ -498,6 +499,7 @@ public:
void addImageProvider(const QString &providerId, QQmlImageProviderBase *provider);
uint textureId(const QString &elementPath);
+ uint textureId(const QString &elementPath, QSize &size, GLenum &format);
QString error();
diff --git a/tests/auto/studio3d/q3dssurfaceviewer/tst_q3dssurfaceviewer.cpp b/tests/auto/studio3d/q3dssurfaceviewer/tst_q3dssurfaceviewer.cpp
index a4b5aa2..7dcf254 100644
--- a/tests/auto/studio3d/q3dssurfaceviewer/tst_q3dssurfaceviewer.cpp
+++ b/tests/auto/studio3d/q3dssurfaceviewer/tst_q3dssurfaceviewer.cpp
@@ -85,6 +85,8 @@ private slots:
void testMouseInput();
void testDataInput_data();
void testDataInput();
+ void testTextureQuery();
+ void testTextureQuery_data();
private:
QWindow *createWindow(const QSize &size);
@@ -1507,6 +1509,64 @@ void tst_Q3DSSurfaceViewer::testDataInput()
delete slideInput;
}
+void tst_Q3DSSurfaceViewer::testTextureQuery_data()
+{
+ testBasics_data();
+}
+
+void tst_Q3DSSurfaceViewer::testTextureQuery()
+{
+ QFETCH(bool, isWindow);
+
+ if (isWindow)
+ createWindowAndViewer(m_viewer, DATAINPUT);
+ else
+ createOffscreenAndViewer(m_viewer, DATAINPUT);
+
+ m_viewer->settings()->setScaleMode(Q3DSViewerSettings::ScaleModeFill);
+
+ QGuiApplication::processEvents();
+ // Test texture info getters, first for layer then for individual material.
+ // Texture id's are likely to change if test ordering changes.
+ QSize texsize;
+ GLenum format;
+
+ uint textureid = m_viewer->presentation()->textureId("Scene.Layer", texsize, format);
+ if (isWindow)
+ QCOMPARE(textureid, 6);
+ else
+ QCOMPARE(textureid, 7);
+
+ QCOMPARE(texsize, QSize(300,200));
+ QCOMPARE(format, GL_RGBA8);
+
+ textureid = m_viewer->presentation()->textureId("Scene.Layer.Rectangle.Default.diffusemap",
+ texsize, format);
+ if (isWindow)
+ QCOMPARE(textureid, 1);
+ else
+ QCOMPARE(textureid, 2);
+ QCOMPARE(texsize, QSize(400,200));
+ QCOMPARE(format, GL_RGBA8);
+
+ m_viewer->presentation()->setAttribute("Scene.Layer.Rectangle.Default.diffusemap",
+ "subpresentation", "");
+ m_viewer->presentation()->setAttribute("Scene.Layer.Rectangle.Default.diffusemap", "sourcepath",
+ "maps/OpenfootageNET_garage-512.hdr");
+
+ QGuiApplication::processEvents();
+
+ // Changed to HDR texture, studio-internally RGB8E but texture query should map to GL RGBA8
+ textureid = m_viewer->presentation()->textureId("Scene.Layer.Rectangle.Default.diffusemap",
+ texsize, format);
+ if (isWindow)
+ QCOMPARE(textureid, 8);
+ else
+ QCOMPARE(textureid, 9);
+
+ QCOMPARE(texsize, QSize(512,256));
+ QCOMPARE(format, GL_RGBA8);
+}
QTEST_MAIN(tst_Q3DSSurfaceViewer)
diff --git a/tests/auto/studio3d/shared/maps/OpenfootageNET_garage-512.hdr b/tests/auto/studio3d/shared/maps/OpenfootageNET_garage-512.hdr
new file mode 100644
index 0000000..015b478
--- /dev/null
+++ b/tests/auto/studio3d/shared/maps/OpenfootageNET_garage-512.hdr
Binary files differ
diff --git a/tests/auto/studio3d/shared/shared_presentations.qrc b/tests/auto/studio3d/shared/shared_presentations.qrc
index d4bb668..25dd40e 100644
--- a/tests/auto/studio3d/shared/shared_presentations.qrc
+++ b/tests/auto/studio3d/shared/shared_presentations.qrc
@@ -11,5 +11,6 @@
<file alias="datainput.uip">presentation/datainput.uip</file>
<file alias="datainput.uia">presentation/datainput.uia</file>
<file alias="datainput_sub.uip">presentation/datainput_sub.uip</file>
+ <file>maps/OpenfootageNET_garage-512.hdr</file>
</qresource>
</RCC>