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