daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 1 | // |
daniel@transgaming.com | f654945 | 2012-01-27 15:39:08 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 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.com | 8fd34bd | 2011-02-18 02:52:14 +0000 | [diff] [blame] | 7 | // IndexDataManager.h: Defines the IndexDataManager, a class that |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 8 | // runs the Buffer translation process for index buffers. |
| 9 | |
daniel@transgaming.com | 8fd34bd | 2011-02-18 02:52:14 +0000 | [diff] [blame] | 10 | #ifndef LIBGLESV2_INDEXDATAMANAGER_H_ |
| 11 | #define LIBGLESV2_INDEXDATAMANAGER_H_ |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 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 | |
daniel@transgaming.com | 6c4b5e0 | 2012-01-27 15:39:12 +0000 | [diff] [blame] | 21 | namespace |
| 22 | { |
| 23 | enum { INITIAL_INDEX_BUFFER_SIZE = 4096 * sizeof(GLuint) }; |
| 24 | } |
| 25 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 26 | namespace rx |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 27 | { |
| 28 | |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 29 | struct TranslatedIndexData |
| 30 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 31 | UINT minIndex; |
| 32 | UINT maxIndex; |
| 33 | UINT startIndex; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | class IndexBuffer |
| 37 | { |
| 38 | public: |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 39 | IndexBuffer(rx::Renderer9 *renderer, UINT size, D3DFORMAT format); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 40 | virtual ~IndexBuffer(); |
| 41 | |
| 42 | UINT size() const { return mBufferSize; } |
| 43 | virtual void *map(UINT requiredSpace, UINT *offset) = 0; |
| 44 | void unmap(); |
| 45 | virtual void reserveSpace(UINT requiredSpace, GLenum type) = 0; |
| 46 | |
| 47 | IDirect3DIndexBuffer9 *getBuffer() const; |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 48 | unsigned int getSerial() const; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 49 | |
| 50 | protected: |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 51 | rx::Renderer9 *const mRenderer; // D3D9_REPLACE |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 52 | |
| 53 | IDirect3DIndexBuffer9 *mIndexBuffer; |
| 54 | UINT mBufferSize; |
| 55 | |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 56 | unsigned int mSerial; |
| 57 | static unsigned int issueSerial(); |
| 58 | static unsigned int mCurrentSerial; |
| 59 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 60 | private: |
| 61 | DISALLOW_COPY_AND_ASSIGN(IndexBuffer); |
| 62 | }; |
| 63 | |
| 64 | class StreamingIndexBuffer : public IndexBuffer |
| 65 | { |
| 66 | public: |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 67 | StreamingIndexBuffer(rx::Renderer9 *renderer, UINT initialSize, D3DFORMAT format); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 68 | ~StreamingIndexBuffer(); |
| 69 | |
daniel@transgaming.com | d976b58 | 2011-03-29 00:56:20 +0000 | [diff] [blame] | 70 | virtual void *map(UINT requiredSpace, UINT *offset); |
| 71 | virtual void reserveSpace(UINT requiredSpace, GLenum type); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | UINT mWritePosition; |
| 75 | }; |
| 76 | |
| 77 | class StaticIndexBuffer : public IndexBuffer |
| 78 | { |
| 79 | public: |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 80 | explicit StaticIndexBuffer(rx::Renderer9 *renderer); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 81 | ~StaticIndexBuffer(); |
| 82 | |
daniel@transgaming.com | d976b58 | 2011-03-29 00:56:20 +0000 | [diff] [blame] | 83 | virtual void *map(UINT requiredSpace, UINT *offset); |
| 84 | virtual void reserveSpace(UINT requiredSpace, GLenum type); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 85 | |
| 86 | bool lookupType(GLenum type); |
| 87 | UINT lookupRange(intptr_t offset, GLsizei count, UINT *minIndex, UINT *maxIndex); // Returns the offset into the index buffer, or -1 if not found |
| 88 | void addRange(intptr_t offset, GLsizei count, UINT minIndex, UINT maxIndex, UINT streamOffset); |
| 89 | |
| 90 | private: |
| 91 | GLenum mCacheType; |
daniel@transgaming.com | 50aadb0 | 2012-11-28 21:06:11 +0000 | [diff] [blame] | 92 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 93 | struct IndexRange |
| 94 | { |
| 95 | intptr_t offset; |
| 96 | GLsizei count; |
| 97 | |
jbauman@chromium.org | 43cbe74 | 2011-09-01 22:09:40 +0000 | [diff] [blame] | 98 | bool operator<(const IndexRange& rhs) const |
| 99 | { |
| 100 | if (offset != rhs.offset) |
| 101 | { |
| 102 | return offset < rhs.offset; |
| 103 | } |
| 104 | if (count != rhs.count) |
| 105 | { |
| 106 | return count < rhs.count; |
| 107 | } |
| 108 | return false; |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | struct IndexResult |
| 113 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 114 | UINT minIndex; |
| 115 | UINT maxIndex; |
| 116 | UINT streamOffset; |
| 117 | }; |
| 118 | |
jbauman@chromium.org | 43cbe74 | 2011-09-01 22:09:40 +0000 | [diff] [blame] | 119 | std::map<IndexRange, IndexResult> mCache; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | class IndexDataManager |
| 123 | { |
| 124 | public: |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 125 | IndexDataManager(rx::Renderer9 *renderer); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 126 | virtual ~IndexDataManager(); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 127 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 128 | GLenum prepareIndexData(GLenum type, GLsizei count, gl::Buffer *arrayElementBuffer, const GLvoid *indices, TranslatedIndexData *translated, IDirect3DIndexBuffer9 **indexBuffer, unsigned int *serial); |
daniel@transgaming.com | f654945 | 2012-01-27 15:39:08 +0000 | [diff] [blame] | 129 | StaticIndexBuffer *getCountingIndices(GLsizei count); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 130 | |
| 131 | private: |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 132 | DISALLOW_COPY_AND_ASSIGN(IndexDataManager); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 133 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 134 | std::size_t typeSize(GLenum type) const; |
| 135 | std::size_t indexSize(D3DFORMAT format) const; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 136 | |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 137 | rx::Renderer9 *const mRenderer; // D3D9_REPLACE |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 138 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 139 | StreamingIndexBuffer *mStreamingBufferShort; |
| 140 | StreamingIndexBuffer *mStreamingBufferInt; |
daniel@transgaming.com | f654945 | 2012-01-27 15:39:08 +0000 | [diff] [blame] | 141 | StaticIndexBuffer *mCountingBuffer; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | } |
| 145 | |
daniel@transgaming.com | 8fd34bd | 2011-02-18 02:52:14 +0000 | [diff] [blame] | 146 | #endif // LIBGLESV2_INDEXDATAMANAGER_H_ |