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