Hash :
f7100b98
Author :
Date :
2014-09-08T16:17:08
Updated the vertex buffer classes to use Error objects. BUG=angle:520 Change-Id: Id003e66b2acbf37dbbe66aaca2fa336c3c884be2 Reviewed-on: https://chromium-review.googlesource.com/217102 Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// VertexBuffer.h: Defines the abstract VertexBuffer class and VertexBufferInterface
// class with derivations, classes that perform graphics API agnostic vertex buffer operations.
#ifndef LIBGLESV2_RENDERER_VERTEXBUFFER_H_
#define LIBGLESV2_RENDERER_VERTEXBUFFER_H_
#include "common/angleutils.h"
#include "libGLESv2/Error.h"
#include <GLES2/gl2.h>
#include <cstddef>
#include <vector>
namespace gl
{
struct VertexAttribute;
struct VertexAttribCurrentValueData;
}
namespace rx
{
class Renderer;
class VertexBuffer
{
public:
VertexBuffer();
virtual ~VertexBuffer();
virtual gl::Error initialize(unsigned int size, bool dynamicUsage) = 0;
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData ¤tValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset) = 0;
virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
unsigned int *outSpaceRequired) const = 0;
virtual unsigned int getBufferSize() const = 0;
virtual gl::Error setBufferSize(unsigned int size) = 0;
virtual gl::Error discard() = 0;
unsigned int getSerial() const;
protected:
void updateSerial();
private:
DISALLOW_COPY_AND_ASSIGN(VertexBuffer);
unsigned int mSerial;
static unsigned int mNextSerial;
};
class VertexBufferInterface
{
public:
VertexBufferInterface(rx::Renderer *renderer, bool dynamic);
virtual ~VertexBufferInterface();
gl::Error reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances);
unsigned int getBufferSize() const;
unsigned int getSerial() const;
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData ¤tValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
bool directStoragePossible(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData ¤tValue) const;
VertexBuffer* getVertexBuffer() const;
protected:
virtual gl::Error reserveSpace(unsigned int size) = 0;
unsigned int getWritePosition() const;
void setWritePosition(unsigned int writePosition);
gl::Error discard();
gl::Error setBufferSize(unsigned int size);
private:
DISALLOW_COPY_AND_ASSIGN(VertexBufferInterface);
rx::Renderer *const mRenderer;
VertexBuffer* mVertexBuffer;
unsigned int mWritePosition;
unsigned int mReservedSpace;
bool mDynamic;
};
class StreamingVertexBufferInterface : public VertexBufferInterface
{
public:
StreamingVertexBufferInterface(rx::Renderer *renderer, std::size_t initialSize);
~StreamingVertexBufferInterface();
protected:
gl::Error reserveSpace(unsigned int size);
};
class StaticVertexBufferInterface : public VertexBufferInterface
{
public:
explicit StaticVertexBufferInterface(rx::Renderer *renderer);
~StaticVertexBufferInterface();
gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData ¤tValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamFffset);
protected:
gl::Error reserveSpace(unsigned int size);
private:
struct VertexElement
{
GLenum type;
GLuint size;
GLuint stride;
bool normalized;
bool pureInteger;
size_t attributeOffset;
unsigned int streamOffset;
};
std::vector<VertexElement> mCache;
};
}
#endif // LIBGLESV2_RENDERER_VERTEXBUFFER_H_