Go to the documentation of this file.00001 #ifndef OPENTISSUE_GPU_CG_UTIL_H
00002 #define OPENTISSUE_GPU_CG_UTIL_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/gl/gl_util.h>
00013
00014
00015 #ifdef WIN32
00016 # define WIN32_LEAN_AND_MEAN
00017 # define NOMINMAX
00018 #endif
00019 #include <Cg/cg.h>
00020 #include <Cg/cgGL.h>
00021 #ifdef WIN32
00022 # undef WIN32_LEAN_AND_MEAN
00023 # undef NOMINMAX
00024 #endif
00025
00026 #include <iostream>
00027 #include <cassert>
00028
00029 namespace OpenTissue
00030 {
00031 namespace cg
00032 {
00033
00037 inline static void cg_error_callback_func()
00038 {
00039 const char * errorString = cgGetErrorString( cgGetError() );
00040 std::cout << "Cg Runtime Error encountered" << std::endl;
00041 std::cout << "\t" << errorString << std::endl;
00042 }
00043
00044 class Program;
00045
00046
00050 inline static CGcontext & context()
00051 {
00052 static CGcontext context = 0;
00053 return context;
00054 }
00055
00059 inline static CGprofile & vertex_profile()
00060 {
00061 static CGprofile vertex_profile;
00062 return vertex_profile;
00063 }
00064
00068 inline static CGprofile & fragment_profile()
00069 {
00070 static CGprofile fragment_profile;
00071 return fragment_profile;
00072 }
00073
00077 inline static Program * & vertex_program()
00078 {
00079 static Program * v_program = 0;
00080 return v_program;
00081 }
00082
00086 inline static Program * & fragment_program()
00087 {
00088 static Program * f_program = 0;
00089 return f_program;
00090 }
00091
00099 inline static bool startup()
00100 {
00101 bool startup_succeded = true;
00102 cgSetErrorCallback( cg_error_callback_func );
00103 context() = cgCreateContext();
00104
00105 cgGLSetManageTextureParameters(context(),true);
00106
00107 if(context()==0)
00108 {
00109 std::cerr << "Cg::startup(): Could not create context" << std::endl;
00110 startup_succeded = false;
00111 }
00112
00113 vertex_profile() = cgGLGetLatestProfile(CG_GL_VERTEX);
00114 if(vertex_profile() == CG_PROFILE_UNKNOWN)
00115 {
00116 std::cerr << "Cg::startup(): invalid vertex profile" << std::endl;
00117 startup_succeded = false;
00118 }
00119 else
00120 {
00121 cgGLSetOptimalOptions( vertex_profile() );
00122 }
00123
00124 std::cout << "vertex profile = " << cgGetProfileString(vertex_profile()) << std::endl;
00125
00126 fragment_profile() = cgGLGetLatestProfile(CG_GL_FRAGMENT);
00127
00128 if(fragment_profile() == CG_PROFILE_UNKNOWN)
00129 {
00130 std::cerr << "Cg::startup(): invalid fragment profile" << std::endl;
00131 startup_succeded = false;
00132 }
00133 else
00134 {
00135 cgGLSetOptimalOptions( fragment_profile() );
00136 }
00137
00138 std::cout << "fragment profile = " << cgGetProfileString(fragment_profile()) << std::endl;
00139
00140 return startup_succeded;
00141 }
00142
00147 inline static void shutdown()
00148 {
00149 cgGLDisableProfile( vertex_profile() );
00150 cgGLDisableProfile( fragment_profile() );
00151 cgDestroyContext( context() );
00152 context() = 0;
00153 }
00154
00155 }
00156 }
00157
00158
00159 #endif