generated from Persson-dev/OpenGLComputeShader
remove memory fetch of vertex shader
This commit is contained in:
@@ -1,18 +1,11 @@
|
|||||||
#version 460 core
|
#version 460 core
|
||||||
|
|
||||||
layout(std430, binding = 3) buffer layoutName
|
|
||||||
{
|
|
||||||
float data_SSBO[];
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(location = 0) uniform mat4 viewMatrix;
|
layout(location = 0) uniform mat4 viewMatrix;
|
||||||
layout(location = 1) uniform mat4 projectionMatrix;
|
layout(location = 1) uniform mat4 projectionMatrix;
|
||||||
|
|
||||||
vec3 unpack(uint index) {
|
layout(location = 0) in vec3 position;
|
||||||
return vec3(data_SSBO[index * 3], data_SSBO[index * 3 + 1], data_SSBO[index * 3 + 2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = projectionMatrix * viewMatrix * vec4(unpack(gl_InstanceID), 1.0);
|
gl_Position = projectionMatrix * viewMatrix * vec4(position, 1.0);
|
||||||
}
|
}
|
||||||
32
src/Main.cpp
32
src/Main.cpp
@@ -169,31 +169,22 @@ static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLuint CreateDummyVAO() {
|
|
||||||
|
static std::tuple<GLuint, GLuint> CreateVAO() {
|
||||||
GLuint vertexArray;
|
GLuint vertexArray;
|
||||||
glCreateVertexArrays(1, &vertexArray);
|
glCreateVertexArrays(1, &vertexArray);
|
||||||
|
|
||||||
GLuint vertexBuffer;
|
GLuint vertexBuffer;
|
||||||
glCreateBuffers(1, &vertexBuffer);
|
glCreateBuffers(1, &vertexBuffer);
|
||||||
|
|
||||||
// Buffer with just one point
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||||
float vertices[] = {0.0f, 0.0f, 0.0f};
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * PARTICLE_COUNT * 3, nullptr, GL_DYNAMIC_DRAW);
|
||||||
glNamedBufferData(vertexBuffer, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
|
||||||
glVertexArrayVertexBuffer(vertexArray, 0, vertexBuffer, 0, sizeof(float) * 3);
|
glVertexArrayVertexBuffer(vertexArray, 0, vertexBuffer, 0, sizeof(float) * 3);
|
||||||
glEnableVertexArrayAttrib(vertexArray, 0);
|
glEnableVertexArrayAttrib(vertexArray, 0);
|
||||||
glVertexArrayAttribFormat(vertexArray, 0, 3, GL_FLOAT, GL_FALSE, 0);
|
glVertexArrayAttribFormat(vertexArray, 0, 3, GL_FLOAT, GL_FALSE, 0);
|
||||||
glVertexArrayAttribBinding(vertexArray, 0, 0);
|
glVertexArrayAttribBinding(vertexArray, 0, 0);
|
||||||
|
|
||||||
return vertexArray;
|
return {vertexArray, vertexBuffer};
|
||||||
}
|
|
||||||
|
|
||||||
static void CreateGpuBuffer() {
|
|
||||||
GLuint ssbo;
|
|
||||||
glGenBuffers(1, &ssbo);
|
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
|
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, ssbo);
|
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(float) * 3 * PARTICLE_COUNT, nullptr,
|
|
||||||
GL_DYNAMIC_COPY); // sizeof(data) only works for statically sized C/C++ arrays.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<glm::mat4> GetTransformMatrixBlended(float dt) {
|
static std::vector<glm::mat4> GetTransformMatrixBlended(float dt) {
|
||||||
@@ -264,9 +255,7 @@ int main() {
|
|||||||
if (!window)
|
if (!window)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
auto vertexArray = CreateDummyVAO();
|
auto [vertexArray, vertexBuffer] = CreateVAO();
|
||||||
|
|
||||||
CreateGpuBuffer();
|
|
||||||
|
|
||||||
float lastTime = (float)glfwGetTime();
|
float lastTime = (float)glfwGetTime();
|
||||||
|
|
||||||
@@ -274,14 +263,17 @@ int main() {
|
|||||||
float secondsTimer = 0.0f;
|
float secondsTimer = 0.0f;
|
||||||
float animationTimer = 0.0f;
|
float animationTimer = 0.0f;
|
||||||
|
|
||||||
glBindVertexArray(vertexArray);
|
|
||||||
|
|
||||||
// ApplyTransforms(SIERPINSKI_TRIANGLE);
|
// ApplyTransforms(SIERPINSKI_TRIANGLE);
|
||||||
s_T1 = GenRandomFractal();
|
s_T1 = GenRandomFractal();
|
||||||
s_T2 = GenRandomFractal();
|
s_T2 = GenRandomFractal();
|
||||||
|
|
||||||
glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
|
glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
|
||||||
|
|
||||||
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vertexBuffer);
|
||||||
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, vertexBuffer);
|
||||||
|
|
||||||
|
glBindVertexArray(vertexArray);
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
// ScopedTimer timer("Main Loop");
|
// ScopedTimer timer("Main Loop");
|
||||||
|
|
||||||
@@ -318,7 +310,7 @@ int main() {
|
|||||||
// Graphics
|
// Graphics
|
||||||
glUseProgram(s_GraphicsShader);
|
glUseProgram(s_GraphicsShader);
|
||||||
|
|
||||||
glDrawArraysInstanced(GL_POINTS, 0, 1, PARTICLE_COUNT);
|
glDrawArrays(GL_POINTS, 0, PARTICLE_COUNT);
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|||||||
Reference in New Issue
Block a user