]> git.tdb.fi Git - libs/gl.git/blobdiff - source/buffer.h
Move buffer resizing out of Bufferable
[libs/gl.git] / source / buffer.h
index a7d4c2ba4314f8cbbc9db9fb6c2422cf0e85da2c..fc9ace78c0ac0f48194a20fdcb1a8e4012be01e1 100644 (file)
@@ -1,14 +1,25 @@
 #ifndef MSP_GL_BUFFER_H_
 #define MSP_GL_BUFFER_H_
 
+#include <stdexcept>
+#include <string>
 #include <vector>
 #include "gl.h"
+#include <msp/gl/extensions/arb_pixel_buffer_object.h>
 #include <msp/gl/extensions/arb_vertex_buffer_object.h>
 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
+#include <msp/gl/extensions/oes_mapbuffer.h>
 
 namespace Msp {
 namespace GL {
 
+class buffer_too_small: public std::logic_error
+{
+public:
+       buffer_too_small(const std::string &w): std::logic_error(w) { }
+       virtual ~buffer_too_small() throw() { }
+};
+
 enum BufferType
 {
        ARRAY_BUFFER         = GL_ARRAY_BUFFER,
@@ -31,6 +42,13 @@ enum BufferUsage
        DYNAMIC_COPY = GL_DYNAMIC_COPY
 };
 
+enum BufferAccess
+{
+       READ_ONLY = GL_READ_ONLY,
+       WRITE_ONLY = GL_WRITE_ONLY,
+       READ_WRITE = GL_READ_WRITE
+};
+
 class BufferRange;
 
 /**
@@ -78,8 +96,13 @@ public:
 
        unsigned get_size() const { return size; }
 
+       void require_size(unsigned) const;
+
        BufferRange *create_range(unsigned, unsigned);
 
+       void *map(BufferAccess);
+       bool unmap();
+
        /** Binds the buffer in its default slot. */
        void bind() const { bind_to(type); }
 
@@ -111,6 +134,7 @@ private:
 
 public:
        BufferRange(Buffer &, unsigned, unsigned);
+       ~BufferRange();
 
        void data(const void *);