daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 1 | // |
| 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 | |
| 7 | // geometry/IndexDataManager.h: Defines the IndexDataManager, a class that |
| 8 | // runs the Buffer translation process for index buffers. |
| 9 | |
| 10 | #ifndef LIBGLESV2_GEOMETRY_INDEXDATAMANAGER_H_ |
| 11 | #define LIBGLESV2_GEOMETRY_INDEXDATAMANAGER_H_ |
| 12 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame^] | 13 | #include <vector> |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 14 | #include <cstddef> |
| 15 | |
| 16 | #define GL_APICALL |
| 17 | #include <GLES2/gl2.h> |
| 18 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 19 | #include "libGLESv2/Context.h" |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 20 | |
| 21 | namespace gl |
| 22 | { |
| 23 | |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 24 | struct TranslatedIndexData |
| 25 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame^] | 26 | UINT minIndex; |
| 27 | UINT maxIndex; |
| 28 | UINT startIndex; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 29 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame^] | 30 | IDirect3DIndexBuffer9 *indexBuffer; |
| 31 | }; |
| 32 | |
| 33 | class 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 | |
| 56 | class 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 | |
| 69 | class 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.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | class IndexDataManager |
| 99 | { |
| 100 | public: |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame^] | 101 | IndexDataManager(Context *context, IDirect3DDevice9 *evice); |
| 102 | virtual ~IndexDataManager(); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 103 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame^] | 104 | GLenum prepareIndexData(GLenum type, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 105 | |
| 106 | private: |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame^] | 107 | DISALLOW_COPY_AND_ASSIGN(IndexDataManager); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 108 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame^] | 109 | std::size_t typeSize(GLenum type) const; |
| 110 | std::size_t indexSize(D3DFORMAT format) const; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 111 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame^] | 112 | IDirect3DDevice9 *const mDevice; |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 113 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame^] | 114 | StreamingIndexBuffer *mStreamingBufferShort; |
| 115 | StreamingIndexBuffer *mStreamingBufferInt; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | } |
| 119 | |
| 120 | #endif // LIBGLESV2_GEOMETRY_INDEXDATAMANAGER_H_ |