From 6d6a59046410cabcfc52f4661dcfd07e3663e04b Mon Sep 17 00:00:00 2001 From: takahiroharada Date: Mon, 13 Dec 2021 14:53:43 -0800 Subject: [PATCH] [RPR-0] Example 65, rpr gltf export example. --- tutorials/65_mesh_convert/main.cpp | 107 +++++++++++++++++++++++++ tutorials/65_mesh_convert/premake4.lua | 23 ++++++ tutorials/premake5.lua | 1 + 3 files changed, 131 insertions(+) create mode 100644 tutorials/65_mesh_convert/main.cpp create mode 100644 tutorials/65_mesh_convert/premake4.lua diff --git a/tutorials/65_mesh_convert/main.cpp b/tutorials/65_mesh_convert/main.cpp new file mode 100644 index 00000000..7dbba740 --- /dev/null +++ b/tutorials/65_mesh_convert/main.cpp @@ -0,0 +1,107 @@ +/*****************************************************************************\ +* +* Module Name simple_render.cpp +* Project Radeon ProRender rendering tutorial +* +* Description Radeon ProRender SDK tutorials +* +* Copyright(C) 2011-2021 Advanced Micro Devices, Inc. All rights reserved. +* +\*****************************************************************************/ + + +// +// Shows how to import an RPR scene as RPRS files ( native RPR file format ) or GLTF ( Khronos Group ). +// It's advised to execute the demo "60_mesh_export" first in order to create the files used in this "61_mesh_import" Demo. +// + + + +#include "RadeonProRender.h" +#include "Math/mathutils.h" +#include "RprLoadStore.h" //For Import RPRS files ( native RPR file format ) +#include "ProRenderGLTF.h" //For Import from GLTF +#include "../common/common.h" + +#include +#include + + +int main(int argc, char *argv[]) +{ + if( argc < 3 ) + return 0; + const std::string src = argv[1]; + const std::string dst = argv[2]; + + // enable Radeon ProRender API trace + // set this before any RPR API calls + // rprContextSetParameterByKey1u(0,RPR_CONTEXT_TRACING_ENABLED,1); + + std::cout << "-- Radeon ProRender SDK Demo --" << std::endl; + + // the RPR context object. + rpr_context context = nullptr; + + // Register the RPR DLL + rpr_int tahoePluginID = rprRegisterPlugin(RPR_PLUGIN_FILE_NAME); + CHECK_NE(tahoePluginID , -1); + rpr_int plugins[] = { tahoePluginID }; + size_t pluginCount = sizeof(plugins) / sizeof(plugins[0]); + + // Create context using a single GPU + // note that multiple GPUs can be enabled for example with creation_flags = RPR_CREATION_FLAGS_ENABLE_GPU0 | RPR_CREATION_FLAGS_ENABLE_GPU1 + CHECK( rprCreateContext(RPR_API_VERSION, plugins, pluginCount, g_ContextCreationFlags, NULL, NULL, &context) ); + + // Set the active plugin. + CHECK( rprContextSetActivePlugin(context, plugins[0]) ); + + std::cout << "RPR Context creation succeeded." << std::endl; + + // create material system + rpr_material_system matsys = nullptr; + CHECK(rprContextCreateMaterialSystem(context, 0, &matsys)); + + // Create framebuffer + rpr_framebuffer_desc desc = { 800,600 }; + rpr_framebuffer_format fmt = { 4, RPR_COMPONENT_TYPE_FLOAT32 }; + rpr_framebuffer frame_buffer = nullptr; + rpr_framebuffer frame_buffer_resolved = nullptr; + CHECK(rprContextCreateFrameBuffer(context, fmt, &desc, &frame_buffer)); + CHECK( rprContextCreateFrameBuffer(context, fmt, &desc, &frame_buffer_resolved) ); + + + // Set framebuffer for the context + CHECK(rprContextSetAOV(context, RPR_AOV_COLOR, frame_buffer)); + + + ///////// RPRS file Import ( native RPR file format ) ////////// + + // Create a scene for the RPRS import + rpr_scene scene_rprs = nullptr; + CHECK(rprContextCreateScene(context, &scene_rprs)); + CHECK(rprContextSetScene(context, scene_rprs)); + + std::cout << "Converting from " << src << std::endl; + std::cout << " to " << dst << std::endl; + // make sure to execute the demo "60_mesh_export" in order to create the cube_floor.rprs file first. + CHECK(rprsImport(src.c_str(), context, matsys, &scene_rprs, true, nullptr)); + + ///////// GLTF Export ////////// + CHECK(rprExportToGLTF(dst.c_str(), context, nullptr, &scene_rprs, 1, 0, nullptr)); + + // delete the RPR objects created during the last rprsImport call. + CHECK(rprsDeleteListImportedObjects(nullptr)); + + // delete the scene + CHECK(rprObjectDelete(scene_rprs));scene_rprs=nullptr; + + // Release the stuff we created + CHECK(rprObjectDelete(matsys));matsys=nullptr; + CHECK(rprObjectDelete(frame_buffer));frame_buffer=nullptr; + CHECK(rprObjectDelete(frame_buffer_resolved));frame_buffer_resolved=nullptr; + CheckNoLeak(context); + CHECK(rprObjectDelete(context));context=nullptr; // Always delete the RPR Context in last. + return 0; +} + diff --git a/tutorials/65_mesh_convert/premake4.lua b/tutorials/65_mesh_convert/premake4.lua new file mode 100644 index 00000000..852816d7 --- /dev/null +++ b/tutorials/65_mesh_convert/premake4.lua @@ -0,0 +1,23 @@ +project "65_mesh_convert" + kind "ConsoleApp" + location "../build" + files { "../65_mesh_convert/**.h", "../65_mesh_convert/**.cpp"} + files { "../common/common.cpp","../common/common.h"} + + -- remove filters for Visual Studio + vpaths { [""] = { "../65_mesh_convert/**.h", "../65_mesh_convert/**.cpp","../common/common.cpp","../common/common.h"} } + + + includedirs{ "../../RadeonProRender/inc" } + + buildoptions "-std=c++11" + + configuration {"x64"} + links {"RadeonProRender64", "RprLoadStore64", "ProRenderGLTF"} + + configuration {"x64", "Debug"} + targetdir "../Bin" + configuration {"x64", "Release"} + targetdir "../Bin" + configuration {} + diff --git a/tutorials/premake5.lua b/tutorials/premake5.lua index 7a52557e..8b99b4ed 100644 --- a/tutorials/premake5.lua +++ b/tutorials/premake5.lua @@ -96,6 +96,7 @@ solution "Tutorials" include "61_mesh_import" include "63_hybrid" include "64_mesh_obj_demo" + include "65_mesh_convert" if fileExists("./MultiTutorials/MultiTutorials.lua") then dofile("./MultiTutorials/MultiTutorials.lua")