1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | // IndexDataManager.h: Defines the IndexDataManager, a class that |
16 | // runs the Buffer translation process for index buffers. |
17 | |
18 | #ifndef LIBGLESV2_INDEXDATAMANAGER_H_ |
19 | #define LIBGLESV2_INDEXDATAMANAGER_H_ |
20 | |
21 | #include "Context.h" |
22 | |
23 | #include <GLES2/gl2.h> |
24 | |
25 | namespace es2 |
26 | { |
27 | |
28 | struct TranslatedIndexData |
29 | { |
30 | TranslatedIndexData(unsigned int primitiveCount) : primitiveCount(primitiveCount) {} |
31 | |
32 | unsigned int minIndex; |
33 | unsigned int maxIndex; |
34 | unsigned int indexOffset; |
35 | unsigned int primitiveCount; |
36 | |
37 | sw::Resource *indexBuffer; |
38 | }; |
39 | |
40 | class StreamingIndexBuffer |
41 | { |
42 | public: |
43 | StreamingIndexBuffer(size_t initialSize); |
44 | virtual ~StreamingIndexBuffer(); |
45 | |
46 | void *map(size_t requiredSpace, size_t *offset); |
47 | void unmap(); |
48 | void reserveSpace(size_t requiredSpace, GLenum type); |
49 | |
50 | sw::Resource *getResource() const; |
51 | |
52 | private: |
53 | sw::Resource *mIndexBuffer; |
54 | size_t mBufferSize; |
55 | size_t mWritePosition; |
56 | }; |
57 | |
58 | class IndexDataManager |
59 | { |
60 | public: |
61 | IndexDataManager(); |
62 | virtual ~IndexDataManager(); |
63 | |
64 | GLenum prepareIndexData(GLenum mode, GLenum type, GLuint start, GLuint end, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated, bool primitiveRestart); |
65 | |
66 | static std::size_t typeSize(GLenum type); |
67 | |
68 | private: |
69 | StreamingIndexBuffer *mStreamingBuffer; |
70 | }; |
71 | |
72 | } |
73 | |
74 | #endif // LIBGLESV2_INDEXDATAMANAGER_H_ |
75 | |