|
|
@@ -24,12 +24,44 @@ TypeHandle CLP(ShaderContext)::_type_handle;
|
|
|
// Description: xyz
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
CLP(ShaderContext)::
|
|
|
-CLP(ShaderContext)(Shader *s) : ShaderContext(s) {
|
|
|
- string header, body;
|
|
|
+CLP(ShaderContext)(CLP(GraphicsStateGuardian) *gsg, Shader *s) : ShaderContext(s) {
|
|
|
+ string header;
|
|
|
+ _gsg = gsg;
|
|
|
+ _valid = false;
|
|
|
s->parse_init();
|
|
|
s->parse_line(header, true, true);
|
|
|
- s->parse_rest(body);
|
|
|
- cerr << "Compiling shader. Language=" << header << " Body=\n" << body << "\n";
|
|
|
+
|
|
|
+#ifdef CGGL
|
|
|
+ _cg_vprogram = 0;
|
|
|
+ _cg_fprogram = 0;
|
|
|
+
|
|
|
+ if (header == "Cg") {
|
|
|
+ if (_gsg->_cg_context == 0) {
|
|
|
+ cerr << "Cannot compile shader, no Cg context\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ string commentary, vs, fs;
|
|
|
+ s->parse_upto(commentary, "---*---", false);
|
|
|
+ s->parse_upto(vs, "---*---", false);
|
|
|
+ s->parse_upto(fs, "---*---", false);
|
|
|
+
|
|
|
+ _cg_vprogram = cgCreateProgram(_gsg->_cg_context, CG_SOURCE,
|
|
|
+ vp.c_str(), _gsg->_cg_vprofile,
|
|
|
+ "main", (char**)NULL);
|
|
|
+ _cg_fprogram = cgCreateProgram(_gsg->_cg_context, CG_SOURCE,
|
|
|
+ fp.c_str(), _gsg->_cg_fprofile,
|
|
|
+ "main", (char**)NULL);
|
|
|
+
|
|
|
+ if ((_cg_vprogram==0)||(_cg_fprogram == 0)) {
|
|
|
+ if (_cg_vprogram != 0) cgDestroyProgram(_cg_vprogram);
|
|
|
+ if (_cg_fprogram != 0) cgDestroyProgram(_cg_fprogram);
|
|
|
+ cerr << "Invalid Cg program" << s->_file << "\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ cerr << "Unrecognized shader language " << header << "\n";
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|