OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/output/program_binding.h" | 5 #include "cc/output/program_binding.h" |
6 | 6 |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "cc/output/geometry_binding.h" | 8 #include "cc/output/geometry_binding.h" |
9 #include "gpu/GLES2/gl2extchromium.h" | 9 #include "gpu/GLES2/gl2extchromium.h" |
10 #include "gpu/command_buffer/client/gles2_interface.h" | 10 #include "gpu/command_buffer/client/gles2_interface.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 context->DeleteShader(vertex_shader_id_); | 170 context->DeleteShader(vertex_shader_id_); |
171 vertex_shader_id_ = 0; | 171 vertex_shader_id_ = 0; |
172 return false; | 172 return false; |
173 } | 173 } |
174 | 174 |
175 program_ = | 175 program_ = |
176 CreateShaderProgram(context, vertex_shader_id_, fragment_shader_id_); | 176 CreateShaderProgram(context, vertex_shader_id_, fragment_shader_id_); |
177 return !!program_; | 177 return !!program_; |
178 } | 178 } |
179 | 179 |
180 bool ProgramBindingBase::Link(GLES2Interface* context, | 180 bool ProgramBindingBase::Link(GLES2Interface* context) { |
181 const std::string& vertex_source, | |
182 const std::string& fragment_source) { | |
183 context->LinkProgram(program_); | 181 context->LinkProgram(program_); |
184 CleanupShaders(context); | 182 CleanupShaders(context); |
185 if (!program_) | 183 if (!program_) |
186 return false; | 184 return false; |
| 185 #ifndef NDEBUG |
187 int linked = 0; | 186 int linked = 0; |
188 context->GetProgramiv(program_, GL_LINK_STATUS, &linked); | 187 context->GetProgramiv(program_, GL_LINK_STATUS, &linked); |
189 if (!linked) { | 188 if (!linked) { |
190 char buffer[1024] = ""; | 189 char buffer[1024] = ""; |
191 context->GetProgramInfoLog(program_, sizeof(buffer), nullptr, buffer); | 190 context->GetProgramInfoLog(program_, sizeof(buffer), nullptr, buffer); |
192 LOG(ERROR) << "Error linking shader: " << buffer << "\n" | 191 DLOG(ERROR) << "Error compiling shader: " << buffer; |
193 << "Vertex shader:\n" | |
194 << vertex_source << "Fragment shader:\n" | |
195 << fragment_source; | |
196 return false; | 192 return false; |
197 } | 193 } |
| 194 #endif |
198 return true; | 195 return true; |
199 } | 196 } |
200 | 197 |
201 void ProgramBindingBase::Cleanup(GLES2Interface* context) { | 198 void ProgramBindingBase::Cleanup(GLES2Interface* context) { |
202 initialized_ = false; | 199 initialized_ = false; |
203 if (!program_) | 200 if (!program_) |
204 return; | 201 return; |
205 | 202 |
206 DCHECK(context); | 203 DCHECK(context); |
207 context->DeleteProgram(program_); | 204 context->DeleteProgram(program_); |
208 program_ = 0; | 205 program_ = 0; |
209 | 206 |
210 CleanupShaders(context); | 207 CleanupShaders(context); |
211 } | 208 } |
212 | 209 |
213 unsigned ProgramBindingBase::LoadShader(GLES2Interface* context, | 210 unsigned ProgramBindingBase::LoadShader(GLES2Interface* context, |
214 unsigned type, | 211 unsigned type, |
215 const std::string& shader_source) { | 212 const std::string& shader_source) { |
216 unsigned shader = context->CreateShader(type); | 213 unsigned shader = context->CreateShader(type); |
217 if (!shader) | 214 if (!shader) |
218 return 0u; | 215 return 0u; |
219 | 216 |
220 const char* shader_source_str[] = { shader_source.data() }; | 217 const char* shader_source_str[] = { shader_source.data() }; |
221 int shader_length[] = { static_cast<int>(shader_source.length()) }; | 218 int shader_length[] = { static_cast<int>(shader_source.length()) }; |
222 context->ShaderSource( | 219 context->ShaderSource( |
223 shader, 1, | 220 shader, 1, |
224 shader_source_str, | 221 shader_source_str, |
225 shader_length); | 222 shader_length); |
226 context->CompileShader(shader); | 223 context->CompileShader(shader); |
| 224 #if DCHECK_IS_ON() |
227 int compiled = 0; | 225 int compiled = 0; |
228 context->GetShaderiv(shader, GL_COMPILE_STATUS, &compiled); | 226 context->GetShaderiv(shader, GL_COMPILE_STATUS, &compiled); |
229 if (!compiled) { | 227 if (!compiled) { |
230 char buffer[1024] = ""; | 228 char buffer[1024] = ""; |
231 context->GetShaderInfoLog(shader, sizeof(buffer), nullptr, buffer); | 229 context->GetShaderInfoLog(shader, sizeof(buffer), nullptr, buffer); |
232 LOG(ERROR) << "Error compiling shader: " << buffer << "\n" | 230 DLOG(ERROR) << "Error compiling shader: " << buffer |
233 << "Shader program:\n" | 231 << "\n shader program: " << shader_source; |
234 << shader_source; | |
235 return 0u; | 232 return 0u; |
236 } | 233 } |
| 234 #endif |
237 return shader; | 235 return shader; |
238 } | 236 } |
239 | 237 |
240 unsigned ProgramBindingBase::CreateShaderProgram(GLES2Interface* context, | 238 unsigned ProgramBindingBase::CreateShaderProgram(GLES2Interface* context, |
241 unsigned vertex_shader, | 239 unsigned vertex_shader, |
242 unsigned fragment_shader) { | 240 unsigned fragment_shader) { |
243 unsigned program_object = context->CreateProgram(); | 241 unsigned program_object = context->CreateProgram(); |
244 if (!program_object) | 242 if (!program_object) |
245 return 0; | 243 return 0; |
246 | 244 |
(...skipping 21 matching lines...) Expand all Loading... |
268 context->DeleteShader(fragment_shader_id_); | 266 context->DeleteShader(fragment_shader_id_); |
269 fragment_shader_id_ = 0; | 267 fragment_shader_id_ = 0; |
270 } | 268 } |
271 } | 269 } |
272 | 270 |
273 bool ProgramBindingBase::IsContextLost(GLES2Interface* context) { | 271 bool ProgramBindingBase::IsContextLost(GLES2Interface* context) { |
274 return context->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 272 return context->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
275 } | 273 } |
276 | 274 |
277 } // namespace cc | 275 } // namespace cc |
OLD | NEW |