d5b07ec0e88e0f32edcc067d8139f6850591fb24
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / client / vertex_array_object_manager.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef GPU_COMMAND_BUFFER_CLIENT_VERTEX_ARRAY_OBJECT_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_VERTEX_ARRAY_OBJECT_MANAGER_H_
7
8 #include <GLES2/gl2.h>
9 #include "base/containers/hash_tables.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "gles2_impl_export.h"
12 #include "gpu/command_buffer/common/types.h"
13
14 namespace gpu {
15 namespace gles2 {
16
17 class GLES2Implementation;
18 class GLES2CmdHelper;
19 class VertexArrayObject;
20
21 // VertexArrayObjectManager manages vertex array objects on the client side
22 // of the command buffer.
23 class GLES2_IMPL_EXPORT VertexArrayObjectManager {
24  public:
25   VertexArrayObjectManager(
26       GLuint max_vertex_attribs,
27       GLuint array_buffer_id,
28       GLuint element_array_buffer_id);
29   ~VertexArrayObjectManager();
30
31   bool IsReservedId(GLuint id) const;
32
33   // Binds an element array.
34   // Returns true if service should be called.
35   bool BindElementArray(GLuint id);
36
37   // Unbind buffer.
38   void UnbindBuffer(GLuint id);
39
40   // Geneates array objects for the given ids.
41   void GenVertexArrays(GLsizei n, const GLuint* arrays);
42
43   // Deletes array objects for the given ids.
44   void DeleteVertexArrays(GLsizei n, const GLuint* arrays);
45
46   // Binds a vertex array.
47   // changed will be set to true if the service should be called.
48   // Returns false if array is an unknown id.
49   bool BindVertexArray(GLuint array, bool* changed);
50
51   // simulated will be set to true if buffers were simulated.
52   // Returns true service should be called.
53   bool SetupSimulatedClientSideBuffers(
54       const char* function_name,
55       GLES2Implementation* gl,
56       GLES2CmdHelper* gl_helper,
57       GLsizei num_elements,
58       GLsizei primcount,
59       bool* simulated);
60
61   // Returns true if buffers were setup.
62   bool SetupSimulatedIndexAndClientSideBuffers(
63       const char* function_name,
64       GLES2Implementation* gl,
65       GLES2CmdHelper* gl_helper,
66       GLsizei count,
67       GLenum type,
68       GLsizei primcount,
69       const void* indices,
70       GLuint* offset,
71       bool* simulated);
72
73   bool HaveEnabledClientSideBuffers() const;
74
75   void SetAttribEnable(GLuint index, bool enabled);
76
77   bool GetVertexAttrib(GLuint index, GLenum pname, uint32* param);
78
79   bool GetAttribPointer(GLuint index, GLenum pname, void** ptr) const;
80
81   // Returns false if error.
82   bool SetAttribPointer(
83       GLuint buffer_id,
84       GLuint index,
85       GLint size,
86       GLenum type,
87       GLboolean normalized,
88       GLsizei stride,
89       const void* ptr);
90
91   void SetAttribDivisor(GLuint index, GLuint divisor);
92
93   GLuint bound_element_array_buffer() const;
94
95  private:
96   typedef base::hash_map<GLuint, VertexArrayObject*> VertexArrayObjectMap;
97
98   bool IsDefaultVAOBound() const;
99
100   GLsizei CollectData(const void* data,
101                       GLsizei bytes_per_element,
102                       GLsizei real_stride,
103                       GLsizei num_elements);
104
105   GLuint max_vertex_attribs_;
106   GLuint array_buffer_id_;
107   GLsizei array_buffer_size_;
108   GLsizei array_buffer_offset_;
109   GLuint element_array_buffer_id_;
110   GLsizei element_array_buffer_size_;
111   GLsizei collection_buffer_size_;
112   scoped_ptr<int8[]> collection_buffer_;
113
114   VertexArrayObject* default_vertex_array_object_;
115   VertexArrayObject* bound_vertex_array_object_;
116   VertexArrayObjectMap vertex_array_objects_;
117
118   DISALLOW_COPY_AND_ASSIGN(VertexArrayObjectManager);
119 };
120
121 }  // namespace gles2
122 }  // namespace gpu
123
124 #endif  // GPU_COMMAND_BUFFER_CLIENT_VERTEX_ARRAY_OBJECT_MANAGER_H_
125