소스 검색

*** empty log message ***

Josh Yelon 20 년 전
부모
커밋
45aca0885e

+ 21 - 3
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -68,6 +68,10 @@
 #include "shader.h"
 #include "shader.h"
 #include "shaderMode.h"
 #include "shaderMode.h"
 
 
+#ifdef CGGL
+#include "Cg/CgGL.h"
+#endif
+
 #include <algorithm>
 #include <algorithm>
 
 
 TypeHandle CLP(GraphicsStateGuardian)::_type_handle;
 TypeHandle CLP(GraphicsStateGuardian)::_type_handle;
@@ -279,8 +283,6 @@ CLP(GraphicsStateGuardian)(const FrameBufferProperties &properties) :
   GraphicsStateGuardian(properties, CS_yup_right) 
   GraphicsStateGuardian(properties, CS_yup_right) 
 {
 {
   _error_count = 0;
   _error_count = 0;
-  _shader_mode = (ShaderMode *)NULL;
-  _shader_context = (CLP(ShaderContext) *)NULL;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -857,6 +859,16 @@ reset() {
 
 
   _error_count = 0;
   _error_count = 0;
 
 
+#ifdef CGGL
+  _cg_context = cgCreateContext();
+  if (_cg_context != 0) {
+    _cg_vprofile = cgGLGetLatestProfile(CG_GL_VERTEX);
+    _cg_fprofile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
+  } else {
+    cerr << "Warning: could not create Cg context.\n";
+  }
+#endif
+
   report_my_gl_errors();
   report_my_gl_errors();
 }
 }
 
 
@@ -1932,7 +1944,7 @@ release_geom(GeomContext *gc) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 ShaderContext *CLP(GraphicsStateGuardian)::
 ShaderContext *CLP(GraphicsStateGuardian)::
 prepare_shader(Shader *shader) {
 prepare_shader(Shader *shader) {
-  return new CLP(ShaderContext)(shader);
+  return new CLP(ShaderContext)(this, shader);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -4750,6 +4762,12 @@ finish_modify_state() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void CLP(GraphicsStateGuardian)::
 void CLP(GraphicsStateGuardian)::
 free_pointers() {
 free_pointers() {
+#ifdef CGGL
+  if (_cg_context) {
+    cgDeleteContext(_cg_context);
+    _cg_context = 0;
+  }
+#endif
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 10 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.h

@@ -41,6 +41,10 @@
 #include "shader.h"
 #include "shader.h"
 #include "shaderMode.h"
 #include "shaderMode.h"
 
 
+#ifdef CGGL
+#include "Cg/CgGL.h"
+#endif
+
 class PlaneNode;
 class PlaneNode;
 class Light;
 class Light;
 
 
@@ -385,6 +389,12 @@ public:
   typedef pvector<GLuint> DeletedDisplayLists;
   typedef pvector<GLuint> DeletedDisplayLists;
   DeletedDisplayLists _deleted_display_lists;
   DeletedDisplayLists _deleted_display_lists;
 
 
+#ifdef CGGL
+  CGcontext _cg_context;
+  CGprofile _cg_vprofile;
+  CGprofile _cg_fprofile;
+#endif
+
   static PStatCollector _load_display_list_pcollector;
   static PStatCollector _load_display_list_pcollector;
   static PStatCollector _primitive_batches_display_list_pcollector;
   static PStatCollector _primitive_batches_display_list_pcollector;
   static PStatCollector _vertices_display_list_pcollector;
   static PStatCollector _vertices_display_list_pcollector;

+ 1 - 0
panda/src/glstuff/glShaderContext_src.I

@@ -42,3 +42,4 @@ unbind() {
 INLINE void CLP(ShaderContext)::
 INLINE void CLP(ShaderContext)::
 rebind(ShaderMode *oldmode, ShaderMode *newmode) {
 rebind(ShaderMode *oldmode, ShaderMode *newmode) {
 }
 }
+

+ 36 - 4
panda/src/glstuff/glShaderContext_src.cxx

@@ -24,12 +24,44 @@ TypeHandle CLP(ShaderContext)::_type_handle;
 //  Description: xyz
 //  Description: xyz
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 CLP(ShaderContext)::
 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_init();
   s->parse_line(header, true, true);
   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";
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 16 - 1
panda/src/glstuff/glShaderContext_src.h

@@ -18,6 +18,11 @@
 
 
 #include "pandabase.h"
 #include "pandabase.h"
 #include "shaderContext.h"
 #include "shaderContext.h"
+#ifdef CGGL
+#include "Cg/CgGL.h"
+#endif
+
+class CLP(GraphicsStateGuardian);
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : GLShaderContext
 //       Class : GLShaderContext
@@ -26,13 +31,23 @@
 
 
 class EXPCL_GL CLP(ShaderContext): public ShaderContext {
 class EXPCL_GL CLP(ShaderContext): public ShaderContext {
 public:
 public:
-  CLP(ShaderContext)(Shader *shader);
+  CLP(ShaderContext)(CLP(GraphicsStateGuardian) *gsg, Shader *shader);
   ~CLP(ShaderContext)();
   ~CLP(ShaderContext)();
 
 
   INLINE void bind(ShaderMode *mode);
   INLINE void bind(ShaderMode *mode);
   INLINE void unbind();
   INLINE void unbind();
   INLINE void rebind(ShaderMode *oldmode, ShaderMode *newmode);
   INLINE void rebind(ShaderMode *oldmode, ShaderMode *newmode);
 
 
+  bool _valid;
+  
+private:
+  CLP(GraphicsStateGuardian) *_gsg;
+  
+#ifdef CGGL
+  CGprogram _cg_vprogram;
+  CGprogram _cg_fprogram;
+#endif
+
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {
     return _type_handle;
     return _type_handle;

+ 3 - 3
panda/src/gobj/shader.cxx

@@ -88,12 +88,13 @@ parse_line(string &result, bool lt, bool rt) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void Shader::
 void Shader::
 parse_upto(string &result, string pattern, bool include) {
 parse_upto(string &result, string pattern, bool include) {
+  GlobPattern endpat(pattern);
   int start = _parse;
   int start = _parse;
   int last = _parse;
   int last = _parse;
-  while (true) {
+  while (_parse < _text.size()) {
     string t;
     string t;
     parse_line(t, true, true);
     parse_line(t, true, true);
-    if (t == pattern) break;
+    if (endpat.matches(t)) break;
     last = _parse;
     last = _parse;
   }
   }
   if (include) {
   if (include) {
@@ -276,4 +277,3 @@ void Shader::
 register_with_read_factory() {
 register_with_read_factory() {
   // IMPLEMENT ME
   // IMPLEMENT ME
 }
 }
-