Skip to content

[RPR-0] Example 65, rpr gltf export example. #42

New issue

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

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

Already on GitHub? Sign in to your account

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions tutorials/65_mesh_convert/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <cassert>
#include <iostream>


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;
}

23 changes: 23 additions & 0 deletions tutorials/65_mesh_convert/premake4.lua
Original file line number Diff line number Diff line change
@@ -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 {}

1 change: 1 addition & 0 deletions tutorials/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down