|
| 1 | +/*****************************************************************************\ |
| 2 | +* |
| 3 | +* Module Name Parameter Enumeration Demo |
| 4 | +* Project Radeon ProRender rendering tutorial |
| 5 | +* |
| 6 | +* Description Radeon ProRender SDK tutorials |
| 7 | +* |
| 8 | +* Copyright(C) 2011-2021 Advanced Micro Devices, Inc. All rights reserved. |
| 9 | +* |
| 10 | +\*****************************************************************************/ |
| 11 | + |
| 12 | +#include "RadeonProRender.h" |
| 13 | + |
| 14 | +#include "../common/common.h" |
| 15 | +#include <iostream> |
| 16 | +#include <vector> |
| 17 | +#include <string> |
| 18 | +#include "../rprTools/RPRStringIDMapper.h" |
| 19 | + |
| 20 | +// |
| 21 | +// This tutorials illustrates how to use getters of the RPR API to get current states/values of different objects. |
| 22 | +// |
| 23 | + |
| 24 | + |
| 25 | +int main() |
| 26 | +{ |
| 27 | + std::cout << "Radeon ProRender SDK parameters enumeration tutorial.\n"; |
| 28 | + |
| 29 | + // Create the RPR context |
| 30 | + rpr_context context = nullptr; |
| 31 | + rpr_int tahoePluginID = rprRegisterPlugin(RPR_PLUGIN_FILE_NAME); |
| 32 | + CHECK_NE(tahoePluginID , -1); |
| 33 | + rpr_int plugins[] = { tahoePluginID }; |
| 34 | + size_t pluginCount = sizeof(plugins) / sizeof(plugins[0]); |
| 35 | + CHECK( rprCreateContext(RPR_API_VERSION, plugins, pluginCount, RPR_CREATION_FLAGS_ENABLE_GPU0, NULL, NULL, &context) ); |
| 36 | + CHECK( rprContextSetActivePlugin(context, plugins[0]) ); |
| 37 | + std::cout << "Context successfully created.\n"; |
| 38 | + |
| 39 | + // class defined in rprTools/RPRStringIDMapper.h . |
| 40 | + // this class helps to turn parameters id into strings. |
| 41 | + RPRStringIDMapper stringMapper; |
| 42 | + |
| 43 | + |
| 44 | + // |
| 45 | + // List parameters from rpr_context |
| 46 | + // |
| 47 | + { |
| 48 | + std::cout<<std::endl<<"=== CONTEXT PARAMETERS ==="<<std::endl; |
| 49 | + |
| 50 | + uint64_t param_count = 0; |
| 51 | + CHECK( rprContextGetInfo(context, RPR_CONTEXT_PARAMETER_COUNT, sizeof(uint64_t), ¶m_count, NULL) ); |
| 52 | + |
| 53 | + std::cout<<param_count<<" parameters :"<<std::endl; |
| 54 | + |
| 55 | + for (uint64_t i = 0; i < param_count; i++) |
| 56 | + { |
| 57 | + rpr_context_info paramID = (rpr_context_info)0; |
| 58 | + CHECK( rprContextGetParameterInfo(context, int(i), RPR_PARAMETER_NAME, sizeof(paramID), ¶mID, NULL) ); |
| 59 | + |
| 60 | + std::string paramName_; |
| 61 | + stringMapper.RPRContextInput_id_to_string(paramID, paramName_); |
| 62 | + |
| 63 | + rpr_parameter_type type; |
| 64 | + CHECK( rprContextGetParameterInfo(context, int(i), RPR_PARAMETER_TYPE, sizeof(type), &type, NULL)); |
| 65 | + |
| 66 | + uint64_t value_length = 0; |
| 67 | + CHECK( rprContextGetParameterInfo(context, int(i), RPR_PARAMETER_VALUE, 0, NULL, &value_length) ); |
| 68 | + char* paramValue = nullptr; |
| 69 | + if (value_length > 0) |
| 70 | + { |
| 71 | + paramValue = new char[value_length]; |
| 72 | + CHECK( rprContextGetParameterInfo(context, int(i), RPR_PARAMETER_VALUE, value_length, paramValue, NULL) ); |
| 73 | + } |
| 74 | + |
| 75 | + std::cout<<paramName_<<" = "; |
| 76 | + |
| 77 | + if ( type == RPR_PARAMETER_TYPE_STRING ) |
| 78 | + { |
| 79 | + std::cout<<"\""<<std::string(paramValue)<<"\""; |
| 80 | + } |
| 81 | + else if ( type == RPR_PARAMETER_TYPE_FLOAT ) |
| 82 | + { |
| 83 | + float f = *(float*)(paramValue); |
| 84 | + std::cout<<f; |
| 85 | + } |
| 86 | + else if ( type == RPR_PARAMETER_TYPE_FLOAT2 ) |
| 87 | + { |
| 88 | + float* f = (float*)(paramValue); |
| 89 | + std::cout<<f[0]<<" , "<<f[1]; |
| 90 | + } |
| 91 | + else if ( type == RPR_PARAMETER_TYPE_FLOAT3 ) |
| 92 | + { |
| 93 | + float* f = (float*)(paramValue); |
| 94 | + std::cout<<f[0]<<" , "<<f[1]<<" , "<<f[2]; |
| 95 | + } |
| 96 | + else if ( type == RPR_PARAMETER_TYPE_FLOAT4 ) |
| 97 | + { |
| 98 | + float* f = (float*)(paramValue); |
| 99 | + std::cout<<f[0]<<" , "<<f[1]<<" , "<<f[2]<<" , "<<f[3]; |
| 100 | + } |
| 101 | + else if ( type == RPR_PARAMETER_TYPE_UINT ) |
| 102 | + { |
| 103 | + rpr_uint v = *(rpr_uint*)(paramValue); |
| 104 | + std::cout<<v; |
| 105 | + } |
| 106 | + else if ( type == RPR_PARAMETER_TYPE_ULONG ) |
| 107 | + { |
| 108 | + rpr_ulong v = *(rpr_ulong*)(paramValue); |
| 109 | + std::cout<<v; |
| 110 | + } |
| 111 | + else if ( type == RPR_PARAMETER_TYPE_LONGLONG ) |
| 112 | + { |
| 113 | + rpr_longlong v = *(rpr_longlong*)(paramValue); |
| 114 | + std::cout<<v; |
| 115 | + } |
| 116 | + else |
| 117 | + { |
| 118 | + std::cout<<"???"; |
| 119 | + } |
| 120 | + |
| 121 | + if ( paramValue ) { delete[] paramValue; paramValue = NULL; } |
| 122 | + |
| 123 | + std::cout<<std::endl; |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | + // create the material system |
| 129 | + rpr_material_system matsys = nullptr; |
| 130 | + CHECK( rprContextCreateMaterialSystem(context, 0, &matsys) ); |
| 131 | + |
| 132 | + // Create a MICROFACET material |
| 133 | + rpr_material_node microfacet; |
| 134 | + CHECK( rprMaterialSystemCreateNode(matsys, RPR_MATERIAL_NODE_MICROFACET, µfacet) ); |
| 135 | + |
| 136 | + // |
| 137 | + // List parameters from rpr_material |
| 138 | + // |
| 139 | + { |
| 140 | + std::cout<<std::endl<<"=== MATERIAL PARAMETERS ==="<<std::endl; |
| 141 | + |
| 142 | + // Get the number of parameters for the material |
| 143 | + size_t num_params = 0; |
| 144 | + CHECK( rprMaterialNodeGetInfo(microfacet, RPR_MATERIAL_NODE_INPUT_COUNT, sizeof(size_t), &num_params , NULL)); |
| 145 | + |
| 146 | + std::cout << "Number of MICROFACET material parameters: " << num_params <<"\n"; |
| 147 | + |
| 148 | + // get the material type. |
| 149 | + rpr_material_node_type nodeType = (rpr_material_node_type)0; |
| 150 | + CHECK( rprMaterialNodeGetInfo(microfacet,RPR_MATERIAL_NODE_TYPE, sizeof(nodeType),&nodeType,NULL)); |
| 151 | + // in this example, we have nodeType = RPR_MATERIAL_NODE_MICROFACET |
| 152 | + |
| 153 | + // For each parameter |
| 154 | + for (size_t i = 0; i < num_params; ++i) |
| 155 | + { |
| 156 | + |
| 157 | + rpr_material_node_input paramNameID = (rpr_material_node_input)0; |
| 158 | + CHECK( rprMaterialNodeGetInputInfo(microfacet, i, RPR_MATERIAL_NODE_INPUT_NAME, sizeof(paramNameID), ¶mNameID, NULL)); |
| 159 | + |
| 160 | + std::string paramName_; |
| 161 | + stringMapper.RPRMaterialInput_id_to_string(paramNameID, paramName_); |
| 162 | + |
| 163 | + std::cout<<paramName_<<" = "; |
| 164 | + |
| 165 | + rpr_uint nodeInputType = 0; |
| 166 | + CHECK( rprMaterialNodeGetInputInfo(microfacet, i, RPR_MATERIAL_NODE_INPUT_TYPE, sizeof(nodeInputType), &nodeInputType, NULL) ); |
| 167 | + |
| 168 | + uint64_t inputValueSizeB = 0; |
| 169 | + CHECK( rprMaterialNodeGetInputInfo(microfacet, i, RPR_MATERIAL_NODE_INPUT_VALUE, 0, NULL, &inputValueSizeB)); |
| 170 | + char* materialParameterValue = new char[inputValueSizeB]; |
| 171 | + CHECK( rprMaterialNodeGetInputInfo(microfacet, i, RPR_MATERIAL_NODE_INPUT_VALUE, inputValueSizeB, materialParameterValue, NULL)); |
| 172 | + |
| 173 | + if ( nodeInputType == RPR_MATERIAL_NODE_INPUT_TYPE_NODE ) |
| 174 | + { |
| 175 | + rpr_material_node* mat = (rpr_material_node*)materialParameterValue; |
| 176 | + if ( *mat ) |
| 177 | + { |
| 178 | + std::cout<<"material:"<<(void*)(*mat); |
| 179 | + } |
| 180 | + else |
| 181 | + { |
| 182 | + std::cout<<"null-material"; |
| 183 | + } |
| 184 | + } |
| 185 | + else if ( nodeInputType == RPR_MATERIAL_NODE_INPUT_TYPE_FLOAT4 ) |
| 186 | + { |
| 187 | + float* f = (float*)(materialParameterValue); |
| 188 | + std::cout<<f[0]<<" , "<<f[1]<<" , "<<f[2]<<" , "<<f[3]; |
| 189 | + } |
| 190 | + else |
| 191 | + { |
| 192 | + std::cout<<"???"; |
| 193 | + } |
| 194 | + |
| 195 | + if ( materialParameterValue ) { delete[] materialParameterValue; materialParameterValue = NULL; } |
| 196 | + |
| 197 | + std::cout<<std::endl; |
| 198 | + |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + CHECK(rprObjectDelete(matsys)); matsys=nullptr; |
| 203 | + CHECK(rprObjectDelete(microfacet)); microfacet=nullptr; |
| 204 | + CheckNoLeak(context); |
| 205 | + CHECK(rprObjectDelete(context)); context=nullptr; |
| 206 | + return 0; |
| 207 | +} |
0 commit comments