| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ |
| 7 | 7 |
| 8 #include <GLES2/gl2.h> | 8 #include <GLES2/gl2.h> |
| 9 |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/synchronization/lock.h" |
| 9 #include "gles2_impl_export.h" | 15 #include "gles2_impl_export.h" |
| 16 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 10 | 17 |
| 11 namespace gpu { | 18 namespace gpu { |
| 12 namespace gles2 { | 19 namespace gles2 { |
| 13 | 20 |
| 14 class GLES2Implementation; | |
| 15 | |
| 16 // Manages info about OpenGL ES Programs. | 21 // Manages info about OpenGL ES Programs. |
| 17 class GLES2_IMPL_EXPORT ProgramInfoManager { | 22 class GLES2_IMPL_EXPORT ProgramInfoManager { |
| 18 public: | 23 public: |
| 19 virtual ~ProgramInfoManager(); | 24 ProgramInfoManager(); |
| 25 ~ProgramInfoManager(); |
| 20 | 26 |
| 21 static ProgramInfoManager* Create(bool shared_resources_across_processes); | 27 void CreateInfo(GLuint program); |
| 22 | 28 |
| 23 virtual void CreateInfo(GLuint program) = 0; | 29 void DeleteInfo(GLuint program); |
| 24 | 30 |
| 25 virtual void DeleteInfo(GLuint program) = 0; | 31 bool GetProgramiv( |
| 32 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params); |
| 26 | 33 |
| 27 virtual bool GetProgramiv( | 34 GLint GetAttribLocation( |
| 28 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) = 0; | 35 GLES2Implementation* gl, GLuint program, const char* name); |
| 29 | 36 |
| 30 virtual GLint GetAttribLocation( | 37 GLint GetUniformLocation( |
| 31 GLES2Implementation* gl, GLuint program, const char* name) = 0; | 38 GLES2Implementation* gl, GLuint program, const char* name); |
| 32 | 39 |
| 33 virtual GLint GetUniformLocation( | 40 GLint GetFragDataLocation( |
| 34 GLES2Implementation* gl, GLuint program, const char* name) = 0; | 41 GLES2Implementation* gl, GLuint program, const char* name); |
| 35 | 42 |
| 36 virtual GLint GetFragDataLocation( | 43 bool GetActiveAttrib( |
| 37 GLES2Implementation* gl, GLuint program, const char* name) = 0; | 44 GLES2Implementation* gl, GLuint program, GLuint index, GLsizei bufsize, |
| 45 GLsizei* length, GLint* size, GLenum* type, char* name); |
| 38 | 46 |
| 39 virtual bool GetActiveAttrib( | 47 bool GetActiveUniform( |
| 40 GLES2Implementation* gl, | 48 GLES2Implementation* gl, GLuint program, GLuint index, GLsizei bufsize, |
| 41 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 49 GLsizei* length, GLint* size, GLenum* type, char* name); |
| 42 GLint* size, GLenum* type, char* name) = 0; | |
| 43 | 50 |
| 44 virtual bool GetActiveUniform( | 51 private: |
| 45 GLES2Implementation* gl, | 52 class Program { |
| 46 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 53 public: |
| 47 GLint* size, GLenum* type, char* name) = 0; | 54 struct UniformInfo { |
| 55 UniformInfo(GLsizei _size, GLenum _type, const std::string& _name); |
| 56 ~UniformInfo(); |
| 48 | 57 |
| 49 protected: | 58 GLsizei size; |
| 50 ProgramInfoManager(); | 59 GLenum type; |
| 60 bool is_array; |
| 61 std::string name; |
| 62 std::vector<GLint> element_locations; |
| 63 }; |
| 64 struct VertexAttrib { |
| 65 VertexAttrib(GLsizei _size, GLenum _type, const std::string& _name, |
| 66 GLint _location); |
| 67 ~VertexAttrib(); |
| 68 |
| 69 GLsizei size; |
| 70 GLenum type; |
| 71 GLint location; |
| 72 std::string name; |
| 73 }; |
| 74 |
| 75 Program(); |
| 76 ~Program(); |
| 77 |
| 78 const VertexAttrib* GetAttribInfo(GLint index) const; |
| 79 |
| 80 GLint GetAttribLocation(const std::string& name) const; |
| 81 |
| 82 const UniformInfo* GetUniformInfo(GLint index) const; |
| 83 |
| 84 // Gets the location of a uniform by name. |
| 85 GLint GetUniformLocation(const std::string& name) const; |
| 86 |
| 87 GLint GetFragDataLocation(const std::string& name) const; |
| 88 void CacheFragDataLocation(const std::string& name, GLint loc); |
| 89 |
| 90 bool GetProgramiv(GLenum pname, GLint* params); |
| 91 |
| 92 // Updates the program info after a successful link. |
| 93 void Update(GLES2Implementation* gl, |
| 94 GLuint program, |
| 95 const std::vector<int8>& result); |
| 96 |
| 97 bool cached() const; |
| 98 |
| 99 private: |
| 100 bool cached_; |
| 101 |
| 102 GLsizei max_attrib_name_length_; |
| 103 |
| 104 // Attrib by index. |
| 105 std::vector<VertexAttrib> attrib_infos_; |
| 106 |
| 107 GLsizei max_uniform_name_length_; |
| 108 |
| 109 // Uniform info by index. |
| 110 std::vector<UniformInfo> uniform_infos_; |
| 111 |
| 112 base::hash_map<std::string, GLint> frag_data_locations_; |
| 113 |
| 114 // This is true if glLinkProgram was successful last time it was called. |
| 115 bool link_status_; |
| 116 }; |
| 117 |
| 118 Program* GetProgramInfo(GLES2Implementation* gl, GLuint program); |
| 119 |
| 120 typedef base::hash_map<GLuint, Program> ProgramInfoMap; |
| 121 |
| 122 ProgramInfoMap program_infos_; |
| 123 |
| 124 mutable base::Lock lock_; |
| 51 }; | 125 }; |
| 52 | 126 |
| 53 } // namespace gles2 | 127 } // namespace gles2 |
| 54 } // namespace gpu | 128 } // namespace gpu |
| 55 | 129 |
| 56 #endif // GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ | 130 #endif // GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ |
| OLD | NEW |