This example uses function calls to create a textured material.
#include <iostream>
#include <string>
#include "example_shared.h"
template <class T>
void dump_instance(
{
mi::Size count = material->get_parameter_count();
for(
mi::Size index = 0; index < count; index++) {
arguments->get_expression( index));
std::string name = material->get_parameter_name( index);
expression_factory->
dump( argument.get(), name.c_str(), 1));
s << " argument " << argument_text->get_c_str() << std::endl;
}
s << std::endl;
}
{
mdl_factory->create_value_factory( transaction.get()));
mdl_factory->create_expression_factory( transaction.get()));
mdl_factory->create_execution_context());
{
check_success( image->reset_file( "nvidia/sdk_examples/resources/example.png") == 0);
transaction->store( image.get(), "nvidia_image");
texture->set_image( "nvidia_image");
texture->set_gamma( 2.2f);
transaction->store( texture.get(), "nvidia_texture");
}
{
check_success( mdl_impexp_api->load_module(
transaction.get(), "::nvidia::sdk_examples::tutorials", context.get()) >= 0);
check_success( print_messages( context.get()));
check_success( mdl_impexp_api->load_module(
transaction.get(), "::base", context.get()) >= 0);
check_success( print_messages( context.get()));
}
{
module->get_function_overloads( "mdl::base::file_texture"));
check_success( overloads->get_length() == 1);
file_texture_name->get_c_str()));
function_definition->get_parameter_types());
check_success( arg_type.is_valid_interface());
check_success( arg_value.is_valid_interface());
check_success( arg_value->set_value( "nvidia_texture") == 0);
arguments->add_expression( "texture", arg_expr.get());
function_definition->create_function_call( arguments.get(), &result));
check_success( result == 0);
transaction->store( function_call.get(), "call of file_texture");
}
{
expression_factory->
create_call(
"call of file_texture"));
check_success( arg_expr.is_valid_interface());
arguments->add_expression( "s", arg_expr.get());
"mdl::base::texture_return.tint(::base::texture_return)"));
function_definition->create_function_call( arguments.get(), &result));
check_success( result == 0);
transaction->store( function_call.get(), "call of texture_return.tint");
}
{
expression_factory->
create_call(
"call of texture_return.tint"));
check_success( arg_expr.is_valid_interface());
arguments->add_expression( "tint", arg_expr.get());
"mdl::nvidia::sdk_examples::tutorials::example_material(color,float)"));
material_definition->create_function_call( arguments.get(), &result));
check_success( result == 0);
transaction->store( material_instance.get(), "instance of example_material");
}
{
"instance of example_material"));
std::cout << "Dumping material instance \"instance of example_material\":" << std::endl;
dump_instance( expression_factory.get(), material_instance.get(), std::cout);
"call of texture_return.tint"));
std::cout << "Dumping function call \"call of texture_return.tint\":" << std::endl;
dump_instance( expression_factory.get(), function_call.get(), std::cout);
"call of file_texture");
std::cout << "Dumping function call \"call of file_texture\":" << std::endl;
dump_instance( expression_factory.get(), function_call.get(), std::cout);
}
transaction->commit();
}
int MAIN_UTF8( int argc, char* argv[])
{
if (!neuray.is_valid_interface())
exit_failure("Failed to load the SDK.");
if (!mi::examples::mdl::configure(neuray.get()))
exit_failure("Failed to initialize the SDK.");
if (ret != 0)
exit_failure("Failed to initialize the SDK. Result code: %d", ret);
create_textured_material( neuray.get());
exit_failure("Failed to shutdown the SDK.");
neuray = nullptr;
if (!mi::examples::mdl::unload())
exit_failure("Failed to unload the SDK.");
exit_success();
}
COMMANDLINE_TO_UTF8
A simple string class.
Definition: istring.h:22
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
This interface is used to interact with the distributed database.
Definition: idatabase.h:289
The interface for creating expressions.
Definition: iexpression.h:650
virtual const IString * dump(const IExpression *expr, const char *name, Size depth=0) const =0
Returns a textual representation of an expression.
virtual IExpression_call * create_call(const char *name) const =0
Creates a call.
virtual IExpression_list * create_expression_list() const =0
Creates a new expression list.
virtual IExpression_constant * create_constant(IValue *value) const =0
Creates a constant (mutable).
This interface represents a function call.
Definition: ifunction_call.h:52
This interface represents a function definition.
Definition: ifunction_definition.h:44
This interface represents a pixel image file.
Definition: iimage.h:66
Factory for various MDL interfaces and functions.
Definition: imdl_factory.h:53
API component for MDL related import and export operations.
Definition: imdl_impexp_api.h:43
This interface represents an MDL module.
Definition: imodule.h:634
This is an object representing the MDL SDK library.
Definition: ineuray.h:44
virtual Sint32 shutdown(bool blocking=true)=0
Shuts down the library.
virtual base::IInterface * get_api_component(const base::Uuid &uuid) const =0
Returns an API component from the MDL SDK API.
virtual Sint32 start(bool blocking=true)=0
Starts the operation of the MDL SDK library.
Textures add image processing options to images.
Definition: itexture.h:68
A texture value.
Definition: ivalue.h:525
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
signed int Sint32
32-bit signed integer.
Definition: types.h:46