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" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 13 | #include "libANGLE/Buffer.h" |
| 14 | #include "libANGLE/formatutils.h" |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 15 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 16 | namespace rx |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 17 | { |
| 18 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 19 | 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] | 20 | { |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 21 | if (sourceType == GL_UNSIGNED_BYTE) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 22 | { |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 23 | ASSERT(destinationType == GL_UNSIGNED_SHORT); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 24 | const GLubyte *in = static_cast<const GLubyte*>(input); |
| 25 | GLushort *out = static_cast<GLushort*>(output); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 26 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 27 | for (GLsizei i = 0; i < count; i++) |
| 28 | { |
| 29 | out[i] = in[i]; |
| 30 | } |
| 31 | } |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 32 | else if (sourceType == GL_UNSIGNED_INT) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 33 | { |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 34 | ASSERT(destinationType == GL_UNSIGNED_INT); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 35 | memcpy(output, input, count * sizeof(GLuint)); |
| 36 | } |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 37 | else if (sourceType == GL_UNSIGNED_SHORT) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 38 | { |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 39 | if (destinationType == GL_UNSIGNED_SHORT) |
| 40 | { |
| 41 | memcpy(output, input, count * sizeof(GLushort)); |
| 42 | } |
| 43 | else if (destinationType == GL_UNSIGNED_INT) |
| 44 | { |
| 45 | const GLushort *in = static_cast<const GLushort*>(input); |
| 46 | GLuint *out = static_cast<GLuint*>(output); |
| 47 | |
| 48 | for (GLsizei i = 0; i < count; i++) |
| 49 | { |
| 50 | out[i] = in[i]; |
| 51 | } |
| 52 | } |
| 53 | else UNREACHABLE(); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 54 | } |
| 55 | else UNREACHABLE(); |
| 56 | } |
| 57 | |
Jamie Madill | fd1bf4e | 2015-03-31 09:46:02 -0400 | [diff] [blame] | 58 | IndexDataManager::IndexDataManager(BufferFactoryD3D *factory, RendererClass rendererClass) |
| 59 | : mFactory(factory), |
| 60 | mRendererClass(rendererClass), |
| 61 | mStreamingBufferShort(nullptr), |
| 62 | mStreamingBufferInt(nullptr) |
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 | |
Jamie Madill | 9236b41 | 2015-02-02 16:51:52 -0500 | [diff] [blame] | 87 | storage = GetImplAs<BufferD3D>(buffer); |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 88 | |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 89 | // We'll trust that the compiler will optimize the % below: |
| 90 | // the operands are unsigned and the divisor is a constant. |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 91 | switch (type) |
| 92 | { |
| 93 | case GL_UNSIGNED_BYTE: alignedOffset = (offset % sizeof(GLubyte) == 0); break; |
| 94 | case GL_UNSIGNED_SHORT: alignedOffset = (offset % sizeof(GLushort) == 0); break; |
| 95 | case GL_UNSIGNED_INT: alignedOffset = (offset % sizeof(GLuint) == 0); break; |
| 96 | default: UNREACHABLE(); alignedOffset = false; |
| 97 | } |
| 98 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 99 | ASSERT(typeInfo.bytes * static_cast<unsigned int>(count) + offset <= storage->getSize()); |
daniel@transgaming.com | 41d8dd8 | 2010-05-12 03:45:03 +0000 | [diff] [blame] | 100 | |
Geoff Lang | c8d297a | 2014-09-19 11:09:08 -0400 | [diff] [blame] | 101 | const uint8_t *bufferData = NULL; |
| 102 | gl::Error error = storage->getData(&bufferData); |
| 103 | if (error.isError()) |
| 104 | { |
| 105 | return error; |
| 106 | } |
| 107 | |
| 108 | indices = bufferData + offset; |
daniel@transgaming.com | 41d8dd8 | 2010-05-12 03:45:03 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 111 | StaticIndexBufferInterface *staticBuffer = storage ? storage->getStaticIndexBuffer() : NULL; |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 112 | IndexBufferInterface *indexBuffer = NULL; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 113 | bool directStorage = alignedOffset && storage && storage->supportsDirectBinding() && |
| 114 | destinationIndexType == type; |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 115 | unsigned int streamOffset = 0; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 116 | |
Jamie Madill | b48e8b0 | 2015-04-15 14:26:37 -0400 | [diff] [blame^] | 117 | // Avoid D3D11's primitive restart index value |
| 118 | // see http://msdn.microsoft.com/en-us/library/windows/desktop/bb205124(v=vs.85).aspx |
| 119 | bool primitiveRestartWorkaround = mRendererClass == RENDERER_D3D11 && |
| 120 | translated->indexRange.end == 0xFFFF && |
| 121 | type == GL_UNSIGNED_SHORT; |
| 122 | |
| 123 | if (primitiveRestartWorkaround) |
| 124 | { |
| 125 | destinationIndexType = GL_UNSIGNED_INT; |
| 126 | directStorage = false; |
| 127 | } |
| 128 | |
| 129 | const gl::Type &destTypeInfo = gl::GetTypeInfo(destinationIndexType); |
| 130 | |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 131 | if (directStorage) |
| 132 | { |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 133 | streamOffset = offset; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 134 | } |
Jamie Madill | b48e8b0 | 2015-04-15 14:26:37 -0400 | [diff] [blame^] | 135 | else if (staticBuffer && |
| 136 | staticBuffer->getBufferSize() != 0 && |
| 137 | alignedOffset && |
| 138 | staticBuffer->getIndexType() == destinationIndexType) |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 139 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 140 | indexBuffer = staticBuffer; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 141 | |
Olli Etuaho | ff5e737 | 2015-03-25 16:52:11 +0200 | [diff] [blame] | 142 | // Using bit-shift here is faster than using division. |
Jamie Madill | b48e8b0 | 2015-04-15 14:26:37 -0400 | [diff] [blame^] | 143 | streamOffset = (offset >> typeInfo.bytesShift) << destTypeInfo.bytesShift; |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 144 | } |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 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; |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 161 | // Using bit-shift here is faster than using division. |
| 162 | convertCount = storage->getSize() >> typeInfo.bytesShift; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 163 | } |
| 164 | else |
| 165 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 166 | storage->invalidateStaticData(); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 167 | staticBuffer = NULL; |
| 168 | } |
| 169 | } |
| 170 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 171 | ASSERT(indexBuffer); |
daniel@transgaming.com | 50aadb0 | 2012-11-28 21:06:11 +0000 | [diff] [blame] | 172 | |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 173 | // Using bit-shift here is faster than using division. |
| 174 | if (convertCount > (std::numeric_limits<unsigned int>::max() >> destTypeInfo.bytesShift)) |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 175 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 176 | return gl::Error(GL_OUT_OF_MEMORY, "Reserving %u indices of %u bytes each exceeds the maximum buffer size.", |
| 177 | convertCount, destTypeInfo.bytes); |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 178 | } |
| 179 | |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 180 | unsigned int bufferSizeRequired = convertCount << destTypeInfo.bytesShift; |
Jamie Madill | b48e8b0 | 2015-04-15 14:26:37 -0400 | [diff] [blame^] | 181 | error = indexBuffer->reserveBufferSpace(bufferSizeRequired, destinationIndexType); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 182 | if (error.isError()) |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 183 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 184 | return error; |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 185 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 186 | |
| 187 | void* output = NULL; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 188 | error = indexBuffer->mapBuffer(bufferSizeRequired, &output, &streamOffset); |
| 189 | if (error.isError()) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 190 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 191 | return error; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Geoff Lang | c8d297a | 2014-09-19 11:09:08 -0400 | [diff] [blame] | 194 | const uint8_t *dataPointer = reinterpret_cast<const uint8_t*>(indices); |
| 195 | if (staticBuffer) |
| 196 | { |
| 197 | error = storage->getData(&dataPointer); |
| 198 | if (error.isError()) |
| 199 | { |
| 200 | return error; |
| 201 | } |
| 202 | } |
| 203 | ConvertIndices(type, destinationIndexType, dataPointer, convertCount, output); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 204 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 205 | error = indexBuffer->unmapBuffer(); |
| 206 | if (error.isError()) |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 207 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 208 | return error; |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 209 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 210 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 211 | if (staticBuffer) |
| 212 | { |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 213 | // Using bit-shift here is faster than using division. |
| 214 | streamOffset = (offset >> typeInfo.bytesShift) << destTypeInfo.bytesShift; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 215 | } |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 216 | } |
| 217 | |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 218 | translated->storage = directStorage ? storage : NULL; |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 219 | translated->indexBuffer = indexBuffer ? indexBuffer->getIndexBuffer() : NULL; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 220 | translated->serial = directStorage ? storage->getSerial() : indexBuffer->getSerial(); |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 221 | // Using bit-shift here is faster than using division. |
| 222 | translated->startIndex = (streamOffset >> destTypeInfo.bytesShift); |
daniel@transgaming.com | 22ada2c | 2013-01-11 04:07:12 +0000 | [diff] [blame] | 223 | translated->startOffset = streamOffset; |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 224 | translated->indexType = destinationIndexType; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 225 | |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 226 | if (storage) |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 227 | { |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 228 | storage->promoteStaticUsage(count << typeInfo.bytesShift); |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 231 | return gl::Error(GL_NO_ERROR); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 234 | gl::Error IndexDataManager::getStreamingIndexBuffer(GLenum destinationIndexType, IndexBufferInterface **outBuffer) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 235 | { |
| 236 | ASSERT(outBuffer); |
| 237 | if (destinationIndexType == GL_UNSIGNED_INT) |
| 238 | { |
| 239 | if (!mStreamingBufferInt) |
| 240 | { |
Jamie Madill | fd1bf4e | 2015-03-31 09:46:02 -0400 | [diff] [blame] | 241 | mStreamingBufferInt = new StreamingIndexBufferInterface(mFactory); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 242 | gl::Error error = mStreamingBufferInt->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT); |
| 243 | if (error.isError()) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 244 | { |
| 245 | SafeDelete(mStreamingBufferInt); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 246 | return error; |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | *outBuffer = mStreamingBufferInt; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 251 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 252 | } |
| 253 | else |
| 254 | { |
| 255 | ASSERT(destinationIndexType == GL_UNSIGNED_SHORT); |
| 256 | |
| 257 | if (!mStreamingBufferShort) |
| 258 | { |
Jamie Madill | fd1bf4e | 2015-03-31 09:46:02 -0400 | [diff] [blame] | 259 | mStreamingBufferShort = new StreamingIndexBufferInterface(mFactory); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 260 | gl::Error error = mStreamingBufferShort->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_SHORT); |
| 261 | if (error.isError()) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 262 | { |
| 263 | SafeDelete(mStreamingBufferShort); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 264 | return error; |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
| 268 | *outBuffer = mStreamingBufferShort; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 269 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 273 | } |