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