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 struct VertexArrayStateGL;
24
25 class VertexArrayGL : public VertexArrayImpl
26 {
27 public:
28 VertexArrayGL(const gl::VertexArrayState &data, GLuint id);
29 VertexArrayGL(const gl::VertexArrayState &data, GLuint id, VertexArrayStateGL *sharedState);
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 VertexArrayStateGL *getNativeState() 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(const gl::Context *context, int numViews);
57 void applyActiveAttribLocationsMask(const gl::Context *context,
58 const gl::AttributesMask &activeMask);
59
60 void validateState(const gl::Context *context) const;
61
62 void recoverForcedStreamingAttributesForDrawArraysInstanced(const gl::Context *context) const;
63
64 private:
65 angle::Result syncDrawState(const gl::Context *context,
66 const gl::AttributesMask &activeAttributesMask,
67 GLint first,
68 GLsizei count,
69 gl::DrawElementsType type,
70 const void *indices,
71 GLsizei instanceCount,
72 bool primitiveRestartEnabled,
73 const void **outIndices) const;
74
75 // Apply index data, only sets outIndexRange if attributesNeedStreaming is true
76 angle::Result syncIndexData(const gl::Context *context,
77 GLsizei count,
78 gl::DrawElementsType type,
79 const void *indices,
80 bool primitiveRestartEnabled,
81 bool attributesNeedStreaming,
82 gl::IndexRange *outIndexRange,
83 const void **outIndices) const;
84
85 // Returns the amount of space needed to stream all attributes that need streaming
86 // and the data size of the largest attribute
87 void computeStreamingAttributeSizes(const gl::AttributesMask &attribsToStream,
88 GLsizei instanceCount,
89 const gl::IndexRange &indexRange,
90 size_t *outStreamingDataSize,
91 size_t *outMaxAttributeDataSize) const;
92
93 // Stream attributes that have client data
94 angle::Result streamAttributes(const gl::Context *context,
95 const gl::AttributesMask &attribsToStream,
96 GLsizei instanceCount,
97 const gl::IndexRange &indexRange,
98 bool applyExtraOffsetWorkaroundForInstancedAttributes) const;
99 void syncDirtyAttrib(const gl::Context *context,
100 size_t attribIndex,
101 const gl::VertexArray::DirtyAttribBits &dirtyAttribBits);
102 void syncDirtyBinding(const gl::Context *context,
103 size_t bindingIndex,
104 const gl::VertexArray::DirtyBindingBits &dirtyBindingBits);
105
106 void updateAttribEnabled(const gl::Context *context, size_t attribIndex);
107 void updateAttribPointer(const gl::Context *context, size_t attribIndex);
108
109 bool supportVertexAttribBinding(const gl::Context *context) const;
110
111 void updateAttribFormat(const gl::Context *context, size_t attribIndex);
112 void updateAttribBinding(const gl::Context *context, size_t attribIndex);
113 void updateBindingBuffer(const gl::Context *context, size_t bindingIndex);
114 void updateBindingDivisor(const gl::Context *context, size_t bindingIndex);
115
116 void updateElementArrayBufferBinding(const gl::Context *context) const;
117
118 void callVertexAttribPointer(const gl::Context *context,
119 GLuint attribIndex,
120 const gl::VertexAttribute &attrib,
121 GLsizei stride,
122 GLintptr offset) const;
123
124 void recoverForcedStreamingAttributesForDrawArraysInstanced(
125 const gl::Context *context,
126 gl::AttributesMask *attributeMask) const;
127
128 GLuint mVertexArrayID = 0;
129 int mAppliedNumViews = 1;
130
131 // Remember the program's active attrib location mask so that attributes can be enabled/disabled
132 // based on whether they are active in the program
133 gl::AttributesMask mProgramActiveAttribLocationsMask;
134
135 bool mOwnsNativeState = false;
136 VertexArrayStateGL *mNativeState = nullptr;
137
138 mutable gl::BindingPointer<gl::Buffer> mElementArrayBuffer;
139 mutable std::array<gl::BindingPointer<gl::Buffer>, gl::MAX_VERTEX_ATTRIBS> mArrayBuffers;
140
141 mutable size_t mStreamingElementArrayBufferSize = 0;
142 mutable GLuint mStreamingElementArrayBuffer = 0;
143
144 mutable size_t mStreamingArrayBufferSize = 0;
145 mutable GLuint mStreamingArrayBuffer = 0;
146
147 // Used for Mac Intel instanced draw workaround
148 mutable gl::AttributesMask mForcedStreamingAttributesForDrawArraysInstancedMask;
149 mutable gl::AttributesMask mInstancedAttributesMask;
150 mutable std::array<GLint, gl::MAX_VERTEX_ATTRIBS> mForcedStreamingAttributesFirstOffsets;
151 };
152
syncDrawElementsState(const gl::Context * context,const gl::AttributesMask & activeAttributesMask,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instanceCount,bool primitiveRestartEnabled,const void ** outIndices)153 ANGLE_INLINE angle::Result VertexArrayGL::syncDrawElementsState(
154 const gl::Context *context,
155 const gl::AttributesMask &activeAttributesMask,
156 GLsizei count,
157 gl::DrawElementsType type,
158 const void *indices,
159 GLsizei instanceCount,
160 bool primitiveRestartEnabled,
161 const void **outIndices) const
162 {
163 return syncDrawState(context, activeAttributesMask, 0, count, type, indices, instanceCount,
164 primitiveRestartEnabled, outIndices);
165 }
166
167 } // namespace rx
168
169 #endif // LIBANGLE_RENDERER_GL_VERTEXARRAYGL_H_
170