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
c7e5ff41
Commit
c7e5ff41
authored
Jun 15, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a simple compute shader with in- and output
parent
2aaf8beb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
3 deletions
+61
-3
subdivision.compute
QTProject/subdivision.compute
+13
-3
subdivision.cpp
QTProject/subdivision.cpp
+48
-0
No files found.
QTProject/subdivision.compute
View file @
c7e5ff41
#version 430
#version 430
core
layout (local_size_x = 1) in;
layout (local_size_x = 2) in;
void main() {
layout(std430, binding=0) readonly buffer Input {
float offset;
};
layout(std430, binding=1) writeonly buffer Output {
float data[];
};
void main(){
data[gl_GlobalInvocationID.x] = 100 * gl_GlobalInvocationID.x + gl_LocalInvocationID.x + offset;
}
}
QTProject/subdivision.cpp
View file @
c7e5ff41
...
@@ -95,4 +95,52 @@ void Subdivision::precomputeTables(Mesh *mesh) {
...
@@ -95,4 +95,52 @@ void Subdivision::precomputeTables(Mesh *mesh) {
}
}
void
Subdivision
::
runShader
(
Mesh
*
mesh
)
{
void
Subdivision
::
runShader
(
Mesh
*
mesh
)
{
/*
* 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"
;
int
num
=
6
*
2
;
// must be a multiple of two as we do not handle the other case
GLfloat
offset
=
3.0
f
;
shader
->
bind
();
// Create an input buffer and set it to the value of offset
GLuint
offsetBufferID
;
f
->
glGenBuffers
(
1
,
&
offsetBufferID
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
offsetBufferID
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
sizeof
(
GLfloat
),
&
offset
,
GL_DYNAMIC_DRAW
);
// Create an output buffer
GLuint
bufferID
;
f
->
glGenBuffers
(
1
,
&
bufferID
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
bufferID
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
sizeof
(
GLfloat
)
*
num
,
NULL
,
GL_DYNAMIC_DRAW
);
// Run the shader
f
->
glDispatchCompute
(
num
/
2
,
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
);
// Map the output buffer so we can read the results
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
bufferID
);
GLfloat
*
ptr
;
ptr
=
(
GLfloat
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_WRITE_ONLY
);
for
(
int
i
=
0
;
i
<
num
;
i
++
)
{
qDebug
()
<<
i
<<
ptr
[
i
];
}
f
->
glUnmapBuffer
(
GL_SHADER_STORAGE_BUFFER
);
// Delete the buffers the free the resources
f
->
glDeleteBuffers
(
1
,
&
offsetBufferID
);
f
->
glDeleteBuffers
(
1
,
&
bufferID
);
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