commit 2b3095b7c02ab35d921531965e5fed4e28762566
parent 89eae2d3472d29694a21d4be8e60f7ef1c370403
Author: Brian Swetland <swetland@frotz.net>
Date: Tue, 29 Jan 2013 20:43:31 -0800
program: add ability to compile from string as well as file
Diffstat:
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/program.cc b/program.cc
@@ -78,9 +78,9 @@ Program::Program() : vsrc(NULL), fsrc(NULL), status(-1) {
}
int Program::compile(const char *vfn, const char *ffn) {
- if (!(vsrc = (char*) load_file(vfn, 0)))
+ if (!(vsrc = (const char*) load_file(vfn, 0)))
return -1;
- if (!(fsrc = (char*) load_file(ffn, 0)))
+ if (!(fsrc = (const char*) load_file(ffn, 0)))
return -1;
if (shader_compile(vsrc, fsrc, &pobj, &vobj, &fobj))
return -1;
@@ -88,3 +88,13 @@ int Program::compile(const char *vfn, const char *ffn) {
return 0;
}
+int Program::compileStr(const char *vsc, const char *fsc) {
+ vsrc = vsc;
+ fsrc = fsc;
+ if (shader_compile(vsrc, fsrc, &pobj, &vobj, &fobj))
+ return -1;
+ status = 0;
+ return 0;
+}
+
+
diff --git a/program.h b/program.h
@@ -18,13 +18,15 @@
class Program {
GLuint pobj, vobj, fobj;
- char *vsrc, *fsrc;
+ const char *vsrc, *fsrc;
int status;
public:
Program();
int compile(const char *vfn, const char *ffn);
+ int compileStr(const char *vsc, const char *fsc);
+
int ready() { return status == 0; }
void use(void) {