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 private:
60 angle::Result syncDrawState(const gl::Context *context,
61 const gl::AttributesMask &activeAttributesMask,
62 GLint first,
63 GLsizei count,
64 gl::DrawElementsType type,
65 const void *indices,
66 GLsizei instanceCount,
67 bool primitiveRestartEnabled,
68 const void **outIndices) const;
69
70 // Apply index data, only sets outIndexRange if attributesNeedStreaming is true
71 angle::Result syncIndexData(const gl::Context *context,
72 GLsizei count,
73 gl::DrawElementsType type,
74 const void *indices,
75 bool primitiveRestartEnabled,
76 bool attributesNeedStreaming,
77 gl::IndexRange *outIndexRange,
78 const void **outIndices) const;
79
80 // Returns the amount of space needed to stream all attributes that need streaming
81 // and the data size of the largest attribute
82 void computeStreamingAttributeSizes(const gl::AttributesMask &attribsToStream,
83 GLsizei instanceCount,
84 const gl::IndexRange &indexRange,
85 size_t *outStreamingDataSize,
86 size_t *outMaxAttributeDataSize) const;
87
88 // Stream attributes that have client data
89 angle::Result streamAttributes(const gl::Context *context,
90 const gl::AttributesMask &attribsToStream,
91 GLsizei instanceCount,
92 const gl::IndexRange &indexRange) const;
93 void syncDirtyAttrib(const gl::Context *context,
94 size_t attribIndex,
95 const gl::VertexArray::DirtyAttribBits &dirtyAttribBits);
96 void syncDirtyBinding(const gl::Context *context,
97 size_t bindingIndex,
98 const gl::VertexArray::DirtyBindingBits &dirtyBindingBits);
99
100 void updateAttribEnabled(size_t attribIndex);
101 void updateAttribPointer(const gl::Context *context, size_t attribIndex);
102
103 bool supportVertexAttribBinding() const;
104
105 void updateAttribFormat(size_t attribIndex);
106 void updateAttribBinding(size_t attribIndex);
107 void updateBindingBuffer(const gl::Context *context, size_t bindingIndex);
108 void updateBindingDivisor(size_t bindingIndex);
109
110 void updateElementArrayBufferBinding(const gl::Context *context) const;
111
112 void callVertexAttribPointer(GLuint attribIndex,
113 const gl::VertexAttribute &attrib,
114 GLsizei stride,
115 GLintptr offset) const;
116
117 const FunctionsGL *mFunctions;
118 StateManagerGL *mStateManager;
119
120 GLuint mVertexArrayID;
121 int mAppliedNumViews;
122
123 // Remember the program's active attrib location mask so that attributes can be enabled/disabled
124 // based on whether they are active in the program
125 gl::AttributesMask mProgramActiveAttribLocationsMask;
126
127 mutable gl::BindingPointer<gl::Buffer> mAppliedElementArrayBuffer;
128
129 mutable std::vector<gl::VertexAttribute> mAppliedAttributes;
130 mutable std::vector<gl::VertexBinding> mAppliedBindings;
131
132 mutable size_t mStreamingElementArrayBufferSize;
133 mutable GLuint mStreamingElementArrayBuffer;
134
135 mutable size_t mStreamingArrayBufferSize;
136 mutable GLuint mStreamingArrayBuffer;
137 };
138
syncDrawElementsState(const gl::Context * context,const gl::AttributesMask & activeAttributesMask,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instanceCount,bool primitiveRestartEnabled,const void ** outIndices)139 ANGLE_INLINE angle::Result VertexArrayGL::syncDrawElementsState(
140 const gl::Context *context,
141 const gl::AttributesMask &activeAttributesMask,
142 GLsizei count,
143 gl::DrawElementsType type,
144 const void *indices,
145 GLsizei instanceCount,
146 bool primitiveRestartEnabled,
147 const void **outIndices) const
148 {
149 return syncDrawState(context, activeAttributesMask, 0, count, type, indices, instanceCount,
150 primitiveRestartEnabled, outIndices);
151 }
152
153 } // namespace rx
154
155 #endif // LIBANGLE_RENDERER_GL_VERTEXARRAYGL_H_
156