#include "ASW.h" #pragma comment( lib, "cg.lib" ) //////////////////////////////////////////////////////////////////////////////////// // ExceptionCG //////////////////////////////////////////////////////////////////////////////////// ASW::GraphicsApi::ExceptionCG:: ExceptionCG(const char * p_ptrFile, const unsigned int p_uintLine, const char * p_ptrFunction, const char * p_ptrDetail, const char * p_ptrError) : ASW::Exception(p_ptrFile, p_uintLine, p_ptrFunction, NULL), m_ptrError(( p_ptrError != NULL ) ? UTIL::Strdup(p_ptrError) : NULL) { m_ptrDetail = ( p_ptrDetail != NULL ) ? UTIL::Strdup(p_ptrDetail) : NULL; } ASW::GraphicsApi::ExceptionCG:: ~ExceptionCG() { delete [] m_ptrError; delete [] m_ptrDetail; } void ASW::GraphicsApi::ExceptionCG:: Print(UTIL::Output & p_clsOutput) { p_clsOutput.Printf("CG has generated an error.\n\nFile: [%s]\nLine: [%u]\nFunction: [%s]\nError: [%s]\nDetail: [%s]", ( m_ptrFile != NULL ) ? m_ptrFile : "unknown", m_uintLine, ( m_ptrFunction != NULL ) ? m_ptrFunction : "unknown", ( m_ptrError != NULL ) ? m_ptrError : "none", ( m_ptrDetail != NULL ) ? m_ptrDetail : "unknown"); } const char * ASW::GraphicsApi::ExceptionCG:: Type() { return "CG"; } //////////////////////////////////////////////////////////////////////////////////// // GraphicsApi //////////////////////////////////////////////////////////////////////////////////// ASW::GraphicsApi:: GraphicsApi() : m_uintMaxLights(0), m_uintMaxIndexValue(0), m_ptrActiveBufferVertex(NULL), m_ptrActiveBufferIndex(NULL), m_ptrActiveShaderPixel(NULL), m_ptrActiveShaderVertex(NULL), m_stuCgContext(NULL), m_enmCgProfilePixel(CG_PROFILE_UNKNOWN), m_enmCgProfileVertex(CG_PROFILE_UNKNOWN) {} void ASW::GraphicsApi:: Cleanup() { cgDestroyContext(m_stuCgContext); m_ptrActiveBufferVertex = NULL; m_ptrActiveBufferIndex = NULL; m_ptrActiveShaderVertex = NULL; m_ptrActiveShaderPixel = NULL; } void ASW::GraphicsApi:: EnableLight(const unsigned int p_uintIndexFirst, const unsigned int p_uintIndexLast, const bool p_blnEnable) { unsigned int uintIndexLast = ( p_uintIndexLast == ~0 ) ? m_uintMaxLights : p_uintIndexLast; for (unsigned int i=p_uintIndexFirst; i 0 && (int)(p_stuShader.m_enmType) < 3, "Invalid shader type"); CGprofile stuProfiles[] = {m_enmCgProfileVertex, m_enmCgProfilePixel}; p_stuShader.m_clsProgram = cgCreateProgramFromFile(m_stuCgContext, // Cg runtime context CG_SOURCE, // Program in human-readable form p_ptrFileName, // Name of file containing program stuProfiles[p_stuShader.m_enmType - 1], p_ptrEntryPoint, // Entry function name NULL); CGerror enmError; const char * ptrError = cgGetLastErrorString(&enmError); if ( enmError != CG_NO_ERROR ) { const char * ptrError = cgGetLastListing(m_stuCgContext); cgGetError(); return false; } p_stuShader.m_blnLoaded = true; return true; } void ASW::GraphicsApi:: Unload(ASW::Shader & p_stuShader) { ASW_ASSERT(p_stuShader.m_blnLoaded, "Shader is not loaded"); //p_stuShader.m_clsParametersUniform.clear(); memset(p_stuShader.m_ptrParametersVarying, 0, ASW::Type::ELEMENT_COUNT * sizeof(CGparameter)); cgDestroyProgram(p_stuShader.m_clsProgram); p_stuShader.m_blnLoaded = false; }