1//
2// Copyright (c) 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
7// VertexBuffer11.h: Defines the D3D11 VertexBuffer implementation.
8
9#ifndef LIBGLESV2_RENDERER_VERTEXBUFFER11_H_
10#define LIBGLESV2_RENDERER_VERTEXBUFFER11_H_
11
12#include "libGLESv2/renderer/VertexBuffer.h"
13
14namespace rx
15{
16class Renderer11;
17
18class VertexBuffer11 : public VertexBuffer
19{
20  public:
21    explicit VertexBuffer11(rx::Renderer11 *const renderer);
22    virtual ~VertexBuffer11();
23
24    virtual bool initialize(unsigned int size, bool dynamicUsage);
25
26    static VertexBuffer11 *makeVertexBuffer11(VertexBuffer *vetexBuffer);
27
28    virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances,
29                                       unsigned int offset);
30    virtual bool storeRawData(const void* data, unsigned int size, unsigned int offset);
31
32    virtual bool getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
33                                  unsigned int *outSpaceRequired) const;
34
35    virtual bool requiresConversion(const gl::VertexAttribute &attrib) const;
36
37    virtual unsigned int getBufferSize() const;
38    virtual bool setBufferSize(unsigned int size);
39    virtual bool discard();
40
41    unsigned int getVertexSize(const gl::VertexAttribute &attrib) const;
42    DXGI_FORMAT getDXGIFormat(const gl::VertexAttribute &attrib) const;
43
44    ID3D11Buffer *getBuffer() const;
45
46  private:
47    DISALLOW_COPY_AND_ASSIGN(VertexBuffer11);
48
49    rx::Renderer11 *const mRenderer;
50
51    ID3D11Buffer *mBuffer;
52    unsigned int mBufferSize;
53    bool mDynamicUsage;
54
55    typedef void (*VertexConversionFunction)(const void *, unsigned int, unsigned int, void *);
56    struct VertexConverter
57    {
58        VertexConversionFunction conversionFunc;
59        bool identity;
60        DXGI_FORMAT dxgiFormat;
61        unsigned int outputElementSize;
62    };
63
64    enum { NUM_GL_VERTEX_ATTRIB_TYPES = 6 };
65
66    // This table is used to generate mAttributeTypes.
67    static const VertexConverter mPossibleTranslations[NUM_GL_VERTEX_ATTRIB_TYPES][2][4]; // [GL types as enumerated by typeIndex()][normalized][size - 1]
68
69    static const VertexConverter &getVertexConversion(const gl::VertexAttribute &attribute);
70};
71
72}
73
74#endif // LIBGLESV2_RENDERER_VERTEXBUFFER11_H_
75