summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/main.c b/main.c
index cc4976d..04eb4ce 100644
--- a/main.c
+++ b/main.c
@@ -32,7 +32,7 @@
// use compute shader to update particles?
// (if false, map the buffer and populate it on the cpu)
-#define USE_COMPUTE_SHADER false
+#define USE_COMPUTE_SHADER true
// enable gl debug
#define USE_GL_DEBUG false
@@ -41,7 +41,7 @@
#define NUM_PARTICLES 1024
// size of compute shader workgroups
-#define WORKGROUP_SIZE 1
+#define WORKGROUP_SIZE 128
typedef struct {
const GLuint type;
@@ -85,11 +85,10 @@ typedef struct {
" mediump vec4 colors[" S(NUM_PARTICLES) "];\n" \
"};\n"
-#if 0
// real compute shader
static const char
cs_src[] =
- "#version 320 es\n"
+ "#version 450 core\n"
#if USE_GL_DEBUG
"#pragma debug(on)\n"
#endif /* USE_GL_DEBUG */
@@ -101,20 +100,24 @@ cs_src[] =
"void main() {\n"
" mediump uint i = gl_GlobalInvocationID.x;\n"
" positions[i] += 0.016 * velocities[i];\n"
+ "\n"
+ " if (positions[i].x > 1.1) {\n"
+ " positions[i].x -= 2.2;\n"
+ " } else if (positions[i].x < -1.1) {\n"
+ " positions[i].x += 2.2;\n"
+ " }\n"
+ "\n"
+ " if (positions[i].y > 1.1) {\n"
+ " positions[i].y -= 2.2;\n"
+ " } else if (positions[i].y < -1.1) {\n"
+ " positions[i].y += 2.2;\n"
+ " }\n"
"}\n";
-#endif /* 0 */
-
-// empty compute shader
-static const char
-cs_src[] =
- "#version 320 es\n"
- "layout(local_size_x = " S(WORKGROUP_SIZE) ") in;\n"
- "void main() {}\n";
// vertex shader
static const char
vs_src[] =
- "#version 320 es\n"
+ "#version 450 core\n"
"\n"
PARTICLE_BUFFER
"\n"
@@ -129,7 +132,7 @@ vs_src[] =
// fragment shader
static const char
fs_src[] =
- "#version 320 es\n"
+ "#version 450 core\n"
"\n"
PARTICLE_BUFFER
"\n"
@@ -451,20 +454,20 @@ ctx_init(context_t * const ctx) {
// set gl context majory version hint
if (SDL_GL_SetAttribute(
SDL_GL_CONTEXT_PROFILE_MASK,
- SDL_GL_CONTEXT_PROFILE_ES
+ SDL_GL_CONTEXT_PROFILE_CORE
) < 0) {
LOG_C("SDL_GL_SetAttribute() failed: %s", SDL_GetError());
exit(EXIT_FAILURE);
}
// set gl context majory version hint
- if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) < 0) {
+ if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4) < 0) {
LOG_C("SDL_GL_SetAttribute() failed: %s", SDL_GetError());
exit(EXIT_FAILURE);
}
// set gl context minor version hint
- if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2) < 0) {
+ if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5) < 0) {
LOG_C("SDL_GL_SetAttribute() failed: %s", SDL_GetError());
exit(EXIT_FAILURE);
}