| 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" |
| 11 #include "cc/output/context_provider.h" | 11 #include "cc/output/context_provider.h" |
| 12 #include "cc/output/shader.h" | 12 #include "cc/output/shader.h" |
| 13 | 13 |
| 14 namespace blink { class WebGraphicsContext3D; } | 14 namespace gpu { |
| 15 namespace gles2 { |
| 16 class GLES2Interface; |
| 17 } |
| 18 } |
| 15 | 19 |
| 16 namespace cc { | 20 namespace cc { |
| 17 | 21 |
| 18 class ProgramBindingBase { | 22 class ProgramBindingBase { |
| 19 public: | 23 public: |
| 20 ProgramBindingBase(); | 24 ProgramBindingBase(); |
| 21 ~ProgramBindingBase(); | 25 ~ProgramBindingBase(); |
| 22 | 26 |
| 23 bool Init(blink::WebGraphicsContext3D* context, | 27 bool Init(gpu::gles2::GLES2Interface* context, |
| 24 const std::string& vertex_shader, | 28 const std::string& vertex_shader, |
| 25 const std::string& fragment_shader); | 29 const std::string& fragment_shader); |
| 26 bool Link(blink::WebGraphicsContext3D* context); | 30 bool Link(gpu::gles2::GLES2Interface* context); |
| 27 void Cleanup(blink::WebGraphicsContext3D* context); | 31 void Cleanup(gpu::gles2::GLES2Interface* context); |
| 28 | 32 |
| 29 unsigned program() const { return program_; } | 33 unsigned program() const { return program_; } |
| 30 bool initialized() const { return initialized_; } | 34 bool initialized() const { return initialized_; } |
| 31 | 35 |
| 32 protected: | 36 protected: |
| 33 unsigned LoadShader(blink::WebGraphicsContext3D* context, | 37 unsigned LoadShader(gpu::gles2::GLES2Interface* context, |
| 34 unsigned type, | 38 unsigned type, |
| 35 const std::string& shader_source); | 39 const std::string& shader_source); |
| 36 unsigned CreateShaderProgram(blink::WebGraphicsContext3D* context, | 40 unsigned CreateShaderProgram(gpu::gles2::GLES2Interface* context, |
| 37 unsigned vertex_shader, | 41 unsigned vertex_shader, |
| 38 unsigned fragment_shader); | 42 unsigned fragment_shader); |
| 39 void CleanupShaders(blink::WebGraphicsContext3D* context); | 43 void CleanupShaders(gpu::gles2::GLES2Interface* context); |
| 40 | 44 |
| 41 unsigned program_; | 45 unsigned program_; |
| 42 unsigned vertex_shader_id_; | 46 unsigned vertex_shader_id_; |
| 43 unsigned fragment_shader_id_; | 47 unsigned fragment_shader_id_; |
| 44 bool initialized_; | 48 bool initialized_; |
| 45 | 49 |
| 46 private: | 50 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase); | 51 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase); |
| 48 }; | 52 }; |
| 49 | 53 |
| 50 template <class VertexShader, class FragmentShader> | 54 template <class VertexShader, class FragmentShader> |
| 51 class ProgramBinding : public ProgramBindingBase { | 55 class ProgramBinding : public ProgramBindingBase { |
| 52 public: | 56 public: |
| 53 ProgramBinding() {} | 57 ProgramBinding() {} |
| 54 | 58 |
| 55 void Initialize(ContextProvider* context_provider, | 59 void Initialize(ContextProvider* context_provider, |
| 56 TexCoordPrecision precision, | 60 TexCoordPrecision precision, |
| 57 SamplerType sampler) { | 61 SamplerType sampler) { |
| 58 DCHECK(context_provider); | 62 DCHECK(context_provider); |
| 59 DCHECK(!initialized_); | 63 DCHECK(!initialized_); |
| 60 | 64 |
| 61 if (context_provider->IsContextLost()) | 65 if (context_provider->IsContextLost()) |
| 62 return; | 66 return; |
| 63 | 67 |
| 64 if (!ProgramBindingBase::Init( | 68 if (!ProgramBindingBase::Init( |
| 65 context_provider->Context3d(), | 69 context_provider->ContextGL(), |
| 66 vertex_shader_.GetShaderString(), | 70 vertex_shader_.GetShaderString(), |
| 67 fragment_shader_.GetShaderString(precision, sampler))) { | 71 fragment_shader_.GetShaderString(precision, sampler))) { |
| 68 DCHECK(context_provider->IsContextLost()); | 72 DCHECK(context_provider->IsContextLost()); |
| 69 return; | 73 return; |
| 70 } | 74 } |
| 71 | 75 |
| 72 int base_uniform_index = 0; | 76 int base_uniform_index = 0; |
| 73 vertex_shader_.Init(context_provider->Context3d(), | 77 vertex_shader_.Init(context_provider->ContextGL(), |
| 74 program_, &base_uniform_index); | 78 program_, &base_uniform_index); |
| 75 fragment_shader_.Init(context_provider->Context3d(), | 79 fragment_shader_.Init(context_provider->ContextGL(), |
| 76 program_, &base_uniform_index); | 80 program_, &base_uniform_index); |
| 77 | 81 |
| 78 // Link after binding uniforms | 82 // Link after binding uniforms |
| 79 if (!Link(context_provider->Context3d())) { | 83 if (!Link(context_provider->ContextGL())) { |
| 80 DCHECK(context_provider->IsContextLost()); | 84 DCHECK(context_provider->IsContextLost()); |
| 81 return; | 85 return; |
| 82 } | 86 } |
| 83 | 87 |
| 84 initialized_ = true; | 88 initialized_ = true; |
| 85 } | 89 } |
| 86 | 90 |
| 87 const VertexShader& vertex_shader() const { return vertex_shader_; } | 91 const VertexShader& vertex_shader() const { return vertex_shader_; } |
| 88 const FragmentShader& fragment_shader() const { return fragment_shader_; } | 92 const FragmentShader& fragment_shader() const { return fragment_shader_; } |
| 89 | 93 |
| 90 private: | 94 private: |
| 91 VertexShader vertex_shader_; | 95 VertexShader vertex_shader_; |
| 92 FragmentShader fragment_shader_; | 96 FragmentShader fragment_shader_; |
| 93 | 97 |
| 94 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); | 98 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); |
| 95 }; | 99 }; |
| 96 | 100 |
| 97 } // namespace cc | 101 } // namespace cc |
| 98 | 102 |
| 99 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ | 103 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ |
| OLD | NEW |