#include "FrameRender.h"
#include <string.h>

void RenderFrame(RGBImage buffer, const PixelCallback** callbacks, usize sizeCallbacks) {
	struct PixelContext pc;
	for (u32 x = 0; x < buffer.width; ++x) {
		for (u32 y = 0; y < buffer.height; ++y) {
			pc.x = x;
			pc.y = y;
			pc.pixel.a = pc.pixel.r = pc.pixel.g = pc.pixel.b = 0;

			for (usize i = 0; i < sizeCallbacks; ++i) {
				// Soft context reset
				if (callbacks[i] == NULL) {
					pc.x = x;
					pc.y = y;
				}
				else
					callbacks[i]->callback(callbacks[i]->callback_self, &pc);
			}

			memcpy(RGBImage_at(buffer, y, x), &pc.pixel, sizeof(pc.pixel));
		}
	}
}
