Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Etienne Schmitt
CGoGN
Commits
5579ce2f
Commit
5579ce2f
authored
Feb 17, 2012
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor update in GMap (const)
update flat shader color & colorPerFaceRender
parent
cd514af0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
136 additions
and
68 deletions
+136
-68
include/Algo/Render/GL2/colorPerFaceRender.h
include/Algo/Render/GL2/colorPerFaceRender.h
+5
-6
include/Algo/Render/GL2/colorPerFaceRender.hpp
include/Algo/Render/GL2/colorPerFaceRender.hpp
+82
-21
include/Topology/generic/genericmap.h
include/Topology/generic/genericmap.h
+2
-2
include/Topology/generic/genericmap.hpp
include/Topology/generic/genericmap.hpp
+22
-1
include/Utils/Shaders/shaderFlatColor.frag
include/Utils/Shaders/shaderFlatColor.frag
+1
-1
include/Utils/Shaders/shaderFlatColor.geom
include/Utils/Shaders/shaderFlatColor.geom
+2
-2
include/Utils/Shaders/shaderFlatColor.h
include/Utils/Shaders/shaderFlatColor.h
+2
-2
include/Utils/Shaders/shaderFlatColor.vert
include/Utils/Shaders/shaderFlatColor.vert
+1
-1
src/Topology/generic/genericmap.cpp
src/Topology/generic/genericmap.cpp
+0
-15
src/Utils/Shaders/shaderFlatColor.cpp
src/Utils/Shaders/shaderFlatColor.cpp
+19
-17
No files found.
include/Algo/Render/GL2/colorPerFaceRender.h
View file @
5579ce2f
...
...
@@ -52,13 +52,8 @@ namespace GL2
class
ColorPerFaceRender
{
protected:
Utils
::
VBO
&
m_vboPos
;
Utils
::
VBO
&
m_vboColors
;
GLuint
m_nbTris
;
public:
/**
* Constructor
...
...
@@ -73,7 +68,11 @@ public:
* @param good selector
*/
template
<
typename
PFP
>
void
updateData
(
typename
PFP
::
MAP
&
map
,
typename
PFP
::
TVEC3
&
positions
,
typename
PFP
::
TVEC3
&
colorPerFace
,
const
FunctorSelect
&
good
=
allDarts
)
;
void
updateVBO
(
Utils
::
VBO
&
vboPosition
,
Utils
::
VBO
&
vboColor
,
typename
PFP
::
MAP
&
map
,
const
typename
PFP
::
TVEC3
&
positions
,
const
typename
PFP
::
TVEC3
&
colorPerFace
,
const
FunctorSelect
&
good
=
allDarts
)
;
template
<
typename
PFP
>
void
updateVBO
(
Utils
::
VBO
&
vboPosition
,
Utils
::
VBO
&
vboNormals
,
Utils
::
VBO
&
vboColor
,
typename
PFP
::
MAP
&
map
,
const
typename
PFP
::
TVEC3
&
positions
,
const
typename
PFP
::
TVEC3
&
normals
,
const
typename
PFP
::
TVEC3
&
colorPerFace
,
const
FunctorSelect
&
good
=
allDarts
)
;
/**
* draw
...
...
include/Algo/Render/GL2/colorPerFaceRender.hpp
View file @
5579ce2f
...
...
@@ -41,33 +41,31 @@ namespace GL2
{
inline
ColorPerFaceRender
::
ColorPerFaceRender
(
Utils
::
VBO
&
vboPosition
,
Utils
::
VBO
&
vboColor
)
:
m_vboPosition
(
vboPosition
),
m_vboColor
(
vboColor
),
m_nbTris
(
0
)
//inline ColorPerFaceRender::ColorPerFaceRender(Utils::VBO& vboPosition, Utils::VBO& vboColor):
// m_vboPos(vboPosition), m_vboColors(vboColor), m_nbTris(0)
//{
//}
inline
ColorPerFaceRender
::
ColorPerFaceRender
()
:
m_nbTris
(
0
)
{
}
template
<
typename
PFP
>
void
ColorPerFaceRender
::
update
Data
(
typename
PFP
::
MAP
&
map
,
typename
PFP
::
TVEC3
&
positions
,
typename
PFP
::
TVEC3
&
colorPerXXX
,
const
FunctorSelect
&
good
)
void
ColorPerFaceRender
::
update
VBO
(
Utils
::
VBO
&
vboPosition
,
Utils
::
VBO
&
vboColor
,
typename
PFP
::
MAP
&
map
,
const
typename
PFP
::
TVEC3
&
positions
,
const
typename
PFP
::
TVEC3
&
colorPerXXX
,
const
FunctorSelect
&
good
)
{
typedef
typename
PFP
::
VEC3
VEC3
;
typedef
typename
PFP
::
REAL
REAL
;
CellMarker
cmv
(
map
,
VOLUME
);
AutoAttributeHandler
<
VEC3
>
centerVolumes
(
map
,
VOLUME
,
"centerVolumes"
);
TraversorW
<
typename
PFP
::
MAP
>
traVol
(
map
,
good
);
for
(
Dart
d
=
traVol
.
begin
();
d
!=
traVol
.
end
();
d
=
traVol
.
next
())
{
centerVolumes
[
d
]
=
Algo
::
Geometry
::
volumeCentroid
<
PFP
>
(
map
,
d
,
positions
);
}
std
::
vector
<
VEC3
>
buffer
;
buffer
.
reserve
(
16384
);
std
::
vector
<
VEC3
>
bufferColors
;
bufferColors
.
reserve
(
16384
);
TraversorCell
<
typename
PFP
::
MAP
>
traFace
(
map
,
PFP
::
MAP
::
ORBIT_IN_PARENT
(
FACE
)
,
good
);
TraversorCell
<
typename
PFP
::
MAP
>
traFace
(
map
,
FACE
,
good
);
for
(
Dart
d
=
traFace
.
begin
();
d
!=
traFace
.
end
();
d
=
traFace
.
next
())
{
...
...
@@ -88,25 +86,88 @@ void ColorPerFaceRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3&
}
while
(
c
!=
d
);
}
m_nbTris
=
buffer
.
size
()
/
4
;
m_nbTris
=
buffer
.
size
()
/
3
;
m_vboPos
->
allocate
(
buffer
.
size
());
VEC3
*
ptrPos
=
reinterpret_cast
<
VEC3
*>
(
m_vboPos
->
lockPtr
());
vboPosition
.
setDataSize
(
3
);
vboPosition
.
allocate
(
buffer
.
size
());
VEC3
*
ptrPos
=
reinterpret_cast
<
VEC3
*>
(
vboPosition
.
lockPtr
());
memcpy
(
ptrPos
,
&
buffer
[
0
],
buffer
.
size
()
*
sizeof
(
VEC3
));
m_
vboPos
->
releasePtr
();
vboPos
ition
.
releasePtr
();
m_vboColors
->
allocate
(
bufferColors
.
size
());
VEC3
*
ptrCol
=
reinterpret_cast
<
VEC3
*>
(
m_vboColors
->
lockPtr
());
vboColor
.
setDataSize
(
3
);
vboColor
.
allocate
(
bufferColors
.
size
());
VEC3
*
ptrCol
=
reinterpret_cast
<
VEC3
*>
(
vboColor
.
lockPtr
());
memcpy
(
ptrCol
,
&
bufferColors
[
0
],
bufferColors
.
size
()
*
sizeof
(
VEC3
));
m_vboColors
->
releasePtr
();
vboColor
.
releasePtr
();
}
template
<
typename
PFP
>
void
ColorPerFaceRender
::
updateVBO
(
Utils
::
VBO
&
vboPosition
,
Utils
::
VBO
&
vboNormal
,
Utils
::
VBO
&
vboColor
,
typename
PFP
::
MAP
&
map
,
const
typename
PFP
::
TVEC3
&
positions
,
const
typename
PFP
::
TVEC3
&
normals
,
const
typename
PFP
::
TVEC3
&
colorPerXXX
,
const
FunctorSelect
&
good
)
{
typedef
typename
PFP
::
VEC3
VEC3
;
typedef
typename
PFP
::
REAL
REAL
;
std
::
vector
<
VEC3
>
buffer
;
buffer
.
reserve
(
16384
);
std
::
vector
<
VEC3
>
bufferNormals
;
bufferNormals
.
reserve
(
16384
);
std
::
vector
<
VEC3
>
bufferColors
;
bufferColors
.
reserve
(
16384
);
TraversorCell
<
typename
PFP
::
MAP
>
traFace
(
map
,
FACE
,
good
);
for
(
Dart
d
=
traFace
.
begin
();
d
!=
traFace
.
end
();
d
=
traFace
.
next
())
{
Dart
a
=
d
;
Dart
b
=
map
.
phi1
(
a
);
Dart
c
=
map
.
phi1
(
b
);
// 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
]);
b
=
c
;
c
=
map
.
phi1
(
b
);
}
while
(
c
!=
d
);
}
m_nbTris
=
buffer
.
size
()
/
3
;
vboPosition
.
setDataSize
(
3
);
vboPosition
.
allocate
(
buffer
.
size
());
VEC3
*
ptrPos
=
reinterpret_cast
<
VEC3
*>
(
vboPosition
.
lockPtr
());
memcpy
(
ptrPos
,
&
buffer
[
0
],
buffer
.
size
()
*
sizeof
(
VEC3
));
vboPosition
.
releasePtr
();
vboNormal
.
setDataSize
(
3
);
vboNormal
.
allocate
(
bufferColors
.
size
());
VEC3
*
ptrNorm
=
reinterpret_cast
<
VEC3
*>
(
vboNormal
.
lockPtr
());
memcpy
(
ptrNorm
,
&
bufferColors
[
0
],
bufferColors
.
size
()
*
sizeof
(
VEC3
));
vboNormal
.
releasePtr
();
vboColor
.
setDataSize
(
3
);
vboColor
.
allocate
(
bufferColors
.
size
());
VEC3
*
ptrCol
=
reinterpret_cast
<
VEC3
*>
(
vboColor
.
lockPtr
());
memcpy
(
ptrCol
,
&
bufferColors
[
0
],
bufferColors
.
size
()
*
sizeof
(
VEC3
));
vboColor
.
releasePtr
();
}
void
ColorPerFaceRender
::
draw
(
Utils
::
GLSLShader
*
sh
)
inline
void
ColorPerFaceRender
::
draw
(
Utils
::
GLSLShader
*
sh
)
{
sh
->
enableVertexAttribs
();
glDrawArrays
(
GL_TRIANGLES
,
0
,
m_nbTris
*
3
);
glDrawArrays
(
GL_TRIANGLES
,
0
,
m_nbTris
*
3
);
sh
->
disableVertexAttribs
();
}
...
...
include/Topology/generic/genericmap.h
View file @
5579ce2f
...
...
@@ -254,7 +254,7 @@ public:
/**
* get the index of dart in topological table
*/
unsigned
int
dartIndex
(
Dart
d
);
unsigned
int
dartIndex
(
Dart
d
)
const
;
/**
* get the insertion level of a dart (use only in MRMaps)
...
...
@@ -602,7 +602,7 @@ public:
/**
* test if a dart belong to the boundary
*/
bool
isBoundaryMarked
(
Dart
d
);
bool
isBoundaryMarked
(
Dart
d
)
const
;
protected:
/**
...
...
include/Topology/generic/genericmap.hpp
View file @
5579ce2f
...
...
@@ -187,7 +187,7 @@ inline void GenericMap::duplicateDart(Dart d)
}
}
inline
unsigned
int
GenericMap
::
dartIndex
(
Dart
d
)
inline
unsigned
int
GenericMap
::
dartIndex
(
Dart
d
)
const
{
if
(
m_isMultiRes
)
return
(
*
m_mrDarts
[
m_mrCurrentLevel
])[
d
.
index
]
;
...
...
@@ -396,4 +396,25 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na
return
amv
;
}
/**************************
* BOUNDARY MANAGEMENT *
**************************/
inline
void
GenericMap
::
boundaryMark
(
Dart
d
)
{
m_markTables
[
DART
][
0
]
->
operator
[](
dartIndex
(
d
)).
setMark
(
m_boundaryMarker
);
}
inline
void
GenericMap
::
boundaryUnmark
(
Dart
d
)
{
m_markTables
[
DART
][
0
]
->
operator
[](
dartIndex
(
d
)).
unsetMark
(
m_boundaryMarker
);
}
inline
bool
GenericMap
::
isBoundaryMarked
(
Dart
d
)
const
{
return
m_markTables
[
DART
][
0
]
->
operator
[](
dartIndex
(
d
)).
testMark
(
m_boundaryMarker
);
}
}
//namespace CGoGN
include/Utils/Shaders/shaderFlatColor.frag
View file @
5579ce2f
// ShaderFlatColor
PerFace
::fragmentShaderText
// ShaderFlatColor::fragmentShaderText
VARYING_FRAG
vec4
ColorFS
;
void
main
()
{
...
...
include/Utils/Shaders/shaderFlatColor.geom
View file @
5579ce2f
// ShaderFlatColor
PerFace
::geometryShaderText
// ShaderFlatColor::geometryShaderText
uniform
float
explode
;
uniform
mat4
ModelViewProjectionMatrix
;
uniform
mat4
NormalMatrix
;
...
...
@@ -21,7 +21,7 @@ void main(void)
vec3
L
=
normalize
(
lightPosition
-
newPos
.
xyz
);
float
lambertTerm
=
dot
(
N
,
L
);
#ifdef AVER
G
AGE_COLOR
#ifdef AVERAGE_COLOR
int
i
;
vec3
averageColor
=
vec3
(
0
.,
0
.,
0
.);
for
(
i
=
0
;
i
<
3
;
i
++
)
...
...
include/Utils/Shaders/shaderFlatColor.h
View file @
5579ce2f
...
...
@@ -34,7 +34,7 @@ namespace CGoGN
namespace
Utils
{
class
ShaderFlatColor
PerFace
:
public
GLSLShader
class
ShaderFlatColor
:
public
GLSLShader
{
protected:
// shader sources
...
...
@@ -59,7 +59,7 @@ protected:
void
restoreUniformsAttribs
();
public:
ShaderFlatColor
PerFace
(
);
ShaderFlatColor
(
bool
averageColor
=
false
);
void
setExplode
(
float
explode
);
...
...
include/Utils/Shaders/shaderFlatColor.vert
View file @
5579ce2f
// ShaderFlatColor
PerFace
::vertexShaderText
// ShaderFlatColor::vertexShaderText
ATTRIBUTE
vec3
VertexPosition
;
ATTRIBUTE
vec3
VertexColor
;
VARYING_VERT
vec3
colorVertex
;
...
...
src/Topology/generic/genericmap.cpp
View file @
5579ce2f
...
...
@@ -859,21 +859,6 @@ unsigned int GenericMap::getNbOrbits(unsigned int orbit, const FunctorSelect& go
return
fcount
.
getNb
();
}
void
GenericMap
::
boundaryMark
(
Dart
d
)
{
m_markTables
[
DART
][
0
]
->
operator
[](
dartIndex
(
d
)).
setMark
(
m_boundaryMarker
);
}
void
GenericMap
::
boundaryUnmark
(
Dart
d
)
{
m_markTables
[
DART
][
0
]
->
operator
[](
dartIndex
(
d
)).
unsetMark
(
m_boundaryMarker
);
}
bool
GenericMap
::
isBoundaryMarked
(
Dart
d
)
{
return
m_markTables
[
DART
][
0
]
->
operator
[](
dartIndex
(
d
)).
testMark
(
m_boundaryMarker
);
}
void
GenericMap
::
boundaryMarkOrbit
(
unsigned
int
orbit
,
Dart
d
)
{
FunctorMark
<
GenericMap
>
fm
(
*
this
,
m_boundaryMarker
,
m_markTables
[
DART
][
0
])
;
...
...
src/Utils/Shaders/shaderFlatColor.cpp
View file @
5579ce2f
...
...
@@ -22,30 +22,32 @@
* *
*******************************************************************************/
#include <string
.h
>
#include <string>
#include <GL/glew.h>
#include "Utils/Shaders/shaderFlatColor
PerFace
.h"
#include "Utils/Shaders/shaderFlatColor.h"
namespace
CGoGN
{
namespace
Utils
{
#include "shaderFlatColor
PerFace
.vert"
#include "shaderFlatColor
PerFace
.frag"
#include "shaderFlatColor
PerFace
.geom"
#include "shaderFlatColor.vert"
#include "shaderFlatColor.frag"
#include "shaderFlatColor.geom"
ShaderFlatColor
PerFace
::
ShaderFlatColor
PerFace
(
)
ShaderFlatColor
::
ShaderFlatColor
(
bool
averageColor
)
{
m_nameVS
=
"shaderFlatColor
PerFace
_vs"
;
m_nameFS
=
"shaderFlatColor
PerFace
_fs"
;
m_nameGS
=
"shaderFlatColor
PerFace
_gs"
;
m_nameVS
=
"shaderFlatColor_vs"
;
m_nameFS
=
"shaderFlatColor_fs"
;
m_nameGS
=
"shaderFlatColor_gs"
;
std
::
string
glxvert
(
*
GLSLShader
::
DEFINES_GL
);
glxvert
.
append
(
vertexShaderText
);
std
::
string
glxgeom
=
GLSLShader
::
defines_Geom
(
"triangles"
,
"triangle_strip"
,
3
);
if
(
averageColor
)
glxgeom
.
append
(
"#define AVERAGE_COLOR 1
\n
"
);
glxgeom
.
append
(
geometryShaderText
);
std
::
string
glxfrag
(
*
GLSLShader
::
DEFINES_GL
);
...
...
@@ -63,19 +65,19 @@ ShaderFlatColorPerFace::ShaderFlatColorPerFace()
setParams
(
m_explode
,
m_ambiant
,
m_light_pos
);
}
void
ShaderFlatColor
PerFace
::
getLocations
()
void
ShaderFlatColor
::
getLocations
()
{
m_unif_explode
=
glGetUniformLocation
(
program_handler
(),
"explode"
);
m_unif_ambiant
=
glGetUniformLocation
(
program_handler
(),
"ambient"
);
m_unif_lightPos
=
glGetUniformLocation
(
program_handler
(),
"lightPosition"
);
}
void
ShaderFlatColor
PerFace
::
setAttributePosition
(
VBO
*
vbo
)
void
ShaderFlatColor
::
setAttributePosition
(
VBO
*
vbo
)
{
m_vboPos
=
vbo
;
bindVA_VBO
(
"VertexPosition"
,
vbo
);
}
void
ShaderFlatColor
PerFace
::
setAttributeColor
(
VBO
*
vbo
)
void
ShaderFlatColor
::
setAttributeColor
(
VBO
*
vbo
)
{
m_vboColor
=
vbo
;
bindVA_VBO
(
"VertexColor"
,
vbo
);
...
...
@@ -83,7 +85,7 @@ void ShaderFlatColorPerFace::setAttributeColor(VBO* vbo)
void
ShaderFlatColor
PerFace
::
setParams
(
float
expl
,
const
Geom
::
Vec4f
&
ambiant
,
const
Geom
::
Vec3f
&
lightPos
)
void
ShaderFlatColor
::
setParams
(
float
expl
,
const
Geom
::
Vec4f
&
ambiant
,
const
Geom
::
Vec3f
&
lightPos
)
{
m_explode
=
expl
;
m_ambiant
=
ambiant
;
...
...
@@ -98,14 +100,14 @@ void ShaderFlatColorPerFace::setParams(float expl, const Geom::Vec4f& ambiant, c
unbind
();
// ??
}
void
ShaderFlatColor
PerFace
::
setExplode
(
float
explode
)
void
ShaderFlatColor
::
setExplode
(
float
explode
)
{
m_explode
=
explode
;
bind
();
glUniform1f
(
m_unif_explode
,
explode
);
}
void
ShaderFlatColor
PerFace
::
setAmbiant
(
const
Geom
::
Vec4f
&
ambiant
)
void
ShaderFlatColor
::
setAmbiant
(
const
Geom
::
Vec4f
&
ambiant
)
{
m_ambiant
=
ambiant
;
bind
();
...
...
@@ -113,14 +115,14 @@ void ShaderFlatColorPerFace::setAmbiant(const Geom::Vec4f& ambiant)
}
void
ShaderFlatColor
PerFace
::
setLightPosition
(
const
Geom
::
Vec3f
&
lp
)
void
ShaderFlatColor
::
setLightPosition
(
const
Geom
::
Vec3f
&
lp
)
{
m_light_pos
=
lp
;
bind
();
glUniform3fv
(
m_unif_lightPos
,
1
,
lp
.
data
());
}
void
ShaderFlatColor
PerFace
::
restoreUniformsAttribs
()
void
ShaderFlatColor
::
restoreUniformsAttribs
()
{
m_unif_explode
=
glGetUniformLocation
(
program_handler
(),
"explode"
);
m_unif_ambiant
=
glGetUniformLocation
(
program_handler
(),
"ambient"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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