Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / cc / output / program_binding.h
bloba10d0ab68d6a36fa086f805d05ec08d3d946eb53
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
3 // found in the LICENSE file.
5 #ifndef CC_OUTPUT_PROGRAM_BINDING_H_
6 #define CC_OUTPUT_PROGRAM_BINDING_H_
8 #include <string>
10 #include "base/logging.h"
11 #include "cc/output/context_provider.h"
12 #include "cc/output/shader.h"
14 namespace gpu {
15 namespace gles2 {
16 class GLES2Interface;
20 namespace cc {
22 class ProgramBindingBase {
23 public:
24 ProgramBindingBase();
25 ~ProgramBindingBase();
27 bool Init(gpu::gles2::GLES2Interface* context,
28 const std::string& vertex_shader,
29 const std::string& fragment_shader);
30 bool Link(gpu::gles2::GLES2Interface* context);
31 void Cleanup(gpu::gles2::GLES2Interface* context);
33 unsigned program() const { return program_; }
34 bool initialized() const { return initialized_; }
36 protected:
37 unsigned LoadShader(gpu::gles2::GLES2Interface* context,
38 unsigned type,
39 const std::string& shader_source);
40 unsigned CreateShaderProgram(gpu::gles2::GLES2Interface* context,
41 unsigned vertex_shader,
42 unsigned fragment_shader);
43 void CleanupShaders(gpu::gles2::GLES2Interface* context);
45 unsigned program_;
46 unsigned vertex_shader_id_;
47 unsigned fragment_shader_id_;
48 bool initialized_;
50 private:
51 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase);
54 template <class VertexShader, class FragmentShader>
55 class ProgramBinding : public ProgramBindingBase {
56 public:
57 ProgramBinding() {}
59 void Initialize(ContextProvider* context_provider,
60 TexCoordPrecision precision,
61 SamplerType sampler,
62 BlendMode blend_mode = BlendModeNone) {
63 DCHECK(context_provider);
64 DCHECK(!initialized_);
66 if (context_provider->IsContextLost())
67 return;
69 fragment_shader_.set_blend_mode(blend_mode);
71 if (!ProgramBindingBase::Init(
72 context_provider->ContextGL(),
73 vertex_shader_.GetShaderString(),
74 fragment_shader_.GetShaderString(precision, sampler))) {
75 DCHECK(context_provider->IsContextLost());
76 return;
79 int base_uniform_index = 0;
80 vertex_shader_.Init(context_provider->ContextGL(),
81 program_, &base_uniform_index);
82 fragment_shader_.Init(context_provider->ContextGL(),
83 program_, &base_uniform_index);
85 // Link after binding uniforms
86 if (!Link(context_provider->ContextGL())) {
87 DCHECK(context_provider->IsContextLost());
88 return;
91 initialized_ = true;
94 const VertexShader& vertex_shader() const { return vertex_shader_; }
95 const FragmentShader& fragment_shader() const { return fragment_shader_; }
97 private:
98 VertexShader vertex_shader_;
99 FragmentShader fragment_shader_;
101 DISALLOW_COPY_AND_ASSIGN(ProgramBinding);
104 } // namespace cc
106 #endif // CC_OUTPUT_PROGRAM_BINDING_H_