* 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
vcg/simplex/vertexplus
wrap/gl

View File

@ -501,11 +501,11 @@ public:
typedef float RadiusType; typedef float RadiusType;
typedef RadiusType ScalarType; typedef RadiusType ScalarType;
RadiusType &R(){ static 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); 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 HasRadius() { return false; }
static bool HasRadiusOcf() { return true; } static bool HasRadiusOcf() { return false; }
static void Name(std::vector<std::string> & name){ T::Name(name);} static void Name(std::vector<std::string> & name){ T::Name(name);}
}; };

View File

@ -557,7 +557,7 @@ public:
typedef A RadiusType; typedef A RadiusType;
typedef RadiusType ScalarType; typedef RadiusType ScalarType;
RadiusType &R(){ assert((*this).Base().RadiusEnabled); return (*this).Base().RadiusV[(*this).Index()];} RadiusType &R(){ assert((*this).Base().RadiusEnabled); return (*this).Base().RadiusV[(*this).Index()];}
const RadiusType &cR() const { assert((*this).Base().RadiusEnabled); return (*this).Base().RadiusV[(*this).Index()];} const RadiusType &cR() const { assert((*this).Base().RadiusEnabled); return (*this).Base().RadiusV[(*this).Index()];}
template <class LeftV> template <class LeftV>

View File

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