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
44d0a2d5
Commit
44d0a2d5
authored
Jun 27, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass vertex buffer and edge table to shader
parent
1884395d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
23 deletions
+49
-23
subdivision.compute
QTProject/subdivision.compute
+15
-5
subdivision.cpp
QTProject/subdivision.cpp
+34
-18
No files found.
QTProject/subdivision.compute
View file @
44d0a2d5
#version 430 core
#version 430 core
layout (local_size_x =
2
) in;
layout (local_size_x =
1
) in;
layout(std430, binding=0) readonly buffer Input {
struct Vertex {
float offset;
vec3 pos;
vec3 norm;
vec2 uv;
};
};
layout(std430, binding=1) writeonly buffer Output {
layout(std430, binding=0) readonly buffer Vertices {
Vertex vertices[];
};
layout(std430, binding=1) readonly buffer EdgeIndices {
unsigned int indices[][4];
};
layout(std430, binding=2) writeonly buffer Output {
float data[];
float data[];
};
};
void main(){
void main(){
data[gl_GlobalInvocationID.x] =
100 * gl_GlobalInvocationID.x + gl_LocalInvocationID.x + offset
;
data[gl_GlobalInvocationID.x] =
vertices[gl_GlobalInvocationID.x].pos.x
;
}
}
QTProject/subdivision.cpp
View file @
44d0a2d5
...
@@ -266,32 +266,47 @@ void Subdivision::precomputeTables(Mesh *mesh, QVector<QVector<unsigned int> > &
...
@@ -266,32 +266,47 @@ void Subdivision::precomputeTables(Mesh *mesh, QVector<QVector<unsigned int> > &
}
}
void
Subdivision
::
runShader
(
Mesh
*
mesh
,
QVector
<
QVector
<
unsigned
int
>
>
&
edgeIndices
)
{
void
Subdivision
::
runShader
(
Mesh
*
mesh
,
QVector
<
QVector
<
unsigned
int
>
>
&
edgeIndices
)
{
/*
* This shader will set the output buffer to its global ID times hundred + the local id + offset.
*
* So, for offset = 0 we will get 0, 101, 200, 301 and so on as there's two threads in a local group.
*/
qDebug
()
<<
"Running compute shader"
;
qDebug
()
<<
"Running compute shader"
;
int
num
=
6
*
2
;
// must be a multiple of two as we do not handle the other case
GLfloat
offset
=
3.0
f
;
Mesh
::
Node
root
=
mesh
->
getRootNode
();
int
firstMeshEntryIndex
=
-
1
;
bool
meshExists
=
root
.
getFirstMeshIndex
(
firstMeshEntryIndex
);
if
(
!
meshExists
){
qDebug
()
<<
"No Mesh found. Abort shader execution."
;
return
;
}
qDebug
()
<<
"Mesh found. Index:"
<<
firstMeshEntryIndex
;
Mesh
::
MeshEntry
*
firstMeshEntry
=
mesh
->
getMeshEntry
(
firstMeshEntryIndex
);
GLuint
vb_handle
=
firstMeshEntry
->
VB_handle
;
QVector
<
Vertex
>
vb
=
firstMeshEntry
->
getVertexBuffer
();
shader
->
bind
();
shader
->
bind
();
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
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
// Create an input buffer and set it to the value of offset
GLuint
offsetBufferID
;
GLuint
indicesID
;
f
->
glGenBuffers
(
1
,
&
offsetBufferID
);
f
->
glGenBuffers
(
1
,
&
indicesID
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
offsetBufferID
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
indicesID
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
sizeof
(
GLfloat
),
&
offset
,
GL_DYNAMIC_DRAW
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
edgeIndices
.
size
()
*
sizeof
(
GLuint
)
*
4
,
&
edgeIDs
[
0
],
GL_DYNAMIC_DRAW
);
delete
edgeIDs
;
// Create an output buffer
// Create an output buffer
GLuint
bufferID
;
GLuint
bufferID
;
f
->
glGenBuffers
(
1
,
&
bufferID
);
f
->
glGenBuffers
(
1
,
&
bufferID
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
bufferID
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
2
,
bufferID
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
sizeof
(
GLfloat
)
*
num
,
NULL
,
GL_DYNAMIC_DRAW
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
vb
.
size
()
*
sizeof
(
GLfloat
)
,
NULL
,
GL_DYNAMIC_DRAW
);
// Run the shader
// Run the shader
f
->
glDispatchCompute
(
num
/
2
,
1
,
1
);
f
->
glDispatchCompute
(
vb
.
size
()
,
1
,
1
);
// Wait for the shader to complete and the data to be written back to the global memory
// Wait for the shader to complete and the data to be written back to the global memory
f
->
glMemoryBarrier
(
GL_SHADER_STORAGE_BARRIER_BIT
);
f
->
glMemoryBarrier
(
GL_SHADER_STORAGE_BARRIER_BIT
);
...
@@ -299,18 +314,19 @@ void Subdivision::runShader(Mesh *mesh, QVector<QVector<unsigned int> > &edgeInd
...
@@ -299,18 +314,19 @@ void Subdivision::runShader(Mesh *mesh, QVector<QVector<unsigned int> > &edgeInd
// Unbind the buffers from the shader
// Unbind the buffers from the shader
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
2
,
0
);
// Map the output buffer so we can read the results
// Map the output buffer so we can read the results
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
bufferID
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
bufferID
);
GLfloat
*
ptr
;
GLfloat
*
ptr
;
ptr
=
(
GLfloat
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_WRITE_ONLY
);
ptr
=
(
GLfloat
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_WRITE_ONLY
);
for
(
int
i
=
0
;
i
<
num
;
i
++
)
{
for
(
int
i
=
0
;
i
<
vb
.
size
()
;
i
++
)
{
qDebug
()
<<
i
<<
ptr
[
i
]
;
qDebug
()
<<
ptr
[
i
]
<<
vb
[
i
].
pos
.
x
()
;
}
}
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
,
&
offsetBuffer
ID
);
f
->
glDeleteBuffers
(
1
,
&
indices
ID
);
f
->
glDeleteBuffers
(
1
,
&
bufferID
);
f
->
glDeleteBuffers
(
1
,
&
bufferID
);
shader
->
release
();
shader
->
release
();
...
...
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