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 #ifndef GLES_POINTER_H 17 #define GLES_POINTER_H 18 19 #include "aemu/base/files/Stream.h" 20 #include <GLES/gl.h> 21 #include "GLESbuffer.h" 22 23 #include <functional> 24 #include <vector> 25 26 class GLESpointer { 27 public: 28 enum AttribType { 29 ARRAY, BUFFER, VALUE 30 }; 31 GLESpointer() = default; 32 GLESpointer(android::base::Stream* stream); 33 void onLoad(android::base::Stream* stream); 34 GLenum getType() const; 35 GLint getSize() const; 36 GLsizei getStride() const; 37 // get*Data, getBufferName all only for legacy (GLES_CM or buffer->client array converseion) setups. 38 const GLvoid* getArrayData() const; 39 GLvoid* getBufferData() const; 40 const GLfloat* getValues() const; 41 unsigned int getValueCount() const; 42 GLuint getBufferName() const; getNormalized()43 GLboolean getNormalized() const { return m_normalize ? GL_TRUE : GL_FALSE; } 44 const GLvoid* getData() const; getDataSize()45 const GLsizei getDataSize() const { return m_dataSize; } 46 unsigned int getBufferOffset() const; 47 void redirectPointerData(); 48 void getBufferConversions(const RangeList& rl, RangeList& rlOut); bufferNeedConversion()49 bool bufferNeedConversion() { return !m_buffer->fullyConverted(); } 50 void setArray(GLint size, 51 GLenum type, 52 GLsizei stride, 53 const GLvoid* data, 54 GLsizei dataSize, 55 bool normalize = false, 56 bool isInt = false); 57 void setBuffer(GLint size, 58 GLenum type, 59 GLsizei stride, 60 GLESbuffer* buf, 61 GLuint bufferName, 62 int offset, 63 bool normalize = false, 64 bool isInt = false); 65 // setValue is used when glVertexAttrib*f(v) is called 66 void setValue(unsigned int count, const GLfloat* val); 67 void setDivisor(GLuint divisor); 68 void setBindingIndex(GLuint bindingindex); 69 void setFormat(GLint size, GLenum type, 70 bool normalize, 71 GLuint reloffset, 72 bool isInt); getBindingIndex()73 GLuint getBindingIndex() const { 74 return m_bindingIndex; 75 } 76 bool isEnable() const; 77 bool isNormalize() const; 78 AttribType getAttribType() const; 79 bool isIntPointer() const; 80 void enable(bool b); 81 void onSave(android::base::Stream* stream) const; 82 void restoreBufferObj(std::function<GLESbuffer*(GLuint)> getBufferObj); 83 private: 84 GLint m_size = 4; 85 GLenum m_type = GL_FLOAT; 86 GLsizei m_stride = 0; 87 bool m_enabled = false; 88 bool m_normalize = false; 89 AttribType m_attribType = ARRAY; 90 GLsizei m_dataSize = 0; 91 const GLvoid* m_data = nullptr; 92 GLESbuffer* m_buffer = nullptr; 93 GLuint m_bufferName = 0; 94 unsigned int m_buffOffset = 0; 95 bool m_isInt = false; 96 GLuint m_divisor = 0; 97 GLuint m_bindingIndex = 0; 98 GLuint m_reloffset = 0; 99 // m_ownData is only used when loading from a snapshot 100 std::vector<unsigned char> m_ownData; 101 GLsizei m_valueCount = 0; 102 GLfloat m_values[4]; 103 }; 104 #endif 105