• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/GLESpointer.h"
17 
18 #include <stdlib.h>
19 #include <string.h>
20 
getType() const21 GLenum GLESpointer::getType() const {
22     return m_type;
23 }
24 
getSize() const25 GLint GLESpointer::getSize() const {
26     return m_size;
27 }
28 
getStride() const29 GLsizei GLESpointer::getStride() const {
30     return m_stride;
31 }
32 
getArrayData() const33 const GLvoid* GLESpointer::getArrayData() const {
34     return m_data;
35 }
36 
getBufferData() const37 GLvoid* GLESpointer::getBufferData() const {
38     return m_buffer
39                    ? static_cast<unsigned char*>(m_buffer->getData()) +
40                              m_buffOffset
41                    : nullptr;
42 }
43 
getValues() const44 const GLfloat* GLESpointer::getValues() const {
45     return m_values;
46 }
47 
getValueCount() const48 unsigned int GLESpointer::getValueCount() const {
49     return m_valueCount;
50 }
51 
getData() const52 const GLvoid* GLESpointer::getData() const {
53     switch (m_attribType) {
54         case ARRAY:
55             return getArrayData();
56             break;
57         case BUFFER:
58             return getBufferData();
59             break;
60         case VALUE:
61             return (GLvoid*)getValues();
62             break;
63     }
64     return nullptr;
65 }
66 
redirectPointerData()67 void GLESpointer::redirectPointerData() {
68     m_ownData.resize(0);
69     m_data = getBufferData();
70 }
71 
getBufferName() const72 GLuint GLESpointer::getBufferName() const {
73     return m_bufferName;
74 }
75 
getBufferOffset() const76 unsigned int GLESpointer::getBufferOffset() const {
77     return m_buffOffset;
78 }
79 
isEnable() const80 bool GLESpointer::isEnable() const {
81     return m_enabled;
82 }
83 
isNormalize() const84 bool GLESpointer::isNormalize() const {
85     return m_normalize;
86 }
87 
getAttribType() const88 GLESpointer::AttribType GLESpointer::getAttribType() const {
89     return m_attribType;
90 }
91 
isIntPointer() const92 bool GLESpointer::isIntPointer() const {
93     return m_isInt;
94 }
95 
enable(bool b)96 void GLESpointer::enable(bool b) {
97     m_enabled = b;
98 }
99 
setArray(GLint size,GLenum type,GLsizei stride,const GLvoid * data,GLsizei dataSize,bool normalize,bool isInt)100 void GLESpointer::setArray(GLint size,
101                            GLenum type,
102                            GLsizei stride,
103                            const GLvoid* data,
104                            GLsizei dataSize,
105                            bool normalize,
106                            bool isInt) {
107     m_ownData.clear();
108     m_size = size;
109     m_type = type;
110     m_stride = stride;
111     m_dataSize = dataSize;
112     m_data = data;
113     m_buffer = nullptr;
114     m_bufferName = 0;
115     m_buffOffset = 0;
116     m_normalize = normalize;
117     m_attribType = ARRAY;
118     m_isInt = isInt;
119 }
120 
setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer * buf,GLuint bufferName,int offset,bool normalize,bool isInt)121 void GLESpointer::setBuffer(GLint size,
122                             GLenum type,
123                             GLsizei stride,
124                             GLESbuffer* buf,
125                             GLuint bufferName,
126                             int offset,
127                             bool normalize,
128                             bool isInt) {
129     m_ownData.clear();
130     m_size = size;
131     m_type = type;
132     m_stride = stride;
133     m_dataSize = 0;
134     m_data = nullptr;
135     m_buffer = buf;
136     m_bufferName = bufferName;
137     m_buffOffset = offset;
138     m_normalize = normalize;
139     m_attribType = BUFFER;
140     m_isInt = isInt;
141 }
142 
setValue(unsigned int count,const GLfloat * val)143 void GLESpointer::setValue(unsigned int count, const GLfloat* val) {
144     memcpy(m_values, val, sizeof(GLfloat) * count);
145     m_valueCount = count;
146     m_attribType = VALUE;
147     m_data = nullptr;
148     m_buffer = nullptr;
149 }
150 
setDivisor(GLuint divisor)151 void GLESpointer::setDivisor(GLuint divisor) {
152     m_divisor = divisor;
153 }
154 
setBindingIndex(GLuint index)155 void GLESpointer::setBindingIndex(GLuint index) {
156     m_bindingIndex = index;
157 }
158 
setFormat(GLint size,GLenum type,bool normalize,GLuint reloffset,bool isInt)159 void GLESpointer::setFormat(GLint size, GLenum type,
160                             bool normalize,
161                             GLuint reloffset,
162                             bool isInt) {
163     m_size = size;
164     m_type = type;
165     m_normalize = normalize;
166     m_reloffset = reloffset;
167     m_isInt = isInt;
168 }
169 
getBufferConversions(const RangeList & rl,RangeList & rlOut)170 void GLESpointer::getBufferConversions(const RangeList& rl, RangeList& rlOut) {
171     m_buffer->getConversions(rl, rlOut);
172 }
173 
GLESpointer(android::base::Stream * stream)174 GLESpointer::GLESpointer(android::base::Stream* stream) {
175     onLoad(stream);
176 }
177 
restoreBufferObj(std::function<GLESbuffer * (GLuint)> getBufferObj)178 void GLESpointer::restoreBufferObj(
179         std::function<GLESbuffer*(GLuint)> getBufferObj) {
180     if (m_attribType != BUFFER) return;
181     m_buffer = getBufferObj(m_bufferName);
182 }
183 
onLoad(android::base::Stream * stream)184 void GLESpointer::onLoad(android::base::Stream* stream) {
185     m_size = stream->getBe32();
186     m_type = stream->getBe32();
187     m_stride = stream->getBe32();
188     m_enabled = stream->getByte();
189     m_normalize = stream->getByte();
190     m_attribType = (GLESpointer::AttribType)stream->getByte();
191     m_bufferName = stream->getBe32();
192     if (m_attribType == ARRAY) {
193         m_dataSize = stream->getBe32();
194         m_ownData.resize(m_dataSize);
195         stream->read(m_ownData.data(), m_dataSize);
196         m_data = m_ownData.data();
197     }
198     m_buffOffset = stream->getBe32();
199     m_isInt = stream->getByte();
200     m_divisor = stream->getBe32();
201     m_bindingIndex = stream->getBe32();
202     m_reloffset = stream->getBe32();
203     m_valueCount = stream->getBe32();
204     stream->read(m_values, sizeof(GLfloat) * m_valueCount);
205 }
206 
onSave(android::base::Stream * stream) const207 void GLESpointer::onSave(android::base::Stream* stream) const {
208     stream->putBe32(m_size);
209     stream->putBe32(m_type);
210     stream->putBe32(m_stride);
211     stream->putByte(m_enabled);
212     stream->putByte(m_normalize);
213     stream->putByte(m_attribType);
214     stream->putBe32(m_bufferName);
215     if (m_attribType == ARRAY) {
216         stream->putBe32(m_dataSize);
217         stream->write(m_data, m_dataSize);
218     }
219     stream->putBe32(m_buffOffset);
220     stream->putByte(m_isInt);
221     stream->putBe32(m_divisor);
222     stream->putBe32(m_bindingIndex);
223     stream->putBe32(m_reloffset);
224     stream->putBe32(m_valueCount);
225     stream->write(m_values, sizeof(GLfloat) * m_valueCount);
226 }
227