Browse Source

merged attributes into vertex buffer as they are always together

Kajetan Johannes Hammerle 2 years ago
parent
commit
fab5942fed
5 changed files with 46 additions and 55 deletions
  1. 0 1
      meson.build
  2. 0 32
      rendering/Attributes.cpp
  3. 0 21
      rendering/Attributes.h
  4. 31 0
      rendering/VertexBuffer.cpp
  5. 15 1
      rendering/VertexBuffer.h

+ 0 - 1
meson.build

@@ -12,7 +12,6 @@ src = [
     'network/ENet.cpp',
     'network/Packet.cpp',
     'network/Server.cpp',
-    'rendering/Attributes.cpp',
     'rendering/FileTexture.cpp',
     'rendering/Shader.cpp',
     'rendering/Texture.cpp',

+ 0 - 32
rendering/Attributes.cpp

@@ -1,32 +0,0 @@
-#include "rendering/Attributes.h"
-
-Attributes& Attributes::addFloat(int count) {
-    attributes.add(GL::Attribute::newFloat(count));
-    return *this;
-}
-
-Attributes& Attributes::addColor4() {
-    attributes.add(GL::Attribute::newColor(4));
-    return *this;
-}
-
-Attributes& Attributes::addSpacer() {
-    attributes.add(GL::Attribute::newDummy());
-    return *this;
-}
-
-void Attributes::set() const {
-    int size = 0;
-    for(const GL::Attribute& a : attributes) {
-        size += a.getSize();
-    }
-    int index = 0;
-    int offset = 0;
-    for(const GL::Attribute& a : attributes) {
-        if(!a.isDummy()) {
-            GL::vertexAttribPointer(index, a, size, offset);
-        }
-        offset += a.getSize();
-        index++;
-    }
-}

+ 0 - 21
rendering/Attributes.h

@@ -1,21 +0,0 @@
-#ifndef ATTRIBUTES_H
-#define ATTRIBUTES_H
-
-#include "utils/ArrayList.h"
-#include "wrapper/GL.h"
-
-class Attributes final {
-    ArrayList<GL::Attribute, 10> attributes;
-
-    friend class VertexBuffer;
-
-public:
-    Attributes& addFloat(int count);
-    Attributes& addColor4();
-    Attributes& addSpacer();
-
-private:
-    void set() const;
-};
-
-#endif

+ 31 - 0
rendering/VertexBuffer.cpp

@@ -1,5 +1,36 @@
 #include "rendering/VertexBuffer.h"
 
+VertexBuffer::Attributes& VertexBuffer::Attributes::addFloat(int count) {
+    attributes.add(GL::Attribute::newFloat(count));
+    return *this;
+}
+
+VertexBuffer::Attributes& VertexBuffer::Attributes::addColor4() {
+    attributes.add(GL::Attribute::newColor(4));
+    return *this;
+}
+
+VertexBuffer::Attributes& VertexBuffer::Attributes::addSpacer() {
+    attributes.add(GL::Attribute::newDummy());
+    return *this;
+}
+
+void VertexBuffer::Attributes::set() const {
+    int size = 0;
+    for(const GL::Attribute& a : attributes) {
+        size += a.getSize();
+    }
+    int index = 0;
+    int offset = 0;
+    for(const GL::Attribute& a : attributes) {
+        if(!a.isDummy()) {
+            GL::vertexAttribPointer(index, a, size, offset);
+        }
+        offset += a.getSize();
+        index++;
+    }
+}
+
 VertexBuffer::VertexBuffer() : vertexArray(0), vertexBuffer(0), size(0) {
 }
 

+ 15 - 1
rendering/VertexBuffer.h

@@ -1,7 +1,7 @@
 #ifndef VERTEXBUFFER_H
 #define VERTEXBUFFER_H
 
-#include "rendering/Attributes.h"
+#include "utils/ArrayList.h"
 #include "wrapper/GL.h"
 
 class VertexBuffer final {
@@ -10,6 +10,20 @@ class VertexBuffer final {
     int size;
 
 public:
+    class Attributes final {
+        ArrayList<GL::Attribute, 10> attributes;
+
+        friend class VertexBuffer;
+
+    public:
+        Attributes& addFloat(int count);
+        Attributes& addColor4();
+        Attributes& addSpacer();
+
+    private:
+        void set() const;
+    };
+
     VertexBuffer();
     ~VertexBuffer();
     VertexBuffer(const VertexBuffer& other) = delete;