• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // VertexBuffer.h: Defines the abstract VertexBuffer class and VertexBufferInterface
8 // class with derivations, classes that perform graphics API agnostic vertex buffer operations.
9 
10 #ifndef LIBGLESV2_RENDERER_VERTEXBUFFER_H_
11 #define LIBGLESV2_RENDERER_VERTEXBUFFER_H_
12 
13 #include "common/angleutils.h"
14 
15 namespace gl
16 {
17 class VertexAttribute;
18 }
19 
20 namespace rx
21 {
22 class Renderer;
23 
24 class VertexBuffer
25 {
26   public:
27     VertexBuffer();
28     virtual ~VertexBuffer();
29 
30     virtual bool initialize(unsigned int size, bool dynamicUsage) = 0;
31 
32     virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count,
33                                        GLsizei instances, unsigned int offset) = 0;
34     virtual bool storeRawData(const void* data, unsigned int size, unsigned int offset) = 0;
35 
36     virtual bool getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
37                                   unsigned int *outSpaceRequired) const = 0;
38 
39     virtual bool requiresConversion(const gl::VertexAttribute &attrib) const = 0;
40 
41     virtual unsigned int getBufferSize() const = 0;
42     virtual bool setBufferSize(unsigned int size) = 0;
43     virtual bool discard() = 0;
44 
45     unsigned int getSerial() const;
46 
47   protected:
48     void updateSerial();
49 
50   private:
51     DISALLOW_COPY_AND_ASSIGN(VertexBuffer);
52 
53     unsigned int mSerial;
54     static unsigned int mNextSerial;
55 };
56 
57 class VertexBufferInterface
58 {
59   public:
60     VertexBufferInterface(rx::Renderer *renderer, bool dynamic);
61     virtual ~VertexBufferInterface();
62 
63     bool reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances);
64     bool reserveRawDataSpace(unsigned int size);
65 
66     unsigned int getBufferSize() const;
67 
68     unsigned int getSerial() const;
69 
70     virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances,
71                                       unsigned int *outStreamOffset);
72     virtual bool storeRawData(const void* data, unsigned int size, unsigned int *outStreamOffset);
73 
74     VertexBuffer* getVertexBuffer() const;
75 
76   protected:
77     virtual bool reserveSpace(unsigned int size) = 0;
78 
79     unsigned int getWritePosition() const;
80     void setWritePosition(unsigned int writePosition);
81 
82     bool discard();
83 
84     bool setBufferSize(unsigned int size);
85 
86   private:
87     DISALLOW_COPY_AND_ASSIGN(VertexBufferInterface);
88 
89     rx::Renderer *const mRenderer;
90 
91     VertexBuffer* mVertexBuffer;
92 
93     unsigned int mWritePosition;
94     unsigned int mReservedSpace;
95     bool mDynamic;
96 };
97 
98 class StreamingVertexBufferInterface : public VertexBufferInterface
99 {
100   public:
101     StreamingVertexBufferInterface(rx::Renderer *renderer, std::size_t initialSize);
102     ~StreamingVertexBufferInterface();
103 
104   protected:
105     bool reserveSpace(unsigned int size);
106 };
107 
108 class StaticVertexBufferInterface : public VertexBufferInterface
109 {
110   public:
111     explicit StaticVertexBufferInterface(rx::Renderer *renderer);
112     ~StaticVertexBufferInterface();
113 
114     bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances,
115                                unsigned int *outStreamOffset);
116 
117     bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamOffset);
118 
119   protected:
120     bool reserveSpace(unsigned int size);
121 
122   private:
123     struct VertexElement
124     {
125         GLenum type;
126         GLint size;
127         GLsizei stride;
128         bool normalized;
129         int attributeOffset;
130 
131         unsigned int streamOffset;
132     };
133 
134     std::vector<VertexElement> mCache;
135 };
136 
137 }
138 
139 #endif // LIBGLESV2_RENDERER_VERTEXBUFFER_H_