Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CGoGN
CGoGN
Commits
612c7ed7
Commit
612c7ed7
authored
Jul 17, 2014
by
Sylvain Thery
Browse files
VBO update with conversion lambda
parent
c926209f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Apps/Tuto/Attributes/vbo_attribs.cpp
View file @
612c7ed7
...
...
@@ -69,19 +69,14 @@ void MyQT::createMap()
colorF
[
PHI_1
(
d2
)]
=
Geom
::
Vec3f
(
0.0
f
,
1.0
f
,
1.0
f
);
// create another attribute on vertices (for edges drawing)
VertexAttribute
<
VEC3
,
MAP
>
colorE
=
myMap
.
addAttribute
<
PFP
::
VEC3
,
VERTEX
,
MAP
>
(
"colorE"
);
VertexAttribute
<
int
,
MAP
>
colorE
=
myMap
.
addAttribute
<
int
,
VERTEX
,
MAP
>
(
"colorE"
);
colorE
[
d1
]
=
Geom
::
Vec3f
(
0.0
f
,
0.5
f
,
0.5
f
)
;
colorE
[
PHI1
(
d1
)]
=
Geom
::
Vec3f
(
0.5
f
,
0.0
f
,
0.5
f
)
;
colorE
[
PHI_1
(
d1
)]
=
Geom
::
Vec3f
(
0.5
f
,
0.5
f
,
0.0
f
)
;
colorE
[
PHI
<
11
>
(
d2
)]
=
Geom
::
Vec3f
(
0.0
f
,
0.5
f
,
0.0
f
)
;
colorE
[
PHI_1
(
d2
)]
=
Geom
::
Vec3f
(
0.5
f
,
0.0
f
,
0.0
f
)
;
colorE
[
d1
]
=
0
;
colorE
[
PHI1
(
d1
)]
=
255
;
colorE
[
PHI_1
(
d1
)]
=
64
;
colorE
[
PHI
<
11
>
(
d2
)]
=
127
;
colorE
[
PHI_1
(
d2
)]
=
192
;
// example of attribute on face
// here for example we store the number of edges of faces at construction
FaceAttribute
<
int
,
MAP
>
side
=
myMap
.
addAttribute
<
int
,
FACE
,
MAP
>
(
"nb_sides"
);
side
[
d1
]
=
3
;
side
[
d2
]
=
4
;
// bounding box of scene
Geom
::
BoundingBox
<
PFP
::
VEC3
>
bb
=
Algo
::
Geometry
::
computeBoundingBox
<
PFP
>
(
myMap
,
position
);
...
...
@@ -94,20 +89,27 @@ void MyQT::createMap()
// first show for be sure that GL context is binded
show
();
// update of position VBO (context GL necessary)
// HERE VBO conversion on the fly
// update of position VBO with on the fly conversion from double to float (automatic)
m_positionVBO
->
updateData
(
position
);
// m_colorVBO1->updateData(colorF);
m_colorVBO2
->
updateData
(
colorE
);
m_colorVBO1
->
updateData_withLambdaConversion
<
PFP
::
VEC3
,
Geom
::
Vec3f
,
3
>
(
colorF
,
[](
const
PFP
::
VEC3
&
x
)
// 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
);
});
// 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
-
x
[
0
]),
float
(
1.0
-
x
[
1
]),
float
(
1.0
-
x
[
2
]));
return
Geom
::
Vec3f
(
float
(
1.0
-
c
[
0
]),
float
(
1.0
-
c
[
1
]),
float
(
1.0
-
c
[
2
]));
});
// m_colorVBO2->updateData_withLambdaConversion<PFP::VEC3,Geom::Vec3f,3>(colorE, [](const PFP::VEC3& x)
// {
// return Geom::Vec3f(float(1.0-x[0]),float(1.0-x[1]),float(1.0-x[2]));
// });
// construct rendering primities
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
Algo
::
Render
::
GL2
::
TRIANGLES
);
...
...
@@ -140,7 +142,6 @@ void MyQT::cb_initGL()
m_shader2
=
new
Utils
::
ShaderColorPerVertex
();
m_shader2
->
setAttributePosition
(
m_positionVBO
);
// m_shader2->setAttributeColor(m_colorVBO1);
// each shader must be registred to allow Qt interface to update matrices uniforms
registerShader
(
m_shader2
);
}
...
...
@@ -151,7 +152,6 @@ void MyQT::cb_redraw()
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
glEnable
(
GL_CULL_FACE
);
// draw yellow points
glLineWidth
(
2.0
f
);
m_shader2
->
setAttributeColor
(
m_colorVBO1
);
m_render
->
draw
(
m_shader2
,
Algo
::
Render
::
GL2
::
LINES
);
...
...
include/Utils/vbo_base.h
View file @
612c7ed7
...
...
@@ -74,7 +74,7 @@ protected:
/**
* update data from AttributeMultiVectorGen to the vbo, with conversion
*/
void
updateData_withConversion
(
const
AttributeMultiVectorGen
*
attrib
,
ConvertBuffer
*
conv
);
void
updateData_with
Internal
Conversion
(
const
AttributeMultiVectorGen
*
attrib
,
ConvertBuffer
*
conv
);
public:
/**
...
...
@@ -147,9 +147,6 @@ public:
void
updateData
(
const
AttributeMultiVectorGen
*
attrib
);
// template <typename T_IN, typename T_OUT, unsigned int VS, typename CONVFUNC>
// void updateData_withLambdaConversion(const AttributeHandlerGen& attribHG, CONVFUNC conv);
/**
* set the converter that convert buffer to float *
*/
...
...
@@ -172,15 +169,24 @@ public:
void
allocate
(
unsigned
int
nbElts
);
template
<
typename
T_IN
,
typename
T_OUT
,
unsigned
int
VS
,
typename
CONVFUNC
>
void
updateData_withLambdaConversion
(
const
AttributeHandlerGen
&
attribHG
,
CONVFUNC
conv
)
/**
* update the VBO from Attribute Handler with on the fly conversion
* template paramters:
* T_IN input type attribute handler
* NB_COMPONENTS 3 for vbo of pos/normal, 2 for texture etc..
* @param attribHG the attribute handler source
* @param conv lambda function that take a const T_IN& and return a Vector<NB_COMPONENTS,float>
*/
template
<
typename
T_IN
,
unsigned
int
NB_COMPONENTS
,
typename
CONVFUNC
>
void
updateDataConversion
(
const
AttributeHandlerGen
&
attribHG
,
CONVFUNC
conv
)
{
typedef
Geom
::
Vector
<
NB_COMPONENTS
,
float
>
T_OUT
;
const
AttributeMultiVectorGen
*
attrib
=
attribHG
.
getDataVectorGen
();
m_name
=
attrib
->
getName
();
m_typeName
=
attrib
->
getTypeName
();
m_data_size
=
V
S
;
m_data_size
=
NB_COMPONENT
S
;
// alloue la memoire pour le buffer et initialise le conv
T_OUT
*
typedBuffer
=
new
T_OUT
[
_BLOCKSIZE_
];
...
...
@@ -189,37 +195,33 @@ public:
unsigned
int
byteTableSize
;
unsigned
int
nbb
=
attrib
->
getBlocksPointers
(
addr
,
byteTableSize
);
m_nbElts
=
nbb
*
_BLOCKSIZE_
/
(
VS
*
sizeof
(
T_OUT
));
// bind buffer to update
glBindBuffer
(
GL_ARRAY_BUFFER
,
*
m_id
);
glBufferData
(
GL_ARRAY_BUFFER
,
nbb
*
_BLOCKSIZE_
,
0
,
GL_STREAM_DRAW
);
m_nbElts
=
nbb
*
_BLOCKSIZE_
/
(
sizeof
(
T_OUT
));
unsigned
int
offset
=
0
;
unsigned
int
szb
=
_BLOCKSIZE_
*
sizeof
(
T_OUT
);
// bind buffer to update
glBindBuffer
(
GL_ARRAY_BUFFER
,
*
m_id
);
glBufferData
(
GL_ARRAY_BUFFER
,
nbb
*
szb
,
0
,
GL_STREAM_DRAW
);
for
(
unsigned
int
i
=
0
;
i
<
nbb
;
++
i
)
{
// convertit les donnees dans le buffer de conv
const
T_IN
*
typedIn
=
reinterpret_cast
<
const
T_IN
*>
(
addr
[
i
]);
T_OUT
*
typedOut
=
typedBuffer
;
// compute conversion
for
(
unsigned
int
i
=
0
;
i
<
_BLOCKSIZE_
;
++
i
)
{
// *typedOut++ = conv(*typedIn++);
std
::
cout
<<
*
typedIn
<<
" -> "
;
*
typedOut
=
conv
(
*
typedIn
++
);
std
::
cout
<<
*
typedOut
++
<<
std
::
endl
;
}
for
(
unsigned
int
j
=
0
;
j
<
_BLOCKSIZE_
;
++
j
)
*
typedOut
++
=
conv
(
*
typedIn
++
);
// update sub-vbo
glBufferSubDataARB
(
GL_ARRAY_BUFFER
,
offset
,
szb
,
typedBuffer
);
glBufferSubDataARB
(
GL_ARRAY_BUFFER
,
offset
,
szb
,
reinterpret_cast
<
void
*>
(
typedBuffer
)
)
;
// block suivant
offset
+=
szb
;
}
// libere la memoire de la conversion
delete
[]
typedBuffer
;
}
...
...
src/Utils/vbo.cpp
View file @
612c7ed7
...
...
@@ -49,7 +49,7 @@ VBO::VBO(const VBO& vbo) :
m_data_size
(
vbo
.
m_data_size
),
m_nbElts
(
vbo
.
m_nbElts
),
m_lock
(
false
),
m_conv
(
NULL
)
m_conv
(
vbo
.
m_conv
)
{
unsigned
int
nbbytes
=
sizeof
(
float
)
*
m_data_size
*
m_nbElts
;
...
...
@@ -97,7 +97,7 @@ void VBO::updateData(const AttributeMultiVectorGen* attrib)
if
(
m_conv
!=
NULL
)
{
updateData_withConversion
(
attrib
,
m_conv
);
updateData_with
Internal
Conversion
(
attrib
,
m_conv
);
return
;
}
...
...
@@ -105,7 +105,7 @@ void VBO::updateData(const AttributeMultiVectorGen* attrib)
if
(
amv3
!=
NULL
)
{
ConvertVec3dToVec3f
conv
;
updateData_withConversion
(
attrib
,
&
conv
);
updateData_with
Internal
Conversion
(
attrib
,
&
conv
);
return
;
}
...
...
@@ -113,7 +113,7 @@ void VBO::updateData(const AttributeMultiVectorGen* attrib)
if
(
amv2
!=
NULL
)
{
ConvertVec2dToVec2f
conv
;
updateData_withConversion
(
attrib
,
&
conv
);
updateData_with
Internal
Conversion
(
attrib
,
&
conv
);
return
;
}
...
...
@@ -121,7 +121,7 @@ void VBO::updateData(const AttributeMultiVectorGen* attrib)
if
(
amv4
!=
NULL
)
{
ConvertVec4dToVec4f
conv
;
updateData_withConversion
(
attrib
,
&
conv
);
updateData_with
Internal
Conversion
(
attrib
,
&
conv
);
return
;
}
...
...
@@ -129,7 +129,7 @@ void VBO::updateData(const AttributeMultiVectorGen* attrib)
if
(
amv1
!=
NULL
)
{
ConvertDoubleToFloat
conv
;
updateData_withConversion
(
attrib
,
&
conv
);
updateData_with
Internal
Conversion
(
attrib
,
&
conv
);
return
;
}
...
...
@@ -159,7 +159,7 @@ void VBO::updateData(const AttributeMultiVectorGen* attrib)
}
void
VBO
::
updateData_withConversion
(
const
AttributeMultiVectorGen
*
attrib
,
ConvertBuffer
*
conv
)
void
VBO
::
updateData_with
Internal
Conversion
(
const
AttributeMultiVectorGen
*
attrib
,
ConvertBuffer
*
conv
)
{
m_name
=
attrib
->
getName
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment