1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // VertexDataManager.h: Defines the VertexDataManager, a class that 16 // runs the Buffer translation process. 17 18 #ifndef LIBGLESV2_VERTEXDATAMANAGER_H_ 19 #define LIBGLESV2_VERTEXDATAMANAGER_H_ 20 21 #include "Context.h" 22 #include "Device.hpp" 23 24 #include <GLES2/gl2.h> 25 26 namespace es2 27 { 28 29 struct TranslatedAttribute 30 { 31 sw::StreamType type; 32 int count; 33 bool normalized; 34 35 unsigned int offset; 36 unsigned int stride; // 0 means not to advance the read pointer at all 37 38 sw::Resource *vertexBuffer; 39 }; 40 41 class VertexBuffer 42 { 43 public: 44 VertexBuffer(unsigned int size); 45 virtual ~VertexBuffer(); 46 47 void unmap(); 48 49 sw::Resource *getResource() const; 50 51 protected: 52 sw::Resource *mVertexBuffer; 53 }; 54 55 class ConstantVertexBuffer : public VertexBuffer 56 { 57 public: 58 ConstantVertexBuffer(float x, float y, float z, float w); 59 ~ConstantVertexBuffer(); 60 }; 61 62 class StreamingVertexBuffer : public VertexBuffer 63 { 64 public: 65 StreamingVertexBuffer(unsigned int size); 66 ~StreamingVertexBuffer(); 67 68 void *map(const VertexAttribute &attribute, unsigned int requiredSpace, unsigned int *streamOffset); 69 void reserveRequiredSpace(); 70 void addRequiredSpace(unsigned int requiredSpace); 71 72 protected: 73 unsigned int mBufferSize; 74 unsigned int mWritePosition; 75 unsigned int mRequiredSpace; 76 }; 77 78 class VertexDataManager 79 { 80 public: 81 VertexDataManager(Context *context); 82 virtual ~VertexDataManager(); 83 84 void dirtyCurrentValue(int index) { mDirtyCurrentValue[index] = true; } 85 86 GLenum prepareVertexData(GLint start, GLsizei count, TranslatedAttribute *outAttribs, GLsizei instanceId); 87 88 private: 89 unsigned int writeAttributeData(StreamingVertexBuffer *vertexBuffer, GLint start, GLsizei count, const VertexAttribute &attribute); 90 91 Context *const mContext; 92 93 StreamingVertexBuffer *mStreamingBuffer; 94 95 bool mDirtyCurrentValue[MAX_VERTEX_ATTRIBS]; 96 ConstantVertexBuffer *mCurrentValueBuffer[MAX_VERTEX_ATTRIBS]; 97 }; 98 99 } 100 101 #endif // LIBGLESV2_VERTEXDATAMANAGER_H_ 102