From 967e64dc0a03570f892b2d7cab4c34004ea65149 Mon Sep 17 00:00:00 2001 From: Ramses Tech User <94632088+ramses-tech-user@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:52:03 +0100 Subject: [PATCH] Oss release 28.0.0-rc4 created 2023-11-28-12-52 see CHANGELOG.md for details Original commit sha: f1a8606a9ede8e9e17ab67e85eb9edb5b2bf80bb Co-authored-by: Askanaz Torosyan <46795157+nVxx@users.noreply.github.com> Co-authored-by: Daniel Haas <25718295+bojackHaasman@users.noreply.github.com> Co-authored-by: Mirko Sova <64351017+smirko-dev@users.noreply.github.com> Co-authored-by: Violin Yanev Co-authored-by: Carsten Rohn <710234+delyas@users.noreply.github.com> Co-authored-by: Tobias Hammer Co-authored-by: Bernhard Kisslinger <65217745+bkisslinger@users.noreply.github.com> Co-authored-by: Martin Veith <3490591+veithm@users.noreply.github.com> Co-authored-by: Jonathan Conrad <833168+jcsneaker@users.noreply.github.com> Co-authored-by: Mohamed Sharaf-El-Deen <769940+mohhsharaf@users.noreply.github.com> Co-authored-by: Markus Keppler <92277233+markuskeppler@users.noreply.github.com> Co-authored-by: Chan Tong Yan <4199832+imyumichan@users.noreply.github.com> --- CHANGELOG.md | 8 + CMakeLists.txt | 2 +- .../examples/logic/16_renderbufferbinding.rst | 19 ++ doc/sphinx/logic.rst | 1 + .../logic/16_renderbufferbinding/main.cpp | 248 ++++++++++++++++++ examples/logic/CMakeLists.txt | 1 + examples/logic/shared/SimpleRenderer.h | 2 +- include/ramses/client/ArrayBuffer.h | 16 +- include/ramses/client/ArrayResource.h | 2 +- include/ramses/client/Scene.h | 8 +- src/client/impl/ArrayBuffer.cpp | 36 +-- src/client/impl/ArrayBufferImpl.cpp | 30 +-- src/client/impl/ArrayBufferImpl.h | 14 +- src/client/impl/ArrayResource.cpp | 2 +- src/client/impl/ArrayResourceImpl.cpp | 6 +- src/client/impl/ArrayResourceImpl.h | 4 +- src/client/impl/GeometryImpl.cpp | 4 +- src/client/impl/RamsesClientImpl.cpp | 4 +- src/client/impl/RamsesClientImpl.h | 2 +- src/client/impl/Scene.cpp | 18 +- src/client/impl/SceneImpl.cpp | 18 +- src/client/impl/SceneImpl.h | 4 +- src/framework/impl/APILoggingMacros.h | 2 +- .../RendererLifecycleTests.cpp | 30 +++ .../res/ARenderTargetSizeChange_High.PNG | Bin 0 -> 221 bytes .../res/ARenderTargetSizeChange_Invalid.PNG | Bin 0 -> 138 bytes .../res/ARenderTargetSizeChange_Low.PNG | Bin 0 -> 153 bytes .../test-content/RenderTargetScene.cpp | 58 +++- .../TestScenes/RenderTargetScene.h | 13 +- .../viewer-tests/LogicViewerAppTest.cpp | 64 ++--- tests/unittests/client/SceneTest.cpp | 27 ++ tools/ramses-viewer/LogicEngineGui.h | 30 --- tools/ramses-viewer/LogicViewerGui.cpp | 103 ++------ tools/ramses-viewer/LogicViewerGui.h | 12 +- tools/ramses-viewer/SceneViewerGui.cpp | 145 +++++----- tools/ramses-viewer/SceneViewerGui.h | 11 +- tools/ramses-viewer/ViewerGui.cpp | 79 ++++-- tools/ramses-viewer/ViewerGui.h | 2 + tools/ramses-viewer/ViewerSettings.cpp | 6 +- tools/ramses-viewer/ViewerSettings.h | 12 +- 40 files changed, 687 insertions(+), 356 deletions(-) create mode 100644 doc/sphinx/examples/logic/16_renderbufferbinding.rst create mode 100644 examples/logic/16_renderbufferbinding/main.cpp create mode 100644 tests/integration/renderer-tests/res/ARenderTargetSizeChange_High.PNG create mode 100644 tests/integration/renderer-tests/res/ARenderTargetSizeChange_Invalid.PNG create mode 100644 tests/integration/renderer-tests/res/ARenderTargetSizeChange_Low.PNG diff --git a/CHANGELOG.md b/CHANGELOG.md index 3193c3c70..b464881e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Ramses Changelog +28.0.0-rc4 +------------------- +### Changed +- `ArrayResource` and `ArrayBuffer` use `size_t` instead of `uint32_t` for number of elements for consistency with other API and STL + +### Fixed +- Fixed abort() with trace logs enabled and API calls containing strings with format string characters ("{}") + 28.0.0-rc3 ------------------- ### Added diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ee997eee..417d670c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.13) set(RAMSES_VERSION_MAJOR 28) set(RAMSES_VERSION_MINOR 0) set(RAMSES_VERSION_PATCH 0) -set(RAMSES_VERSION_POSTFIX "-rc3") +set(RAMSES_VERSION_POSTFIX "-rc4") set(RAMSES_VERSION "${RAMSES_VERSION_MAJOR}.${RAMSES_VERSION_MINOR}.${RAMSES_VERSION_PATCH}${RAMSES_VERSION_POSTFIX}") project(ramses-sdk diff --git a/doc/sphinx/examples/logic/16_renderbufferbinding.rst b/doc/sphinx/examples/logic/16_renderbufferbinding.rst new file mode 100644 index 000000000..99437a1cf --- /dev/null +++ b/doc/sphinx/examples/logic/16_renderbufferbinding.rst @@ -0,0 +1,19 @@ +.. + ------------------------------------------------------------------------- + Copyright (C) 2023 BMW AG + ------------------------------------------------------------------------- + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at https://mozilla.org/MPL/2.0/. + ------------------------------------------------------------------------- + +.. default-domain:: cpp +.. highlight:: cpp + +================================ +RenderBufferBinding example +================================ + +.. literalinclude:: ../../../../examples/logic/16_renderbufferbinding/main.cpp + :start-after: #include + :end-before: return 0; diff --git a/doc/sphinx/logic.rst b/doc/sphinx/logic.rst index fecda4092..c63525a94 100644 --- a/doc/sphinx/logic.rst +++ b/doc/sphinx/logic.rst @@ -570,3 +570,4 @@ List of all logic examples examples/logic/13_render_order examples/logic/14_skinbinding examples/logic/15_meshnodebinding + examples/logic/16_renderbufferbinding diff --git a/examples/logic/16_renderbufferbinding/main.cpp b/examples/logic/16_renderbufferbinding/main.cpp new file mode 100644 index 000000000..b4fd9bdd6 --- /dev/null +++ b/examples/logic/16_renderbufferbinding/main.cpp @@ -0,0 +1,248 @@ +// ------------------------------------------------------------------------- +// Copyright (C) 2023 BMW AG +// ------------------------------------------------------------------------- +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +// ------------------------------------------------------------------------- + +#include "ramses/client/logic/LogicEngine.h" +#include "ramses/client/logic/CameraBinding.h" +#include "ramses/client/logic/RenderBufferBinding.h" +#include "ramses/client/logic/LuaInterface.h" +#include "ramses/client/logic/Property.h" + +#include "ramses/client/ramses-client.h" +#include "ramses/client/ramses-utils.h" + +#include "SimpleRenderer.h" + +#include +#include +#include +#include + +/** +* This example demonstrates how to change resolution of a render target/buffer using logic, +after the render buffer scene object was already created in a scene but was not created by the renderer yet. +* This can be useful if an asset is created and exported with a certain initial resolution but there is a need to adjust it +* in runtime upon loading to match platform display resolution or a certain level of detail. +*/ + +/// Helper method which creates a simple ramses scene with render target. +ramses::Scene* CreateSceneWithRenderTarget(ramses::RamsesClient& client); + +int main() +{ + /// Use simple class to create ramses framework objects which are not essential for this example. + SimpleRenderer renderer; + + /// Create a simple Ramses scene with a render target which gets a triangle rendered into and then its contents are displayed on a quad as texture. + auto scene = CreateSceneWithRenderTarget(*renderer.getClient()); + + ramses::LogicEngine& logicEngine{ *scene->createLogicEngine() }; + logicEngine.setStatisticsLoggingRate(0u); + + /// Create interface for logic which will control the resolution of the render target and viewport in scene created above + ramses::LuaInterface* logicInterface = logicEngine.createLuaInterface(R"( + function interface(IN) + IN.resolution = Type:Int32() + end + )", "logicInterface"); + + /** + * Now we create CameraBinding and RenderBufferBinding which will be used to link the appropriate properties for the resolution change + * to be correctly applied. + * In order to change the resolution of our render target in our scene, we need to link the render buffer width and height and also + * viewport witdth and height of the camera used for the render pass rendering into the render target. + */ + ramses::CameraBinding* cameraBinding = logicEngine.createCameraBinding(*scene->findObject("renderTargetCamera"), "cameraBinding"); + logicEngine.link( + *logicInterface->getOutputs()->getChild("resolution"), + *cameraBinding->getInputs()->getChild("viewport")->getChild("width")); + logicEngine.link( + *logicInterface->getOutputs()->getChild("resolution"), + *cameraBinding->getInputs()->getChild("viewport")->getChild("height")); + + ramses::RenderBufferBinding* renderBufferBinding = logicEngine.createRenderBufferBinding(*scene->findObject("renderBuffer"), "renderBufferBinding"); + logicEngine.link( + *logicInterface->getOutputs()->getChild("resolution"), + *renderBufferBinding->getInputs()->getChild("width")); + logicEngine.link( + *logicInterface->getOutputs()->getChild("resolution"), + *renderBufferBinding->getInputs()->getChild("height")); + /** + * Note that we do not link all the RenderBufferBinding input properties ('sampleCount' is not used here), + * meaning it will stay untouched and use the initial value given when RenderBuffer was created. + */ + + /** + * Changing resolution of a render buffer via RenderBufferBinding has a very important limitation, it can only be done BEFORE the scene + * is rendered (before it reaches RendererSceneState::Ready state to be precise), any attempt to change resolution later will have no effect + * (only an error will be logged). + */ + /// The actual change of resolution in our scene is then as simple as calling a setter on the logic interface we created + logicInterface->getInputs()->getChild("resolution")->set(256); + + /// Show the scene on the renderer. + renderer.showScene(scene->getSceneId()); + + /// Simulate an application loop. + while (!renderer.isWindowClosed()) + { + /// Update the LogicEngine. This will apply changes to Ramses scene from any running script. + logicEngine.update(); + + /// In order to commit the changes to Ramses scene we need to "flush" them. + scene->flush(); + + /// Process window events, check if window was closed + renderer.processEvents(); + + /// Throttle the simulation loop by sleeping for a bit. + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + + return 0; +} + +ramses::Scene* CreateSceneWithRenderTarget(ramses::RamsesClient& client) +{ + /// Initial resolution is intentionally very low so it is clearly visible when the change later on in example is applied + constexpr uint32_t InitialRenderTargetRes = 8u; + + ramses::Scene* scene = client.createScene(ramses::sceneId_t{ 123u }, "scene"); + ramses::RenderBuffer* renderBuffer = scene->createRenderBuffer( + InitialRenderTargetRes, InitialRenderTargetRes, ramses::ERenderBufferFormat::RGBA8, ramses::ERenderBufferAccessMode::ReadWrite, 0u, "renderBuffer"); + + /// There are other examples which describe all the steps below in detail, therefore documentation here is reduced. + + /// Render pass rendering a triangle into a render target + { + const std::string_view vertSrc = R"(#version 100 + uniform highp mat4 mvpMatrix; + attribute vec3 a_position; + void main() + { + gl_Position = mvpMatrix * vec4(a_position, 1.0); + })"; + const std::string_view fragSrc = R"(#version 100 + void main(void) + { + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); + })"; + + ramses::EffectDescription effectDesc; + effectDesc.setVertexShader(vertSrc); + effectDesc.setFragmentShader(fragSrc); + effectDesc.setUniformSemantic("mvpMatrix", ramses::EEffectUniformSemantic::ModelViewProjectionMatrix); + + auto effect = scene->createEffect(effectDesc); + auto appearance = scene->createAppearance(*effect); + auto geometry = scene->createGeometry(*effect); + const std::array indicesData = { 0, 1, 2 }; + geometry->setIndices(*scene->createArrayResource(3u, indicesData.data())); + const std::array vertexPositionsData{ ramses::vec3f{-1.f, 0.f, -1.f}, ramses::vec3f{1.f, 0.f, -1.f}, ramses::vec3f{0.f, 1.f, -1.f} }; + const auto vertexPositions = scene->createArrayResource(3u, vertexPositionsData.data()); + geometry->setInputBuffer(*effect->findAttributeInput("a_position"), *vertexPositions); + + auto meshNode = scene->createMeshNode(); + meshNode->setAppearance(*appearance); + meshNode->setGeometry(*geometry); + + auto translateNode = scene->createNode(); + translateNode->addChild(*meshNode); + translateNode->translate({ 0.0f, -0.5f, -5.0f }); + + auto renderPass = scene->createRenderPass(); + auto renderGroup = scene->createRenderGroup(); + renderPass->addRenderGroup(*renderGroup); + renderGroup->addMeshNode(*meshNode); + + auto camera = scene->createOrthographicCamera("renderTargetCamera"); + camera->setFrustum(-1.f, 1.f, -1.f, 1.f, 1.f, 10.f); + camera->setViewport(0, 0, InitialRenderTargetRes, InitialRenderTargetRes); + + renderPass->setCamera(*camera); + + ramses::RenderTargetDescription rtDesc; + rtDesc.addRenderBuffer(*renderBuffer); + ramses::RenderTarget* renderTarget = scene->createRenderTarget(rtDesc); + renderPass->setRenderTarget(renderTarget); + renderPass->setClearColor({ 0.f, 0.f, 1.f, 0.5f }); + renderPass->setClearFlags(ramses::EClearFlag::All); + } + + /// Main render pass which renders contents of the render target created above as a texture on a quad + { + const std::string_view vertSrc = R"(#version 100 + uniform highp mat4 mvpMatrix; + attribute vec3 a_position; + attribute vec2 a_texcoord; + varying vec2 v_texcoord; + void main() + { + gl_Position = mvpMatrix * vec4(a_position, 1.0); + v_texcoord = a_texcoord; + })"; + const std::string_view fragSrc = R"(#version 100 + precision highp float; + uniform sampler2D u_texture; + varying lowp vec2 v_texcoord; + void main(void) + { + vec4 color = texture2D(u_texture, v_texcoord); + gl_FragColor = color; + })"; + + ramses::EffectDescription effectDesc; + effectDesc.setVertexShader(vertSrc); + effectDesc.setFragmentShader(fragSrc); + effectDesc.setUniformSemantic("mvpMatrix", ramses::EEffectUniformSemantic::ModelViewProjectionMatrix); + auto effect = scene->createEffect(effectDesc); + + const std::array indicesArray{ 0, 1, 2, 2, 1, 3 }; + const auto indices = scene->createArrayResource(6u, indicesArray.data()); + const std::array vertexPositionsArray{ + ramses::vec3f{ -0.5f, -0.5f, 0.f }, + ramses::vec3f{ 0.5f, -0.5f, 0.f }, + ramses::vec3f{ -0.5f, 0.5f, 0.f }, + ramses::vec3f{ 0.5f, 0.5f, 0.f } }; + const auto vertexPositions = scene->createArrayResource(4u, vertexPositionsArray.data()); + const std::array textureCoordsArray{ ramses::vec2f{0.f, 0.f}, ramses::vec2f{2.f, 0.f}, ramses::vec2f{0.f, 2.f}, ramses::vec2f{2.f, 2.f} }; + const auto textureCoords = scene->createArrayResource(4u, textureCoordsArray.data()); + + auto appearance = scene->createAppearance(*effect); + auto geometry = scene->createGeometry(*effect); + geometry->setIndices(*indices); + geometry->setInputBuffer(*effect->findAttributeInput("a_position"), *vertexPositions); + geometry->setInputBuffer(*effect->findAttributeInput("a_texcoord"), *textureCoords); + + auto sampler = scene->createTextureSampler( + ramses::ETextureAddressMode::Repeat, + ramses::ETextureAddressMode::Repeat, + ramses::ETextureSamplingMethod::Linear, + ramses::ETextureSamplingMethod::Linear, + *renderBuffer); + appearance->setInputTexture(*effect->findUniformInput("u_texture"), *sampler); + + auto meshNode = scene->createMeshNode("quad"); + meshNode->setAppearance(*appearance); + meshNode->setGeometry(*geometry); + meshNode->setTranslation({ 0.f, 0.f, -4.f }); + + auto camera = scene->createPerspectiveCamera(); + camera->setViewport(0, 0, SimpleRenderer::GetDisplaySize()[0], SimpleRenderer::GetDisplaySize()[1]); + camera->setFrustum(19.0f, float(SimpleRenderer::GetDisplaySize()[0]) / float(SimpleRenderer::GetDisplaySize()[1]), 0.1f, 100.0f); + auto renderPass = scene->createRenderPass(); + renderPass->setCamera(*camera); + auto renderGroup = scene->createRenderGroup(); + renderPass->addRenderGroup(*renderGroup); + renderGroup->addMeshNode(*meshNode); + } + + scene->flush(); + scene->publish(); + + return scene; +} diff --git a/examples/logic/CMakeLists.txt b/examples/logic/CMakeLists.txt index d12b775b6..85a9bdac6 100644 --- a/examples/logic/CMakeLists.txt +++ b/examples/logic/CMakeLists.txt @@ -60,4 +60,5 @@ if(ramses-sdk_BUILD_FULL_SHARED_LIB) add_example(NAME 12_anchor_point FILES 12_anchor_point/main.cpp LOCAL_EXAMPLE) add_example(NAME 13_render_order FILES 13_render_order/main.cpp LOCAL_EXAMPLE) add_example(NAME 15_meshnodebinding FILES 15_meshnodebinding/main.cpp LOCAL_EXAMPLE) + add_example(NAME 16_renderbufferbinding FILES 16_renderbufferbinding/main.cpp LOCAL_EXAMPLE) endif() diff --git a/examples/logic/shared/SimpleRenderer.h b/examples/logic/shared/SimpleRenderer.h index c67344fac..23a74bd5d 100644 --- a/examples/logic/shared/SimpleRenderer.h +++ b/examples/logic/shared/SimpleRenderer.h @@ -27,7 +27,7 @@ class SimpleRenderer : public ramses::RendererEventHandlerEmpty { ramses::RamsesFrameworkConfig frameworkConfig{ramses::EFeatureLevel_Latest}; frameworkConfig.setPeriodicLogInterval(std::chrono::seconds(0)); - frameworkConfig.setLogLevel(ramses::ELogLevel::Off); + frameworkConfig.setLogLevel(ramses::ELogLevel::Info); m_framework = std::make_unique(frameworkConfig); m_ramsesClient = m_framework->createClient("example client"); diff --git a/include/ramses/client/ArrayBuffer.h b/include/ramses/client/ArrayBuffer.h index 0449d0d5f..12cf65b73 100644 --- a/include/ramses/client/ArrayBuffer.h +++ b/include/ramses/client/ArrayBuffer.h @@ -52,7 +52,7 @@ namespace ramses * @return true for success, false otherwise (check log or #ramses::RamsesFramework::getLastError for details). */ template - bool updateData(uint32_t firstElement, uint32_t numElements, const T* bufferData); + bool updateData(size_t firstElement, size_t numElements, const T* bufferData); /** * @brief Returns the maximum number of data elements that can be stored in the data buffer. @@ -62,7 +62,7 @@ namespace ramses * * @return Maximum number of elements */ - [[nodiscard]] uint32_t getMaximumNumberOfElements() const; + [[nodiscard]] size_t getMaximumNumberOfElements() const; /** * @brief Returns the used number of data elements. @@ -73,7 +73,7 @@ namespace ramses * * @return Used size in number of elements */ - [[nodiscard]] uint32_t getUsedNumberOfElements() const; + [[nodiscard]] size_t getUsedNumberOfElements() const; /** * @brief Returns the data type associated with the buffer data @@ -95,7 +95,7 @@ namespace ramses * @return true for success, false otherwise (check log or #ramses::RamsesFramework::getLastError for details). */ template - bool getData(T* buffer, uint32_t numElements) const; + bool getData(T* buffer, size_t numElements) const; /** * Get the internal data for implementation specifics of ArrayBuffer. @@ -127,18 +127,18 @@ namespace ramses private: /// Internal implementation of #updateData - template bool updateDataInternal(uint32_t firstElement, uint32_t numElements, const T* bufferData); + template bool updateDataInternal(size_t firstElement, size_t numElements, const T* bufferData); /// Internal implementation of #getData - template bool getDataInternal(T* buffer, uint32_t numElements) const; + template bool getDataInternal(T* buffer, size_t numElements) const; }; - template bool ArrayBuffer::updateData(uint32_t firstElement, uint32_t numElements, const T* bufferData) + template bool ArrayBuffer::updateData(size_t firstElement, size_t numElements, const T* bufferData) { static_assert(IsArrayResourceDataType(), "Unsupported data type!"); return updateDataInternal(firstElement, numElements, bufferData); } - template bool ArrayBuffer::getData(T* buffer, uint32_t numElements) const + template bool ArrayBuffer::getData(T* buffer, size_t numElements) const { static_assert(IsArrayResourceDataType(), "Unsupported data type!"); return getDataInternal(buffer, numElements); diff --git a/include/ramses/client/ArrayResource.h b/include/ramses/client/ArrayResource.h index f75d6f85d..70f2fc79e 100644 --- a/include/ramses/client/ArrayResource.h +++ b/include/ramses/client/ArrayResource.h @@ -33,7 +33,7 @@ namespace ramses /** * @brief Returns number of elements of the array. */ - [[nodiscard]] uint32_t getNumberOfElements() const; + [[nodiscard]] size_t getNumberOfElements() const; /** * @brief Returns the data type of the data array. diff --git a/include/ramses/client/Scene.h b/include/ramses/client/Scene.h index d92075b1b..9a123c908 100644 --- a/include/ramses/client/Scene.h +++ b/include/ramses/client/Scene.h @@ -537,7 +537,7 @@ namespace ramses */ template ArrayResource* createArrayResource( - uint32_t numElements, + size_t numElements, const T* arrayData, std::string_view name = {}); @@ -651,7 +651,7 @@ namespace ramses * @param[in] name The optional name of the created array buffer. * @return A pointer to the created array buffer. */ - ArrayBuffer* createArrayBuffer(EDataType dataType, uint32_t maxNumElements, std::string_view name = {}); + ArrayBuffer* createArrayBuffer(EDataType dataType, size_t maxNumElements, std::string_view name = {}); /** * @brief Create a new Texture2DBuffer. The created object is a mutable buffer object that can be used @@ -889,7 +889,7 @@ namespace ramses private: /// Internal implementation of #createArrayResource - template ArrayResource* createArrayResourceInternal(uint32_t numElements, const T* arrayData, std::string_view name); + template ArrayResource* createArrayResourceInternal(size_t numElements, const T* arrayData, std::string_view name); template [[nodiscard]] const T* findObjectByNameInternal(std::string_view name) const; template [[nodiscard]] T* findObjectByNameInternal(std::string_view name); @@ -901,7 +901,7 @@ namespace ramses static void StaticTypeCheck(); }; - template ArrayResource* Scene::createArrayResource(uint32_t numElements, const T* arrayData, std::string_view name) + template ArrayResource* Scene::createArrayResource(size_t numElements, const T* arrayData, std::string_view name) { static_assert(IsArrayResourceDataType(), "Unsupported data type!"); return createArrayResourceInternal(numElements, arrayData, name); diff --git a/src/client/impl/ArrayBuffer.cpp b/src/client/impl/ArrayBuffer.cpp index b8f9d91dc..4dfbdbeb0 100644 --- a/src/client/impl/ArrayBuffer.cpp +++ b/src/client/impl/ArrayBuffer.cpp @@ -21,7 +21,7 @@ namespace ramses { } - template bool ArrayBuffer::updateDataInternal(uint32_t firstElement, uint32_t numElements, const T* bufferData) + template bool ArrayBuffer::updateDataInternal(size_t firstElement, size_t numElements, const T* bufferData) { if (GetEDataType() != m_impl.getDataType()) { @@ -35,12 +35,12 @@ namespace ramses return status; } - uint32_t ArrayBuffer::getMaximumNumberOfElements() const + size_t ArrayBuffer::getMaximumNumberOfElements() const { return m_impl.getMaximumNumberOfElements(); } - uint32_t ArrayBuffer::getUsedNumberOfElements() const + size_t ArrayBuffer::getUsedNumberOfElements() const { return m_impl.getUsedNumberOfElements(); } @@ -50,7 +50,7 @@ namespace ramses return m_impl.getDataType(); } - template bool ArrayBuffer::getDataInternal(T* buffer, uint32_t numElements) const + template bool ArrayBuffer::getDataInternal(T* buffer, size_t numElements) const { if (GetEDataType() != m_impl.getDataType()) { @@ -72,19 +72,19 @@ namespace ramses return m_impl; } - template RAMSES_API bool ArrayBuffer::updateDataInternal(uint32_t, uint32_t, const uint16_t*); - template RAMSES_API bool ArrayBuffer::updateDataInternal(uint32_t, uint32_t, const uint32_t*); - template RAMSES_API bool ArrayBuffer::updateDataInternal(uint32_t, uint32_t, const float*); - template RAMSES_API bool ArrayBuffer::updateDataInternal(uint32_t, uint32_t, const vec2f*); - template RAMSES_API bool ArrayBuffer::updateDataInternal(uint32_t, uint32_t, const vec3f*); - template RAMSES_API bool ArrayBuffer::updateDataInternal(uint32_t, uint32_t, const vec4f*); - template RAMSES_API bool ArrayBuffer::updateDataInternal(uint32_t, uint32_t, const std::byte*); + template RAMSES_API bool ArrayBuffer::updateDataInternal(size_t, size_t, const uint16_t*); + template RAMSES_API bool ArrayBuffer::updateDataInternal(size_t, size_t, const uint32_t*); + template RAMSES_API bool ArrayBuffer::updateDataInternal(size_t, size_t, const float*); + template RAMSES_API bool ArrayBuffer::updateDataInternal(size_t, size_t, const vec2f*); + template RAMSES_API bool ArrayBuffer::updateDataInternal(size_t, size_t, const vec3f*); + template RAMSES_API bool ArrayBuffer::updateDataInternal(size_t, size_t, const vec4f*); + template RAMSES_API bool ArrayBuffer::updateDataInternal(size_t, size_t, const std::byte*); - template RAMSES_API bool ArrayBuffer::getDataInternal(uint16_t*, uint32_t) const; - template RAMSES_API bool ArrayBuffer::getDataInternal(uint32_t*, uint32_t) const; - template RAMSES_API bool ArrayBuffer::getDataInternal(float*, uint32_t) const; - template RAMSES_API bool ArrayBuffer::getDataInternal(vec2f*, uint32_t) const; - template RAMSES_API bool ArrayBuffer::getDataInternal(vec3f*, uint32_t) const; - template RAMSES_API bool ArrayBuffer::getDataInternal(vec4f*, uint32_t) const; - template RAMSES_API bool ArrayBuffer::getDataInternal(std::byte*, uint32_t) const; + template RAMSES_API bool ArrayBuffer::getDataInternal(uint16_t*, size_t) const; + template RAMSES_API bool ArrayBuffer::getDataInternal(uint32_t*, size_t) const; + template RAMSES_API bool ArrayBuffer::getDataInternal(float*, size_t) const; + template RAMSES_API bool ArrayBuffer::getDataInternal(vec2f*, size_t) const; + template RAMSES_API bool ArrayBuffer::getDataInternal(vec3f*, size_t) const; + template RAMSES_API bool ArrayBuffer::getDataInternal(vec4f*, size_t) const; + template RAMSES_API bool ArrayBuffer::getDataInternal(std::byte*, size_t) const; } diff --git a/src/client/impl/ArrayBufferImpl.cpp b/src/client/impl/ArrayBufferImpl.cpp index a36ad07a9..8aa1afe7c 100644 --- a/src/client/impl/ArrayBufferImpl.cpp +++ b/src/client/impl/ArrayBufferImpl.cpp @@ -22,12 +22,12 @@ namespace ramses::internal ArrayBufferImpl::~ArrayBufferImpl() = default; - void ArrayBufferImpl::initializeFrameworkData(ramses::EDataType dataType, uint32_t numElements) + void ArrayBufferImpl::initializeFrameworkData(ramses::EDataType dataType, size_t numElements) { assert(!m_dataBufferHandle.isValid()); const ramses::internal::EDataBufferType dataBufferType = DataTypeUtils::DeductBufferTypeFromDataType(dataType); const ramses::internal::EDataType dataTypeInternal = DataTypeUtils::ConvertDataTypeToInternal(dataType); - const uint32_t maximumSizeInBytes = EnumToSize(dataTypeInternal) * numElements; + const uint32_t maximumSizeInBytes = EnumToSize(dataTypeInternal) * static_cast(numElements); m_dataBufferHandle = getIScene().allocateDataBuffer(dataBufferType, dataTypeInternal, maximumSizeInBytes, {}); } @@ -44,16 +44,16 @@ namespace ramses::internal return m_dataBufferHandle; } - uint32_t ArrayBufferImpl::getElementCount() const + size_t ArrayBufferImpl::getElementCount() const { const GeometryDataBuffer& dataBuffer = getIScene().getDataBuffer(m_dataBufferHandle); - return static_cast(dataBuffer.data.size()) / EnumToSize(dataBuffer.dataType); + return dataBuffer.data.size() / EnumToSize(dataBuffer.dataType); } - uint32_t ArrayBufferImpl::getUsedElementCount() const + size_t ArrayBufferImpl::getUsedElementCount() const { const GeometryDataBuffer& dataBuffer = getIScene().getDataBuffer(m_dataBufferHandle); - return static_cast(dataBuffer.usedSize) / EnumToSize(dataBuffer.dataType); + return dataBuffer.usedSize / EnumToSize(dataBuffer.dataType); } ramses::EDataType ArrayBufferImpl::getDataType() const @@ -62,10 +62,10 @@ namespace ramses::internal return DataTypeUtils::ConvertDataTypeFromInternal(dataBuffer.dataType); } - bool ArrayBufferImpl::getData(std::byte* buffer, uint32_t numElements) const + bool ArrayBufferImpl::getData(std::byte* buffer, size_t numElements) const { const auto& dataBuffer = getIScene().getDataBuffer(m_dataBufferHandle); - const uint32_t dataSizeToCopy = std::min(numElements * EnumToSize(dataBuffer.dataType), static_cast(dataBuffer.data.size())); + const auto dataSizeToCopy = std::min(numElements * EnumToSize(dataBuffer.dataType), dataBuffer.data.size()); PlatformMemory::Copy(buffer, dataBuffer.data.data(), dataSizeToCopy); return true; @@ -142,30 +142,30 @@ namespace ramses::internal report.add(EIssueType::Warning, "DataBuffer is not used anywhere, destroy it if not needed.", &getRamsesObject()); } - bool ArrayBufferImpl::updateData(uint32_t firstElement, uint32_t numElements, const std::byte* bufferData) + bool ArrayBufferImpl::updateData(size_t firstElement, size_t numElements, const std::byte* bufferData) { const GeometryDataBuffer& dataBuffer = getIScene().getDataBuffer(m_dataBufferHandle); const size_t maximumSizeInBytes = dataBuffer.data.size(); - const uint32_t offsetInBytes = firstElement * EnumToSize(dataBuffer.dataType); - const uint32_t dataSizeInBytes = numElements * EnumToSize(dataBuffer.dataType); + const size_t offsetInBytes = firstElement * EnumToSize(dataBuffer.dataType); + const size_t dataSizeInBytes = numElements * EnumToSize(dataBuffer.dataType); if (offsetInBytes + dataSizeInBytes > maximumSizeInBytes) { getErrorReporting().set("DataBuffer::update failed - trying to write data beyond maximum size", *this); return false; } - getIScene().updateDataBuffer(m_dataBufferHandle, offsetInBytes, dataSizeInBytes, bufferData); + getIScene().updateDataBuffer(m_dataBufferHandle, static_cast(offsetInBytes), static_cast(dataSizeInBytes), bufferData); return true; } - uint32_t ArrayBufferImpl::getMaximumNumberOfElements() const + size_t ArrayBufferImpl::getMaximumNumberOfElements() const { const GeometryDataBuffer& dataBuffer = getIScene().getDataBuffer(m_dataBufferHandle); - return static_cast(dataBuffer.data.size()) / EnumToSize(dataBuffer.dataType); + return dataBuffer.data.size() / EnumToSize(dataBuffer.dataType); } - uint32_t ArrayBufferImpl::getUsedNumberOfElements() const + size_t ArrayBufferImpl::getUsedNumberOfElements() const { const GeometryDataBuffer& dataBuffer = getIScene().getDataBuffer(m_dataBufferHandle); return dataBuffer.usedSize / EnumToSize(dataBuffer.dataType); diff --git a/src/client/impl/ArrayBufferImpl.h b/src/client/impl/ArrayBufferImpl.h index ab73cce67..f8f0d7c7b 100644 --- a/src/client/impl/ArrayBufferImpl.h +++ b/src/client/impl/ArrayBufferImpl.h @@ -22,22 +22,22 @@ namespace ramses::internal ArrayBufferImpl(SceneImpl& scene, std::string_view databufferName); ~ArrayBufferImpl() override; - void initializeFrameworkData(ramses::EDataType dataType, uint32_t numElements); + void initializeFrameworkData(ramses::EDataType dataType, size_t numElements); void deinitializeFrameworkData() override; bool serialize(IOutputStream& outStream, SerializationContext& serializationContext) const override; bool deserialize(IInputStream& inStream, DeserializationContext& serializationContext) override; void onValidate(ValidationReportImpl& report) const override; - bool updateData(uint32_t firstElement, uint32_t numElements, const std::byte* bufferData); + bool updateData(size_t firstElement, size_t numElements, const std::byte* bufferData); [[nodiscard]] DataBufferHandle getDataBufferHandle() const; - [[nodiscard]] uint32_t getMaximumNumberOfElements() const; - [[nodiscard]] uint32_t getElementCount() const; - [[nodiscard]] uint32_t getUsedNumberOfElements() const; - [[nodiscard]] uint32_t getUsedElementCount() const; + [[nodiscard]] size_t getMaximumNumberOfElements() const; + [[nodiscard]] size_t getElementCount() const; + [[nodiscard]] size_t getUsedNumberOfElements() const; + [[nodiscard]] size_t getUsedElementCount() const; [[nodiscard]] ramses::EDataType getDataType() const; - [[nodiscard]] bool getData(std::byte* buffer, uint32_t numElements) const; + [[nodiscard]] bool getData(std::byte* buffer, size_t numElements) const; private: DataBufferHandle m_dataBufferHandle; diff --git a/src/client/impl/ArrayResource.cpp b/src/client/impl/ArrayResource.cpp index 00277b7c5..aaa935ab7 100644 --- a/src/client/impl/ArrayResource.cpp +++ b/src/client/impl/ArrayResource.cpp @@ -18,7 +18,7 @@ namespace ramses { } - uint32_t ArrayResource::getNumberOfElements() const + size_t ArrayResource::getNumberOfElements() const { return m_impl.getElementCount(); } diff --git a/src/client/impl/ArrayResourceImpl.cpp b/src/client/impl/ArrayResourceImpl.cpp index a21382640..45da26010 100644 --- a/src/client/impl/ArrayResourceImpl.cpp +++ b/src/client/impl/ArrayResourceImpl.cpp @@ -19,9 +19,9 @@ namespace ramses::internal ArrayResourceImpl::~ArrayResourceImpl() = default; - void ArrayResourceImpl::initializeFromFrameworkData(uint32_t elementCount, ramses::EDataType elementType) + void ArrayResourceImpl::initializeFromFrameworkData(size_t elementCount, ramses::EDataType elementType) { - m_elementCount = elementCount; + m_elementCount = static_cast(elementCount); m_elementType = elementType; } @@ -49,7 +49,7 @@ namespace ramses::internal return true; } - uint32_t ArrayResourceImpl::getElementCount() const + size_t ArrayResourceImpl::getElementCount() const { return m_elementCount; } diff --git a/src/client/impl/ArrayResourceImpl.h b/src/client/impl/ArrayResourceImpl.h index 1483af6e2..ff6d84067 100644 --- a/src/client/impl/ArrayResourceImpl.h +++ b/src/client/impl/ArrayResourceImpl.h @@ -22,11 +22,11 @@ namespace ramses::internal ArrayResourceImpl(ResourceHashUsage arrayHash, SceneImpl& scene, std::string_view name); ~ArrayResourceImpl() override; - void initializeFromFrameworkData(uint32_t elementCount, ramses::EDataType elementType); + void initializeFromFrameworkData(size_t elementCount, ramses::EDataType elementType); bool serialize(IOutputStream& outStream, SerializationContext& serializationContext) const override; bool deserialize(IInputStream& inStream, DeserializationContext& serializationContext) override; - [[nodiscard]] uint32_t getElementCount() const; + [[nodiscard]] size_t getElementCount() const; [[nodiscard]] ramses::EDataType getElementType() const; private: diff --git a/src/client/impl/GeometryImpl.cpp b/src/client/impl/GeometryImpl.cpp index 5541165af..5148307a8 100644 --- a/src/client/impl/GeometryImpl.cpp +++ b/src/client/impl/GeometryImpl.cpp @@ -248,7 +248,7 @@ namespace ramses::internal if (indicesFieldSemantics == ramses::internal::EFixedSemantics::Indices) { getIScene().setDataResource(m_attributeInstance, field, arrayResource.getLowlevelResourceHash(), ramses::internal::DataBufferHandle::Invalid(), 0u, 0u, 0u); - m_indicesCount = arrayResource.getElementCount(); + m_indicesCount = static_cast(arrayResource.getElementCount()); return true; } @@ -287,7 +287,7 @@ namespace ramses::internal getIScene().setDataResource(m_attributeInstance, field, ramses::internal::ResourceContentHash::Invalid(), dataBufferHandle, 0u, 0u, 0u); - m_indicesCount = dataBuffer.getElementCount(); + m_indicesCount = static_cast(dataBuffer.getElementCount()); return true; } diff --git a/src/client/impl/RamsesClientImpl.cpp b/src/client/impl/RamsesClientImpl.cpp index e817529bd..35ce6af41 100644 --- a/src/client/impl/RamsesClientImpl.cpp +++ b/src/client/impl/RamsesClientImpl.cpp @@ -739,7 +739,7 @@ namespace ramses::internal } } - ramses::internal::ManagedResource RamsesClientImpl::createManagedArrayResource(uint32_t numElements, ramses::EDataType type, const void* arrayData, std::string_view name) + ramses::internal::ManagedResource RamsesClientImpl::createManagedArrayResource(size_t numElements, ramses::EDataType type, const void* arrayData, std::string_view name) { if (0u == numElements || nullptr == arrayData) { @@ -750,7 +750,7 @@ namespace ramses::internal ramses::internal::EDataType elementType = DataTypeUtils::ConvertDataTypeToInternal(type); ramses::internal::EResourceType resourceType = DataTypeUtils::DeductResourceTypeFromDataType(type); - auto resource = new ramses::internal::ArrayResource(resourceType, numElements, elementType, arrayData, name); + auto resource = new ramses::internal::ArrayResource(resourceType, static_cast(numElements), elementType, arrayData, name); return manageResource(resource); } diff --git a/src/client/impl/RamsesClientImpl.h b/src/client/impl/RamsesClientImpl.h index 11a8eb7a2..ea432594d 100644 --- a/src/client/impl/RamsesClientImpl.h +++ b/src/client/impl/RamsesClientImpl.h @@ -132,7 +132,7 @@ namespace ramses::internal ramses::SceneReference* findSceneReference(sceneId_t masterSceneId, sceneId_t referencedSceneId); // NOLINTNEXTLINE(modernize-avoid-c-arrays) - ramses::internal::ManagedResource createManagedArrayResource(uint32_t numElements, ramses::EDataType type, const void* arrayData, std::string_view name); + ramses::internal::ManagedResource createManagedArrayResource(size_t numElements, ramses::EDataType type, const void* arrayData, std::string_view name); template ramses::internal::ManagedResource createManagedTexture(ramses::internal::EResourceType textureType, uint32_t width, uint32_t height, uint32_t depth, ETextureFormat format, const std::vector& mipLevelData, bool generateMipChain, const TextureSwizzle& swizzle, std::string_view name); ramses::internal::ManagedResource createManagedEffect(const EffectDescription& effectDesc, std::string_view name, std::string& errorMessages); diff --git a/src/client/impl/Scene.cpp b/src/client/impl/Scene.cpp index db773a400..004ae55d6 100644 --- a/src/client/impl/Scene.cpp +++ b/src/client/impl/Scene.cpp @@ -165,7 +165,7 @@ namespace ramses return m_impl.getUniformTimeMs(); } - ArrayBuffer* Scene::createArrayBuffer(EDataType dataType, uint32_t maxNumElements, std::string_view name /*= {}*/) + ArrayBuffer* Scene::createArrayBuffer(EDataType dataType, size_t maxNumElements, std::string_view name /*= {}*/) { auto dataBufferObject = m_impl.createArrayBuffer(dataType, maxNumElements, name); LOG_HL_CLIENT_API3(LOG_API_RAMSESOBJECT_PTR_STRING(dataBufferObject), maxNumElements, dataType, name); @@ -422,7 +422,7 @@ namespace ramses } template - ArrayResource* Scene::createArrayResourceInternal(uint32_t numElements, const T* arrayData, std::string_view name) + ArrayResource* Scene::createArrayResourceInternal(size_t numElements, const T* arrayData, std::string_view name) { auto arr = m_impl.createArrayResource(numElements, arrayData, name); LOG_HL_CLIENT_API4(LOG_API_RESOURCE_PTR_STRING(arr), numElements, GetEDataType(), LOG_API_GENERIC_PTR_STRING(arrayData), name); @@ -482,13 +482,13 @@ namespace ramses return m_impl; } - template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(uint32_t, const uint16_t*, std::string_view); - template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(uint32_t, const uint32_t*, std::string_view); - template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(uint32_t, const float*, std::string_view); - template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(uint32_t, const vec2f*, std::string_view); - template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(uint32_t, const vec3f*, std::string_view); - template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(uint32_t, const vec4f*, std::string_view); - template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(uint32_t, const std::byte*, std::string_view); + template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(size_t, const uint16_t*, std::string_view); + template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(size_t, const uint32_t*, std::string_view); + template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(size_t, const float*, std::string_view); + template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(size_t, const vec2f*, std::string_view); + template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(size_t, const vec3f*, std::string_view); + template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(size_t, const vec4f*, std::string_view); + template RAMSES_API ArrayResource* Scene::createArrayResourceInternal(size_t, const std::byte*, std::string_view); template RAMSES_API SceneObject* Scene::findObjectByNameInternal(std::string_view); template RAMSES_API LogicEngine* Scene::findObjectByNameInternal(std::string_view); diff --git a/src/client/impl/SceneImpl.cpp b/src/client/impl/SceneImpl.cpp index d71776acf..0f842ca0c 100644 --- a/src/client/impl/SceneImpl.cpp +++ b/src/client/impl/SceneImpl.cpp @@ -1487,7 +1487,7 @@ namespace ramses::internal m_nextSceneVersion = sceneVersion; } - ArrayBuffer* SceneImpl::createArrayBuffer(ramses::EDataType dataType, uint32_t maxNumElements, std::string_view name) + ArrayBuffer* SceneImpl::createArrayBuffer(ramses::EDataType dataType, size_t maxNumElements, std::string_view name) { if (!IsArrayResourceDataType(dataType)) { @@ -1646,7 +1646,7 @@ namespace ramses::internal } template - ramses::ArrayResource* SceneImpl::createArrayResource(uint32_t numElements, const T* arrayData, std::string_view name) + ramses::ArrayResource* SceneImpl::createArrayResource(size_t numElements, const T* arrayData, std::string_view name) { if (0u == numElements || nullptr == arrayData) { @@ -1955,11 +1955,11 @@ namespace ramses::internal m_resources.insert({ resourceWithNewId.getResourceId(), &resourceWithNewId }); } - template ramses::ArrayResource* SceneImpl::createArrayResource(uint32_t, const uint16_t*, std::string_view); - template ramses::ArrayResource* SceneImpl::createArrayResource(uint32_t, const uint32_t*, std::string_view); - template ramses::ArrayResource* SceneImpl::createArrayResource(uint32_t, const float*, std::string_view); - template ramses::ArrayResource* SceneImpl::createArrayResource(uint32_t, const vec2f*, std::string_view); - template ramses::ArrayResource* SceneImpl::createArrayResource(uint32_t, const vec3f*, std::string_view); - template ramses::ArrayResource* SceneImpl::createArrayResource(uint32_t, const vec4f*, std::string_view); - template ramses::ArrayResource* SceneImpl::createArrayResource(uint32_t, const std::byte*, std::string_view); + template ramses::ArrayResource* SceneImpl::createArrayResource(size_t, const uint16_t*, std::string_view); + template ramses::ArrayResource* SceneImpl::createArrayResource(size_t, const uint32_t*, std::string_view); + template ramses::ArrayResource* SceneImpl::createArrayResource(size_t, const float*, std::string_view); + template ramses::ArrayResource* SceneImpl::createArrayResource(size_t, const vec2f*, std::string_view); + template ramses::ArrayResource* SceneImpl::createArrayResource(size_t, const vec3f*, std::string_view); + template ramses::ArrayResource* SceneImpl::createArrayResource(size_t, const vec4f*, std::string_view); + template ramses::ArrayResource* SceneImpl::createArrayResource(size_t, const std::byte*, std::string_view); } diff --git a/src/client/impl/SceneImpl.h b/src/client/impl/SceneImpl.h index c46d0d5b6..a978b5ca4 100644 --- a/src/client/impl/SceneImpl.h +++ b/src/client/impl/SceneImpl.h @@ -190,7 +190,7 @@ namespace ramses::internal bool createTextureConsumer(const TextureSamplerMS& sampler, dataConsumerId_t id); bool createTextureConsumer(const TextureSamplerExternal& sampler, dataConsumerId_t id); - ArrayBuffer* createArrayBuffer(ramses::EDataType dataType, uint32_t maxNumElements, std::string_view name); + ArrayBuffer* createArrayBuffer(ramses::EDataType dataType, size_t maxNumElements, std::string_view name); Texture2DBuffer* createTexture2DBuffer (size_t mipLevels, uint32_t width, uint32_t height, ETextureFormat textureFormat, std::string_view name); SceneReference* createSceneReference(sceneId_t referencedScene, std::string_view name); @@ -208,7 +208,7 @@ namespace ramses::internal template // NOLINTNEXTLINE(modernize-avoid-c-arrays) - ramses::ArrayResource* createArrayResource(uint32_t numElements, const T* arrayData, std::string_view name); + ramses::ArrayResource* createArrayResource(size_t numElements, const T* arrayData, std::string_view name); Texture2D* createTexture2D(uint32_t width, uint32_t height, ETextureFormat format, const std::vector& mipLevelData, bool generateMipChain, const TextureSwizzle& swizzle, std::string_view name); Texture3D* createTexture3D(uint32_t width, uint32_t height, uint32_t depth, ETextureFormat format, const std::vector& mipLevelData, bool generateMipChain, std::string_view name); TextureCube* createTextureCube(uint32_t size, ETextureFormat format, const std::vector& mipLevelData, bool generateMipChain, const TextureSwizzle& swizzle, std::string_view name); diff --git a/src/framework/impl/APILoggingMacros.h b/src/framework/impl/APILoggingMacros.h index fa65af80a..7b5972c83 100644 --- a/src/framework/impl/APILoggingMacros.h +++ b/src/framework/impl/APILoggingMacros.h @@ -50,7 +50,7 @@ // Client side macros #define LOG_HL_CLIENT_API_STR(...) \ - LOG_API_LOGLEVEL(ramses::internal::CONTEXT_HLAPI_CLIENT, __VA_ARGS__) + LOG_API_LOGLEVEL(ramses::internal::CONTEXT_HLAPI_CLIENT, "{}", __VA_ARGS__) #define LOG_HL_CLIENT_API_NOARG(retval) \ LOG_HL_CLIENT_API_STR(LOG_API_BASE(retval)) diff --git a/tests/integration/renderer-tests/renderer-lifecycle-tests/RendererLifecycleTests.cpp b/tests/integration/renderer-tests/renderer-lifecycle-tests/RendererLifecycleTests.cpp index 7714ae737..6c898cfba 100644 --- a/tests/integration/renderer-tests/renderer-lifecycle-tests/RendererLifecycleTests.cpp +++ b/tests/integration/renderer-tests/renderer-lifecycle-tests/RendererLifecycleTests.cpp @@ -20,6 +20,7 @@ #include "TestScenes/TextureSamplerScene.h" #include "TestScenes/TransformationLinkScene.h" #include "TestScenes/VisibilityScene.h" +#include "TestScenes/RenderTargetScene.h" // These includes are needed because of ramses API usage #include "ramses/renderer/IRendererEventHandler.h" @@ -1957,4 +1958,33 @@ namespace ramses::internal testScenesAndRenderer.unpublish(sceneId3); testScenesAndRenderer.destroyRenderer(); } + + TEST_F(ARendererLifecycleTest, ChangeResolutionOfRenderTargetUsingLogic) + { + const sceneId_t sceneId = createScene(RenderTargetScene::RENDERBUFFER_LOGIC_LOWRES); + testScenesAndRenderer.initializeRenderer(); + displayId_t display = createDisplayForWindow(); + + // render initial low res + testScenesAndRenderer.publish(sceneId); + testScenesAndRenderer.flush(sceneId); + testRenderer.setSceneMapping(sceneId, display); + ASSERT_TRUE(testScenesAndRenderer.getSceneToState(sceneId, RendererSceneState::Rendered)); + ASSERT_TRUE(checkScreenshot(display, "ARenderTargetSizeChange_Low")); + + // unmap scene, change resolution of render target and render again + ASSERT_TRUE(testScenesAndRenderer.getSceneToState(sceneId, RendererSceneState::Available)); + testScenesAndRenderer.getScenesRegistry().setSceneState(sceneId, RenderTargetScene::RENDERBUFFER_LOGIC_HIGHRES); + testScenesAndRenderer.flush(sceneId); + ASSERT_TRUE(testScenesAndRenderer.getSceneToState(sceneId, RendererSceneState::Rendered)); + ASSERT_TRUE(checkScreenshot(display, "ARenderTargetSizeChange_High")); + + // change back to lowres while scene rendered -> such change is not valid for already uploaded render buffer but it will change viewport + testScenesAndRenderer.getScenesRegistry().setSceneState(sceneId, RenderTargetScene::RENDERBUFFER_LOGIC_LOWRES); + testScenesAndRenderer.flush(sceneId); + ASSERT_TRUE(checkScreenshot(display, "ARenderTargetSizeChange_Invalid")); + + testScenesAndRenderer.unpublish(sceneId); + testScenesAndRenderer.destroyRenderer(); + } } diff --git a/tests/integration/renderer-tests/res/ARenderTargetSizeChange_High.PNG b/tests/integration/renderer-tests/res/ARenderTargetSizeChange_High.PNG new file mode 100644 index 0000000000000000000000000000000000000000..2c1e5af6e6f48c44e0cb2e211204ab7516976e3c GIT binary patch literal 221 zcmeAS@N?(olHy`uVBq!ia0vp^4M6O`#0(_Y@0k7uNO1=Egt!9f{|x`@>+Ac3l30Ko zrjj7P;Q#fiyfM##yhcwK$B+ufx05&W9#9Zq-khQ#(O4_d$mBnBd*-4S_Fm0XG{6$`r9zf-8*wlIWT{ zuh?S`o?2UHAQmMU+o=DdS$|)`%|V7p%%^ RY6d!n!PC{xWt~$(698x=QoR5G literal 0 HcmV?d00001 diff --git a/tests/integration/renderer-tests/res/ARenderTargetSizeChange_Invalid.PNG b/tests/integration/renderer-tests/res/ARenderTargetSizeChange_Invalid.PNG new file mode 100644 index 0000000000000000000000000000000000000000..106b75f5cbc4cfd33c0e23de77f9315e349279b9 GIT binary patch literal 138 zcmeAS@N?(olHy`uVBq!ia0vp^4M6O`#0(_Y@0k7uNO1=Egt!9f{|x`@>+Ac3l30Ko zrjj7P;Q#fiyfM##JUver$B+ufx0g3^GB9v3J5Ddz@->a!0~>%v;t5kgQu&X%Q~loCIGY5DE$Bc literal 0 HcmV?d00001 diff --git a/tests/integration/renderer-tests/res/ARenderTargetSizeChange_Low.PNG b/tests/integration/renderer-tests/res/ARenderTargetSizeChange_Low.PNG new file mode 100644 index 0000000000000000000000000000000000000000..368b15a6220b26b5f5d08c4235f7da53170fd5c3 GIT binary patch literal 153 zcmeAS@N?(olHy`uVBq!ia0vp^4M6O`#0(_Y@0k7uNO1=Egt!9f{|x`@>+Ac3l30Ko zrjj7P;Q#fiyfM##JX=o}$B+ufx0AKS7!(AU_NpBH9ci(2|D(-O4^Fb2@|&akkd6JA y)6+d`zlvI9+<2|+@kPLK*{eUT0sQ9=T`y_9^j=WZ^>94UAO=rYKbLh*2~7Y&P&EJm literal 0 HcmV?d00001 diff --git a/tests/integration/test-content/RenderTargetScene.cpp b/tests/integration/test-content/RenderTargetScene.cpp index d7f1094ad..03d256cdf 100644 --- a/tests/integration/test-content/RenderTargetScene.cpp +++ b/tests/integration/test-content/RenderTargetScene.cpp @@ -21,19 +21,30 @@ #include "ramses/client/MeshNode.h" #include "ramses/client/Appearance.h" #include "ramses/client/RenderTargetDescription.h" +#include "ramses/client/logic/LogicEngine.h" +#include "ramses/client/logic/RenderBufferBinding.h" +#include "ramses/client/logic/CameraBinding.h" +#include "ramses/client/logic/LuaInterface.h" +#include "ramses/client/logic/Property.h" #include namespace ramses::internal { RenderTargetScene::RenderTargetScene(ramses::Scene& scene, uint32_t state, const glm::vec3& cameraPosition, uint32_t vpWidth, uint32_t vpHeight) - : IntegrationScene(scene, cameraPosition, vpWidth, vpHeight) - , m_renderBuffer(createRenderBuffer(state)) + : IntegrationScene{ scene, cameraPosition, vpWidth, vpHeight } + , m_camera{ *createCamera(state) } + , m_renderBuffer{ *createRenderBuffer(state) } { initInputRenderPass(state); initFinalRenderPass(); + if (state == RENDERBUFFER_LOGIC_LOWRES || state == RENDERBUFFER_LOGIC_HIGHRES) + { + createLogic(); + setState(state); + } } - const ramses::RenderBuffer& RenderTargetScene::createRenderBuffer(uint32_t state) + ramses::RenderBuffer* RenderTargetScene::createRenderBuffer(uint32_t state) { ramses::ERenderBufferFormat bufferFormat = ramses::ERenderBufferFormat::RGBA8; @@ -41,6 +52,8 @@ namespace ramses::internal { case PERSPECTIVE_PROJECTION: case ORTHOGRAPHIC_PROJECTION: + case RENDERBUFFER_LOGIC_LOWRES: + case RENDERBUFFER_LOGIC_HIGHRES: bufferFormat = ramses::ERenderBufferFormat::RGBA8; break; case RENDERBUFFER_FORMAT_RGBA4: @@ -85,9 +98,9 @@ namespace ramses::internal break; } - const ramses::RenderBuffer* renderBuffer = m_scene.createRenderBuffer(16u, 16u, bufferFormat, ramses::ERenderBufferAccessMode::ReadWrite); + ramses::RenderBuffer* renderBuffer = m_scene.createRenderBuffer(16u, 16u, bufferFormat, ramses::ERenderBufferAccessMode::ReadWrite); assert(renderBuffer != nullptr); - return *renderBuffer; + return renderBuffer; } ramses::Camera* RenderTargetScene::createCamera(uint32_t state) @@ -115,6 +128,8 @@ namespace ramses::internal case RENDERBUFFER_FORMAT_RGB32F: case RENDERBUFFER_FORMAT_RGBA16F: case RENDERBUFFER_FORMAT_RGBA32F: + case RENDERBUFFER_LOGIC_LOWRES: + case RENDERBUFFER_LOGIC_HIGHRES: { ramses::OrthographicCamera* camera = m_scene.createOrthographicCamera(); camera->setFrustum(-1.f, 1.f, -1.f, 1.f, 1.f, 10.f); @@ -154,7 +169,7 @@ namespace ramses::internal renderPass->addRenderGroup(*renderGroup); renderGroup->addMeshNode(*meshNode); - renderPass->setCamera(*createCamera(state)); + renderPass->setCamera(m_camera); ramses::RenderTargetDescription rtDesc; rtDesc.addRenderBuffer(m_renderBuffer); @@ -214,4 +229,35 @@ namespace ramses::internal renderPass->addRenderGroup(*renderGroup); renderGroup->addMeshNode(*meshNode); } + + void RenderTargetScene::createLogic() + { + const std::string_view intfSrc = R"( + function interface(inputs) + inputs.res = Type:Int32() + end + )"; + + // resolution interface links to camera viewport and renderbuffer resolution + auto logic = m_scene.createLogicEngine("logic"); + auto camBinding = logic->createCameraBinding(m_camera); + auto rbBinding = logic->createRenderBufferBinding(m_renderBuffer); + auto intf = logic->createLuaInterface(intfSrc, "logicIntf"); + logic->link(*intf->getOutputs()->getChild(0u), *camBinding->getInputs()->getChild("viewport")->getChild("width")); + logic->link(*intf->getOutputs()->getChild(0u), *camBinding->getInputs()->getChild("viewport")->getChild("height")); + logic->link(*intf->getOutputs()->getChild(0u), *rbBinding->getInputs()->getChild("width")); + logic->link(*intf->getOutputs()->getChild(0u), *rbBinding->getInputs()->getChild("height")); + } + + void RenderTargetScene::setState(uint32_t state) + { + if (state != RENDERBUFFER_LOGIC_LOWRES && state != RENDERBUFFER_LOGIC_HIGHRES) + return; + + auto logicIntf = m_scene.findObject("logicIntf")->as(); + assert(logicIntf); + logicIntf->getInputs()->getChild("res")->set(state == RENDERBUFFER_LOGIC_LOWRES ? 4 : 64); + + m_scene.findObject("logic")->update(); + } } diff --git a/tests/integration/test-content/TestScenes/RenderTargetScene.h b/tests/integration/test-content/TestScenes/RenderTargetScene.h index d5d2d8846..a371be490 100644 --- a/tests/integration/test-content/TestScenes/RenderTargetScene.h +++ b/tests/integration/test-content/TestScenes/RenderTargetScene.h @@ -23,6 +23,8 @@ namespace ramses::internal public: RenderTargetScene(ramses::Scene& scene, uint32_t state, const glm::vec3& cameraPosition, uint32_t vpWidth = IntegrationScene::DefaultViewportWidth, uint32_t vpHeight = IntegrationScene::DefaultViewportHeight); + void setState(uint32_t state); + enum { PERSPECTIVE_PROJECTION = 0, @@ -39,15 +41,20 @@ namespace ramses::internal RENDERBUFFER_FORMAT_RGB16F, RENDERBUFFER_FORMAT_RGB32F, RENDERBUFFER_FORMAT_RGBA16F, - RENDERBUFFER_FORMAT_RGBA32F + RENDERBUFFER_FORMAT_RGBA32F, + + RENDERBUFFER_LOGIC_LOWRES, + RENDERBUFFER_LOGIC_HIGHRES }; private: - const ramses::RenderBuffer& createRenderBuffer(uint32_t state); + ramses::RenderBuffer* createRenderBuffer(uint32_t state); ramses::Camera* createCamera(uint32_t state); void initInputRenderPass(uint32_t state); void initFinalRenderPass(); + void createLogic(); - const ramses::RenderBuffer& m_renderBuffer; + ramses::Camera& m_camera; + ramses::RenderBuffer& m_renderBuffer; }; } diff --git a/tests/integration/viewer-tests/LogicViewerAppTest.cpp b/tests/integration/viewer-tests/LogicViewerAppTest.cpp index 68eff4e8e..a1e012028 100644 --- a/tests/integration/viewer-tests/LogicViewerAppTest.cpp +++ b/tests/integration/viewer-tests/LogicViewerAppTest.cpp @@ -114,21 +114,19 @@ end )"; const auto iniFile = R"( -[Window][LogicEngine[10]] +[Window][Logic] +Pos=0,0 +Size=540,720 +Collapsed=0 + +[Window][Scene[1]: simple triangle scene (FeatureLevel 01)] Pos=0,0 Size=540,720 Collapsed=0 [ramses-viewer][Settings] -ShowInterfaces=1 -ShowScripts=1 -ShowAnimationNodes=1 -ShowTimerNodes=1 -ShowDataArrays=1 -ShowRamsesBindings=1 +ShowLogicWindow=1 ShowUpdateReport=0 -ShowLinkedInputs=1 -ShowOutputs=1 LuaPreferObjectIds=0 LuaPreferIdentifiers=0 )"; @@ -153,9 +151,7 @@ class UI [[nodiscard]] int32_t updateReport() const { - // there's an extra line in the view section if update report is enabled - const bool showUpdateReport = m_settings ? m_settings->showUpdateReport : false; - return 86 + yMiddle + (showUpdateReport ? 20 : 0); + return 66 + yMiddle ; } private: @@ -802,6 +798,7 @@ namespace ramses::internal TEST_F(ALogicViewerAppUI, reloadConfiguration) { + m_app->getSettings()->showLogicWindow = false; const int32_t xFile = 25; auto* script = m_app->getLogicViewer()->getLogic().findObject("allTypesScript"); ASSERT_TRUE(script != nullptr); @@ -817,7 +814,7 @@ namespace ramses::internal SaveFile(R"(rlogic.scripts.allTypesScript.IN.paramString.value = "World")"); EXPECT_TRUE(click(xFile, ui.titleBar + ui.yMiddle)); - EXPECT_TRUE(click(xFile, ui.titleBar + ui.buttonHeight + ui.yMiddle)); + EXPECT_TRUE(click(xFile, ui.titleBar + ui.buttonHeight + 4*ui.smallButtonHeight + ui.yMiddle)); EXPECT_EQ("World", prop->get().value()); SaveFile(R"(rlogic.scripts.allTypesScript.IN.paramString.value = "Foo")"); @@ -828,7 +825,7 @@ namespace ramses::internal TEST_F(ALogicViewerAppUI, reloadConfigurationWithHiddenUI) { auto* settings = m_app->getSettings(); - settings->showGui = false; + settings->showWindow = false; auto* script = m_app->getLogicViewer()->getLogic().findObject("allTypesScript"); ASSERT_TRUE(script != nullptr); auto* prop = script->getOutputs()->getChild("paramString"); @@ -882,7 +879,7 @@ namespace ramses::internal EXPECT_TRUE(CompareImage("screenshot.png", "ALogicViewerApp_yellow.png")); // Modify the "blue" input 0 -> 1 - EXPECT_TRUE(dragX(100, 100 + 10, ui.titleBar + 2 * ui.buttonHeight + 2 * ui.smallButtonHeight + ui.yMiddle)); + EXPECT_TRUE(dragX(100, 100 + 10, ui.titleBar + 1 * ui.buttonHeight + 2 * ui.smallButtonHeight + ui.yMiddle)); EXPECT_EQ(Result(), m_app->getLogicViewer()->call("screenshot")); EXPECT_TRUE(CompareImage("screenshot.png", "ALogicViewerApp_white.png")); @@ -894,29 +891,12 @@ namespace ramses::internal TEST_F(ALogicViewerAppUI, settings) { - const int xSettings = 75; - auto* settings = m_app->getSettings(); EXPECT_TRUE(settings->showLogicWindow); - EXPECT_TRUE(contextMenuSelect(700, 350, 2)); + EXPECT_TRUE(contextMenuSelect(700, 350, 1)); EXPECT_FALSE(settings->showLogicWindow); - EXPECT_TRUE(contextMenuSelect(700, 350, 2)); + EXPECT_TRUE(contextMenuSelect(700, 350, 1)); EXPECT_TRUE(settings->showLogicWindow); - - EXPECT_FALSE(settings->luaPreferObjectIds); - EXPECT_TRUE(click(xSettings, ui.titleBar + ui.yMiddle)); - EXPECT_TRUE(click(xSettings, ui.titleBar + ui.buttonHeight + 2 * ui.smallButtonHeight + 3 * ui.hline + ui.yMiddle)); - EXPECT_TRUE(settings->luaPreferObjectIds); - - EXPECT_FALSE(settings->luaPreferIdentifiers); - EXPECT_TRUE(click(xSettings, ui.titleBar + ui.yMiddle)); - EXPECT_TRUE(click(xSettings, ui.titleBar + ui.buttonHeight + 1 * ui.smallButtonHeight + 3 * ui.hline + ui.yMiddle)); - EXPECT_TRUE(settings->luaPreferIdentifiers); - - EXPECT_FALSE(settings->showUpdateReport); - EXPECT_TRUE(click(xSettings, ui.titleBar + ui.yMiddle)); - EXPECT_TRUE(click(xSettings, ui.titleBar + ui.buttonHeight + 0 * ui.smallButtonHeight + ui.hline + ui.yMiddle)); - EXPECT_TRUE(settings->showUpdateReport); } class ALogicViewerAppUIClearColor : public ALogicViewerAppUIBase, public ::testing::TestWithParam @@ -963,28 +943,18 @@ namespace ramses::internal TEST_F(ALogicViewerAppUIUpdateReport, updateReport) { - setup(R"([Window][LogicEngine[10]] + setup(R"([Window][Logic] Pos=0,0 Size=540,720 Collapsed=0 [ramses-viewer][Settings] -ShowInterfaces=1 -ShowScripts=1 -ShowAnimationNodes=1 -ShowTimerNodes=1 -ShowDataArrays=1 -ShowRamsesBindings=1 -ShowUpdateReport=1 -ShowLinkedInputs=1 -ShowOutputs=1 +ShowLogicWindow=1 LuaPreferObjectIds=0 LuaPreferIdentifiers=0 )"); + m_app->getSettings()->showUpdateReportDetails = true; const int32_t mouseX = 100; - EXPECT_TRUE(click(mouseX, ui.updateReport())); - EXPECT_TRUE(click(mouseX, ui.updateReport() + 2 * ui.buttonHeight + 7 * ui.smallButtonHeight + ui.hline)); - EXPECT_TRUE(click(mouseX, ui.updateReport() + 2 * ui.buttonHeight + 6 * ui.smallButtonHeight + ui.hline)); const auto& report = m_app->getLogicViewer()->getUpdateReport(); diff --git a/tests/unittests/client/SceneTest.cpp b/tests/unittests/client/SceneTest.cpp index 83c2a1a65..54d857ae3 100644 --- a/tests/unittests/client/SceneTest.cpp +++ b/tests/unittests/client/SceneTest.cpp @@ -1918,4 +1918,31 @@ namespace ramses::internal EXPECT_TRUE(loadedScene->findObject("boundNode")->getTranslation(nodeTr)); EXPECT_EQ(glm::vec3(111, 222, 333), nodeTr); } + + TEST(SceneAPILog, log_export) + { + static ramses::RamsesFrameworkConfig config(ramses::EFeatureLevel::EFeatureLevel_01); + config.setLogLevel(ramses::ELogLevel::Trace); + ramses::RamsesFramework ramsesFramework{config}; + ramses::RamsesClient& client = *ramsesFramework.createClient("example client"); + ramses::Scene* scene = client.createScene(ramses::sceneId_t(123u), "example scene"); + + ramses::SaveFileConfig saveConfig; + saveConfig.setMetadataString(R"({ +"generator" : "test" +})"); + ASSERT_TRUE(scene->saveToFile("saveToFile_empty.ramses", saveConfig)); + ASSERT_TRUE(std::filesystem::remove("saveToFile_empty.ramses")); + } + + TEST(SceneAPILog, log_create_node) + { + ramses::RamsesFrameworkConfig config{ramses::EFeatureLevel::EFeatureLevel_01}; + config.setLogLevel(ramses::ELogLevel::Trace); + ramses::RamsesFramework ramsesFramework{config}; + ramses::RamsesClient& client = *ramsesFramework.createClient("example client"); + ramses::Scene* scene = client.createScene(ramses::sceneId_t(123u), "example scene"); + + scene->createNode("{}"); + } } diff --git a/tools/ramses-viewer/LogicEngineGui.h b/tools/ramses-viewer/LogicEngineGui.h index c820bff27..ac3477e1b 100644 --- a/tools/ramses-viewer/LogicEngineGui.h +++ b/tools/ramses-viewer/LogicEngineGui.h @@ -39,9 +39,6 @@ namespace ramses::internal public: explicit LogicEngineGui(const ViewerSettings& settings); - template - void drawCollection(ramses::LogicEngine& logicEngine, std::string_view ns, const char* headline); - template void drawCollection(ramses::Collection collection, std::string_view ns, const char* headline, const C& cb); @@ -78,33 +75,6 @@ namespace ramses::internal const ViewerSettings& m_settings; }; - template - inline void LogicEngineGui::drawCollection(ramses::LogicEngine& logicEngine, std::string_view ns, const char* headline) - { - const bool openCollection = ImGui::CollapsingHeader(headline); - if (ImGui::BeginPopupContextItem(fmt::format("{}ContextMenu", ns).c_str())) - { - if (ImGui::MenuItem(fmt::format("{}: Copy all inputs", headline).c_str())) - { - copyInputs(ns, logicEngine.getCollection()); - } - ImGui::EndPopup(); - } - if (openCollection) - { - for (auto* obj : logicEngine.getCollection()) - { - const bool open = DrawTreeNode(obj); - drawNodeContextMenu(obj, ns); - if (open) - { - draw(obj); - ImGui::TreePop(); - } - } - } - } - template void LogicEngineGui::drawCollection(ramses::Collection collection, std::string_view ns, const char* headline, const C& cbDrawItem) { diff --git a/tools/ramses-viewer/LogicViewerGui.cpp b/tools/ramses-viewer/LogicViewerGui.cpp index 0162a9227..50a3b1328 100644 --- a/tools/ramses-viewer/LogicViewerGui.cpp +++ b/tools/ramses-viewer/LogicViewerGui.cpp @@ -146,11 +146,10 @@ namespace ramses::internal LogicViewerGui::LogicViewerGui(ViewerGuiApp& app, std::string& errorMessage) : m_settings(*app.getSettings()) , m_viewer(*app.getLogicViewer()) - , m_logicEngine(m_viewer.getLogic()) , m_lastErrorMessage(errorMessage) , m_filename(app.getLuaFile()) { - m_viewer.enableUpdateReport(m_settings.showUpdateReport, m_updateReportInterval); + m_viewer.enableUpdateReport(m_settings.showUpdateReport, m_settings.updateReportInterval); } void LogicViewerGui::handleShortcuts() @@ -172,17 +171,9 @@ namespace ramses::internal } } - void LogicViewerGui::draw() - { - if (m_settings.showLogicWindow) - { - drawWindow(); - } - } - void LogicViewerGui::drawMenuItemReload() { - if (ImGui::MenuItem("Reload configuration", "F5")) + if (ImGui::MenuItem("Reload lua configuration", "F5")) { reloadConfiguration(); } @@ -216,55 +207,24 @@ namespace ramses::internal void LogicViewerGui::drawWindow() { - const auto windowTitle = m_logicEngine.getName().empty() - ? fmt::format("LogicEngine[{}]", m_logicEngine.getSceneObjectId().getValue()) - : fmt::format("LogicEngine[{}]: {}", m_logicEngine.getSceneObjectId().getValue(), m_logicEngine.getName()); - if (!ImGui::Begin(windowTitle.c_str(), &m_settings.showLogicWindow, ImGuiWindowFlags_MenuBar)) + if (!ImGui::Begin("Logic", &m_settings.showLogicWindow)) { ImGui::End(); return; } + drawContents(); + ImGui::End(); + } - drawMenuBar(); + void LogicViewerGui::drawContents() + { drawCurrentView(); if (m_settings.showUpdateReport) { + ImGui::Separator(); drawUpdateReport(); } - - ImGui::End(); - } - - void LogicViewerGui::drawMenuBar() - { - if (ImGui::BeginMenuBar()) - { - if (ImGui::BeginMenu("File")) - { - drawMenuItemReload(); - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Settings")) - { - if (ImGui::MenuItem("Show Update Report", nullptr, &m_settings.showUpdateReport)) - { - m_viewer.enableUpdateReport(m_settings.showUpdateReport, m_updateReportInterval); - ImGui::MarkIniSettingsDirty(); - } - ImGui::Separator(); - auto changed = ImGui::MenuItem("Lua: prefer identifiers (scripts.foo)", nullptr, &m_settings.luaPreferIdentifiers); - changed = ImGui::MenuItem("Lua: prefer object ids (scripts[1])", nullptr, &m_settings.luaPreferObjectIds) || changed; - ImGui::EndMenu(); - - if (changed) - { - ImGui::MarkIniSettingsDirty(); - } - } - ImGui::EndMenuBar(); - } } void LogicViewerGui::drawCurrentView() @@ -306,32 +266,30 @@ namespace ramses::internal { ImGui::TextUnformatted("no views defined in configuration file"); } - - if (m_settings.showUpdateReport) - { - ImGui::Separator(); - ImGui::TextUnformatted(fmt::format("Average Update Time: {} ms", m_viewer.getUpdateReport().getTotalTime().average).c_str()); - ImGui::SameLine(); - HelpMarker("Time it took to update the whole logic nodes network (LogicEngine::update())."); - } } void LogicViewerGui::drawUpdateReport() { - const bool open = ImGui::CollapsingHeader("Update Report"); - if (open) + ImGui::TextUnformatted(fmt::format("Average Update Time: {} ms", m_viewer.getUpdateReport().getTotalTime().average).c_str()); + ImGui::SameLine(); + HelpMarker("Time it took to update the whole logic nodes network (LogicEngine::update())."); + ImGui::SameLine(); + if (ImGui::SmallButton(m_settings.showUpdateReportDetails ? "Hide Details" : "Show Details")) + m_settings.showUpdateReportDetails = !m_settings.showUpdateReportDetails; + + if (m_settings.showUpdateReportDetails) { - auto interval = static_cast(m_updateReportInterval); + auto interval = static_cast(m_settings.updateReportInterval); bool refresh = m_viewer.isUpdateReportEnabled(); if (ImGui::Checkbox("Auto Refresh", &refresh)) { - m_viewer.enableUpdateReport(refresh, m_updateReportInterval); + m_viewer.enableUpdateReport(refresh, m_settings.updateReportInterval); } ImGui::SetNextItemWidth(100); if (ImGui::DragInt("Refresh Interval", &interval, 0.5f, 1, 1000, "%d Frames")) { - m_updateReportInterval = static_cast(interval); - m_viewer.enableUpdateReport(refresh, m_updateReportInterval); + m_settings.updateReportInterval = static_cast(interval); + m_viewer.enableUpdateReport(refresh, m_settings.updateReportInterval); } const auto& report = m_viewer.getUpdateReport(); const auto& executed = report.getNodesExecuted(); @@ -341,7 +299,8 @@ namespace ramses::internal ImGui::Separator(); ImGui::TextUnformatted("Summary:"); ImGui::SameLine(); - HelpMarker("Timing data is collected and summarized for {} frames.\n'min', 'max', 'avg' show the minimum, maximum, and average value for the measured interval.", m_updateReportInterval); + HelpMarker("Timing data is collected and summarized for {} frames.\n'min', 'max', 'avg' show the minimum, maximum, and average value for the measured interval.", + m_settings.updateReportInterval); ImGui::Indent(); const auto& updateTime = report.getTotalTime(); @@ -443,22 +402,6 @@ namespace ramses::internal } } - void LogicViewerGui::DrawDataArray(const ramses::DataArray* obj, std::string_view context) - { - if (obj != nullptr) - { - if (!context.empty()) - { - ImGui::TextUnformatted( - fmt::format("{}: [{}]: {} Type:{}[{}]", context.data(), obj->getSceneObjectId().getValue(), obj->getName(), GetLuaPrimitiveTypeName(obj->getDataType()), obj->getNumElements()).c_str()); - } - else - { - ImGui::TextUnformatted(fmt::format("[{}]: {} Type:{}[{}]", obj->getSceneObjectId().getValue(), obj->getName(), GetLuaPrimitiveTypeName(obj->getDataType()), obj->getNumElements()).c_str()); - } - } - } - void LogicViewerGui::saveDefaultLuaFile() { const auto result = m_viewer.saveDefaultLuaFile(m_filename, m_settings); diff --git a/tools/ramses-viewer/LogicViewerGui.h b/tools/ramses-viewer/LogicViewerGui.h index ef45c8bff..3f86e8745 100644 --- a/tools/ramses-viewer/LogicViewerGui.h +++ b/tools/ramses-viewer/LogicViewerGui.h @@ -32,34 +32,30 @@ namespace ramses::internal * If it does not exist the LogicViewerGui will provide a UI to save the default settings */ explicit LogicViewerGui(ViewerGuiApp& app, std::string& errorMessage); - void draw(); + + void drawWindow(); + void drawContents(); void drawGlobalContextMenuItems(); + void drawMenuItemReload(); void handleShortcuts(); private: - void drawMenuItemReload(); - void drawWindow(); - void drawMenuBar(); void drawCurrentView(); void drawUpdateReport(); void drawSaveDefaultLuaFile(); - static void DrawDataArray(const ramses::DataArray* obj, std::string_view context = std::string_view()); - void reloadConfiguration(); void loadLuaFile(const std::string& filename); void saveDefaultLuaFile(); ViewerSettings& m_settings; LogicViewer& m_viewer; - ramses::LogicEngine& m_logicEngine; std::string& m_lastErrorMessage; std::string m_filename; - size_t m_updateReportInterval = 60u; }; } diff --git a/tools/ramses-viewer/SceneViewerGui.cpp b/tools/ramses-viewer/SceneViewerGui.cpp index 486889138..e002dc5aa 100644 --- a/tools/ramses-viewer/SceneViewerGui.cpp +++ b/tools/ramses-viewer/SceneViewerGui.cpp @@ -62,6 +62,9 @@ #include "internal/Core/Utils/File.h" #include "glm/gtc/type_ptr.hpp" #include "impl/TextureEnumsImpl.h" +#include +namespace fs = std::filesystem; + namespace ramses::internal { namespace @@ -315,12 +318,18 @@ namespace ramses::internal : m_scene(scene) , m_validationCache(app.getValidationReport()) , m_loadedSceneFile(app.getSceneFile()) - , m_filename(app.getSceneFile()) , m_lastErrorMessage(errorMessage) , m_imageCache(app.getImguiClientHelper()->getScene()) , m_settings(*app.getSettings()) , m_progressMonitor(progressMonitor) { + // can't write to the open scene file -> propose another name + fs::path p(app.getSceneFile()); + auto newName = p.stem(); + newName += "_copy.ramses"; + p.replace_filename(newName); + m_filename = p.string(); + ramses::internal::StringOutputStream dummyStream; SceneDumper sceneDumper(scene.impl()); sceneDumper.dumpUnrequiredObjects(dummyStream); @@ -1705,7 +1714,7 @@ namespace ramses::internal void SceneViewerGui::drawArrayResource(ArrayResourceImpl& obj) { drawResource(obj); - ImGui::Text("%s[%u]", EnumToString(obj.getElementType()), obj.getElementCount()); + ImGui::Text("%s[%lu]", EnumToString(obj.getElementType()), obj.getElementCount()); drawRefs("Used by Geometry", obj, [&](const ramses::Geometry* ref) { auto& iScene = m_scene.impl().getIScene(); const auto& layout = iScene.getDataLayout(ref->impl().getAttributeDataLayout()); @@ -1723,7 +1732,7 @@ namespace ramses::internal void SceneViewerGui::drawArrayBuffer(ArrayBufferImpl& obj) { - ImGui::Text("%s[%u]", EnumToString(obj.getDataType()), obj.getElementCount()); + ImGui::Text("%s[%lu]", EnumToString(obj.getDataType()), obj.getElementCount()); drawRefs("Used by Geometry", obj, [&](const ramses::Geometry* ref) { auto& iScene = m_scene.impl().getIScene(); const auto& layout = iScene.getDataLayout(ref->impl().getAttributeDataLayout()); @@ -2132,14 +2141,19 @@ namespace ramses::internal } } - void SceneViewerGui::drawFile() + void SceneViewerGui::drawSaveFile() { - if (ImGui::CollapsingHeader("File")) + if (m_saveToFile) + ImGui::OpenPopup("Save scene to file"); + m_saveToFile = false; + + bool askOverwrite = false; + + if (ImGui::BeginPopupModal("Save scene to file", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::Checkbox("Compress scene file", &m_compressFile); ImGui::InputText("##filename", &m_filename); - ImGui::SameLine(); - if (ImGui::Button("Save")) + if (ImGui::Button("Save", ImVec2(120, 0))) { File file = File(m_filename); if (m_loadedSceneFile == m_filename) @@ -2148,48 +2162,49 @@ namespace ramses::internal } else if (file.exists() && !m_alwaysOverwrite) { - ImGui::OpenPopup("Overwrite?"); + askOverwrite = true; } else { saveSceneToFile(); + ImGui::CloseCurrentPopup(); } } - - if (ImGui::BeginPopupModal("Overwrite?", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) + ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); + if (ImGui::Button("Cancel", ImVec2(120, 0))) { - ImGui::Text("File exists:\n%s\nOverwrite?", m_filename.c_str()); - ImGui::Separator(); - - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - ImGui::Checkbox("Don't ask me next time", &m_alwaysOverwrite); - ImGui::PopStyleVar(); - - if (ImGui::Button("OK", ImVec2(120, 0))) - { - saveSceneToFile(); - ImGui::CloseCurrentPopup(); - } - ImGui::SetItemDefaultFocus(); - ImGui::SameLine(); - if (ImGui::Button("Cancel", ImVec2(120, 0))) - { - ImGui::CloseCurrentPopup(); - } - ImGui::EndPopup(); + ImGui::CloseCurrentPopup(); } + ImGui::EndPopup(); } - } - void SceneViewerGui::draw() - { - drawInspectionWindow(); + auto popupTitle = fmt::format("Overwrite {}?", fs::path(m_filename).filename().string()); - if (m_nodeVisibilityChanged) + if (askOverwrite) + ImGui::OpenPopup(popupTitle.c_str()); + + if (ImGui::BeginPopupModal(popupTitle.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - // refresh resource information in next interation - m_nodeVisibilityChanged = false; // TODO: won't work if node visibility changed by logic gui - m_resourceInfo->clear(); + ImGui::Text("File exists:\n%s\nOverwrite?", m_filename.c_str()); + ImGui::Separator(); + + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + ImGui::Checkbox("Don't ask me next time", &m_alwaysOverwrite); + ImGui::PopStyleVar(); + + if (ImGui::Button("OK", ImVec2(120, 0))) + { + saveSceneToFile(); + ImGui::CloseCurrentPopup(); + } + ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); + if (ImGui::Button("Cancel", ImVec2(120, 0))) + { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); } } @@ -2200,45 +2215,41 @@ namespace ramses::internal drawMenuItemExportShaderSources(); } - void SceneViewerGui::drawInspectionWindow() + void SceneViewerGui::handleShortcuts() { - if (m_settings.showSceneViewerWindow) + if (ImGui::IsKeyPressed(ramses::EKeyCode_S) && ImGui::GetIO().KeyCtrl) { - const auto featureLevel = m_scene.getRamsesClient().getRamsesFramework().getFeatureLevel(); - const std::string windowTitle = - m_scene.getName().empty() - ? fmt::format("Scene[{}] (FeatureLevel 0{})", m_scene.getSceneId().getValue(), featureLevel) - : fmt::format("Scene[{}]: {} (FeatureLevel 0{})", m_scene.getSceneId().getValue(), m_scene.getName(), featureLevel); + m_saveToFile = true; + } + } - if (!ImGui::Begin(windowTitle.c_str(), &m_settings.showSceneViewerWindow, ImGuiWindowFlags_MenuBar)) - { - ImGui::End(); - return; - } - drawMenuBar(); - drawFile(); - drawSceneObjects(); - drawNodeHierarchy(); - drawResources(); - drawRenderHierarchy(); - drawErrors(); - ImGui::End(); + void SceneViewerGui::drawContents() + { + drawSceneObjects(); + drawNodeHierarchy(); + drawResources(); + drawRenderHierarchy(); + drawErrors(); + + drawSaveFile(); + + if (m_nodeVisibilityChanged) + { + // refresh resource information in next interation + m_nodeVisibilityChanged = false; // TODO: won't work if node visibility changed by logic gui + m_resourceInfo->clear(); } } - void SceneViewerGui::drawMenuBar() + void SceneViewerGui::drawFileMenuItems() { - if (ImGui::BeginMenuBar()) + if (ImGui::MenuItem("Save", "Ctrl+S")) { - if (ImGui::BeginMenu("Tools")) - { - drawMenuItemCopyTexture2D(); - drawMenuItemStorePng(); - drawMenuItemExportShaderSources(); - ImGui::EndMenu(); - } - ImGui::EndMenuBar(); + m_saveToFile = true; } + drawMenuItemCopyTexture2D(); + drawMenuItemStorePng(); + drawMenuItemExportShaderSources(); } void SceneViewerGui::drawMenuItemCopyTexture2D() diff --git a/tools/ramses-viewer/SceneViewerGui.h b/tools/ramses-viewer/SceneViewerGui.h index 76cc65b93..6cb29e5c5 100644 --- a/tools/ramses-viewer/SceneViewerGui.h +++ b/tools/ramses-viewer/SceneViewerGui.h @@ -48,14 +48,17 @@ namespace ramses::internal struct MipMap; class ViewerGuiApp; + class LogicViewerGui; struct ViewerSettings; class SceneViewerGui { public: SceneViewerGui(ViewerGuiApp& app, ramses::Scene& scene, std::string& errorMessage, ProgressMonitor& progressMonitor); - void draw(); + void drawContents(); + void handleShortcuts(); + void drawFileMenuItems(); void drawGlobalContextMenuItems(); private: @@ -71,8 +74,6 @@ namespace ramses::internal [[nodiscard]] const ramses::internal::DataSlot* findDataSlot(ramses::internal::TextureSamplerHandle handle) const; [[nodiscard]] const ramses::internal::DataSlot* findDataSlot(ramses::internal::ResourceContentHash hash) const; - void drawInspectionWindow(); - void drawMenuBar(); void drawMenuItemCopyTexture2D(); void drawMenuItemStorePng(); void drawMenuItemExportShaderSources(); @@ -115,7 +116,7 @@ namespace ramses::internal static void DrawSceneReference(SceneReferenceImpl& obj); void drawDataSlot(const ramses::internal::DataSlot& obj); - void drawFile(); + void drawSaveFile(); void drawSceneObjects(); void drawSceneObjectsFilter(); void drawNodeHierarchy(); @@ -175,6 +176,8 @@ namespace ramses::internal bool m_alwaysOverwrite = false; bool m_nodeVisibilityChanged = false; + bool m_saveToFile = false; + ImguiImageCache m_imageCache; struct RefKey diff --git a/tools/ramses-viewer/ViewerGui.cpp b/tools/ramses-viewer/ViewerGui.cpp index cc7dce426..36aeb861a 100644 --- a/tools/ramses-viewer/ViewerGui.cpp +++ b/tools/ramses-viewer/ViewerGui.cpp @@ -44,14 +44,16 @@ namespace ramses::internal { if (ImGui::IsKeyPressed(ramses::EKeyCode_F11)) { - m_settings.showGui = !m_settings.showGui; + m_settings.showWindow = !m_settings.showWindow; } - if (ImGui::IsKeyPressed(ramses::EKeyCode_F10)) + if (ImGui::IsKeyPressed(ramses::EKeyCode_F10) && m_app.getLogicViewer()) { - m_settings.showSceneViewerWindow = !m_settings.showSceneViewerWindow; + m_settings.showLogicWindow = !m_settings.showLogicWindow; } + if (m_sceneGui) + m_sceneGui->handleShortcuts(); if (m_logicGui) m_logicGui->handleShortcuts(); @@ -75,14 +77,39 @@ namespace ramses::internal drawErrorPopup(); drawProgressPopup(); - if (m_settings.showGui) + if (m_settings.showWindow) + drawWindow(); + if (m_logicGui && m_settings.showLogicWindow) + m_logicGui->drawWindow(); + } + + void ViewerGui::drawWindow() + { + const auto featureLevel = m_app.getScene()->getRamsesClient().getRamsesFramework().getFeatureLevel(); + const std::string windowTitle = + m_app.getScene()->getName().empty() + ? fmt::format("Scene[{}] (FeatureLevel 0{})", m_app.getScene()->getSceneId().getValue(), featureLevel) + : fmt::format("Scene[{}]: {} (FeatureLevel 0{})", m_app.getScene()->getSceneId().getValue(), m_app.getScene()->getName(), featureLevel); + + if (!ImGui::Begin(windowTitle.c_str(), &m_settings.showWindow, ImGuiWindowFlags_MenuBar)) { - drawMenuBar(); - if (m_sceneGui) - m_sceneGui->draw(); - if (m_logicGui) - m_logicGui->draw(); + ImGui::End(); + return; } + + drawMenuBar(); + if (m_logicGui && !m_settings.showLogicWindow) + { + ImGui::SetNextItemOpen(true, ImGuiCond_Once); + bool showInline = true; + if (ImGui::CollapsingHeader("Logic", &showInline)) + m_logicGui->drawContents(); + m_settings.showLogicWindow = !showInline; + } + + if (m_sceneGui) + m_sceneGui->drawContents(); + ImGui::End(); } void ViewerGui::setSceneTexture(ramses::TextureSampler* sampler, uint32_t width, uint32_t height) @@ -94,26 +121,44 @@ namespace ramses::internal void ViewerGui::drawMenuBar() { - if (ImGui::BeginMainMenuBar()) + if (ImGui::BeginMenuBar()) { + if (ImGui::BeginMenu("File")) + { + if (m_sceneGui) + m_sceneGui->drawFileMenuItems(); + if (m_logicGui) + { + ImGui::Separator(); + m_logicGui->drawMenuItemReload(); + } + ImGui::EndMenu(); + } if (ImGui::BeginMenu("Settings")) { drawMenuItemShowWindow(); drawMenuItemDisplaySettings(); ImGui::EndMenu(); } - ImGui::EndMainMenuBar(); + ImGui::EndMenuBar(); } } void ViewerGui::drawMenuItemShowWindow() { - ImGui::MenuItem("Show Gui", "F11", &m_settings.showGui); - ImGui::MenuItem("Show Scene Inspection Window", "F10", &m_settings.showSceneViewerWindow, m_settings.showGui); - ImGui::MenuItem("Show Logic Window", nullptr, &m_settings.showLogicWindow, m_settings.showGui); + ImGui::MenuItem("Show Scene Window", "F11", &m_settings.showWindow); + if (m_app.getLogicViewer()) + ImGui::MenuItem("Show Logic Window", "F10", &m_settings.showLogicWindow); if (m_app.getGuiMode() == ViewerGuiApp::GuiMode::On) { - ImGui::MenuItem("Show Scene in Window", nullptr, &m_settings.showSceneInWindow, m_settings.showGui); + ImGui::MenuItem("Show Scene in Window", nullptr, &m_settings.showSceneInWindow); + } + if (m_app.getLogicViewer()) + { + if (ImGui::MenuItem("Show LogicEngine Update Report", nullptr, &m_settings.showUpdateReport)) + { + m_app.getLogicViewer()->enableUpdateReport(m_settings.showUpdateReport, m_settings.updateReportInterval); + } } } @@ -140,6 +185,10 @@ namespace ramses::internal m_renderer->setFramerateLimit(m_displayId, fps); m_renderer->flush(); } + + ImGui::Separator(); + ImGui::MenuItem("Lua: prefer identifiers (scripts.foo)", nullptr, &m_settings.luaPreferIdentifiers); + ImGui::MenuItem("Lua: prefer object ids (scripts[1])", nullptr, &m_settings.luaPreferObjectIds); } } diff --git a/tools/ramses-viewer/ViewerGui.h b/tools/ramses-viewer/ViewerGui.h index eeb4db8c2..a0ec61c63 100644 --- a/tools/ramses-viewer/ViewerGui.h +++ b/tools/ramses-viewer/ViewerGui.h @@ -35,6 +35,8 @@ namespace ramses::internal void openErrorPopup(const std::string& message); private: + void drawWindow(); + void drawMenuBar(); void drawMenuItemShowWindow(); void drawMenuItemDisplaySettings(); diff --git a/tools/ramses-viewer/ViewerSettings.cpp b/tools/ramses-viewer/ViewerSettings.cpp index 3e8f6eba8..04078780b 100644 --- a/tools/ramses-viewer/ViewerSettings.cpp +++ b/tools/ramses-viewer/ViewerSettings.cpp @@ -54,9 +54,9 @@ namespace ramses::internal { auto* gui = static_cast(handler->UserData); int flag = 0; - if (IniReadFlag(line, "ShowSceneViewerWindow=%d", &flag)) + if (IniReadFlag(line, "ShowWindow=%d", &flag)) { - gui->showSceneViewerWindow = (flag != 0); + gui->showWindow = (flag != 0); } else if (IniReadFlag(line, "ShowLogicWindow=%d", &flag)) { @@ -83,7 +83,7 @@ namespace ramses::internal // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) 3rd party interface buf->appendf("[%s][Settings]\n", handler->TypeName); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) 3rd party interface - buf->appendf("ShowSceneViewerWindow=%d\n", gui->showSceneViewerWindow ? 1 : 0); + buf->appendf("ShowWindow=%d\n", gui->showWindow ? 1 : 0); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) 3rd party interface buf->appendf("ShowLogicWindow=%d\n", gui->showLogicWindow ? 1 : 0); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) 3rd party interface diff --git a/tools/ramses-viewer/ViewerSettings.h b/tools/ramses-viewer/ViewerSettings.h index f1705018d..08120507f 100644 --- a/tools/ramses-viewer/ViewerSettings.h +++ b/tools/ramses-viewer/ViewerSettings.h @@ -19,22 +19,22 @@ namespace ramses::internal { struct ViewerSettings { - // scene viewer settings - bool showGui = true; + bool showWindow = true; - bool showSceneViewerWindow = true; - bool showSceneInWindow = false; + bool showSceneInWindow = false; // show the scene in an imgui window instead of background const std::array zoomLevels = {(1.f / 4.f), (1.f / 3.f), (1.f / 2.f), (2.f / 3.f), (3.f / 4.f), 1.f}; int zoomIx = 4; - // Logic viewer settings - bool showLogicWindow = true; + bool showLogicWindow = false; bool showUpdateReport = true; + bool showUpdateReportDetails = false; bool luaPreferObjectIds = false; bool luaPreferIdentifiers = false; + size_t updateReportInterval = 60u; + glm::vec4 clearColor{ 0, 0, 0, 1 }; ViewerSettings();