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