| 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_SERVICE_PROGRAM_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 kUniformMatrix2x4f = 1 << 16, | 59 kUniformMatrix2x4f = 1 << 16, |
| 60 kUniformMatrix3x2f = 1 << 17, | 60 kUniformMatrix3x2f = 1 << 17, |
| 61 kUniformMatrix3x4f = 1 << 18, | 61 kUniformMatrix3x4f = 1 << 18, |
| 62 kUniformMatrix4x2f = 1 << 19, | 62 kUniformMatrix4x2f = 1 << 19, |
| 63 kUniformMatrix4x3f = 1 << 20, | 63 kUniformMatrix4x3f = 1 << 20, |
| 64 }; | 64 }; |
| 65 struct FragmentInputInfo { | 65 struct FragmentInputInfo { |
| 66 FragmentInputInfo(GLenum _type, GLuint _location) | 66 FragmentInputInfo(GLenum _type, GLuint _location) |
| 67 : type(_type), location(_location) {} | 67 : type(_type), location(_location) {} |
| 68 FragmentInputInfo() : type(GL_NONE), location(0) {} | 68 FragmentInputInfo() : type(GL_NONE), location(0) {} |
| 69 bool IsValid() const { return type != GL_NONE; } | |
| 70 GLenum type; | 69 GLenum type; |
| 71 GLuint location; | 70 GLuint location; |
| 72 }; | 71 }; |
| 73 | 72 |
| 74 struct UniformInfo { | 73 struct UniformInfo { |
| 75 UniformInfo(); | 74 UniformInfo(); |
| 76 UniformInfo(const std::string& client_name, | 75 UniformInfo(const std::string& client_name, |
| 77 GLint client_location_base, | 76 GLint client_location_base, |
| 78 GLenum _type, | 77 GLenum _type, |
| 79 bool _is_array, | 78 bool _is_array, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 100 type(_type), | 99 type(_type), |
| 101 location(_location), | 100 location(_location), |
| 102 name(_name) { | 101 name(_name) { |
| 103 } | 102 } |
| 104 GLsizei size; | 103 GLsizei size; |
| 105 GLenum type; | 104 GLenum type; |
| 106 GLint location; | 105 GLint location; |
| 107 std::string name; | 106 std::string name; |
| 108 }; | 107 }; |
| 109 | 108 |
| 110 class UniformLocationEntry { | 109 template <typename T> |
| 110 class ShaderVariableLocationEntry { |
| 111 public: | 111 public: |
| 112 UniformLocationEntry() : uniform_(nullptr), inactive_(false) {} | 112 ShaderVariableLocationEntry() |
| 113 bool IsUnused() const { return !uniform_ && !inactive_; } | 113 : shader_variable_(nullptr), inactive_(false) {} |
| 114 bool IsUnused() const { return !shader_variable_ && !inactive_; } |
| 114 bool IsInactive() const { return inactive_; } | 115 bool IsInactive() const { return inactive_; } |
| 115 bool IsActive() const { return uniform_ != nullptr; } | 116 bool IsActive() const { return shader_variable_ != nullptr; } |
| 116 void SetInactive() { | 117 void SetInactive() { |
| 117 uniform_ = nullptr; | 118 shader_variable_ = nullptr; |
| 118 inactive_ = true; | 119 inactive_ = true; |
| 119 } | 120 } |
| 120 void SetActive(UniformInfo* uniform) { | 121 void SetActive(T* shader_variable) { |
| 121 DCHECK(uniform); | 122 DCHECK(shader_variable); |
| 122 uniform_ = uniform; | 123 shader_variable_ = shader_variable; |
| 123 inactive_ = false; | 124 inactive_ = false; |
| 124 } | 125 } |
| 125 const UniformInfo* uniform() const { | 126 const T* shader_variable() const { |
| 126 DCHECK(IsActive()); | 127 DCHECK(IsActive()); |
| 127 return uniform_; | 128 return shader_variable_; |
| 128 } | 129 } |
| 129 UniformInfo* uniform() { | 130 T* shader_variable() { |
| 130 DCHECK(IsActive()); | 131 DCHECK(IsActive()); |
| 131 return uniform_; | 132 return shader_variable_; |
| 132 } | 133 } |
| 133 | 134 |
| 134 private: | 135 private: |
| 135 UniformInfo* uniform_; // Pointer to uniform_info_ vector entry. | 136 T* shader_variable_; // Pointer to *_info_ vector entry. |
| 136 bool inactive_; | 137 bool inactive_; |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 typedef std::vector<UniformInfo> UniformInfoVector; | 140 typedef std::vector<UniformInfo> UniformInfoVector; |
| 140 typedef std::vector<UniformLocationEntry> UniformLocationVector; | 141 typedef std::vector<ShaderVariableLocationEntry<UniformInfo>> |
| 142 UniformLocationVector; |
| 141 typedef std::vector<VertexAttrib> AttribInfoVector; | 143 typedef std::vector<VertexAttrib> AttribInfoVector; |
| 142 typedef std::vector<FragmentInputInfo> FragmentInputInfoVector; | 144 typedef std::vector<FragmentInputInfo> FragmentInputInfoVector; |
| 145 typedef std::vector<ShaderVariableLocationEntry<FragmentInputInfo>> |
| 146 FragmentInputLocationVector; |
| 143 typedef std::vector<int> SamplerIndices; | 147 typedef std::vector<int> SamplerIndices; |
| 144 typedef std::map<std::string, GLint> LocationMap; | 148 typedef std::map<std::string, GLint> LocationMap; |
| 145 typedef std::vector<std::string> StringVector; | 149 typedef std::vector<std::string> StringVector; |
| 146 | 150 |
| 147 Program(ProgramManager* manager, GLuint service_id); | 151 Program(ProgramManager* manager, GLuint service_id); |
| 148 | 152 |
| 149 GLuint service_id() const { | 153 GLuint service_id() const { |
| 150 return service_id_; | 154 return service_id_; |
| 151 } | 155 } |
| 152 | 156 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 const std::string* GetUniformMappedName( | 189 const std::string* GetUniformMappedName( |
| 186 const std::string& original_name) const; | 190 const std::string& original_name) const; |
| 187 | 191 |
| 188 // If the hashed name is not found, return NULL. | 192 // If the hashed name is not found, return NULL. |
| 189 const std::string* GetOriginalNameFromHashedName( | 193 const std::string* GetOriginalNameFromHashedName( |
| 190 const std::string& hashed_name) const; | 194 const std::string& hashed_name) const; |
| 191 | 195 |
| 192 const FragmentInputInfo* GetFragmentInputInfoByFakeLocation( | 196 const FragmentInputInfo* GetFragmentInputInfoByFakeLocation( |
| 193 GLint fake_location) const; | 197 GLint fake_location) const; |
| 194 | 198 |
| 199 bool IsInactiveFragmentInputLocationByFakeLocation(GLint fake_location) const; |
| 200 |
| 195 // Gets the fake location of a uniform by name. | 201 // Gets the fake location of a uniform by name. |
| 196 GLint GetUniformFakeLocation(const std::string& name) const; | 202 GLint GetUniformFakeLocation(const std::string& name) const; |
| 197 | 203 |
| 198 // Gets the UniformInfo of a uniform by location. | 204 // Gets the UniformInfo of a uniform by location. |
| 199 const UniformInfo* GetUniformInfoByFakeLocation( | 205 const UniformInfo* GetUniformInfoByFakeLocation( |
| 200 GLint fake_location, GLint* real_location, GLint* array_index) const; | 206 GLint fake_location, GLint* real_location, GLint* array_index) const; |
| 201 | 207 |
| 202 // Returns true if |fake_location| is a location for an inactive uniform, | 208 // Returns true if |fake_location| is a location for an inactive uniform, |
| 203 // -1 for bound, non-existing uniform. | 209 // -1 for bound, non-existing uniform. |
| 204 bool IsInactiveUniformLocationByFakeLocation(GLint fake_location) const; | 210 bool IsInactiveUniformLocationByFakeLocation(GLint fake_location) const; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 GLsizei max_uniform_name_length_; | 438 GLsizei max_uniform_name_length_; |
| 433 | 439 |
| 434 // Uniform info by index. | 440 // Uniform info by index. |
| 435 UniformInfoVector uniform_infos_; | 441 UniformInfoVector uniform_infos_; |
| 436 UniformLocationVector uniform_locations_; | 442 UniformLocationVector uniform_locations_; |
| 437 | 443 |
| 438 // The indices of the uniforms that are samplers. | 444 // The indices of the uniforms that are samplers. |
| 439 SamplerIndices sampler_indices_; | 445 SamplerIndices sampler_indices_; |
| 440 | 446 |
| 441 FragmentInputInfoVector fragment_input_infos_; | 447 FragmentInputInfoVector fragment_input_infos_; |
| 448 FragmentInputLocationVector fragment_input_locations_; |
| 442 | 449 |
| 443 // The program this Program is tracking. | 450 // The program this Program is tracking. |
| 444 GLuint service_id_; | 451 GLuint service_id_; |
| 445 | 452 |
| 446 // Shaders by type of shader. | 453 // Shaders by type of shader. |
| 447 scoped_refptr<Shader> | 454 scoped_refptr<Shader> |
| 448 attached_shaders_[kMaxAttachedShaders]; | 455 attached_shaders_[kMaxAttachedShaders]; |
| 449 | 456 |
| 450 // True if this program is marked as deleted. | 457 // True if this program is marked as deleted. |
| 451 bool deleted_; | 458 bool deleted_; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 }; | 567 }; |
| 561 | 568 |
| 562 inline const FeatureInfo& Program::feature_info() const { | 569 inline const FeatureInfo& Program::feature_info() const { |
| 563 return *manager_->feature_info_.get(); | 570 return *manager_->feature_info_.get(); |
| 564 } | 571 } |
| 565 | 572 |
| 566 } // namespace gles2 | 573 } // namespace gles2 |
| 567 } // namespace gpu | 574 } // namespace gpu |
| 568 | 575 |
| 569 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ | 576 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
| OLD | NEW |