1 //
2 // Copyright (c) 2002-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 // 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     GLenum 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     GLenum 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     gl::Error prepareIndexData(const gl::Context *context,
73                                GLenum srcType,
74                                GLenum dstType,
75                                GLsizei count,
76                                gl::Buffer *glBuffer,
77                                const void *indices,
78                                TranslatedIndexData *translated);
79 
80   private:
81     gl::Error streamIndexData(const void *data,
82                               unsigned int count,
83                               GLenum srcType,
84                               GLenum dstType,
85                               bool usePrimitiveRestartFixedIndex,
86                               TranslatedIndexData *translated);
87     gl::Error getStreamingIndexBuffer(GLenum destinationIndexType,
88                                       IndexBufferInterface **outBuffer);
89 
90     using StreamingBuffer = std::unique_ptr<StreamingIndexBufferInterface>;
91 
92     BufferFactoryD3D *const mFactory;
93     std::unique_ptr<StreamingIndexBufferInterface> mStreamingBufferShort;
94     std::unique_ptr<StreamingIndexBufferInterface> mStreamingBufferInt;
95 };
96 
97 GLenum GetIndexTranslationDestType(GLenum srcType,
98                                    const gl::HasIndexRange &lazyIndexRange,
99                                    bool usePrimitiveRestartWorkaround);
100 
101 bool IsOffsetAligned(GLenum elementType, unsigned int offset);
102 
103 }  // namespace rx
104 
105 #endif  // LIBANGLE_INDEXDATAMANAGER_H_
106