Commit 5f970d8b authored by Pierre Kraemer's avatar Pierre Kraemer

changes in VBO update -> no more template

parent 961a4d0e
......@@ -33,6 +33,7 @@ public slots:
bool isUsed() const { return !l_views.empty(); }
bool isShared() const { return l_views.size() > 1; }
qglviewer::Camera::Type getType() { return type(); }
void changeType(qglviewer::Camera::Type type);
/*********************************************************
......
......@@ -226,15 +226,13 @@ public:
void initPrimitives(int prim, std::vector<GLuint>& tableIndices) ;
/**
* initialization of the VBO indices primitives
* using the given table
* return if the given primitive connectivity VBO is up to date
* @param prim primitive to draw: POINT_INDICES, LINE_INDICES, TRIANGLE_INDICES
*/
bool isPrimitiveUpToDate(int prim) { return m_indexBufferUpToDate[prim]; }
/**
* initialization of the VBO indices primitives
* using the given table
* set the given primitive connectivity VBO dirty
* @param prim primitive to draw: POINT_INDICES, LINE_INDICES, TRIANGLE_INDICES
*/
void setPrimitiveDirty(int prim) { m_indexBufferUpToDate[prim] = false; }
......
......@@ -96,21 +96,21 @@ public:
/**
* get / set name of the attribute
*/
const std::string& getName();
const std::string& getName() const;
void setName(const std::string& n);
/**
* get / set name of the type of the attribute
*/
const std::string& getTypeName();
const std::string& getTypeName() const;
void setTypeName(const std::string& n);
/**
* get block size
*/
unsigned int getBlockSize();
unsigned int getBlockSize() const;
/**************************************
* MULTI VECTOR MANAGEMENT *
......@@ -141,11 +141,16 @@ public:
*/
virtual void clear() = 0;
/**
* get size of type
*/
virtual int getSizeOfType() const = 0;
/**************************************
* DATA ACCESS *
**************************************/
virtual unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& byteBlockSize) = 0;
virtual unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& byteBlockSize) const = 0;
/**************************************
* LINES MANAGEMENT *
......@@ -258,6 +263,8 @@ public:
void clear();
int getSizeOfType() const;
/**************************************
* DATA ACCESS *
**************************************/
......@@ -277,7 +284,7 @@ public:
/**
* Get the addresses of each block of data
*/
unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& byteBlockSize);
unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& byteBlockSize) const;
/**************************************
* LINES MANAGEMENT *
......
......@@ -60,7 +60,7 @@ inline void AttributeMultiVectorGen::setIndex(unsigned int i)
m_index = i ;
}
inline const std::string& AttributeMultiVectorGen::getName()
inline const std::string& AttributeMultiVectorGen::getName() const
{
return m_attrName;
}
......@@ -70,7 +70,7 @@ inline void AttributeMultiVectorGen::setName(const std::string& n)
m_attrName = n ;
}
inline const std::string& AttributeMultiVectorGen::getTypeName()
inline const std::string& AttributeMultiVectorGen::getTypeName() const
{
return m_typeName;
}
......@@ -80,7 +80,7 @@ inline void AttributeMultiVectorGen::setTypeName(const std::string& n)
m_typeName = n ;
}
inline unsigned int AttributeMultiVectorGen::getBlockSize()
inline unsigned int AttributeMultiVectorGen::getBlockSize() const
{
return _BLOCKSIZE_ ;
}
......@@ -261,6 +261,12 @@ inline void AttributeMultiVector<T>::clear()
m_tableData.clear();
}
template <typename T>
inline int AttributeMultiVector<T>::getSizeOfType() const
{
return sizeof(T);
}
/**************************************
* DATA ACCESS *
**************************************/
......@@ -278,14 +284,14 @@ inline const T& AttributeMultiVector<T>::operator[](unsigned int i) const
}
template <typename T>
unsigned int AttributeMultiVector<T>::getBlocksPointers(std::vector<void*>& addr, unsigned int& byteBlockSize)
unsigned int AttributeMultiVector<T>::getBlocksPointers(std::vector<void*>& addr, unsigned int& byteBlockSize) const
{
byteBlockSize = _BLOCKSIZE_ * sizeof(T);
addr.reserve(m_tableData.size());
addr.clear();
for (typename std::vector<T*>::iterator it = m_tableData.begin(); it != m_tableData.end(); ++it)
for (typename std::vector<T*>::const_iterator it = m_tableData.begin(); it != m_tableData.end(); ++it)
addr.push_back(*it);
return addr.size();
......
......@@ -43,7 +43,6 @@ public:
virtual void clear(bool removeAttrib) ;
/****************************************
* ATTRIBUTES MANAGEMENT *
****************************************/
......@@ -72,6 +71,14 @@ public:
template <typename T, unsigned int ORBIT>
AttributeHandler<T, ORBIT> getAttribute(const std::string& nameAttr) ;
/**
* @brief get a generic pointer to an existing attribute multi vector
* @param orbit the concerned orbit
* @param nameAttr attribute name
* @return a pointer to an AttributeMultiVectorGen
*/
AttributeMultiVectorGen* getAttributeVectorGen(unsigned int orbit, const std::string& nameAttr) ;
/**
* check if an attribute exist ( get, test if valid and add if necessary)
* @param nameAttr attribute name
......
......@@ -40,8 +40,9 @@ inline bool AttribMap::removeAttribute(AttributeHandler<T, ORBIT>& attr)
assert(attr.isValid() || !"Invalid attribute handler") ;
if(m_attribs[attr.getOrbit()].template removeAttribute<T>(attr.getIndex()))
{
AttributeMultiVectorGen* amv = attr.getDataVector();
typedef std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator IT ;
std::pair<IT, IT> bounds = attributeHandlers.equal_range(attr.getDataVector()) ;
std::pair<IT, IT> bounds = attributeHandlers.equal_range(amv) ;
for(IT i = bounds.first; i != bounds.second; ++i)
(*i).second->setInvalid() ;
attributeHandlers.erase(bounds.first, bounds.second) ;
......@@ -62,7 +63,7 @@ inline AttributeHandler<T ,ORBIT> AttribMap::checkAttribute(const std::string& n
{
AttributeHandler<T,ORBIT> att = this->getAttribute<T,ORBIT>(nameAttr);
if (!att.isValid())
att = this->addAttribute<T,ORBIT>("position");
att = this->addAttribute<T,ORBIT>(nameAttr);
return att;
}
......
......@@ -45,7 +45,9 @@ protected:
bool valid ;
public:
AttributeHandlerGen(GenericMap* m, bool v) : m_map(m), valid(v)
AttributeHandlerGen(GenericMap* m, bool v) :
m_map(m),
valid(v)
{}
GenericMap* map() const
......@@ -58,8 +60,14 @@ public:
return valid ;
}
virtual int getSizeOfType() const = 0;
virtual unsigned int getOrbit() const = 0;
virtual const std::string& name() const = 0;
// virtual const std::string& typeName() const = 0;
virtual const std::string& typeName() const = 0;
virtual AttributeMultiVectorGen* getDataVectorGen() const = 0;
protected:
void setInvalid()
......@@ -138,10 +146,20 @@ public:
*/
AttributeMultiVector<T>* getDataVector() const ;
/**
* get attribute data vector (generic MultiVector)
*/
virtual AttributeMultiVectorGen* getDataVectorGen() const ;
/**
* get size of attribute type
*/
virtual int getSizeOfType() const ;
/**
* get attribute orbit
*/
unsigned int getOrbit() const ;
virtual unsigned int getOrbit() const ;
/**
* get attribute index
......@@ -153,10 +171,10 @@ public:
*/
virtual const std::string& name() const ;
// /**
// * get attribute type name
// */
// virtual const std::string& typeName() const ;
/**
* get attribute type name
*/
virtual const std::string& typeName() const ;
/**
* give the number of elements of the attribute container
......
......@@ -57,7 +57,6 @@ AttributeHandler<T, ORBIT>::AttributeHandler() :
AttributeHandlerGen(NULL, false), m_attrib(NULL)
{}
template <typename T, unsigned int ORBIT>
AttributeHandler<T, ORBIT>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) :
AttributeHandlerGen(m, false), m_attrib(amv)
......@@ -74,7 +73,8 @@ AttributeHandler<T, ORBIT>::AttributeHandler(GenericMap* m, AttributeMultiVector
template <typename T, unsigned int ORBIT>
AttributeHandler<T, ORBIT>::AttributeHandler(const AttributeHandler<T, ORBIT>& ta) :
AttributeHandlerGen(ta.m_map, ta.valid), m_attrib(ta.m_attrib)
AttributeHandlerGen(ta.m_map, ta.valid),
m_attrib(ta.m_attrib)
{
if(valid)
registerInMap() ;
......@@ -138,6 +138,18 @@ inline AttributeMultiVector<T>* AttributeHandler<T, ORBIT>::getDataVector() cons
return m_attrib ;
}
template <typename T, unsigned int ORBIT>
inline AttributeMultiVectorGen* AttributeHandler<T, ORBIT>::getDataVectorGen() const
{
return m_attrib ;
}
template <typename T, unsigned int ORBIT>
inline int AttributeHandler<T, ORBIT>::getSizeOfType() const
{
return sizeof(T) ;
}
template <typename T, unsigned int ORBIT>
inline unsigned int AttributeHandler<T, ORBIT>::getOrbit() const
{
......@@ -156,11 +168,11 @@ inline const std::string& AttributeHandler<T, ORBIT>::name() const
return m_attrib->getName() ;
}
//template <typename T, unsigned int ORBIT>
//inline const std::string& AttributeHandler<T, ORBIT>::typeName() const
//{
// return nameOfType(T()) ;
//}
template <typename T, unsigned int ORBIT>
inline const std::string& AttributeHandler<T, ORBIT>::typeName() const
{
return m_attrib->getTypeName();
}
template <typename T, unsigned int ORBIT>
......
......@@ -28,83 +28,6 @@ namespace CGoGN
namespace Utils
{
template <typename ATTR_HANDLER>
void VBO::updateData(const ATTR_HANDLER& attrib)
{
if (m_lock)
{
CGoGNerr << "Error locked VBO" << CGoGNendl;
return;
}
m_name = attrib.name();
m_typeName = nameOfType(typename ATTR_HANDLER::DATA_TYPE());
m_data_size = sizeof(typename ATTR_HANDLER::DATA_TYPE) / sizeof(float);
AttributeMultiVector<typename ATTR_HANDLER::DATA_TYPE>* mv = attrib.getDataVector() ;
std::vector<void*> addr;
unsigned int byteTableSize;
unsigned int nbb = mv->getBlocksPointers(addr, byteTableSize);
glBindBuffer(GL_ARRAY_BUFFER, *m_id);
glBufferData(GL_ARRAY_BUFFER, nbb * byteTableSize, 0, GL_STREAM_DRAW);
m_nbElts = nbb * byteTableSize / sizeof(typename ATTR_HANDLER::DATA_TYPE);
unsigned int offset = 0;
for (unsigned int i = 0; i < nbb; ++i)
{
glBufferSubDataARB(GL_ARRAY_BUFFER, offset, byteTableSize, addr[i]);
offset += byteTableSize;
}
}
template <typename ATTR_HANDLER>
void VBO::updateData(const ATTR_HANDLER& attrib, ConvertAttrib* conv)
{
if (m_lock)
{
CGoGNerr << "Error locked VBO" << CGoGNendl;
return;
}
m_name = attrib.name();
m_typeName = nameOfType(typename ATTR_HANDLER::DATA_TYPE());
m_data_size = conv->sizeElt();
AttributeMultiVector<typename ATTR_HANDLER::DATA_TYPE>* mv = attrib.getDataVector() ;
std::vector<void*> addr;
unsigned int byteTableSize;
unsigned int nbb = mv->getBlocksPointers(addr, byteTableSize);
// alloue la memoire pour le buffer et initialise le conv
conv->reserve(mv->getBlockSize());
// bind buffer to update
glBindBuffer(GL_ARRAY_BUFFER, *m_id);
glBufferData(GL_ARRAY_BUFFER, nbb * conv->sizeBuffer(), 0, GL_STREAM_DRAW);
m_nbElts = nbb * conv->nbElt();
unsigned int offset = 0;
for (unsigned int i = 0; i < nbb; ++i)
{
// convertit les donnees dans le buffer de conv
conv->convert(addr[i]);
// update sub-vbo
glBufferSubDataARB(GL_ARRAY_BUFFER, offset, conv->sizeBuffer(), conv->buffer());
// block suivant
offset += conv->sizeBuffer();
}
// libere la memoire de la conversion
conv->release();
}
template <typename T>
void VBO::updateData(std::vector<T>& data)
{
......
......@@ -29,6 +29,7 @@
#include <vector>
#include "Utils/gl_def.h"
#include "Container/convert.h"
#include "Topology/generic/attributeHandler.h"
namespace CGoGN
{
......@@ -41,7 +42,7 @@ class GLSLShader;
/**
* Encapsulation of OpenGL Vertex Buffer Object
* Manage
* - alloc /release of GL buffer
* - alloc / release of GL buffer
* - ref by Shaders
* - size of data (invidual cells)
*/
......@@ -124,17 +125,15 @@ public:
/**
* update data from attribute handler to the vbo