blob: 0889510a5ba2fcf99916e2be3308a16a744d9a65 [file] [log] [blame]
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +00001//
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.
5//
6
daniel@transgaming.com8fd34bd2011-02-18 02:52:14 +00007// IndexDataManager.h: Defines the IndexDataManager, a class that
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +00008// runs the Buffer translation process for index buffers.
9
daniel@transgaming.com8fd34bd2011-02-18 02:52:14 +000010#ifndef LIBGLESV2_INDEXDATAMANAGER_H_
11#define LIBGLESV2_INDEXDATAMANAGER_H_
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +000012
daniel@transgaming.com83921382011-01-08 05:46:00 +000013#include <vector>
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +000014#include <cstddef>
15
16#define GL_APICALL
17#include <GLES2/gl2.h>
18
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Context.h"
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +000020
21namespace gl
22{
23
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +000024struct TranslatedIndexData
25{
daniel@transgaming.com83921382011-01-08 05:46:00 +000026 UINT minIndex;
27 UINT maxIndex;
28 UINT startIndex;
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +000029
daniel@transgaming.com83921382011-01-08 05:46:00 +000030 IDirect3DIndexBuffer9 *indexBuffer;
31};
32
33class IndexBuffer
34{
35 public:
36 IndexBuffer(IDirect3DDevice9 *device, UINT size, D3DFORMAT format);
37 virtual ~IndexBuffer();
38
39 UINT size() const { return mBufferSize; }
40 virtual void *map(UINT requiredSpace, UINT *offset) = 0;
41 void unmap();
42 virtual void reserveSpace(UINT requiredSpace, GLenum type) = 0;
43
44 IDirect3DIndexBuffer9 *getBuffer() const;
45
46 protected:
47 IDirect3DDevice9 *const mDevice;
48
49 IDirect3DIndexBuffer9 *mIndexBuffer;
50 UINT mBufferSize;
51
52 private:
53 DISALLOW_COPY_AND_ASSIGN(IndexBuffer);
54};
55
56class StreamingIndexBuffer : public IndexBuffer
57{
58 public:
59 StreamingIndexBuffer(IDirect3DDevice9 *device, UINT initialSize, D3DFORMAT format);
60 ~StreamingIndexBuffer();
61
62 void *map(UINT requiredSpace, UINT *offset);
63 void reserveSpace(UINT requiredSpace, GLenum type);
64
65 private:
66 UINT mWritePosition;
67};
68
69class StaticIndexBuffer : public IndexBuffer
70{
71 public:
72 explicit StaticIndexBuffer(IDirect3DDevice9 *device);
73 ~StaticIndexBuffer();
74
75 void *map(UINT requiredSpace, UINT *offset);
76 void reserveSpace(UINT requiredSpace, GLenum type);
77
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);
81
82 private:
83 GLenum mCacheType;
84
85 struct IndexRange
86 {
87 intptr_t offset;
88 GLsizei count;
89
90 UINT minIndex;
91 UINT maxIndex;
92 UINT streamOffset;
93 };
94
95 std::vector<IndexRange> mCache;
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +000096};
97
98class IndexDataManager
99{
100 public:
daniel@transgaming.com83921382011-01-08 05:46:00 +0000101 IndexDataManager(Context *context, IDirect3DDevice9 *evice);
102 virtual ~IndexDataManager();
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +0000103
daniel@transgaming.com83921382011-01-08 05:46:00 +0000104 GLenum prepareIndexData(GLenum type, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated);
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +0000105
106 private:
daniel@transgaming.com83921382011-01-08 05:46:00 +0000107 DISALLOW_COPY_AND_ASSIGN(IndexDataManager);
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +0000108
daniel@transgaming.com83921382011-01-08 05:46:00 +0000109 std::size_t typeSize(GLenum type) const;
110 std::size_t indexSize(D3DFORMAT format) const;
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +0000111
daniel@transgaming.com83921382011-01-08 05:46:00 +0000112 IDirect3DDevice9 *const mDevice;
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +0000113
daniel@transgaming.com83921382011-01-08 05:46:00 +0000114 StreamingIndexBuffer *mStreamingBufferShort;
115 StreamingIndexBuffer *mStreamingBufferInt;
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +0000116};
117
118}
119
daniel@transgaming.com8fd34bd2011-02-18 02:52:14 +0000120#endif // LIBGLESV2_INDEXDATAMANAGER_H_