1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/libGLESv2/renderer/VertexBuffer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,139 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +// VertexBuffer.h: Defines the abstract VertexBuffer class and VertexBufferInterface 1.11 +// class with derivations, classes that perform graphics API agnostic vertex buffer operations. 1.12 + 1.13 +#ifndef LIBGLESV2_RENDERER_VERTEXBUFFER_H_ 1.14 +#define LIBGLESV2_RENDERER_VERTEXBUFFER_H_ 1.15 + 1.16 +#include "common/angleutils.h" 1.17 + 1.18 +namespace gl 1.19 +{ 1.20 +class VertexAttribute; 1.21 +} 1.22 + 1.23 +namespace rx 1.24 +{ 1.25 +class Renderer; 1.26 + 1.27 +class VertexBuffer 1.28 +{ 1.29 + public: 1.30 + VertexBuffer(); 1.31 + virtual ~VertexBuffer(); 1.32 + 1.33 + virtual bool initialize(unsigned int size, bool dynamicUsage) = 0; 1.34 + 1.35 + virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, 1.36 + GLsizei instances, unsigned int offset) = 0; 1.37 + virtual bool storeRawData(const void* data, unsigned int size, unsigned int offset) = 0; 1.38 + 1.39 + virtual bool getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, 1.40 + unsigned int *outSpaceRequired) const = 0; 1.41 + 1.42 + virtual bool requiresConversion(const gl::VertexAttribute &attrib) const = 0; 1.43 + 1.44 + virtual unsigned int getBufferSize() const = 0; 1.45 + virtual bool setBufferSize(unsigned int size) = 0; 1.46 + virtual bool discard() = 0; 1.47 + 1.48 + unsigned int getSerial() const; 1.49 + 1.50 + protected: 1.51 + void updateSerial(); 1.52 + 1.53 + private: 1.54 + DISALLOW_COPY_AND_ASSIGN(VertexBuffer); 1.55 + 1.56 + unsigned int mSerial; 1.57 + static unsigned int mNextSerial; 1.58 +}; 1.59 + 1.60 +class VertexBufferInterface 1.61 +{ 1.62 + public: 1.63 + VertexBufferInterface(rx::Renderer *renderer, bool dynamic); 1.64 + virtual ~VertexBufferInterface(); 1.65 + 1.66 + bool reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances); 1.67 + bool reserveRawDataSpace(unsigned int size); 1.68 + 1.69 + unsigned int getBufferSize() const; 1.70 + 1.71 + unsigned int getSerial() const; 1.72 + 1.73 + virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances, 1.74 + unsigned int *outStreamOffset); 1.75 + virtual bool storeRawData(const void* data, unsigned int size, unsigned int *outStreamOffset); 1.76 + 1.77 + VertexBuffer* getVertexBuffer() const; 1.78 + 1.79 + protected: 1.80 + virtual bool reserveSpace(unsigned int size) = 0; 1.81 + 1.82 + unsigned int getWritePosition() const; 1.83 + void setWritePosition(unsigned int writePosition); 1.84 + 1.85 + bool discard(); 1.86 + 1.87 + bool setBufferSize(unsigned int size); 1.88 + 1.89 + private: 1.90 + DISALLOW_COPY_AND_ASSIGN(VertexBufferInterface); 1.91 + 1.92 + rx::Renderer *const mRenderer; 1.93 + 1.94 + VertexBuffer* mVertexBuffer; 1.95 + 1.96 + unsigned int mWritePosition; 1.97 + unsigned int mReservedSpace; 1.98 + bool mDynamic; 1.99 +}; 1.100 + 1.101 +class StreamingVertexBufferInterface : public VertexBufferInterface 1.102 +{ 1.103 + public: 1.104 + StreamingVertexBufferInterface(rx::Renderer *renderer, std::size_t initialSize); 1.105 + ~StreamingVertexBufferInterface(); 1.106 + 1.107 + protected: 1.108 + bool reserveSpace(unsigned int size); 1.109 +}; 1.110 + 1.111 +class StaticVertexBufferInterface : public VertexBufferInterface 1.112 +{ 1.113 + public: 1.114 + explicit StaticVertexBufferInterface(rx::Renderer *renderer); 1.115 + ~StaticVertexBufferInterface(); 1.116 + 1.117 + bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances, 1.118 + unsigned int *outStreamOffset); 1.119 + 1.120 + bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamOffset); 1.121 + 1.122 + protected: 1.123 + bool reserveSpace(unsigned int size); 1.124 + 1.125 + private: 1.126 + struct VertexElement 1.127 + { 1.128 + GLenum type; 1.129 + GLint size; 1.130 + GLsizei stride; 1.131 + bool normalized; 1.132 + int attributeOffset; 1.133 + 1.134 + unsigned int streamOffset; 1.135 + }; 1.136 + 1.137 + std::vector<VertexElement> mCache; 1.138 +}; 1.139 + 1.140 +} 1.141 + 1.142 +#endif // LIBGLESV2_RENDERER_VERTEXBUFFER_H_ 1.143 \ No newline at end of file