* 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
io_trimesh

View File

@ -8,7 +8,7 @@
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
@ -129,7 +129,7 @@ All the Components that can be added to a vertex should be defined in the namesp
*/
/*------------------------- EMPTY COORD & NORMAL -----------------------------------------*/
/*------------------------- EMPTY COORD & NORMAL -----------------------------------------*/
template <class T> class EmptyCoordNormal: public T {
public:
typedef vcg::Point3f CoordType;
@ -147,11 +147,11 @@ public:
static bool HasNormal() { return false; }
static bool HasNormalOcc() { return false; }
template < class LeftV>
void ImportLocal(const LeftV & left ) { T::ImportLocal( left); }
void ImportLocal(const LeftV & left ) { T::ImportLocal( left); }
static void Name(std::vector<std::string> & name){T::Name(name);}
};
/*-------------------------- COORD ----------------------------------------*/
/*-------------------------- COORD ----------------------------------------*/
template <class A, class T> class Coord: public T {
public:
@ -163,12 +163,12 @@ public:
CoordType &UberP() { return _coord; }
template < class LeftV>
void ImportLocal(const LeftV & left ) { P().Import(left.cP()); T::ImportLocal( left); }
void ImportLocal(const LeftV & left ) { P().Import(left.cP()); T::ImportLocal( left); }
static bool HasCoord() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord"));T::Name(name);}
private:
CoordType _coord;
CoordType _coord;
};
template <class T> class Coord3f: public Coord<vcg::Point3f, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord3f"));T::Name(name);}
@ -177,7 +177,7 @@ template <class T> class Coord3d: public Coord<vcg::Point3d, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord3d"));T::Name(name);}
};
/*-------------------------- NORMAL ----------------------------------------*/
/*-------------------------- NORMAL ----------------------------------------*/
template <class A, class T> class Normal: public T {
public:
@ -190,7 +190,7 @@ public:
static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal"));T::Name(name);}
private:
NormalType _norm;
NormalType _norm;
};
template <class T> class Normal3s: public Normal<vcg::Point3s, T> {
@ -204,7 +204,7 @@ public: static void Name(std::vector<std::string> & name){name.push_back(std::st
};
/*-------------------------- INCREMENTAL MARK ----------------------------------------*/
/*-------------------------- INCREMENTAL MARK ----------------------------------------*/
template <class T> class EmptyMark: public T {
public:
@ -228,12 +228,12 @@ public:
template < class LeftV>
void ImportLocal(const LeftV & left ) { IMark() = left.IMark(); T::ImportLocal( left); }
static void Name(std::vector<std::string> & name){name.push_back(std::string("Mark"));T::Name(name);}
private:
int _imark;
};
/*-------------------------- TEXCOORD ----------------------------------------*/
/*-------------------------- TEXCOORD ----------------------------------------*/
template <class TT> class EmptyTexCoord: public TT {
public:
@ -256,7 +256,7 @@ public:
static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord"));TT::Name(name);}
private:
TexCoordType _t;
TexCoordType _t;
};
template <class TT> class TexCoord2s: public TexCoord<TexCoord2<short,1>, TT> {
@ -270,7 +270,7 @@ template <class TT> class TexCoord2d: public TexCoord<TexCoord2<double,1>, TT> {
static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord2d"));TT::Name(name);}
};
/*------------------------- FLAGS -----------------------------------------*/
/*------------------------- FLAGS -----------------------------------------*/
template <class T> class EmptyBitFlags: public T {
public:
typedef int FlagType;
@ -296,10 +296,10 @@ public:
static void Name(std::vector<std::string> & name){name.push_back(std::string("BitFlags"));T::Name(name);}
private:
int _flags;
int _flags;
};
/*-------------------------- EMPTY COLOR & QUALITY ----------------------------------*/
/*-------------------------- EMPTY COLOR & QUALITY ----------------------------------*/
template <class T> class EmptyColorQuality: public T {
public:
@ -315,7 +315,7 @@ public:
static void Name(std::vector<std::string> & name){T::Name(name);}
};
/*-------------------------- Color ----------------------------------*/
/*-------------------------- Color ----------------------------------*/
template <class A, class T> class Color: public T {
public:
@ -330,14 +330,14 @@ public:
static void Name(std::vector<std::string> & name){name.push_back(std::string("Color"));T::Name(name);}
private:
ColorType _color;
ColorType _color;
};
template <class TT> class Color4b: public Color<vcg::Color4b, TT> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Color4b"));TT::Name(name);}
};
/*-------------------------- Quality ----------------------------------*/
/*-------------------------- Quality ----------------------------------*/
template <class A, class TT> class Quality: public TT {
public:
@ -350,7 +350,7 @@ public:
static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality"));TT::Name(name);}
private:
QualityType _quality;
QualityType _quality;
};
template <class TT> class Qualitys: public Quality<short, TT> {
@ -392,7 +392,7 @@ public:
static void Name(std::vector<std::string> & name){TT::Name(name);}
};
/*-------------------------- Curvature ----------------------------------*/
/*-------------------------- Curvature ----------------------------------*/
template <class TT> class EmptyCurvature: public TT {
public:
@ -422,7 +422,7 @@ public:
static void Name(std::vector<std::string> & name){name.push_back(std::string("Curvature"));TT::Name(name);}
private:
Point2<A> _hk;
Point2<A> _hk;
};
@ -433,14 +433,14 @@ template <class T> class Curvatured: public Curvature<double , T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Curvatured"));T::Name(name);}
};
/*-------------------------- Curvature Direction ----------------------------------*/
/*-------------------------- Curvature Direction ----------------------------------*/
template <class S>
struct CurvatureDirBaseType{
typedef Point3<S> VecType;
typedef S ScalarType;
CurvatureDirBaseType () {}
Point3<S>max_dir,min_dir; // max and min curvature direction
Point3<S>max_dir,min_dir; // max and min curvature direction
S k1,k2;// max and min curvature values
};
@ -482,7 +482,7 @@ public:
static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDir"));TT::Name(name);}
private:
CurvatureDirType _curv;
CurvatureDirType _curv;
};
@ -493,25 +493,25 @@ template <class T> class CurvatureDird: public CurvatureDir<CurvatureDirBaseType
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDird"));T::Name(name);}
};
/*-------------------------- Empty Radius ----------------------------------*/
/*-------------------------- Empty Radius ----------------------------------*/
template <class T> class EmptyRadius: public T {
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);}
};
/*----------------------------- VEADJ ------------------------------*/
/*----------------------------- VEADJ ------------------------------*/
template <class T> class EmptyVEAdj: public T {
@ -537,13 +537,13 @@ public:
static bool HasVEAdjacency() { return true; }
static bool HasVEAdjacencyOcc() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("VEAdj"));T::Name(name);}
private:
typename T::EdgePointer _ep ;
int _zp ;
typename T::EdgePointer _ep ;
int _zp ;
};
/*----------------------------- VFADJ ------------------------------*/
/*----------------------------- VFADJ ------------------------------*/
template <class T> class EmptyVFAdj: public T {
@ -571,11 +571,11 @@ public:
static void Name(std::vector<std::string> & name){name.push_back(std::string("VFAdj"));T::Name(name);}
private:
typename T::FacePointer _fp ;
int _zp ;
typename T::FacePointer _fp ;
int _zp ;
};
/*----------------------------- VTADJ ------------------------------*/
/*----------------------------- VTADJ ------------------------------*/
template <class T> class EmptyVTAdj: public T {
@ -599,8 +599,8 @@ public:
static void Name( std::vector< std::string > & name ) { name.push_back( std::string("VTAdj") ); T::Name(name); }
private:
typename T::TetraPointer _tp ;
int _zp ;
typename T::TetraPointer _tp ;
int _zp ;
};
} // end namespace vert

