| 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 <GLES3/gl3.h> | 8 #include <GLES3/gl3.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 GLES2Implementation* gl, GLuint program, const char* name); | 53 GLES2Implementation* gl, GLuint program, const char* name); |
| 54 | 54 |
| 55 bool GetActiveUniformBlockName( | 55 bool GetActiveUniformBlockName( |
| 56 GLES2Implementation* gl, GLuint program, GLuint index, | 56 GLES2Implementation* gl, GLuint program, GLuint index, |
| 57 GLsizei buf_size, GLsizei* length, char* name); | 57 GLsizei buf_size, GLsizei* length, char* name); |
| 58 | 58 |
| 59 bool GetActiveUniformBlockiv( | 59 bool GetActiveUniformBlockiv( |
| 60 GLES2Implementation* gl, GLuint program, GLuint index, | 60 GLES2Implementation* gl, GLuint program, GLuint index, |
| 61 GLenum pname, GLint* params); | 61 GLenum pname, GLint* params); |
| 62 | 62 |
| 63 // Attempt to update the |index| uniform block binding. |
| 64 // It's no op if the program does not exist, or the |index| uniform block |
| 65 // is not in the cache, or binding >= GL_MAX_UNIFORM_BUFFER_BINDINGS. |
| 66 void UniformBlockBinding( |
| 67 GLES2Implementation* gl, GLuint program, GLuint index, GLuint binding); |
| 68 |
| 69 bool GetTransformFeedbackVarying( |
| 70 GLES2Implementation* gl, GLuint program, GLuint index, GLsizei bufsize, |
| 71 GLsizei* length, GLsizei* size, GLenum* type, char* name); |
| 72 |
| 73 bool GetUniformIndices( |
| 74 GLES2Implementation* gl, GLuint program, GLsizei count, |
| 75 const char* const* names, GLuint* indices); |
| 76 |
| 77 bool GetActiveUniformsiv( |
| 78 GLES2Implementation* gl, GLuint program, GLsizei count, |
| 79 const GLuint* indices, GLenum pname, GLint* params); |
| 80 |
| 63 private: | 81 private: |
| 64 friend class ProgramInfoManagerTest; | 82 friend class ProgramInfoManagerTest; |
| 65 | 83 |
| 84 FRIEND_TEST_ALL_PREFIXES(ProgramInfoManagerTest, UpdateES2); |
| 66 FRIEND_TEST_ALL_PREFIXES(ProgramInfoManagerTest, UpdateES3UniformBlocks); | 85 FRIEND_TEST_ALL_PREFIXES(ProgramInfoManagerTest, UpdateES3UniformBlocks); |
| 86 FRIEND_TEST_ALL_PREFIXES(ProgramInfoManagerTest, |
| 87 UpdateES3TransformFeedbackVaryings); |
| 88 FRIEND_TEST_ALL_PREFIXES(ProgramInfoManagerTest, |
| 89 GetActiveUniformsivCached); |
| 67 | 90 |
| 68 enum ProgramInfoType { | 91 enum ProgramInfoType { |
| 69 kES2, | 92 kES2, |
| 70 kES3UniformBlocks, | 93 kES3UniformBlocks, |
| 94 kES3TransformFeedbackVaryings, |
| 95 kES3Uniformsiv, |
| 71 kNone, | 96 kNone, |
| 72 }; | 97 }; |
| 73 | 98 |
| 74 // Need GLES2_IMPL_EXPORT for tests. | 99 // Need GLES2_IMPL_EXPORT for tests. |
| 75 class GLES2_IMPL_EXPORT Program { | 100 class GLES2_IMPL_EXPORT Program { |
| 76 public: | 101 public: |
| 77 struct UniformInfo { | 102 struct UniformInfo { |
| 78 UniformInfo(GLsizei _size, GLenum _type, const std::string& _name); | 103 UniformInfo(GLsizei _size, GLenum _type, const std::string& _name); |
| 79 ~UniformInfo(); | 104 ~UniformInfo(); |
| 80 | 105 |
| 81 GLsizei size; | 106 GLsizei size; |
| 82 GLenum type; | 107 GLenum type; |
| 83 bool is_array; | 108 bool is_array; |
| 84 std::string name; | 109 std::string name; |
| 85 std::vector<GLint> element_locations; | 110 std::vector<GLint> element_locations; |
| 86 }; | 111 }; |
| 112 struct UniformES3 { |
| 113 UniformES3(); |
| 114 ~UniformES3(); |
| 115 |
| 116 GLint block_index; |
| 117 GLint offset; |
| 118 GLint array_stride; |
| 119 GLint matrix_stride; |
| 120 GLint is_row_major; |
| 121 }; |
| 87 struct VertexAttrib { | 122 struct VertexAttrib { |
| 88 VertexAttrib(GLsizei _size, GLenum _type, const std::string& _name, | 123 VertexAttrib(GLsizei _size, GLenum _type, const std::string& _name, |
| 89 GLint _location); | 124 GLint _location); |
| 90 ~VertexAttrib(); | 125 ~VertexAttrib(); |
| 91 | 126 |
| 92 GLsizei size; | 127 GLsizei size; |
| 93 GLenum type; | 128 GLenum type; |
| 94 GLint location; | 129 GLint location; |
| 95 std::string name; | 130 std::string name; |
| 96 }; | 131 }; |
| 97 struct UniformBlock { | 132 struct UniformBlock { |
| 98 UniformBlock(); | 133 UniformBlock(); |
| 99 ~UniformBlock(); | 134 ~UniformBlock(); |
| 100 | 135 |
| 101 GLuint binding; | 136 GLuint binding; |
| 102 GLuint data_size; | 137 GLuint data_size; |
| 103 std::vector<GLuint> active_uniform_indices; | 138 std::vector<GLuint> active_uniform_indices; |
| 104 GLboolean referenced_by_vertex_shader; | 139 GLboolean referenced_by_vertex_shader; |
| 105 GLboolean referenced_by_fragment_shader; | 140 GLboolean referenced_by_fragment_shader; |
| 106 std::string name; | 141 std::string name; |
| 107 }; | 142 }; |
| 143 struct TransformFeedbackVarying { |
| 144 TransformFeedbackVarying(); |
| 145 ~TransformFeedbackVarying(); |
| 146 |
| 147 GLsizei size; |
| 148 GLenum type; |
| 149 std::string name; |
| 150 }; |
| 108 | 151 |
| 109 Program(); | 152 Program(); |
| 110 ~Program(); | 153 ~Program(); |
| 111 | 154 |
| 112 const VertexAttrib* GetAttribInfo(GLint index) const; | 155 const VertexAttrib* GetAttribInfo(GLint index) const; |
| 113 | 156 |
| 114 GLint GetAttribLocation(const std::string& name) const; | 157 GLint GetAttribLocation(const std::string& name) const; |
| 115 | 158 |
| 116 const UniformInfo* GetUniformInfo(GLint index) const; | 159 const UniformInfo* GetUniformInfo(GLint index) const; |
| 117 | 160 |
| 118 // Gets the location of a uniform by name. | 161 // Gets the location of a uniform by name. |
| 119 GLint GetUniformLocation(const std::string& name) const; | 162 GLint GetUniformLocation(const std::string& name) const; |
| 163 // Gets the index of a uniform by name. Return INVALID_INDEX in failure. |
| 164 GLuint GetUniformIndex(const std::string& name) const; |
| 165 |
| 166 bool GetUniformsiv( |
| 167 GLsizei count, const GLuint* indices, GLenum pname, GLint* params); |
| 120 | 168 |
| 121 GLint GetFragDataLocation(const std::string& name) const; | 169 GLint GetFragDataLocation(const std::string& name) const; |
| 122 void CacheFragDataLocation(const std::string& name, GLint loc); | 170 void CacheFragDataLocation(const std::string& name, GLint loc); |
| 123 | 171 |
| 124 bool GetProgramiv(GLenum pname, GLint* params); | 172 bool GetProgramiv(GLenum pname, GLint* params); |
| 125 | 173 |
| 126 // Gets the index of a uniform block by name. | 174 // Gets the index of a uniform block by name. |
| 127 GLuint GetUniformBlockIndex(const std::string& name) const; | 175 GLuint GetUniformBlockIndex(const std::string& name) const; |
| 128 const UniformBlock* GetUniformBlock(GLuint index) const; | 176 const UniformBlock* GetUniformBlock(GLuint index) const; |
| 177 // Update the binding if the |index| uniform block is in the cache. |
| 178 void UniformBlockBinding(GLuint index, GLuint binding); |
| 179 |
| 180 const TransformFeedbackVarying* GetTransformFeedbackVarying( |
| 181 GLuint index) const; |
| 129 | 182 |
| 130 // Updates the ES2 only program info after a successful link. | 183 // Updates the ES2 only program info after a successful link. |
| 131 void UpdateES2(const std::vector<int8>& result); | 184 void UpdateES2(const std::vector<int8>& result); |
| 132 | 185 |
| 133 // Updates the ES3 UniformBlock info after a successful link. | 186 // Updates the ES3 UniformBlock info after a successful link. |
| 134 void UpdateES3UniformBlocks(const std::vector<int8>& result); | 187 void UpdateES3UniformBlocks(const std::vector<int8>& result); |
| 135 | 188 |
| 189 // Updates the ES3 Uniformsiv info after a successful link. |
| 190 void UpdateES3Uniformsiv(const std::vector<int8>& result); |
| 191 |
| 192 // Updates the ES3 TransformFeedbackVaryings info after a successful link. |
| 193 void UpdateES3TransformFeedbackVaryings(const std::vector<int8>& result); |
| 194 |
| 136 bool IsCached(ProgramInfoType type) const; | 195 bool IsCached(ProgramInfoType type) const; |
| 137 | 196 |
| 138 private: | 197 private: |
| 139 bool cached_es2_; | 198 bool cached_es2_; |
| 140 | 199 |
| 141 GLsizei max_attrib_name_length_; | 200 GLsizei max_attrib_name_length_; |
| 142 | 201 |
| 143 // Attrib by index. | 202 // Attrib by index. |
| 144 std::vector<VertexAttrib> attrib_infos_; | 203 std::vector<VertexAttrib> attrib_infos_; |
| 145 | 204 |
| 146 GLsizei max_uniform_name_length_; | 205 GLsizei max_uniform_name_length_; |
| 147 | 206 |
| 148 // Uniform info by index. | 207 // Uniform info by index. |
| 149 std::vector<UniformInfo> uniform_infos_; | 208 std::vector<UniformInfo> uniform_infos_; |
| 150 | 209 |
| 151 // This is true if glLinkProgram was successful last time it was called. | 210 // This is true if glLinkProgram was successful last time it was called. |
| 152 bool link_status_; | 211 bool link_status_; |
| 153 | 212 |
| 154 // BELOW ARE ES3 ONLY INFORMATION. | 213 // BELOW ARE ES3 ONLY INFORMATION. |
| 155 | 214 |
| 156 bool cached_es3_uniform_blocks_; | 215 bool cached_es3_uniform_blocks_; |
| 157 | 216 |
| 158 uint32_t active_uniform_block_max_name_length_; | 217 uint32_t active_uniform_block_max_name_length_; |
| 159 | 218 |
| 160 // Uniform blocks by index. | 219 // Uniform blocks by index. |
| 161 std::vector<UniformBlock> uniform_blocks_; | 220 std::vector<UniformBlock> uniform_blocks_; |
| 162 | 221 |
| 222 bool cached_es3_transform_feedback_varyings_; |
| 223 |
| 224 uint32_t transform_feedback_varying_max_length_; |
| 225 |
| 226 // TransformFeedback varyings by index. |
| 227 std::vector<TransformFeedbackVarying> transform_feedback_varyings_; |
| 228 |
| 229 bool cached_es3_uniformsiv_; |
| 230 |
| 231 std::vector<UniformES3> uniforms_es3_; |
| 232 |
| 163 base::hash_map<std::string, GLint> frag_data_locations_; | 233 base::hash_map<std::string, GLint> frag_data_locations_; |
| 164 }; | 234 }; |
| 165 | 235 |
| 166 Program* GetProgramInfo( | 236 Program* GetProgramInfo( |
| 167 GLES2Implementation* gl, GLuint program, ProgramInfoType type); | 237 GLES2Implementation* gl, GLuint program, ProgramInfoType type); |
| 168 | 238 |
| 169 typedef base::hash_map<GLuint, Program> ProgramInfoMap; | 239 typedef base::hash_map<GLuint, Program> ProgramInfoMap; |
| 170 | 240 |
| 171 ProgramInfoMap program_infos_; | 241 ProgramInfoMap program_infos_; |
| 172 | 242 |
| 173 mutable base::Lock lock_; | 243 mutable base::Lock lock_; |
| 174 }; | 244 }; |
| 175 | 245 |
| 176 } // namespace gles2 | 246 } // namespace gles2 |
| 177 } // namespace gpu | 247 } // namespace gpu |
| 178 | 248 |
| 179 #endif // GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ | 249 #endif // GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_ |
| OLD | NEW |