I've been working on a path tracer project for the few days, and since I ultimately want it to run on the GPU using OpenCL, I wrote most of it in C. Earlier today I decided to move it entirely to C, just to be sure that the code I write will require minimum effort to port to OpenCL, and in doing so, the only part of the path tracer code I even touched was the random generator, going from this:
1 2 3 4 5 6 7
typedefstruct _mt_state {
staticunsignedlong mt[N]; /* the array for the state vector */
staticint mti;
} mt_state;
unsignedlong _mt_state::mt[N];
int _mt_state::mti;
to this
1 2 3 4
typedefstruct _mt_state {
unsignedlong mt[N]; /* the array for the state vector */
int mti;
} mt_state;
After that I compiled with a C compiler without problems, but when I run my path tracer now, it is radically slower than it was with the C++ version. I know this isn't much info to go on, but does anyone know why this would happen? Again, the path tracer code has remained untouched except for the above adjustments.
I wanted to do it so that when I move my rendering code over to an OpenCL kernel its all C. OpenCL still doesn't have native support for C++. I thought about the change of the static variables, but I only have one struct, passing pointers to it to other functions. Its not being passed by value anywhere, so there shouldn't be any copies of it, right?
EDIT: You were right, I had overlooked a couple of crucial functions to which the struct was being passed by value! It's all working like it did before now, cheers :)