|
1 #include "precompiled.h" |
|
2 // |
|
3 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. |
|
4 // Use of this source code is governed by a BSD-style license that can be |
|
5 // found in the LICENSE file. |
|
6 // |
|
7 |
|
8 // BufferStorage9.cpp Defines the BufferStorage9 class. |
|
9 |
|
10 #include "libGLESv2/renderer/BufferStorage9.h" |
|
11 #include "common/debug.h" |
|
12 |
|
13 namespace rx |
|
14 { |
|
15 |
|
16 BufferStorage9::BufferStorage9() |
|
17 { |
|
18 mMemory = NULL; |
|
19 mAllocatedSize = 0; |
|
20 mSize = 0; |
|
21 } |
|
22 |
|
23 BufferStorage9::~BufferStorage9() |
|
24 { |
|
25 delete[] mMemory; |
|
26 } |
|
27 |
|
28 BufferStorage9 *BufferStorage9::makeBufferStorage9(BufferStorage *bufferStorage) |
|
29 { |
|
30 ASSERT(HAS_DYNAMIC_TYPE(BufferStorage9*, bufferStorage)); |
|
31 return static_cast<BufferStorage9*>(bufferStorage); |
|
32 } |
|
33 |
|
34 void *BufferStorage9::getData() |
|
35 { |
|
36 return mMemory; |
|
37 } |
|
38 |
|
39 void BufferStorage9::setData(const void* data, unsigned int size, unsigned int offset) |
|
40 { |
|
41 if (!mMemory || offset + size > mAllocatedSize) |
|
42 { |
|
43 unsigned int newAllocatedSize = offset + size; |
|
44 void *newMemory = new char[newAllocatedSize]; |
|
45 |
|
46 if (offset > 0 && mMemory && mAllocatedSize > 0) |
|
47 { |
|
48 memcpy(newMemory, mMemory, std::min(offset, mAllocatedSize)); |
|
49 } |
|
50 |
|
51 delete[] mMemory; |
|
52 mMemory = newMemory; |
|
53 mAllocatedSize = newAllocatedSize; |
|
54 } |
|
55 |
|
56 mSize = std::max(mSize, offset + size); |
|
57 if (data) |
|
58 { |
|
59 memcpy(reinterpret_cast<char*>(mMemory) + offset, data, size); |
|
60 } |
|
61 } |
|
62 |
|
63 void BufferStorage9::clear() |
|
64 { |
|
65 mSize = 0; |
|
66 } |
|
67 |
|
68 unsigned int BufferStorage9::getSize() const |
|
69 { |
|
70 return mSize; |
|
71 } |
|
72 |
|
73 bool BufferStorage9::supportsDirectBinding() const |
|
74 { |
|
75 return false; |
|
76 } |
|
77 |
|
78 } |