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