1
0
This commit is contained in:
Niklas Birk 2020-04-01 14:40:21 +02:00
parent 9c0188c389
commit 0ac020d531
7 changed files with 17 additions and 18 deletions

View File

@ -336,7 +336,7 @@ void createComputeDescriptorSets(Compute *compute)
void createShaderModule(VkDevice device, char *filename, VkShaderModule *shaderModule)
{
long shaderSourceSize;
size_t shaderSourceSize;
char *shaderSource = readFile(filename, "rb", &shaderSourceSize);
VkShaderModuleCreateInfo shaderModuleInfo;

View File

@ -20,7 +20,7 @@
#define WORKGROUP_SIZE_Z 1
#define SUCCESS 0
#define FAILURE -1
#define FAILURE (-1)
#define ASSERT_VK(f) { \
VkResult res = (f); \
if (res != VK_SUCCESS) { \
@ -28,7 +28,7 @@
assert(res == VK_SUCCESS); \
} \
}
#define ASSERT_GLFW_SUCCESS(res) { if (res != GLFW_TRUE) { printf("Error-Code: %d", res); return FAILURE; } }
#define ASSERT_GLFW_SUCCESS(res) { if ((res) != GLFW_TRUE) { printf("Error-Code: %d", res); return FAILURE; } }
typedef struct dt {
float dt;

View File

@ -70,10 +70,10 @@ int main()
glBindBuffer(GL_ARRAY_BUFFER, particleBuffer);
// position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeOfParticle, (GLvoid *)0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, (GLsizei) sizeOfParticle, (GLvoid *)0);
// color
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeOfParticle, (GLvoid *)24);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, (GLsizei) sizeOfParticle, (GLvoid *)24);
glBindVertexArray(0);
/************* RENDER LOOP *************/
@ -94,7 +94,7 @@ int main()
/*** UPDATE ***/
glUseProgram(computeShaderProgram);
glUniform1f(dtUniformLocation, tFrame);
glUniform1f(dtUniformLocation, (GLfloat) tFrame);
glDispatchCompute(PARTICLE_AMOUNT / WORKGROUP_SIZE_X, 1, 1);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT);

View File

@ -1,6 +1,5 @@
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include "particlesystem.h"
@ -74,9 +73,9 @@ void resetParticle(emitter *e, particle *p)
p->position->y = e->position->y;
p->position->z = e->position->z;
p->velocity->x = ((float) (rand() % 2 ? -1 : 1) * rand()) / RAND_MAX;
p->velocity->y = ((float) (rand() % 2 ? -1 : 1) * rand()) / RAND_MAX;
p->velocity->z = ((float) (rand() % 2 ? -1 : 1) * rand()) / RAND_MAX;
p->velocity->x = ((float) ((rand() % 2 ? -1 : 1) * rand())) / RAND_MAX;
p->velocity->y = ((float) ((rand() % 2 ? -1 : 1) * rand())) / RAND_MAX;
p->velocity->z = ((float) ((rand() % 2 ? -1 : 1) * rand())) / RAND_MAX;
p->age = rand() / 10;
}
@ -86,7 +85,7 @@ void resetParticle(emitter *e, particle *p)
*/
int drawParticles(particle_system *particleSystem)
{
return 0;
}
/*

View File

@ -4,11 +4,11 @@
#include <string.h>
#include "utils.h"
char *readFile(char *filename, char *mode, long *size)
char *readFile(char *filename, char *mode, size_t *size)
{
FILE *file;
char *buffer;
long bytes;
size_t bytes;
if((file = fopen(filename, mode)) == NULL)
{
@ -16,7 +16,7 @@ char *readFile(char *filename, char *mode, long *size)
}
fseek(file, 0L, SEEK_END);
bytes = ftell(file);
bytes = (size_t) ftell(file);
fseek(file, 0L, SEEK_SET);
if((buffer = calloc(bytes, sizeof(char))) == NULL)

View File

@ -6,4 +6,4 @@
#define WORKGROUP_SIZE_X 1024
char *readFile(char *filename, char *mode, long *size);
char *readFile(char *filename, char *mode, size_t *size);

View File

@ -23,7 +23,7 @@ int main()
freeParticleSystem(ps);
/************* INIT GLFW *************/
ASSERT_GLFW_SUCCESS(glfwInit());
ASSERT_GLFW_SUCCESS(glfwInit())
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "Informatikprojekt - Vulkan", NULL, NULL);
@ -54,8 +54,8 @@ int main()
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = &compute.semaphore;
ASSERT_VK(vkQueueSubmit(compute.queue, 1, &submitInfo, VK_NULL_HANDLE));
ASSERT_VK(vkQueueWaitIdle(compute.queue));
ASSERT_VK(vkQueueSubmit(compute.queue, 1, &submitInfo, VK_NULL_HANDLE))
ASSERT_VK(vkQueueWaitIdle(compute.queue))
createComputeCommandBuffer(&compute);