* make EmptyRadius::HasRadius returns false

* make gl/Shader and gl/Program* a bit easier to use:
 - automatic object creation
 - add Uniform() overloads for vcg::Point*f types
This commit is contained in:
Paolo Cignoni 2008-10-15 08:02:14 +00:00
parent 79ef95435a
commit 64ce68dac0
4 changed files with 97 additions and 56 deletions

View File

@ -501,11 +501,11 @@ public:
typedef float RadiusType;
typedef RadiusType ScalarType;
RadiusType &R(){ static ScalarType v = 0.0; assert(0); return v; }
const RadiusType &cR() const { static const ScalarType & v = 0.0; assert(0); return v; }
RadiusType &R(){ static ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; }
const RadiusType &cR() const { static const ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; }
static bool HasRadius() { return true; }
static bool HasRadiusOcf() { return true; }
static bool HasRadius() { return false; }
static bool HasRadiusOcf() { return false; }
static void Name(std::vector<std::string> & name){ T::Name(name);}
};

View File

@ -6,6 +6,9 @@
#include <set>
#include "gl_object.h"
#include "../../vcg/space/point2.h"
#include "../../vcg/space/point3.h"
#include "../../vcg/space/point4.h"
class Shader : public GLObject, public Bindable
{
@ -49,6 +52,9 @@ public:
void SetSource(const char * src)
{
if (this->objectID==0)
Gen();
this->flags |= SOURCE_DIRTY;
this->compiled = false;
this->source = src;
@ -59,6 +65,9 @@ public:
bool LoadSource(const char * fileName)
{
if (this->objectID==0)
Gen();
this->flags |= SOURCE_DIRTY;
this->compiled = false;
FILE * f = fopen(fileName, "rb");
@ -375,6 +384,8 @@ public:
void Attach(Shader * shd)
{
if (this->objectID==0)
Gen();
this->shaders.insert(shd);
this->linked = false;
glAttachShader(this->objectID, shd->ObjectID());
@ -405,15 +416,19 @@ public:
bool Link(void)
{
bool ok = true;
for (std::set<Shader *>::iterator it=this->shaders.begin(); it!=this->shaders.end(); ++it)
{
Shader * shd = (*it);
if (!shd->IsCompiled())
{
shd->Compile();
ok = shd->Compile() && ok;
}
}
if (!ok)
return false;
glLinkProgram(this->objectID);
GLint cm = 0;
@ -487,6 +502,24 @@ public:
glUniform4f(loc, x, y, z, w);
}
void Uniform(const char * name, const vcg::Point3f& p)
{
const GLint loc = glGetUniformLocation(this->objectID, name);
glUniform2fv(loc, 1, p.V());
}
void Uniform(const char * name, const vcg::Point2f& p)
{
const GLint loc = glGetUniformLocation(this->objectID, name);
glUniform3fv(loc, 1, p.V());
}
void Uniform(const char * name, const vcg::Point4f& p)
{
const GLint loc = glGetUniformLocation(this->objectID, name);
glUniform4fv(loc, 1, p.V());
}
void Parameter(GLenum pname, int value)
{
glProgramParameteriEXT(this->objectID, pname, value);
@ -525,19 +558,27 @@ public:
void SetSources(const char * vsrc, const char * fsrc)
{
if (vsrc) {
this->vshd.SetSource(vsrc);
this->fshd.SetSource(fsrc);
this->prog.Attach(&(this->vshd));
}
if (fsrc) {
this->fshd.SetSource(fsrc);
this->prog.Attach(&(this->fshd));
}
}
void LoadSources(const char * vfile, const char * ffile)
{
if (vfile) {
this->vshd.LoadSource(vfile);
this->fshd.LoadSource(ffile);
this->prog.Attach(&(this->vshd));
}
if (ffile) {
this->fshd.LoadSource(ffile);
this->prog.Attach(&(this->fshd));
}
}
protected:
void DoBind(void)