blob: d492de74dc50126a12f270094c14eff5cb4bf061 [file] [log] [blame]
daniel@transgaming.com29787c32012-12-20 20:55:48 +00001//
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.comdcfb1f72012-12-20 20:57:03 +00007// VertexBuffer.h: Defines the abstract VertexBuffer class and VertexBufferInterface
8// class with derivations, classes that perform graphics API agnostic vertex buffer operations.
daniel@transgaming.com29787c32012-12-20 20:55:48 +00009
10#ifndef LIBGLESV2_RENDERER_VERTEXBUFFER_H_
11#define LIBGLESV2_RENDERER_VERTEXBUFFER_H_
12
shannon.woods@transgaming.comd2811d62013-02-28 23:11:19 +000013#include "common/angleutils.h"
14
15namespace gl
16{
Brandon Jones5bf98292014-06-06 17:19:38 -070017struct VertexAttribute;
Jamie Madilla857c362013-07-02 11:57:02 -040018struct VertexAttribCurrentValueData;
shannon.woods@transgaming.comd2811d62013-02-28 23:11:19 +000019}
daniel@transgaming.com29787c32012-12-20 20:55:48 +000020
21namespace rx
22{
shannon.woods@transgaming.comd2811d62013-02-28 23:11:19 +000023class Renderer;
daniel@transgaming.com29787c32012-12-20 20:55:48 +000024
daniel@transgaming.comdcfb1f72012-12-20 20:57:03 +000025class VertexBuffer
26{
27 public:
28 VertexBuffer();
29 virtual ~VertexBuffer();
30
31 virtual bool initialize(unsigned int size, bool dynamicUsage) = 0;
32
Jamie Madilla857c362013-07-02 11:57:02 -040033 virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
34 GLint start, GLsizei count, GLsizei instances, unsigned int offset) = 0;
Geoff Langa36ead42013-08-02 11:54:08 -040035 virtual bool getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
36 unsigned int *outSpaceRequired) const = 0;
daniel@transgaming.comdcfb1f72012-12-20 20:57:03 +000037
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.come4e45062012-12-20 20:56:53 +000054class VertexBufferInterface
daniel@transgaming.com29787c32012-12-20 20:55:48 +000055{
56 public:
daniel@transgaming.com4150d362012-12-20 21:07:43 +000057 VertexBufferInterface(rx::Renderer *renderer, bool dynamic);
daniel@transgaming.come4e45062012-12-20 20:56:53 +000058 virtual ~VertexBufferInterface();
daniel@transgaming.com29787c32012-12-20 20:55:48 +000059
Geoff Langfe5b2722013-07-09 15:58:36 -040060 bool reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances);
daniel@transgaming.coma41d07f2012-12-20 20:55:57 +000061
daniel@transgaming.com4150d362012-12-20 21:07:43 +000062 unsigned int getBufferSize() const;
daniel@transgaming.com29787c32012-12-20 20:55:48 +000063
daniel@transgaming.com29787c32012-12-20 20:55:48 +000064 unsigned int getSerial() const;
65
Geoff Langa36ead42013-08-02 11:54:08 -040066 virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
67 GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
daniel@transgaming.com4150d362012-12-20 21:07:43 +000068
Jamie Madilla5d67472014-02-04 16:04:13 -050069 bool directStoragePossible(const gl::VertexAttribute &attrib,
70 const gl::VertexAttribCurrentValueData &currentValue) const;
71
daniel@transgaming.com4150d362012-12-20 21:07:43 +000072 VertexBuffer* getVertexBuffer() const;
73
daniel@transgaming.com29787c32012-12-20 20:55:48 +000074 protected:
daniel@transgaming.com4150d362012-12-20 21:07:43 +000075 virtual bool reserveSpace(unsigned int size) = 0;
daniel@transgaming.com29787c32012-12-20 20:55:48 +000076
daniel@transgaming.com4150d362012-12-20 21:07:43 +000077 unsigned int getWritePosition() const;
78 void setWritePosition(unsigned int writePosition);
daniel@transgaming.com29787c32012-12-20 20:55:48 +000079
daniel@transgaming.com4150d362012-12-20 21:07:43 +000080 bool discard();
81
82 bool setBufferSize(unsigned int size);
daniel@transgaming.coma41d07f2012-12-20 20:55:57 +000083
84 private:
daniel@transgaming.come4e45062012-12-20 20:56:53 +000085 DISALLOW_COPY_AND_ASSIGN(VertexBufferInterface);
daniel@transgaming.com4150d362012-12-20 21:07:43 +000086
87 rx::Renderer *const mRenderer;
88
89 VertexBuffer* mVertexBuffer;
90
91 unsigned int mWritePosition;
92 unsigned int mReservedSpace;
93 bool mDynamic;
daniel@transgaming.com29787c32012-12-20 20:55:48 +000094};
95
daniel@transgaming.come4e45062012-12-20 20:56:53 +000096class StreamingVertexBufferInterface : public VertexBufferInterface
daniel@transgaming.com29787c32012-12-20 20:55:48 +000097{
98 public:
daniel@transgaming.com4150d362012-12-20 21:07:43 +000099 StreamingVertexBufferInterface(rx::Renderer *renderer, std::size_t initialSize);
daniel@transgaming.come4e45062012-12-20 20:56:53 +0000100 ~StreamingVertexBufferInterface();
daniel@transgaming.com29787c32012-12-20 20:55:48 +0000101
daniel@transgaming.com4150d362012-12-20 21:07:43 +0000102 protected:
103 bool reserveSpace(unsigned int size);
daniel@transgaming.com29787c32012-12-20 20:55:48 +0000104};
105
daniel@transgaming.come4e45062012-12-20 20:56:53 +0000106class StaticVertexBufferInterface : public VertexBufferInterface
daniel@transgaming.com29787c32012-12-20 20:55:48 +0000107{
108 public:
daniel@transgaming.com4150d362012-12-20 21:07:43 +0000109 explicit StaticVertexBufferInterface(rx::Renderer *renderer);
daniel@transgaming.come4e45062012-12-20 20:56:53 +0000110 ~StaticVertexBufferInterface();
daniel@transgaming.com29787c32012-12-20 20:55:48 +0000111
Geoff Langa36ead42013-08-02 11:54:08 -0400112 bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
113 GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
daniel@transgaming.com29787c32012-12-20 20:55:48 +0000114
Geoff Langa36ead42013-08-02 11:54:08 -0400115 bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamFffset);
daniel@transgaming.com4150d362012-12-20 21:07:43 +0000116
117 protected:
118 bool reserveSpace(unsigned int size);
daniel@transgaming.com29787c32012-12-20 20:55:48 +0000119
120 private:
121 struct VertexElement
122 {
123 GLenum type;
124 GLint size;
125 GLsizei stride;
126 bool normalized;
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +0000127 bool pureInteger;
daniel@transgaming.com29787c32012-12-20 20:55:48 +0000128 int attributeOffset;
129
daniel@transgaming.com4150d362012-12-20 21:07:43 +0000130 unsigned int streamOffset;
daniel@transgaming.com29787c32012-12-20 20:55:48 +0000131 };
132
133 std::vector<VertexElement> mCache;
134};
135
136}
137
138#endif // LIBGLESV2_RENDERER_VERTEXBUFFER_H_