]> git.tdb.fi Git - libs/gl.git/blob - source/vertexarray.h
Get rid of the typedefs for fundamental types
[libs/gl.git] / source / vertexarray.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GL_VERTEXARRAY_H_
9 #define MSP_GL_VERTEXARRAY_H_
10
11 #include <vector>
12 #include <msp/core/refptr.h>
13 #include <msp/datafile/loader.h>
14 #include "datatype.h"
15 #include "primitivetype.h"
16 #include "vertexarraybuilder.h"
17 #include "vertexformat.h"
18
19 namespace Msp {
20 namespace GL {
21
22 class Buffer;
23
24 class VertexArray
25 {
26 public:
27         class Loader: public DataFile::Loader, public VertexArrayBuilder
28         {
29         public:
30                 Loader(VertexArray &);
31         };
32
33 private:
34         VertexFormat format;
35         std::vector<float> data;
36         unsigned stride;
37         Buffer *vbuf;
38         bool own_vbuf;
39
40         VertexArray(const VertexArray &);
41         VertexArray &operator=(const VertexArray &);
42 public:
43         VertexArray(const VertexFormat &);
44         ~VertexArray();
45
46         const VertexFormat &get_format() const { return format; }
47         const std::vector<float> &get_data() const { return data; }
48         void         use_vertex_buffer();
49         void         use_vertex_buffer(Buffer *);
50         void         reserve(unsigned);
51         unsigned     size() const { return data.size()/stride; }
52         void         clear();
53         void         reset(const VertexFormat &);
54         void         apply() const;
55         void         update_data();
56         float        *append();
57         float        *operator[](unsigned i) { return &data[0]+i*stride; }
58         const float  *operator[](unsigned i) const { return &data[0]+i*stride; }
59 private:
60         void set_array(unsigned, bool, unsigned) const;
61
62         static unsigned enabled_arrays;
63 };
64
65 void array_element(int);
66 void draw_arrays(PrimitiveType, int, unsigned);
67 void draw_elements(PrimitiveType, unsigned, DataType, const void *);
68 void draw_range_elements(PrimitiveType, unsigned, unsigned, unsigned, DataType, const void *);
69
70 inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned *indices)
71 { draw_elements(mode, count, UNSIGNED_INT, indices); }
72
73 inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned short *indices)
74 { draw_elements(mode, count, UNSIGNED_SHORT, indices); }
75
76 inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned short *indices)
77 { draw_range_elements(mode, low, high, count, UNSIGNED_SHORT, indices); }
78
79 inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned *indices)
80 { draw_range_elements(mode, low, high, count, UNSIGNED_INT, indices); }
81
82 } // namespace GL
83 } // namespace Msp
84
85 #endif