Commit ac226cdf authored by Sylvain Thery's avatar Sylvain Thery

add easy way to use double in position and normal attributes

parent 7c026cab
......@@ -55,36 +55,37 @@ void ColorPerEdgeRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboColor
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
typedef Geom::Vec3f VEC3F;
std::vector<VEC3> buffer;
std::vector<VEC3F> buffer;
buffer.reserve(16384);
std::vector<VEC3> bufferColors;
std::vector<VEC3F> bufferColors;
bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP, EDGE> traEdge(map);
for (Dart d=traEdge.begin(); d!=traEdge.end(); d=traEdge.next())
{
buffer.push_back(positions[d]);
bufferColors.push_back(colorPerXXX[d]);
buffer.push_back(PFP::toVec3f(positions[d]);
bufferColors.push_back(PFP::toVec3f(colorPerXXX[d]));
Dart e = map.phi2(d);
buffer.push_back(positions[e]);
bufferColors.push_back(colorPerXXX[e]);
buffer.push_back(PFP::toVec3f(positions[e]));
bufferColors.push_back(PFP::toVec3f(colorPerXXX[e])) ;
}
m_nbEdges = buffer.size()/2;
vboPosition.setDataSize(3);
vboPosition.allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(vboPosition.lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
VEC3F* ptrPos = reinterpret_cast<VEC3F*>(vboPosition.lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3F));
vboPosition.releasePtr();
vboColor.setDataSize(3);
vboColor.allocate(bufferColors.size());
VEC3* ptrCol = reinterpret_cast<VEC3*>(vboColor.lockPtr());
memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3));
VEC3F* ptrCol = reinterpret_cast<VEC3F*>(vboColor.lockPtr());
memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3F));
vboColor.releasePtr();
}
......
......@@ -55,11 +55,12 @@ void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboColor
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
typedef Geom::Vec3f VEC3F;
std::vector<VEC3> buffer;
std::vector<VEC3F> buffer;
buffer.reserve(16384);
std::vector<VEC3> bufferColors;
std::vector<VEC3F> bufferColors;
bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP, FACE> traFace(map);
......@@ -87,14 +88,14 @@ void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboColor
vboPosition.setDataSize(3);
vboPosition.allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(vboPosition.lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
VEC3F* ptrPos = reinterpret_cast<VEC3F*>(vboPosition.lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3F));
vboPosition.releasePtr();
vboColor.setDataSize(3);
vboColor.allocate(bufferColors.size());
VEC3* ptrCol = reinterpret_cast<VEC3*>(vboColor.lockPtr());
memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3));
VEC3F* ptrCol = reinterpret_cast<VEC3F*>(vboColor.lockPtr());
memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3F));
vboColor.releasePtr();
}
......@@ -105,14 +106,15 @@ void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboNorma
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
typedef Geom::Vec3f VEC3F;
std::vector<VEC3> buffer;
std::vector<VEC3F> buffer;
buffer.reserve(16384);
std::vector<VEC3> bufferNormals;
std::vector<VEC3F> bufferNormals;
bufferNormals.reserve(16384);
std::vector<VEC3> bufferColors;
std::vector<VEC3F> bufferColors;
bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP, FACE> traFace(map);
......@@ -125,15 +127,15 @@ void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboNorma
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
buffer.push_back(positions[d]);
bufferNormals.push_back(normals[d]);
bufferColors.push_back(colorPerXXX[d]);
buffer.push_back(positions[b]);
bufferNormals.push_back(normals[b]);
bufferColors.push_back(colorPerXXX[b]);
buffer.push_back(positions[c]);
bufferNormals.push_back(normals[c]);
bufferColors.push_back(colorPerXXX[c]);
buffer.push_back(PFP::toVec3f(positions[d]));
bufferNormals.push_back(PFP::toVec3f(normals[d]));
bufferColors.push_back(PFP::toVec3f(colorPerXXX[d]));
buffer.push_back(PFP::toVec3f(positions[b]));
bufferNormals.push_back(PFP::toVec3f(normals[b]);
bufferColors.push_back(PFP::toVec3f(colorPerXXX[b]));
buffer.push_back(PFP::toVec3f(positions[c]);
bufferNormals.push_back(PFP::toVec3f(normals[c]));
bufferColors.push_back(PFP::toVec3f(colorPerXXX[c]));
b = c;
c = map.phi1(b);
} while (c != d);
......@@ -143,20 +145,20 @@ void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboNorma
vboPosition.setDataSize(3);
vboPosition.allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(vboPosition.lockPtr());
memcpy(ptrPos, &buffer[0], buffer.size()*sizeof(VEC3));
VEC3F* ptrPos = reinterpret_cast<VEC3F*>(vboPosition.lockPtr());
memcpy(ptrPos, &buffer[0], buffer.size()*sizeof(VEC3F));
vboPosition.releasePtr();
vboNormal.setDataSize(3);
vboNormal.allocate(bufferColors.size());
VEC3* ptrNorm = reinterpret_cast<VEC3*>(vboNormal.lockPtr());
memcpy(ptrNorm, &bufferColors[0], bufferColors.size()*sizeof(VEC3));
VEC3F* ptrNorm = reinterpret_cast<VEC3F*>(vboNormal.lockPtr());
memcpy(ptrNorm, &bufferColors[0], bufferColors.size()*sizeof(VEC3F));
vboNormal.releasePtr();
vboColor.setDataSize(3);
vboColor.allocate(bufferColors.size());
VEC3* ptrCol = reinterpret_cast<VEC3*>(vboColor.lockPtr());
memcpy(ptrCol, &bufferColors[0], bufferColors.size()*sizeof(VEC3));
VEC3F* ptrCol = reinterpret_cast<VEC3F*>(vboColor.lockPtr());
memcpy(ptrCol, &bufferColors[0], bufferColors.size()*sizeof(VEC3F));
vboColor.releasePtr();
}
......
......@@ -54,8 +54,9 @@ DataPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboData, typen
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
typedef Geom::Vec3f VEC3F;
std::vector<VEC3> buffer;
std::vector<VEC3F> buffer;
buffer.reserve(16384);
std::vector<T> bufferData;
......@@ -71,11 +72,11 @@ DataPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboData, typen
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
buffer.push_back(positions[d]);
buffer.push_back(PFP::toVec3f(positions[d]));
bufferData.push_back(dataPerXXX[d]);
buffer.push_back(positions[b]);
buffer.push_back(PFP::toVec3f(positions[b]));
bufferData.push_back(dataPerXXX[b]);
buffer.push_back(positions[c]);
buffer.push_back(PFP::toVec3f(positions[c]));
bufferData.push_back(dataPerXXX[c]);
b = c;
c = map.phi1(b);
......@@ -86,8 +87,8 @@ DataPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboData, typen
vboPosition.setDataSize(3);
vboPosition.allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(vboPosition.lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
VEC3F* ptrPos = reinterpret_cast<VEC3F*>(vboPosition.lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3F));
vboPosition.releasePtr();
assert(sizeof(T) % sizeof(float) == 0 || !"DataPerFaceRender::updateVBO: VBO's only work with data types which are a multiple of 4 bytes") ;
......
......@@ -22,6 +22,8 @@
* *
*******************************************************************************/
#include "Geometry/vector_gen.h"
namespace CGoGN
{
......@@ -34,11 +36,12 @@ namespace Render
template<typename PFP>
void drawerAddEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions, float k)
{
const typename PFP::VEC3& P = positions[d];
const Geom::Vec3f& P = PFP::toVec3f(positions[d]);
Dart e = map.phi1(d);
const typename PFP::VEC3& Q = positions[e];
const Geom::Vec3f& Q = PFP::toVec3f(positions[e]);
typename PFP::VEC3 C = (P+Q)/ typename PFP::REAL(2.0);
Geom::Vec3f C = (P+Q)/ typename PFP::REAL(2.0);
dr.vertex(C*(1.0f-k) + k*P);
dr.vertex(C*(1.0f-k) + k*Q);
......@@ -47,9 +50,9 @@ void drawerAddEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vert
template<typename PFP>
void drawerAddEdgeShrink(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions, const typename PFP::VEC3& C, float k)
{
const typename PFP::VEC3& P = positions[d];
const Geom::Vec3f& P = PFP::toVec3f(positions[d]);
Dart e = map.phi1(d);
const typename PFP::VEC3& Q = positions[e];
const Geom::Vec3f& Q = PFP::toVec3f(positions[e]);
dr.vertex(C*(1.0f-k) + k*P);
dr.vertex(C*(1.0f-k) + k*Q);
......@@ -58,7 +61,7 @@ void drawerAddEdgeShrink(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, cons
template<typename PFP>
void drawerAddFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions, float k)
{
typename PFP::VEC3 C = Algo::Surface::Geometry::faceCentroid<PFP>(map,d,positions);
Geom::Vec3f C = PFP::toVec3f(Algo::Surface::Geometry::faceCentroid<PFP>(map,d,positions));
Traversor2FE<typename PFP::MAP> trav(map,d);
for (Dart e=trav.begin(); e!=trav.end(); e=trav.next())
......@@ -70,7 +73,7 @@ void drawerAddFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vert
template<typename PFP>
void drawerAddVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions,float k)
{
typename PFP::VEC3 C = Algo::Surface::Geometry::volumeCentroid<PFP>(map,d,positions);
Geom::Vec3f C = PFP::toVec3f(Algo::Surface::Geometry::volumeCentroid<PFP>(map,d,positions));
Traversor3WE<typename PFP::MAP> trav(map,d);
for (Dart e=trav.begin(); e!=trav.end(); e=trav.next())
......
......@@ -123,6 +123,7 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
{
typedef typename EMBV::DATA_TYPE VEC3;
typedef typename PFP::REAL REAL;
typedef Geom::Vec3f VEC3F;
Map3& map = dynamic_cast<Map3&>(mapx); // TODO reflechir comment virer ce warning quand on compile avec PFP::MAP=Map3
......@@ -144,15 +145,15 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
DartAutoAttribute<VEC3> fv2(mapx);
m_vbo2->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW);
GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* colorDartBuf = reinterpret_cast<VEC3*>(ColorDartsBuffer);
VEC3F* colorDartBuf = reinterpret_cast<VEC3F*>(ColorDartsBuffer);
if (m_bufferDartPosition!=NULL)
delete m_bufferDartPosition;
m_bufferDartPosition = new Geom::Vec3f[2*m_nbDarts];
VEC3* positionDartBuf = reinterpret_cast<VEC3*>(m_bufferDartPosition);
m_bufferDartPosition = new VEC3F[2*m_nbDarts];
VEC3F* positionDartBuf = reinterpret_cast<VEC3F*>(m_bufferDartPosition);
unsigned int posDBI=0;
......@@ -194,8 +195,8 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
VEC3 PP = 0.56f*P + 0.44f*Q;
VEC3 QQ = 0.56f*Q + 0.44f*P;
*positionDartBuf++ = P;
*positionDartBuf++ = PP;
*positionDartBuf++ = PFP::toVec3f(P);
*positionDartBuf++ = PFP::toVec3f(PP);
if (map.isBoundaryMarked3(d))
{
*colorDartBuf++ = m_boundaryDartsColor;
......@@ -212,8 +213,8 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
fv2[d] = (P+PP)*0.5f;
*positionDartBuf++ = Q;
*positionDartBuf++ = QQ;
*positionDartBuf++ = PFP::toVec3f(Q);
*positionDartBuf++ = PFP::toVec3f(QQ);
Dart dx = map.phi3(d);
if (map.isBoundaryMarked3(dx))
......@@ -239,14 +240,14 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
glUnmapBuffer(GL_ARRAY_BUFFER);
m_vbo0->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), m_bufferDartPosition, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), m_bufferDartPosition, GL_STREAM_DRAW);
// alpha2
m_vbo1->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW);
GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* positionF2 = reinterpret_cast<VEC3*>(PositionBuffer2);
VEC3F* positionF2 = reinterpret_cast<VEC3F*>(PositionBuffer2);
m_nbRel2=0;
......@@ -256,8 +257,8 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
//if (d < e)
{
*positionF2++ = fv2[d];
*positionF2++ = fv2[e];
*positionF2++ = PFP::toVec3f(fv2[d]);
*positionF2++ = PFP::toVec3f(fv2[e]);
m_nbRel2++;
}
}
......@@ -271,12 +272,16 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
template<typename PFP>
void Topo3PrimalRender::computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute<typename PFP::VEC3>& posExpl)
{
typedef Geom::Vec3f VEC3F;
typedef typename PFP::VEC3 VEC3;
m_vbo0->bind();
typename PFP::VEC3* positionsPtr = reinterpret_cast<typename PFP::VEC3*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY));
VEC3F* positionsPtr = reinterpret_cast<VEC3F*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY));
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
posExpl[d] = (positionsPtr[m_attIndex[d]] + positionsPtr[m_attIndex[d]+1])*0.5f;
const VEC3F& v =(positionsPtr[m_attIndex[d]] + positionsPtr[m_attIndex[d]+1])*0.5f;
posExpl[d] = PFP::toVec3f(v);
}
m_vbo0->bind();
......
This diff is collapsed.
......@@ -80,6 +80,8 @@ void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute<typena
}
}
template<typename PFP>
void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, bool withBoundary)
{
......@@ -88,6 +90,8 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
typedef Geom::Vec3f VEC3F;
std::vector<Dart> vecDarts;
vecDarts.reserve(mapx.getNbDarts()); // no problem dart is int: no problem of memory
......@@ -112,9 +116,9 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
DartAutoAttribute<VEC3> fv2(mapx);
m_vbo3->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW);
GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* colorDartBuf = reinterpret_cast<VEC3*>(ColorDartsBuffer);
VEC3F* colorDartBuf = reinterpret_cast<VEC3F*>(ColorDartsBuffer);
// m_vbo0->bind();
// glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW);
......@@ -124,7 +128,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
if (m_bufferDartPosition!=NULL)
delete m_bufferDartPosition;
m_bufferDartPosition = new Geom::Vec3f[2*m_nbDarts];
VEC3* positionDartBuf = reinterpret_cast<VEC3*>(m_bufferDartPosition);
VEC3F* positionDartBuf = reinterpret_cast<VEC3F*>(m_bufferDartPosition);
std::vector<VEC3> vecPos;
vecPos.reserve(16);
......@@ -172,8 +176,8 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
m_attIndex[d] = indexDC;
indexDC+=2;
*positionDartBuf++ = P;
*positionDartBuf++ = Q;
*positionDartBuf++ = PFP::toVec3f(P);
*positionDartBuf++ = PFP::toVec3f(Q);
*colorDartBuf++ = m_dartsColor;
*colorDartBuf++ = m_dartsColor;
VEC3 f = P*0.5f + Q*0.5f;
......@@ -215,8 +219,8 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
m_attIndex[d] = indexDC;
indexDC+=2;
*positionDartBuf++ = P;
*positionDartBuf++ = Q;
*positionDartBuf++ = PFP::toVec3f(P);
*positionDartBuf++ = PFP::toVec3f(Q);
*colorDartBuf++ = m_dartsBoundaryColor;
*colorDartBuf++ = m_dartsBoundaryColor;
VEC3 f = P*0.5f + Q*0.5f;
......@@ -233,22 +237,22 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
}
m_vbo0->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), m_bufferDartPosition, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), m_bufferDartPosition, GL_STREAM_DRAW);
// glUnmapBuffer(GL_ARRAY_BUFFER);
m_vbo3->bind();
glUnmapBuffer(GL_ARRAY_BUFFER);
m_vbo1->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW);
GLvoid* PositionBuffer1 = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
m_vbo2->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW);
GLvoid* PositionBuffer2 = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* positionF1 = reinterpret_cast<VEC3*>(PositionBuffer1);
VEC3* positionF2 = reinterpret_cast<VEC3*>(PositionBuffer2);
VEC3F* positionF1 = reinterpret_cast<VEC3F*>(PositionBuffer1);
VEC3F* positionF2 = reinterpret_cast<VEC3F*>(PositionBuffer2);
m_nbRel2 =0;
for(std::vector<Dart>::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++)
......@@ -260,14 +264,14 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
// if (good(e) && (e.index > d.index))
if ( (withBoundary || !mapx.isBoundaryMarked2(e)) && (e.index > d.index))
{
*positionF2++ = fv2[d];
*positionF2++ = fv2[e];
*positionF2++ = PFP::toVec3f(fv2[d]);
*positionF2++ = PFP::toVec3f(fv2[e]);
m_nbRel2++;
}
e = mapx.phi1(d);
*positionF1++ = fv1[d];
*positionF1++ = fv11[e];
*positionF1++ = PFP::toVec3f(fv1[d]);
*positionF1++ = PFP::toVec3f(fv11[e]);
}
m_nbRel1 = vecDarts.size();
......@@ -286,6 +290,8 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
typedef Geom::Vec3f VEC3F;
std::vector<Dart> vecDarts;
vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory
......@@ -311,14 +317,14 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
DartAutoAttribute<VEC3> fv2(map);
m_vbo3->bind();
glBufferData(GL_ARRAY_BUFFER, 4*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 4*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW);
GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* colorDartBuf = reinterpret_cast<VEC3*>(ColorDartsBuffer);
VEC3F* colorDartBuf = reinterpret_cast<VEC3F*>(ColorDartsBuffer);
m_vbo0->bind();
glBufferData(GL_ARRAY_BUFFER, 4*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 4*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW);
GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* positionDartBuf = reinterpret_cast<VEC3*>(PositionDartsBuffer);
VEC3F* positionDartBuf = reinterpret_cast<VEC3F*>(PositionDartsBuffer);
std::vector<VEC3> vecPos;
vecPos.reserve(16);
......@@ -366,13 +372,13 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
m_attIndex[d] = indexDC;
indexDC+=2;
*positionDartBuf++ = P;
*positionDartBuf++ = PFP::toVec3f(P);
*colorDartBuf++ = m_dartsColor;
*positionDartBuf++ = PP;
*positionDartBuf++ = PFP::toVec3f(PP);
*colorDartBuf++ = m_dartsColor;
*positionDartBuf++ = Q;
*positionDartBuf++ = PFP::toVec3f(Q);
*colorDartBuf++ = m_dartsColor;
*positionDartBuf++ = QQ;
*positionDartBuf++ = PFP::toVec3f(QQ);
*colorDartBuf++ = m_dartsColor;
VEC3 f = P*0.5f + PP*0.5f;
......@@ -402,15 +408,15 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
glUnmapBuffer(GL_ARRAY_BUFFER);
m_vbo1->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW);
GLvoid* PositionBuffer1 = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
m_vbo2->bind();
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW);
GLvoid* PositionBuffer2 = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
VEC3* positionF1 = reinterpret_cast<VEC3*>(PositionBuffer1);
VEC3* positionF2 = reinterpret_cast<VEC3*>(PositionBuffer2);
VEC3F* positionF1 = reinterpret_cast<VEC3F*>(PositionBuffer1);
VEC3F* positionF2 = reinterpret_cast<VEC3F*>(PositionBuffer2);
m_nbRel2 = 0;
for(std::vector<Dart>::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++)
......@@ -420,14 +426,14 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
// if (d < e )
if ( (withBoundary || !map.isBoundaryMarked2(e)) && (d < e ))
{
*positionF2++ = fv2[d];
*positionF2++ = fv2[e];
*positionF2++ = PFP::toVec3f(fv2[d]);
*positionF2++ = PFP::toVec3f(fv2[e]);
m_nbRel2++;
}
e = map.beta1(d);
*positionF1++ = fv1[d];
*positionF1++ = fv1[e];
*positionF1++ = PFP::toVec3f(fv1[d]);
*positionF1++ = PFP::toVec3f(fv1[e]);
}
m_nbRel1 = vecDarts.size()/2;
......
......@@ -4,6 +4,7 @@
#include <limits>
#include <math.h>
#include <iostream>
#include "Geometry/vector_gen.h"
namespace CGoGN
{
......@@ -11,10 +12,10 @@ namespace CGoGN
/**
* Conversion d'un T* en U* en fonction de la surcharge des membres
* Classe abstraite, a surcharger:
* - reserve(), convert() & destructeur (exemple dans ConvertSimpleCast)
* - reserve(), convert(), release() & vectorSize()
*
*/
class ConvertAttrib
class ConvertBuffer
{
protected:
/**
......@@ -27,70 +28,81 @@ protected:
*/
unsigned int m_nb;
/**
* size of element in input
*/
unsigned int m_szElt;
/**
* buffer
*/
void* m_buffer;
public:
/**
* size of buffer in
*
*/
ConvertAttrib() : m_size(0),m_nb(0),m_buffer(NULL) {}
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) {}
/**
* size of buffer in
*
*/
virtual ~ConvertAttrib() {}
// virtual ~ConvertBuffer() = 0;
~ConvertBuffer() {}
/**
* set the number of element to convert & reserve memory for buffer
* @param nb nb elements (usually block size when call from VBO)
*/
virtual void reserve(unsigned int nb) = 0;
/**
* release memory buffer ( and set ptr to null)
* release memory buffer ( and set ptrs to null)
*/
virtual void release();
virtual void release() = 0;
/**
* convert a table to tbe buffer
* convert the buffer