• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 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 // VertexArrayGL.h: Defines the class interface for VertexArrayGL.
8 
9 #ifndef LIBANGLE_RENDERER_GL_VERTEXARRAYGL_H_
10 #define LIBANGLE_RENDERER_GL_VERTEXARRAYGL_H_
11 
12 #include "libANGLE/renderer/VertexArrayImpl.h"
13 
14 #include "common/mathutil.h"
15 #include "libANGLE/Context.h"
16 #include "libANGLE/renderer/gl/ContextGL.h"
17 
18 namespace rx
19 {
20 
21 class FunctionsGL;
22 class StateManagerGL;
23 
24 class VertexArrayGL : public VertexArrayImpl
25 {
26   public:
27     VertexArrayGL(const gl::VertexArrayState &data,
28                   const FunctionsGL *functions,
29                   StateManagerGL *stateManager);
30     ~VertexArrayGL() override;
31 
32     void destroy(const gl::Context *context) override;
33 
34     angle::Result syncClientSideData(const gl::Context *context,
35                                      const gl::AttributesMask &activeAttributesMask,
36                                      GLint first,
37                                      GLsizei count,
38                                      GLsizei instanceCount) const;
39     angle::Result syncDrawElementsState(const gl::Context *context,
40                                         const gl::AttributesMask &activeAttributesMask,
41                                         GLsizei count,
42                                         gl::DrawElementsType type,
43                                         const void *indices,
44                                         GLsizei instanceCount,
45                                         bool primitiveRestartEnabled,
46                                         const void **outIndices) const;
47 
48     GLuint getVertexArrayID() const;
49     GLuint getAppliedElementArrayBufferID() const;
50 
51     angle::Result syncState(const gl::Context *context,
52                             const gl::VertexArray::DirtyBits &dirtyBits,
53                             gl::VertexArray::DirtyAttribBitsArray *attribBits,
54                             gl::VertexArray::DirtyBindingBitsArray *bindingBits) override;
55 
56     void applyNumViewsToDivisor(int numViews);
57     void applyActiveAttribLocationsMask(const gl::AttributesMask &activeMask);
58 
59     void validateState() const;
60 
61   private:
62     angle::Result syncDrawState(const gl::Context *context,
63                                 const gl::AttributesMask &activeAttributesMask,
64                                 GLint first,
65                                 GLsizei count,
66                                 gl::DrawElementsType type,
67                                 const void *indices,
68                                 GLsizei instanceCount,
69                                 bool primitiveRestartEnabled,
70                                 const void **outIndices) const;
71 
72     // Apply index data, only sets outIndexRange if attributesNeedStreaming is true
73     angle::Result syncIndexData(const gl::Context *context,
74                                 GLsizei count,
75                                 gl::DrawElementsType type,
76                                 const void *indices,
77                                 bool primitiveRestartEnabled,
78                                 bool attributesNeedStreaming,
79                                 gl::IndexRange *outIndexRange,
80                                 const void **outIndices) const;
81 
82     // Returns the amount of space needed to stream all attributes that need streaming
83     // and the data size of the largest attribute
84     void computeStreamingAttributeSizes(const gl::AttributesMask &attribsToStream,
85                                         GLsizei instanceCount,
86                                         const gl::IndexRange &indexRange,
87                                         size_t *outStreamingDataSize,
88                                         size_t *outMaxAttributeDataSize) const;
89 
90     // Stream attributes that have client data
91     angle::Result streamAttributes(const gl::Context *context,
92                                    const gl::AttributesMask &attribsToStream,
93                                    GLsizei instanceCount,
94                                    const gl::IndexRange &indexRange) const;
95     void syncDirtyAttrib(const gl::Context *context,
96                          size_t attribIndex,
97                          const gl::VertexArray::DirtyAttribBits &dirtyAttribBits);
98     void syncDirtyBinding(const gl::Context *context,
99                           size_t bindingIndex,
100                           const gl::VertexArray::DirtyBindingBits &dirtyBindingBits);
101 
102     void updateAttribEnabled(size_t attribIndex);
103     void updateAttribPointer(const gl::Context *context, size_t attribIndex);
104 
105     bool supportVertexAttribBinding() const;
106 
107     void updateAttribFormat(size_t attribIndex);
108     void updateAttribBinding(size_t attribIndex);
109     void updateBindingBuffer(const gl::Context *context, size_t bindingIndex);
110     void updateBindingDivisor(size_t bindingIndex);
111 
112     void updateElementArrayBufferBinding(const gl::Context *context) const;
113 
114     void callVertexAttribPointer(GLuint attribIndex,
115                                  const gl::VertexAttribute &attrib,
116                                  GLsizei stride,
117                                  GLintptr offset) const;
118 
119     const FunctionsGL *mFunctions;
120     StateManagerGL *mStateManager;
121 
122     GLuint mVertexArrayID;
123     int mAppliedNumViews;
124 
125     // Remember the program's active attrib location mask so that attributes can be enabled/disabled
126     // based on whether they are active in the program
127     gl::AttributesMask mProgramActiveAttribLocationsMask;
128 
129     mutable gl::BindingPointer<gl::Buffer> mAppliedElementArrayBuffer;
130 
131     mutable std::vector<gl::VertexAttribute> mAppliedAttributes;
132     mutable std::vector<gl::VertexBinding> mAppliedBindings;
133 
134     mutable size_t mStreamingElementArrayBufferSize;
135     mutable GLuint mStreamingElementArrayBuffer;
136 
137     mutable size_t mStreamingArrayBufferSize;
138     mutable GLuint mStreamingArrayBuffer;
139 };
140 
syncDrawElementsState(const gl::Context * context,const gl::AttributesMask & activeAttributesMask,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instanceCount,bool primitiveRestartEnabled,const void ** outIndices)141 ANGLE_INLINE angle::Result VertexArrayGL::syncDrawElementsState(
142     const gl::Context *context,
143     const gl::AttributesMask &activeAttributesMask,
144     GLsizei count,
145     gl::DrawElementsType type,
146     const void *indices,
147     GLsizei instanceCount,
148     bool primitiveRestartEnabled,
149     const void **outIndices) const
150 {
151     return syncDrawState(context, activeAttributesMask, 0, count, type, indices, instanceCount,
152                          primitiveRestartEnabled, outIndices);
153 }
154 
155 }  // namespace rx
156 
157 #endif  // LIBANGLE_RENDERER_GL_VERTEXARRAYGL_H_
158