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
85836b9d
Commit
85836b9d
authored
Sep 27, 2016
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
temp
parent
4d9d60a3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
14 deletions
+92
-14
main.cpp
QTProject/main.cpp
+1
-1
mainwidget.cpp
QTProject/mainwidget.cpp
+2
-1
mesh.cpp
QTProject/mesh.cpp
+12
-5
mesh.h
QTProject/mesh.h
+4
-2
subdivision.cpp
QTProject/subdivision.cpp
+69
-5
subdivision.h
QTProject/subdivision.h
+4
-0
No files found.
QTProject/main.cpp
View file @
85836b9d
...
...
@@ -6,7 +6,7 @@ int main(int argc, char *argv[])
{
QApplication
a
(
argc
,
argv
);
QLoggingCategory
::
setFilterRules
(
"timing.debug=true
\n
"
"mesh.debug=
fals
e
\n
"
"mesh.debug=
tru
e
\n
"
"mesh.render.debug=false
\n
"
"subdiv.debug=true
\n
"
"subdiv.trace.debug=false
\n
"
);
...
...
QTProject/mainwidget.cpp
View file @
85836b9d
...
...
@@ -145,7 +145,8 @@ void MainWidget::initializeGL(){
subdivision
->
init
();
//loadNewMesh( "../Models/demon_head.3ds");
loadNewMesh
(
"../Models/torus.obj"
);
// loadNewMesh( "../Models/torus.obj");
loadNewMesh
(
"../Models/box.obj"
);
}
void
MainWidget
::
loadNewMesh
(){
...
...
QTProject/mesh.cpp
View file @
85836b9d
...
...
@@ -4,6 +4,7 @@
Mesh
::
SubdivEntry
::
SubdivEntry
()
{
VB_handle
=
0xFFFFFFFF
;
VB_handle_irregular
=
0xFFFFFFFF
;
IB_irregular_handle
=
0xFFFFFFFF
;
IB_regular_handle
=
0xFFFFFFFF
;
}
...
...
@@ -39,10 +40,10 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Verti
f
->
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
Vertex
)
*
Vertices
.
size
(),
&
Vertices
[
0
],
GL_STATIC_DRAW
);
QVector
<
unsigned
int
>
patches
;
this
->
init
(
f
,
VB_handle
,
Vertices
,
Indices_irregular
,
patches
);
this
->
init
(
f
,
VB_handle
,
Vertices
,
Vertices
,
Indices_irregular
,
patches
);
}
void
Mesh
::
SubdivEntry
::
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
void
Mesh
::
SubdivEntry
::
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
){
this
->
f
=
f
;
this
->
VB_handle
=
VB_handle
;
...
...
@@ -52,9 +53,15 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVe
indices_regular
=
patches
;
qCDebug
(
log_mesh
)
<<
"Vertices"
<<
vertices
.
length
();
qCDebug
(
log_mesh
)
<<
"Vertices Irregular"
<<
Vertices_irregular
.
length
();
qCDebug
(
log_mesh
)
<<
"Indices irregular"
<<
indices_irregular
.
length
();
qCDebug
(
log_mesh
)
<<
"Indices patches"
<<
patches
.
length
();
f
->
glGenBuffers
(
1
,
&
VB_handle_irregular
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
VB_handle_irregular
);
if
(
Vertices_irregular
.
size
()
!=
0
)
f
->
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
Vertex
)
*
Vertices_irregular
.
size
(),
&
Vertices_irregular
[
0
],
GL_STATIC_DRAW
);
f
->
glGenBuffers
(
1
,
&
IB_irregular_handle
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB_irregular_handle
);
if
(
indices_irregular
.
size
()
!=
0
)
...
...
@@ -96,10 +103,10 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
}
}
void
Mesh
::
MeshEntry
::
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
)
{
void
Mesh
::
MeshEntry
::
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_Irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
)
{
SubdivEntry
*
entry
=
new
SubdivEntry
;
buffers
.
push_back
(
std
::
shared_ptr
<
SubdivEntry
>
(
entry
));
entry
->
init
(
f
,
VB_handle
,
Vertices
,
Indices_irregular
,
patches
);
entry
->
init
(
f
,
VB_handle
,
Vertices
,
Vertices_Irregular
,
Indices_irregular
,
patches
);
}
Mesh
::
MeshEntry
::~
MeshEntry
()
...
...
@@ -481,7 +488,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
}
}
else
{
if
(
!
entry
->
indices_irregular
.
isEmpty
())
{
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entry
->
VB_handle
);
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entry
->
VB_handle
_irregular
);
f
->
glVertexAttribPointer
(
positionIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
0
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entry
->
IB_irregular_handle
);
...
...
QTProject/mesh.h
View file @
85836b9d
...
...
@@ -32,11 +32,13 @@ public:
SubdivEntry
();
~
SubdivEntry
();
GLuint
VB_handle
;
GLuint
VB_handle_irregular
;
GLuint
IB_irregular_handle
;
GLuint
IB_regular_handle
;
QVector
<
Vertex
>
vertices
;
QVector
<
Vertex
>
vertices_irregular
;
QVector
<
unsigned
int
>
indices_irregular
;
QVector
<
unsigned
int
>
indices_regular
;
...
...
@@ -44,7 +46,7 @@ public:
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices_irregular
);
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
);
void
updateIndices
();
};
...
...
@@ -54,7 +56,7 @@ public:
~
MeshEntry
();
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices
);
void
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
);
void
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_Irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
);
QString
name
;
...
...
QTProject/subdivision.cpp
View file @
85836b9d
...
...
@@ -109,13 +109,13 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
QVector
<
unsigned
int
>
irregular_ib
;
trianglesToIB
(
irregular
,
irregular_ib
);
updateIrregularForDraw
(
irregular
,
irregular_ib
,
result
);
updateIrregularForDraw
(
irregular
,
neighbors
,
result
);
QVector
<
unsigned
int
>
patches
;
getPatchIndexBuffer
(
regular
,
neighbors
,
patches
);
qCDebug
(
log_subdiv
)
<<
"patches"
<<
patches
.
length
();
current_mesh
->
update
(
result
.
vb_handle
,
result
.
vertex_buffer
,
irregular_ib
,
patches
);
current_mesh
->
update
(
result
.
vb_handle
,
result
.
vertex_buffer
,
result
.
vertex_buffer_irregular
,
irregular_ib
,
patches
);
}
}
...
...
@@ -1040,13 +1040,77 @@ void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indic
edgeShader
->
release
();
}
void
Subdivision
::
updateIrregularForDraw
(
const
QVector
<
Triangle
>
&
triangles
,
const
QVector
<
unsigned
int
>
&
ib
,
Result
result
){
result
.
vertex_buffer_irregular
_draw
.
resize
(
result
.
vertex_buffer
);
void
Subdivision
::
updateIrregularForDraw
(
const
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
Result
&
result
){
result
.
vertex_buffer_irregular
.
resize
(
result
.
vertex_buffer
.
size
()
);
for
(
int
i
=
0
;
i
<
ib
.
length
();
++
i
)
{
QVectorIterator
<
Triangle
>
it
(
triangles
);
while
(
it
.
hasNext
())
{
Triangle
triangle
=
it
.
next
();
Triangle
::
Neighbors
ns
=
neighbors
.
value
(
triangle
);
QVector
<
Triangle
>
neighboring_triangles
;
// u
Vertex
currentCorner
=
triangle
.
u
();
neighboring_triangles
=
vertexNeighbors
(
triangle
,
ns
.
uv
,
neighbors
);
QVector
<
Vertex
>
surroundingVertex
;
QVectorIterator
<
Triangle
>
extra
(
neighboring_triangles
);
while
(
extra
.
hasNext
())
{
Triangle
extra_triangle
=
extra
.
next
();
if
(
currentCorner
.
samePos
(
extra_triangle
.
u
())
){
bool
found
=
false
;
for
(
int
i
=
0
;
i
<
surroundingVertex
.
length
()
&&
!
found
;
++
i
)
{
if
(
extra_triangle
.
u
().
samePos
(
surroundingVertex
[
i
])){
found
=
true
;
}
}
if
(
!
found
)
surroundingVertex
.
push_back
(
extra_triangle
.
u
());
}
if
(
currentCorner
.
samePos
(
extra_triangle
.
v
())
)
found
=
false
;
for
(
int
i
=
0
;
i
<
surroundingVertex
.
length
()
&&
!
found
;
++
i
)
{
if
(
extra_triangle
.
v
().
samePos
(
surroundingVertex
[
i
])){
found
=
true
;
}
}
if
(
!
found
)
surroundingVertex
.
push_back
(
extra_triangle
.
v
());
Triangle
extra_triangle
=
extra
.
next
();
if
(
currentCorner
.
samePos
(
extra_triangle
.
w
())
)
found
=
false
;
for
(
int
i
=
0
;
i
<
surroundingVertex
.
length
()
&&
!
found
;
++
i
)
{
if
(
extra_triangle
.
w
().
samePos
(
surroundingVertex
[
i
])){
found
=
true
;
}
}
if
(
!
found
)
surroundingVertex
.
push_back
(
extra_triangle
.
w
());
}
//v
//w
neighboring_triangles
+=
vertexNeighbors
(
triangle
,
ns
.
vw
,
neighbors
);
neighboring_triangles
+=
vertexNeighbors
(
triangle
,
ns
.
wu
,
neighbors
);
result
.
vertex_buffer_irregular
[
triangle
.
u_idx
()]
=
result
.
vertex_buffer
.
at
(
triangle
.
u_idx
());
result
.
vertex_buffer_irregular
[
triangle
.
v_idx
()]
=
result
.
vertex_buffer
.
at
(
triangle
.
v_idx
());
result
.
vertex_buffer_irregular
[
triangle
.
w_idx
()]
=
result
.
vertex_buffer
.
at
(
triangle
.
w_idx
());
}
}
QTProject/subdivision.h
View file @
85836b9d
...
...
@@ -41,6 +41,7 @@ private:
{
GLuint
vb_handle
;
QVector
<
Vertex
>
vertex_buffer
;
QVector
<
Vertex
>
vertex_buffer_irregular
;
};
struct
Patch
...
...
@@ -69,6 +70,9 @@ private:
void
runCopyShader
(
GLuint
size
,
GLuint
vb_in
,
GLuint
vb_out
);
void
runVertexShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
vertex_indices_handle
,
GLuint
vertex_offsets_handle
,
GLuint
output_handle
,
GLuint
offset_handle
);
void
runEdgeShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
edge_indices_handle
,
GLuint
output_handle
,
GLuint
offset_handle
);
void
updateIrregularForDraw
(
const
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
Result
&
result
);
QVector
<
unsigned
int
>
patchIBToTriangleIB
(
QVector
<
unsigned
int
>
ib
);
...
...
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