daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 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.cpp: 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 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame^] | 10 | #include "libANGLE/renderer/d3d/IndexDataManager.h" |
| 11 | #include "libANGLE/renderer/d3d/BufferD3D.h" |
| 12 | #include "libANGLE/renderer/d3d/IndexBuffer.h" |
| 13 | #include "libANGLE/renderer/d3d/RendererD3D.h" |
| 14 | #include "libANGLE/Buffer.h" |
| 15 | #include "libANGLE/formatutils.h" |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 16 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 17 | namespace rx |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 18 | { |
| 19 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 20 | static void ConvertIndices(GLenum sourceType, GLenum destinationType, const void *input, GLsizei count, void *output) |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 21 | { |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 22 | if (sourceType == GL_UNSIGNED_BYTE) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 23 | { |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 24 | ASSERT(destinationType == GL_UNSIGNED_SHORT); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 25 | const GLubyte *in = static_cast<const GLubyte*>(input); |
| 26 | GLushort *out = static_cast<GLushort*>(output); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 27 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 28 | for (GLsizei i = 0; i < count; i++) |
| 29 | { |
| 30 | out[i] = in[i]; |
| 31 | } |
| 32 | } |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 33 | else if (sourceType == GL_UNSIGNED_INT) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 34 | { |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 35 | ASSERT(destinationType == GL_UNSIGNED_INT); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 36 | memcpy(output, input, count * sizeof(GLuint)); |
| 37 | } |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 38 | else if (sourceType == GL_UNSIGNED_SHORT) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 39 | { |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 40 | if (destinationType == GL_UNSIGNED_SHORT) |
| 41 | { |
| 42 | memcpy(output, input, count * sizeof(GLushort)); |
| 43 | } |
| 44 | else if (destinationType == GL_UNSIGNED_INT) |
| 45 | { |
| 46 | const GLushort *in = static_cast<const GLushort*>(input); |
| 47 | GLuint *out = static_cast<GLuint*>(output); |
| 48 | |
| 49 | for (GLsizei i = 0; i < count; i++) |
| 50 | { |
| 51 | out[i] = in[i]; |
| 52 | } |
| 53 | } |
| 54 | else UNREACHABLE(); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 55 | } |
| 56 | else UNREACHABLE(); |
| 57 | } |
| 58 | |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 59 | IndexDataManager::IndexDataManager(RendererD3D *renderer) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 60 | : mRenderer(renderer), |
| 61 | mStreamingBufferShort(NULL), |
| 62 | mStreamingBufferInt(NULL) |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 63 | { |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 66 | IndexDataManager::~IndexDataManager() |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 67 | { |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 68 | SafeDelete(mStreamingBufferShort); |
| 69 | SafeDelete(mStreamingBufferInt); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 70 | } |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 71 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 72 | gl::Error IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer *buffer, const GLvoid *indices, TranslatedIndexData *translated) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 73 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 74 | const gl::Type &typeInfo = gl::GetTypeInfo(type); |
| 75 | |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 76 | GLenum destinationIndexType = (type == GL_UNSIGNED_INT) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 77 | |
Geoff Lang | b23fc09 | 2013-08-06 10:43:14 -0400 | [diff] [blame] | 78 | unsigned int offset = 0; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 79 | bool alignedOffset = false; |
| 80 | |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 81 | BufferD3D *storage = NULL; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 82 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 83 | if (buffer != NULL) |
| 84 | { |
Geoff Lang | b23fc09 | 2013-08-06 10:43:14 -0400 | [diff] [blame] | 85 | offset = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(indices)); |
| 86 | |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 87 | storage = BufferD3D::makeBufferD3D(buffer->getImplementation()); |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 88 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 89 | switch (type) |
| 90 | { |
| 91 | case GL_UNSIGNED_BYTE: alignedOffset = (offset % sizeof(GLubyte) == 0); break; |
| 92 | case GL_UNSIGNED_SHORT: alignedOffset = (offset % sizeof(GLushort) == 0); break; |
| 93 | case GL_UNSIGNED_INT: alignedOffset = (offset % sizeof(GLuint) == 0); break; |
| 94 | default: UNREACHABLE(); alignedOffset = false; |
| 95 | } |
| 96 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 97 | ASSERT(typeInfo.bytes * static_cast<unsigned int>(count) + offset <= storage->getSize()); |
daniel@transgaming.com | 41d8dd8 | 2010-05-12 03:45:03 +0000 | [diff] [blame] | 98 | |
Geoff Lang | c8d297a | 2014-09-19 11:09:08 -0400 | [diff] [blame] | 99 | const uint8_t *bufferData = NULL; |
| 100 | gl::Error error = storage->getData(&bufferData); |
| 101 | if (error.isError()) |
| 102 | { |
| 103 | return error; |
| 104 | } |
| 105 | |
| 106 | indices = bufferData + offset; |
daniel@transgaming.com | 41d8dd8 | 2010-05-12 03:45:03 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 109 | StaticIndexBufferInterface *staticBuffer = storage ? storage->getStaticIndexBuffer() : NULL; |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 110 | IndexBufferInterface *indexBuffer = NULL; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 111 | bool directStorage = alignedOffset && storage && storage->supportsDirectBinding() && |
| 112 | destinationIndexType == type; |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 113 | unsigned int streamOffset = 0; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 114 | |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 115 | if (directStorage) |
| 116 | { |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 117 | streamOffset = offset; |
Geoff Lang | f23eb28 | 2013-07-22 10:52:19 -0400 | [diff] [blame] | 118 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 119 | if (!buffer->getIndexRangeCache()->findRange(type, offset, count, NULL, NULL)) |
Geoff Lang | f23eb28 | 2013-07-22 10:52:19 -0400 | [diff] [blame] | 120 | { |
Jamie Madill | ef9d63e | 2014-08-04 10:48:02 -0400 | [diff] [blame] | 121 | buffer->getIndexRangeCache()->addRange(type, offset, count, translated->indexRange, offset); |
Geoff Lang | f23eb28 | 2013-07-22 10:52:19 -0400 | [diff] [blame] | 122 | } |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 123 | } |
shannon.woods@transgaming.com | 38e8788 | 2013-02-28 23:18:32 +0000 | [diff] [blame] | 124 | else if (staticBuffer && staticBuffer->getBufferSize() != 0 && staticBuffer->getIndexType() == type && alignedOffset) |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 125 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 126 | indexBuffer = staticBuffer; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 127 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 128 | if (!staticBuffer->getIndexRangeCache()->findRange(type, offset, count, NULL, &streamOffset)) |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 129 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 130 | streamOffset = (offset / typeInfo.bytes) * gl::GetTypeInfo(destinationIndexType).bytes; |
Jamie Madill | 39b4346 | 2014-08-18 16:39:50 -0400 | [diff] [blame] | 131 | staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->indexRange, streamOffset); |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 132 | } |
| 133 | } |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 134 | |
| 135 | // Avoid D3D11's primitive restart index value |
| 136 | // see http://msdn.microsoft.com/en-us/library/windows/desktop/bb205124(v=vs.85).aspx |
Jamie Madill | 39b4346 | 2014-08-18 16:39:50 -0400 | [diff] [blame] | 137 | if (translated->indexRange.end == 0xFFFF && type == GL_UNSIGNED_SHORT && mRenderer->getMajorShaderModel() > 3) |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 138 | { |
| 139 | destinationIndexType = GL_UNSIGNED_INT; |
| 140 | directStorage = false; |
| 141 | indexBuffer = NULL; |
| 142 | } |
| 143 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 144 | const gl::Type &destTypeInfo = gl::GetTypeInfo(destinationIndexType); |
| 145 | |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 146 | if (!directStorage && !indexBuffer) |
| 147 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 148 | gl::Error error = getStreamingIndexBuffer(destinationIndexType, &indexBuffer); |
| 149 | if (error.isError()) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 150 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 151 | return error; |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 152 | } |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 153 | |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 154 | unsigned int convertCount = count; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 155 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 156 | if (staticBuffer) |
| 157 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 158 | if (staticBuffer->getBufferSize() == 0 && alignedOffset) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 159 | { |
| 160 | indexBuffer = staticBuffer; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 161 | convertCount = storage->getSize() / typeInfo.bytes; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 162 | } |
| 163 | else |
| 164 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 165 | storage->invalidateStaticData(); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 166 | staticBuffer = NULL; |
| 167 | } |
| 168 | } |
| 169 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 170 | ASSERT(indexBuffer); |
daniel@transgaming.com | 50aadb0 | 2012-11-28 21:06:11 +0000 | [diff] [blame] | 171 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 172 | if (convertCount > std::numeric_limits<unsigned int>::max() / destTypeInfo.bytes) |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 173 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 174 | return gl::Error(GL_OUT_OF_MEMORY, "Reserving %u indices of %u bytes each exceeds the maximum buffer size.", |
| 175 | convertCount, destTypeInfo.bytes); |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 176 | } |
| 177 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 178 | unsigned int bufferSizeRequired = convertCount * destTypeInfo.bytes; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 179 | error = indexBuffer->reserveBufferSpace(bufferSizeRequired, type); |
| 180 | if (error.isError()) |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 181 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 182 | return error; |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 183 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 184 | |
| 185 | void* output = NULL; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 186 | error = indexBuffer->mapBuffer(bufferSizeRequired, &output, &streamOffset); |
| 187 | if (error.isError()) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 188 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 189 | return error; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Geoff Lang | c8d297a | 2014-09-19 11:09:08 -0400 | [diff] [blame] | 192 | const uint8_t *dataPointer = reinterpret_cast<const uint8_t*>(indices); |
| 193 | if (staticBuffer) |
| 194 | { |
| 195 | error = storage->getData(&dataPointer); |
| 196 | if (error.isError()) |
| 197 | { |
| 198 | return error; |
| 199 | } |
| 200 | } |
| 201 | ConvertIndices(type, destinationIndexType, dataPointer, convertCount, output); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 202 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 203 | error = indexBuffer->unmapBuffer(); |
| 204 | if (error.isError()) |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 205 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 206 | return error; |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 207 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 208 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 209 | if (staticBuffer) |
| 210 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 211 | streamOffset = (offset / typeInfo.bytes) * destTypeInfo.bytes; |
Jamie Madill | 39b4346 | 2014-08-18 16:39:50 -0400 | [diff] [blame] | 212 | staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->indexRange, streamOffset); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 213 | } |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 214 | } |
| 215 | |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 216 | translated->storage = directStorage ? storage : NULL; |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 217 | translated->indexBuffer = indexBuffer ? indexBuffer->getIndexBuffer() : NULL; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 218 | translated->serial = directStorage ? storage->getSerial() : indexBuffer->getSerial(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 219 | translated->startIndex = streamOffset / destTypeInfo.bytes; |
daniel@transgaming.com | 22ada2c | 2013-01-11 04:07:12 +0000 | [diff] [blame] | 220 | translated->startOffset = streamOffset; |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 221 | translated->indexType = destinationIndexType; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 222 | |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 223 | if (storage) |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 224 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 225 | storage->promoteStaticUsage(count * typeInfo.bytes); |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 228 | return gl::Error(GL_NO_ERROR); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 231 | gl::Error IndexDataManager::getStreamingIndexBuffer(GLenum destinationIndexType, IndexBufferInterface **outBuffer) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 232 | { |
| 233 | ASSERT(outBuffer); |
| 234 | if (destinationIndexType == GL_UNSIGNED_INT) |
| 235 | { |
| 236 | if (!mStreamingBufferInt) |
| 237 | { |
| 238 | mStreamingBufferInt = new StreamingIndexBufferInterface(mRenderer); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 239 | gl::Error error = mStreamingBufferInt->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT); |
| 240 | if (error.isError()) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 241 | { |
| 242 | SafeDelete(mStreamingBufferInt); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 243 | return error; |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | *outBuffer = mStreamingBufferInt; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 248 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 249 | } |
| 250 | else |
| 251 | { |
| 252 | ASSERT(destinationIndexType == GL_UNSIGNED_SHORT); |
| 253 | |
| 254 | if (!mStreamingBufferShort) |
| 255 | { |
| 256 | mStreamingBufferShort = new StreamingIndexBufferInterface(mRenderer); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 257 | gl::Error error = mStreamingBufferShort->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_SHORT); |
| 258 | if (error.isError()) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 259 | { |
| 260 | SafeDelete(mStreamingBufferShort); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 261 | return error; |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | *outBuffer = mStreamingBufferShort; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 266 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 270 | } |