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 #include "gpu/command_buffer/service/context_state.h" | 5 #include "gpu/command_buffer/service/context_state.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 9 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
10 #include "gpu/command_buffer/service/buffer_manager.h" | 10 #include "gpu/command_buffer/service/buffer_manager.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 74 |
75 } // anonymous namespace. | 75 } // anonymous namespace. |
76 | 76 |
77 TextureUnit::TextureUnit() | 77 TextureUnit::TextureUnit() |
78 : bind_target(GL_TEXTURE_2D) { | 78 : bind_target(GL_TEXTURE_2D) { |
79 } | 79 } |
80 | 80 |
81 TextureUnit::~TextureUnit() { | 81 TextureUnit::~TextureUnit() { |
82 } | 82 } |
83 | 83 |
84 bool Vec4::Equal(const Vec4& other) const { | |
85 if (type_ != other.type_) | |
86 return false; | |
87 switch (type_) { | |
88 case kFloat: | |
89 for (size_t ii = 0; ii < 4; ++ii) { | |
90 if (v_[ii].float_value != other.v_[ii].float_value) | |
91 return false; | |
92 } | |
93 break; | |
94 case kInt: | |
95 for (size_t ii = 0; ii < 4; ++ii) { | |
96 if (v_[ii].int_value != other.v_[ii].int_value) | |
97 return false; | |
98 } | |
99 break; | |
100 case kUInt: | |
101 for (size_t ii = 0; ii < 4; ++ii) { | |
102 if (v_[ii].uint_value != other.v_[ii].uint_value) | |
103 return false; | |
104 } | |
105 break; | |
106 } | |
107 return true; | |
108 } | |
109 | |
110 template <> | |
111 void Vec4::GetValues<GLfloat>(GLfloat* values) const { | |
112 DCHECK(values); | |
113 switch (type_) { | |
114 case kFloat: | |
115 for (size_t ii = 0; ii < 4; ++ii) | |
116 values[ii] = v_[ii].float_value; | |
117 break; | |
118 case kInt: | |
119 for (size_t ii = 0; ii < 4; ++ii) | |
120 values[ii] = static_cast<GLfloat>(v_[ii].int_value); | |
Zhenyao Mo
2015/05/13 16:52:25
Note that the casting behavior might change depend
| |
121 break; | |
122 case kUInt: | |
123 for (size_t ii = 0; ii < 4; ++ii) | |
124 values[ii] = static_cast<GLfloat>(v_[ii].uint_value); | |
125 break; | |
126 } | |
127 } | |
128 | |
129 template <> | |
130 void Vec4::GetValues<GLint>(GLint* values) const { | |
131 DCHECK(values); | |
132 switch (type_) { | |
133 case kFloat: | |
134 for (size_t ii = 0; ii < 4; ++ii) | |
135 values[ii] = static_cast<GLint>(v_[ii].float_value); | |
136 break; | |
137 case kInt: | |
138 for (size_t ii = 0; ii < 4; ++ii) | |
139 values[ii] = v_[ii].int_value; | |
140 break; | |
141 case kUInt: | |
142 for (size_t ii = 0; ii < 4; ++ii) | |
143 values[ii] = static_cast<GLint>(v_[ii].uint_value); | |
144 break; | |
145 } | |
146 } | |
147 | |
148 template <> | |
149 void Vec4::GetValues<GLuint>(GLuint* values) const { | |
150 DCHECK(values); | |
151 switch (type_) { | |
152 case kFloat: | |
153 for (size_t ii = 0; ii < 4; ++ii) | |
154 values[ii] = static_cast<GLuint>(v_[ii].float_value); | |
155 break; | |
156 case kInt: | |
157 for (size_t ii = 0; ii < 4; ++ii) | |
158 values[ii] = static_cast<GLuint>(v_[ii].int_value); | |
159 break; | |
160 case kUInt: | |
161 for (size_t ii = 0; ii < 4; ++ii) | |
162 values[ii] = v_[ii].uint_value; | |
163 break; | |
164 } | |
165 } | |
166 | |
167 template <> | |
168 void Vec4::SetValues<GLfloat>(const GLfloat* values) { | |
169 DCHECK(values); | |
170 for (size_t ii = 0; ii < 4; ++ii) | |
171 v_[ii].float_value = values[ii]; | |
172 type_ = kFloat; | |
173 } | |
174 | |
175 template <> | |
176 void Vec4::SetValues<GLint>(const GLint* values) { | |
177 DCHECK(values); | |
178 for (size_t ii = 0; ii < 4; ++ii) | |
179 v_[ii].int_value = values[ii]; | |
180 type_ = kInt; | |
181 } | |
182 | |
183 template <> | |
184 void Vec4::SetValues<GLuint>(const GLuint* values) { | |
185 DCHECK(values); | |
186 for (size_t ii = 0; ii < 4; ++ii) | |
187 v_[ii].uint_value = values[ii]; | |
188 type_ = kUInt; | |
189 } | |
190 | |
84 ContextState::ContextState(FeatureInfo* feature_info, | 191 ContextState::ContextState(FeatureInfo* feature_info, |
85 ErrorStateClient* error_state_client, | 192 ErrorStateClient* error_state_client, |
86 Logger* logger) | 193 Logger* logger) |
87 : active_texture_unit(0), | 194 : active_texture_unit(0), |
88 bound_renderbuffer_valid(false), | 195 bound_renderbuffer_valid(false), |
89 pack_reverse_row_order(false), | 196 pack_reverse_row_order(false), |
90 ignore_cached_state(false), | 197 ignore_cached_state(false), |
91 fbo_binding_for_scissor_workaround_dirty(false), | 198 fbo_binding_for_scissor_workaround_dirty(false), |
92 feature_info_(feature_info), | 199 feature_info_(feature_info), |
93 error_state_(ErrorState::Create(error_state_client, logger)) { | 200 error_state_(ErrorState::Create(error_state_client, logger)) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 void ContextState::RestoreActiveTextureUnitBinding(unsigned int target) const { | 285 void ContextState::RestoreActiveTextureUnitBinding(unsigned int target) const { |
179 DCHECK_LT(active_texture_unit, texture_units.size()); | 286 DCHECK_LT(active_texture_unit, texture_units.size()); |
180 const TextureUnit& texture_unit = texture_units[active_texture_unit]; | 287 const TextureUnit& texture_unit = texture_units[active_texture_unit]; |
181 if (TargetIsSupported(feature_info_, target)) | 288 if (TargetIsSupported(feature_info_, target)) |
182 glBindTexture(target, GetServiceId(texture_unit, target)); | 289 glBindTexture(target, GetServiceId(texture_unit, target)); |
183 } | 290 } |
184 | 291 |
185 void ContextState::RestoreVertexAttribValues() const { | 292 void ContextState::RestoreVertexAttribValues() const { |
186 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); | 293 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); |
187 ++attrib) { | 294 ++attrib) { |
188 glVertexAttrib4fv(attrib, attrib_values[attrib].v); | 295 switch (attrib_values[attrib].type()) { |
296 case Vec4::kFloat: | |
297 { | |
298 GLfloat v[4]; | |
299 attrib_values[attrib].GetValues(v); | |
300 glVertexAttrib4fv(attrib, v); | |
301 } | |
302 break; | |
303 case Vec4::kInt: | |
304 { | |
305 GLint v[4]; | |
306 attrib_values[attrib].GetValues(v); | |
307 glVertexAttribI4iv(attrib, v); | |
308 } | |
309 break; | |
310 case Vec4::kUInt: | |
311 { | |
312 GLuint v[4]; | |
313 attrib_values[attrib].GetValues(v); | |
314 glVertexAttribI4uiv(attrib, v); | |
315 } | |
316 break; | |
317 } | |
189 } | 318 } |
190 } | 319 } |
191 | 320 |
192 void ContextState::RestoreVertexAttribArrays( | 321 void ContextState::RestoreVertexAttribArrays( |
193 const scoped_refptr<VertexAttribManager> attrib_manager) const { | 322 const scoped_refptr<VertexAttribManager> attrib_manager) const { |
194 // This is expected to be called only for VAO with service_id 0, | 323 // This is expected to be called only for VAO with service_id 0, |
195 // either to restore the default VAO or a virtual VAO with service_id 0. | 324 // either to restore the default VAO or a virtual VAO with service_id 0. |
196 GLuint vao_service_id = attrib_manager->service_id(); | 325 GLuint vao_service_id = attrib_manager->service_id(); |
197 DCHECK(vao_service_id == 0); | 326 DCHECK(vao_service_id == 0); |
198 | 327 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 | 426 |
298 // Include the auto-generated part of this file. We split this because it means | 427 // Include the auto-generated part of this file. We split this because it means |
299 // we can easily edit the non-auto generated parts right here in this file | 428 // we can easily edit the non-auto generated parts right here in this file |
300 // instead of having to edit some template or the code generator. | 429 // instead of having to edit some template or the code generator. |
301 #include "gpu/command_buffer/service/context_state_impl_autogen.h" | 430 #include "gpu/command_buffer/service/context_state_impl_autogen.h" |
302 | 431 |
303 } // namespace gles2 | 432 } // namespace gles2 |
304 } // namespace gpu | 433 } // namespace gpu |
305 | 434 |
306 | 435 |
OLD | NEW |