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 #ifndef CC_OUTPUT_PROGRAM_BINDING_H_ | 5 #ifndef CC_OUTPUT_PROGRAM_BINDING_H_ |
6 #define CC_OUTPUT_PROGRAM_BINDING_H_ | 6 #define CC_OUTPUT_PROGRAM_BINDING_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 namespace cc { | 25 namespace cc { |
26 | 26 |
27 class ProgramBindingBase { | 27 class ProgramBindingBase { |
28 public: | 28 public: |
29 ProgramBindingBase(); | 29 ProgramBindingBase(); |
30 ~ProgramBindingBase(); | 30 ~ProgramBindingBase(); |
31 | 31 |
32 bool Init(gpu::gles2::GLES2Interface* context, | 32 bool Init(gpu::gles2::GLES2Interface* context, |
33 const std::string& vertex_shader, | 33 const std::string& vertex_shader, |
34 const std::string& fragment_shader); | 34 const std::string& fragment_shader); |
35 bool Link(gpu::gles2::GLES2Interface* context); | 35 bool Link(gpu::gles2::GLES2Interface* context, |
| 36 const std::string& vertex_source, |
| 37 const std::string& fragment_source); |
36 void Cleanup(gpu::gles2::GLES2Interface* context); | 38 void Cleanup(gpu::gles2::GLES2Interface* context); |
37 | 39 |
38 unsigned program() const { return program_; } | 40 unsigned program() const { return program_; } |
39 bool initialized() const { return initialized_; } | 41 bool initialized() const { return initialized_; } |
40 | 42 |
41 protected: | 43 protected: |
42 unsigned LoadShader(gpu::gles2::GLES2Interface* context, | 44 unsigned LoadShader(gpu::gles2::GLES2Interface* context, |
43 unsigned type, | 45 unsigned type, |
44 const std::string& shader_source); | 46 const std::string& shader_source); |
45 unsigned CreateShaderProgram(gpu::gles2::GLES2Interface* context, | 47 unsigned CreateShaderProgram(gpu::gles2::GLES2Interface* context, |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 fragment_shader_.uv_texture_mode_ = key.uv_texture_mode_; | 398 fragment_shader_.uv_texture_mode_ = key.uv_texture_mode_; |
397 } | 399 } |
398 | 400 |
399 void InitializeInternal(ContextProvider* context_provider) { | 401 void InitializeInternal(ContextProvider* context_provider) { |
400 DCHECK(context_provider); | 402 DCHECK(context_provider); |
401 DCHECK(!initialized_); | 403 DCHECK(!initialized_); |
402 | 404 |
403 if (IsContextLost(context_provider->ContextGL())) | 405 if (IsContextLost(context_provider->ContextGL())) |
404 return; | 406 return; |
405 | 407 |
406 if (!ProgramBindingBase::Init(context_provider->ContextGL(), | 408 std::string vertex_source = vertex_shader_.GetShaderString(); |
407 vertex_shader_.GetShaderString(), | 409 std::string fragment_source = fragment_shader_.GetShaderString(); |
408 fragment_shader_.GetShaderString())) { | 410 if (!ProgramBindingBase::Init(context_provider->ContextGL(), vertex_source, |
| 411 fragment_source)) { |
409 DCHECK(IsContextLost(context_provider->ContextGL())); | 412 DCHECK(IsContextLost(context_provider->ContextGL())); |
410 return; | 413 return; |
411 } | 414 } |
412 | 415 |
413 int base_uniform_index = 0; | 416 int base_uniform_index = 0; |
414 vertex_shader_.Init(context_provider->ContextGL(), | 417 vertex_shader_.Init(context_provider->ContextGL(), |
415 program_, &base_uniform_index); | 418 program_, &base_uniform_index); |
416 fragment_shader_.Init(context_provider->ContextGL(), | 419 fragment_shader_.Init(context_provider->ContextGL(), |
417 program_, &base_uniform_index); | 420 program_, &base_uniform_index); |
418 | 421 |
419 // Link after binding uniforms | 422 // Link after binding uniforms |
420 if (!Link(context_provider->ContextGL())) { | 423 if (!Link(context_provider->ContextGL(), vertex_source, fragment_source)) { |
421 DCHECK(IsContextLost(context_provider->ContextGL())); | 424 DCHECK(IsContextLost(context_provider->ContextGL())); |
422 return; | 425 return; |
423 } | 426 } |
424 | 427 |
425 initialized_ = true; | 428 initialized_ = true; |
426 } | 429 } |
427 | 430 |
428 VertexShader vertex_shader_; | 431 VertexShader vertex_shader_; |
429 FragmentShader fragment_shader_; | 432 FragmentShader fragment_shader_; |
430 | 433 |
431 DISALLOW_COPY_AND_ASSIGN(Program); | 434 DISALLOW_COPY_AND_ASSIGN(Program); |
432 }; | 435 }; |
433 | 436 |
434 } // namespace cc | 437 } // namespace cc |
435 | 438 |
436 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ | 439 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ |
OLD | NEW |