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 // BufferD3D.h: Defines the rx::BufferD3D class, an implementation of BufferImpl.
8 
9 #ifndef LIBANGLE_RENDERER_D3D_BUFFERD3D_H_
10 #define LIBANGLE_RENDERER_D3D_BUFFERD3D_H_
11 
12 #include "libANGLE/angletypes.h"
13 #include "libANGLE/renderer/BufferImpl.h"
14 
15 #include <stdint.h>
16 #include <vector>
17 
18 namespace gl
19 {
20 struct VertexAttribute;
21 class VertexBinding;
22 }
23 
24 namespace rx
25 {
26 class BufferFactoryD3D;
27 class StaticIndexBufferInterface;
28 class StaticVertexBufferInterface;
29 
30 enum class D3DBufferUsage
31 {
32     STATIC,
33     DYNAMIC,
34 };
35 
36 class BufferD3D : public BufferImpl
37 {
38   public:
39     BufferD3D(const gl::BufferState &state, BufferFactoryD3D *factory);
40     ~BufferD3D() override;
41 
getSerial()42     unsigned int getSerial() const { return mSerial; }
43 
44     virtual size_t getSize() const = 0;
45     virtual bool supportsDirectBinding() const = 0;
46     virtual gl::Error markTransformFeedbackUsage(const gl::Context *context) = 0;
47     virtual gl::Error getData(const gl::Context *context, const uint8_t **outData) = 0;
48 
49     // Warning: you should ensure binding really matches attrib.bindingIndex before using this
50     // function.
51     StaticVertexBufferInterface *getStaticVertexBuffer(const gl::VertexAttribute &attribute,
52                                                        const gl::VertexBinding &binding);
53     StaticIndexBufferInterface *getStaticIndexBuffer();
54 
55     virtual void initializeStaticData(const gl::Context *context);
56     virtual void invalidateStaticData(const gl::Context *context);
57 
58     void promoteStaticUsage(const gl::Context *context, int dataSize);
59 
60     gl::Error getIndexRange(const gl::Context *context,
61                             GLenum type,
62                             size_t offset,
63                             size_t count,
64                             bool primitiveRestartEnabled,
65                             gl::IndexRange *outRange) override;
66 
getFactory()67     BufferFactoryD3D *getFactory() const { return mFactory; }
getUsage()68     D3DBufferUsage getUsage() const { return mUsage; }
69 
70   protected:
71     void updateSerial();
72     void updateD3DBufferUsage(const gl::Context *context, gl::BufferUsage usage);
73     void emptyStaticBufferCache();
74 
75     BufferFactoryD3D *mFactory;
76     unsigned int mSerial;
77     static unsigned int mNextSerial;
78 
79     std::vector<std::unique_ptr<StaticVertexBufferInterface>> mStaticVertexBuffers;
80     StaticIndexBufferInterface *mStaticIndexBuffer;
81     unsigned int mStaticBufferCacheTotalSize;
82     unsigned int mStaticVertexBufferOutOfDate;
83     unsigned int mUnmodifiedDataUse;
84     D3DBufferUsage mUsage;
85 };
86 
87 }
88 
89 #endif // LIBANGLE_RENDERER_D3D_BUFFERD3D_H_
90