Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OpenGL
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
C-Fu
OpenGL
Commits
30f1a1e6
Commit
30f1a1e6
authored
8 years ago
by
Anakin
Browse files
Options
Downloads
Patches
Plain Diff
passing poylNormal, tangent, bitangent to shader
parent
cdf19911
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
QtMeshViewer/Header/GeometryEngine.h
+1
-0
1 addition, 0 deletions
QtMeshViewer/Header/GeometryEngine.h
QtMeshViewer/Resources/fshader.glsl
+4
-0
4 additions, 0 deletions
QtMeshViewer/Resources/fshader.glsl
QtMeshViewer/Source/GeometryEngine.cpp
+54
-23
54 additions, 23 deletions
QtMeshViewer/Source/GeometryEngine.cpp
with
59 additions
and
23 deletions
QtMeshViewer/Header/GeometryEngine.h
+
1
−
0
View file @
30f1a1e6
...
...
@@ -34,6 +34,7 @@ private:
// functions
private:
void
clearData
();
void
setupPipeline
(
QOpenGLShaderProgram
*
program
);
public:
void
drawGeometry
(
QOpenGLShaderProgram
*
program
);
...
...
This diff is collapsed.
Click to expand it.
QtMeshViewer/Resources/fshader.glsl
+
4
−
0
View file @
30f1a1e6
...
...
@@ -22,6 +22,10 @@ uniform struct Light {
float
ambientCoefficient
;
}
light
;
attribute
vec3
a_polyNorm
;
attribute
vec3
a_polyTan
;
attribute
vec3
a_polyBiTan
;
varying
vec2
v_surfaceUV
;
varying
vec3
v_surfacePosition
;
varying
vec3
v_surfaceNormal
;
...
...
This diff is collapsed.
Click to expand it.
QtMeshViewer/Source/GeometryEngine.cpp
+
54
−
23
View file @
30f1a1e6
...
...
@@ -52,26 +52,8 @@ void GeometryEngine::clearData()
m_drawList
.
clear
();
}
void
GeometryEngine
::
drawGeometry
(
QOpenGLShaderProgram
*
program
)
void
GeometryEngine
::
setupPipeline
(
QOpenGLShaderProgram
*
program
)
{
if
(
!
m_arrayBuf
.
isCreated
()
||
!
m_indexBuf
.
isCreated
())
return
;
// Setup
// Tell OpenGL which VBOs to use
m_arrayBuf
.
bind
();
m_indexBuf
.
bind
();
// Allways normalize by this
QMatrix4x4
normMatrix
;
float
maxExtent
=
std
::
max
(
std
::
max
(
m_boundings
.
extents
[
0
],
m_boundings
.
extents
[
1
]),
m_boundings
.
extents
[
2
]);
normMatrix
.
scale
(
1
/
maxExtent
);
normMatrix
.
translate
(
-
m_boundings
.
center
[
0
],
-
m_boundings
.
center
[
1
],
-
m_boundings
.
center
[
2
]);
program
->
setUniformValue
(
"norm_matrix"
,
normMatrix
);
// Allways use texture unit 0
program
->
setUniformValue
(
"texture"
,
0
);
// Offset for position
quintptr
offset
=
0
;
...
...
@@ -88,14 +70,63 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
program
->
enableAttributeArray
(
texcoordLocation
);
program
->
setAttributeBuffer
(
texcoordLocation
,
GL_FLOAT
,
offset
,
2
,
sizeof
(
VertexData
));
//Offset for
n
ormal
//Offset for
vertexN
ormal
offset
+=
sizeof
(
QVector2D
);
// Tell OpenGL programmable pipeline how to locate vertex normal data
int
normLocation
=
program
->
attributeLocation
(
"a_normal"
);
program
->
enableAttributeArray
(
normLocation
);
program
->
setAttributeBuffer
(
normLocation
,
GL_FLOAT
,
offset
,
3
,
sizeof
(
VertexData
));
int
vertNormLocation
=
program
->
attributeLocation
(
"a_normal"
);
program
->
enableAttributeArray
(
vertNormLocation
);
program
->
setAttributeBuffer
(
vertNormLocation
,
GL_FLOAT
,
offset
,
3
,
sizeof
(
VertexData
));
//Offset for polygonNormal
offset
+=
sizeof
(
QVector3D
);
// Tell OpenGL programmable pipeline how to locate polygon normal data
int
polyNormLocation
=
program
->
attributeLocation
(
"a_polyNorm"
);
program
->
enableAttributeArray
(
polyNormLocation
);
program
->
setAttributeBuffer
(
polyNormLocation
,
GL_FLOAT
,
offset
,
3
,
sizeof
(
VertexData
));
//Offset for polygonTangent
offset
+=
sizeof
(
QVector3D
);
// Tell OpenGL programmable pipeline how to locate polygon tangent data
int
polyTanLocation
=
program
->
attributeLocation
(
"a_polyTan"
);
program
->
enableAttributeArray
(
polyTanLocation
);
program
->
setAttributeBuffer
(
polyTanLocation
,
GL_FLOAT
,
offset
,
3
,
sizeof
(
VertexData
));
//Offset for polygonBitangent
offset
+=
sizeof
(
QVector3D
);
// Tell OpenGL programmable pipeline how to locate polygon bitangent data
int
polyBiTanLocation
=
program
->
attributeLocation
(
"a_polyBiTan"
);
program
->
enableAttributeArray
(
polyBiTanLocation
);
program
->
setAttributeBuffer
(
polyBiTanLocation
,
GL_FLOAT
,
offset
,
3
,
sizeof
(
VertexData
));
}
void
GeometryEngine
::
drawGeometry
(
QOpenGLShaderProgram
*
program
)
{
if
(
!
m_arrayBuf
.
isCreated
()
||
!
m_indexBuf
.
isCreated
())
return
;
// Setup
// Tell OpenGL which VBOs to use
m_arrayBuf
.
bind
();
m_indexBuf
.
bind
();
// Allways normalize by this
QMatrix4x4
normMatrix
;
float
maxExtent
=
std
::
max
(
std
::
max
(
m_boundings
.
extents
[
0
],
m_boundings
.
extents
[
1
]),
m_boundings
.
extents
[
2
]);
normMatrix
.
scale
(
1
/
maxExtent
);
normMatrix
.
translate
(
-
m_boundings
.
center
[
0
],
-
m_boundings
.
center
[
1
],
-
m_boundings
.
center
[
2
]);
program
->
setUniformValue
(
"norm_matrix"
,
normMatrix
);
// Allways use texture unit 0
program
->
setUniformValue
(
"texture"
,
0
);
//setup the pipeline
setupPipeline
(
program
);
// Paint
for
(
auto
&
it
:
m_drawList
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment