1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <GLcommon/GLESbuffer.h>
17 #include <string.h>
18 
setBuffer(GLuint size,GLuint usage,const GLvoid * data)19 bool  GLESbuffer::setBuffer(GLuint size,GLuint usage,const GLvoid* data) {
20     m_size = size;
21     m_usage = usage;
22     if(m_data) {
23         delete [] m_data;
24         m_data = NULL;
25     }
26     m_data = new unsigned char[size];
27     if(m_data) {
28         if(data) {
29             memcpy(m_data,data,size);
30         }
31         m_conversionManager.clear();
32         m_conversionManager.addRange(Range(0,m_size));
33         return true;
34     }
35     return false;
36 }
37 
setSubBuffer(GLint offset,GLuint size,const GLvoid * data)38 bool  GLESbuffer::setSubBuffer(GLint offset,GLuint size,const GLvoid* data) {
39     if(offset + size > m_size) return false;
40     memcpy(m_data+offset,data,size);
41     m_conversionManager.addRange(Range(offset,size));
42     m_conversionManager.merge();
43     return true;
44 }
45 
getConversions(const RangeList & rIn,RangeList & rOut)46 void  GLESbuffer::getConversions(const RangeList& rIn,RangeList& rOut) {
47         m_conversionManager.delRanges(rIn,rOut);
48         rOut.merge();
49 }
50 
~GLESbuffer()51 GLESbuffer::~GLESbuffer() {
52     if(m_data) {
53         delete [] m_data;
54     }
55 }
56