Shader modifications

This commit is contained in:
Josh Yelon 2005-09-05 15:20:37 +00:00
parent 405960a827
commit 9ad64a6b4b
5 changed files with 122 additions and 24 deletions

View File

@ -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

View File

@ -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) {
}

View File

@ -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() {

View File

@ -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

View File

@ -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<string> _args;
typedef pmap<PreparedGraphicsObjects *, ShaderContext *> Contexts;
@ -80,6 +88,7 @@ public:
GraphicsStateGuardianBase *gsg);
private:
void parse(void);
void clear_prepared(PreparedGraphicsObjects *prepared_objects);
public: