| | #include "shadeop.h"
#include <stdio.h>
/*
A simple DSO shadeops.
Notes that 'extern "C"' is not necessary for '.c' files.
Only c++ files need that.
*/
extern "C" {
SHADEOP_TABLE(sqr) =
{
{"float sqr(float)", "sqr_init", "sqr_cleanup"},
{"point sqr_p(point)", "sqr_init", "sqr_cleanup"},
{""}
};
}
extern "C" SHADEOP_INIT(sqr_init)
{
return 0x0; /* No init data */
}
/*
returns the given float, squared.
NOTES
- argv[0] contains a pointer to the result, in this case a float.
-
*/
extern "C" SHADEOP( sqr )
{
float *result = (float *)argv[0];
float f = *((float*)argv[1]);
*result = f * f;
return 0;
}
/*
returns the given point, squared.
*/
extern "C" SHADEOP(sqr_p)
{
float *result = (float *)argv[0];
float *f = ((float*)argv[1]);
result[0] = f[0] * f[0];
result[1] = f[1] * f[1];
result[2] = f[2] * f[2];
return 0;
}
extern "C" SHADEOP_CLEANUP( sqr_cleanup )
{
/* Nothing to do */
}
Here is how to compile a DSO under differnt environments:
- Linux
- g++ -shared -o sqr.dso $DELIGHT/include sqr.cpp
- IRIX
- CC -shared -o sqr.dso $
DELIGHT /include sqr.cpp
- Windows
- cl -I%DELIGHT%/include -LD sqr.cpp
To avoid memory leaks, use the macro ASSIGN_STRING (declared in `shadeop.h' code to copy strings. This macro will delete (if needed) the old string before assigning the new one. Here is an example that illustrates how to use the macro:
| SHADEOP_TABLE(test) =
{
{"string teststring(string)", "", ""},
{""}
};
extern "C" SHADEOP(teststring)
{
const char **res = (const char **)(argv[0]);
const char **arg1 = (const char **)(argv[1]);
ASSIGN_STRING(*res, "Hello");
ASSIGN_STRING(*arg1, "World");
}
|
This document was generated
by Aghiles Kheffache on July, 31 2003
using texi2html
3Delight 1.0.0. Copyright 2000-2003 The 3Delight Team.
All Rights Reserved.
|
|