View File

@ -557,7 +557,7 @@ public:
typedef A RadiusType;
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()];}
template <class LeftV>

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,18 +558,26 @@ public:
void SetSources(const char * vsrc, const char * fsrc)
{
this->vshd.SetSource(vsrc);
this->fshd.SetSource(fsrc);
this->prog.Attach(&(this->vshd));
this->prog.Attach(&(this->fshd));
if (vsrc) {
this->vshd.SetSource(vsrc);
this->prog.Attach(&(this->vshd));
}
if (fsrc) {
this->fshd.SetSource(fsrc);
this->prog.Attach(&(this->fshd));
}
}
void LoadSources(const char * vfile, const char * ffile)
{
this->vshd.LoadSource(vfile);
this->fshd.LoadSource(ffile);
this->prog.Attach(&(this->vshd));
this->prog.Attach(&(this->fshd));
if (vfile) {
this->vshd.LoadSource(vfile);
this->prog.Attach(&(this->vshd));
}
if (ffile) {
this->fshd.LoadSource(ffile);
this->prog.Attach(&(this->fshd));
}
}
protected:

View File

@ -8,7 +8,7 @@
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
@ -75,8 +75,8 @@ namespace vcg {
namespace tri {
namespace io {
/**
This class encapsulate a filter for automatically importing meshes by guessing
/**
This class encapsulate a filter for automatically importing meshes by guessing
the right filter according to the extension
*/
@ -151,7 +151,7 @@ static bool ErrorCritical(int error)
case KT_OBJ : return ImporterOBJ<OpenMeshType>::ErrorCritical(error); break;
}
return true;
return true;
}
static const char *ErrorMsg(int error)
@ -163,7 +163,7 @@ static const char *ErrorMsg(int error)
case KT_OFF : return ImporterOFF<OpenMeshType>::ErrorMsg(error); break;
case KT_OBJ : return ImporterOBJ<OpenMeshType>::ErrorMsg(error); break;
}
return "Unknown type";
return "Unknown type";
}
static bool LoadMask(const char * filename, int &mask)
@ -192,7 +192,7 @@ static bool LoadMask(const char * filename, int &mask)
err = ImporterOBJ<OpenMeshType>::LoadMask(filename, mask);
LastType()=KT_OBJ;
}
else
else
{
err = false;
LastType()=KT_UNKNOWN;