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