Commit fc493e8f authored by Sylvain Thery's avatar Sylvain Thery

automatic double usage !

parent 9e054a2d
......@@ -30,7 +30,7 @@ using namespace CGoGN ;
void MyQT::cb_initGL()
{
position = myMap.addAttribute<PFP::VEC3, VERTEX, MAP>("position");
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,50,50);
c.embedIntoCylinder(position,0.5,0.7,1.0);
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
......@@ -43,7 +43,7 @@ void MyQT::cb_initGL()
m_render = new Algo::Render::GL2::MapRender();
// create VBO for position
m_positionVBO = new Utils::VBO(&converterDF);
m_positionVBO = new Utils::VBO();
m_positionVBO->updateData(position);
m_shader = new Utils::ShaderSimpleColor();
......
......@@ -68,8 +68,6 @@ public:
Algo::Render::GL2::MapRender* m_render;
// converter for automatic conversion when updating VBOs
ConvertVec3dToVec3f converterDF;
Utils::VBO* m_positionVBO;
Utils::ShaderSimpleColor* m_shader;
......
......@@ -28,11 +28,6 @@ protected:
*/
unsigned int m_nb;
/**
* size of element in input
*/
unsigned int m_szElt;
/**
* buffer
*/
......@@ -42,9 +37,7 @@ public:
/**
*
*/
ConvertBuffer() : m_size(0),m_nb(0),m_szElt(0),m_buffer(NULL) {}
ConvertBuffer(unsigned int sz) : m_size(0),m_nb(0),m_szElt(sz),m_buffer(NULL) {}
ConvertBuffer() : m_size(0),m_nb(0),m_buffer(NULL) {}
/**
*
......@@ -95,11 +88,8 @@ class ConvertToFloat : public ConvertBuffer
{
protected:
float* m_typedBuffer;
unsigned int m_szVect;
public:
ConvertToFloat():
ConvertBuffer(sizeof(TYPE_IN)),m_szVect(1)
ConvertToFloat()
{}
~ConvertToFloat()
......@@ -119,7 +109,7 @@ public:
void reserve(unsigned int nb)
{
m_nb = nb*m_szVect; // store number of elements
m_nb = nb; // store number of elements
m_typedBuffer = new float[m_nb]; // allocate buffer
m_buffer = m_typedBuffer; // store void* casted ptr
m_size = m_nb*sizeof(float); // store size of buffer in bytes
......@@ -137,12 +127,7 @@ public:
unsigned int vectorSize()
{
return m_szVect;
}
void setPseudoVectorSize(unsigned int sz)
{
m_szVect = sz;
return 1;
}
};
......@@ -159,8 +144,8 @@ protected:
TYPE_OUT* m_typedBuffer;
public:
ConvertNormalized():
ConvertBuffer(sizeof(TYPE_IN))
ConvertNormalized()/*:
ConvertBuffer(sizeof(TYPE_IN))*/
{}
~ConvertNormalized()
......@@ -226,7 +211,11 @@ protected:
TYPE_IN m_diff;
public:
ConvertToRGBf(TYPE_IN min, TYPE_IN max) : ConvertBuffer(sizeof(TYPE_IN)),m_min(min), m_diff(max-min) {}
ConvertToRGBf(TYPE_IN min, TYPE_IN max) :
// ConvertBuffer(sizeof(TYPE_IN)),
m_min(min),
m_diff(max-min),
m_typedBuffer(NULL) {}
~ConvertToRGBf()
{
......@@ -306,24 +295,26 @@ public:
unsigned int vectorSize()
{
return 1;
return 3;
}
};
class ConvertVec3dToVec3f : public ConvertBuffer
template< unsigned int D>
class ConvertVecXdToVecXf : public ConvertBuffer
{
protected:
Geom::Vec3f* m_typedBuffer;
typedef Geom::Vector<D,float> VECF;
typedef Geom::Vector<D,double> VECD;
VECF* m_typedBuffer;
public:
ConvertVec3dToVec3f():
ConvertBuffer(sizeof(Geom::Vec3d)),
ConvertVecXdToVecXf():
m_typedBuffer(NULL)
{}
~ConvertVec3dToVec3f()
~ConvertVecXdToVecXf()
{
if (m_typedBuffer)
delete[] m_typedBuffer;
......@@ -341,32 +332,36 @@ public:
void reserve(unsigned int nb)
{
m_nb = nb; // store number of elements
m_typedBuffer = new Geom::Vec3f[nb]; // allocate buffer typed (not possible to delete void*)
m_typedBuffer = new VECF[nb]; // allocate buffer typed (not possible to delete void*)
m_buffer = m_typedBuffer; // store void* casted ptr
m_size = nb*sizeof(Geom::Vec3f); // store size of buffer in bytes
m_size = nb*sizeof(VECF); // store size of buffer in bytes
}
void convert(const void* ptrIn)
{
// cast ptr in & out with right type
const Geom::Vec3d* typedIn = reinterpret_cast<const Geom::Vec3d*>(ptrIn);
Geom::Vec3f* typedOut = m_typedBuffer;
const VECD* typedIn = reinterpret_cast<const VECD*>(ptrIn);
VECF* typedOut = m_typedBuffer;
// compute conversion
for (unsigned int i = 0; i < m_nb; ++i)
{
const Geom::Vec3d& vd = *typedIn++;
*typedOut++ = Geom::Vec3f(float(vd[0]),float(vd[1]),float(vd[2]));
const VECD& vd = *typedIn++;
for (unsigned int j=0; j<D; ++j)
(*typedOut)[j] = float(vd[j]);
typedOut++;
}
}
unsigned int vectorSize()
{
return 3;
return D;
}
};
typedef ConvertVecXdToVecXf<2> ConvertVec2dToVec2f;
typedef ConvertVecXdToVecXf<3> ConvertVec3dToVec3f;
typedef ConvertVecXdToVecXf<4> ConvertVec4dToVec4f;
typedef ConvertToFloat<double> ConvertDoubleToFloat;
......
......@@ -101,6 +101,39 @@ void VBO::updateData(const AttributeMultiVectorGen* attrib)
return;
}
const AttributeMultiVector<Geom::Vec3d>* amv3 = dynamic_cast<const AttributeMultiVector<Geom::Vec3d>*>(attrib);
if (amv3 != NULL)
{
ConvertVec3dToVec3f conv;
updateData_withConversion(attrib,&conv);
return;
}
const AttributeMultiVector<Geom::Vec2d>* amv2 = dynamic_cast<const AttributeMultiVector<Geom::Vec2d>*>(attrib);
if (amv2 != NULL)
{
ConvertVec2dToVec2f conv;
updateData_withConversion(attrib,&conv);
return;
}
const AttributeMultiVector<Geom::Vec4d>* amv4 = dynamic_cast<const AttributeMultiVector<Geom::Vec4d>*>(attrib);
if (amv4 != NULL)
{
ConvertVec4dToVec4f conv;
updateData_withConversion(attrib,&conv);
return;
}
const AttributeMultiVector<double>* amv1 = dynamic_cast<const AttributeMultiVector<double>*>(attrib);
if (amv1 != NULL)
{
ConvertDoubleToFloat conv;
updateData_withConversion(attrib,&conv);
return;
}
m_name = attrib->getName();
m_typeName = attrib->getTypeName();
......@@ -140,7 +173,7 @@ void VBO::updateData_withConversion(const AttributeMultiVectorGen* attrib, Conve
unsigned int byteTableSize;
unsigned int nbb = attrib->getBlocksPointers(addr, byteTableSize);
// m_nbElts = nbb * attrib->getBlockSize()/m_data_size;
m_nbElts = nbb * attrib->getBlockSize()/(m_data_size*sizeof(float));
// bind buffer to update
glBindBuffer(GL_ARRAY_BUFFER, *m_id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment