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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
KennethVanhoey
CGoGN
Commits
7aea3ea5
Commit
7aea3ea5
authored
Oct 01, 2012
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update GLSL usage on VRJ
parent
089fc32b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
6 deletions
+88
-6
include/Utils/GLSLShader.h
include/Utils/GLSLShader.h
+11
-0
include/Utils/gl_matrices.h
include/Utils/gl_matrices.h
+42
-4
src/Utils/GLSLShader.cpp
src/Utils/GLSLShader.cpp
+35
-2
No files found.
include/Utils/GLSLShader.h
View file @
7aea3ea5
...
...
@@ -370,6 +370,12 @@ public:
*/
void
updateMatrices
(
const
glm
::
mat4
&
projection
,
const
glm
::
mat4
&
modelview
);
/**
* update projection, modelview, ... matrices
*/
void
updateMatrices
(
const
glm
::
mat4
&
projection
,
const
glm
::
mat4
&
modelview
,
const
glm
::
mat4
&
PMV
,
const
glm
::
mat4
&
normalMatrix
);
/**
* bind, enable, and set all vertex attrib pointers
* @param stride: the stride parameter, number osf byte between two consecutive attributes
...
...
@@ -386,6 +392,11 @@ public:
/// sent current matrices to all shaders
static
void
updateCurrentMatrices
();
static
glm
::
mat4
&
currentNormalMatrix
()
{
return
s_current_matrices
->
m_matrices
[
4
];}
static
glm
::
mat4
&
currentPMV
()
{
return
s_current_matrices
->
m_matrices
[
3
];}
/// get current transformation matrix
static
glm
::
mat4
&
currentTransfo
()
{
return
s_current_matrices
->
m_matrices
[
2
];}
/// get current modelview matrix
...
...
include/Utils/gl_matrices.h
View file @
7aea3ea5
...
...
@@ -27,7 +27,9 @@
#define __GL_MATRICES_H_
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include <stack>
#include "Geometry/vector_gen.h"
namespace
CGoGN
{
...
...
@@ -37,13 +39,49 @@ namespace Utils
class
GL_Matrices
{
public:
/// 0: projection / 1: modelView /2: transfo
glm
::
mat4
m_matrices
[
3
];
/// 0: projection / 1: modelView /2: transfo
/ 3:PMV /4:normal
glm
::
mat4
m_matrices
[
5
];
/// stack of transfo matrix
std
::
stack
<
glm
::
mat4
>
m_stack
;
void
pushTransfo
()
{
m_stack
.
push
(
m_matrices
[
2
]);
}
void
popTransfo
()
{
if
(
m_stack
.
empty
())
return
;
m_matrices
[
2
]
=
m_stack
.
top
();
m_stack
.
pop
();
}
public:
void
pushTransfo
()
{
m_stack
.
push
(
m_matrices
[
2
]);
}
void
popTransfo
()
{
if
(
m_stack
.
empty
())
return
;
m_matrices
[
2
]
=
m_stack
.
top
();
m_stack
.
pop
();
}
glm
::
mat4
getTransfo
()
const
{
return
m_matrices
[
2
];
}
void
rotate
(
float
angle
,
const
Geom
::
Vec3f
&
Axis
)
{
m_matrices
[
2
]
=
glm
::
rotate
(
m_matrices
[
2
],
angle
,
glm
::
vec3
(
Axis
[
0
],
Axis
[
1
],
Axis
[
2
]));
}
void
translate
(
const
Geom
::
Vec3f
&
P
)
{
m_matrices
[
2
]
=
glm
::
translate
(
m_matrices
[
2
],
glm
::
vec3
(
P
[
0
],
P
[
1
],
P
[
2
]));
}
void
scale
(
const
Geom
::
Vec3f
&
S
)
{
m_matrices
[
2
]
=
glm
::
scale
(
m_matrices
[
2
],
glm
::
vec3
(
S
[
0
],
S
[
1
],
S
[
2
]));
}
void
scale
(
float
s
)
{
m_matrices
[
2
]
=
glm
::
scale
(
m_matrices
[
2
],
glm
::
vec3
(
s
,
s
,
s
));
}
};
...
...
src/Utils/GLSLShader.cpp
View file @
7aea3ea5
...
...
@@ -1020,9 +1020,32 @@ void GLSLShader::updateMatrices(const glm::mat4& projection, const glm::mat4& mo
glm
::
mat4
normalMatrix
=
glm
::
gtx
::
inverse_transpose
::
inverseTranspose
(
modelview
);
glUniformMatrix4fv
(
*
m_uniMat_Normal
,
1
,
false
,
&
normalMatrix
[
0
][
0
]);
}
}
void
GLSLShader
::
updateMatrices
(
const
glm
::
mat4
&
projection
,
const
glm
::
mat4
&
modelview
,
const
glm
::
mat4
&
PMV
,
const
glm
::
mat4
&
normalMatrix
)
{
this
->
bind
();
if
(
*
m_uniMat_Proj
>=
0
)
glUniformMatrix4fv
(
*
m_uniMat_Proj
,
1
,
false
,
&
projection
[
0
][
0
]);
if
(
*
m_uniMat_Model
>=
0
)
glUniformMatrix4fv
(
*
m_uniMat_Model
,
1
,
false
,
&
modelview
[
0
][
0
]);
if
(
*
m_uniMat_ModelProj
>=
0
)
{
glUniformMatrix4fv
(
*
m_uniMat_ModelProj
,
1
,
false
,
&
PMV
[
0
][
0
]);
}
if
(
*
m_uniMat_Normal
>=
0
)
{
glUniformMatrix4fv
(
*
m_uniMat_Normal
,
1
,
false
,
&
normalMatrix
[
0
][
0
]);
}
}
void
GLSLShader
::
enableVertexAttribs
(
unsigned
int
stride
,
unsigned
int
begin
)
const
{
this
->
bind
();
...
...
@@ -1042,13 +1065,17 @@ void GLSLShader::disableVertexAttribs() const
this
->
unbind
();
}
void
GLSLShader
::
updateCurrentMatrices
()
{
glm
::
mat4
model
(
currentModelView
());
model
*=
currentTransfo
();
currentPMV
()
=
currentProjection
()
*
model
;
currentNormalMatrix
()
=
glm
::
gtx
::
inverse_transpose
::
inverseTranspose
(
model
);
for
(
std
::
set
<
std
::
pair
<
void
*
,
GLSLShader
*>
>::
iterator
it
=
m_registeredShaders
.
begin
();
it
!=
m_registeredShaders
.
end
();
++
it
)
it
->
second
->
updateMatrices
(
currentProjection
(),
model
);
it
->
second
->
updateMatrices
(
currentProjection
(),
model
,
currentPMV
(),
currentNormalMatrix
()
);
}
void
GLSLShader
::
updateAllFromGLMatrices
()
...
...
@@ -1062,14 +1089,20 @@ void GLSLShader::updateAllFromGLMatrices()
glm
::
mat4
proj
;
for
(
unsigned
int
i
=
0
;
i
<
4
;
++
i
)
{
for
(
unsigned
int
j
=
0
;
j
<
4
;
++
j
)
{
proj
[
i
][
j
]
=
float
(
projection
[
4
*
i
+
j
]);
model
[
i
][
j
]
=
float
(
modelview
[
4
*
i
+
j
]);
}
}
model
*=
currentTransfo
();
currentPMV
()
=
proj
*
model
;
currentNormalMatrix
()
=
glm
::
gtx
::
inverse_transpose
::
inverseTranspose
(
model
);
for
(
std
::
set
<
std
::
pair
<
void
*
,
GLSLShader
*>
>::
iterator
it
=
m_registeredShaders
.
begin
();
it
!=
m_registeredShaders
.
end
();
++
it
)
it
->
second
->
updateMatrices
(
proj
,
model
);
it
->
second
->
updateMatrices
(
proj
,
model
,
currentPMV
(),
currentNormalMatrix
()
);
}
...
...
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