*** empty log message ***

This commit is contained in:
Josh Yelon 2005-09-06 21:33:34 +00:00
parent 292b0d1d95
commit 45aca0885e
6 changed files with 87 additions and 11 deletions

View File

@ -68,6 +68,10 @@
#include "shader.h"
#include "shaderMode.h"
#ifdef CGGL
#include "Cg/CgGL.h"
#endif
#include <algorithm>
TypeHandle CLP(GraphicsStateGuardian)::_type_handle;
@ -279,8 +283,6 @@ CLP(GraphicsStateGuardian)(const FrameBufferProperties &properties) :
GraphicsStateGuardian(properties, CS_yup_right)
{
_error_count = 0;
_shader_mode = (ShaderMode *)NULL;
_shader_context = (CLP(ShaderContext) *)NULL;
}
////////////////////////////////////////////////////////////////////
@ -857,6 +859,16 @@ reset() {
_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();
}
@ -1932,7 +1944,7 @@ release_geom(GeomContext *gc) {
////////////////////////////////////////////////////////////////////
ShaderContext *CLP(GraphicsStateGuardian)::
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)::
free_pointers() {
#ifdef CGGL
if (_cg_context) {
cgDeleteContext(_cg_context);
_cg_context = 0;
}
#endif
}
////////////////////////////////////////////////////////////////////

View File

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

View File

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

View File

@ -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";
}
////////////////////////////////////////////////////////////////////

View File

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

View File

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