shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 2 | // |
daniel@transgaming.com | 8ca9c6e | 2012-01-27 15:38:54 +0000 | [diff] [blame] | 3 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
daniel@transgaming.com | 8fd34bd | 2011-02-18 02:52:14 +0000 | [diff] [blame] | 8 | // VertexDataManager.h: Defines the VertexDataManager, a class that |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 9 | // runs the Buffer translation process. |
| 10 | |
Brandon Jones | c7a4104 | 2014-06-23 12:03:25 -0700 | [diff] [blame] | 11 | #include "libGLESv2/renderer/d3d/VertexDataManager.h" |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 12 | #include "libGLESv2/renderer/d3d/BufferD3D.h" |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 13 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 14 | #include "libGLESv2/Buffer.h" |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 15 | #include "libGLESv2/ProgramBinary.h" |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 16 | #include "libGLESv2/VertexAttribute.h" |
Brandon Jones | c7a4104 | 2014-06-23 12:03:25 -0700 | [diff] [blame] | 17 | #include "libGLESv2/renderer/d3d/VertexBuffer.h" |
Jamie Madill | a5d6747 | 2014-02-04 16:04:13 -0500 | [diff] [blame] | 18 | #include "libGLESv2/renderer/Renderer.h" |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 19 | |
| 20 | namespace |
| 21 | { |
| 22 | enum { INITIAL_STREAM_BUFFER_SIZE = 1024*1024 }; |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 23 | // This has to be at least 4k or else it fails on ATI cards. |
| 24 | enum { CONSTANT_VERTEX_BUFFER_SIZE = 4096 }; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 25 | } |
| 26 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 27 | namespace rx |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 28 | { |
| 29 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 30 | static int ElementsInBuffer(const gl::VertexAttribute &attrib, unsigned int size) |
jbauman@chromium.org | 059fc15 | 2011-11-18 19:26:17 +0000 | [diff] [blame] | 31 | { |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 32 | // Size cannot be larger than a GLsizei |
| 33 | if (size > static_cast<unsigned int>(std::numeric_limits<int>::max())) |
| 34 | { |
| 35 | size = static_cast<unsigned int>(std::numeric_limits<int>::max()); |
| 36 | } |
| 37 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 38 | GLsizei stride = ComputeVertexAttributeStride(attrib); |
| 39 | return (size - attrib.offset % stride + (stride - ComputeVertexAttributeTypeSize(attrib))) / stride; |
jbauman@chromium.org | 059fc15 | 2011-11-18 19:26:17 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 42 | static int StreamingBufferElementCount(const gl::VertexAttribute &attrib, int vertexDrawCount, int instanceDrawCount) |
Jamie Madill | 9b4f384 | 2013-08-26 15:29:30 -0400 | [diff] [blame] | 43 | { |
| 44 | // For instanced rendering, we draw "instanceDrawCount" sets of "vertexDrawCount" vertices. |
| 45 | // |
| 46 | // A vertex attribute with a positive divisor loads one instanced vertex for every set of |
| 47 | // non-instanced vertices, and the instanced vertex index advances once every "mDivisor" instances. |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 48 | if (instanceDrawCount > 0 && attrib.divisor > 0) |
Jamie Madill | 9b4f384 | 2013-08-26 15:29:30 -0400 | [diff] [blame] | 49 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 50 | return instanceDrawCount / attrib.divisor; |
Jamie Madill | 9b4f384 | 2013-08-26 15:29:30 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | return vertexDrawCount; |
| 54 | } |
| 55 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 56 | VertexDataManager::VertexDataManager(Renderer *renderer) : mRenderer(renderer) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 57 | { |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 58 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 59 | { |
shannon.woods%transgaming.com@gtempaccount.com | 3026dc7 | 2013-04-13 03:37:27 +0000 | [diff] [blame] | 60 | mCurrentValue[i].FloatValues[0] = std::numeric_limits<float>::quiet_NaN(); |
| 61 | mCurrentValue[i].FloatValues[1] = std::numeric_limits<float>::quiet_NaN(); |
| 62 | mCurrentValue[i].FloatValues[2] = std::numeric_limits<float>::quiet_NaN(); |
| 63 | mCurrentValue[i].FloatValues[3] = std::numeric_limits<float>::quiet_NaN(); |
| 64 | mCurrentValue[i].Type = GL_FLOAT; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 65 | mCurrentValueBuffer[i] = NULL; |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 66 | mCurrentValueOffsets[i] = 0; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 67 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 68 | |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 69 | mStreamingBuffer = new StreamingVertexBufferInterface(renderer, INITIAL_STREAM_BUFFER_SIZE); |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 70 | |
| 71 | if (!mStreamingBuffer) |
| 72 | { |
| 73 | ERR("Failed to allocate the streaming vertex buffer."); |
| 74 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | VertexDataManager::~VertexDataManager() |
| 78 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 79 | delete mStreamingBuffer; |
| 80 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 81 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 82 | { |
| 83 | delete mCurrentValueBuffer[i]; |
| 84 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 87 | GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[], |
| 88 | gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *translated, GLsizei instances) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 89 | { |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 90 | if (!mStreamingBuffer) |
| 91 | { |
| 92 | return GL_OUT_OF_MEMORY; |
| 93 | } |
| 94 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 95 | for (int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 96 | { |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 97 | translated[attributeIndex].active = (programBinary->getSemanticIndex(attributeIndex) != -1); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 98 | } |
| 99 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 100 | // Invalidate static buffers that don't contain matching attributes |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 101 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 102 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 103 | if (translated[i].active && attribs[i].enabled) |
daniel@transgaming.com | c828b14 | 2010-05-12 03:42:04 +0000 | [diff] [blame] | 104 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 105 | gl::Buffer *buffer = attribs[i].buffer.get(); |
daniel@transgaming.com | c828b14 | 2010-05-12 03:42:04 +0000 | [diff] [blame] | 106 | |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 107 | if (buffer) |
shannon.woods@transgaming.com | a9a509e | 2013-02-28 23:10:44 +0000 | [diff] [blame] | 108 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 109 | BufferD3D *bufferImpl = BufferD3D::makeBufferD3D(buffer->getImplementation()); |
| 110 | StaticVertexBufferInterface *staticBuffer = bufferImpl->getStaticVertexBuffer(); |
| 111 | |
| 112 | if (staticBuffer && staticBuffer->getBufferSize() > 0 && !staticBuffer->lookupAttribute(attribs[i], NULL) && |
| 113 | !staticBuffer->directStoragePossible(attribs[i], currentValues[i])) |
| 114 | { |
| 115 | bufferImpl->invalidateStaticData(); |
| 116 | } |
shannon.woods@transgaming.com | a9a509e | 2013-02-28 23:10:44 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // Reserve the required space in the buffers |
| 122 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
| 123 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 124 | if (translated[i].active && attribs[i].enabled) |
shannon.woods@transgaming.com | a9a509e | 2013-02-28 23:10:44 +0000 | [diff] [blame] | 125 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 126 | gl::Buffer *buffer = attribs[i].buffer.get(); |
Brandon Jones | b23375f | 2014-07-08 10:49:39 -0700 | [diff] [blame] | 127 | BufferD3D *bufferImpl = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL; |
| 128 | StaticVertexBufferInterface *staticBuffer = bufferImpl ? bufferImpl->getStaticVertexBuffer() : NULL; |
| 129 | VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); |
| 130 | |
| 131 | if (!vertexBuffer->directStoragePossible(attribs[i], currentValues[i])) |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 132 | { |
Brandon Jones | b23375f | 2014-07-08 10:49:39 -0700 | [diff] [blame] | 133 | if (staticBuffer) |
daniel@transgaming.com | 5ee2ad0 | 2011-01-08 05:46:20 +0000 | [diff] [blame] | 134 | { |
Brandon Jones | b23375f | 2014-07-08 10:49:39 -0700 | [diff] [blame] | 135 | if (staticBuffer->getBufferSize() == 0) |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 136 | { |
Brandon Jones | b23375f | 2014-07-08 10:49:39 -0700 | [diff] [blame] | 137 | int totalCount = ElementsInBuffer(attribs[i], bufferImpl->getSize()); |
| 138 | if (!staticBuffer->reserveVertexSpace(attribs[i], totalCount, 0)) |
Geoff Lang | fe5b272 | 2013-07-09 15:58:36 -0400 | [diff] [blame] | 139 | { |
| 140 | return GL_OUT_OF_MEMORY; |
| 141 | } |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 142 | } |
daniel@transgaming.com | 5ee2ad0 | 2011-01-08 05:46:20 +0000 | [diff] [blame] | 143 | } |
Brandon Jones | b23375f | 2014-07-08 10:49:39 -0700 | [diff] [blame] | 144 | else |
| 145 | { |
| 146 | int totalCount = StreamingBufferElementCount(attribs[i], count, instances); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 147 | ASSERT(!bufferImpl || ElementsInBuffer(attribs[i], bufferImpl->getSize()) >= totalCount); |
Brandon Jones | b23375f | 2014-07-08 10:49:39 -0700 | [diff] [blame] | 148 | |
| 149 | if (!mStreamingBuffer->reserveVertexSpace(attribs[i], totalCount, instances)) |
| 150 | { |
| 151 | return GL_OUT_OF_MEMORY; |
| 152 | } |
| 153 | } |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 154 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
| 158 | // Perform the vertex data translations |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 159 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 160 | { |
| 161 | if (translated[i].active) |
| 162 | { |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 163 | GLenum result; |
| 164 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 165 | if (attribs[i].enabled) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 166 | { |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 167 | result = storeAttribute(attribs[i], currentValues[i], &translated[i], |
| 168 | start, count, instances); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 169 | } |
daniel@transgaming.com | 9a0606c | 2010-05-12 03:42:00 +0000 | [diff] [blame] | 170 | else |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 171 | { |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 172 | if (!mCurrentValueBuffer[i]) |
| 173 | { |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 174 | mCurrentValueBuffer[i] = new StreamingVertexBufferInterface(mRenderer, CONSTANT_VERTEX_BUFFER_SIZE); |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 177 | result = storeCurrentValue(attribs[i], currentValues[i], &translated[i], |
| 178 | &mCurrentValue[i], &mCurrentValueOffsets[i], |
| 179 | mCurrentValueBuffer[i]); |
| 180 | } |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 181 | |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 182 | if (result != GL_NO_ERROR) |
| 183 | { |
| 184 | return result; |
daniel@transgaming.com | 9a0606c | 2010-05-12 03:42:00 +0000 | [diff] [blame] | 185 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 188 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 189 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 190 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 191 | if (translated[i].active && attribs[i].enabled) |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 192 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 193 | gl::Buffer *buffer = attribs[i].buffer.get(); |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 194 | |
| 195 | if (buffer) |
| 196 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 197 | BufferD3D *bufferImpl = BufferD3D::makeBufferD3D(buffer->getImplementation()); |
| 198 | bufferImpl->promoteStaticUsage(count * ComputeVertexAttributeTypeSize(attribs[i])); |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 203 | return GL_NO_ERROR; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 206 | GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib, |
| 207 | const gl::VertexAttribCurrentValueData ¤tValue, |
| 208 | TranslatedAttribute *translated, |
| 209 | GLint start, |
| 210 | GLsizei count, |
| 211 | GLsizei instances) |
| 212 | { |
| 213 | gl::Buffer *buffer = attrib.buffer.get(); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 214 | ASSERT(buffer || attrib.pointer); |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 215 | |
| 216 | BufferD3D *storage = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL; |
| 217 | StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL; |
| 218 | VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); |
| 219 | bool directStorage = vertexBuffer->directStoragePossible(attrib, currentValue); |
| 220 | |
| 221 | unsigned int streamOffset = 0; |
| 222 | unsigned int outputElementSize = 0; |
| 223 | |
| 224 | if (directStorage) |
| 225 | { |
| 226 | outputElementSize = ComputeVertexAttributeStride(attrib); |
| 227 | streamOffset = attrib.offset + outputElementSize * start; |
| 228 | } |
| 229 | else if (staticBuffer) |
| 230 | { |
| 231 | if (!staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize)) |
| 232 | { |
| 233 | return GL_OUT_OF_MEMORY; |
| 234 | } |
| 235 | |
| 236 | if (!staticBuffer->lookupAttribute(attrib, &streamOffset)) |
| 237 | { |
| 238 | // Convert the entire buffer |
| 239 | int totalCount = ElementsInBuffer(attrib, storage->getSize()); |
| 240 | int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib); |
| 241 | |
| 242 | if (!staticBuffer->storeVertexAttributes(attrib, currentValue, -startIndex, totalCount, |
| 243 | 0, &streamOffset)) |
| 244 | { |
| 245 | return GL_OUT_OF_MEMORY; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | unsigned int firstElementOffset = (attrib.offset / ComputeVertexAttributeStride(attrib)) * outputElementSize; |
| 250 | unsigned int startOffset = (instances == 0 || attrib.divisor == 0) ? start * outputElementSize : 0; |
| 251 | if (streamOffset + firstElementOffset + startOffset < streamOffset) |
| 252 | { |
| 253 | return GL_OUT_OF_MEMORY; |
| 254 | } |
| 255 | |
| 256 | streamOffset += firstElementOffset + startOffset; |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | int totalCount = StreamingBufferElementCount(attrib, count, instances); |
| 261 | if (!mStreamingBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize) || |
| 262 | !mStreamingBuffer->storeVertexAttributes(attrib, currentValue, start, totalCount, instances, |
| 263 | &streamOffset)) |
| 264 | { |
| 265 | return GL_OUT_OF_MEMORY; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | translated->storage = directStorage ? storage : NULL; |
| 270 | translated->vertexBuffer = vertexBuffer->getVertexBuffer(); |
| 271 | translated->serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial(); |
| 272 | translated->divisor = attrib.divisor; |
| 273 | |
| 274 | translated->attribute = &attrib; |
| 275 | translated->currentValueType = currentValue.Type; |
| 276 | translated->stride = outputElementSize; |
| 277 | translated->offset = streamOffset; |
| 278 | |
| 279 | return GL_NO_ERROR; |
| 280 | } |
| 281 | |
| 282 | GLenum VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib, |
| 283 | const gl::VertexAttribCurrentValueData ¤tValue, |
| 284 | TranslatedAttribute *translated, |
| 285 | gl::VertexAttribCurrentValueData *cachedValue, |
| 286 | size_t *cachedOffset, |
| 287 | StreamingVertexBufferInterface *buffer) |
| 288 | { |
| 289 | if (*cachedValue != currentValue) |
| 290 | { |
| 291 | if (!buffer->reserveVertexSpace(attrib, 1, 0)) |
| 292 | { |
| 293 | return GL_OUT_OF_MEMORY; |
| 294 | } |
| 295 | |
| 296 | unsigned int streamOffset; |
| 297 | if (!buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset)) |
| 298 | { |
| 299 | return GL_OUT_OF_MEMORY; |
| 300 | } |
| 301 | |
| 302 | *cachedValue = currentValue; |
| 303 | *cachedOffset = streamOffset; |
| 304 | } |
| 305 | |
| 306 | translated->storage = NULL; |
| 307 | translated->vertexBuffer = buffer->getVertexBuffer(); |
| 308 | translated->serial = buffer->getSerial(); |
| 309 | translated->divisor = 0; |
| 310 | |
| 311 | translated->attribute = &attrib; |
| 312 | translated->currentValueType = currentValue.Type; |
| 313 | translated->stride = 0; |
| 314 | translated->offset = *cachedOffset; |
| 315 | |
| 316 | return GL_NO_ERROR; |
| 317 | } |
| 318 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 319 | } |