summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/libGLESv2/renderer/BufferStorage9.cpp
blob: e69e7a8921e3f3eb0f7e69d3f5b6f71c3f99fa39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "precompiled.h"
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// BufferStorage9.cpp Defines the BufferStorage9 class.

#include "libGLESv2/renderer/BufferStorage9.h"
#include "common/debug.h"

namespace rx
{

BufferStorage9::BufferStorage9()
{
    mMemory = NULL;
    mAllocatedSize = 0;
    mSize = 0;
}

BufferStorage9::~BufferStorage9()
{
    delete[] mMemory;
}

BufferStorage9 *BufferStorage9::makeBufferStorage9(BufferStorage *bufferStorage)
{
    ASSERT(HAS_DYNAMIC_TYPE(BufferStorage9*, bufferStorage));
    return static_cast<BufferStorage9*>(bufferStorage);
}

void *BufferStorage9::getData()
{
    return mMemory;
}

void BufferStorage9::setData(const void* data, unsigned int size, unsigned int offset)
{
    if (!mMemory || offset + size > mAllocatedSize)
    {
        unsigned int newAllocatedSize = offset + size;
        void *newMemory = new char[newAllocatedSize];

        if (offset > 0 && mMemory && mAllocatedSize > 0)
        {
            memcpy(newMemory, mMemory, std::min(offset, mAllocatedSize));
        }

        delete[] mMemory;
        mMemory = newMemory;
        mAllocatedSize = newAllocatedSize;
    }

    mSize = std::max(mSize, offset + size);
    if (data)
    {
        memcpy(reinterpret_cast<char*>(mMemory) + offset, data, size);
    }
}

void BufferStorage9::clear()
{
    mSize = 0;
}

unsigned int BufferStorage9::getSize() const
{
    return mSize;
}

bool BufferStorage9::supportsDirectBinding() const
{
    return false;
}

}