From 9ad64a6b4b4a91477e6ad2742542b70302f5ef15 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Mon, 5 Sep 2005 15:20:37 +0000 Subject: [PATCH] Shader modifications --- panda/src/glstuff/glShaderContext_src.I | 18 ----- panda/src/glstuff/glShaderContext_src.cxx | 24 +++++++ panda/src/glstuff/glShaderContext_src.h | 10 +-- panda/src/gobj/shader.cxx | 83 +++++++++++++++++++++++ panda/src/gobj/shader.h | 11 ++- 5 files changed, 122 insertions(+), 24 deletions(-) diff --git a/panda/src/glstuff/glShaderContext_src.I b/panda/src/glstuff/glShaderContext_src.I index 0f0092c7f3..93ca611844 100755 --- a/panda/src/glstuff/glShaderContext_src.I +++ b/panda/src/glstuff/glShaderContext_src.I @@ -16,24 +16,6 @@ // //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: GLShaderContext::Constructor -// Access: Public -// Description: xyz -//////////////////////////////////////////////////////////////////// -INLINE CLP(ShaderContext):: -CLP(ShaderContext)(Shader *s) : ShaderContext(s) { -} - -//////////////////////////////////////////////////////////////////// -// Function: GLShaderContext::Destructor -// Access: Public -// Description: xyz -//////////////////////////////////////////////////////////////////// -INLINE CLP(ShaderContext):: -~CLP(ShaderContext)(void) { -} - //////////////////////////////////////////////////////////////////// // Function: GLShaderContext::bind // Access: Public diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 912490c84f..056dde4f83 100755 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -17,3 +17,27 @@ //////////////////////////////////////////////////////////////////// TypeHandle CLP(ShaderContext)::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: GLShaderContext::Constructor +// Access: Public +// Description: xyz +//////////////////////////////////////////////////////////////////// +CLP(ShaderContext):: +CLP(ShaderContext)(Shader *s) : ShaderContext(s) { + string header, body; + s->parse_init(); + s->parse_line(header, true, true); + s->parse_rest(body); + cerr << "Compiling shader. Language=" << header << " Body=\n" << body << "\n"; +} + +//////////////////////////////////////////////////////////////////// +// Function: GLShaderContext::Destructor +// Access: Public +// Description: xyz +//////////////////////////////////////////////////////////////////// +CLP(ShaderContext):: +~CLP(ShaderContext)(void) { +} + diff --git a/panda/src/glstuff/glShaderContext_src.h b/panda/src/glstuff/glShaderContext_src.h index a688ccb452..59205c927d 100755 --- a/panda/src/glstuff/glShaderContext_src.h +++ b/panda/src/glstuff/glShaderContext_src.h @@ -26,12 +26,12 @@ class EXPCL_GL CLP(ShaderContext): public ShaderContext { public: - INLINE CLP(ShaderContext)(Shader *shader); - INLINE ~CLP(ShaderContext)(void); + CLP(ShaderContext)(Shader *shader); + ~CLP(ShaderContext)(void); - void bind(ShaderMode *mode); - void unbind(void); - void rebind(ShaderMode *oldmode, ShaderMode *newmode); + INLINE void bind(ShaderMode *mode); + INLINE void unbind(void); + INLINE void rebind(ShaderMode *oldmode, ShaderMode *newmode); public: static TypeHandle get_class_type() { diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index 5dc3c20d6d..6ea7f40a7f 100755 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -42,6 +42,89 @@ Shader:: release_all(); } +//////////////////////////////////////////////////////////////////// +// Function: Shader::parse_init +// Access: Public +// Description: Set a 'parse pointer' to the beginning of the shader. +//////////////////////////////////////////////////////////////////// +void Shader:: +parse_init(void) { + _parse = 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: Shader::parse_line +// Access: Public +// Description: Parse a line of text. If 'lt' is true, trim blanks +// from the left end of the line. If 'rt' is true, trim +// blanks from the right end (the newline is always +// trimmed). +//////////////////////////////////////////////////////////////////// +void Shader:: +parse_line(string &result, bool lt, bool rt) { + int len = _text.size(); + int head = _parse; + int tail = head; + while ((tail < len) && (_text[tail] != '\n')) tail++; + if (tail < len) { + _parse = tail+1; + } else { + _parse = tail; + } + if (lt) { + while ((head < tail)&&(isspace(_text[head]))) head++; + while ((tail > head)&&(isspace(_text[tail-1]))) tail--; + } + result = _text.substr(head, tail-head); +} + +//////////////////////////////////////////////////////////////////// +// Function: Shader::parse_upto +// Access: Public +// Description: Parse lines until you read a line that matches the +// specified pattern. Returns all the preceding lines, +// and if the include flag is set, returns the final +// line as well. +//////////////////////////////////////////////////////////////////// +void Shader:: +parse_upto(string &result, string pattern, bool include) { + int start = _parse; + int last = _parse; + while (true) { + string t; + parse_line(t, true, true); + if (t == pattern) break; + last = _parse; + } + if (include) { + result = _text.substr(start, _parse - start); + } else { + result = _text.substr(start, last - start); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: Shader::parse_rest +// Access: Public +// Description: Returns the rest of the text from the current +// parse location. +//////////////////////////////////////////////////////////////////// +void Shader:: +parse_rest(string &result) { + result = _text.substr(_parse, _text.size() - _parse); +} + +//////////////////////////////////////////////////////////////////// +// Function: Shader::parse_eof +// Access: Public +// Description: Returns true if the parse pointer is at the end of +// the shader. +//////////////////////////////////////////////////////////////////// +bool Shader:: +parse_eof(void) { + return _text.size() == _parse; +} + //////////////////////////////////////////////////////////////////// // Function: Shader::arg_index // Access: Public diff --git a/panda/src/gobj/shader.h b/panda/src/gobj/shader.h index 2172ca9401..ab5312ae39 100755 --- a/panda/src/gobj/shader.h +++ b/panda/src/gobj/shader.h @@ -55,17 +55,25 @@ PUBLISHED: INLINE const string &get_text(void); INLINE const Filename &get_file(void); - + void prepare(PreparedGraphicsObjects *prepared_objects); bool release(PreparedGraphicsObjects *prepared_objects); int release_all(); +PUBLISHED: + void parse_init(void); + void parse_line(string &result, bool rt, bool lt); + void parse_upto(string &result, string pattern, bool include); + void parse_rest(string &result); + bool parse_eof(void); + public: INLINE int arg_count(void); int arg_index(const string &id); string _text; Filename _file; + int _parse; vector _args; typedef pmap Contexts; @@ -80,6 +88,7 @@ public: GraphicsStateGuardianBase *gsg); private: + void parse(void); void clear_prepared(PreparedGraphicsObjects *prepared_objects); public: