2 // Copyright (c) 2002-2010 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.
7 // IndexDataManager.h: Defines the IndexDataManager, a class that
8 // runs the Buffer translation process for index buffers.
10 #ifndef LIBGLESV2_INDEXDATAMANAGER_H_
11 #define LIBGLESV2_INDEXDATAMANAGER_H_
17 #include <GLES2/gl2.h>
19 #include "libGLESv2/Context.h"
24 struct TranslatedIndexData
30 IDirect3DIndexBuffer9 *indexBuffer;
36 IndexBuffer(IDirect3DDevice9 *device, UINT size, D3DFORMAT format);
37 virtual ~IndexBuffer();
39 UINT size() const { return mBufferSize; }
40 virtual void *map(UINT requiredSpace, UINT *offset) = 0;
42 virtual void reserveSpace(UINT requiredSpace, GLenum type) = 0;
44 IDirect3DIndexBuffer9 *getBuffer() const;
47 IDirect3DDevice9 *const mDevice;
49 IDirect3DIndexBuffer9 *mIndexBuffer;
53 DISALLOW_COPY_AND_ASSIGN(IndexBuffer);
56 class StreamingIndexBuffer : public IndexBuffer
59 StreamingIndexBuffer(IDirect3DDevice9 *device, UINT initialSize, D3DFORMAT format);
60 ~StreamingIndexBuffer();
62 virtual void *map(UINT requiredSpace, UINT *offset);
63 virtual void reserveSpace(UINT requiredSpace, GLenum type);
69 class StaticIndexBuffer : public IndexBuffer
72 explicit StaticIndexBuffer(IDirect3DDevice9 *device);
75 virtual void *map(UINT requiredSpace, UINT *offset);
76 virtual void reserveSpace(UINT requiredSpace, GLenum type);
78 bool lookupType(GLenum type);
79 UINT lookupRange(intptr_t offset, GLsizei count, UINT *minIndex, UINT *maxIndex); // Returns the offset into the index buffer, or -1 if not found
80 void addRange(intptr_t offset, GLsizei count, UINT minIndex, UINT maxIndex, UINT streamOffset);
95 std::vector<IndexRange> mCache;
98 class IndexDataManager
101 IndexDataManager(Context *context, IDirect3DDevice9 *evice);
102 virtual ~IndexDataManager();
104 GLenum prepareIndexData(GLenum type, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated);
107 DISALLOW_COPY_AND_ASSIGN(IndexDataManager);
109 std::size_t typeSize(GLenum type) const;
110 std::size_t indexSize(D3DFORMAT format) const;
112 IDirect3DDevice9 *const mDevice;
114 StreamingIndexBuffer *mStreamingBufferShort;
115 StreamingIndexBuffer *mStreamingBufferInt;
120 #endif // LIBGLESV2_INDEXDATAMANAGER_H_