1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_FILTERFW_CORE_VERTEXFRAME_H
18#define ANDROID_FILTERFW_CORE_VERTEXFRAME_H
19
20#include <GLES2/gl2.h>
21
22namespace android {
23namespace filterfw {
24
25// A VertexFrame stores vertex attribute data in a VBO. Unlike other frames,
26// you often create instances of VertexFrame yourself, to pass vertex data to
27// a ShaderProgram. Note, that any kind of reading from VertexFrames is NOT
28// supported. Once data is uploaded to a VertexFrame, it cannot be read from
29// again.
30class VertexFrame {
31  public:
32    // Create a VertexFrame of the specified size (in bytes).
33    explicit VertexFrame(int size);
34
35    ~VertexFrame();
36
37    // Upload the given data to the vertex buffer. The size must match the size
38    // passed in the constructor for the first upload. Subsequent uploads must
39    // be able to fit within the allocated space (i.e. size must not exceed the
40    // frame's size).
41    bool WriteData(const uint8_t* data, int size);
42
43    // The size of the vertex buffer in bytes.
44    int Size() const;
45
46    // Return the id of the internal VBO. Returns 0 if no VBO has been
47    // generated yet. The internal VBO is generated the first time data is
48    // uploaded.
49    GLuint GetVboId() const {
50      return vbo_;
51    }
52
53    // Returns true if the frame contains an allocated VBO.
54    bool HasBuffer() const {
55      return vbo_ != 0;
56    }
57
58  private:
59    // Create the VBO
60    bool CreateBuffer();
61
62    // Returns true if the VBO has been created.
63    bool HasVBO() const {
64      return vbo_ != 0;
65    }
66
67    // The internal VBO handle
68    GLuint vbo_;
69
70    // The size of this frame in bytes
71    int size_;
72};
73
74} // namespace filterfw
75} // namespace android
76
77#endif  // ANDROID_FILTERFW_CORE_VERTEXFRAME_H
78