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
9c5ff7de
Commit
9c5ff7de
authored
Jun 29, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Execute vertex shader
parent
1c7fdb0d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
subdivision.cpp
QTProject/subdivision.cpp
+43
-0
subdivision.h
QTProject/subdivision.h
+1
-0
No files found.
QTProject/subdivision.cpp
View file @
9c5ff7de
...
@@ -320,6 +320,18 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
...
@@ -320,6 +320,18 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
void
Subdivision
::
runShader
(
Input
input
,
Tables
&
tables
)
{
void
Subdivision
::
runShader
(
Input
input
,
Tables
&
tables
)
{
qDebug
()
<<
"Running compute shader"
;
qDebug
()
<<
"Running compute shader"
;
// Create an input buffer for the vertex indices
GLuint
vertex_indices_handle
;
f
->
glGenBuffers
(
1
,
&
vertex_indices_handle
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
vertex_indices_handle
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
tables
.
vertex_indices
.
size
()
*
sizeof
(
GLuint
),
tables
.
vertex_indices
.
data
(),
GL_DYNAMIC_DRAW
);
// Create an input buffer for the vertex offsets
GLuint
vertex_offsets_handle
;
f
->
glGenBuffers
(
1
,
&
vertex_offsets_handle
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
vertex_offsets_handle
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
tables
.
vertex_offsets
.
size
()
*
sizeof
(
GLuint
),
tables
.
vertex_offsets
.
data
(),
GL_DYNAMIC_DRAW
);
// Create an input buffer for the edge indices
// Create an input buffer for the edge indices
GLuint
edge_indices_handle
;
GLuint
edge_indices_handle
;
f
->
glGenBuffers
(
1
,
&
edge_indices_handle
);
f
->
glGenBuffers
(
1
,
&
edge_indices_handle
);
...
@@ -334,6 +346,7 @@ void Subdivision::runShader(Input input, Tables &tables) {
...
@@ -334,6 +346,7 @@ void Subdivision::runShader(Input input, Tables &tables) {
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
0
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
0
);
runVertexShader
(
input
.
vertex_buffer
.
size
(),
input
.
vb_handle
,
vertex_indices_handle
,
vertex_offsets_handle
,
output_handle
);
int
edgeOffset
=
input
.
vertex_buffer
.
size
();
int
edgeOffset
=
input
.
vertex_buffer
.
size
();
runEdgeShader
(
tables
.
edge_indices
.
size
()
/
4
,
input
.
vb_handle
,
edge_indices_handle
,
output_handle
,
edgeOffset
);
runEdgeShader
(
tables
.
edge_indices
.
size
()
/
4
,
input
.
vb_handle
,
edge_indices_handle
,
output_handle
,
edgeOffset
);
...
@@ -341,16 +354,46 @@ void Subdivision::runShader(Input input, Tables &tables) {
...
@@ -341,16 +354,46 @@ void Subdivision::runShader(Input input, Tables &tables) {
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
output_handle
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
output_handle
);
Vertex
*
ptr
;
Vertex
*
ptr
;
ptr
=
(
Vertex
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_WRITE_ONLY
);
ptr
=
(
Vertex
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_WRITE_ONLY
);
qDebug
()
<<
"New vertices:"
;
for
(
int
i
=
0
;
i
<
input
.
vertex_buffer
.
size
();
i
++
)
{
qDebug
()
<<
ptr
[
i
].
pos
;
}
qDebug
()
<<
"New edge points:"
;
for
(
int
i
=
0
;
i
<
tables
.
edge_indices
.
size
()
/
4
;
i
++
)
{
for
(
int
i
=
0
;
i
<
tables
.
edge_indices
.
size
()
/
4
;
i
++
)
{
qDebug
()
<<
ptr
[
edgeOffset
+
i
].
pos
;
qDebug
()
<<
ptr
[
edgeOffset
+
i
].
pos
;
}
}
f
->
glUnmapBuffer
(
GL_SHADER_STORAGE_BUFFER
);
f
->
glUnmapBuffer
(
GL_SHADER_STORAGE_BUFFER
);
// Delete the buffers the free the resources
// Delete the buffers the free the resources
f
->
glDeleteBuffers
(
1
,
&
vertex_indices_handle
);
f
->
glDeleteBuffers
(
1
,
&
vertex_offsets_handle
);
f
->
glDeleteBuffers
(
1
,
&
edge_indices_handle
);
f
->
glDeleteBuffers
(
1
,
&
edge_indices_handle
);
f
->
glDeleteBuffers
(
1
,
&
output_handle
);
f
->
glDeleteBuffers
(
1
,
&
output_handle
);
}
}
void
Subdivision
::
runVertexShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
vertex_indices_handle
,
GLuint
vertex_offsets_handle
,
GLuint
output_handle
)
{
vertexShader
->
bind
();
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
vb_handle
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
vertex_indices_handle
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
2
,
vertex_offsets_handle
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
3
,
output_handle
);
// Run the shader
f
->
glDispatchCompute
(
size
,
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
);
// Unbind the buffers from the shader
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
2
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
3
,
0
);
vertexShader
->
release
();
}
void
Subdivision
::
runEdgeShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
edge_indices_handle
,
GLuint
output_handle
,
GLuint
offset
)
{
void
Subdivision
::
runEdgeShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
edge_indices_handle
,
GLuint
output_handle
,
GLuint
offset
)
{
edgeShader
->
bind
();
edgeShader
->
bind
();
...
...
QTProject/subdivision.h
View file @
9c5ff7de
...
@@ -38,6 +38,7 @@ private:
...
@@ -38,6 +38,7 @@ private:
QOpenGLShaderProgram
*
initComputeShaderProgram
(
QString
&
source
);
QOpenGLShaderProgram
*
initComputeShaderProgram
(
QString
&
source
);
Tables
precomputeTables
(
Input
input
);
Tables
precomputeTables
(
Input
input
);
void
runShader
(
Input
input
,
Tables
&
tables
);
void
runShader
(
Input
input
,
Tables
&
tables
);
void
runVertexShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
vertex_indices_handle
,
GLuint
vertex_offsets_handle
,
GLuint
output_handle
);
void
runEdgeShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
edge_indices_handle
,
GLuint
output_handle
,
GLuint
offset
);
void
runEdgeShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
edge_indices_handle
,
GLuint
output_handle
,
GLuint
offset
);
};
};
...
...
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