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
1431f036
Commit
1431f036
authored
Jun 28, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Turn edgeIndices_base into a flat array
parent
23085e12
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
37 deletions
+45
-37
subdivision.cpp
QTProject/subdivision.cpp
+43
-33
subdivision.h
QTProject/subdivision.h
+2
-4
No files found.
QTProject/subdivision.cpp
View file @
1431f036
...
...
@@ -15,15 +15,6 @@ void Subdivision::init() {
edgeShader
=
initComputeShaderProgram
(
source
);
}
QVector
<
unsigned
int
>
Subdivision
::
fillVector
(
unsigned
int
a
,
unsigned
int
b
,
unsigned
int
c
,
unsigned
int
d
){
QVector
<
unsigned
int
>
x
;
x
.
push_back
(
a
);
x
.
push_back
(
b
);
x
.
push_back
(
c
);
x
.
push_back
(
d
);
return
x
;
}
QOpenGLShaderProgram
*
Subdivision
::
initComputeShaderProgram
(
QString
&
source
){
qDebug
()
<<
"Compiling compute shader ..."
;
QOpenGLShader
*
computeShader
=
new
QOpenGLShader
(
QOpenGLShader
::
Compute
);
...
...
@@ -61,7 +52,7 @@ Mesh *Subdivision::subdivide(Mesh *mesh) {
input
.
vertex_buffer
=
current_mesh
->
getVertexBuffer
();
input
.
index_buffer
=
current_mesh
->
getIndexBuffer
();
QVector
<
QVector
<
unsigned
int
>
>
edgeIndices
;
QVector
<
unsigned
int
>
edgeIndices
;
QVector
<
unsigned
int
>
vertexIndices
;
QVector
<
unsigned
int
>
vertexIndicesOffsets
;
precomputeTables
(
input
,
edgeIndices
,
vertexIndices
,
vertexIndicesOffsets
);
...
...
@@ -69,7 +60,7 @@ Mesh *Subdivision::subdivide(Mesh *mesh) {
return
NULL
;
}
void
Subdivision
::
precomputeTables
(
Input
input
,
QVector
<
QVector
<
unsigned
int
>
>
&
edgeIndices_base
,
void
Subdivision
::
precomputeTables
(
Input
input
,
QVector
<
unsigned
int
>
&
edgeIndices_base
,
QVector
<
unsigned
int
>
&
vertexIndices
,
QVector
<
unsigned
int
>
&
vertexIndicesOffsets
)
{
QVector
<
unsigned
int
>
ib
=
input
.
index_buffer
;
QVector
<
Vertex
>
vb
=
input
.
vertex_buffer
;
...
...
@@ -119,13 +110,22 @@ void Subdivision::precomputeTables(Input input, QVector<QVector<unsigned int> >
//zx = ba, cb, ac
//TODO if oder else if?
if
(
x
.
samePos
(
a
)
&&
y
.
samePos
(
c
)){
edgeIndices_base
.
push_back
(
fillVector
(
x_i
,
y_i
,
z_i
,
b_i
));
edgeIndices_base
.
push_back
(
x_i
);
edgeIndices_base
.
push_back
(
y_i
);
edgeIndices_base
.
push_back
(
z_i
);
edgeIndices_base
.
push_back
(
b_i
);
}
if
(
x
.
samePos
(
b
)
&&
y
.
samePos
(
a
)){
edgeIndices_base
.
push_back
(
fillVector
(
x_i
,
y_i
,
z_i
,
c_i
));
edgeIndices_base
.
push_back
(
x_i
);
edgeIndices_base
.
push_back
(
y_i
);
edgeIndices_base
.
push_back
(
z_i
);
edgeIndices_base
.
push_back
(
c_i
);
}
if
(
x
.
samePos
(
c
)
&&
y
.
samePos
(
b
)){
edgeIndices_base
.
push_back
(
fillVector
(
x_i
,
y_i
,
z_i
,
a_i
));
edgeIndices_base
.
push_back
(
x_i
);
edgeIndices_base
.
push_back
(
y_i
);
edgeIndices_base
.
push_back
(
z_i
);
edgeIndices_base
.
push_back
(
a_i
);
}
}
}
...
...
@@ -146,13 +146,22 @@ void Subdivision::precomputeTables(Input input, QVector<QVector<unsigned int> >
//yz = ba, cb, ac
if
(
y
.
samePos
(
a
)
&&
z
.
samePos
(
c
)){
edgeIndices_base
.
push_back
(
fillVector
(
y_i
,
z_i
,
x_i
,
b_i
));
edgeIndices_base
.
push_back
(
y_i
);
edgeIndices_base
.
push_back
(
z_i
);
edgeIndices_base
.
push_back
(
x_i
);
edgeIndices_base
.
push_back
(
b_i
);
}
if
(
y
.
samePos
(
b
)
&&
z
.
samePos
(
a
)){
edgeIndices_base
.
push_back
(
fillVector
(
y_i
,
z_i
,
x_i
,
c_i
));
edgeIndices_base
.
push_back
(
y_i
);
edgeIndices_base
.
push_back
(
z_i
);
edgeIndices_base
.
push_back
(
x_i
);
edgeIndices_base
.
push_back
(
c_i
);
}
if
(
y
.
samePos
(
c
)
&&
z
.
samePos
(
b
)){
edgeIndices_base
.
push_back
(
fillVector
(
y_i
,
z_i
,
x_i
,
a_i
));
edgeIndices_base
.
push_back
(
y_i
);
edgeIndices_base
.
push_back
(
z_i
);
edgeIndices_base
.
push_back
(
x_i
);
edgeIndices_base
.
push_back
(
a_i
);
}
}
}
...
...
@@ -174,13 +183,22 @@ void Subdivision::precomputeTables(Input input, QVector<QVector<unsigned int> >
if
(
x
.
samePos
(
a
)
&&
z
.
samePos
(
b
)){
edgeIndices_base
.
push_back
(
fillVector
(
x_i
,
z_i
,
y_i
,
c_i
));
edgeIndices_base
.
push_back
(
x_i
);
edgeIndices_base
.
push_back
(
z_i
);
edgeIndices_base
.
push_back
(
y_i
);
edgeIndices_base
.
push_back
(
c_i
);
}
if
(
x
.
samePos
(
b
)
&&
z
.
samePos
(
c
)){
edgeIndices_base
.
push_back
(
fillVector
(
x_i
,
z_i
,
y_i
,
a_i
));
edgeIndices_base
.
push_back
(
x_i
);
edgeIndices_base
.
push_back
(
z_i
);
edgeIndices_base
.
push_back
(
y_i
);
edgeIndices_base
.
push_back
(
a_i
);
}
if
(
x
.
samePos
(
c
)
&&
z
.
samePos
(
a
)){
edgeIndices_base
.
push_back
(
fillVector
(
x_i
,
z_i
,
y_i
,
b_i
));
edgeIndices_base
.
push_back
(
x_i
);
edgeIndices_base
.
push_back
(
z_i
);
edgeIndices_base
.
push_back
(
y_i
);
edgeIndices_base
.
push_back
(
b_i
);
}
}
}
//quadratische Laufzeit ftw
...
...
@@ -264,34 +282,26 @@ void Subdivision::precomputeTables(Input input, QVector<QVector<unsigned int> >
}
void
Subdivision
::
runShader
(
Input
input
,
QVector
<
QVector
<
unsigned
int
>
>
&
edgeIndices
)
{
void
Subdivision
::
runShader
(
Input
input
,
QVector
<
unsigned
int
>
&
edgeIndices
)
{
qDebug
()
<<
"Running compute shader"
;
edgeShader
->
bind
();
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
input
.
vb_handle
);
GLuint
*
edgeIDs
=
new
GLuint
[
edgeIndices
.
size
()
*
4
];
for
(
uint
i
=
0
;
i
<
edgeIndices
.
size
();
i
++
)
{
for
(
uint
j
=
0
;
j
<
4
;
j
++
)
{
edgeIDs
[
4
*
i
+
j
]
=
edgeIndices
[
i
][
j
];
}
}
// Create an input buffer and set it to the value of offset
GLuint
indicesID
;
f
->
glGenBuffers
(
1
,
&
indicesID
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
indicesID
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
edgeIndices
.
size
()
*
sizeof
(
GLuint
)
*
4
,
&
edgeIDs
[
0
],
GL_DYNAMIC_DRAW
);
delete
edgeIDs
;
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
edgeIndices
.
size
()
*
sizeof
(
GLuint
),
edgeIndices
.
data
(),
GL_DYNAMIC_DRAW
);
// Create an output buffer
GLuint
bufferID
;
f
->
glGenBuffers
(
1
,
&
bufferID
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
2
,
bufferID
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
edgeIndices
.
size
()
*
sizeof
(
Vertex
),
NULL
,
GL_DYNAMIC_DRAW
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
edgeIndices
.
size
()
*
sizeof
(
Vertex
)
/
4
,
NULL
,
GL_DYNAMIC_DRAW
);
// Run the shader
f
->
glDispatchCompute
(
edgeIndices
.
size
(),
1
,
1
);
f
->
glDispatchCompute
(
edgeIndices
.
size
()
/
4
,
1
,
1
);
// Wait for the shader to complete and the data to be written back to the global memory
f
->
glMemoryBarrier
(
GL_SHADER_STORAGE_BARRIER_BIT
);
...
...
@@ -305,7 +315,7 @@ void Subdivision::runShader(Input input, QVector<QVector<unsigned int> > &edgeIn
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
bufferID
);
Vertex
*
ptr
;
ptr
=
(
Vertex
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_WRITE_ONLY
);
for
(
int
i
=
0
;
i
<
edgeIndices
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
edgeIndices
.
size
()
/
4
;
i
++
)
{
qDebug
()
<<
ptr
[
i
].
pos
;
}
f
->
glUnmapBuffer
(
GL_SHADER_STORAGE_BUFFER
);
...
...
QTProject/subdivision.h
View file @
1431f036
...
...
@@ -27,11 +27,9 @@ private:
QOpenGLShaderProgram
*
edgeShader
;
QOpenGLShaderProgram
*
initComputeShaderProgram
(
QString
&
source
);
void
precomputeTables
(
Input
input
,
QVector
<
QVector
<
unsigned
int
>
>
&
edgeIndices_base
,
void
precomputeTables
(
Input
input
,
QVector
<
unsigned
int
>
&
edgeIndices_base
,
QVector
<
unsigned
int
>
&
vertexIndices
,
QVector
<
unsigned
int
>
&
vertexIndicesOffsets
);
void
runShader
(
Input
input
,
QVector
<
QVector
<
unsigned
int
>
>
&
edgeIndices
);
QVector
<
unsigned
int
>
fillVector
(
unsigned
int
a
,
unsigned
int
b
,
unsigned
int
c
,
unsigned
int
d
);
void
runShader
(
Input
input
,
QVector
<
unsigned
int
>
&
edgeIndices
);
};
#endif
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