/*-
 * Copyright (c) 1999,2000 Qube Software, Ltd.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of the source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 
 * 2. Any redistribution solely in binary form must conspicuously
 *    reproduce the following disclaimer in documentation provided with the
 *    binary redistribution.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'', WITHOUT ANY WARRANTIES, EXPRESS
 * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  LICENSOR SHALL
 * NOT BE LIABLE FOR ANY LOSS OR DAMAGES RESULTING FROM THE USE OF THIS
 * SOFTWARE, EITHER ALONE OR IN COMBINATION WITH ANY OTHER SOFTWARE.
 * 
 * 	$Id: varray.cpp,v 1.15 2000/05/26 11:05:29 dfr Exp $
 */

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include "maths.h"
#include "draw.h"
#include "event.h"
#include "utilsout.h"

using namespace std;
using namespace Draw;
using namespace Utils;
using namespace Maths;

static float
randomFloat()
{
	unsigned int fraction;
	int exp;
	
	fraction = (long)rand() & ((1 << 23) - 1);
	exp = rand() & 7;	// modest range of exponents

	return ldexpf(fraction / (float)(1 << 23), exp - 4);
}

static Vec3f
randomVec()
{
    return Vec3f(randomFloat(), randomFloat(), randomFloat());
}

static void performTest()
{
    try {
	Factory* f = Factory::create();
	VertexArray* va = f->createVertexArray(FVF::Coord, 0);

	//srandom(time(0) + getpid());
	srand(0);
	for (unsigned int i = 0; i < 1000000; i++) {
	    Vec3f t = randomVec();
	    va->add(&t);
	}

	delete f;
    }
    catch (const Problem& p) {
        cout << "Error: " << p << endl;
    }
}

int
main(int argc, char** argv)
{

    performTest();
    return 0;
}

#ifdef STATIC

/* Make sure the drivers we want are linked in. */

#ifdef q_windows
extern int QDriver_OS_Win32;
int* osref = &QDriver_OS_Win32;

extern int QDriver_Input_Win32;
int* inpref = &QDriver_Input_Win32;

extern int QDriver_Display_DX7;
int* displayref = &QDriver_Display_DX7;
#else    
extern int QDriver_OS_X11;
int* osref = &QDriver_OS_X11;

extern int QDriver_Display_OpenGL;
int* displayref = &QDriver_Display_OpenGL;
#endif

#endif // STATIC
