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 | |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 117 | if (directStorage) |
| 118 | { |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 119 | streamOffset = offset; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 120 | } |
shannon.woods@transgaming.com | 38e8788 | 2013-02-28 23:18:32 +0000 | [diff] [blame] | 121 | else if (staticBuffer && staticBuffer->getBufferSize() != 0 && staticBuffer->getIndexType() == type && alignedOffset) |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 122 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 123 | indexBuffer = staticBuffer; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 124 | |
Olli Etuaho | ff5e737 | 2015-03-25 16:52:11 +0200 | [diff] [blame] | 125 | // Using bit-shift here is faster than using division. |
| 126 | streamOffset = (offset >> typeInfo.bytesShift) << gl::GetTypeInfo(destinationIndexType).bytesShift; |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 127 | } |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 128 | |
| 129 | // Avoid D3D11's primitive restart index value |
| 130 | // see http://msdn.microsoft.com/en-us/library/windows/desktop/bb205124(v=vs.85).aspx |
Jamie Madill | fd1bf4e | 2015-03-31 09:46:02 -0400 | [diff] [blame^] | 131 | if (translated->indexRange.end == 0xFFFF && type == GL_UNSIGNED_SHORT && mRendererClass == RENDERER_D3D11) |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 132 | { |
| 133 | destinationIndexType = GL_UNSIGNED_INT; |
| 134 | directStorage = false; |
| 135 | indexBuffer = NULL; |
| 136 | } |
| 137 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 138 | const gl::Type &destTypeInfo = gl::GetTypeInfo(destinationIndexType); |
| 139 | |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 140 | if (!directStorage && !indexBuffer) |
| 141 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 142 | gl::Error error = getStreamingIndexBuffer(destinationIndexType, &indexBuffer); |
| 143 | if (error.isError()) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 144 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 145 | return error; |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 146 | } |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 147 | |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 148 | unsigned int convertCount = count; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 149 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 150 | if (staticBuffer) |
| 151 | { |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 152 | if (staticBuffer->getBufferSize() == 0 && alignedOffset) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 153 | { |
| 154 | indexBuffer = staticBuffer; |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 155 | // Using bit-shift here is faster than using division. |
| 156 | convertCount = storage->getSize() >> typeInfo.bytesShift; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 157 | } |
| 158 | else |
| 159 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 160 | storage->invalidateStaticData(); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 161 | staticBuffer = NULL; |
| 162 | } |
| 163 | } |
| 164 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 165 | ASSERT(indexBuffer); |
daniel@transgaming.com | 50aadb0 | 2012-11-28 21:06:11 +0000 | [diff] [blame] | 166 | |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 167 | // Using bit-shift here is faster than using division. |
| 168 | if (convertCount > (std::numeric_limits<unsigned int>::max() >> destTypeInfo.bytesShift)) |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 169 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 170 | return gl::Error(GL_OUT_OF_MEMORY, "Reserving %u indices of %u bytes each exceeds the maximum buffer size.", |
| 171 | convertCount, destTypeInfo.bytes); |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 174 | unsigned int bufferSizeRequired = convertCount << destTypeInfo.bytesShift; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 175 | error = indexBuffer->reserveBufferSpace(bufferSizeRequired, type); |
| 176 | if (error.isError()) |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 177 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 178 | return error; |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 179 | } |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 180 | |
| 181 | void* output = NULL; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 182 | error = indexBuffer->mapBuffer(bufferSizeRequired, &output, &streamOffset); |
| 183 | if (error.isError()) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 184 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 185 | return error; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Geoff Lang | c8d297a | 2014-09-19 11:09:08 -0400 | [diff] [blame] | 188 | const uint8_t *dataPointer = reinterpret_cast<const uint8_t*>(indices); |
| 189 | if (staticBuffer) |
| 190 | { |
| 191 | error = storage->getData(&dataPointer); |
| 192 | if (error.isError()) |
| 193 | { |
| 194 | return error; |
| 195 | } |
| 196 | } |
| 197 | ConvertIndices(type, destinationIndexType, dataPointer, convertCount, output); |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 198 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 199 | error = indexBuffer->unmapBuffer(); |
| 200 | if (error.isError()) |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 201 | { |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 202 | return error; |
daniel@transgaming.com | 1e3a804 | 2012-12-20 21:09:55 +0000 | [diff] [blame] | 203 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 204 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 205 | if (staticBuffer) |
| 206 | { |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 207 | // Using bit-shift here is faster than using division. |
| 208 | streamOffset = (offset >> typeInfo.bytesShift) << destTypeInfo.bytesShift; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 209 | } |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 210 | } |
| 211 | |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 212 | translated->storage = directStorage ? storage : NULL; |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 213 | translated->indexBuffer = indexBuffer ? indexBuffer->getIndexBuffer() : NULL; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 214 | translated->serial = directStorage ? storage->getSerial() : indexBuffer->getSerial(); |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 215 | // Using bit-shift here is faster than using division. |
| 216 | translated->startIndex = (streamOffset >> destTypeInfo.bytesShift); |
daniel@transgaming.com | 22ada2c | 2013-01-11 04:07:12 +0000 | [diff] [blame] | 217 | translated->startOffset = streamOffset; |
Nicolas Capens | 8d62bcc | 2014-07-25 15:08:21 -0400 | [diff] [blame] | 218 | translated->indexType = destinationIndexType; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 219 | |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 220 | if (storage) |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 221 | { |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 222 | storage->promoteStaticUsage(count << typeInfo.bytesShift); |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 225 | return gl::Error(GL_NO_ERROR); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 228 | gl::Error IndexDataManager::getStreamingIndexBuffer(GLenum destinationIndexType, IndexBufferInterface **outBuffer) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 229 | { |
| 230 | ASSERT(outBuffer); |
| 231 | if (destinationIndexType == GL_UNSIGNED_INT) |
| 232 | { |
| 233 | if (!mStreamingBufferInt) |
| 234 | { |
Jamie Madill | fd1bf4e | 2015-03-31 09:46:02 -0400 | [diff] [blame^] | 235 | mStreamingBufferInt = new StreamingIndexBufferInterface(mFactory); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 236 | gl::Error error = mStreamingBufferInt->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT); |
| 237 | if (error.isError()) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 238 | { |
| 239 | SafeDelete(mStreamingBufferInt); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 240 | return error; |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | *outBuffer = mStreamingBufferInt; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 245 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 246 | } |
| 247 | else |
| 248 | { |
| 249 | ASSERT(destinationIndexType == GL_UNSIGNED_SHORT); |
| 250 | |
| 251 | if (!mStreamingBufferShort) |
| 252 | { |
Jamie Madill | fd1bf4e | 2015-03-31 09:46:02 -0400 | [diff] [blame^] | 253 | mStreamingBufferShort = new StreamingIndexBufferInterface(mFactory); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 254 | gl::Error error = mStreamingBufferShort->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_SHORT); |
| 255 | if (error.isError()) |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 256 | { |
| 257 | SafeDelete(mStreamingBufferShort); |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 258 | return error; |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| 262 | *outBuffer = mStreamingBufferShort; |
Geoff Lang | c9e69b1 | 2014-09-08 16:06:25 -0400 | [diff] [blame] | 263 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | 1c134e6 | 2014-09-08 15:32:18 -0400 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 267 | } |