1 //
2 // Copyright 2014 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 // VertexArray11.h: Defines the rx::VertexArray11 class which implements rx::VertexArrayImpl.
8 
9 #ifndef LIBANGLE_RENDERER_D3D_D3D11_VERTEXARRAY11_H_
10 #define LIBANGLE_RENDERER_D3D_D3D11_VERTEXARRAY11_H_
11 
12 #include "libANGLE/Framebuffer.h"
13 #include "libANGLE/renderer/VertexArrayImpl.h"
14 #include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
15 #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
16 #include "libANGLE/signal_utils.h"
17 
18 namespace rx
19 {
20 class Renderer11;
21 
22 class VertexArray11 : public VertexArrayImpl, public OnBufferDataDirtyReceiver
23 {
24   public:
25     VertexArray11(const gl::VertexArrayState &data);
26     ~VertexArray11() override;
27     void destroy(const gl::Context *context) override;
28 
29     void syncState(const gl::Context *context,
30                    const gl::VertexArray::DirtyBits &dirtyBits) override;
31     // This will flush any pending attrib updates and then check the dynamic attribs mask.
32     bool hasActiveDynamicAttrib(const gl::Context *context);
33     gl::Error updateDirtyAndDynamicAttribs(const gl::Context *context,
34                                            VertexDataManager *vertexDataManager,
35                                            const DrawCallVertexParams &vertexParams);
36     void clearDirtyAndPromoteDynamicAttribs(const gl::Context *context,
37                                             const DrawCallVertexParams &vertexParams);
38 
39     const std::vector<TranslatedAttribute> &getTranslatedAttribs() const;
40 
41     // SignalReceiver implementation
42     void signal(size_t channelID, const gl::Context *context) override;
43 
getCurrentStateSerial()44     Serial getCurrentStateSerial() const { return mCurrentStateSerial; }
45 
46     // In case of a multi-view program change, we have to update all attributes so that the divisor
47     // is adjusted.
48     void markAllAttributeDivisorsForAdjustment(int numViews);
49 
50     bool flushAttribUpdates(const gl::Context *context);
51 
52     // Returns true if the element array buffer needs to be translated.
53     bool updateElementArrayStorage(const gl::Context *context,
54                                    GLenum elementType,
55                                    GLenum destElementType,
56                                    const void *indices);
57 
58     TranslatedIndexData *getCachedIndexInfo();
59     void setCachedIndexInfoValid();
60     bool isCachedIndexInfoValid() const;
61 
62   private:
63     void updateVertexAttribStorage(const gl::Context *context, size_t attribIndex);
64 
65     std::vector<VertexStorageType> mAttributeStorageTypes;
66     std::vector<TranslatedAttribute> mTranslatedAttribs;
67 
68     // The mask of attributes marked as dynamic.
69     gl::AttributesMask mDynamicAttribsMask;
70 
71     // A mask of attributes that need to be re-evaluated.
72     gl::AttributesMask mAttribsToUpdate;
73 
74     // A set of attributes we know are dirty, and need to be re-translated.
75     gl::AttributesMask mAttribsToTranslate;
76 
77     // We need to keep a safe pointer to the Buffer so we can attach the correct dirty callbacks.
78     std::vector<gl::BindingPointer<gl::Buffer>> mCurrentArrayBuffers;
79     gl::BindingPointer<gl::Buffer> mCurrentElementArrayBuffer;
80 
81     std::vector<OnBufferDataDirtyBinding> mOnArrayBufferDataDirty;
82     OnBufferDataDirtyBinding mOnElementArrayBufferDataDirty;
83 
84     Serial mCurrentStateSerial;
85 
86     // The numViews value used to adjust the divisor.
87     int mAppliedNumViewsToDivisor;
88 
89     // If the index buffer needs re-streaming.
90     GLenum mLastElementType;
91     unsigned int mLastDrawElementsOffset;
92     IndexStorageType mCurrentElementArrayStorage;
93     TranslatedIndexData mCachedIndexInfo;
94     bool mCachedIndexInfoValid;
95 };
96 
97 }  // namespace rx
98 
99 #endif // LIBANGLE_RENDERER_D3D_D3D11_VERTEXARRAY11_H_
100