did vulkan stuff / opengl stuff
This commit is contained in:
parent
1d10921b75
commit
357cca6dd5
@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.15)
|
||||
project(Informatikprojekt C)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(PROJECT_SOURCES particlesystem.h particlesystem.c def.h)
|
||||
set(PROJECT_SOURCES_OPENGL ${PROJECT_SOURCES} initOpenGL.h initOpenGL.c def.h glad/src/glad.c)
|
||||
set(PROJECT_SOURCES particlesystem.h particlesystem.c utils.h utils.c)
|
||||
set(PROJECT_SOURCES_OPENGL ${PROJECT_SOURCES} initOpenGL.h initOpenGL.c utils.h glad/src/glad.c)
|
||||
set(PROJECT_SOURCES_VULKAN ${PROJECT_SOURCES} initVulkan.h initVulkan.c)
|
||||
|
||||
add_executable(Informatikprojekt cpuMain.c ${PROJECT_SOURCES_OPENGL})
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "particlesystem.h"
|
||||
#include "initOpenGL.h"
|
||||
#include "def.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define PARTICLE_AMOUNT 1000
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "initVulkan.h"
|
||||
|
||||
int initVulkan(VkInstance *vkInstance, VkDevice *device, VkSurfaceKHR *surface, GLFWwindow *window,
|
||||
VkSwapchainKHR *swapChain, VkImageView *imageViews, uint32_t *amountImages)
|
||||
VkSwapchainKHR *swapChain, VkImageView **imageViews, uint32_t *amountImages)
|
||||
{
|
||||
// VkApplicationInfo
|
||||
VkApplicationInfo appInfo;
|
||||
@ -68,14 +68,16 @@ int initVulkan(VkInstance *vkInstance, VkDevice *device, VkSurfaceKHR *surface,
|
||||
ASSERT_VK_SUCCESS(vkGetSwapchainImagesKHR(*device, *swapChain, amountImages, swapChainImages))
|
||||
|
||||
// Image view
|
||||
imageViews = malloc(*amountImages * sizeof(VkImageView));
|
||||
*imageViews = malloc(*amountImages * sizeof(VkImageView));
|
||||
VkImageViewCreateInfo imageViewInfo;
|
||||
for (int i = 0; i < *amountImages; i++)
|
||||
{
|
||||
initImageViewInfo(&imageViewInfo, swapChainImages, i);
|
||||
ASSERT_VK_SUCCESS(vkCreateImageView(*device, &imageViewInfo, NULL, &imageViews[i]))
|
||||
ASSERT_VK_SUCCESS(vkCreateImageView(*device, &imageViewInfo, NULL, &*imageViews[i]))
|
||||
}
|
||||
|
||||
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#include "def.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define APP_NAME "Informatikprojekt - Vulkan"
|
||||
#define APP_VERSION VK_MAKE_VERSION(0, 0, 0)
|
||||
@ -26,7 +26,7 @@
|
||||
val * 9.313226e-10
|
||||
|
||||
int initVulkan(VkInstance *vkInstance, VkDevice *device, VkSurfaceKHR *surface, GLFWwindow *window,
|
||||
VkSwapchainKHR *swapChain, VkImageView *imageViews, uint32_t *amountImages);
|
||||
VkSwapchainKHR *swapChain, VkImageView **imageViews, uint32_t *amountImages);
|
||||
void initAppInfo(VkApplicationInfo *appInfo);
|
||||
void initCreateInfo(VkApplicationInfo *appInfo, VkInstanceCreateInfo *instanceInfo);
|
||||
void initQueueInfo(VkDeviceQueueCreateInfo *queueInfo);
|
||||
|
28
openglMain.c
28
openglMain.c
@ -1,6 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "particlesystem.h"
|
||||
#include "initOpenGL.h"
|
||||
#include "def.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define PARTICLE_AMOUNT 1000000
|
||||
|
||||
@ -31,6 +32,7 @@ int main()
|
||||
const GLchar *computeShaderSource = "#version 460\n"
|
||||
"\n"
|
||||
"#define FLOAT_MAX 4294967296.0f\n"
|
||||
"#define FLOAT_FACTOR 0.00000000023283064365386962890625f\n"
|
||||
"\n"
|
||||
"struct particle\n"
|
||||
"{\n"
|
||||
@ -64,13 +66,17 @@ int main()
|
||||
"\n"
|
||||
"uint rand(uint seed)\n"
|
||||
"{\n"
|
||||
" // Xorshift algorithm from George Marsaglia's paper\n"
|
||||
" seed ^= (seed << 13u);\n"
|
||||
" seed ^= (seed >> 17u);\n"
|
||||
" seed ^= (seed << 5u);\n"
|
||||
" return seed;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"int foreSign(uint seed)\n"
|
||||
"{\n"
|
||||
" return rand(seed) % 2 == 0 ? 1 : -1;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" uint gid = gl_GlobalInvocationID.x;\n"
|
||||
@ -82,7 +88,7 @@ int main()
|
||||
" uint hash1 = hash(uvec3(uint(part.px * FLOAT_MAX), uint(part.cy * FLOAT_MAX), uint(part.vz * FLOAT_MAX)));\n"
|
||||
" uint hash2 = hash(uvec3(uint(part.vx * FLOAT_MAX), uint(part.py * FLOAT_MAX), uint(part.cz * FLOAT_MAX)));\n"
|
||||
" uint hash3 = hash(uvec3(uint(part.cx * FLOAT_MAX), uint(part.vy * FLOAT_MAX), uint(part.pz * FLOAT_MAX)));\n"
|
||||
" \n"
|
||||
"\n"
|
||||
" if (part.age < 0 || part.px > 1 || part.py > 1 || part.pz > 1 || part.px < -1 || part.py < -1 || part.pz < -1)\n"
|
||||
" {\n"
|
||||
" part.px = resetPos.x;\n"
|
||||
@ -91,13 +97,13 @@ int main()
|
||||
"\n"
|
||||
" part.age = rand(hash(uvec3(hash1, hash2, hash3))) % (250 - 60 + 1) + 60;\n"
|
||||
"\n"
|
||||
" part.vx = (rand(hash1) % 2 == 0 ? 1 : -1) * float(rand(hash2)) * (1.0f / FLOAT_MAX);\n"
|
||||
" part.vy = (rand(hash3) % 2 == 0 ? 1 : -1) * float(rand(hash1)) * (1.0f / FLOAT_MAX);\n"
|
||||
" part.vz = (rand(hash2) % 2 == 0 ? 1 : -1) * float(rand(hash3)) * (1.0f / FLOAT_MAX);\n"
|
||||
" part.vx = foreSign(hash1) * float(rand(hash2)) * FLOAT_FACTOR;\n"
|
||||
" part.vy = foreSign(hash3) * float(rand(hash1)) * FLOAT_FACTOR;\n"
|
||||
" part.vz = foreSign(hash2) * float(rand(hash3)) * FLOAT_FACTOR;\n"
|
||||
"\n"
|
||||
" part.cx = float(rand(hash3)) * (1.0f / FLOAT_MAX);\n"
|
||||
" part.cy = float(rand(hash2)) * (1.0f / FLOAT_MAX);\n"
|
||||
" part.cz = float(rand(hash1)) * (1.0f / FLOAT_MAX);\n"
|
||||
" part.cx = float(rand(hash1 ^ hash2)) * FLOAT_FACTOR;\n"
|
||||
" part.cy = float(rand(hash2 ^ hash3)) * FLOAT_FACTOR;\n"
|
||||
" part.cz = float(rand(hash3 ^ hash1)) * FLOAT_FACTOR;\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
@ -105,10 +111,6 @@ int main()
|
||||
" part.py += part.vy * dt;\n"
|
||||
" part.pz += part.vz * dt;\n"
|
||||
"\n"
|
||||
" part.cx = float(rand(hash1)) * (1.0f / FLOAT_MAX);\n"
|
||||
" part.cy = float(rand(hash1)) * (1.0f / FLOAT_MAX);\n"
|
||||
" part.cz = float(rand(hash1)) * (1.0f / FLOAT_MAX);\n"
|
||||
"\n"
|
||||
" part.age -= 0.01f;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
|
@ -1,6 +1,7 @@
|
||||
#version 460
|
||||
|
||||
#define FLOAT_MAX 4294967296.0f
|
||||
#define FLOAT_FACTOR 0.00000000023283064365386962890625f
|
||||
|
||||
struct particle
|
||||
{
|
||||
@ -34,13 +35,17 @@ uint hash(uvec3 seed)
|
||||
|
||||
uint rand(uint seed)
|
||||
{
|
||||
// Xorshift algorithm from George Marsaglia's paper
|
||||
seed ^= (seed << 13u);
|
||||
seed ^= (seed >> 17u);
|
||||
seed ^= (seed << 5u);
|
||||
return seed;
|
||||
}
|
||||
|
||||
int foreSign(uint seed)
|
||||
{
|
||||
return rand(seed) % 2 == 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
uint gid = gl_GlobalInvocationID.x;
|
||||
@ -61,13 +66,13 @@ void main()
|
||||
|
||||
part.age = rand(hash(uvec3(hash1, hash2, hash3))) % (250 - 60 + 1) + 60;
|
||||
|
||||
part.vx = (rand(hash1) % 2 == 0 ? 1 : -1) * float(rand(hash2)) * (1.0f / FLOAT_MAX);
|
||||
part.vy = (rand(hash3) % 2 == 0 ? -1 : 1) * float(rand(hash1)) * (1.0f / FLOAT_MAX);
|
||||
part.vz = (rand(hash2) % 2 == 0 ? 1 : -1) * float(rand(hash3)) * (1.0f / FLOAT_MAX);
|
||||
part.vx = foreSign(hash1) * float(rand(hash2)) * FLOAT_FACTOR;
|
||||
part.vy = foreSign(hash3) * float(rand(hash1)) * FLOAT_FACTOR;
|
||||
part.vz = foreSign(hash2) * float(rand(hash3)) * FLOAT_FACTOR;
|
||||
|
||||
part.cx = float(rand(hash1)) * (1.0f / FLOAT_MAX);
|
||||
part.cy = float(rand(hash1)) * (1.0f / FLOAT_MAX);
|
||||
part.cz = float(rand(hash1)) * (1.0f / FLOAT_MAX);
|
||||
part.cx = float(rand(hash1 ^ hash2)) * FLOAT_FACTOR;
|
||||
part.cy = float(rand(hash2 ^ hash3)) * FLOAT_FACTOR;
|
||||
part.cz = float(rand(hash3 ^ hash1)) * FLOAT_FACTOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -75,10 +80,6 @@ void main()
|
||||
part.py += part.vy * dt;
|
||||
part.pz += part.vz * dt;
|
||||
|
||||
part.cx = float(rand(hash1)) * (1.0f / FLOAT_MAX);
|
||||
part.cy = float(rand(hash1)) * (1.0f / FLOAT_MAX);
|
||||
part.cz = float(rand(hash1)) * (1.0f / FLOAT_MAX);
|
||||
|
||||
part.age -= 0.01f;
|
||||
}
|
||||
|
||||
|
27
utils.c
Normal file
27
utils.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
char *readFile(char *path)
|
||||
{
|
||||
FILE *file = fopen(path, "r");
|
||||
char *str = malloc(BUFFER_SIZE);
|
||||
int c, i = 0, j = 1;
|
||||
|
||||
while ((c = fgetc(file)) != EOF)
|
||||
{
|
||||
if (i == j * BUFFER_SIZE)
|
||||
{
|
||||
str = realloc(str, ++j * BUFFER_SIZE);
|
||||
}
|
||||
|
||||
str[i++] = (char) c;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
@ -3,3 +3,5 @@
|
||||
|
||||
#define UPPER_AGE 250
|
||||
#define LOWER_AGE 60
|
||||
|
||||
char *readFile(char *path);
|
@ -8,7 +8,7 @@ int main()
|
||||
VkDevice device;
|
||||
VkSurfaceKHR surface;
|
||||
VkSwapchainKHR swapChain;
|
||||
VkImageView *imageViews;
|
||||
VkImageView *imageViews = NULL;
|
||||
uint32_t amountImages;
|
||||
|
||||
// GLFW
|
||||
@ -18,7 +18,7 @@ int main()
|
||||
GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "Informatikprojekt - Vulkan", NULL, NULL);
|
||||
|
||||
// Init Vulkan
|
||||
ASSERT_SUCCESS(initVulkan(&vkInstance, &device, &surface, window, &swapChain, imageViews, &amountImages))
|
||||
ASSERT_SUCCESS(initVulkan(&vkInstance, &device, &surface, window, &swapChain, &imageViews, &amountImages))
|
||||
|
||||
// Render Loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
|
Loading…
Reference in New Issue
Block a user