daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
daniel@transgaming.com | dcfb1f7 | 2012-12-20 20:57:03 +0000 | [diff] [blame] | 7 | // VertexBuffer.h: Defines the abstract VertexBuffer class and VertexBufferInterface |
| 8 | // class with derivations, classes that perform graphics API agnostic vertex buffer operations. |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 9 | |
| 10 | #ifndef LIBGLESV2_RENDERER_VERTEXBUFFER_H_ |
| 11 | #define LIBGLESV2_RENDERER_VERTEXBUFFER_H_ |
| 12 | |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 13 | #include "common/angleutils.h" |
| 14 | |
| 15 | namespace gl |
| 16 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame^] | 17 | struct VertexAttribute; |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 18 | struct VertexAttribCurrentValueData; |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 19 | } |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 20 | |
| 21 | namespace rx |
| 22 | { |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 23 | class Renderer; |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 24 | |
daniel@transgaming.com | dcfb1f7 | 2012-12-20 20:57:03 +0000 | [diff] [blame] | 25 | class VertexBuffer |
| 26 | { |
| 27 | public: |
| 28 | VertexBuffer(); |
| 29 | virtual ~VertexBuffer(); |
| 30 | |
| 31 | virtual bool initialize(unsigned int size, bool dynamicUsage) = 0; |
| 32 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 33 | virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData ¤tValue, |
| 34 | GLint start, GLsizei count, GLsizei instances, unsigned int offset) = 0; |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 35 | virtual bool getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, |
| 36 | unsigned int *outSpaceRequired) const = 0; |
daniel@transgaming.com | dcfb1f7 | 2012-12-20 20:57:03 +0000 | [diff] [blame] | 37 | |
| 38 | virtual unsigned int getBufferSize() const = 0; |
| 39 | virtual bool setBufferSize(unsigned int size) = 0; |
| 40 | virtual bool discard() = 0; |
| 41 | |
| 42 | unsigned int getSerial() const; |
| 43 | |
| 44 | protected: |
| 45 | void updateSerial(); |
| 46 | |
| 47 | private: |
| 48 | DISALLOW_COPY_AND_ASSIGN(VertexBuffer); |
| 49 | |
| 50 | unsigned int mSerial; |
| 51 | static unsigned int mNextSerial; |
| 52 | }; |
| 53 | |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 54 | class VertexBufferInterface |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 55 | { |
| 56 | public: |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 57 | VertexBufferInterface(rx::Renderer *renderer, bool dynamic); |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 58 | virtual ~VertexBufferInterface(); |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 59 | |
Geoff Lang | fe5b272 | 2013-07-09 15:58:36 -0400 | [diff] [blame] | 60 | bool reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances); |
daniel@transgaming.com | a41d07f | 2012-12-20 20:55:57 +0000 | [diff] [blame] | 61 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 62 | unsigned int getBufferSize() const; |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 63 | |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 64 | unsigned int getSerial() const; |
| 65 | |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 66 | virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData ¤tValue, |
| 67 | GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset); |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 68 | |
Jamie Madill | a5d6747 | 2014-02-04 16:04:13 -0500 | [diff] [blame] | 69 | bool directStoragePossible(const gl::VertexAttribute &attrib, |
| 70 | const gl::VertexAttribCurrentValueData ¤tValue) const; |
| 71 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 72 | VertexBuffer* getVertexBuffer() const; |
| 73 | |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 74 | protected: |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 75 | virtual bool reserveSpace(unsigned int size) = 0; |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 76 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 77 | unsigned int getWritePosition() const; |
| 78 | void setWritePosition(unsigned int writePosition); |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 79 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 80 | bool discard(); |
| 81 | |
| 82 | bool setBufferSize(unsigned int size); |
daniel@transgaming.com | a41d07f | 2012-12-20 20:55:57 +0000 | [diff] [blame] | 83 | |
| 84 | private: |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(VertexBufferInterface); |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 86 | |
| 87 | rx::Renderer *const mRenderer; |
| 88 | |
| 89 | VertexBuffer* mVertexBuffer; |
| 90 | |
| 91 | unsigned int mWritePosition; |
| 92 | unsigned int mReservedSpace; |
| 93 | bool mDynamic; |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 96 | class StreamingVertexBufferInterface : public VertexBufferInterface |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 97 | { |
| 98 | public: |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 99 | StreamingVertexBufferInterface(rx::Renderer *renderer, std::size_t initialSize); |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 100 | ~StreamingVertexBufferInterface(); |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 101 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 102 | protected: |
| 103 | bool reserveSpace(unsigned int size); |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 106 | class StaticVertexBufferInterface : public VertexBufferInterface |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 107 | { |
| 108 | public: |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 109 | explicit StaticVertexBufferInterface(rx::Renderer *renderer); |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 110 | ~StaticVertexBufferInterface(); |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 111 | |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 112 | bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData ¤tValue, |
| 113 | GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset); |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 114 | |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 115 | bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamFffset); |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 116 | |
| 117 | protected: |
| 118 | bool reserveSpace(unsigned int size); |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 119 | |
| 120 | private: |
| 121 | struct VertexElement |
| 122 | { |
| 123 | GLenum type; |
| 124 | GLint size; |
| 125 | GLsizei stride; |
| 126 | bool normalized; |
shannon.woods%transgaming.com@gtempaccount.com | 8de4e6a | 2013-04-13 03:37:44 +0000 | [diff] [blame] | 127 | bool pureInteger; |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 128 | int attributeOffset; |
| 129 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 130 | unsigned int streamOffset; |
daniel@transgaming.com | 29787c3 | 2012-12-20 20:55:48 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | std::vector<VertexElement> mCache; |
| 134 | }; |
| 135 | |
| 136 | } |
| 137 | |
| 138 | #endif // LIBGLESV2_RENDERER_VERTEXBUFFER_H_ |