Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CGoGN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Pitiot
CGoGN
Commits
807a3cd1
Commit
807a3cd1
authored
Jul 18, 2014
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new VBO updating conversions methods
parent
5ecec1a3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
499 additions
and
436 deletions
+499
-436
Apps/Tuto/Attributes/vbo_attribs.cpp
Apps/Tuto/Attributes/vbo_attribs.cpp
+14
-9
Apps/Tuto/Attributes/vbo_attribs.h
Apps/Tuto/Attributes/vbo_attribs.h
+2
-0
include/Container/convert.h
include/Container/convert.h
+411
-326
include/Utils/vbo_base.h
include/Utils/vbo_base.h
+39
-27
src/Utils/GLSLShader.cpp
src/Utils/GLSLShader.cpp
+1
-0
src/Utils/vbo.cpp
src/Utils/vbo.cpp
+32
-74
No files found.
Apps/Tuto/Attributes/vbo_attribs.cpp
View file @
807a3cd1
...
...
@@ -71,7 +71,7 @@ void MyQT::createMap()
// create another attribute on vertices (for edges drawing)
VertexAttribute
<
int
,
MAP
>
colorE
=
myMap
.
addAttribute
<
int
,
VERTEX
,
MAP
>
(
"colorE"
);
colorE
[
d1
]
=
0
;
colorE
[
d1
]
=
152
;
colorE
[
PHI1
(
d1
)]
=
255
;
colorE
[
PHI_1
(
d1
)]
=
64
;
colorE
[
PHI
<
11
>
(
d2
)]
=
127
;
...
...
@@ -96,21 +96,24 @@ void MyQT::createMap()
m_positionVBO
->
updateData
(
position
);
// update color edge with on the fly computation of RGB from int
m_colorVBO1
->
updateDataConversion
<
int
,
3
>
(
colorE
,
[](
const
float
&
x
)
{
return
Geom
::
Vec3f
(
float
(
x
)
/
255.0
f
,
float
(
255
-
x
)
/
255.0
f
,
1.0
f
);
});
// code writen in lambda
// m_colorVBO1->updateDataConversion<int,3>(colorE, [](const float& x)
// {
// return Geom::Vec3f(float(x)/255.0f,float(x)/255.0f,float(x)/255.0f);
// });
// or with furnished operator of conversion
DataConversion
::
operatorScalarToRGBf
<
int
>
conv2col
(
0
,
255
);
m_colorVBO1
->
updateDataConversion
<
int
,
3
>
(
colorE
,
conv2col
);
// update color face with on the fly inversion of RGB
m_colorVBO2
->
updateDataConversion
<
PFP
::
VEC3
,
3
>
(
colorF
,
[](
const
PFP
::
VEC3
&
c
)
{
return
Geom
::
Vec3f
(
float
(
1.0
-
c
[
0
]),
float
(
1.0
-
c
[
1
]),
float
(
1.0
-
c
[
2
]));
return
Geom
::
Vec3f
(
float
(
1.0
-
c
[
2
]),
float
(
1.0
-
c
[
1
]),
float
(
1.0
-
c
[
0
]));
});
// construct rendering primities
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
Algo
::
Render
::
GL2
::
TRIANGLES
);
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
Algo
::
Render
::
GL2
::
LINES
);
...
...
@@ -133,6 +136,8 @@ void MyQT::cb_initGL()
m_colorVBO1
=
new
Utils
::
VBO
();
m_colorVBO2
=
new
Utils
::
VBO
();
m_scalarVBO
=
new
Utils
::
VBO
();
// using simple shader with color
m_shader
=
new
Utils
::
ShaderSimpleColor
();
m_shader
->
setAttributePosition
(
m_positionVBO
);
...
...
@@ -152,7 +157,7 @@ void MyQT::cb_redraw()
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
glEnable
(
GL_CULL_FACE
);
glLineWidth
(
2
.0
f
);
glLineWidth
(
4
.0
f
);
m_shader2
->
setAttributeColor
(
m_colorVBO1
);
m_render
->
draw
(
m_shader2
,
Algo
::
Render
::
GL2
::
LINES
);
...
...
Apps/Tuto/Attributes/vbo_attribs.h
View file @
807a3cd1
...
...
@@ -72,6 +72,8 @@ protected:
Utils
::
VBO
*
m_colorVBO1
;
// color per vertex for face drawing
Utils
::
VBO
*
m_colorVBO2
;
// color per vertex for edge drawing
Utils
::
VBO
*
m_scalarVBO
;
// color per vertex for edge drawing
//shaders
Utils
::
ShaderSimpleColor
*
m_shader
;
Utils
::
ShaderColorPerVertex
*
m_shader2
;
...
...
include/Container/convert.h
View file @
807a3cd1
...
...
@@ -8,362 +8,447 @@
namespace
CGoGN
{
/**
* Conversion d'un T* en U* en fonction de la surcharge des membres
* Classe abstraite, a surcharger:
* - reserve(), convert(), release() & vectorSize()
*
*/
class
ConvertBuffer
namespace
DataConversion
{
protected:
/**
* size of buffer in bytes
*/
unsigned
int
m_size
;
/**
* size of buffer in number of elements
*/
unsigned
int
m_nb
;
/**
* buffer
*/
void
*
m_buffer
;
public:
/**
*
*/
ConvertBuffer
()
:
m_size
(
0
),
m_nb
(
0
),
m_buffer
(
NULL
)
{}
/**
*
*/
// 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 ptrs to null)
*/
virtual
void
release
()
=
0
;
/**
* convert the buffer
*/
virtual
void
convert
(
const
void
*
ptrIn
)
=
0
;
/**
* get the data size in elements (ex: 3 for Vec3f)
*/
virtual
unsigned
int
vectorSize
()
=
0
;
/**
* get the buffer (void*)
*/
void
*
buffer
()
{
return
m_buffer
;
}
/**
* get the size of buffer in bytes
*/
unsigned
int
sizeBuffer
()
{
return
m_size
;
}
template
<
unsigned
int
D
>
inline
Geom
::
Vector
<
D
,
float
>
funcVecXdToVecXf
(
const
Geom
::
Vector
<
D
,
double
>&
x
)
{
Geom
::
Vector
<
D
,
float
>
v
;
for
(
unsigned
int
j
=
0
;
j
<
D
;
++
j
)
v
[
j
]
=
float
(
x
[
j
]);
return
v
;
}
};
template
<
typename
TYPE_IN
>
inline
float
funcToFloat
(
const
TYPE_IN
&
x
)
{
return
float
(
x
);
}
/**
* Convertit simplement en castant chaque element
* Exemple double ou int float
*/
template
<
typename
TYPE_IN
>
class
ConvertToFloat
:
public
ConvertBuffer
class
operatorToFloatNormalized
{
protected:
float
*
m_typedBuffer
;
double
m_min
;
double
m_diff
;
public:
ConvertToFloat
()
{}
~
ConvertToFloat
()
{
if
(
m_typedBuffer
)
delete
[]
m_typedBuffer
;
}
operatorToFloatNormalized
(
TYPE_IN
min
,
TYPE_IN
max
)
:
m_min
(
double
(
min
)),
m_diff
(
double
(
max
-
min
))
{}
void
release
(
)
inline
float
operator
()
(
const
TYPE_IN
&
x
)
{
delete
[]
m_typedBuffer
;
m_typedBuffer
=
NULL
;
m_buffer
=
NULL
;
m_nb
=
0
;
m_size
=
0
;
}
void
reserve
(
unsigned
int
nb
)
{
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
}
void
convert
(
const
void
*
ptrIn
)
{
// cast ptr in & out with right type
const
TYPE_IN
*
typedIn
=
reinterpret_cast
<
const
TYPE_IN
*>
(
ptrIn
);
float
*
typedOut
=
reinterpret_cast
<
float
*>
(
m_buffer
);
// compute conversion
for
(
unsigned
int
i
=
0
;
i
<
m_nb
;
++
i
)
*
typedOut
++
=
float
(
*
typedIn
++
);
}
unsigned
int
vectorSize
()
{
return
1
;
double
v
=
(
double
(
x
)
-
m_min
)
/
m_diff
;
return
float
(
v
);
}
};
/**
* Convertit un type scalaire (char, short, int, ...)
* en un autre (float ou double) en le normalisant
* entre 0 et 1
*/
template
<
typename
TYPE_IN
,
typename
TYPE_OUT
>
class
ConvertNormalized
:
public
ConvertBuffer
template
<
typename
TYPE_IN
>
class
operatorScalarToRGBf
{
protected:
TYPE_OUT
*
m_typedBuffer
;
double
m_min
;
double
m_diff
;
public:
ConvertNormalized
()
/*:
ConvertBuffer(sizeof(TYPE_IN))*/
{}
~
ConvertNormalized
()
{
if
(
m_typedBuffer
)
delete
[]
m_typedBuffer
;
}
operatorScalarToRGBf
(
TYPE_IN
min
,
TYPE_IN
max
)
:
m_min
(
double
(
min
)),
m_diff
(
double
(
max
-
min
))
{}
void
release
(
)
inline
Geom
::
Vec3f
operator
()
(
const
TYPE_IN
&
x
)
{
if
(
m_typedBuffer
)
{
delete
[]
m_typedBuffer
;
m_typedBuffer
=
NULL
;
m_buffer
=
NULL
;
m_nb
=
0
;
m_size
=
0
;
}
}
void
reserve
(
unsigned
int
nb
)
{
m_nb
=
nb
;
// store number of elements
m_typedBuffer
=
new
TYPE_OUT
[
m_nb
];
// allocate buffer
m_buffer
=
m_typedBuffer
;
// store void* casted ptr
m_size
=
m_nb
*
sizeof
(
TYPE_OUT
);
// store size of buffer in bytes
}
void
convert
(
const
void
*
ptrIn
)
{
// cast ptr in & out with right type
const
TYPE_IN
*
typedIn
=
reinterpret_cast
<
const
TYPE_IN
*>
(
ptrIn
);
TYPE_OUT
*
typedOut
=
reinterpret_cast
<
TYPE_OUT
*>
(
m_buffer
);
// compute conversion
for
(
int
i
=
0
;
i
<
m_nb
;
++
i
)
double
h
=
(
360.0
/
m_diff
)
*
(
double
(
x
)
-
m_min
);
// normalize in 0-360
int
hi
=
int
(
floor
(
h
/
60.0
))
%
6
;
float
f
=
float
((
h
/
60.0
)
-
floor
(
h
/
60.0
));
float
q
=
1.0
f
-
f
;
switch
(
hi
)
{
TYPE_OUT
val
=
(
float
(
*
typedIn
++
)
-
TYPE_OUT
(
std
::
numeric_limits
<
TYPE_IN
>::
min
()));
val
/=
TYPE_OUT
(
std
::
numeric_limits
<
TYPE_IN
>::
max
())
-
TYPE_OUT
(
std
::
numeric_limits
<
TYPE_IN
>::
min
());
*
typedOut
++
=
val
;
case
0
:
return
Geom
::
Vec3f
(
0.0
f
,
f
,
1.0
f
);
break
;
case
1
:
return
Geom
::
Vec3f
(
0.0
f
,
1.0
f
,
q
);
break
;
case
2
:
return
Geom
::
Vec3f
(
f
,
1.0
f
,
0.0
f
);
break
;
case
3
:
return
Geom
::
Vec3f
(
1.0
f
,
q
,
0.0
f
);
break
;
case
4
:
return
Geom
::
Vec3f
(
1.0
f
,
0.0
f
,
f
);
break
;
case
5
:
return
Geom
::
Vec3f
(
q
,
0.0
f
,
1.0
f
);
default:
break
;
}
return
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
0.0
f
);
}
unsigned
int
vectorSize
()
{
return
1
;
}
};
}
/**
* Convertit un type scalaire (char, short, int, float ..)
* en une couleur variant suivant un schema hsv
* Un min et max donne les valeurs servant à l'interpolation
*/
template
<
typename
TYPE_IN
>
class
ConvertToRGBf
:
public
ConvertBuffer
{
protected:
float
*
m_typedBuffer
;
TYPE_IN
m_min
;
TYPE_IN
m_diff
;
public:
ConvertToRGBf
(
TYPE_IN
min
,
TYPE_IN
max
)
:
// ConvertBuffer(sizeof(TYPE_IN)),
m_min
(
min
),
m_diff
(
max
-
min
),
m_typedBuffer
(
NULL
)
{}
~
ConvertToRGBf
()
{
if
(
m_typedBuffer
)
delete
[]
m_typedBuffer
;
}
void
release
()
{
if
(
m_typedBuffer
)
{
delete
[]
m_typedBuffer
;
m_typedBuffer
=
NULL
;
m_buffer
=
NULL
;
m_nb
=
0
;
m_size
=
0
;
}
}
///**
// * Conversion d'un T* en U* en fonction de la surcharge des membres
// * Classe abstraite, a surcharger:
// * - reserve(), convert(), release() & vectorSize()
// *
// */
//class ConvertBuffer
//{
//protected:
// /**
// * size of buffer in bytes
// */
// unsigned int m_size;
void
reserve
(
unsigned
int
nb
)
{
m_nb
=
nb
;
// store number of elements
m_typedBuffer
=
new
float
[
3
*
nb
];
// allocate buffer
m_buffer
=
m_typedBuffer
;
// store void* casted ptr
m_size
=
3
*
nb
*
sizeof
(
float
);
// store size of buffer in bytes
}
// /**
// * size of buffer in number of elements
// */
// unsigned int m_nb;
// /**
// * buffer
// */
// void* m_buffer;
//public:
// /**
// *
// */
// ConvertBuffer() : m_size(0),m_nb(0),m_buffer(NULL) {}
// /**
// *
// */
//// 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 ptrs to null)
// */
// virtual void release() = 0;
// /**
// * convert the buffer
// */
// virtual void convert(const void* ptrIn) = 0;
// /**
// * get the data size in elements (ex: 3 for Vec3f)
// */
// virtual unsigned int vectorSize() = 0;
// /**
// * get the buffer (void*)
// */
// void* buffer() { return m_buffer; }
// /**
// * get the size of buffer in bytes
// */
// unsigned int sizeBuffer() { return m_size; }
//};
///**
//* Convertit simplement en castant chaque element
//* Exemple double ou int float
//*/
//template<typename TYPE_IN>
//class ConvertToFloat : public ConvertBuffer
//{
//protected:
// float* m_typedBuffer;
//public:
// ConvertToFloat()
// {}
// ~ConvertToFloat()
// {
// if (m_typedBuffer)
// delete[] m_typedBuffer;
// }
// void release()
// {
// delete[] m_typedBuffer;
// m_typedBuffer = NULL;
// m_buffer = NULL;
// m_nb = 0;
// m_size = 0;
// }
void
convert
(
const
void
*
ptrIn
)
{
// cast ptr in & out with right type
const
TYPE_IN
*
typedIn
=
reinterpret_cast
<
const
TYPE_IN
*>
(
ptrIn
);
float
*
typedOut
=
reinterpret_cast
<
float
*>
(
m_buffer
);
// void reserve(unsigned int nb)
// {
// 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
// }
// void convert(const void* ptrIn)
// {
// // cast ptr in & out with right type
// const TYPE_IN* typedIn = reinterpret_cast<const TYPE_IN*>(ptrIn);
// float* typedOut = reinterpret_cast<float*>(m_buffer);
// // compute conversion
// for (unsigned int i = 0; i < m_nb; ++i)
// *typedOut++ = float(*typedIn++);
// }
// unsigned int vectorSize()
// {
// return 1;
// }
//};
///**
//* Convertit un type scalaire (char, short, int, ...)
//* en un autre (float ou double) en le normalisant
//* entre 0 et 1
//*/
//template<typename TYPE_IN, typename TYPE_OUT>
//class ConvertNormalized : public ConvertBuffer
//{
//protected:
// TYPE_OUT* m_typedBuffer;
//public:
// ConvertNormalized()/*:
// ConvertBuffer(sizeof(TYPE_IN))*/
// {}
// ~ConvertNormalized()
// {
// if (m_typedBuffer)
// delete[] m_typedBuffer;
// }
// void release()
// {
// if (m_typedBuffer)
// {
// delete[] m_typedBuffer;
// m_typedBuffer = NULL;
// m_buffer = NULL;
// m_nb = 0;
// m_size = 0;
// }
// }
// void reserve(unsigned int nb)
// {
// m_nb = nb; // store number of elements
// m_typedBuffer = new TYPE_OUT[m_nb]; // allocate buffer
// m_buffer = m_typedBuffer; // store void* casted ptr
// m_size = m_nb*sizeof(TYPE_OUT); // store size of buffer in bytes
// }
// void convert(const void* ptrIn)
// {
// // cast ptr in & out with right type
// const TYPE_IN* typedIn = reinterpret_cast<const TYPE_IN*>(ptrIn);
// TYPE_OUT* typedOut = reinterpret_cast<TYPE_OUT*>(m_buffer);
// compute conversion
for
(
int
i
=
0
;
i
<
m_nb
;
++
i
)
{
float
h
=
(
360.0
f
/
(
m_diff
))
*
(
*
typedIn
++
-
m_min
);
// normalize in 0-360
int
hi
=
int
(
floor
(
h
/
60.0
f
))
%
6
;
float
f
=
(
h
/
60.0
)
-
floor
(
h
/
60.0
);
float
q
=
1.0
f
-
f
;
switch
(
hi
)
{
case
0
:
*
typedOut
++
=
0.0
f
;
*
typedOut
++
=
f
;
*
typedOut
++
=
1.0
f
;
break
;
case
1
:
*
typedOut
++
=
0.0
f
;
*
typedOut
++
=
1.0
f
;
*
typedOut
++
=
q
;
break
;
case
2
:
*
typedOut
++
=
f
;
*
typedOut
++
=
1.0
f
;
*
typedOut
++
=
0.0
f
;
break
;
case
3
:
*
typedOut
++
=
1.0
f
;
*
typedOut
++
=
q
;
*
typedOut
++
=
0.0
f
;
break
;
case
4
:
*
typedOut
++
=
1.0
f
;
*
typedOut
++
=
0.0
f
;
*
typedOut
++
=
f
;
break
;
case
5
:
*
typedOut
++
=
q
;
*
typedOut
++
=
0.0
f
;
*
typedOut
++
=
1.0
f
;
default:
break
;
}
}
}
unsigned
int
vectorSize
()
{
return
3
;
}
};
template
<
unsigned
int
D
>
class
ConvertVecXdToVecXf
:
public
ConvertBuffer
{
protected:
typedef
Geom
::
Vector
<
D
,
float
>
VECF
;
typedef
Geom
::
Vector
<
D
,
double
>
VECD
;
VECF
*
m_typedBuffer
;
public:
ConvertVecXdToVecXf
()
:
m_typedBuffer
(
NULL
)
{}
~
ConvertVecXdToVecXf
()
{
if
(
m_typedBuffer
)
delete
[]
m_typedBuffer
;
}
void
release
()
{
delete
[]
m_typedBuffer
;
m_typedBuffer
=
NULL
;
m_buffer
=
NULL
;
m_nb
=
0
;
m_size
=
0
;
}
void
reserve
(
unsigned
int
nb
)
{
m_nb
=
nb
;
// store number of elements
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
(
VECF
);
// store size of buffer in bytes
}
void
convert
(
const
void
*
ptrIn