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() { | |
bajones
2015/01/30 21:40:22
Pretty sure just moving the closing curly brace on
piman
2015/01/30 21:55:39
It actually needs to be out-of-line because of non
Zhenyao Mo
2015/01/30 22:11:38
Thank you both for the tips. However, why my loca
piman
2015/01/30 22:15:45
It's a clang plugin.
| |
57 } | |
48 | 58 |
49 protected: | 59 GLsizei size; |
50 ProgramInfoManager(); | 60 GLenum type; |
61 bool is_array; | |
62 std::string name; | |
63 std::vector<GLint> element_locations; | |
64 }; | |
65 struct VertexAttrib { | |
66 VertexAttrib(GLsizei _size, GLenum _type, const std::string& _name, | |
67 GLint _location) | |
68 : size(_size), | |
69 type(_type), | |
70 location(_location), | |
71 name(_name) { | |
72 } | |
73 ~VertexAttrib() { | |
bajones
2015/01/30 21:40:22
Ditto
| |
74 } | |
75 | |
76 GLsizei size; | |
77 GLenum type; | |
78 GLint location; | |
79 std::string name; | |
80 }; | |
81 | |
82 typedef std::vector<UniformInfo> UniformInfoVector; | |
83 typedef std::vector<VertexAttrib> AttribInfoVector; | |
84 | |
85 Program(); | |
86 ~Program() { | |
bajones
2015/01/30 21:40:22
Ditto
| |
87 } | |
88 | |
89 const AttribInfoVector& GetAttribInfos() const { | |
90 return attrib_infos_; | |
91 } | |
92 | |
93 const VertexAttrib* GetAttribInfo(GLint index) const { | |
94 return (static_cast<size_t>(index) < attrib_infos_.size()) ? | |
95 &attrib_infos_[index] : NULL; | |
96 } | |
97 | |
98 GLint GetAttribLocation(const std::string& name) const; | |
99 | |
100 const UniformInfo* GetUniformInfo(GLint index) const { | |
101 return (static_cast<size_t>(index) < uniform_infos_.size()) ? | |
102 &uniform_infos_[index] : NULL; | |
103 } | |
104 | |
105 // Gets the location of a uniform by name. | |
106 GLint GetUniformLocation(const std::string& name) const; | |
107 | |
108 GLint GetFragDataLocation(const std::string& name) const; | |
109 void CacheFragDataLocation(const std::string& name, GLint loc); | |
110 | |
111 bool GetProgramiv(GLenum pname, GLint* params); | |
112 | |
113 // Updates the program info after a successful link. | |
114 void Update(GLES2Implementation* gl, | |
115 GLuint program, | |
116 const std::vector<int8>& result); | |
117 | |
118 bool cached() const { return cached_; } | |
119 | |
120 private: | |
121 bool cached_; | |
122 | |
123 GLsizei max_attrib_name_length_; | |
124 | |
125 // Attrib by index. | |
126 AttribInfoVector attrib_infos_; | |
127 | |
128 GLsizei max_uniform_name_length_; | |
129 | |
130 // Uniform info by index. | |
131 UniformInfoVector uniform_infos_; | |
132 | |
133 base::hash_map<std::string, GLint> frag_data_locations_; | |
134 | |
135 // This is true if glLinkProgram was successful last time it was called. | |
136 bool link_status_; | |
137 }; | |
138 | |
139 Program* GetProgramInfo(GLES2Implementation* gl, GLuint program); | |
140 | |
141 typedef base::hash_map<GLuint, Program> ProgramInfoMap; | |
142 | |
143 ProgramInfoMap program_infos_; | |
144 | |
145 mutable base::Lock lock_; | |
51 }; | 146 }; |
52 | 147 |
53 } // namespace gles2 | 148 } // namespace gles2 |
54 } // namespace gpu | 149 } // namespace gpu |
55 | 150 |
56 #endif // GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ | 151 #endif // GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ |
OLD | NEW |