39 moShaderCG::moShaderCG() :
moShader()
44 m_cgFragmentShader = NULL;
45 m_cgVertexShader = NULL;
48 moShaderCG::~moShaderCG()
60 if (m_cgVertexShader != NULL)
62 cgDestroyProgram(m_cgVertexShader);
63 m_cgVertexShader = NULL;
65 if (m_cgFragmentShader != NULL)
67 cgDestroyProgram(m_cgFragmentShader);
68 m_cgFragmentShader = NULL;
71 if(m_cgContext != NULL)
73 cgDestroyContext(m_cgContext);
80 void moShaderCG::CreateVertShader(
moText vert_source)
82 m_cgContext = cgCreateContext();
84 compileVertShader(vert_source);
86 MODebug2->Error(
moText(
"moShaderCG:: Couldn't create CG Context") );
90 void moShaderCG::CreateFragShader(
moText frag_source)
92 m_cgContext = cgCreateContext();
94 compileFragShader(frag_source);
96 MODebug2->Error(
moText(
"moShaderCG:: Couldn't create CG Context") );
100 void moShaderCG::CreateShader(
moText vert_source,
moText frag_source)
102 m_cgContext = cgCreateContext();
104 compileVertShader(vert_source);
105 compileFragShader(frag_source);
107 MODebug2->Error(
moText(
"moShaderCG:: Couldn't create CG Context") );
111 void moShaderCG::LoadVertShader(
moText vert_filename)
113 moText vert_source = LoadShaderSource(vert_filename);
114 CreateVertShader(vert_source);
117 void moShaderCG::LoadFragShader(
moText frag_filename)
119 moText frag_source = LoadShaderSource(frag_filename);
120 CreateFragShader(frag_source);
123 void moShaderCG::LoadShader(
moText vert_filename,
moText frag_filename)
125 moText vert_source = LoadShaderSource(vert_filename);
126 moText frag_source = LoadShaderSource(frag_filename);
127 CreateShader(vert_source, frag_source);
131 static void checkForCgError(
moText situation )
134 const char *
string = cgGetLastErrorString(&error);
136 if (error != CG_NO_ERROR) {
140 if (error == CG_COMPILER_ERROR) {
148 void moShaderCG::StartShader()
152 if (m_cgVertexShader != NULL)
154 cgGLBindProgram(m_cgVertexShader);
155 checkForCgError(
"Binding vertex program");
156 cgGLEnableProfile(m_cgVertexProfile);
157 checkForCgError(
"enabling vertex profile");
159 if (m_cgFragmentShader != NULL)
161 cgGLBindProgram(m_cgFragmentShader);
162 checkForCgError(
"Binding fragment program");
163 cgGLEnableProfile(m_cgFragmentProfile);
164 checkForCgError(
"enabling fragments profile");
170 void moShaderCG::StopShader()
172 if (m_cgVertexShader != NULL) cgGLDisableProfile(m_cgVertexProfile);
173 if (m_cgFragmentShader != NULL) cgGLDisableProfile(m_cgFragmentProfile);
178 CGparameter moShaderCG::GetVertParameter(
moText pName)
180 return cgGetNamedParameter(m_cgVertexShader, pName);
183 CGparameter moShaderCG::GetFragParameter(
moText pName)
185 return cgGetNamedParameter(m_cgFragmentShader, pName);
188 void moShaderCG::compileVertShader(
moText vert_source)
190 m_cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
191 if (m_cgVertexProfile == CG_PROFILE_UNKNOWN)
193 if (MODebug != NULL) MODebug2->Error(
moText(
"Vertex profile not found"));
194 m_VertErrorCode = -1;
197 cgGLSetOptimalOptions(m_cgVertexProfile);
198 m_cgVertexShader = cgCreateProgram(m_cgContext, CG_SOURCE, vert_source, m_cgVertexProfile, NULL, NULL);
199 if (m_cgVertexShader == NULL)
201 CGerror Error = cgGetError();
202 const char* errorString = cgGetErrorString(Error);
203 if (MODebug2 != NULL)
205 MODebug2->Error(
moText(
"Cg error!"));
209 +
moText(
"] could not be created: ")
211 MODebug2->Error(
moText(cgGetLastListing(m_cgContext)));
217 cgGLLoadProgram(m_cgVertexShader);
222 void moShaderCG::compileFragShader(
moText frag_source)
224 m_cgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
225 if (m_cgFragmentProfile == CG_PROFILE_UNKNOWN)
227 MODebug2->Error(
moText(
"Fragment profile not found"));
228 m_FragErrorCode = -1;
231 cgGLSetOptimalOptions(m_cgFragmentProfile);
232 m_cgFragmentShader = cgCreateProgram(m_cgContext, CG_SOURCE, frag_source, m_cgFragmentProfile, NULL, NULL);
233 if (m_cgFragmentShader == NULL)
235 CGerror Error = cgGetError();
236 const char* errorString = cgGetErrorString(Error);
239 MODebug2->Error(
moText(
"Cg error!"));
241 moText(
"Fragment shader [")
243 +
moText(
"] could not be created: ")
245 MODebug2->Error(
moText(cgGetLastListing(m_cgContext)));
252 cgGLLoadProgram(m_cgFragmentShader);
static void Error(moText p_text)
Anuncia un error.
virtual MOboolean Finish()
virtual void StartShader()
clase de para manejar textos
virtual void StopShader()
void SetType(MOuint p_type)