1 //
2 // Copyright 2002 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 // IndexDataManager.h: Defines the IndexDataManager, a class that
8 // runs the Buffer translation process for index buffers.
9
10 #ifndef LIBANGLE_INDEXDATAMANAGER_H_
11 #define LIBANGLE_INDEXDATAMANAGER_H_
12
13 #include <GLES2/gl2.h>
14
15 #include "common/angleutils.h"
16 #include "common/mathutil.h"
17 #include "libANGLE/Error.h"
18 #include "libANGLE/renderer/d3d/RendererD3D.h"
19
20 namespace
21 {
22 enum
23 {
24 INITIAL_INDEX_BUFFER_SIZE = 4096 * sizeof(GLuint)
25 };
26 }
27
28 namespace gl
29 {
30 class Buffer;
31 }
32
33 namespace rx
34 {
35 class IndexBufferInterface;
36 class StaticIndexBufferInterface;
37 class StreamingIndexBufferInterface;
38 class IndexBuffer;
39 class BufferD3D;
40 class RendererD3D;
41
42 struct SourceIndexData
43 {
44 BufferD3D *srcBuffer;
45 const void *srcIndices;
46 unsigned int srcCount;
47 gl::DrawElementsType srcIndexType;
48 bool srcIndicesChanged;
49 };
50
51 struct TranslatedIndexData
52 {
53 unsigned int startIndex;
54 unsigned int startOffset; // In bytes
55
56 IndexBuffer *indexBuffer;
57 BufferD3D *storage;
58 gl::DrawElementsType indexType;
59 unsigned int serial;
60
61 SourceIndexData srcIndexData;
62 };
63
64 class IndexDataManager : angle::NonCopyable
65 {
66 public:
67 explicit IndexDataManager(BufferFactoryD3D *factory);
68 virtual ~IndexDataManager();
69
70 void deinitialize();
71
72 angle::Result prepareIndexData(const gl::Context *context,
73 gl::DrawElementsType srcType,
74 gl::DrawElementsType dstType,
75 GLsizei count,
76 gl::Buffer *glBuffer,
77 const void *indices,
78 TranslatedIndexData *translated);
79
80 private:
81 angle::Result streamIndexData(const gl::Context *context,
82 const void *data,
83 unsigned int count,
84 gl::DrawElementsType srcType,
85 gl::DrawElementsType dstType,
86 bool usePrimitiveRestartFixedIndex,
87 TranslatedIndexData *translated);
88 angle::Result getStreamingIndexBuffer(const gl::Context *context,
89 gl::DrawElementsType destinationIndexType,
90 IndexBufferInterface **outBuffer);
91
92 using StreamingBuffer = std::unique_ptr<StreamingIndexBufferInterface>;
93
94 BufferFactoryD3D *const mFactory;
95 std::unique_ptr<StreamingIndexBufferInterface> mStreamingBufferShort;
96 std::unique_ptr<StreamingIndexBufferInterface> mStreamingBufferInt;
97 };
98
99 angle::Result GetIndexTranslationDestType(const gl::Context *context,
100 GLsizei indexCount,
101 gl::DrawElementsType indexType,
102 const void *indices,
103 bool usePrimitiveRestartWorkaround,
104 gl::DrawElementsType *destTypeOut);
105
IsOffsetAligned(gl::DrawElementsType elementType,unsigned int offset)106 ANGLE_INLINE bool IsOffsetAligned(gl::DrawElementsType elementType, unsigned int offset)
107 {
108 return (offset % gl::GetDrawElementsTypeSize(elementType) == 0);
109 }
110 } // namespace rx
111
112 #endif // LIBANGLE_INDEXDATAMANAGER_H_
113