//////////////////////////////////////////////////////////////////////
//
//                             Pixie
//
// Copyright © 1999 - 2003, Okan Arikan
//
// Contact: okan@cs.berkeley.edu
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//
//  File				:	sdrinfo.cpp
//  Classes				:	-
//  Description			:	sdr info probram
//
////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#ifndef		__INTEL_COMPILER
#ifdef		WIN32
#ifdef		_DEBUG
#include <crtdbg.h>
#endif
#endif
#endif


#include "common/global.h"
#include "common/os.h"

#include "sdr/sdr.h"

///////////////////////////////////////////////////////////////////////
// Function				:	main
// Description			:	The god
// Return Value			:	-
// Comments				:
// Date last edited		:	12/01/2001
int main(int argc, char* argv[]) {
	// Init the memory manager
	memoryManagerInit();

	if (argc > 1) {
		TSdrShader		*cShader	=	sdrGet(argv[1],osEnvironment("SHADERS"));
		TSdrParameter	*cParameter;

		if (cShader == NULL) {
			fprintf(stderr,"Unable to find shader \"%s\"\n",argv[1]);
			exit(1);
		}

		switch(cShader->type) {
		case SHADER_SURFACE:
			fprintf(stdout,"surface ");
			break;
		case SHADER_DISPLACEMENT:
			fprintf(stdout,"displacement ");
			break;
		case SHADER_VOLUME:
			fprintf(stdout,"volume ");
			break;
		case SHADER_LIGHT:
			fprintf(stdout,"light ");
			break;
		case SHADER_IMAGER:
			fprintf(stdout,"imager ");
			break;
		}

		fprintf(stdout,"\"%s\"\n",cShader->name);

		for (cParameter=cShader->parameters;cParameter!=NULL;cParameter=cParameter->next) {
			fprintf(stdout,"\t\"%s\" ",cParameter->name);

			fprintf(stdout,"\"");
			switch(cParameter->container) {
			case CONTAINER_CONSTANT:
				fprintf(stdout,"constant ");
				break;
			case CONTAINER_UNIFORM:
				fprintf(stdout,"uniform ");
				break;
			case CONTAINER_VARYING:
				fprintf(stdout,"varying ");
				break;
			case CONTAINER_VERTEX:
				fprintf(stdout,"vertex ");
				break;
			}

			switch(cParameter->type) {
			case TYPE_FLOAT:
				fprintf(stdout,"float");
				break;
			case TYPE_VECTOR:
				fprintf(stdout,"vector");
				break;
			case TYPE_NORMAL:
				fprintf(stdout,"normal");
				break;
			case TYPE_POINT:
				fprintf(stdout,"point");
				break;
			case TYPE_COLOR:
				fprintf(stdout,"color");
				break;
			case TYPE_MATRIX:
				fprintf(stdout,"matrix");
				break;
			case TYPE_STRING:
				fprintf(stdout,"string");
				break;
			}

			if (cParameter->numItems > 1) {
				fprintf(stdout,"[%d]",cParameter->numItems);
			}

			fprintf(stdout,"\"\n");

			fprintf(stdout,"\t\tDefault value: ");

			if (cParameter->numItems > 1) {
				fprintf(stdout,"0\n");
			} else {
				switch(cParameter->type) {
				case TYPE_FLOAT:
					fprintf(stdout,"%g\n",cParameter->defaultValue.scalar);
					break;
				case TYPE_VECTOR:
				case TYPE_NORMAL:
				case TYPE_POINT:
				case TYPE_COLOR:
					if (cParameter->space != NULL) {
						fprintf(stdout,"\"%s\" ",cParameter->space);
					}

					if (cParameter->defaultValue.vector != NULL) {
						fprintf(stdout,"[%g %g %g]\n",cParameter->defaultValue.vector[0],cParameter->defaultValue.vector[1],cParameter->defaultValue.vector[2]);
					} else {
						fprintf(stdout,"[0 0 0]\n");
					}
					break;
				case TYPE_MATRIX:
					if (cParameter->defaultValue.matrix != NULL) {
						fprintf(stdout,"[%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g]\n"
							,cParameter->defaultValue.matrix[0]
							,cParameter->defaultValue.matrix[1]
							,cParameter->defaultValue.matrix[2]
							,cParameter->defaultValue.matrix[3]
							,cParameter->defaultValue.matrix[4]
							,cParameter->defaultValue.matrix[5]
							,cParameter->defaultValue.matrix[6]
							,cParameter->defaultValue.matrix[7]
							,cParameter->defaultValue.matrix[8]
							,cParameter->defaultValue.matrix[9]
							,cParameter->defaultValue.matrix[10]
							,cParameter->defaultValue.matrix[11]
							,cParameter->defaultValue.matrix[12]
							,cParameter->defaultValue.matrix[13]
							,cParameter->defaultValue.matrix[14]
							,cParameter->defaultValue.matrix[15]);
					} else {
						fprintf(stdout,"[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n");
					}
					break;
				case TYPE_STRING:
					if (cParameter->defaultValue.string != NULL) {
						fprintf(stdout,"\"%s\"\n",cParameter->defaultValue.string);
					} else {
						fprintf(stdout,"NULL");
					}
					break;
				}
			}

		}

		sdrDelete(cShader);
	}

	// Shutdown the memory manager
	memoryManagerTini();

	return 0;
}

