Browse Source

bug fixes, resize for lists

Kajetan Johannes Hammerle 3 years ago
parent
commit
6c37eecba8
4 changed files with 34 additions and 4 deletions
  1. 1 1
      math/MatrixStack.h
  2. 29 0
      utils/List.h
  3. 2 2
      wrapper/GL.cpp
  4. 2 1
      wrapper/Shader.cpp

+ 1 - 1
math/MatrixStack.h

@@ -36,7 +36,7 @@ public:
 
     void clear() {
         stack.clear();
-        stack.push(Matrix());
+        stack.add(Matrix());
     }
 
     template<int L>

+ 29 - 0
utils/List.h

@@ -66,6 +66,35 @@ public:
         swap(copy);
     }
 
+    void resize(int n, const T& t) {
+        if(length < n) {
+            reserve(n);
+            for(int i = length; i < n; i++) {
+                add(t);
+            }
+        } else if(length > n) {
+            for(int i = n; i < length; i++) {
+                data[i].~T();
+            }
+            length = n;
+        }
+    }
+
+    template<typename... Args>
+    void resize(int n, Args&&... args) {
+        if(length < n) {
+            reserve(n);
+            for(int i = length; i < n; i++) {
+                add(std::forward<Args>(args)...);
+            }
+        } else if(length > n) {
+            for(int i = n; i < length; i++) {
+                data[i].~T();
+            }
+            length = n;
+        }
+    }
+
     List& add(const T& t) {
         ensureCapacity();
         new(data + length++) T(t);

+ 2 - 2
wrapper/GL.cpp

@@ -37,7 +37,7 @@ GL::Attribute GL::Attribute::newFloat(int count) {
 }
 
 GL::Attribute GL::Attribute::newColor(int count) {
-    return GL::Attribute(count, sizeof(float), GL_FLOAT, false);
+    return GL::Attribute(count, sizeof(unsigned char), GL_UNSIGNED_BYTE, true);
 }
 
 GL::Attribute GL::Attribute::newDummy() {
@@ -321,7 +321,7 @@ void GL::drawBuffers(int length, ColorAttachment* c) {
 
 bool GL::printFramebufferError() {
     GLenum error = glCheckFramebufferStatus(GL_FRAMEBUFFER);
-    if(error == GL_FRAMEBUFFER_COMPLETE) {
+    if(error != GL_FRAMEBUFFER_COMPLETE) {
         std::cout << "framebuffer error: " << error << '\n';
         return true;
     }

+ 2 - 1
wrapper/Shader.cpp

@@ -62,10 +62,11 @@ bool Shader::readFile(List<char>& code, const char* path) const {
     while(true) {
         int c = in.get();
         if(c == EOF) {
-            return false;
+            break;
         }
         code.add(c);
     }
+    code.add('\0');
     return false;
 }