Kajetan Johannes Hammerle 3 years ago
parent
commit
1875c39786

+ 1 - 3
Main.cpp

@@ -1,6 +1,7 @@
 #include <iostream>
 
 #include "rendering/FileTexture.h"
+#include "rendering/Framebuffer.h"
 #include "tests/ArrayListTests.h"
 #include "tests/ArrayTests.h"
 #include "tests/BitArrayTests.h"
@@ -18,14 +19,12 @@
 #include "tests/RandomTests.h"
 #include "tests/RingBufferTests.h"
 #include "tests/SplitStringTests.h"
-#include "tests/StackAllocatorTests.h"
 #include "tests/StackTests.h"
 #include "tests/StringBufferTests.h"
 #include "tests/TypedBufferTests.h"
 #include "tests/UniquePointerTests.h"
 #include "tests/UtilsTests.h"
 #include "tests/VectorTests.h"
-#include "wrapper/Framebuffer.h"
 
 int main(int argAmount, char** args) {
     if(argAmount < 2) {
@@ -53,7 +52,6 @@ int main(int argAmount, char** args) {
     ClockTests::test();
     PNGReaderTests::test(args[1]);
     BufferTests::test();
-    StackAllocatorTests::test();
     TypedBufferTests::test();
     UniquePointerTests::test();
     return 0;

+ 14 - 8
images/PNGReader.cpp

@@ -5,16 +5,19 @@
 #include "images/PNGReader.h"
 
 PNGReader::PNGReader(const char* path)
-    : path(path), width(0), height(0), channels(0), bitDepth(0), rowBytes(0), file(fopen(path, "r")), read(nullptr),
-      info(nullptr), rowPointers(nullptr) {
+    : path(path), width(0), height(0), channels(0), bitDepth(0), rowBytes(0),
+      file(fopen(path, "r")), read(nullptr), info(nullptr),
+      rowPointers(nullptr) {
     if(file == nullptr) {
-        std::cout << "file '" << path << "' cannot be read: " << strerror(errno) << "\n";
+        std::cout << "file '" << path << "' cannot be read: " << strerror(errno)
+                  << "\n";
         return;
     }
     if(checkSignature()) {
         return;
     }
-    read = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
+    read = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr,
+                                  nullptr);
     if(read == nullptr) {
         std::cout << "cannot create png read data structure\n";
         return;
@@ -67,12 +70,14 @@ int PNGReader::getChannels() const {
 }
 
 int PNGReader::getBufferSize() const {
-    return width * height;
+    return width * height * channels;
 }
 
 bool PNGReader::hasError() const {
     if(channels < 1 || channels > 4) {
-        std::cout << "'" << path << "' has unsupported number of channels: " << channels << "\n";
+        std::cout << "'" << path
+                  << "' has unsupported number of channels: " << channels
+                  << "\n";
         return true;
     } else if(width < 1 || width > 2048 || height < 1 || height > 2048) {
         std::cout << "width and height of '" << path << "' are too big\n";
@@ -80,7 +85,7 @@ bool PNGReader::hasError() const {
     } else if(bitDepth != 8 && bitDepth != 16) {
         std::cout << "bit depth of '" << path << "' is neither 8 or 16\n";
         return true;
-    } else if(getBufferSize() * channels != (rowBytes * height * 8 / bitDepth)) {
+    } else if(getBufferSize() != (rowBytes * height * 8 / bitDepth)) {
         std::cout << "'" << path << "' needs an unexpected buffer size\n";
         return true;
     }
@@ -105,7 +110,8 @@ bool PNGReader::readData(ColorChannel* buffer) {
         std::cout << "png file '" << path << "' has used error callback\n";
         return true;
     }
-    rowPointers = static_cast<ColorChannel**>(png_malloc(read, height * sizeof(ColorChannel*)));
+    rowPointers = static_cast<ColorChannel**>(
+        png_malloc(read, height * sizeof(ColorChannel*)));
     for(int i = 0; i < height; i++) {
         rowPointers[i] = (buffer + i * width * channels);
     }

+ 1 - 1
input/Buttons.h

@@ -4,7 +4,7 @@
 #include "input/Button.h"
 #include "utils/Array.h"
 #include "utils/ArrayList.h"
-#include "wrapper/Window.h"
+#include "rendering/Window.h"
 
 typedef ArrayList<Button, 32> ButtonList;
 

+ 6 - 3
memory/StackAllocator.h

@@ -5,7 +5,6 @@
 #include <type_traits>
 
 namespace StackAllocator {
-
     struct Pointer {
         int lastPointer;
         int pointer;
@@ -22,7 +21,9 @@ namespace StackAllocator {
         Pointer dataPointer;
 
     public:
-        Array(int n) : length(n), dataPointer(StackAllocator::allocate(sizeof(T), length)) {
+        Array(int n)
+            : length(n),
+              dataPointer(StackAllocator::allocate(sizeof(T), length)) {
             for(int i = 0; i < length; i++) {
                 new((*this) + i) T;
             }
@@ -72,7 +73,9 @@ namespace StackAllocator {
         Pointer dataPointer;
 
     public:
-        Object() : length(1), dataPointer(StackAllocator::allocate(sizeof(T), length)) {
+        Object()
+            : length(1),
+              dataPointer(StackAllocator::allocate(sizeof(T), length)) {
             if(!hasError()) {
                 new(StackAllocator::get(dataPointer)) T;
             }

+ 8 - 10
meson.build

@@ -34,21 +34,19 @@ sources = ['Main.cpp',
     'tests/PNGReaderTests.cpp',
     'tests/BufferTests.cpp',
     'tests/TypedBufferTests.cpp',
-    'wrapper/Texture.cpp',
     'wrapper/GL.cpp',
     'wrapper/GLFW.cpp',
     'wrapper/GLEW.cpp', 
-    'wrapper/Shader.cpp', 
-    'wrapper/VertexBuffer.cpp',
-    'wrapper/Attributes.cpp',
-    'wrapper/Window.cpp',
-    'wrapper/WindowOptions.cpp',
+    'rendering/Texture.cpp',
+    'rendering/Shader.cpp', 
+    'rendering/VertexBuffer.cpp',
+    'rendering/Attributes.cpp',
+    'rendering/Window.cpp',
+    'rendering/WindowOptions.cpp',
+    'rendering/TextureFormat.cpp',
+    'rendering/FileTexture.cpp',
     'input/Button.cpp',
     'input/Buttons.cpp',
-    'wrapper/TextureFormat.cpp',
-    'rendering/FileTexture.cpp',
-    'memory/StackAllocator.cpp',
-    'tests/StackAllocatorTests.cpp',
     'tests/UniquePointerTests.cpp',
     'utils/Buffer.cpp']
 

+ 1 - 1
wrapper/Attributes.cpp → rendering/Attributes.cpp

@@ -1,4 +1,4 @@
-#include "wrapper/Attributes.h"
+#include "rendering/Attributes.h"
 
 Attributes& Attributes::addFloat(int count) {
     attributes.add(GL::Attribute::newFloat(count));

+ 0 - 0
wrapper/Attributes.h → rendering/Attributes.h


+ 4 - 2
rendering/FileTexture.cpp

@@ -1,12 +1,14 @@
 #include "rendering/FileTexture.h"
 #include "images/PNGReader.h"
-#include "memory/StackAllocator.h"
+#include "utils/List.h"
 
-FileTexture::FileTexture(const char* path, int maxMipMaps) : texture(maxMipMaps) {
+FileTexture::FileTexture(const char* path, int maxMipMaps)
+    : texture(maxMipMaps) {
     PNGReader png(path);
     if(png.hasError()) {
         return;
     }
+    List<ColorChannel> buffer;
     StackAllocator::Array<ColorChannel> buffer(png.getBufferSize());
     if(buffer.getLength() == png.getBufferSize() && !png.readData(buffer)) {
         texture.setFormat(TextureFormat::color8(png.getChannels()));

+ 1 - 1
rendering/FileTexture.h

@@ -1,7 +1,7 @@
 #ifndef FILETEXTURE_H
 #define FILETEXTURE_H
 
-#include "wrapper/Texture.h"
+#include "rendering/Texture.h"
 
 class FileTexture final {
     Texture texture;

+ 1 - 1
wrapper/Framebuffer.h → rendering/Framebuffer.h

@@ -3,9 +3,9 @@
 
 #include <iostream>
 
+#include "rendering/Texture.h"
 #include "utils/ArrayList.h"
 #include "utils/Size.h"
-#include "wrapper/Texture.h"
 
 template<int N>
 class Framebuffer final {

+ 1 - 1
wrapper/Shader.cpp → rendering/Shader.cpp

@@ -1,8 +1,8 @@
 #include <fstream>
 #include <iostream>
 
+#include "rendering/Shader.h"
 #include "wrapper/GL.h"
-#include "wrapper/Shader.h"
 
 Shader::Shader(const char* vertexPath, const char* fragmentPath,
                const char* geometryPath)

+ 0 - 0
wrapper/Shader.h → rendering/Shader.h


+ 1 - 1
wrapper/Texture.cpp → rendering/Texture.cpp

@@ -1,4 +1,4 @@
-#include "wrapper/Texture.h"
+#include "rendering/Texture.h"
 
 Texture::Texture(const TextureFormat& format, int maxMipMaps)
     : format(format), texture(GL::genTexture()), maxMipMaps(maxMipMaps) {

+ 1 - 1
wrapper/Texture.h → rendering/Texture.h

@@ -1,8 +1,8 @@
 #ifndef TEXTURE_H
 #define TEXTURE_H
 
+#include "rendering/TextureFormat.h"
 #include "wrapper/GL.h"
-#include "wrapper/TextureFormat.h"
 
 class Texture final {
     TextureFormat format;

+ 1 - 1
wrapper/TextureFormat.cpp → rendering/TextureFormat.cpp

@@ -1,4 +1,4 @@
-#include "wrapper/TextureFormat.h"
+#include "rendering/TextureFormat.h"
 
 TextureFormat::TextureFormat(const GL::TextureFormat& tf, bool linear,
                              bool depth)

+ 0 - 0
wrapper/TextureFormat.h → rendering/TextureFormat.h


+ 1 - 1
wrapper/VertexBuffer.cpp → rendering/VertexBuffer.cpp

@@ -1,4 +1,4 @@
-#include "wrapper/VertexBuffer.h"
+#include "rendering/VertexBuffer.h"
 
 VertexBuffer::VertexBuffer()
     : vertexArray(GL::genVertexArray()), vertexBuffer(GL::genBuffer()) {

+ 1 - 1
wrapper/VertexBuffer.h → rendering/VertexBuffer.h

@@ -1,7 +1,7 @@
 #ifndef VERTEXBUFFER_H
 #define VERTEXBUFFER_H
 
-#include "wrapper/Attributes.h"
+#include "rendering/Attributes.h"
 #include "wrapper/GL.h"
 
 class VertexBuffer final {

+ 7 - 4
wrapper/Window.cpp → rendering/Window.cpp

@@ -1,6 +1,6 @@
 #include <iostream>
 
-#include "wrapper/Window.h"
+#include "rendering/Window.h"
 
 Window::Window(const WindowOptions& options) : window(nullptr) {
     glfwDefaultWindowHints();
@@ -17,8 +17,10 @@ Window::Window(const WindowOptions& options) : window(nullptr) {
     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, options.majorVersion);
     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, options.minorVersion);
 
-    GLFWmonitor* monitor = options.fullscreen ? glfwGetPrimaryMonitor() : nullptr;
-    window = glfwCreateWindow(options.size.width, options.size.height, options.name, monitor, nullptr);
+    GLFWmonitor* monitor =
+        options.fullscreen ? glfwGetPrimaryMonitor() : nullptr;
+    window = glfwCreateWindow(options.size.width, options.size.height,
+                              options.name, monitor, nullptr);
     if(window == nullptr) {
         std::cout << "could not create window\n";
         return;
@@ -50,7 +52,8 @@ void Window::swapBuffers() {
 }
 
 void Window::trapCursor(bool trap) {
-    glfwSetInputMode(window, GLFW_CURSOR, trap ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
+    glfwSetInputMode(window, GLFW_CURSOR,
+                     trap ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
 }
 
 Size Window::getSize() const {

+ 1 - 1
wrapper/Window.h → rendering/Window.h

@@ -4,7 +4,7 @@
 #include <GL/glew.h>
 #include <GLFW/glfw3.h>
 
-#include "wrapper/WindowOptions.h"
+#include "rendering/WindowOptions.h"
 
 class Window final {
     GLFWwindow* window;

+ 7 - 0
rendering/WindowOptions.cpp

@@ -0,0 +1,7 @@
+#include "rendering/WindowOptions.h"
+
+WindowOptions::WindowOptions(int majorVersion, int minorVersion,
+                             const Size& size, bool es, const char* name)
+    : majorVersion(majorVersion), minorVersion(minorVersion), size(size),
+      fullscreen(false), es(es), vsync(true), name(name) {
+}

+ 0 - 0
wrapper/WindowOptions.h → rendering/WindowOptions.h


+ 0 - 6
wrapper/WindowOptions.cpp

@@ -1,6 +0,0 @@
-#include "WindowOptions.h"
-
-WindowOptions::WindowOptions(int majorVersion, int minorVersion, const Size& size, bool es, const char* name)
-    : majorVersion(majorVersion), minorVersion(minorVersion), size(size), fullscreen(false), es(es), vsync(true),
-      name(name) {
-}