~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/3rdparty/angle/src/libGLESv2/Buffer.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
 
3
// Use of this source code is governed by a BSD-style license that can be
 
4
// found in the LICENSE file.
 
5
//
 
6
 
 
7
// Buffer.cpp: Implements the gl::Buffer class, representing storage of vertex and/or
 
8
// index data. Implements GL buffer objects and related functionality.
 
9
// [OpenGL ES 2.0.24] section 2.9 page 21.
 
10
 
 
11
#include "libGLESv2/Buffer.h"
 
12
 
 
13
#include "libGLESv2/main.h"
 
14
#include "libGLESv2/VertexDataManager.h"
 
15
#include "libGLESv2/IndexDataManager.h"
 
16
 
 
17
namespace gl
 
18
{
 
19
 
 
20
Buffer::Buffer(GLuint id) : RefCountObject(id)
 
21
{
 
22
    mContents = NULL;
 
23
    mSize = 0;
 
24
    mUsage = GL_DYNAMIC_DRAW;
 
25
 
 
26
    mStaticVertexBuffer = NULL;
 
27
    mStaticIndexBuffer = NULL;
 
28
    mUnmodifiedDataUse = 0;
 
29
}
 
30
 
 
31
Buffer::~Buffer()
 
32
{
 
33
    delete[] mContents;
 
34
    delete mStaticVertexBuffer;
 
35
    delete mStaticIndexBuffer;
 
36
}
 
37
 
 
38
void Buffer::bufferData(const void *data, GLsizeiptr size, GLenum usage)
 
39
{
 
40
    if (size == 0)
 
41
    {
 
42
        delete[] mContents;
 
43
        mContents = NULL;
 
44
    }
 
45
    else if (size != mSize)
 
46
    {
 
47
        delete[] mContents;
 
48
        mContents = new GLubyte[size];
 
49
        memset(mContents, 0, size);
 
50
    }
 
51
 
 
52
    if (data != NULL && size > 0)
 
53
    {
 
54
        memcpy(mContents, data, size);
 
55
    }
 
56
 
 
57
    mSize = size;
 
58
    mUsage = usage;
 
59
 
 
60
    invalidateStaticData();
 
61
 
 
62
    if (usage == GL_STATIC_DRAW)
 
63
    {
 
64
        mStaticVertexBuffer = new StaticVertexBuffer(getDevice());
 
65
        mStaticIndexBuffer = new StaticIndexBuffer(getDevice());
 
66
    }
 
67
}
 
68
 
 
69
void Buffer::bufferSubData(const void *data, GLsizeiptr size, GLintptr offset)
 
70
{
 
71
    memcpy(mContents + offset, data, size);
 
72
    
 
73
    if ((mStaticVertexBuffer && mStaticVertexBuffer->size() != 0) || (mStaticIndexBuffer && mStaticIndexBuffer->size() != 0))
 
74
    {
 
75
        invalidateStaticData();
 
76
    }
 
77
 
 
78
    mUnmodifiedDataUse = 0;
 
79
}
 
80
 
 
81
StaticVertexBuffer *Buffer::getStaticVertexBuffer()
 
82
{
 
83
    return mStaticVertexBuffer;
 
84
}
 
85
 
 
86
StaticIndexBuffer *Buffer::getStaticIndexBuffer()
 
87
{
 
88
    return mStaticIndexBuffer;
 
89
}
 
90
 
 
91
void Buffer::invalidateStaticData()
 
92
{
 
93
    delete mStaticVertexBuffer;
 
94
    mStaticVertexBuffer = NULL;
 
95
 
 
96
    delete mStaticIndexBuffer;
 
97
    mStaticIndexBuffer = NULL;
 
98
 
 
99
    mUnmodifiedDataUse = 0;
 
100
}
 
101
 
 
102
// Creates static buffers if sufficient used data has been left unmodified
 
103
void Buffer::promoteStaticUsage(int dataSize)
 
104
{
 
105
    if (!mStaticVertexBuffer && !mStaticIndexBuffer)
 
106
    {
 
107
        mUnmodifiedDataUse += dataSize;
 
108
 
 
109
        if (mUnmodifiedDataUse > 3 * mSize)
 
110
        {
 
111
            mStaticVertexBuffer = new StaticVertexBuffer(getDevice());
 
112
            mStaticIndexBuffer = new StaticIndexBuffer(getDevice());
 
113
        }
 
114
    }
 
115
}
 
116
 
 
117
}