aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-25 23:47:27 +0200
committerAdrian Kummerlaender2018-05-25 23:48:59 +0200
commitf728e4c8d202de241673a13ce61570b6acb4bba7 (patch)
treea7e29c4319f0e6d667b98f359ddf089c0565c15a /src
parent5157658ec0cc07d2c56c978ca010cbb78236439f (diff)
downloadcomputicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.gz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.bz2
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.lz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.xz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.zst
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.zip
Restructure source directory
Diffstat (limited to 'src')
-rw-r--r--src/buffer/frame/texture_framebuffer.h (renamed from src/texture_buffer.h)16
-rw-r--r--src/buffer/vertex/particle_vertex_buffer.h (renamed from src/particle_vertex_buffer.h)0
-rw-r--r--src/buffer/vertex/texture_display_vertex_buffer.h (renamed from src/texture_display_buffer.h)6
-rw-r--r--src/glfw/guard.h (renamed from src/glfw_guard.h)0
-rw-r--r--src/glfw/window.h (renamed from src/window.h)0
-rw-r--r--src/main.cc53
-rw-r--r--src/shader/code/compute.glsl (renamed from src/shader/compute.glsl)0
-rw-r--r--src/shader/code/display_fragment.glsl (renamed from src/shader/display_fragment.glsl)0
-rw-r--r--src/shader/code/display_vertex.glsl (renamed from src/shader/display_vertex.glsl)0
-rw-r--r--src/shader/code/fragment.glsl (renamed from src/shader/fragment.glsl)0
-rw-r--r--src/shader/code/vertex.glsl (renamed from src/shader/vertex.glsl)0
-rw-r--r--src/shader/util.h46
-rw-r--r--src/shader/wrap/compute_shader.h (renamed from src/compute_shader.h)0
-rw-r--r--src/shader/wrap/graphic_shader.h (renamed from src/graphic_shader.h)2
-rw-r--r--src/util.h40
15 files changed, 93 insertions, 70 deletions
diff --git a/src/texture_buffer.h b/src/buffer/frame/texture_framebuffer.h
index 08c617b..31153ff 100644
--- a/src/texture_buffer.h
+++ b/src/buffer/frame/texture_framebuffer.h
@@ -1,10 +1,12 @@
#pragma once
-class TextureBuffer {
+class TextureFramebuffer {
private:
GLuint _id;
GLuint _texture;
+ bool _good = false;
+
public:
struct Guard {
const GLuint _id;
@@ -21,7 +23,7 @@ public:
return Guard(_id);
}
- TextureBuffer(std::size_t width, std::size_t height) {
+ TextureFramebuffer(std::size_t width, std::size_t height) {
glGenFramebuffers(1, &_id);
auto guard = use();
@@ -33,15 +35,19 @@ public:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);
- if ( glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE ) {
- std::cerr << "Texture framebuffer error" << std::endl;
+ if ( glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE ) {
+ _good = true;
}
}
- ~TextureBuffer() {
+ ~TextureFramebuffer() {
glDeleteFramebuffers(1, &_id);
}
+ bool isGood() const {
+ return _good;
+ }
+
void resize(std::size_t width, std::size_t height) const {
auto guard = use();
diff --git a/src/particle_vertex_buffer.h b/src/buffer/vertex/particle_vertex_buffer.h
index 25855a2..25855a2 100644
--- a/src/particle_vertex_buffer.h
+++ b/src/buffer/vertex/particle_vertex_buffer.h
diff --git a/src/texture_display_buffer.h b/src/buffer/vertex/texture_display_vertex_buffer.h
index b38f9c0..6d4eec2 100644
--- a/src/texture_display_buffer.h
+++ b/src/buffer/vertex/texture_display_vertex_buffer.h
@@ -2,7 +2,7 @@
#include <vector>
-class TextureDisplayBuffer {
+class TextureDisplayVertexBuffer {
private:
const std::vector<GLfloat> _data;
@@ -10,7 +10,7 @@ private:
GLuint _buffer;
public:
- TextureDisplayBuffer():
+ TextureDisplayVertexBuffer():
_data{
-1.f, 1.f, 0.f, 1.f,
-1.f, -1.f, 0.f, 0.f,
@@ -40,7 +40,7 @@ public:
1, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), (void*)(2*sizeof(GLfloat)));
}
- ~TextureDisplayBuffer() {
+ ~TextureDisplayVertexBuffer() {
glDeleteBuffers(1, &_buffer);
glDeleteVertexArrays(1, &_array);
}
diff --git a/src/glfw_guard.h b/src/glfw/guard.h
index 37d3ffb..37d3ffb 100644
--- a/src/glfw_guard.h
+++ b/src/glfw/guard.h
diff --git a/src/window.h b/src/glfw/window.h
index 794dd5f..794dd5f 100644
--- a/src/window.h
+++ b/src/glfw/window.h
diff --git a/src/main.cc b/src/main.cc
index b2262e6..9f32bc3 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -5,22 +5,25 @@
#include <memory>
#include <algorithm>
-#include "glfw_guard.h"
-#include "window.h"
+#include "glfw/guard.h"
+#include "glfw/window.h"
-#include "particle_vertex_buffer.h"
-#include "texture_display_buffer.h"
+#include "buffer/frame/texture_framebuffer.h"
-#include "graphic_shader.h"
-#include "compute_shader.h"
-#include "texture_buffer.h"
+#include "buffer/vertex/particle_vertex_buffer.h"
+#include "buffer/vertex/texture_display_vertex_buffer.h"
-#include "shader/vertex.glsl"
-#include "shader/fragment.glsl"
-#include "shader/compute.glsl"
+#include "shader/wrap/graphic_shader.h"
+#include "shader/wrap/compute_shader.h"
-#include "shader/display_vertex.glsl"
-#include "shader/display_fragment.glsl"
+#include "shader/code/vertex.glsl"
+#include "shader/code/fragment.glsl"
+#include "shader/code/compute.glsl"
+
+#include "shader/code/display_vertex.glsl"
+#include "shader/code/display_fragment.glsl"
+
+#include "util.h"
const unsigned int particle_count = 2500;
const unsigned int max_ups = 100;
@@ -95,10 +98,10 @@ int main() {
glm::mat4 MVP = getMVP(world_width, world_height);
- std::vector<std::unique_ptr<TextureBuffer>> texture_buffers;
+ std::vector<std::unique_ptr<TextureFramebuffer>> texture_framebuffers;
std::unique_ptr<ParticleVertexBuffer> particle_buffer;
- std::unique_ptr<TextureDisplayBuffer> display_buffer;
+ std::unique_ptr<TextureDisplayVertexBuffer> display_buffer;
std::unique_ptr<GraphicShader> scene_shader;
std::unique_ptr<ComputeShader> compute_shader;
@@ -106,13 +109,13 @@ int main() {
window.init([&]() {
for ( unsigned int i = 0; i < texture_count; ++i ) {
- texture_buffers.emplace_back(
- new TextureBuffer(window_width, window_height));
+ texture_framebuffers.emplace_back(
+ new TextureFramebuffer(window_width, window_height));
}
particle_buffer = std::make_unique<ParticleVertexBuffer>(
makeInitialParticles(particle_count, world_width, world_height));
- display_buffer = std::make_unique<TextureDisplayBuffer>();
+ display_buffer = std::make_unique<TextureDisplayVertexBuffer>();
scene_shader = std::make_unique<GraphicShader>(
VERTEX_SHADER_CODE, FRAGMENT_SHADER_CODE);
@@ -124,12 +127,20 @@ int main() {
DISPLAY_VERTEX_SHADER_CODE, DISPLAY_FRAGMENT_SHADER_CODE);
});
+ if ( std::any_of(texture_framebuffers.cbegin(), texture_framebuffers.cend(),
+ [](auto& texture_framebuffer) -> bool {
+ return !texture_framebuffer->isGood();
+ }) ) {
+ std::cerr << "Texture framebuffer error" << std::endl;
+ return -1;
+ }
+
auto lastFrame = std::chrono::high_resolution_clock::now();
auto lastRotate = std::chrono::high_resolution_clock::now();
bool justRotated = true;
std::vector<GLuint> textures;
- for ( const auto& texture_buffer : texture_buffers ) {
+ for ( const auto& texture_buffer : texture_framebuffers ) {
textures.emplace_back(texture_buffer->getTexture());
}
@@ -142,7 +153,7 @@ int main() {
MVP = getMVP(world_width, world_height);
- for ( auto& texture_buffer : texture_buffers ) {
+ for ( auto& texture_buffer : texture_framebuffers ) {
texture_buffer->resize(window_width, window_height);
}
}
@@ -158,14 +169,14 @@ int main() {
if ( util::millisecondsSince(lastRotate) >= 1000/10 ) {
std::rotate(textures.begin(), textures.end()-1, textures.end());
- std::rotate(texture_buffers.begin(), texture_buffers.end()-1, texture_buffers.end());
+ std::rotate(texture_framebuffers.begin(), texture_framebuffers.end()-1, texture_framebuffers.end());
justRotated = true;
lastRotate = std::chrono::high_resolution_clock::now();
}
{
- auto texGuard = texture_buffers[0]->use();
+ auto texGuard = texture_framebuffers[0]->use();
auto sdrGuard = scene_shader->use();
scene_shader->setUniform("MVP", MVP);
diff --git a/src/shader/compute.glsl b/src/shader/code/compute.glsl
index eaf5579..eaf5579 100644
--- a/src/shader/compute.glsl
+++ b/src/shader/code/compute.glsl
diff --git a/src/shader/display_fragment.glsl b/src/shader/code/display_fragment.glsl
index b731ebe..b731ebe 100644
--- a/src/shader/display_fragment.glsl
+++ b/src/shader/code/display_fragment.glsl
diff --git a/src/shader/display_vertex.glsl b/src/shader/code/display_vertex.glsl
index 60bbfc7..60bbfc7 100644
--- a/src/shader/display_vertex.glsl
+++ b/src/shader/code/display_vertex.glsl
diff --git a/src/shader/fragment.glsl b/src/shader/code/fragment.glsl
index 37e18bd..37e18bd 100644
--- a/src/shader/fragment.glsl
+++ b/src/shader/code/fragment.glsl
diff --git a/src/shader/vertex.glsl b/src/shader/code/vertex.glsl
index 4c307d8..4c307d8 100644
--- a/src/shader/vertex.glsl
+++ b/src/shader/code/vertex.glsl
diff --git a/src/shader/util.h b/src/shader/util.h
new file mode 100644
index 0000000..7aec674
--- /dev/null
+++ b/src/shader/util.h
@@ -0,0 +1,46 @@
+#pragma once
+
+#include <iostream>
+
+namespace util {
+
+GLint getUniform(GLuint program, const std::string& name) {
+ const GLint uniform = glGetUniformLocation(program, name.c_str());
+ if ( uniform == -1 ) {
+ std::cerr << "Could not bind uniform " << name << std::endl;
+ }
+ return uniform;
+}
+
+GLint compileShader(const std::string& source, GLenum type) {
+ GLint shader = glCreateShader(type);
+
+ if ( !shader ) {
+ std::cerr << "Cannot create a shader of type " << type << std::endl;
+ exit(-1);
+ }
+
+ const char* source_data = source.c_str();
+ const int source_length = source.size();
+
+ glShaderSource(shader, 1, &source_data, &source_length);
+ glCompileShader(shader);
+
+ GLint compiled;
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
+ if ( !compiled ) {
+ std::cerr << "Cannot compile shader" << std::endl;
+ GLint maxLength = 0;
+ glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
+ std::vector<GLchar> errorLog(maxLength);
+ glGetShaderInfoLog(shader, maxLength, &maxLength, &errorLog[0]);
+ for( auto c : errorLog ) {
+ std::cerr << c;
+ }
+ std::cerr << std::endl;
+ }
+
+ return shader;
+}
+
+}
diff --git a/src/compute_shader.h b/src/shader/wrap/compute_shader.h
index 9f5c5cb..9f5c5cb 100644
--- a/src/compute_shader.h
+++ b/src/shader/wrap/compute_shader.h
diff --git a/src/graphic_shader.h b/src/shader/wrap/graphic_shader.h
index c67dc01..03249d5 100644
--- a/src/graphic_shader.h
+++ b/src/shader/wrap/graphic_shader.h
@@ -1,6 +1,6 @@
#pragma once
-#include "util.h"
+#include "shader/util.h"
class GraphicShader {
private:
diff --git a/src/util.h b/src/util.h
index 05e9303..1863563 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,7 +1,6 @@
#pragma once
#include <chrono>
-#include <iostream>
namespace util {
@@ -11,43 +10,4 @@ double millisecondsSince(std::chrono::time_point<std::chrono::high_resolution_cl
).count();
}
-GLint getUniform(GLuint program, const std::string& name) {
- const GLint uniform = glGetUniformLocation(program, name.c_str());
- if ( uniform == -1 ) {
- std::cerr << "Could not bind uniform " << name << std::endl;
- }
- return uniform;
-}
-
-GLint compileShader(const std::string& source, GLenum type) {
- GLint shader = glCreateShader(type);
-
- if ( !shader ) {
- std::cerr << "Cannot create a shader of type " << type << std::endl;
- exit(-1);
- }
-
- const char* source_data = source.c_str();
- const int source_length = source.size();
-
- glShaderSource(shader, 1, &source_data, &source_length);
- glCompileShader(shader);
-
- GLint compiled;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
- if ( !compiled ) {
- std::cerr << "Cannot compile shader" << std::endl;
- GLint maxLength = 0;
- glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
- std::vector<GLchar> errorLog(maxLength);
- glGetShaderInfoLog(shader, maxLength, &maxLength, &errorLog[0]);
- for( auto c : errorLog ) {
- std::cerr << c;
- }
- std::cerr << std::endl;
- }
-
- return shader;
-}
-
}