Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
Unterteilungsalgorithmen
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
Unterteilungsalgorithmen
Commits
55d42e89
Commit
55d42e89
authored
Aug 18, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render regular patches without subdivision
Splits original mesh into regular and irregular meshes and renders them separately.
parent
0e9ef934
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
32 deletions
+64
-32
mainwidget.cpp
QTProject/mainwidget.cpp
+8
-12
mesh.cpp
QTProject/mesh.cpp
+28
-18
mesh.h
QTProject/mesh.h
+1
-1
subdivideRegular.tcs
QTProject/subdivideRegular.tcs
+1
-1
subdivision.cpp
QTProject/subdivision.cpp
+25
-0
subdivision.h
QTProject/subdivision.h
+1
-0
No files found.
QTProject/mainwidget.cpp
View file @
55d42e89
...
...
@@ -149,7 +149,7 @@ void MainWidget::loadNewMesh(QString path){
qDebug
()
<<
"Opening File:"
<<
path
;
mesh
=
new
Mesh
(
this
,
path
);
subdivision
->
splitRegular
(
mesh
);
}
void
MainWidget
::
subdivide
(
int
level
){
...
...
@@ -222,19 +222,15 @@ void MainWidget::paintGL(){
rot
.
rotate
(
time
/
100.0
*
36
/
5
,
QVector3D
(
0
,
1
,
0
));
}
if
(
subdivLevel
>
0
){
regularShader
->
bind
();
regularShader
->
setUniformValue
(
"wireframe"
,
wireframe
);
regularShader
->
setUniformValue
(
"colorTexture"
,
0
);
regularShader
->
setUniformValue
(
"LightPos"
,
QVector3D
(
0
,
100
,
100
));
regularShader
->
setUniformValue
(
"subdiv"
,
subdivLevel
);
mesh
->
render
(
regularShader
,
cam
->
getMatrix
()
*
rot
,
m_projection
,
subdivLevel
,
true
);
regularShader
->
bind
();
regularShader
->
setUniformValue
(
"wireframe"
,
wireframe
);
regularShader
->
setUniformValue
(
"colorTexture"
,
0
);
regularShader
->
setUniformValue
(
"LightPos"
,
QVector3D
(
0
,
100
,
100
));
regularShader
->
setUniformValue
(
"subdiv"
,
subdivLevel
);
regularShader
->
release
();
}
mesh
->
render
(
regularShader
,
cam
->
getMatrix
()
*
rot
,
m_projection
,
subdivLevel
,
true
);
regularShader
->
release
();
subdivisionShader
->
bind
();
subdivisionShader
->
setUniformValue
(
"wireframe"
,
wireframe
);
...
...
QTProject/mesh.cpp
View file @
55d42e89
...
...
@@ -37,6 +37,18 @@ void Mesh::SubdivEntry::addRegular(QVector<unsigned int>& Indices){
}
void
Mesh
::
SubdivEntry
::
updateIndices
()
{
f
->
glDeleteBuffers
(
1
,
&
IB_handle
);
f
->
glGenBuffers
(
1
,
&
IB_handle
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB_handle
);
f
->
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
unsigned
int
)
*
indices
.
size
(),
&
indices
[
0
],
GL_STATIC_DRAW
);
f
->
glDeleteBuffers
(
1
,
&
IB_Regular
);
f
->
glGenBuffers
(
1
,
&
IB_Regular
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB_Regular
);
f
->
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
unsigned
int
)
*
indicesRegular
.
size
(),
&
indicesRegular
[
0
],
GL_STATIC_DRAW
);
}
void
Mesh
::
SubdivEntry
::
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices
){
...
...
@@ -462,26 +474,24 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
// qDebug()<<"Render"<<subdivision<<entry->indices;
if
(
regular
){
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entries
[
index
].
buffers
[
subdivision
-
1
]
->
VB_handle
);
f
->
glVertexAttribPointer
(
positionIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
0
);
if
(
!
entry
->
indicesRegular
.
isEmpty
())
{
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entry
->
VB_handle
);
f
->
glVertexAttribPointer
(
positionIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
0
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entry
->
IB_Regular
);
f
->
glPatchParameteri
(
GL_PATCH_VERTICES
,
12
);
f
->
glDrawElements
(
GL_PATCHES
,
entry
->
indicesRegular
.
size
(),
GL_UNSIGNED_INT
,
0
);
}
else
{
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entry
->
VB_handle
);
f
->
glVertexAttribPointer
(
positionIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
0
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entry
->
IB_handle
);
f
->
glPatchParameteri
(
GL_PATCH_VERTICES
,
3
);
f
->
glDrawElements
(
GL_PATCHES
,
entry
->
indices
.
size
(),
GL_UNSIGNED_INT
,
0
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entry
->
IB_Regular
);
f
->
glPatchParameteri
(
GL_PATCH_VERTICES
,
12
);
f
->
glDrawElements
(
GL_PATCHES
,
entry
->
indicesRegular
.
size
(),
GL_UNSIGNED_INT
,
0
);
}
}
else
{
if
(
!
entry
->
indices
.
isEmpty
())
{
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entry
->
VB_handle
);
f
->
glVertexAttribPointer
(
positionIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
0
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entry
->
IB_handle
);
f
->
glPatchParameteri
(
GL_PATCH_VERTICES
,
3
);
f
->
glDrawElements
(
GL_PATCHES
,
entry
->
indices
.
size
(),
GL_UNSIGNED_INT
,
0
);
}
}
}
void
Mesh
::
findObjectDimension
(
Node
node
,
QMatrix4x4
transform
,
QVector3D
&
min
,
QVector3D
&
max
){
...
...
QTProject/mesh.h
View file @
55d42e89
...
...
@@ -74,7 +74,7 @@ public:
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices
);
void
addRegular
(
QVector
<
unsigned
int
>&
Indices
);
void
updateIndices
();
};
struct
MeshEntry
{
...
...
QTProject/subdivideRegular.tcs
View file @
55d42e89
...
...
@@ -12,7 +12,7 @@ void main()
tcPosition[gl_InvocationID] = vPosition[gl_InvocationID];
float tesselation = subdiv+1
5
;
float tesselation = subdiv+1;
gl_TessLevelOuter[0] = tesselation;
gl_TessLevelOuter[1] = tesselation;
...
...
QTProject/subdivision.cpp
View file @
55d42e89
...
...
@@ -363,6 +363,31 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
return
tables
;
}
void
Subdivision
::
splitRegular
(
Mesh
*
mesh
)
{
Mesh
::
Node
root
=
mesh
->
getRootNode
();
int
first_mesh_index
=
-
1
;
if
(
!
root
.
getFirstMeshIndex
(
first_mesh_index
))
{
qCritical
()
<<
"No mesh found, aborting subdivision"
;
return
;
}
Mesh
::
MeshEntry
*
current_mesh
=
mesh
->
getMeshEntry
(
first_mesh_index
);
QVector
<
unsigned
int
>
regular
;
QVector
<
unsigned
int
>
irregular
;
findRegular
(
current_mesh
->
buffers
[
0
]
->
indices
,
current_mesh
->
buffers
[
0
]
->
vertices
,
regular
,
irregular
);
findRegular
(
current_mesh
->
buffers
[
0
]
->
indicesRegular
,
current_mesh
->
buffers
[
0
]
->
vertices
,
regular
,
irregular
);
QVector
<
unsigned
int
>
patches
=
getPatchIndexBuffer
(
regular
);
current_mesh
->
buffers
[
0
]
->
indicesRegular
=
patches
;
current_mesh
->
buffers
[
0
]
->
indices
=
irregular
;
current_mesh
->
buffers
[
0
]
->
updateIndices
();
qDebug
()
<<
"regular: "
<<
regular
.
length
();
qDebug
()
<<
"irregular: "
<<
irregular
.
length
();
}
/**
* @brief Subdivision::getPatchIndexBuffer
* Computes an index buffer for the patches. patches are in order from figure 6(a) from the paper:
...
...
QTProject/subdivision.h
View file @
55d42e89
...
...
@@ -13,6 +13,7 @@ public:
~
Subdivision
();
void
init
();
void
splitRegular
(
Mesh
*
mesh
);
void
subdivide
(
Mesh
*
mesh
,
int
level
);
void
setDebugOutbut
(
bool
debug
);
...
...
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