diff options
Diffstat (limited to 'BuddhaTest/src')
-rw-r--r-- | BuddhaTest/src/BuddhaTest.cpp | 17 | ||||
-rw-r--r-- | BuddhaTest/src/Helpers.cpp | 9 |
2 files changed, 19 insertions, 7 deletions
diff --git a/BuddhaTest/src/BuddhaTest.cpp b/BuddhaTest/src/BuddhaTest.cpp index d1b6a66..f8b9074 100644 --- a/BuddhaTest/src/BuddhaTest.cpp +++ b/BuddhaTest/src/BuddhaTest.cpp @@ -14,6 +14,9 @@ int main() unsigned int bufferWidth = 1600;
unsigned int bufferHeight = 900;
+ unsigned int windowWidth = 1600;
+ unsigned int windowHeight = 900;
+
unsigned int orbitLengthRed = 10;
unsigned int orbitLengthGreen = 100;
unsigned int orbitLengthBlue = 1000;
@@ -31,7 +34,7 @@ int main() glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
/* Create a windowed mode window and its OpenGL context */
- window = glfwCreateWindow(1600, 900, "Buddhabrot", NULL, NULL);
+ window = glfwCreateWindow(windowWidth, windowHeight, "Buddhabrot", NULL, NULL);
if (!window)
{
std::cerr << "Failed to create OpenGL 4.3 core context. We do not support compatibility contexts." << std::endl;
@@ -77,7 +80,7 @@ int main() // Create and compile our GLSL program from the shaders
GLuint VertexAndFragmentShaders = Helpers::LoadShaders("Shaders/BuddhaVertex.glsl", "Shaders/BuddhaFragment.glsl");
//Do the same for the compute shader:
- GLuint ComputeShader = Helpers::LoadComputeShader("Shaders/BuddhaCompute.glsl");
+ GLuint ComputeShader = Helpers::LoadComputeShader("Shaders/BuddhaCompute.glsl", 1024, 1, 1);
uint32_t iterationCount{0};
glUseProgram(ComputeShader);
@@ -103,7 +106,7 @@ int main() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(VertexAndFragmentShaders);
- glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
@@ -113,12 +116,12 @@ int main() 0, // stride
(void*)0 // array buffer offset
);
- // Draw the triangle !
+ // Draw the triangle strip!
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // Triangle strip with 4 vertices -> quad.
glDisableVertexAttribArray(0);
/* Swap front and back buffers */
- glfwSwapBuffers(window);
+ glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
@@ -133,6 +136,10 @@ int main() Helpers::WriteOutputPNG(readBackBuffer,bufferWidth,bufferHeight);
}
+ //a bit of cleanup
+ glDeleteBuffers(1,&vertexbuffer);
+ glDeleteBuffers(1,&drawBuffer);
+
glfwTerminate();
return 0;
}
diff --git a/BuddhaTest/src/Helpers.cpp b/BuddhaTest/src/Helpers.cpp index 3512d0f..b092dc2 100644 --- a/BuddhaTest/src/Helpers.cpp +++ b/BuddhaTest/src/Helpers.cpp @@ -98,7 +98,7 @@ namespace Helpers return ProgramID;
}
- GLuint LoadComputeShader(const char* compute_file_path)
+ GLuint LoadComputeShader(const char* compute_file_path, unsigned int localSizeX, unsigned int localSizeY, unsigned int localSizeZ)
{
GLuint ComputeShaderID = glCreateShader(GL_COMPUTE_SHADER);
// Read the compute shader
@@ -107,6 +107,11 @@ namespace Helpers std::ifstream ComputeShaderCodeStream(compute_file_path, std::ios::in);
if (ComputeShaderCodeStream.is_open()) {
std::stringstream sstr;
+ sstr << "#version 430" <<
+ std::endl <<
+ "layout (local_size_x = " << localSizeX <<
+ ", local_size_y = " << localSizeY <<
+ ", local_size_z = " << localSizeZ << ") in;" << std::endl;
sstr << ComputeShaderCodeStream.rdbuf();
ComputeShaderCode = sstr.str();
ComputeShaderCodeStream.close();
@@ -158,7 +163,7 @@ namespace Helpers rows[i] = pngData.data()+3*width*i;
}
- uint32_t maxValue{UINT32_C(0)};
+ uint32_t maxValue{UINT32_C(1)};
for(unsigned int i = 0; i < data.size();++i)
{
maxValue = std::max(maxValue,data[i]);
|