| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 protected: | 36 protected: |
| 37 unsigned LoadShader(gpu::gles2::GLES2Interface* context, | 37 unsigned LoadShader(gpu::gles2::GLES2Interface* context, |
| 38 unsigned type, | 38 unsigned type, |
| 39 const std::string& shader_source); | 39 const std::string& shader_source); |
| 40 unsigned CreateShaderProgram(gpu::gles2::GLES2Interface* context, | 40 unsigned CreateShaderProgram(gpu::gles2::GLES2Interface* context, |
| 41 unsigned vertex_shader, | 41 unsigned vertex_shader, |
| 42 unsigned fragment_shader); | 42 unsigned fragment_shader); |
| 43 void CleanupShaders(gpu::gles2::GLES2Interface* context); | 43 void CleanupShaders(gpu::gles2::GLES2Interface* context); |
| 44 | 44 |
| 45 bool IsContextLost(gpu::gles2::GLES2Interface* context); |
| 46 |
| 45 unsigned program_; | 47 unsigned program_; |
| 46 unsigned vertex_shader_id_; | 48 unsigned vertex_shader_id_; |
| 47 unsigned fragment_shader_id_; | 49 unsigned fragment_shader_id_; |
| 48 bool initialized_; | 50 bool initialized_; |
| 49 | 51 |
| 50 private: | 52 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase); | 53 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase); |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 template <class VertexShader, class FragmentShader> | 56 template <class VertexShader, class FragmentShader> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 72 } | 74 } |
| 73 | 75 |
| 74 void Initialize(ContextProvider* context_provider, | 76 void Initialize(ContextProvider* context_provider, |
| 75 TexCoordPrecision precision, | 77 TexCoordPrecision precision, |
| 76 SamplerType sampler, | 78 SamplerType sampler, |
| 77 BlendMode blend_mode, | 79 BlendMode blend_mode, |
| 78 bool mask_for_background) { | 80 bool mask_for_background) { |
| 79 DCHECK(context_provider); | 81 DCHECK(context_provider); |
| 80 DCHECK(!initialized_); | 82 DCHECK(!initialized_); |
| 81 | 83 |
| 82 if (context_provider->IsContextLost()) | 84 if (IsContextLost(context_provider->ContextGL())) |
| 83 return; | 85 return; |
| 84 | 86 |
| 85 fragment_shader_.set_blend_mode(blend_mode); | 87 fragment_shader_.set_blend_mode(blend_mode); |
| 86 fragment_shader_.set_mask_for_background(mask_for_background); | 88 fragment_shader_.set_mask_for_background(mask_for_background); |
| 87 | 89 |
| 88 if (!ProgramBindingBase::Init( | 90 if (!ProgramBindingBase::Init( |
| 89 context_provider->ContextGL(), | 91 context_provider->ContextGL(), |
| 90 vertex_shader_.GetShaderString(), | 92 vertex_shader_.GetShaderString(), |
| 91 fragment_shader_.GetShaderString(precision, sampler))) { | 93 fragment_shader_.GetShaderString(precision, sampler))) { |
| 92 DCHECK(context_provider->IsContextLost()); | 94 DCHECK(IsContextLost(context_provider->ContextGL())); |
| 93 return; | 95 return; |
| 94 } | 96 } |
| 95 | 97 |
| 96 int base_uniform_index = 0; | 98 int base_uniform_index = 0; |
| 97 vertex_shader_.Init(context_provider->ContextGL(), | 99 vertex_shader_.Init(context_provider->ContextGL(), |
| 98 program_, &base_uniform_index); | 100 program_, &base_uniform_index); |
| 99 fragment_shader_.Init(context_provider->ContextGL(), | 101 fragment_shader_.Init(context_provider->ContextGL(), |
| 100 program_, &base_uniform_index); | 102 program_, &base_uniform_index); |
| 101 | 103 |
| 102 // Link after binding uniforms | 104 // Link after binding uniforms |
| 103 if (!Link(context_provider->ContextGL())) { | 105 if (!Link(context_provider->ContextGL())) { |
| 104 DCHECK(context_provider->IsContextLost()); | 106 DCHECK(IsContextLost(context_provider->ContextGL())); |
| 105 return; | 107 return; |
| 106 } | 108 } |
| 107 | 109 |
| 108 initialized_ = true; | 110 initialized_ = true; |
| 109 } | 111 } |
| 110 | 112 |
| 111 const VertexShader& vertex_shader() const { return vertex_shader_; } | 113 const VertexShader& vertex_shader() const { return vertex_shader_; } |
| 112 const FragmentShader& fragment_shader() const { return fragment_shader_; } | 114 const FragmentShader& fragment_shader() const { return fragment_shader_; } |
| 113 | 115 |
| 114 private: | 116 private: |
| 115 VertexShader vertex_shader_; | 117 VertexShader vertex_shader_; |
| 116 FragmentShader fragment_shader_; | 118 FragmentShader fragment_shader_; |
| 117 | 119 |
| 118 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); | 120 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); |
| 119 }; | 121 }; |
| 120 | 122 |
| 121 } // namespace cc | 123 } // namespace cc |
| 122 | 124 |
| 123 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ | 125 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ |
| OLD | NEW |